松下工位节拍PLC配置

tags/yfai-mes-ext-v1.0
yxw 1 year ago
parent 6681dd3ac0
commit 3af19e5765

@ -0,0 +1,64 @@
package cn.estsh.i3plus.ext.mes.api.base.jx;
import cn.estsh.i3plus.ext.mes.pojo.bean.SxWorkCellTaktCollectPlcCfg;
import cn.estsh.i3plus.pojo.base.bean.ListPager;
import cn.estsh.i3plus.pojo.base.common.Pager;
import io.swagger.annotations.ApiOperation;
/**
* @Description:MES_PLC
* @Reference:
* @Author: jessica.chen
* @CreateDate: 2019\11\13 13:56
* @Modify:
**/
public interface ISxWorkCellTaktCollectPlcCfgService {
/**
* MES_PLC
*
* @param mesManageCode PLC
* @return mesManageCode
*/
@ApiOperation(value = "添加MES_松下工位节拍PLC配置信息", notes = "传入MES_松下工位节拍PLC配置对象")
SxWorkCellTaktCollectPlcCfg insertSxWorkCellTaktCollectPlcCfg(SxWorkCellTaktCollectPlcCfg mesManageCode);
/**
* MES_PLC
*
* @param mesManageCode PLC
* @param userName
*/
@ApiOperation(value = "更新MES_松下工位节拍PLC配置", notes = "更新MES_松下工位节拍PLC配置")
void updateSxWorkCellTaktCollectPlcCfg(SxWorkCellTaktCollectPlcCfg mesManageCode, String userName);
/**
* MES_PLC
*
* @param mesManageCode PLC
* @param pager
* @return
*/
@ApiOperation(value = "按条件分页查询MES_松下工位节拍PLC配置信息", notes = "按条件分页查询MES_松下工位节拍PLC配置信息")
ListPager<SxWorkCellTaktCollectPlcCfg> querySxWorkCellTaktCollectPlcCfgByPager(SxWorkCellTaktCollectPlcCfg mesManageCode, Pager pager);
/**
*
*
* @param ids id
* @param userName
*/
@ApiOperation("软删扭矩管理信息")
int deleteWeaklySxWorkCellTaktCollectPlcCfgByIds(String[] ids, String userName);
/**
* /
*
* @param ids id
* @param status
* @param userName
* @return
*/
@ApiOperation(value = "批量禁用/启用详情")
int updateSxWorkCellTaktCollectPlcCfgStatus(String[] ids, int status, String userName);
}

