k94314517
2024-11-21 a28e0d402702e69e0e75b0c902835239d21bfb6f
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
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
184
185
186
187
188
189
190
191
192
193
194
195
package com.doumee.service.business.impl;
 
import com.doumee.core.constants.ResponseStatus;
import com.doumee.core.exception.BusinessException;
import com.doumee.core.model.LoginUserInfo;
import com.doumee.core.model.PageData;
import com.doumee.core.model.PageWrap;
import com.doumee.core.utils.Constants;
import com.doumee.core.utils.Utils;
import com.doumee.dao.business.YwLinePointMapper;
import com.doumee.dao.business.YwPatrolLineMapper;
import com.doumee.dao.business.model.*;
import com.doumee.service.business.YwPatrolLineService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.github.yulichang.wrapper.MPJLambdaWrapper;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.CollectionUtils;
 
import java.util.Date;
import java.util.List;
import java.util.Objects;
 
/**
 * 运维巡检路线信息表Service实现
 * @author 江蹄蹄
 * @date 2024/11/19 16:07
 */
@Service
public class YwPatrolLineServiceImpl implements YwPatrolLineService {
 
    @Autowired
    private YwPatrolLineMapper ywPatrolLineMapper;
 
    @Autowired
    private YwLinePointMapper ywLinePointMapper;
 
