41525导入功能优化-校验并返回数据+枚举中文导入

tags/yfai-mes-ext-v1.0
gsz 11 months ago
parent 4326bbe286
commit aa6c6f58b3

@ -43,6 +43,9 @@ public interface IBaseMesService<T extends BaseBean> {
@ApiOperation(value = "校验导入数据", notes = "校验导入数据")
void validateImport(List<T> bean);
@ApiOperation(value = "校验并返回导入数据", notes = "校验并返回导入数据")
List<T> validateReturnImport(List<T> bean);
@ApiOperation(value = "修改信息", notes = "修改信息")
T update(T bean);

@ -459,6 +459,33 @@ public abstract class BaseMesController<T extends BaseBean> extends BaseControll
return ImppExceptionBuilder.newInstance().buildExceptionResult(e);
}
}
@PostMapping(value = "/import-ext")
@ApiOperation(value = "导入数据校验返回")
public ResultBean importExtExcel(@RequestParam("file") MultipartFile file) {
try {
MesExcelTool excelTool = new MesExcelTool(entityManager, RedisCacheTool.getImppRedis());
List<T> beanList = excelTool.importData(file.getOriginalFilename(), file.getInputStream(), mesClass);
// 校验导入数据
List<T> returnImport = baseService.validateReturnImport(beanList);
String userName = AuthUtil.getSessionUser().getUserName();
String organizeCode = AuthUtil.getOrganize().getOrganizeCode();
// 导入数据初始化
for (T bean : returnImport) {
ConvertBean.serviceModelInitialize(bean, userName);
bean.setOrganizeCode(organizeCode);
}
baseService.insertBatch(returnImport);
// 导入后
afterImport(returnImport);
return ResultBean.success("导入成功").setCode(ResourceEnumUtil.MESSAGE.SUCCESS.getCode());
} catch (ImppBusiException e) {
return ResultBean.fail(e);
} catch (Exception e) {
return ImppExceptionBuilder.newInstance().buildExceptionResult(e);
}
}
@GetMapping(value = "/down-template")
@ApiOperation(value = "下载导入模板")

@ -163,7 +163,12 @@ public abstract class BaseMesService<T extends BaseBean> implements IBaseMesServ
/* 新增数据校验 */
ValidatorBean.beginValid(beanList);
}
@Override
public List<T> validateReturnImport(List<T> beanList) {
/* 新增数据校验 */
ValidatorBean.beginValid(beanList);
return beanList;
}
protected void onInsertBean(T item) {
}

@ -5,10 +5,15 @@ import cn.estsh.i3plus.platform.common.exception.ImppExceptionEnum;
import cn.estsh.i3plus.pojo.base.bean.DdlPackBean;
import cn.estsh.i3plus.pojo.base.enumutil.CommonEnumUtil;
import cn.estsh.i3plus.pojo.base.tool.DdlPreparedPack;
import cn.estsh.i3plus.pojo.base.util.StringUtil;
import cn.estsh.i3plus.pojo.mes.bean.MesEquipmentSpotCheck;
import cn.estsh.i3plus.pojo.mes.bean.MesEquipmentSpotCheckDetail;
import cn.estsh.i3plus.pojo.mes.bean.MesEquipmentSpotCheckPart;
import cn.estsh.i3plus.pojo.mes.repository.MesEquipmentSpotCheckRepository;
import cn.estsh.impp.framework.boot.exception.ImppExceptionBuilder;
import cn.estsh.impp.framework.boot.util.ValidatorBean;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;
@ -17,6 +22,8 @@ import java.util.List;
@Slf4j
public class MesEquipmentSpotCheckDetailService extends BaseMesService<MesEquipmentSpotCheckDetail> implements IMesEquipmentSpotCheckDetailService {
@Autowired
private MesEquipmentSpotCheckRepository equipmentSpotCheckRepository;
protected void setPackQueryBean(MesEquipmentSpotCheckDetail bean, DdlPackBean packBean) {
DdlPreparedPack.getNumEqualPack(bean.getPid(), "pid", packBean);
DdlPreparedPack.getStringLikerPack(bean.getSpotCheckItemCode(), "spotCheckItemCode", packBean);
@ -82,5 +89,41 @@ public class MesEquipmentSpotCheckDetailService extends BaseMesService<MesEquipm
}
}
}
@Override
public List<MesEquipmentSpotCheckDetail> validateReturnImport(List<MesEquipmentSpotCheckDetail> beanList) {
for (MesEquipmentSpotCheckDetail item : beanList) {
// 数据校验
if(StringUtil.isEmpty(item.getPid())){
ValidatorBean.checkNotNull(item.getSpotCheckCode(), "点检项目代码不能为空");
ValidatorBean.checkNotNull(item.getSpotCheckItemCode(), "点检内容代码不能为空");
DdlPackBean seriesPackBean = DdlPackBean.getDdlPackBean(item.getOrganizeCode());
DdlPreparedPack.getStringEqualPack(item.getSpotCheckCode(), "spotCheckCode", seriesPackBean);
MesEquipmentSpotCheck itemFlg = equipmentSpotCheckRepository.getByProperty(seriesPackBean);
if (StringUtil.isEmpty(itemFlg)) {
throw ImppExceptionBuilder.newInstance()
.setSystemID(CommonEnumUtil.SOFT_TYPE.MES.getCode())
.setErrorCode(ImppExceptionEnum.VARIFY_EXCEPTION.getCode())
.setErrorDetail("【%s】点检项目代码不存在请检查数据", item.getSpotCheckCode())
.build();
}
item.setPid(itemFlg.getId());
}else {
ValidatorBean.checkNotNull(item.getId(), "点检项目id不能为空");
DdlPackBean seriesPackBean = DdlPackBean.getDdlPackBean(item.getOrganizeCode());
DdlPreparedPack.getNumNOEqualPack(item.getId(), "id", seriesPackBean);
if (!baseRDao.isExitByHql(seriesPackBean)) {
throw ImppExceptionBuilder.newInstance()
.setSystemID(CommonEnumUtil.SOFT_TYPE.MES.getCode())
.setErrorCode(ImppExceptionEnum.VARIFY_EXCEPTION.getCode())
.setErrorDetail("【%s】点检项目id不存在请检查数据", item.getPid())
.build();
}
}
}
return beanList;
}
}