@ -61,7 +61,6 @@ public class MesPartExtController {
.notNull(MesExtConstWords.PART_NO, part.getPartNo()) .notNull(MesExtConstWords.PART_NO, part.getPartNo())
.notNull(MesExtConstWords.PART_NAME, part.getPartName()) .notNull(MesExtConstWords.PART_NAME, part.getPartName())
.notNull(MesExtConstWords.CATEGORY_CODE1, part.getCategoryCode1()) .notNull(MesExtConstWords.CATEGORY_CODE1, part.getCategoryCode1())
.notNull(MesExtConstWords.PROCESS_MATCH_TYPE, part.getProcessMatchType())
.notNull(MesExtConstWords.PACKAGE_MATCH_TYPE, part.getPackageMatchType()) .notNull(MesExtConstWords.PACKAGE_MATCH_TYPE, part.getPackageMatchType())
.notNull(MesExtConstWords.IS_OQC, part.getIsOqc()) .notNull(MesExtConstWords.IS_OQC, part.getIsOqc())
.notNull(MesExtConstWords.IS_CREATE_SN, part.getIsCreateSn()) .notNull(MesExtConstWords.IS_CREATE_SN, part.getIsCreateSn())
@ -90,7 +89,6 @@ public class MesPartExtController {
.notNull(MesExtConstWords.PART_NO, part.getPartNo()) .notNull(MesExtConstWords.PART_NO, part.getPartNo())
.notNull(MesExtConstWords.PART_NAME, part.getPartName()) .notNull(MesExtConstWords.PART_NAME, part.getPartName())
.notNull(MesExtConstWords.CATEGORY_CODE1, part.getCategoryCode1()) .notNull(MesExtConstWords.CATEGORY_CODE1, part.getCategoryCode1())
.notNull(MesExtConstWords.PROCESS_MATCH_TYPE, part.getProcessMatchType())
.notNull(MesExtConstWords.PACKAGE_MATCH_TYPE, part.getPackageMatchType()) .notNull(MesExtConstWords.PACKAGE_MATCH_TYPE, part.getPackageMatchType())
.notNull(MesExtConstWords.IS_OQC, part.getIsOqc()) .notNull(MesExtConstWords.IS_OQC, part.getIsOqc())
.notNull(MesExtConstWords.IS_CREATE_SN, part.getIsCreateSn()) .notNull(MesExtConstWords.IS_CREATE_SN, part.getIsCreateSn())

@ -0,0 +1,119 @@
package cn.estsh.i3plus.ext.mes.apiservice.controller.base.jx;
import cn.estsh.i3plus.ext.mes.api.base.jx.ISxWorkCellTaktCollectPlcCfgService;
import cn.estsh.i3plus.ext.mes.pojo.bean.SxWorkCellTaktCollectPlcCfg;
import cn.estsh.i3plus.ext.mes.pojo.util.MesExtConstWords;
import cn.estsh.i3plus.platform.common.convert.ConvertBean;
import cn.estsh.i3plus.platform.common.util.CommonConstWords;
import cn.estsh.i3plus.pojo.base.common.Pager;
import cn.estsh.i3plus.pojo.base.enumutil.CommonEnumUtil;
import cn.estsh.i3plus.pojo.base.enumutil.ResourceEnumUtil;
import cn.estsh.i3plus.pojo.platform.bean.SessionUser;
import cn.estsh.impp.framework.boot.auth.AuthUtil;
import cn.estsh.impp.framework.boot.exception.ImppBusiException;
import cn.estsh.impp.framework.boot.exception.ImppExceptionBuilder;
import cn.estsh.impp.framework.boot.util.ResultBean;
import cn.estsh.impp.framework.boot.util.ValidatorBean;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
/**
* @Author: xinwang.yi
* @CreateDate: 2021/01/18 13:33
* @Description:
**/
@RestController
@Api(tags = "松下工位节拍PLC配置 控制层")
@RequestMapping(CommonConstWords.BASE_URL_MES + "/work-cell-takt")
public class SxWorkCellTaktCollectPlcCfgController {
public static final Logger LOGGER = LoggerFactory.getLogger(SxWorkCellTaktCollectPlcCfgController.class);
@Autowired
private ISxWorkCellTaktCollectPlcCfgService workCellTaktCollectPlcCfgService;
@PostMapping(value = "/insert")
@ApiOperation(value = "添加MES_松下工位节拍PLC配置信息")
public ResultBean insertSxWorkCellTaktCollectPlcCfg(SxWorkCellTaktCollectPlcCfg workCellTaktCollectPlcCfg) {
try {
//条件验证
ValidatorBean.beginValid(workCellTaktCollectPlcCfg)
.notNull(MesExtConstWords.WORK_CENTER_CODE,workCellTaktCollectPlcCfg.getWorkCenterCode())
.notNull(MesExtConstWords.WORK_CELL_CODE,workCellTaktCollectPlcCfg.getWorkCellCode())
.notNull(MesExtConstWords.PLC_CODE, workCellTaktCollectPlcCfg.getPlcCode())
.notNull(MesExtConstWords.STATUS, workCellTaktCollectPlcCfg.getStatus());
workCellTaktCollectPlcCfg.setOrganizeCode(AuthUtil.getOrganize().getOrganizeCode());
workCellTaktCollectPlcCfgService.insertSxWorkCellTaktCollectPlcCfg(workCellTaktCollectPlcCfg);
return ResultBean.success("添加成功").setCode(ResourceEnumUtil.MESSAGE.SUCCESS.getCode());
} catch (ImppBusiException imppException) {
LOGGER.error(imppException.getErrorMsg() + "{}", imppException.getErrorDetail(), imppException);
return ResultBean.fail(imppException);
} catch (Exception e) {
return ImppExceptionBuilder.newInstance().buildExceptionResult(e);
}
}
@PostMapping(value = "/update")
@ApiOperation(value = "更新MES_松下工位节拍PLC配置项目")
public ResultBean updateSxWorkCellTaktCollectPlcCfg(SxWorkCellTaktCollectPlcCfg workCellTaktCollectPlcCfg) {
try {
//条件验证
ValidatorBean.beginValid(workCellTaktCollectPlcCfg)
.notNull(MesExtConstWords.WORK_CENTER_CODE,workCellTaktCollectPlcCfg.getWorkCenterCode())
.notNull(MesExtConstWords.WORK_CELL_CODE,workCellTaktCollectPlcCfg.getWorkCellCode())
.notNull(MesExtConstWords.PLC_CODE, workCellTaktCollectPlcCfg.getPlcCode())
.notNull(MesExtConstWords.STATUS, workCellTaktCollectPlcCfg.getStatus());
if (workCellTaktCollectPlcCfg.getId() == null || workCellTaktCollectPlcCfg.getId().longValue() < 1) {
throw ImppExceptionBuilder.newInstance()
.setSystemID(CommonEnumUtil.SOFT_TYPE.MES.getCode())
.setErrorCode(cn.estsh.i3plus.platform.common.exception.ImppExceptionEnum.VARIFY_EXCEPTION.getCode())
.setErrorDetail("请选择需要操作的资源。")
.build();
}
workCellTaktCollectPlcCfgService.updateSxWorkCellTaktCollectPlcCfg(workCellTaktCollectPlcCfg, AuthUtil.getSessionUser().getUserName());
return ResultBean.success("修改成功").setCode(ResourceEnumUtil.MESSAGE.SUCCESS.getCode());
} catch (ImppBusiException busExcep) {
return ResultBean.fail(busExcep);
} catch (Exception e) {
return ImppExceptionBuilder.newInstance().buildExceptionResult(e);
}
}
@GetMapping(value = "/query")
@ApiOperation(value = "按条件分页查询MES_松下工位节拍PLC配置项目信息", notes = "按条件分页查询MES_松下工位节拍PLC配置项目信息")
public ResultBean querySxWorkCellTaktCollectPlcCfgByPager(SxWorkCellTaktCollectPlcCfg workCellTaktCollectPlcCfg, Pager pager) {
try {
workCellTaktCollectPlcCfg.setOrganizeCode(AuthUtil.getOrganize().getOrganizeCode());
return ResultBean.success().setListPager(workCellTaktCollectPlcCfgService.querySxWorkCellTaktCollectPlcCfgByPager(workCellTaktCollectPlcCfg, pager))
.setCode(ResourceEnumUtil.MESSAGE.SUCCESS.getCode());
} catch (ImppBusiException busExcep) {
return ResultBean.fail(busExcep);
} catch (Exception e) {
return ImppExceptionBuilder.newInstance().buildExceptionResult(e);
}
}
@PutMapping(value = "/update-status-batch")
@ApiOperation(value = "批量禁用/启用详情", notes = "批量禁用/启用详情")
public ResultBean updateSxWorkCellTaktCollectPlcCfgStatus(String[] ids, int status) {
try {
ConvertBean.modelSafeArrayNumber(ids, true);
//登陆用户
SessionUser user = AuthUtil.getSessionUser();
workCellTaktCollectPlcCfgService.updateSxWorkCellTaktCollectPlcCfgStatus(ids, status, user.getUserName());
return ResultBean.success("修改成功")
.setCode(ResourceEnumUtil.MESSAGE.SUCCESS.getCode());
} catch (ImppBusiException busExcep) {
return ResultBean.fail(busExcep);
} catch (Exception e) {
return ImppExceptionBuilder.newInstance().buildExceptionResult(e);
}
}
}

@ -0,0 +1,139 @@
package cn.estsh.i3plus.ext.mes.apiservice.serviceimpl.base.jx;
import cn.estsh.i3plus.ext.mes.api.base.jx.IManageCodeService;
import cn.estsh.i3plus.ext.mes.api.base.jx.ISxWorkCellTaktCollectPlcCfgService;
import cn.estsh.i3plus.ext.mes.pojo.bean.SxWorkCellTaktCollectPlcCfg;
import cn.estsh.i3plus.ext.mes.pojo.repository.SxWorkCellTaktCollectPlcCfgRepository;
import cn.estsh.i3plus.ext.mes.pojo.sqlpack.MesExtHqlPack;
import cn.estsh.i3plus.ext.mes.pojo.util.MesExtConstWords;
import cn.estsh.i3plus.ext.mes.pojo.util.MesExtEnumUtil;
import cn.estsh.i3plus.platform.common.convert.ConvertBean;
import cn.estsh.i3plus.platform.common.exception.ImppExceptionEnum;
import cn.estsh.i3plus.platform.common.tool.TimeTool;
import cn.estsh.i3plus.pojo.base.bean.DdlPackBean;
import cn.estsh.i3plus.pojo.base.bean.ListPager;
import cn.estsh.i3plus.pojo.base.common.Pager;
import cn.estsh.i3plus.pojo.base.common.PagerHelper;
import cn.estsh.i3plus.pojo.base.enumutil.CommonEnumUtil;
import cn.estsh.i3plus.pojo.base.tool.DdlPreparedPack;
import cn.estsh.i3plus.pojo.base.tool.HqlPack;
import cn.estsh.impp.framework.boot.auth.AuthUtil;
import cn.estsh.impp.framework.boot.exception.ImppExceptionBuilder;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;
/**
* @Author: xinwang.yi
* @CreateDate: 2023/10/09 11:41
* @Description:
**/
@Service
public class SxWorkCellTaktCollectPlcCfgService implements ISxWorkCellTaktCollectPlcCfgService {
@Autowired
private SxWorkCellTaktCollectPlcCfgRepository workCellTaktCollectPlcCfgRepository;
@Override
public SxWorkCellTaktCollectPlcCfg insertSxWorkCellTaktCollectPlcCfg(SxWorkCellTaktCollectPlcCfg sxWorkCellTaktCollectPlcCfg) {
//数据唯一性校验
DdlPackBean packBean = DdlPackBean.getDdlPackBean(sxWorkCellTaktCollectPlcCfg.getOrganizeCode());
DdlPreparedPack.getStringEqualPack(sxWorkCellTaktCollectPlcCfg.getOrganizeCode(), MesExtConstWords.ORGANIZE_CODE, packBean);
DdlPreparedPack.getStringEqualPack(sxWorkCellTaktCollectPlcCfg.getWorkCenterCode(), MesExtConstWords.WORK_CENTER_CODE, packBean);
DdlPreparedPack.getStringEqualPack(sxWorkCellTaktCollectPlcCfg.getWorkCellCode(), MesExtConstWords.WORK_CELL_CODE, packBean);
SxWorkCellTaktCollectPlcCfg sxWorkCellTaktCollectPlcCfgIsExist = workCellTaktCollectPlcCfgRepository.getByProperty(packBean);
if (sxWorkCellTaktCollectPlcCfgIsExist != null) {
throw ImppExceptionBuilder.newInstance()
.setSystemID(CommonEnumUtil.SOFT_TYPE.MES.getCode())
.setErrorCode(ImppExceptionEnum.VARIFY_EXCEPTION_DATA_EXIT.getCode())
.setErrorDetail("产线代码【%s】工位代码【%s】在工位节拍PLC配置信息中已存在状态为【%s】"
, sxWorkCellTaktCollectPlcCfgIsExist.getWorkCenterCode(), sxWorkCellTaktCollectPlcCfgIsExist.getWorkCellCode(), MesExtEnumUtil.IS_ENABLE.valueOfDescription(sxWorkCellTaktCollectPlcCfgIsExist.getStatus()))
.setErrorSolution("请更换新增参数")
.build();
}
ConvertBean.serviceModelInitialize(sxWorkCellTaktCollectPlcCfg, AuthUtil.getSessionUser().getUserName());
return workCellTaktCollectPlcCfgRepository.insert(sxWorkCellTaktCollectPlcCfg);
}
@Override
public void updateSxWorkCellTaktCollectPlcCfg(SxWorkCellTaktCollectPlcCfg sxWorkCellTaktCollectPlcCfg, String userName) {
SxWorkCellTaktCollectPlcCfg sxWorkCellTaktCollectPlcCfgDb = workCellTaktCollectPlcCfgRepository.getById(sxWorkCellTaktCollectPlcCfg.getId());
if (null == sxWorkCellTaktCollectPlcCfgDb)
throw ImppExceptionBuilder.newInstance()
.setSystemID(CommonEnumUtil.SOFT_TYPE.MES.getCode())
.setErrorCode(ImppExceptionEnum.VARIFY_EXCEPTION_DATA_NOT_EXIT.getCode())
.setErrorDetail("ID[%s]记录不存在", sxWorkCellTaktCollectPlcCfg.getId())
.build();
// 封装唯一校验查询条件
DdlPackBean packBean = DdlPackBean.getDdlPackBean(sxWorkCellTaktCollectPlcCfg.getOrganizeCode());
DdlPreparedPack.getStringEqualPack(sxWorkCellTaktCollectPlcCfg.getWorkCenterCode(), MesExtConstWords.WORK_CENTER_NAME, packBean);
DdlPreparedPack.getStringEqualPack(sxWorkCellTaktCollectPlcCfg.getWorkCellCode(), MesExtConstWords.WORK_CELL_CODE, packBean);
SxWorkCellTaktCollectPlcCfg sxWorkCellTaktCollectPlcCfgIsExist = workCellTaktCollectPlcCfgRepository.getByProperty(packBean);
if (null != sxWorkCellTaktCollectPlcCfgIsExist && sxWorkCellTaktCollectPlcCfgIsExist.getId().compareTo(sxWorkCellTaktCollectPlcCfgIsExist.getId()) != 0) {
throw ImppExceptionBuilder.newInstance()
.setSystemID(CommonEnumUtil.SOFT_TYPE.MES.getCode())
.setErrorCode(ImppExceptionEnum.VARIFY_EXCEPTION_DATA_EXIT.getCode())
.setErrorDetail("产线代码【%s】工位代码【%s】在在工位节拍PLC配置信息启用或禁用数据中已存在"
, sxWorkCellTaktCollectPlcCfg.getWorkCenterCode(), sxWorkCellTaktCollectPlcCfg.getWorkCellCode())
.setErrorSolution("请更换新增参数")
.build();
}
sxWorkCellTaktCollectPlcCfgDb.setWorkCenterCode(sxWorkCellTaktCollectPlcCfg.getWorkCenterCode());
sxWorkCellTaktCollectPlcCfgDb.setWorkCellCode(sxWorkCellTaktCollectPlcCfg.getWorkCellCode());
sxWorkCellTaktCollectPlcCfgDb.setPlcCode(sxWorkCellTaktCollectPlcCfg.getPlcCode());
sxWorkCellTaktCollectPlcCfgDb.setStatus(sxWorkCellTaktCollectPlcCfg.getStatus());
sxWorkCellTaktCollectPlcCfgDb.setSystemSyncStatus(MesExtEnumUtil.IF_SYNC_STATUS.NO_SYNC.getValue());
ConvertBean.serviceModelUpdate(sxWorkCellTaktCollectPlcCfg, userName);
workCellTaktCollectPlcCfgRepository.save(sxWorkCellTaktCollectPlcCfg);
}
@Override
public ListPager<SxWorkCellTaktCollectPlcCfg> querySxWorkCellTaktCollectPlcCfgByPager(SxWorkCellTaktCollectPlcCfg sxWorkCellTaktCollectPlcCfg, Pager pager) {
if (sxWorkCellTaktCollectPlcCfg == null) {
pager = PagerHelper.getPager(pager, workCellTaktCollectPlcCfgRepository.listCount());
return new ListPager(workCellTaktCollectPlcCfgRepository.listPager(pager), pager);
} else {
DdlPackBean hqlPack = MesExtHqlPack.getSxWorkCellTaktCollectPlcCfg(sxWorkCellTaktCollectPlcCfg);
hqlPack.setOrderByStr(sxWorkCellTaktCollectPlcCfg.orderBy());
pager = PagerHelper.getPager(pager, workCellTaktCollectPlcCfgRepository.findByHqlWhereCount(hqlPack));
List<SxWorkCellTaktCollectPlcCfg> byHqlWherePage = workCellTaktCollectPlcCfgRepository.findByHqlWherePage(hqlPack, pager);
return new ListPager(byHqlWherePage, pager);
}
}
@Override
public int deleteWeaklySxWorkCellTaktCollectPlcCfgByIds(String[] ids, String userName) {
StringBuffer wheres = new StringBuffer();
HqlPack.getInPack(String.join(",", ids), MesExtConstWords.ID, wheres);
int num = workCellTaktCollectPlcCfgRepository.updateByHqlWhere(
wheres.toString(),
new String[]{MesExtConstWords.SYSTEM_SYNC_STATUS, MesExtConstWords.IS_VALID, MesExtConstWords.MODIFY_USER, MesExtConstWords.MODIFY_DATE_TIME},
new Object[]{MesExtEnumUtil.IF_SYNC_STATUS.NO_SYNC.getValue(), CommonEnumUtil.TRUE_OR_FALSE.TRUE.getValue(), userName, TimeTool.getNowTime(true)}
);
return num;
}
@Override
public int updateSxWorkCellTaktCollectPlcCfgStatus(String[] ids, int status, String userName) {
StringBuffer wheres = new StringBuffer();
HqlPack.getInPack(String.join(",", ids), MesExtConstWords.ID, wheres);
int num = workCellTaktCollectPlcCfgRepository.updateByHqlWhere(
wheres.toString(),
new String[]{MesExtConstWords.SYSTEM_SYNC_STATUS, MesExtConstWords.IS_VALID, MesExtConstWords.MODIFY_USER, MesExtConstWords.MODIFY_DATE_TIME},
new Object[]{MesExtEnumUtil.IF_SYNC_STATUS.NO_SYNC.getValue(), status, userName, TimeTool.getNowTime(true)}
);
return num;
}
}

@ -0,0 +1,272 @@
package cn.estsh.i3plus.ext.mes.apiservice.serviceimpl.excel.jx;
import cn.estsh.i3plus.ext.mes.api.base.IExcelImportExtService;
import cn.estsh.i3plus.ext.mes.apiservice.serviceimpl.base.CommonExtService;
import cn.estsh.i3plus.ext.mes.pojo.bean.SxWorkCellTaktCollectPlcCfg;
import cn.estsh.i3plus.ext.mes.pojo.bean.MesWorkCenterExt;
import cn.estsh.i3plus.ext.mes.pojo.model.ExcelImportErrorExtModel;
import cn.estsh.i3plus.ext.mes.pojo.model.ExcelImportResultExtModel;
import cn.estsh.i3plus.ext.mes.pojo.repository.SxWorkCellTaktCollectPlcCfgRepository;
import cn.estsh.i3plus.ext.mes.pojo.repository.MesWorkCenterExtRepository;
import cn.estsh.i3plus.ext.mes.pojo.util.MesExtConstWords;
import cn.estsh.i3plus.ext.mes.pojo.util.MesExtEnumUtil;
import cn.estsh.i3plus.platform.common.convert.ConvertBean;
import cn.estsh.i3plus.platform.common.util.MesConstWords;
import cn.estsh.i3plus.pojo.base.enumutil.CommonEnumUtil;
import cn.estsh.i3plus.pojo.mes.bean.MesWorkCell;
import cn.estsh.i3plus.pojo.mes.repository.MesWorkCellRepository;
import org.apache.poi.ss.usermodel.CellType;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
import org.springframework.util.StringUtils;
import java.util.*;
import java.util.function.Function;
import java.util.stream.Collectors;
/**
* @Description : PLC
* @Reference :
* @Author : xinwang.yi
* @CreateDate : 2023-10-23
* @Modify:
**/
@Service
public class SxWorkCellTaktCollectPlcCfgExcelService implements IExcelImportExtService {
@Autowired
private SxWorkCellTaktCollectPlcCfgRepository sxWorkCellTaktCollectPlcCfgRepository;
@Autowired
private MesWorkCellRepository workCellRepository;
@Autowired
private CommonExtService commonExtService;
/**
* PLC
*
* @param workbook
* @param organizeCode
* @param userName
* @return
*/
@Override
public ExcelImportResultExtModel insertDataByExcel(Workbook workbook, String organizeCode, String userName) {
//读取表格
ExcelImportResultExtModel excelImportResultExtModel = this.sheetExtractSxWorkCellTaktCollectPlcCfg(workbook.getSheetAt(0), organizeCode, userName);
//数据入库
this.insertExcelSxWorkCellTaktCollectPlcCfg(excelImportResultExtModel);
return excelImportResultExtModel;
}
/**
* PLC-
*
* @param sheetAt
* @param organizeCode
* @param userName
* @return
*/
private ExcelImportResultExtModel sheetExtractSxWorkCellTaktCollectPlcCfg(Sheet sheetAt, String organizeCode, String userName) {
//从0行开始读取
int totalNumberOfRows = sheetAt.getLastRowNum() + 1;
//SxWorkCellTaktCollectPlcCfg集合
List<SxWorkCellTaktCollectPlcCfg> sxWorkCellTaktCollectPlcCfgList = new ArrayList<>();
//成功数量
Integer successRowNum = 0;
//失败数量
Integer failRowNum = 0;
//错误的行号
String errorRows = "";
//错误行信息集合
List<ExcelImportErrorExtModel> excelImportErrorExtModels = new ArrayList<>();
//用于EXCEL表中的 松下工位节拍PLC配置 唯一校验
Map<String, String> sxWorkCellTaktCollectPlcCfgByOnlyMap = new HashMap<>();
//根据松下工位节拍PLC配置 查询替代料中是否存在数据
List<SxWorkCellTaktCollectPlcCfg> sxWorkCellTaktCollectPlcCfgDbList = sxWorkCellTaktCollectPlcCfgRepository.findByProperty(
new String[]{MesConstWords.ORGANIZE_CODE, MesConstWords.IS_DELETED},
new Object[]{organizeCode, CommonEnumUtil.TRUE_OR_FALSE.FALSE.getValue()});
Map<String, SxWorkCellTaktCollectPlcCfg> sxWorkCellTaktCollectPlcCfgMap = CollectionUtils.isEmpty(sxWorkCellTaktCollectPlcCfgDbList) ? null :
sxWorkCellTaktCollectPlcCfgDbList.stream().filter(o -> null != o).collect(Collectors.toMap( o -> new StringJoiner(MesExtConstWords.AND).add(o.getWorkCenterCode()).add(o.getWorkCellCode()).toString(), Function.identity()));
//List<MesWorkCenterExt> workCenterList = workCenterExtRepository.findByProperty(
// new String[]{MesExtConstWords.ORGANIZE_CODE, MesExtConstWords.IS_DELETED, MesExtConstWords.IS_VALID},
// new Object[]{organizeCode, CommonEnumUtil.TRUE_OR_FALSE.FALSE.getValue(), CommonEnumUtil.IS_VAILD.VAILD.getValue()});
//Map<String, MesWorkCenterExt> workCenterCodeMap = CollectionUtils.isEmpty(workCenterList) ? null :
// workCenterList.stream().filter(o -> null != o).collect(Collectors.toMap(MesWorkCenterExt::getWorkCenterCode, Function.identity(), (x,y) -> y));
List<MesWorkCell> workCellList = workCellRepository.findByProperty(
new String[]{MesExtConstWords.ORGANIZE_CODE, MesExtConstWords.IS_DELETED, MesExtConstWords.IS_VALID},
new Object[]{organizeCode, CommonEnumUtil.TRUE_OR_FALSE.FALSE.getValue(), CommonEnumUtil.IS_VAILD.VAILD.getValue()});
Map<String, MesWorkCell> workCellMap = CollectionUtils.isEmpty(workCellList) ? null :
workCellList.stream().filter(o -> null != o).collect(Collectors.toMap(o -> new StringJoiner(MesExtConstWords.AND).add(o.getWorkCenterCode()).add(o.getWorkCellCode()).toString(), Function.identity(), (x,y) -> y));
//从excel表的第5行数据开始导入getFirstRowNum是从0行开始读取
for (int i = (sheetAt.getFirstRowNum() + 4); i < totalNumberOfRows; i++) {
Row row = sheetAt.getRow(i);
//空行跳过
if (null == row) {
continue;
}
//获取总列数
Short lastCellNum = row.getLastCellNum();
if (lastCellNum > 0) {
int rowNum = i + 1; //当前行号
int errorNum = 0; //错误数量
String cellNum = ""; //错误列号
String errorInfo = ""; //错误信息
//松下工位节拍PLC配置
try {
//第一列必须有值,否则跳过
row.getCell(0).setCellType(CellType.STRING);
} catch (Exception e) {
continue;
}
String workCenterCode = row.getCell(0, Row.MissingCellPolicy.CREATE_NULL_AS_BLANK).getStringCellValue().trim();
//产线代码
String workCellCode = null;
try {
row.getCell(1).setCellType(CellType.STRING);
workCellCode = row.getCell(1, Row.MissingCellPolicy.CREATE_NULL_AS_BLANK).getStringCellValue().trim();
} catch (Exception e) {
}
//PLC代码
String plcCode = null;
try {
row.getCell(2).setCellType(CellType.STRING);
plcCode = row.getCell(2, Row.MissingCellPolicy.CREATE_NULL_AS_BLANK).getStringCellValue().trim();
} catch (Exception e) {
}
//产线代码
String status = null;
try {
row.getCell(3).setCellType(CellType.STRING);
status = row.getCell(3, Row.MissingCellPolicy.CREATE_NULL_AS_BLANK).getStringCellValue().trim();
} catch (Exception e) {
}
//校验松下工位节拍PLC配置
if (StringUtils.isEmpty(workCenterCode)) {
errorNum++;
cellNum += "A;";
errorInfo += "第A列数据必填;";
}
//产线代码
if (StringUtils.isEmpty(workCellCode)) {
errorNum++;
cellNum += "B;";
errorInfo += "第B列数据必填;";
} else if (StringUtils.isEmpty(workCenterCode) || (CollectionUtils.isEmpty(workCellMap)) || (!workCellMap.containsKey(new StringJoiner(MesExtConstWords.AND).add(workCenterCode).add(workCellCode).toString()))){
errorNum++;
cellNum += "B;";
errorInfo += "第B列数据无效;";
}
if (StringUtils.isEmpty(plcCode)) {
errorNum++;
cellNum += "C;";
errorInfo += "第C列数据必填;";
}
if (!StringUtils.isEmpty(status) && MesExtEnumUtil.IS_ENABLE.descriptionOfValue(status) == null) {
errorNum++;
cellNum += "D;";
errorInfo += "第D列数据无效;";
}
String key = new StringJoiner(MesExtConstWords.AND).add(workCenterCode).add(workCellCode).toString();
Boolean isExist = false;
//校验唯一性 不重复
if (!sxWorkCellTaktCollectPlcCfgByOnlyMap.containsKey(key)) {
sxWorkCellTaktCollectPlcCfgByOnlyMap.put(key, String.valueOf(rowNum));
//根据松下工位节拍PLC配置查询替代信息中是否存在数据
//if (StringUtils.isEmpty(errorInfo) && !CollectionUtils.isEmpty(sxWorkCellTaktCollectPlcCfgMap) && sxWorkCellTaktCollectPlcCfgMap.containsKey(key)) {
// errorNum++;
// cellNum += "A;";
// errorInfo += "第A列数据已经存在数据库;";
//}
//校验是否已经存在数据库
if (StringUtils.isEmpty(errorInfo) && !CollectionUtils.isEmpty(sxWorkCellTaktCollectPlcCfgMap) && sxWorkCellTaktCollectPlcCfgMap.containsKey(key)) isExist = true;
} else {
errorNum++;
cellNum += "AB;";
errorInfo += "第AB列数据跟第" + sxWorkCellTaktCollectPlcCfgByOnlyMap.get(key) +
"行的第AB列数据重复;";
}
//没有错误的时候封装SxWorkCellTaktCollectPlcCfg
if (errorNum == 0) {
SxWorkCellTaktCollectPlcCfg sxWorkCellTaktCollectPlcCfg;
if (isExist) {
sxWorkCellTaktCollectPlcCfg = sxWorkCellTaktCollectPlcCfgMap.get(key);
ConvertBean.serviceModelUpdate(sxWorkCellTaktCollectPlcCfg, userName);
} else {
sxWorkCellTaktCollectPlcCfg = new SxWorkCellTaktCollectPlcCfg();
ConvertBean.serviceModelInitialize(sxWorkCellTaktCollectPlcCfg, userName);
sxWorkCellTaktCollectPlcCfg.setWorkCenterCode(workCenterCode);
sxWorkCellTaktCollectPlcCfg.setWorkCellCode(workCellCode);
}
sxWorkCellTaktCollectPlcCfg.setPlcCode(workCenterCode);
sxWorkCellTaktCollectPlcCfg.setStatus(StringUtils.isEmpty(status) ? MesExtEnumUtil.IS_ENABLE.ENABLE.getValue() : MesExtEnumUtil.IS_ENABLE.descriptionOfValue(status));
sxWorkCellTaktCollectPlcCfg.setSystemSyncStatus(MesExtEnumUtil.IF_SYNC_STATUS.NO_SYNC.getValue());
sxWorkCellTaktCollectPlcCfgList.add(sxWorkCellTaktCollectPlcCfg);
successRowNum++;
} else {
//封装错误行信息ExcelImportErrorExtModel
excelImportErrorExtModels = commonExtService.getExcelImportErrorModels(excelImportErrorExtModels, rowNum, errorNum, cellNum, errorInfo);
errorRows += rowNum + ";";
failRowNum++;
}
}
}
//校验EXCEL数据
commonExtService.checkExcelData(failRowNum, successRowNum, errorRows);
//封装返回结果
ExcelImportResultExtModel excelImportResultExtModel = commonExtService.getExcelImportResultModel(failRowNum, successRowNum, excelImportErrorExtModels, errorRows);
excelImportResultExtModel.setExcelList((failRowNum > 0) ? null : sxWorkCellTaktCollectPlcCfgList);
return excelImportResultExtModel;
}
/**
* PLC-
*
* @param excelImportResultExtModel
*/
private void insertExcelSxWorkCellTaktCollectPlcCfg(ExcelImportResultExtModel excelImportResultExtModel) {
//导入数据
if (null != excelImportResultExtModel) {
List<SxWorkCellTaktCollectPlcCfg> processTorqueManageList = excelImportResultExtModel.getExcelList();
if (!CollectionUtils.isEmpty(processTorqueManageList)) sxWorkCellTaktCollectPlcCfgRepository.saveAll(processTorqueManageList);
}
}
}

@ -936,5 +936,17 @@ public class MesExtHqlPack {
return packBean; return packBean;
} }
public static DdlPackBean getSxWorkCellTaktCollectPlcCfg(SxWorkCellTaktCollectPlcCfg workCellTaktCollectPlcCfg) {
DdlPackBean packBean = getAllBaseDataByNormalPro(workCellTaktCollectPlcCfg, workCellTaktCollectPlcCfg.getOrganizeCode());
DdlPreparedPack.getStringLikerPack(workCellTaktCollectPlcCfg.getWorkCenterCode(), MesExtConstWords.WORK_CENTER_CODE, packBean);
DdlPreparedPack.getStringLikerPack(workCellTaktCollectPlcCfg.getWorkCellCode(), MesExtConstWords.WORK_CELL_CODE, packBean);
DdlPreparedPack.getNumEqualPack(workCellTaktCollectPlcCfg.getPlcCode(), MesExtConstWords.PLC_CODE, packBean);
DdlPreparedPack.getNumEqualPack(workCellTaktCollectPlcCfg.getStatus(), MesExtConstWords.STATUS, packBean);
if (!StringUtils.isEmpty(workCellTaktCollectPlcCfg.getModifyDateTimeStart()) || !StringUtils.isEmpty(workCellTaktCollectPlcCfg.getModifyDateTimeEnd())) {
DdlPreparedPack.timeBuilder(workCellTaktCollectPlcCfg.getModifyDateTimeStart(), workCellTaktCollectPlcCfg.getModifyDateTimeEnd(), MesExtConstWords.MODIFY_DATE_TIME, packBean, true);
}
return packBean;
}
} }

