无关风月
2024-08-28 1c4311135628b53daa336821ff452292a9d063e9
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
package com.ruoyi.management.service.impl;
 
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ruoyi.common.core.utils.page.PageDTO;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.management.domain.SlEquipment;
import com.ruoyi.management.domain.SlGoodsMaterials;
import com.ruoyi.management.domain.SlStoreManagement;
import com.ruoyi.management.domain.dto.SlEquipmentDTO;
import com.ruoyi.management.domain.dto.SlEquipmentQuery;
import com.ruoyi.management.domain.vo.SlEquipmentVO;
import com.ruoyi.management.domain.vo.SlGoodsMaterialsVO;
import com.ruoyi.management.mapper.SlEquipmentMapper;
import com.ruoyi.management.mapper.SlStoreManagementMapper;
import com.ruoyi.management.service.SlEquipmentService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruoyi.system.api.domain.SeBei;
import org.springframework.stereotype.Service;
 
import javax.annotation.Resource;
import java.util.*;
 
/**
 * <p>
 * 设备管理 服务实现类
 * </p>
 *
 * @author hjl
 * @since 2024-06-25
 */
@Service
public class SlEquipmentServiceImpl extends ServiceImpl<SlEquipmentMapper, SlEquipment> implements SlEquipmentService {
 
    @Resource
    private SlStoreManagementMapper slStoreManagementMapper;
 
    @Override
    public PageDTO<SlEquipmentVO> getSlEquipmentList(SlEquipmentQuery slEquipmentQuery) {
        Page<SlEquipment> page = new Page<>(slEquipmentQuery.getPageCurr(), slEquipmentQuery.getPageSize());
        LambdaQueryWrapper< SlEquipment> wrapper= Wrappers.lambdaQuery();
        if(slEquipmentQuery.getEquipmentName()!=null&&slEquipmentQuery.getEquipmentName()!=""){
            wrapper.like(SlEquipment::getEquipmentName,slEquipmentQuery.getEquipmentName());
        }
        if(slEquipmentQuery.getType()!=null&&slEquipmentQuery.getType()!=0){
        wrapper.eq(SlEquipment::getType,slEquipmentQuery.getType());
        }
        wrapper.eq( SlEquipment::getDelFlag,0);
        wrapper.orderByDesc(SlEquipment::getCreateTime);
        Page<SlEquipment> page1 = this.page(page, wrapper);
        PageDTO<SlEquipmentVO> slEquipmentVOPageDTO = PageDTO.of(page1, SlEquipmentVO.class);
        List<SlEquipmentVO> list = slEquipmentVOPageDTO.getList();
        for (SlEquipmentVO sl:list){
            SlStoreManagement slStoreManagement = slStoreManagementMapper.selectById(sl.getManagementId());
            sl.setStoreManagementName(slStoreManagement.getStoreManagementName());
            sl.setCountyCode(slStoreManagement.getCountyCode());
            sl.setProvinceName(slStoreManagement.getProvinceName());
            sl.setProvinceCode(slStoreManagement.getProvinceCode());
            sl.setCountyName(slStoreManagement.getCountyName());
            sl.setCityCode(slStoreManagement.getCityCode());
            sl.setCityName(slStoreManagement.getCityName());
            sl.setTownName(slStoreManagement.getTownName());
            sl.setTownCode(slStoreManagement.getTownCode());
        }
        return slEquipmentVOPageDTO;
    }
 
    @Override
    public AjaxResult addSlEquipment(SlEquipmentDTO slEquipmentDTO) {
 
        if (slEquipmentDTO.getId()==null){
            List<SlEquipment> list = this.list(new QueryWrapper<SlEquipment>()
                    .eq("type", slEquipmentDTO.getType())
                            .eq("del_flag","0")
                    .eq("equipment_num", slEquipmentDTO.getEquipmentNum()));
            if (!list.isEmpty()){
                return AjaxResult.error("当前设备已存在相同设备编号");
            }
            SlEquipment slEquipment=new SlEquipment();
            slEquipment.setEquipmentName(slEquipmentDTO.getEquipmentName());
            slEquipment.setEquipmentNum(slEquipmentDTO.getEquipmentNum());
            slEquipment.setType(slEquipmentDTO.getType());
            slEquipment.setManagementId(slEquipmentDTO.getManagementId());
            slEquipment.setCreateTime(new Date());
            this.save(slEquipment);
        }else{
            SlEquipment byId = this.getById(slEquipmentDTO.getId());
            List<SlEquipment> list = this.list(new QueryWrapper<SlEquipment>()
                    .eq("type", slEquipmentDTO.getType())
                    .ne("id",slEquipmentDTO.getId())
                            .eq("del_flag","0")
                    .eq("equipment_num", slEquipmentDTO.getEquipmentNum()));
            if (!list.isEmpty()){
                return AjaxResult.error("当前设备已存在相同设备编号");
            }
            if (slEquipmentDTO.getEquipmentName()!=null){
                byId.setEquipmentName(slEquipmentDTO.getEquipmentName());
            }
            if (slEquipmentDTO.getEquipmentNum()!=null){
                byId.setEquipmentNum(slEquipmentDTO.getEquipmentNum());
            }
            if (slEquipmentDTO.getType()!=null){
                byId.setType(slEquipmentDTO.getType());
            }
            if (slEquipmentDTO.getManagementId()!=null){
                byId.setManagementId(slEquipmentDTO.getManagementId());
            }
            this.updateById(byId);
        }
        return AjaxResult.success();
    }
 