@ -6,10 +6,13 @@ import cn.estsh.i3plus.pojo.base.bean.DdlPackBean;
import cn.estsh.i3plus.pojo.base.enumutil.CommonEnumUtil;
import cn.estsh.i3plus.pojo.base.tool.DdlPreparedPack;
import cn.estsh.i3plus.pojo.base.util.StringUtil;
import cn.estsh.i3plus.pojo.mes.bean.MesEquipmentSpotCheck;
import cn.estsh.i3plus.pojo.mes.bean.MesEquipmentSpotCheckPart;
import cn.estsh.i3plus.pojo.mes.repository.MesEquipmentSpotCheckRepository;
import cn.estsh.impp.framework.boot.exception.ImppExceptionBuilder;
import cn.estsh.impp.framework.boot.util.ValidatorBean;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;
@ -19,6 +22,8 @@ import java.util.List;
public class MesEquipmentSpotCheckPartService extends BaseMesService<MesEquipmentSpotCheckPart> implements IMesEquipmentSpotCheckPartService {
@Autowired
private MesEquipmentSpotCheckRepository equipmentSpotCheckRepository;
protected void setPackQueryBean(MesEquipmentSpotCheckPart bean, DdlPackBean packBean) {
DdlPreparedPack.getNumEqualPack(bean.getPid(), "pid", packBean);
DdlPreparedPack.getStringLikerPack(bean.getPartNo(), "partNo", packBean);
@ -58,4 +63,40 @@ public class MesEquipmentSpotCheckPartService extends BaseMesService<MesEquipmen
}
}
}
@Override
public List<MesEquipmentSpotCheckPart> validateReturnImport(List<MesEquipmentSpotCheckPart> beanList) {
for (MesEquipmentSpotCheckPart item : beanList) {
// 数据校验
if(StringUtil.isEmpty(item.getPid())){
ValidatorBean.checkNotNull(item.getSpotCheckCode(), "点检项目代码不能为空");
DdlPackBean seriesPackBean = DdlPackBean.getDdlPackBean(item.getOrganizeCode());
DdlPreparedPack.getStringEqualPack(item.getSpotCheckCode(), "spotCheckCode", seriesPackBean);
MesEquipmentSpotCheck itemFlg = equipmentSpotCheckRepository.getByProperty(seriesPackBean);
if (StringUtil.isEmpty(itemFlg)) {
throw ImppExceptionBuilder.newInstance()
.setSystemID(CommonEnumUtil.SOFT_TYPE.MES.getCode())
.setErrorCode(ImppExceptionEnum.VARIFY_EXCEPTION.getCode())
.setErrorDetail("【%s】点检项目代码不存在请检查数据", item.getSpotCheckCode())
.build();
}
item.setPid(itemFlg.getId());
}else {
ValidatorBean.checkNotNull(item.getId(), "点检项目id不能为空");
DdlPackBean seriesPackBean = DdlPackBean.getDdlPackBean(item.getOrganizeCode());
DdlPreparedPack.getNumNOEqualPack(item.getId(), "id", seriesPackBean);
if (!baseRDao.isExitByHql(seriesPackBean)) {
throw ImppExceptionBuilder.newInstance()
.setSystemID(CommonEnumUtil.SOFT_TYPE.MES.getCode())
.setErrorCode(ImppExceptionEnum.VARIFY_EXCEPTION.getCode())
.setErrorDetail("【%s】点检项目id不存在请检查数据", item.getPid())
.build();
}
}
}
return beanList;
}
}

Loading…
Cancel
Save