    @Override
    @Transactional(rollbackFor = {Exception.class,BusinessException.class})
    public Integer create(YwPatrolLine ywPatrolLine) {
        if(Objects.isNull(ywPatrolLine)
        || StringUtils.isBlank(ywPatrolLine.getName())
        || com.github.xiaoymin.knife4j.core.util.CollectionUtils.isEmpty(ywPatrolLine.getLinePointList())){
            throw new BusinessException(ResponseStatus.BAD_REQUEST);
        }
 
        LoginUserInfo loginUserInfo = ywPatrolLine.getLoginUserInfo();
        ywPatrolLine.setCreateDate(new Date());
        ywPatrolLine.setCreator(loginUserInfo.getId());
        ywPatrolLine.setIsdeleted(Constants.ZERO);
        ywPatrolLine.setStatus(Constants.ZERO);
        ywPatrolLineMapper.insert(ywPatrolLine);
        //循环处理 子集数据
 
        List<YwLinePoint> ywLinePointList = ywPatrolLine.getLinePointList();
        for (YwLinePoint ywLinePoint:ywLinePointList) {
            if(Objects.isNull(ywLinePoint)
            || Objects.isNull(ywLinePoint.getPointId())
            || Objects.isNull(ywLinePoint.getNeedScancode())
            ){
                throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(),"巡检点配置错误");
            }
            ywLinePoint.setCreateDate(new Date());
            ywLinePoint.setCreator(loginUserInfo.getId());
            ywLinePoint.setIsdeleted(Constants.ZERO);
            ywLinePoint.setLineId(ywLinePoint.getId());
        }
        ywLinePointMapper.insert(ywLinePointList);
        return ywPatrolLine.getId();
    }
 
    @Override
    public void deleteById(Integer id, LoginUserInfo user) {
        ywPatrolLineMapper.deleteById(id);
    }
 
    @Override
    public void delete(YwPatrolLine ywPatrolLine) {
        UpdateWrapper<YwPatrolLine> deleteWrapper = new UpdateWrapper<>(ywPatrolLine);
        ywPatrolLineMapper.delete(deleteWrapper);
    }
 
    @Override
    public void deleteByIdInBatch(List<Integer> ids, LoginUserInfo user) {
        if (CollectionUtils.isEmpty(ids)) {
            return;
        }
        ywPatrolLineMapper.deleteBatchIds(ids);
    }
 
    @Override
    public void updateById(YwPatrolLine ywPatrolLine) {
        if(Objects.isNull(ywPatrolLine)
                || StringUtils.isBlank(ywPatrolLine.getName())
                || com.github.xiaoymin.knife4j.core.util.CollectionUtils.isEmpty(ywPatrolLine.getLinePointList())){
            throw new BusinessException(ResponseStatus.BAD_REQUEST);
        }
 
        LoginUserInfo loginUserInfo = ywPatrolLine.getLoginUserInfo();
        ywPatrolLine.setEditDate(new Date());
        ywPatrolLine.setEditor(loginUserInfo.getId());
        ywPatrolLineMapper.updateById(ywPatrolLine);
        //删除子数据
        ywLinePointMapper.delete(new QueryWrapper<YwLinePoint>().lambda()
                .eq(YwLinePoint::getLineId,ywPatrolLine.getId()));
        //循环处理 子集数据
        List<YwLinePoint> ywLinePointList = ywPatrolLine.getLinePointList();
        for (YwLinePoint ywLinePoint:ywLinePointList) {
            if(Objects.isNull(ywLinePoint)
                    || Objects.isNull(ywLinePoint.getPointId())
                    || Objects.isNull(ywLinePoint.getNeedScancode())
            ){
                throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(),"巡检点配置错误");
            }
            ywLinePoint.setLineId(ywLinePoint.getId());
            ywLinePoint.setCreateDate(new Date());
            ywLinePoint.setCreator(loginUserInfo.getId());
            ywLinePoint.setIsdeleted(Constants.ZERO);
        }
        ywLinePointMapper.insert(ywLinePointList);
    }
 
    @Override
    public void updateByIdInBatch(List<YwPatrolLine> ywPatrolLines) {
        if (CollectionUtils.isEmpty(ywPatrolLines)) {
            return;
        }
        for (YwPatrolLine ywPatrolLine: ywPatrolLines) {
            this.updateById(ywPatrolLine);
        }
    }
 
    @Override
    public YwPatrolLine findById(Integer id) {
        return ywPatrolLineMapper.selectById(id);
    }
 
 
    @Override
    public YwPatrolLine getDetail(Integer id) {
        YwPatrolLine ywPatrolLine =  ywPatrolLineMapper.selectById(id);
 
        List<YwLinePoint> ywLinePointList = ywLinePointMapper.selectJoinList(YwLinePoint.class,new MPJLambdaWrapper<YwLinePoint>()
                .selectAll(YwLinePoint.class)
                .selectAs(YwPatrolPoint::getName,YwLinePoint::getPointName)
                .leftJoin(YwPatrolLine.class,YwPatrolLine::getId,YwLinePoint::getPointId)
                .eq(YwLinePoint::getLineId,id)
                .orderByAsc(YwLinePoint::getSortnum)
        );
 
        ywPatrolLine.setLinePointList(ywLinePointList);
 
        return ywPatrolLine;
    }
 
 
    @Override
    public YwPatrolLine findOne(YwPatrolLine ywPatrolLine) {
        QueryWrapper<YwPatrolLine> wrapper = new QueryWrapper<>(ywPatrolLine);
        return ywPatrolLineMapper.selectOne(wrapper);
    }
 
    @Override
    public List<YwPatrolLine> findList(YwPatrolLine ywPatrolLine) {
        QueryWrapper<YwPatrolLine> wrapper = new QueryWrapper<>(ywPatrolLine);
        return ywPatrolLineMapper.selectList(wrapper);
    }
  
    @Override
    public PageData<YwPatrolLine> findPage(PageWrap<YwPatrolLine> pageWrap) {
        IPage<YwPatrolLine> page = new Page<>(pageWrap.getPage(), pageWrap.getCapacity());
        MPJLambdaWrapper<YwPatrolLine> queryWrapper = new MPJLambdaWrapper<YwPatrolLine>();
        Utils.MP.blankToNull(pageWrap.getModel());
        YwPatrolLine model = pageWrap.getModel();
        queryWrapper.selectAll(YwPatrolLine.class)
                .select(" ( select count(1) from  yw_line_point y where y.LINE_ID = yw_patrol_line.id ) as lineAmount ")
                .like(Objects.nonNull(model)&&StringUtils.isNotBlank(model.getName()),YwPatrolLine::getName,model.getName())
                .eq(YwPatrolLine::getIsdeleted,Constants.ZERO)
                .orderByDesc(YwPatrolLine::getCreateDate)
        ;
        IPage iPage = ywPatrolLineMapper.selectJoinPage(page,YwPatrolLine.class,queryWrapper);
        return PageData.from(iPage);
    }
 
    @Override
    public long count(YwPatrolLine ywPatrolLine) {
        QueryWrapper<YwPatrolLine> wrapper = new QueryWrapper<>(ywPatrolLine);
        return ywPatrolLineMapper.selectCount(wrapper);
    }
}