TInspectionPlanServiceImpl.java 7.13 KB
Newer Older
1 2
package com.zehong.system.service.impl;

3
import java.util.ArrayList;
4
import java.util.List;
5 6 7
import java.util.regex.Matcher;
import java.util.regex.Pattern;

8
import com.zehong.common.core.domain.entity.SysUser;
9
import com.zehong.common.utils.DateUtils;
10
import com.zehong.system.domain.*;
11
import com.zehong.system.domain.form.InspectionPlanForm;
12
import com.zehong.system.domain.vo.InspectionPlanVo;
13 14
import com.zehong.system.mapper.*;
import org.springframework.beans.BeanUtils;
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.zehong.system.service.ITInspectionPlanService;

/**
 * 巡检计划Service业务层处理
 * 
 * @author zehong
 * @date 2021-07-21
 */
@Service
public class TInspectionPlanServiceImpl implements ITInspectionPlanService 
{
    @Autowired
    private TInspectionPlanMapper tInspectionPlanMapper;
30 31
    @Autowired
    private TInspectionDataMapper tInspectionDataMapper;
32 33 34 35 36 37 38 39
    @Autowired
    private SysUserMapper sysUserMapper;
    @Autowired
    private TWorkOrderMapper tWorkOrderMapper;
    @Autowired
    private TPipeMapper tPipeMapper;
    @Autowired
    private TDeviceInfoMapper tDeviceInfoMapper;
40 41 42 43 44 45 46 47

    /**
     * 查询巡检计划
     * 
     * @param planId 巡检计划ID
     * @return 巡检计划
     */
    @Override
48
    public InspectionPlanVo selectTInspectionPlanById(int planId) throws Exception
49
    {
50 51 52 53
        InspectionPlanVo inspectionPlanVo = new InspectionPlanVo();
        TInspectionPlan tInspectionPlan = tInspectionPlanMapper.selectTInspectionPlanById(planId);
        BeanUtils.copyProperties(tInspectionPlan, inspectionPlanVo);

54
        if(tInspectionPlan.getOrderId() != null && !"".equals(tInspectionPlan.getOrderId())) {
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89
            TWorkOrder tWorkOrder = tWorkOrderMapper.selectTWorkOrderById(tInspectionPlan.getOrderId());
            inspectionPlanVo.setAllotTime(tWorkOrder.getAllotTime());
            // 获取巡检员姓名
            SysUser appointInspector = sysUserMapper.selectUserById(tWorkOrder.getAppointInspector());
            inspectionPlanVo.setAppointInspectorName(appointInspector.getNickName());
        }

        List<TDeviceInfo> deviceInfoList = new ArrayList<>();
        List<TPipe> pipeList = new ArrayList<>();

        TInspectionData tInspectionData = new TInspectionData();
        tInspectionData.setPlanId(planId);
        List<TInspectionData> dataList = tInspectionDataMapper.selectTInspectionDataList(tInspectionData);

        if(dataList.size() != 0) {
            TDeviceInfo deviceInfo = null;
            TPipe pipe = null;

            for (TInspectionData temp : dataList) {
                if (!"0".equals(temp.getDeviceType())) {
                    deviceInfo = tDeviceInfoMapper.selectTDeviceInfoById(temp.getDeviceId());
                    if (deviceInfo != null) {
                        deviceInfoList.add(deviceInfo);
                    }
                } else {
                    pipe = tPipeMapper.selectTPipeById(temp.getDeviceId());
                    if (pipe != null) {
                        pipeList.add(pipe);
                    }
                }
            }
        }
        inspectionPlanVo.setPipeList(pipeList);
        inspectionPlanVo.setDeviceList(deviceInfoList);
        return inspectionPlanVo;
90 91 92 93 94
    }

    /**
     * 查询巡检计划列表
     * 
95
     * @param inspectionPlanForm 巡检计划
96 97 98
     * @return 巡检计划
     */
    @Override
99
    public List<TInspectionPlan> selectTInspectionPlanList(InspectionPlanForm inspectionPlanForm)
100
    {
101
        return tInspectionPlanMapper.selectTInspectionPlanList(inspectionPlanForm);
102 103 104 105 106 107 108 109 110
    }

