package com.steerinfo.meterwork.meterworkzeroalarm.service.impl;

import com.steerinfo.framework.mapper.IBaseMapper;
import com.steerinfo.framework.service.impl.BaseServiceImpl;
import com.steerinfo.framework.service.pagehelper.PageHelper;
import com.steerinfo.framework.service.pagehelper.PageList;
import com.steerinfo.meterwork.meterworkzeroalarm.model.MeterWorkZeroAlarm;
import com.steerinfo.meterwork.meterworkzeroalarm.mapper.MeterWorkZeroAlarmMapper;
import com.steerinfo.meterwork.meterworkzeroalarm.service.IMeterWorkZeroAlarmService;
import com.steerinfo.util.PublicMethod;
import com.steerinfo.util.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Date;
import java.util.HashMap;
import java.util.List;

/**
 * MeterWorkZeroAlarm服务实现：
 *
 * @author generator
 * @version 1.0-SNAPSHORT 2021-11-20 11:16
 * 类描述
 * 修订历史：
 * 日期：2021-11-20
 * 作者：generator
 * 参考：
 * 描述：MeterWorkZeroAlarm服务实现
 * @Copyright 湖南视拓信息技术股份有限公司. All rights reserved.
 * @see null
 */
@Service(value = "meterWorkZeroAlarmService")
public class MeterWorkZeroAlarmServiceImpl extends BaseServiceImpl<MeterWorkZeroAlarm, String> implements IMeterWorkZeroAlarmService {

    @Resource
    private MeterWorkZeroAlarmMapper meterWorkZeroAlarmMapper;

    @Override
    protected IBaseMapper<MeterWorkZeroAlarm, String> getMapper() {
        return meterWorkZeroAlarmMapper;
    }

    /**
     * 新增零点报警记录
     *
     * @param model
     * @return
     */
    @Override
    public String doInsertZeroAlarm(MeterWorkZeroAlarm model) {
        if (model == null || StringUtils.isEmpty(model.getBaseSpotNo())
                || StringUtils.isEmpty(model.getBaseSpotName()) || StringUtils.isEmpty(model.getScalePointNo())) {
            return "参数不允许为空！计量点编号，计量点名称，秤点编号CAR**均不允许为空";
        }
        String maxId = PublicMethod.IdCreate(2);
        model.setAlarmNo(maxId);
        model.setZeroTime(new Date());
        model.setCreateTime(new Date());
        if (StringUtils.isEmpty(model.getCreateManNo())) {
            model.setCreateManNo("system");
            model.setCreateManNo("系统自动创建");
        }
        meterWorkZeroAlarmMapper.insertSelective(model);
        return null;
    }

    @Override
    public PageList<MeterWorkZeroAlarm> likeByDesc(HashMap<String, Object> params, Integer pageNum, Integer pageSize) {
        PageHelper.startPage(pageNum, pageSize);
        List<MeterWorkZeroAlarm> rows = meterWorkZeroAlarmMapper.likeByDesc(params);
        PageList pageInfo = new PageList(rows);
        return pageInfo;
    }
}
