质检物料组,物料信息导入

master
zhaoxiaolin 7 months ago
parent 0785b6b95b
commit fe49dcaa8e

@ -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<QcProjectType> list = qcCheckTypeProjectService.getProjectOptions(qcCheckProject);
return list;
}
@PostMapping("/importTemplate")
@Log(title = "生成订单模板", businessType = BusinessType.EXPORT)
public void importTemplate(HttpServletResponse response) throws IOException {
ArrayList<ExcelCol> 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<ExcelCol> 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<QcMaterialGroupDetail> util = new ExcelUtil<>(QcMaterialGroupDetail.class);
// 接收表格信息
List<QcMaterialGroupDetail> orderList = util.importExcel(file.getInputStream());
return qcCheckTypeProjectService.importOrder(orderList);
}
}

@ -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;
}
/**
* 10
*/

@ -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<QcProjectType> getProjectOptions(QcCheckProject qcCheckProject);
QcProjectType getProductGroup(String materialCode);
QcMaterialGroupDetail selectExist(QcMaterialGroupDetail materialGroupDetail);
}

@ -66,4 +66,6 @@ public interface QcMaterialGroupMapper {
public List<QcMaterialGroup> getMaterialChildrenList(QcMaterialGroup qcMaterialGroup);
public List<QcMaterialGroup> validationData(String id);
String selectGroupIdByName(String groupName);
}

@ -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<QcCheckTypeProject> typeProjects);
List<QcProjectType> getProjectOptions(QcCheckProject qcCheckProject);
AjaxResult importOrder(List<QcMaterialGroupDetail> orderList);
}

@ -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<QcMaterialGroupDetail> 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<QcMaterialGroupDetail> 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<QcMaterialGroupDetail> 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;
}
}

@ -315,4 +315,8 @@
where bp.product_code like concat('%',#{materialCode},'%')
and bp.del_flag = '0'
</select>
<select id="selectExist" resultType="com.op.quality.domain.QcMaterialGroupDetail">
select material_name from qc_material_group_detail
where group_id = #{groupId} and material_code = #{materialCode} and del_flag = '0'
</select>
</mapper>

@ -127,4 +127,7 @@
from qc_check_type_project
where group_id = #{id}
</select>
<select id="selectGroupIdByName" resultType="java.lang.String">
select id from qc_material_group where group_name = #{groupName} and del_flag = '0'
</select>
</mapper>

Loading…
Cancel
Save