diff --git a/op-modules/op-mes/src/main/java/com/op/mes/controller/MesLineController.java b/op-modules/op-mes/src/main/java/com/op/mes/controller/MesLineController.java index 077b6a94..a36a6e88 100644 --- a/op-modules/op-mes/src/main/java/com/op/mes/controller/MesLineController.java +++ b/op-modules/op-mes/src/main/java/com/op/mes/controller/MesLineController.java @@ -1,9 +1,15 @@ package com.op.mes.controller; +import java.io.IOException; +import java.util.ArrayList; import java.util.List; +import javax.servlet.ServletOutputStream; import javax.servlet.http.HttpServletResponse; +import com.op.common.core.domain.ExcelCol; +import com.op.common.core.utils.poi.ExcelMapUtil; import com.op.mes.domain.MesLineProduct; +import org.apache.poi.xssf.streaming.SXSSFWorkbook; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.util.ObjectUtils; import org.springframework.web.bind.annotation.GetMapping; @@ -23,6 +29,7 @@ import com.op.common.core.web.controller.BaseController; import com.op.common.core.web.domain.AjaxResult; import com.op.common.core.utils.poi.ExcelUtil; import com.op.common.core.web.page.TableDataInfo; +import org.springframework.web.multipart.MultipartFile; /** * 线体管理Controller @@ -120,5 +127,52 @@ public class MesLineController extends BaseController { List list = mesLineService.getProductListBom(mesLineProduct); return getDataTable(list); } + + @PostMapping("/importTemplate") + @Log(title = "生成订单模板", businessType = BusinessType.EXPORT) + public void importTemplate(HttpServletResponse response) throws IOException { + + ArrayList excelCols = new ArrayList<>(); + excelCols.add(new ExcelCol("线体编码", "lineCode", 20)); + excelCols.add(new ExcelCol("产品编码", "productCode", 20)); + excelCols.add(new ExcelCol("产品名称", "productName", 20)); + excelCols.add(new ExcelCol("标准用人", "useMan", 20)); + excelCols.add(new ExcelCol("标准效率", "efficiency", 20)); + excelCols.add(new ExcelCol("标准工时", "attr1", 20)); + String titleName = "线体产品信息导入"; + SXSSFWorkbook workbook = null; + try { + //设置响应头 + response.setHeader("Content-disposition", + "attachment; filename=" + titleName); + response.setContentType("application/octet-stream;charset=UTF-8"); + ServletOutputStream outputStream = response.getOutputStream(); + //调用工具类 + workbook = ExcelMapUtil.initWorkbook(titleName, null, excelCols, null); + workbook.write(outputStream); + } catch (Exception e) { + e.printStackTrace(); + } finally { + if (workbook != null) { + workbook.dispose(); + } + } + } + /** + * 导入订单信息接口 + * + * @param file + * @return + * @throws Exception + */ + @Log(title = "导入线体产品信息", businessType = BusinessType.IMPORT) + @PostMapping("/importData") + public AjaxResult importData(MultipartFile file) throws Exception { + // 创建接收对象 + ExcelUtil util = new ExcelUtil<>(MesLine.class); + // 接收表格信息 + List orderList = util.importExcel(file.getInputStream()); + return mesLineService.importOrder(orderList); + } } diff --git a/op-modules/op-mes/src/main/java/com/op/mes/domain/MesLine.java b/op-modules/op-mes/src/main/java/com/op/mes/domain/MesLine.java index 88994fc3..96a59ba9 100644 --- a/op-modules/op-mes/src/main/java/com/op/mes/domain/MesLine.java +++ b/op-modules/op-mes/src/main/java/com/op/mes/domain/MesLine.java @@ -27,11 +27,13 @@ public class MesLine extends BaseEntity { */ @Excel(name = "线体编码") private String lineCode; - + @Excel(name = "产品编码") + private String productCode; + @Excel(name = "产品名称") + private String productName; /** * 线体名称 */ - @Excel(name = "线体名称") private String lineName; /** @@ -49,31 +51,27 @@ public class MesLine extends BaseEntity { /** * 检验工具 */ - @Excel(name = "检验工具") + @Excel(name = "标准工时") private String attr1; /** * $column.columnComment */ - @Excel(name = "${comment}", readConverterExp = "$column.readConverterExp()") private String attr2; /** * $column.columnComment */ - @Excel(name = "${comment}", readConverterExp = "$column.readConverterExp()") private String attr3; /** * 预留字段1 */ - @Excel(name = "预留字段1") private String attr4; /** * 工厂编码 */ - @Excel(name = "工厂编码") private String factoryCode; /** @@ -85,6 +83,22 @@ public class MesLine extends BaseEntity { private BigDecimal standarXl;//标准效率 private BigDecimal actXl;//实际效率 + public String getProductCode() { + return productCode; + } + + public void setProductCode(String productCode) { + this.productCode = productCode; + } + + public String getProductName() { + return productName; + } + + public void setProductName(String productName) { + this.productName = productName; + } + private List productList; public BigDecimal getStandarMan() { diff --git a/op-modules/op-mes/src/main/java/com/op/mes/mapper/MesLineMapper.java b/op-modules/op-mes/src/main/java/com/op/mes/mapper/MesLineMapper.java index 27e695d6..b6c32d7b 100644 --- a/op-modules/op-mes/src/main/java/com/op/mes/mapper/MesLineMapper.java +++ b/op-modules/op-mes/src/main/java/com/op/mes/mapper/MesLineMapper.java @@ -69,4 +69,10 @@ public interface MesLineMapper { public MesLine validate(MesLine mesLine); public List getProductListBom(MesLineProduct mesLineProduct); + + MesLine selectInfoByLineProduct(MesLine mesLine); + + void insertLineProduct(MesLine mesLine); + + void updateLineProduct(MesLine mesLine); } diff --git a/op-modules/op-mes/src/main/java/com/op/mes/service/IMesLineService.java b/op-modules/op-mes/src/main/java/com/op/mes/service/IMesLineService.java index fbca681e..bb8c111f 100644 --- a/op-modules/op-mes/src/main/java/com/op/mes/service/IMesLineService.java +++ b/op-modules/op-mes/src/main/java/com/op/mes/service/IMesLineService.java @@ -2,6 +2,7 @@ package com.op.mes.service; import java.util.List; +import com.op.common.core.web.domain.AjaxResult; import com.op.mes.domain.MesLine; import com.op.mes.domain.MesLineProduct; @@ -68,4 +69,6 @@ public interface IMesLineService { public MesLine validate(MesLine mesLine); public List getProductListBom(MesLineProduct productDto); + + AjaxResult importOrder(List orderList); } diff --git a/op-modules/op-mes/src/main/java/com/op/mes/service/impl/MesLineServiceImpl.java b/op-modules/op-mes/src/main/java/com/op/mes/service/impl/MesLineServiceImpl.java index 47b34aaa..7217382a 100644 --- a/op-modules/op-mes/src/main/java/com/op/mes/service/impl/MesLineServiceImpl.java +++ b/op-modules/op-mes/src/main/java/com/op/mes/service/impl/MesLineServiceImpl.java @@ -1,12 +1,16 @@ package com.op.mes.service.impl; import java.math.BigDecimal; +import java.util.Date; import java.util.List; import java.util.stream.Collectors; import com.baomidou.dynamic.datasource.annotation.DS; import com.op.common.core.utils.DateUtils; +import com.op.common.core.utils.ServletUtils; +import com.op.common.core.utils.StringUtils; 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.mes.domain.MesLineProcess; import com.op.mes.domain.MesLineProduct; @@ -25,6 +29,9 @@ import org.springframework.web.context.request.ServletRequestAttributes; import javax.servlet.http.HttpServletRequest; +import static com.op.common.core.web.domain.AjaxResult.error; +import static com.op.common.core.web.domain.AjaxResult.success; + /** * 线体管理Service业务层处理 * @@ -231,4 +238,98 @@ public class MesLineServiceImpl implements IMesLineService { public List getProductListBom(MesLineProduct mesLineProduct) { return mesLineMapper.getProductListBom(mesLineProduct); } + @Override + @DS("#header.poolName") + @Transactional + public AjaxResult importOrder(List mesLineList) { + + for(MesLine mesLineProduct:mesLineList){ + String factoryCode = ServletUtils.getRequest().getHeader("PoolName").replace("ds_",""); + mesLineProduct.setFactoryCode(factoryCode); + mesLineProduct.setCreateBy(SecurityUtils.getUsername()); + mesLineProduct.setCreateTime(DateUtils.getNowDate()); + } + + // 数据校验 + AjaxResult checkResult = checkImportOrder(mesLineList); + // 如果数据校验成功 + if (checkResult.isSuccess()) { + String info = syncImportFunc(mesLineList); + return success("信息导入完成。其中导入失败订单:"+info); + }else{ + return checkResult; + } + } + /** + * 校验导入订单信息 + * + * @param orderList + */ + public AjaxResult checkImportOrder(List orderList) { + + // 传入对象不能为空 + if (orderList.size() == 0 || StringUtils.isNull(orderList)) { + return error(500, "导入的订单信息不能为空!信息导入失败!"); + } + + // 循环遍历校验数据是否为空 + for (MesLine mesLine : orderList) { + + // 订单号 + if (mesLine.getLineCode().isEmpty() || mesLine.getLineCode() == null) { + return error(500, "线体不能为空!信息导入失败!"); + } + // 物料号 + if (mesLine.getProductCode().isEmpty() || mesLine.getProductCode() == null) { + return error(500, "产品编码不能为空!信息导入失败!"); + } + // 物料名称 + if (mesLine.getProductName().isEmpty() || mesLine.getProductName() == null) { + return error(500, "产品名称不能为空!信息导入失败!"); + } + // 订单数量 + if (mesLine.getUseMan() == 0 || mesLine.getUseMan() == null) { + return error(500, "标准用人不能为0或空!信息导入失败!"); + } + // 单位 + if (mesLine.getEfficiency() == null) { + return error(500, "标准效率不能为空!信息导入失败!"); + } + // 订单拆分状态 + if (mesLine.getAttr1().isEmpty() || mesLine.getAttr1() == null) { + return error(500, "标准工时不能为空!信息导入失败!"); + } + + } + return success(); + } + public String syncImportFunc(List mesLineList){ + String failOrder = ""; + for (MesLine mesLine:mesLineList) { + String msg = syncFunc(mesLine); + if(StringUtils.isNotBlank(msg)){ + failOrder += msg+","; + } + } + return failOrder; + } + + @Transactional(rollbackFor = Exception.class) + public String syncFunc(MesLine mesLine){ + String failOrder = ""; + //pro_order_workorder + Date nowDate = DateUtils.getNowDate(); + MesLine orderExit = mesLineMapper.selectInfoByLineProduct(mesLine); + if (orderExit==null) {//不存在就插入 + mesLine.setId(IdUtils.fastSimpleUUID()); + mesLine.setCreateTime(nowDate); + mesLineMapper.insertLineProduct(mesLine); + } else {//存在,如果没活动更新,否则不允许更新,关闭订单 + mesLine.setId(IdUtils.fastSimpleUUID()); + mesLine.setUpdateTime(nowDate); + mesLine.setUpdateBy(SecurityUtils.getUsername()); + mesLineMapper.updateLineProduct(mesLine); + } + return failOrder; + } } diff --git a/op-modules/op-mes/src/main/resources/mapper/mes/MesLineMapper.xml b/op-modules/op-mes/src/main/resources/mapper/mes/MesLineMapper.xml index ee671166..64ab6d24 100644 --- a/op-modules/op-mes/src/main/resources/mapper/mes/MesLineMapper.xml +++ b/op-modules/op-mes/src/main/resources/mapper/mes/MesLineMapper.xml @@ -20,47 +20,40 @@ + + - select id, line_code, line_name, use_man, efficiency, attr1, attr2, attr3, attr4, create_by, - create_time, update_by, update_time, factory_code, del_flag from mes_line + select id, line_code, product_code,product_name,use_man, efficiency, attr1, attr2, attr3, attr4, create_by, + create_time, update_by, update_time, factory_code, del_flag from mes_line_product @@ -166,5 +216,11 @@ '%') + diff --git a/op-modules/op-mes/src/main/resources/mapper/mes/MesReportWorkMapper.xml b/op-modules/op-mes/src/main/resources/mapper/mes/MesReportWorkMapper.xml index 3828ac70..12c2a398 100644 --- a/op-modules/op-mes/src/main/resources/mapper/mes/MesReportWorkMapper.xml +++ b/op-modules/op-mes/src/main/resources/mapper/mes/MesReportWorkMapper.xml @@ -668,28 +668,27 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"