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

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

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

/**
 * 巡检计划Service业务层处理
 * 
 * @author zehong
 * @date 2021-07-21
 */
@Service
public class TInspectionPlanServiceImpl implements ITInspectionPlanService 
{
    @Autowired
    private TInspectionPlanMapper tInspectionPlanMapper;
29 30
    @Autowired
    private TInspectionDataMapper tInspectionDataMapper;
31 32 33 34 35 36 37 38

    /**
     * 查询巡检计划
     * 
     * @param planId 巡检计划ID
     * @return 巡检计划
     */
    @Override
39
    public TInspectionPlan selectTInspectionPlanById(int planId) throws Exception
40 41 42 43 44 45 46
    {
        return tInspectionPlanMapper.selectTInspectionPlanById(planId);
    }

    /**
     * 查询巡检计划列表
     * 
47
     * @param inspectionPlanForm 巡检计划
48 49 50
     * @return 巡检计划
     */
    @Override
51
    public List<TInspectionPlan> selectTInspectionPlanList(InspectionPlanForm inspectionPlanForm)
52
    {
53
        return tInspectionPlanMapper.selectTInspectionPlanList(inspectionPlanForm);
54 55 56 57 58 59 60 61 62
    }

    /**
     * 新增巡检计划
     * 
     * @param tInspectionPlan 巡检计划
     * @return 结果
     */
    @Override
63
    public int insertTInspectionPlan(TInspectionPlan tInspectionPlan) throws Exception
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 90 91
        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);
                }
            }
        }
92
        tInspectionPlan.setPlanStatus("0");
93 94 95 96 97 98
        tInspectionPlan.setCreateTime(DateUtils.getNowDate());
        return tInspectionPlanMapper.insertTInspectionPlan(tInspectionPlan);
    }

    /**
     * 修改巡检计划
99
     *
100 101 102 103
     * @param tInspectionPlan 巡检计划
     * @return 结果
     */
    @Override
104
    public int updateTInspectionPlan(TInspectionPlan tInspectionPlan) throws Exception
105
    {
106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135
        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);
                }
            }
        }

136 137 138 139 140 141 142 143 144 145 146
        tInspectionPlan.setUpdateTime(DateUtils.getNowDate());
        return tInspectionPlanMapper.updateTInspectionPlan(tInspectionPlan);
    }

    /**
     * 批量删除巡检计划
     * 
     * @param planIds 需要删除的巡检计划ID
     * @return 结果
     */
    @Override
147
    public int deleteTInspectionPlanByIds(int[] planIds)
148 149 150 151 152 153 154 155 156 157 158
    {
        return tInspectionPlanMapper.deleteTInspectionPlanByIds(planIds);
    }

    /**
     * 删除巡检计划信息
     * 
     * @param planId 巡检计划ID
     * @return 结果
     */
    @Override
159
    public int deleteTInspectionPlanById(int planId)
160 161 162 163
    {
        return tInspectionPlanMapper.deleteTInspectionPlanById(planId);
    }
}