    @Override
    public SlEquipmentVO getSlEquipmentOne(SlEquipmentDTO slEquipmentDTO) {
        SlEquipment byId = this.getById(slEquipmentDTO.getId());
        SlEquipmentVO slEquipmentVO=new SlEquipmentVO();
        slEquipmentVO.setEquipmentName(byId.getEquipmentName());
        slEquipmentVO.setEquipmentNum(byId.getEquipmentNum());
        slEquipmentVO.setType(byId.getType());
        slEquipmentVO.setManagementId(byId.getManagementId());
 
        SlStoreManagement slStoreManagement = slStoreManagementMapper.selectById(byId.getManagementId());
        slEquipmentVO.setCountyCode(slStoreManagement.getCountyCode());
        slEquipmentVO.setStoreManagementName(slStoreManagement.getStoreManagementName());
        slEquipmentVO.setProvinceName(slStoreManagement.getProvinceName());
        slEquipmentVO.setProvinceCode(slStoreManagement.getProvinceCode());
        slEquipmentVO.setCountyName(slStoreManagement.getCountyName());
        slEquipmentVO.setCityCode(slStoreManagement.getCityCode());
        slEquipmentVO.setCityName(slStoreManagement.getCityName());
        slEquipmentVO.setTownName(slStoreManagement.getTownName());
        slEquipmentVO.setTownCode(slStoreManagement.getTownCode());
 
        return slEquipmentVO;
    }
 
    @Override
    public Integer getequipmente(SeBei seBei) {
        LambdaQueryWrapper< SlStoreManagement> wrapper= Wrappers.lambdaQuery();
 
        List<Long> arr=new ArrayList<>();
        wrapper.eq(SlStoreManagement::getDelFlag,0);
        List<SlStoreManagement> page = slStoreManagementMapper.selectList(wrapper);
        for (SlStoreManagement a:page){
            List<String> list = Arrays.asList(a.getAdministratorId().split(","));
            if (list.contains(seBei.getUserId().toString())){
                arr.add(a.getId());
            }
        }
        LambdaQueryWrapper< SlStoreManagement> wrapper1= Wrappers.lambdaQuery();
        wrapper1.eq(SlStoreManagement::getDelFlag,0);
        List<SlStoreManagement> page1 = slStoreManagementMapper.selectList(wrapper1);
        for (SlStoreManagement a1:page1){
            List<String> list = Arrays.asList(a1.getCompetentId().split(","));
            if (list.contains(seBei.getUserId().toString())){
                arr.add(a1.getId());
            }
        }
        LambdaQueryWrapper< SlStoreManagement> wrapper2= Wrappers.lambdaQuery();
        wrapper2.eq(SlStoreManagement::getDelFlag,0);
        List<SlStoreManagement> page2 = slStoreManagementMapper.selectList(wrapper2);
        for (SlStoreManagement a2:page2){
            List<String> list = Arrays.asList(a2.getDirectorId().split(","));
            if (list.contains(seBei.getUserId().toString())){
                arr.add(a2.getId());
            }
        }
        Set<Long> set = new HashSet<>(arr);
        arr.clear();
        arr.addAll(set);
 
        int i=1;
        for (Long arr1:arr){
            LambdaQueryWrapper< SlEquipment> wrapper3= Wrappers.lambdaQuery();
                wrapper3.eq(SlEquipment::getManagementId,arr1);
                wrapper3.eq(SlEquipment::getEquipmentNum,seBei.getSebei());
            wrapper3.eq( SlEquipment::getDelFlag,0);
            List<SlEquipment> page3 = this.list( wrapper3);
            if (page3.size()>0){
                i=2;
                break;
            }
 
        }
      return i;
    }
}