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]));
|
}
|
}
|
}
|