yangys
2024-03-28 23a939ed820ee32f9a4309f9c81b7bab5a566f30
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
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
package com.qianwen.smartman.modules.cps.service.impl;
 
import com.alibaba.excel.write.merge.AbstractMergeStrategy;
import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.core.toolkit.support.SFunction;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import java.lang.invoke.SerializedLambda;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Optional;
import java.util.stream.Collectors;
import com.qianwen.smartman.common.cache.RegionCache;
import com.qianwen.smartman.common.constant.CommonConstant;
import com.qianwen.smartman.common.constant.ExcelConstant;
import com.qianwen.smartman.common.enums.StatusType;
import com.qianwen.smartman.common.utils.MessageUtils;
import com.qianwen.smartman.common.utils.ValidatorUtils;
import com.qianwen.core.excel.util.ExcelUtil;
import com.qianwen.core.log.exception.ServiceException;
import com.qianwen.core.mp.service.impl.BladeServiceImpl;
import com.qianwen.core.mp.support.Condition;
import com.qianwen.core.mp.support.Query;
import com.qianwen.core.oss.model.BladeFile;
import com.qianwen.core.tool.utils.Func;
import com.qianwen.smartman.modules.cps.convert.MalfunctionTypeConvert;
import com.qianwen.smartman.modules.cps.convert.MalfunctionTypeRecordConvert;
import com.qianwen.smartman.modules.cps.entity.MalfunctionType;
import com.qianwen.smartman.modules.cps.excel.MalfunctionTypeImport;
import com.qianwen.smartman.modules.cps.mapper.MalfunctionTypeMapper;
import com.qianwen.smartman.modules.cps.service.IMalfunctionTypeService;
import com.qianwen.smartman.modules.cps.vo.MalfunctionTypeRecordVO;
import com.qianwen.smartman.modules.cps.vo.MalfunctionTypeVO;
import com.qianwen.smartman.modules.resource.builder.oss.OssBuilder;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;
 
@Service
/* loaded from: blade-api.jar:BOOT-INF/classes/org/springblade/modules/cps/service/impl/MalfunctionTypeServiceImpl.class */
public class MalfunctionTypeServiceImpl extends BladeServiceImpl<MalfunctionTypeMapper, MalfunctionType> implements IMalfunctionTypeService {
    private final OssBuilder ossBuilder;
 
    public MalfunctionTypeServiceImpl(final OssBuilder ossBuilder) {
        this.ossBuilder = ossBuilder;
    }
 
    @Override // org.springblade.modules.cps.service.IMalfunctionTypeService
    public MalfunctionTypeVO insert(MalfunctionTypeVO malfunctionTypeVO) {
        boolean id = (Func.isNotEmpty(malfunctionTypeVO.getId()) ? Boolean.TRUE : Boolean.FALSE).booleanValue();
        boolean result = checkUnableMalfunctionTypeVO(malfunctionTypeVO.getCode());
        if (!id && result) {
            throw new ServiceException(MessageUtils.message("cps.malfunction.type.stop.status", new Object[0]));
        }
        checkMalfunctionTypeVO(malfunctionTypeVO);
        MalfunctionType malfunctionType = MalfunctionTypeConvert.INSTANCE.convert(malfunctionTypeVO);
        saveOrUpdate(malfunctionType);
        return MalfunctionTypeConvert.INSTANCE.convert(malfunctionType);
    }
 
    @Override // org.springblade.modules.cps.service.IMalfunctionTypeService
    public Boolean deleteMalfunctionTypeByIdList(List<Long> malfunctionTypeIds, Integer type) {
        if (StatusType.REMOVE.getType().equals(type)) {
            return Boolean.valueOf(remove(Wrappers.<MalfunctionType>lambdaQuery().in(MalfunctionType::getId, malfunctionTypeIds))); 
            /*
            return Boolean.valueOf(remove((Wrapper) Wrappers.lambdaQuery().in((v0) -> {
                return v0.getId();
            }, malfunctionTypeIds)));*/
        }
        return Boolean.valueOf(changeStatus(malfunctionTypeIds, CommonConstant.DEACTIVATE));
    }
 
