package com.steerinfo.associate.maintenancerecord.service.impl;

import com.steerinfo.baseinfo.meterbaseunitdirect.model.MeterBaseUnitDirect;
import com.steerinfo.framework.mapper.IBaseMapper;
import com.steerinfo.framework.service.impl.BaseServiceImpl;
import com.steerinfo.associate.maintenancerecord.model.MaintenanceRecord;
import com.steerinfo.associate.maintenancerecord.mapper.MaintenanceRecordMapper;
import com.steerinfo.associate.maintenancerecord.service.IMaintenanceRecordService;
import com.steerinfo.util.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.Date;
import java.math.BigDecimal;

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

    @Autowired
    private MaintenanceRecordMapper maintenanceRecordMapper;

    @Override
    protected IBaseMapper<MaintenanceRecord, String> getMapper() {
        return maintenanceRecordMapper;
    }

    @Override
    public String checkandadd(MaintenanceRecord model) {
        if (StringUtils.isEmpty(model.getEquipmentNo())){
            return "设备编号不能为空";
        }
        if (StringUtils.isEmpty(model.getEquipmentName())){
            return "设备名称不能为空";
        }
        if (StringUtils.isEmpty(model.getTeamGroupNo())){
            return "班组编号不能为空";
        }
        String no = maintenanceRecordMapper.GetNewID();
        model.setMaintenanceRecordNo(no);
        model.setVaildFlag("1");
        model.setCreateTime(new Date());
        maintenanceRecordMapper.insert(model);
        return "";
    }

    @Override
    public String checkandupdate(String id, MaintenanceRecord model) {
        if (model.getEquipmentNo() == null || model.getEquipmentNo().equals("")){
            return "设备编号不能为空";
        }
        if (model.getEquipmentName() == null || model.getEquipmentName().equals("")){
            return "设备名称不能为空";
        }
        if (model.getTeamGroupNo() == null || model.getTeamGroupNo().equals("")){
            return "班组编号不能为空";
        }
        model.setUpdateTime(new Date());
        maintenanceRecordMapper.updateByPrimaryKey(model);
        return "";
    }
}
