|
|
|
@ -1,6 +1,7 @@
|
|
|
|
|
package com.op.quality.service.impl;
|
|
|
|
|
|
|
|
|
|
import java.util.List;
|
|
|
|
|
import java.util.Optional;
|
|
|
|
|
|
|
|
|
|
import com.baomidou.dynamic.datasource.annotation.DS;
|
|
|
|
|
import com.op.common.core.exception.ServiceException;
|
|
|
|
@ -8,7 +9,10 @@ import com.op.common.core.utils.DateUtils;
|
|
|
|
|
import com.op.common.core.utils.StringUtils;
|
|
|
|
|
import com.op.common.core.utils.bean.BeanValidators;
|
|
|
|
|
import com.op.common.core.utils.uuid.IdUtils;
|
|
|
|
|
import com.op.common.core.web.domain.AjaxResult;
|
|
|
|
|
import com.op.common.security.utils.SecurityUtils;
|
|
|
|
|
import com.op.quality.domain.QcProjectType;
|
|
|
|
|
import com.op.quality.mapper.QcProjectTypeMapper;
|
|
|
|
|
import org.slf4j.Logger;
|
|
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
@ -24,6 +28,9 @@ import org.springframework.web.context.request.ServletRequestAttributes;
|
|
|
|
|
import javax.servlet.http.HttpServletRequest;
|
|
|
|
|
import javax.validation.Validator;
|
|
|
|
|
|
|
|
|
|
import static com.op.common.core.web.domain.AjaxResult.error;
|
|
|
|
|
import static com.op.common.core.web.domain.AjaxResult.success;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 检验项目维护Service业务层处理
|
|
|
|
|
*
|
|
|
|
@ -40,6 +47,9 @@ public class QcCheckProjectServiceImpl implements IQcCheckProjectService {
|
|
|
|
|
@Autowired
|
|
|
|
|
protected Validator validator;
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
private QcProjectTypeMapper qcProjectTypeMapper;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 查询检验项目维护
|
|
|
|
|
*
|
|
|
|
@ -127,7 +137,7 @@ public class QcCheckProjectServiceImpl implements IQcCheckProjectService {
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
@DS("#header.poolName")
|
|
|
|
|
public String importCheckProject(List<QcCheckProject> projectList, Boolean isUpdateSupport, String operName) {
|
|
|
|
|
public AjaxResult importCheckProject(List<QcCheckProject> projectList, Boolean isUpdateSupport, String operName) {
|
|
|
|
|
if (CollectionUtils.isEmpty(projectList)) {
|
|
|
|
|
throw new ServiceException("导入的检测项目数据为空!");
|
|
|
|
|
}
|
|
|
|
@ -139,6 +149,9 @@ public class QcCheckProjectServiceImpl implements IQcCheckProjectService {
|
|
|
|
|
HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
|
|
|
|
|
String key = "#header.poolName";
|
|
|
|
|
String factoryCode = request.getHeader(key.substring(8)).replace("ds_", "");
|
|
|
|
|
//校验数据
|
|
|
|
|
AjaxResult checkResult = checkImportProject(projectList);
|
|
|
|
|
if (checkResult.isSuccess()) {
|
|
|
|
|
for (QcCheckProject project : projectList) {
|
|
|
|
|
try {
|
|
|
|
|
QcCheckProject pro = qcCheckProjectMapper.selectCheckProjectByRuleName(project.getRuleName(), project.getProjectType());
|
|
|
|
@ -176,7 +189,9 @@ public class QcCheckProjectServiceImpl implements IQcCheckProjectService {
|
|
|
|
|
} else {
|
|
|
|
|
successMsg.insert(0, "恭喜您,数据已全部导入成功! 共" + successNum + " 条,数据如下:");
|
|
|
|
|
}
|
|
|
|
|
return successMsg.toString();
|
|
|
|
|
return success(successMsg.toString());
|
|
|
|
|
}
|
|
|
|
|
return checkResult;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private String getOrderNum() {
|
|
|
|
@ -187,4 +202,53 @@ public class QcCheckProjectServiceImpl implements IQcCheckProjectService {
|
|
|
|
|
orderNum = now + "0" + checkProject.getSerialNumber();
|
|
|
|
|
return orderNum;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public AjaxResult checkImportProject(List<QcCheckProject> qcCheckProjectList) {
|
|
|
|
|
if (CollectionUtils.isEmpty(qcCheckProjectList)) {
|
|
|
|
|
return error(500,"导入的订单信息不能为空!信息导入失败");
|
|
|
|
|
}
|
|
|
|
|
for (QcCheckProject project : qcCheckProjectList) {
|
|
|
|
|
if (StringUtils.isEmpty(project.getOrderNum())) {
|
|
|
|
|
return error(500,"检验规则编号不能为空,信息导入失败,请检查是否存在空数据项");
|
|
|
|
|
}
|
|
|
|
|
if (StringUtils.isEmpty(project.getRuleName())) {
|
|
|
|
|
return error(500,"检验规则名称不能为空,信息导入失败");
|
|
|
|
|
}
|
|
|
|
|
if (StringUtils.isEmpty(project.getPropertyCode())) {
|
|
|
|
|
return error(500,"检验规则属性不能为空,信息导入失败");
|
|
|
|
|
}
|
|
|
|
|
if (StringUtils.isEmpty(project.getProjectType())) {
|
|
|
|
|
return error(500,"检验方案类型不能为空,信息导入失败");
|
|
|
|
|
}else {
|
|
|
|
|
boolean flag = typeConverter(project);
|
|
|
|
|
if (!flag) {
|
|
|
|
|
String ruleName = project.getRuleName();
|
|
|
|
|
return error(500,"检验规则名称:"+ ruleName +"检验方案类型不规范,信息导入失败");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (project.getSort() == null) {
|
|
|
|
|
return error(500,"排序不能为空,信息导入失败");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return success();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 方案类型转换
|
|
|
|
|
*/
|
|
|
|
|
public boolean typeConverter(QcCheckProject project) {
|
|
|
|
|
String projectType = project.getProjectType();
|
|
|
|
|
List<QcProjectType> projectTypes = qcProjectTypeMapper.selectQcProjectTypeList(new QcProjectType());
|
|
|
|
|
//筛选出检验方案类型名称相同的项目
|
|
|
|
|
Optional<QcProjectType> matchedType = projectTypes.stream()
|
|
|
|
|
.filter(item -> projectType.equals(item.getProjectTypeName()))
|
|
|
|
|
.findFirst();
|
|
|
|
|
//使用code替换名称
|
|
|
|
|
if (matchedType.isPresent()) {
|
|
|
|
|
project.setProjectType(matchedType.get().getProjectTypeCode());
|
|
|
|
|
return true;
|
|
|
|
|
}else {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|