From fe49dcaa8e941e06912f2a204c7530299793e8e5 Mon Sep 17 00:00:00 2001 From: zhaoxiaolin Date: Fri, 28 Jun 2024 10:45:12 +0800 Subject: [PATCH] =?UTF-8?q?=E8=B4=A8=E6=A3=80=E7=89=A9=E6=96=99=E7=BB=84?= =?UTF-8?q?=EF=BC=8C=E7=89=A9=E6=96=99=E4=BF=A1=E6=81=AF=E5=AF=BC=E5=85=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../QcCheckTypeProjectController.java | 86 +++++++++++++++- .../quality/domain/QcMaterialGroupDetail.java | 13 ++- .../mapper/QcCheckTypeProjectMapper.java | 7 +- .../quality/mapper/QcMaterialGroupMapper.java | 2 + .../service/IQcCheckTypeProjectService.java | 4 + .../impl/QcCheckTypeProjectServiceImpl.java | 97 +++++++++++++++++++ .../quality/QcCheckTypeProjectMapper.xml | 4 + .../mapper/quality/QcMaterialGroupMapper.xml | 3 + 8 files changed, 207 insertions(+), 9 deletions(-) diff --git a/op-modules/op-quality/src/main/java/com/op/quality/controller/QcCheckTypeProjectController.java b/op-modules/op-quality/src/main/java/com/op/quality/controller/QcCheckTypeProjectController.java index fbbf3fdc..4e633d8c 100644 --- a/op-modules/op-quality/src/main/java/com/op/quality/controller/QcCheckTypeProjectController.java +++ b/op-modules/op-quality/src/main/java/com/op/quality/controller/QcCheckTypeProjectController.java @@ -1,12 +1,16 @@ package com.op.quality.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.quality.domain.QcCheckProject; -import com.op.quality.domain.QcMaterialGroup; -import com.op.quality.domain.QcProjectType; +import com.op.common.core.domain.ExcelCol; +import com.op.common.core.utils.poi.ExcelMapUtil; +import com.op.quality.domain.*; import com.op.quality.service.IQcMaterialGroupService; +import org.apache.poi.xssf.streaming.SXSSFWorkbook; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PostMapping; @@ -19,12 +23,12 @@ import org.springframework.web.bind.annotation.RestController; import com.op.common.log.annotation.Log; import com.op.common.log.enums.BusinessType; import com.op.common.security.annotation.RequiresPermissions; -import com.op.quality.domain.QcCheckTypeProject; import com.op.quality.service.IQcCheckTypeProjectService; 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 @@ -127,4 +131,78 @@ public class QcCheckTypeProjectController extends BaseController { List list = qcCheckTypeProjectService.getProjectOptions(qcCheckProject); return 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(); + } + } + } + + @PostMapping("/importMaterailTemplate") + public void importMaterailTemplate(HttpServletResponse response) throws IOException { + + ArrayList excelCols = new ArrayList<>(); + excelCols.add(new ExcelCol("质检物料组名称", "groupName", 50)); + excelCols.add(new ExcelCol("物料编码", "materialCode", 50)); + excelCols.add(new ExcelCol("物料名称", "materialName", 50)); + 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<>(QcMaterialGroupDetail.class); + // 接收表格信息 + List orderList = util.importExcel(file.getInputStream()); + return qcCheckTypeProjectService.importOrder(orderList); + } } diff --git a/op-modules/op-quality/src/main/java/com/op/quality/domain/QcMaterialGroupDetail.java b/op-modules/op-quality/src/main/java/com/op/quality/domain/QcMaterialGroupDetail.java index dbdce17d..be24f61f 100644 --- a/op-modules/op-quality/src/main/java/com/op/quality/domain/QcMaterialGroupDetail.java +++ b/op-modules/op-quality/src/main/java/com/op/quality/domain/QcMaterialGroupDetail.java @@ -26,10 +26,13 @@ public class QcMaterialGroupDetail extends BaseEntity { private String groupId; //物料组编码 private String groupCode; + //物料组名称 + @Excel(name = "质检物料组名称") + private String groupName; /** * 物料号 */ - @Excel(name = "物料号") + @Excel(name = "物料编码") private String materialCode; /** @@ -50,6 +53,14 @@ public class QcMaterialGroupDetail extends BaseEntity { @Excel(name = "工厂编码") private String factoryCode; + public String getGroupName() { + return groupName; + } + + public void setGroupName(String groupName) { + this.groupName = groupName; + } + /** * 删除标识1删除0正常 */ diff --git a/op-modules/op-quality/src/main/java/com/op/quality/mapper/QcCheckTypeProjectMapper.java b/op-modules/op-quality/src/main/java/com/op/quality/mapper/QcCheckTypeProjectMapper.java index a858713c..4975b703 100644 --- a/op-modules/op-quality/src/main/java/com/op/quality/mapper/QcCheckTypeProjectMapper.java +++ b/op-modules/op-quality/src/main/java/com/op/quality/mapper/QcCheckTypeProjectMapper.java @@ -3,10 +3,7 @@ package com.op.quality.mapper; import java.util.List; import java.util.Map; -import com.op.quality.domain.QcCheckProject; -import com.op.quality.domain.QcCheckTaskDetail; -import com.op.quality.domain.QcCheckTypeProject; -import com.op.quality.domain.QcProjectType; +import com.op.quality.domain.*; import com.op.system.api.domain.SysDictData; import org.apache.ibatis.annotations.MapKey; import org.apache.ibatis.annotations.Mapper; @@ -84,4 +81,6 @@ public interface QcCheckTypeProjectMapper { List getProjectOptions(QcCheckProject qcCheckProject); QcProjectType getProductGroup(String materialCode); + + QcMaterialGroupDetail selectExist(QcMaterialGroupDetail materialGroupDetail); } diff --git a/op-modules/op-quality/src/main/java/com/op/quality/mapper/QcMaterialGroupMapper.java b/op-modules/op-quality/src/main/java/com/op/quality/mapper/QcMaterialGroupMapper.java index 60419adf..112a74f9 100644 --- a/op-modules/op-quality/src/main/java/com/op/quality/mapper/QcMaterialGroupMapper.java +++ b/op-modules/op-quality/src/main/java/com/op/quality/mapper/QcMaterialGroupMapper.java @@ -66,4 +66,6 @@ public interface QcMaterialGroupMapper { public List getMaterialChildrenList(QcMaterialGroup qcMaterialGroup); public List validationData(String id); + + String selectGroupIdByName(String groupName); } diff --git a/op-modules/op-quality/src/main/java/com/op/quality/service/IQcCheckTypeProjectService.java b/op-modules/op-quality/src/main/java/com/op/quality/service/IQcCheckTypeProjectService.java index bd2d0e4e..d846e749 100644 --- a/op-modules/op-quality/src/main/java/com/op/quality/service/IQcCheckTypeProjectService.java +++ b/op-modules/op-quality/src/main/java/com/op/quality/service/IQcCheckTypeProjectService.java @@ -2,8 +2,10 @@ package com.op.quality.service; import java.util.List; +import com.op.common.core.web.domain.AjaxResult; import com.op.quality.domain.QcCheckProject; import com.op.quality.domain.QcCheckTypeProject; +import com.op.quality.domain.QcMaterialGroupDetail; import com.op.quality.domain.QcProjectType; /** @@ -71,4 +73,6 @@ public interface IQcCheckTypeProjectService { int submitProjects(List typeProjects); List getProjectOptions(QcCheckProject qcCheckProject); + + AjaxResult importOrder(List orderList); } diff --git a/op-modules/op-quality/src/main/java/com/op/quality/service/impl/QcCheckTypeProjectServiceImpl.java b/op-modules/op-quality/src/main/java/com/op/quality/service/impl/QcCheckTypeProjectServiceImpl.java index 02ddc356..e851b40a 100644 --- a/op-modules/op-quality/src/main/java/com/op/quality/service/impl/QcCheckTypeProjectServiceImpl.java +++ b/op-modules/op-quality/src/main/java/com/op/quality/service/impl/QcCheckTypeProjectServiceImpl.java @@ -7,10 +7,15 @@ import java.util.Map; import com.baomidou.dynamic.datasource.annotation.DS; import com.baomidou.dynamic.datasource.toolkit.DynamicDataSourceContextHolder; import com.op.common.core.utils.DateUtils; +import com.op.common.core.utils.ServletUtils; 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.QcCheckProject; +import com.op.quality.domain.QcMaterialGroupDetail; import com.op.quality.domain.QcProjectType; +import com.op.quality.mapper.QcMaterialGroupDetailMapper; +import com.op.quality.mapper.QcMaterialGroupMapper; import com.op.system.api.domain.SysDictData; import org.apache.commons.lang.StringUtils; import org.springframework.beans.factory.annotation.Autowired; @@ -18,11 +23,15 @@ import org.springframework.stereotype.Service; import com.op.quality.mapper.QcCheckTypeProjectMapper; import com.op.quality.domain.QcCheckTypeProject; import com.op.quality.service.IQcCheckTypeProjectService; +import org.springframework.transaction.annotation.Transactional; import org.springframework.web.context.request.RequestContextHolder; 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业务层处理 * @@ -34,6 +43,12 @@ public class QcCheckTypeProjectServiceImpl implements IQcCheckTypeProjectService @Autowired private QcCheckTypeProjectMapper qcCheckTypeProjectMapper; + @Autowired + private QcMaterialGroupDetailMapper qcMaterialGroupDetailMapper; + + @Autowired + private QcMaterialGroupMapper qcMaterialGroupMapper; + /** * 查询物料检验项目维护 * @@ -162,5 +177,87 @@ public class QcCheckTypeProjectServiceImpl implements IQcCheckTypeProjectService return qcCheckTypeProjectMapper.getProjectOptions(qcCheckProject); } + @Override + @DS("#header.poolName") + @Transactional + public AjaxResult importOrder(List mgDetails) { + String GroupId = qcMaterialGroupMapper.selectGroupIdByName(mgDetails.get(0).getGroupName()); + + if(StringUtils.isBlank(GroupId)){ + return error("没有找到对应的质检物料组"); + } + + for(QcMaterialGroupDetail mgDetail:mgDetails){ + String factoryCode = ServletUtils.getRequest().getHeader("PoolName").replace("ds_",""); + mgDetail.setFactoryCode(factoryCode); + mgDetail.setCreateBy(SecurityUtils.getUsername()); + mgDetail.setCreateTime(DateUtils.getNowDate()); + mgDetail.setGroupId(GroupId); + } + + // 数据校验 + AjaxResult checkResult = checkImportOrder(mgDetails); + // 如果数据校验成功 + if (checkResult.isSuccess()) { + String info = syncImportFunc(mgDetails); + return success("信息导入完成。其中导入失败订单:"+info); + }else{ + return checkResult; + } + } + /** + * 校验导入订单信息 + * + * @param mgDetails + */ + public AjaxResult checkImportOrder(List mgDetails) { + + // 传入对象不能为空 + if (mgDetails.size() == 0 || com.op.common.core.utils.StringUtils.isNull(mgDetails)) { + return error(500, "信息不能为空!信息导入失败!"); + } + + // 循环遍历校验数据是否为空 + for (QcMaterialGroupDetail mesLine : mgDetails) { + + // 物料组名称 + if (!StringUtils.isNotBlank(mesLine.getGroupName())) { + return error(500, "物料组名称不能为空!信息导入失败!"); + } + // 物料号 + if (!StringUtils.isNotBlank(mesLine.getMaterialCode())) { + return error(500, "物料编码不能为空!信息导入失败!"); + } + // 物料名称 + if (!StringUtils.isNotBlank(mesLine.getMaterialName())) { + return error(500, "物料名称不能为空!信息导入失败!"); + } + + } + return success(); + } + public String syncImportFunc(List mesLineList){ + String failOrder = ""; + for (QcMaterialGroupDetail mesLine:mesLineList) { + String msg = syncFunc(mesLine); + if(StringUtils.isNotBlank(msg)){ + failOrder += msg+","; + } + } + return failOrder; + } + + @Transactional(rollbackFor = Exception.class) + public String syncFunc(QcMaterialGroupDetail materialGroupDetail){ + String failOrder = ""; + Date nowDate = DateUtils.getNowDate(); + QcMaterialGroupDetail orderExit = qcCheckTypeProjectMapper.selectExist(materialGroupDetail); + if (orderExit==null) {//不存在就插入 + materialGroupDetail.setId(IdUtils.fastSimpleUUID()); + materialGroupDetail.setCreateTime(nowDate); + qcMaterialGroupDetailMapper.insertQcMaterialGroupDetail(materialGroupDetail); + } + return failOrder; + } } diff --git a/op-modules/op-quality/src/main/resources/mapper/quality/QcCheckTypeProjectMapper.xml b/op-modules/op-quality/src/main/resources/mapper/quality/QcCheckTypeProjectMapper.xml index b202ef12..3472c515 100644 --- a/op-modules/op-quality/src/main/resources/mapper/quality/QcCheckTypeProjectMapper.xml +++ b/op-modules/op-quality/src/main/resources/mapper/quality/QcCheckTypeProjectMapper.xml @@ -315,4 +315,8 @@ where bp.product_code like concat('%',#{materialCode},'%') and bp.del_flag = '0' + diff --git a/op-modules/op-quality/src/main/resources/mapper/quality/QcMaterialGroupMapper.xml b/op-modules/op-quality/src/main/resources/mapper/quality/QcMaterialGroupMapper.xml index a14c64d6..4a558445 100644 --- a/op-modules/op-quality/src/main/resources/mapper/quality/QcMaterialGroupMapper.xml +++ b/op-modules/op-quality/src/main/resources/mapper/quality/QcMaterialGroupMapper.xml @@ -127,4 +127,7 @@ from qc_check_type_project where group_id = #{id} +