    /**
     * 新增巡检计划
     * 
     * @param tInspectionPlan 巡检计划
     * @return 结果
     */
    @Override
111
    public int insertTInspectionPlan(TInspectionPlan tInspectionPlan) throws Exception
112
    {
113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139
        String deviceIds = tInspectionPlan.getDeviceIds();
        String[] stringArr = deviceIds.split("],");
        String deviceType = null;

        for(int i = 0; i < stringArr.length; i++) {
            String[] temp = stringArr[i].split(",");

            for (int j = 0; j < temp.length; j++) {
                String regEx="[^0-9]";
                Pattern p = Pattern.compile(regEx);
                Matcher m = p.matcher(temp[j]);
//                System.out.println(m.replaceAll("").trim());

                if(j == 0) {
                    deviceType = m.replaceAll("").trim();
                } else {
                    Integer deviceId = Integer.valueOf(m.replaceAll("").trim());
                    TInspectionData data = new TInspectionData();
                    data.setPlanId(tInspectionPlan.getPlanId());
                    data.setDeviceId(deviceId);
                    data.setDeviceType(deviceType);
                    data.setCreateTime(DateUtils.getNowDate());

                    tInspectionDataMapper.insertTInspectionData(data);
                }
            }
        }
140
        tInspectionPlan.setPlanStatus("0");
141 142 143 144 145 146
        tInspectionPlan.setCreateTime(DateUtils.getNowDate());
        return tInspectionPlanMapper.insertTInspectionPlan(tInspectionPlan);
    }

    /**
     * 修改巡检计划
147
     *
148 149 150 151
     * @param tInspectionPlan 巡检计划
     * @return 结果
     */
    @Override
152
    public int updateTInspectionPlan(TInspectionPlan tInspectionPlan) throws Exception
153
    {
154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183
        tInspectionDataMapper.deleteTInspectionDataByPlanId(tInspectionPlan.getPlanId());

        String deviceIds = tInspectionPlan.getDeviceIds();
        String[] stringArr = deviceIds.split("],");
        String deviceType = null;

        for(int i = 0; i < stringArr.length; i++) {
            String[] temp = stringArr[i].split(",");

            for (int j = 0; j < temp.length; j++) {
                String regEx="[^0-9]";
                Pattern p = Pattern.compile(regEx);
                Matcher m = p.matcher(temp[j]);
//                System.out.println(m.replaceAll("").trim());

                if(j == 0) {
                    deviceType = m.replaceAll("").trim();
                } else {
                    Integer deviceId = Integer.valueOf(m.replaceAll("").trim());
                    TInspectionData data = new TInspectionData();
                    data.setPlanId(tInspectionPlan.getPlanId());
                    data.setDeviceId(deviceId);
                    data.setDeviceType(deviceType);
                    data.setCreateTime(DateUtils.getNowDate());

                    tInspectionDataMapper.insertTInspectionData(data);
                }
            }
        }

184 185 186 187 188 189 190 191 192 193 194
        tInspectionPlan.setUpdateTime(DateUtils.getNowDate());
        return tInspectionPlanMapper.updateTInspectionPlan(tInspectionPlan);
    }

    /**
     * 批量删除巡检计划
     * 
     * @param planIds 需要删除的巡检计划ID
     * @return 结果
     */
    @Override
195
    public int deleteTInspectionPlanByIds(int[] planIds)
196 197 198 199 200 201 202 203 204 205 206
    {
        return tInspectionPlanMapper.deleteTInspectionPlanByIds(planIds);
    }

    /**
     * 删除巡检计划信息
     * 
     * @param planId 巡检计划ID
     * @return 结果
     */
    @Override
207
    public int deleteTInspectionPlanById(int planId)
208 209 210 211
    {
        return tInspectionPlanMapper.deleteTInspectionPlanById(planId);
    }
}