@ -89,7 +89,10 @@ public class MesExtEnumUtil {
MES_JX_BADNESS_CLASSIFY_DETAIL(970, "jxBadnessClassifyDetailExcelService", "JX不良分类明细"), MES_JX_BADNESS_CLASSIFY_DETAIL(970, "jxBadnessClassifyDetailExcelService", "JX不良分类明细"),
MES_WORK_CELL_EXT(980, "workCellExtExcelService", "工位信息导入"), MES_WORK_CELL_EXT(980, "workCellExtExcelService", "工位信息导入"),
REPAIR_JUDGE_TYPE(990, "repairJudgeTypeExcelService", "返修判定类型导入"), REPAIR_JUDGE_TYPE(990, "repairJudgeTypeExcelService", "返修判定类型导入"),
MES_TIME_SEGMENT_STATISTICS(1000, "jxTimeSegmentStatisticsExcelService", "分时段统计方式导入"); MES_TIME_SEGMENT_STATISTICS(1000, "jxTimeSegmentStatisticsExcelService", "分时段统计方式导入"),
MES_JX_WORK_CELL_TAKT_COLLECT_PLC_CFG(1010, "sxWorkCellTaktCollectPlcCfgExcelService", "松下工位节拍PLC配置导入");
private int value; private int value;
private String service; private String service;

Loading…
Cancel
Save