|
|
@ -1,11 +1,20 @@ |
|
|
|
package com.win.module.mes.service.qmsqualitygroup; |
|
|
|
|
|
|
|
import cn.hutool.core.collection.CollUtil; |
|
|
|
import com.alibaba.fastjson.JSONObject; |
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
|
|
|
import com.win.framework.common.pojo.CustomConditions; |
|
|
|
import com.win.framework.mybatis.core.query.LambdaQueryWrapperX; |
|
|
|
import com.win.framework.mybatis.core.query.QueryWrapperX; |
|
|
|
import com.win.module.mes.controller.qmsqualitygroup.vo.*; |
|
|
|
|
|
|
|
import com.win.module.mes.dal.dataobject.qmsqualityclass.QmsQualityclassDO; |
|
|
|
import com.win.module.mes.dal.mysql.qmsqualityclass.QmsQualityclassMapper; |
|
|
|
import com.win.module.mes.enums.EnumUtils; |
|
|
|
import com.win.module.mes.enums.ErrorCodeConstants; |
|
|
|
import com.win.module.system.util.StringUtils; |
|
|
|
import org.springframework.stereotype.Service; |
|
|
|
|
|
|
|
import javax.annotation.Resource; |
|
|
|
|
|
|
|
import org.springframework.transaction.annotation.Transactional; |
|
|
@ -35,12 +44,13 @@ public class QmsQualitygroupServiceImpl implements QmsQualitygroupService { |
|
|
|
|
|
|
|
@Resource |
|
|
|
private QmsQualitygroupMapper qualitygroupMapper; |
|
|
|
|
|
|
|
@Resource |
|
|
|
private QmsQualityclassMapper qualityclassMapper; |
|
|
|
@Override |
|
|
|
public Integer createQualitygroup(QmsQualitygroupCreateReqVO createReqVO) { |
|
|
|
|
|
|
|
boolean falg = this.validateQmsQualitygroupCreate(createReqVO); |
|
|
|
if(!falg){ |
|
|
|
if (!falg) { |
|
|
|
throw exception(QUALITYGROUP_LIST_IS_EXIT); |
|
|
|
} |
|
|
|
// 插入
|
|
|
@ -54,7 +64,7 @@ public class QmsQualitygroupServiceImpl implements QmsQualitygroupService { |
|
|
|
private boolean validateQmsQualitygroupCreate(QmsQualitygroupCreateReqVO createReqVO) { |
|
|
|
boolean flag = true; |
|
|
|
List<QmsQualitygroupDO> qmsQualitygroupDOS = qualitygroupMapper.selectListByCode(createReqVO); |
|
|
|
if(qmsQualitygroupDOS.size() > 0){ |
|
|
|
if (qmsQualitygroupDOS.size() > 0) { |
|
|
|
flag = false; |
|
|
|
} |
|
|
|
return flag; |
|
|
@ -64,6 +74,10 @@ public class QmsQualitygroupServiceImpl implements QmsQualitygroupService { |
|
|
|
public Integer updateQualitygroup(QmsQualitygroupUpdateReqVO updateReqVO) { |
|
|
|
// 校验存在
|
|
|
|
validateQualitygroupExists(updateReqVO.getId()); |
|
|
|
if(updateReqVO.getStatus() == "2"){ |
|
|
|
//增加是否被引用的校验
|
|
|
|
validateQualitygroupUsed(updateReqVO.getCode()); |
|
|
|
} |
|
|
|
// 更新
|
|
|
|
QmsQualitygroupDO updateObj = QmsQualitygroupConvert.INSTANCE.convert(updateReqVO); |
|
|
|
return qualitygroupMapper.updateById(updateObj); |
|
|
@ -72,16 +86,36 @@ public class QmsQualitygroupServiceImpl implements QmsQualitygroupService { |
|
|
|
@Override |
|
|
|
public Integer deleteQualitygroup(Integer id) { |
|
|
|
// 校验存在
|
|
|
|
validateQualitygroupExists(id); |
|
|
|
QmsQualitygroupDO qmsQualitygroupDO = qualitygroupMapper.selectById(id); |
|
|
|
if(StringUtils.isNotNull(qmsQualitygroupDO)){ |
|
|
|
//增加是否被引用的校验
|
|
|
|
validateQualitygroupUsed(qmsQualitygroupDO.getCode()); |
|
|
|
// 删除
|
|
|
|
return qualitygroupMapper.deleteById(id); |
|
|
|
}else{ |
|
|
|
throw exception(QUALITYGROUP_IS_NOT_EXIST); |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
private void validateQualitygroupExists(Integer id) { |
|
|
|
if (qualitygroupMapper.selectById(id) == null) { |
|
|
|
//throw exception(QUALITYGROUP_NOT_EXISTS);
|
|
|
|
throw exception(QUALITYGROUP_IS_NOT_EXIST); |
|
|
|
} |
|
|
|
} |
|
|
|
/**验证是否被使用*/ |
|
|
|
private void validateQualitygroupUsed(String code) { |
|
|
|
LambdaQueryWrapperX<QmsQualityclassDO> queryWrapper = new LambdaQueryWrapperX<QmsQualityclassDO>(); |
|
|
|
queryWrapper.eq(QmsQualityclassDO::getGroupCode,code).eq(QmsQualityclassDO::getDeleted,"0"); |
|
|
|
if(StringUtils.isNotEmpty(qualityclassMapper.selectList(queryWrapper))){ |
|
|
|
throw exception(QUALITYGROUP_IS_INUSE); |
|
|
|
} |
|
|
|
} |
|
|
|
//add by zhousq 2024-05-24 增加导入时的数据校验
|
|
|
|
public QmsQualitygroupDO getQualitygroupByCode(String code) { |
|
|
|
|
|
|
|
return qualitygroupMapper.selectOne(QmsQualitygroupDO::getCode, code); |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public QmsQualitygroupDO getQualitygroup(Integer id) { |
|
|
@ -112,77 +146,83 @@ public class QmsQualitygroupServiceImpl implements QmsQualitygroupService { |
|
|
|
return qualitygroupMapper.selectSenior(conditions); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 导入时验证数据的必填内容 |
|
|
|
*/ |
|
|
|
private boolean validateRequried(QmsQualitygroupExcelVO data) { |
|
|
|
if (StringUtils.isEmpty(data.getCode()) || StringUtils.isEmpty(data.getName())) { |
|
|
|
return false; |
|
|
|
} else { |
|
|
|
return true; |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
///2024-05-24 导入优化
|
|
|
|
@Override |
|
|
|
@Transactional |
|
|
|
public List<QmsQualitygroupExcelVO> importQmsQualitygroupList(List<QmsQualitygroupExcelVO> datas, Integer mode, boolean updatePart) { |
|
|
|
if (CollUtil.isEmpty(datas)) { |
|
|
|
//数据预处理
|
|
|
|
if (StringUtils.isEmpty(datas)) { //导入数据不能为空
|
|
|
|
throw exception(QUALITYGROUP_IMPORT_LIST_IS_EMPTY); |
|
|
|
} |
|
|
|
|
|
|
|
List<QmsQualitygroupExcelVO> errorList = new ArrayList<>(); |
|
|
|
List<QmsQualitygroupDO> insertList = new ArrayList<>(); |
|
|
|
List<QmsQualitygroupDO> updateList = new ArrayList<>(); |
|
|
|
datas.forEach(item -> { |
|
|
|
boolean flag = true; |
|
|
|
|
|
|
|
//数据校验逻辑
|
|
|
|
|
|
|
|
//校验通过
|
|
|
|
if(flag){ |
|
|
|
QmsQualitygroupCreateReqVO qmsQualitygroupCreateReqVO = new QmsQualitygroupCreateReqVO(); |
|
|
|
qmsQualitygroupCreateReqVO.setCode(item.getCode()); |
|
|
|
// 判断如果不存在,在进行插入
|
|
|
|
List<QmsQualitygroupDO> qmsQualitygroupDOS = qualitygroupMapper.selectListByCode(qmsQualitygroupCreateReqVO); |
|
|
|
|
|
|
|
if (mode == 2) {//追加:只新增,不修改
|
|
|
|
if(qmsQualitygroupDOS.size()>0){ |
|
|
|
try { |
|
|
|
if (!validateRequried(item)) { // 数据项验证通过
|
|
|
|
//编码不存在
|
|
|
|
QmsQualitygroupExcelErrorVO qmsQualitygroupExcelErrorVO = new QmsQualitygroupExcelErrorVO(); |
|
|
|
qmsQualitygroupExcelErrorVO.setImportStatus("失败"); |
|
|
|
qmsQualitygroupExcelErrorVO.setImportRemark(QUALITYGROUP_LIST_IS_EXIT.getMsg()); |
|
|
|
qmsQualitygroupExcelErrorVO.setImportStatus("错误"); |
|
|
|
qmsQualitygroupExcelErrorVO.setImportRemark("编码、名称等关键数据项为空!" + JSONObject.toJSONString(item)); |
|
|
|
errorList.add(qmsQualitygroupExcelErrorVO); |
|
|
|
} else { |
|
|
|
//校验数据项是否存在
|
|
|
|
QmsQualitygroupDO udo = getQualitygroupByCode(item.getCode()); |
|
|
|
if (null == udo) { //不存在可以进行插入
|
|
|
|
if (mode == 1 || mode == 2) { |
|
|
|
QmsQualitygroupDO insert = QmsQualitygroupConvert.INSTANCE.convert(item); // 数据去重
|
|
|
|
if (insertList.stream().filter(find -> find.getCode().equals(insert.getCode())).findFirst().isEmpty()) { |
|
|
|
insertList.add(insert); |
|
|
|
}else{ |
|
|
|
qualitygroupMapper.insert(QmsQualitygroupConvert.INSTANCE.convert(item)); |
|
|
|
} |
|
|
|
} |
|
|
|
else if (mode == 3) {//覆盖:只修改不新增
|
|
|
|
if(CollectionUtils.isEmpty(qmsQualitygroupDOS)){ |
|
|
|
QmsQualitygroupExcelErrorVO qmsQualitygroupExcelErrorVO = new QmsQualitygroupExcelErrorVO(); |
|
|
|
qmsQualitygroupExcelErrorVO.setImportStatus("失败"); |
|
|
|
qmsQualitygroupExcelErrorVO.setImportRemark(QUALITYGROUP_IMPORT_LIST_IS_EMPTY.getMsg()); |
|
|
|
qmsQualitygroupExcelErrorVO.setImportStatus("错误"); |
|
|
|
qmsQualitygroupExcelErrorVO.setImportRemark("编码数据重复-编码" +item.getCode()); |
|
|
|
errorList.add(qmsQualitygroupExcelErrorVO); |
|
|
|
}else{ |
|
|
|
QmsQualitygroupDO updateObj = QmsQualitygroupConvert.INSTANCE.convert(item); |
|
|
|
updateObj.setId(qmsQualitygroupDOS.get(0).getId()); |
|
|
|
qualitygroupMapper.updateById(updateObj); |
|
|
|
} |
|
|
|
} |
|
|
|
else if (mode == 1){//更新:新增并修改
|
|
|
|
try{ |
|
|
|
if(CollectionUtils.isEmpty(qmsQualitygroupDOS)){ |
|
|
|
qualitygroupMapper.insert(QmsQualitygroupConvert.INSTANCE.convert(item)); |
|
|
|
}else if(qmsQualitygroupDOS.size()>0){ |
|
|
|
QmsQualitygroupDO updateObj = QmsQualitygroupConvert.INSTANCE.convert(item); |
|
|
|
updateObj.setId(qmsQualitygroupDOS.get(0).getId()); |
|
|
|
qualitygroupMapper.updateById(updateObj); |
|
|
|
} else { |
|
|
|
if (mode != 1) { |
|
|
|
QmsQualitygroupDO convert = QmsQualitygroupConvert.INSTANCE.convert(item); |
|
|
|
convert.setId(udo.getId()); |
|
|
|
updateList.add(convert); |
|
|
|
} |
|
|
|
}catch (Exception e){ |
|
|
|
QmsQualitygroupExcelErrorVO qmsQualitygroupExcelErrorVO = new QmsQualitygroupExcelErrorVO(); |
|
|
|
qmsQualitygroupExcelErrorVO.setImportStatus("失败"); |
|
|
|
qmsQualitygroupExcelErrorVO.setImportRemark(QUALITYCLASS_ERROR.getMsg()); |
|
|
|
errorList.add(qmsQualitygroupExcelErrorVO); |
|
|
|
} |
|
|
|
|
|
|
|
}else{ |
|
|
|
} |
|
|
|
} catch (Exception e) { |
|
|
|
//
|
|
|
|
QmsQualitygroupExcelErrorVO qmsQualitygroupExcelErrorVO = new QmsQualitygroupExcelErrorVO(); |
|
|
|
qmsQualitygroupExcelErrorVO.setImportStatus("失败"); |
|
|
|
qmsQualitygroupExcelErrorVO.setImportRemark(QUALITYCLASS_ERRORMODE.getMsg()); |
|
|
|
qmsQualitygroupExcelErrorVO.setImportStatus("错误"); |
|
|
|
qmsQualitygroupExcelErrorVO.setImportRemark("数据异常" + JSONObject.toJSONString(item)); |
|
|
|
errorList.add(qmsQualitygroupExcelErrorVO); |
|
|
|
} |
|
|
|
} |
|
|
|
}); |
|
|
|
|
|
|
|
if (!CollectionUtils.isEmpty(errorList)) { |
|
|
|
}); |
|
|
|
//错误不为空并非部分更新,手工回滚
|
|
|
|
if (!errorList.isEmpty() && !updatePart) { |
|
|
|
// 有数据错误,且不允许部分更新
|
|
|
|
TransactionAspectSupport.currentTransactionStatus().setRollbackOnly(); |
|
|
|
} else { |
|
|
|
//无错误或
|
|
|
|
//insert 的时候需要进行去重
|
|
|
|
qualitygroupMapper.insertBatch(insertList); |
|
|
|
if (StringUtils.isNotEmpty(updateList)) { |
|
|
|
qualitygroupMapper.updateBatch(updateList); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
return errorList; |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|