    @Override // org.springblade.modules.cps.service.IMalfunctionTypeService
    public IPage<MalfunctionTypeVO> listPage(Query query, String keyWord, Integer status) {
        IPage<MalfunctionType> page = page(Condition.getPage(query), Wrappers.<MalfunctionType>query()
                .lambda()
                .eq(MalfunctionType::getStatus, (status == null) ? CommonConstant.ENABLE : status)
                .likeRight(Func.isNotEmpty(keyWord), MalfunctionType::getName, keyWord)
                .or()
                .likeRight(Func.isNotEmpty(keyWord), MalfunctionType::getCode, keyWord)
                .orderByDesc(Arrays.asList(MalfunctionType::getCreateTime,  MalfunctionType::getId)));
        
        /*
        IPage<MalfunctionType> page = page(Condition.getPage(query), (Wrapper) ((LambdaQueryWrapper) ((LambdaQueryWrapper) Wrappers.query().lambda().eq((v0) -> {
            return v0.getStatus();
        }, status == null ? CommonConstant.ENABLE : status)).likeRight(Func.isNotEmpty(keyWord), (v0) -> {
            return v0.getName();
        }, keyWord).or()).likeRight(Func.isNotEmpty(keyWord), (v0) -> {
            return v0.getCode();
        }, keyWord).orderByDesc((v0) -> {
            return v0.getCreateTime();
        }, new SFunction[]{(v0) -> {
            return v0.getId();
        }}));*/
        return Optional.ofNullable(page).map(p -> {
            Page<MalfunctionTypeVO> page2 = new Page<>(p.getCurrent(), p.getSize(), p.getTotal());
            page2.setRecords(MalfunctionTypeConvert.INSTANCE.convert(p.getRecords()));
            return page2;
        }).orElse(new Page<>());
    }
 
    @Override // org.springblade.modules.cps.service.IMalfunctionTypeService
    public MalfunctionTypeVO detail(Long malfunctionTypeId) {
        MalfunctionType malfunctionType = (MalfunctionType) this.baseMapper.selectById(malfunctionTypeId);
        return MalfunctionTypeConvert.INSTANCE.convert(malfunctionType);
    }
 
    @Override // org.springblade.modules.cps.service.IMalfunctionTypeService
    public BladeFile importMalfunctionType(List<MalfunctionTypeImport> data) {
        if (Func.isEmpty(data)) {
            throw new ServiceException(MessageUtils.message("excel.import.data.can.not.be.null", new Object[0]));
        }
        if (data.size() > 200) {
            throw new ServiceException(MessageUtils.message("excel.import.size.failed", new Object[0]));
        }
        HashMap<String, Object> codeMap = new HashMap<>(16);
        List<MalfunctionType> malfunctionTypeList = list(Wrappers.<MalfunctionType>lambdaQuery().eq(MalfunctionType::getStatus, CommonConstant.ENABLE));
        if (Func.isNotEmpty(malfunctionTypeList)) {
            malfunctionTypeList.forEach(x -> {
                codeMap.put(x.getCode(), null);
            });
        }
        boolean flag = Boolean.TRUE.booleanValue();
        for (MalfunctionTypeImport malfunctionTypeImport : data) {
            checkImportMalfunctionType(malfunctionTypeImport, codeMap);
            if (Func.isNotEmpty(malfunctionTypeImport.getFailReason())) {
                flag = Boolean.FALSE.booleanValue();
            }
        }
        if (!flag) {
            MultipartFile multipartFile = ExcelUtil.exportFillTemplateToMultipartFile(ExcelConstant.DIRECTORY + "malfunctionTypeFailTemplate" + ExcelConstant.SUFFIX, MessageUtils.message("excel.import.failed.report.name", new Object[0]) + ExcelConstant.SUFFIX, "故障类型表", data.stream().filter(x2 -> {
                return Func.isNotEmpty(x2.getFailReason());
            }).collect(Collectors.toList()), null, null);
            return this.ossBuilder.tempTemplate().putFile(multipartFile.getOriginalFilename(), multipartFile);
        }
        data.forEach(x3 -> {
            MalfunctionType malfunctionType = MalfunctionTypeConvert.INSTANCE.convert(x3);
            saveOrUpdate(malfunctionType);
        });
        return null;
    }
 
    @Override // org.springblade.modules.cps.service.IMalfunctionTypeService
    public Boolean updateMalfunctionType(MalfunctionTypeVO malfunctionTypeVO) {
        checkMalfunctionTypeVO(malfunctionTypeVO);
        Long id = malfunctionTypeVO.getId();
        String name = malfunctionTypeVO.getName();
        String remark = malfunctionTypeVO.getRemark();
        return Boolean.valueOf(update(Wrappers.<MalfunctionType>lambdaUpdate()
                .set(Func.isNotBlank(name), MalfunctionType::getName, name)
                .set(MalfunctionType::getRemark, remark)
                .eq(MalfunctionType::getId, id)));
        /*
        return Boolean.valueOf(update((Wrapper) ((LambdaUpdateWrapper) ((LambdaUpdateWrapper) Wrappers.lambdaUpdate().set(Func.isNotBlank(name), (v0) -> {
            return v0.getName();
        }, name)).set((v0) -> {
            return v0.getRemark();
        }, remark)).eq((v0) -> {
            return v0.getId();
        }, id)));*/
    }
 
    @Override // org.springblade.modules.cps.service.IMalfunctionTypeService
    public List<MalfunctionTypeRecordVO> getCodeAndRecord() {
        List<MalfunctionType> list = list(Wrappers.<MalfunctionType>lambdaQuery()
                .eq(MalfunctionType::getStatus, CommonConstant.ENABLE)
                .orderByDesc(MalfunctionType::getCode));
        
        return MalfunctionTypeRecordConvert.INSTANCE.convert(list);
    }
 
    private void checkImportMalfunctionType(MalfunctionTypeImport malfunctionTypeImport, HashMap<String, Object> codeMap) {
        if (Func.isEmpty(malfunctionTypeImport.getCode())) {
            malfunctionTypeImport.setFailReason(MessageUtils.message("cps.malfunction.type.code.can.not.be.null", new Object[0]));
        } else if (codeMap.containsKey(malfunctionTypeImport.getCode())) {
            malfunctionTypeImport.setFailReason(MessageUtils.message("cps.malfunction.type.code.already.exists", new Object[0]));
        } else if (ValidatorUtils.checkContextLength(malfunctionTypeImport.getCode())) {
            malfunctionTypeImport.setFailReason(MessageUtils.message("cps.malfunction.type.code.can.not.exceed", new Object[0]));
        }
        boolean result = checkUnableMalfunctionTypeVO(malfunctionTypeImport.getCode());
        if (result) {
            malfunctionTypeImport.setFailReason(MessageUtils.message("cps.malfunction.type.stop.status", new Object[0]));
        }
        codeMap.put(malfunctionTypeImport.getCode(), null);
        if (Func.isEmpty(malfunctionTypeImport.getName())) {
            malfunctionTypeImport.setFailReason(MessageUtils.message("cps.malfunction.type.name.can.not.be.null", new Object[0]));
        } else if (ValidatorUtils.checkContextLength(malfunctionTypeImport.getName())) {
            malfunctionTypeImport.setFailReason(MessageUtils.message("cps.malfunction.type.name.can.not.exceed", new Object[0]));
        }
        if (Func.isNotEmpty(malfunctionTypeImport.getRemark()) && ValidatorUtils.checkContextLength(malfunctionTypeImport.getRemark())) {
            malfunctionTypeImport.setFailReason(MessageUtils.message("cps.malfunction.type.remark.can.not.exceed", new Object[0]));
        }
    }
 
    private boolean checkUnableMalfunctionTypeVO(String code) {
         MalfunctionType malfunctionType = getOne(Wrappers.<MalfunctionType>lambdaQuery().eq(MalfunctionType::getCode, code)
                 .eq(MalfunctionType::getStatus, CommonConstant.DEACTIVATE));
         /*
        MalfunctionType malfunctionType = (MalfunctionType) getOne((Wrapper) ((LambdaQueryWrapper) Wrappers.lambdaQuery().eq((v0) -> {
            return v0.getCode();
        }, code)).eq((v0) -> {
            return v0.getStatus();
        }, CommonConstant.DEACTIVATE));*/
        if (malfunctionType != null) {
            return Boolean.TRUE.booleanValue();
        }
        return Boolean.FALSE.booleanValue();
    }
 
    private void checkMalfunctionTypeVO(MalfunctionTypeVO malfunctionTypeVO) {
        Long count = Long.valueOf(count(Wrappers.<MalfunctionType>lambdaQuery()
                  .ne(Func.isNotEmpty(malfunctionTypeVO.getId()), MalfunctionType::getId, malfunctionTypeVO.getId())
                  .eq(MalfunctionType::getStatus, CommonConstant.ENABLE)
                  .eq(MalfunctionType::getCode, malfunctionTypeVO.getCode())));
        /*
        Long count = Long.valueOf(count((Wrapper) ((LambdaQueryWrapper) Wrappers.<MalfunctionType>lambdaQuery().ne(Func.isNotEmpty(malfunctionTypeVO.getId()), (v0) -> {
            return v0.getId();
        }, malfunctionTypeVO.getId()).eq((v0) -> {
            return v0.getStatus();
        }, CommonConstant.ENABLE)).eq((v0) -> {
            return v0.getCode();
        }, malfunctionTypeVO.getCode())));*/
        if (count.longValue() > 0) {
            throw new ServiceException(MessageUtils.message("cps.malfunction.type.code.already.exists", new Object[0]));
        }
    }
}