From 4961e3ff5110ec9b9774cdc440b2cfa421143030 Mon Sep 17 00:00:00 2001 From: fengyuan_yang <1976974459@qq.com> Date: Fri, 18 Oct 2024 10:52:50 +0800 Subject: [PATCH] =?UTF-8?q?2024-10-18=20=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/PartInformationController.java | 48 +++++- .../part/mapper/PartInformationMapper.java | 11 +- .../part/service/PartInformationService.java | 17 +- .../impl/PartInformationServiceImpl.java | 159 +++++++++++++++++- .../mapper/part/PartInformationMapper.xml | 34 +++- 5 files changed, 243 insertions(+), 26 deletions(-) diff --git a/src/main/java/com/spring/modules/part/controller/PartInformationController.java b/src/main/java/com/spring/modules/part/controller/PartInformationController.java index 21bd94c5..2cfb93ff 100644 --- a/src/main/java/com/spring/modules/part/controller/PartInformationController.java +++ b/src/main/java/com/spring/modules/part/controller/PartInformationController.java @@ -9,6 +9,7 @@ import com.spring.modules.base.data.PlmPropertiesModelHeaderData; import com.spring.modules.change.vo.ChangeRequestVo; import com.spring.modules.customer.entity.CustomerGroupInformationEntity; import com.spring.modules.customer.vo.CustomerInformationVo; +import com.spring.modules.oss.entity.SysOssEntity; import com.spring.modules.part.entity.*; import com.spring.modules.part.service.PartInformationService; import com.spring.modules.part.vo.*; @@ -16,9 +17,13 @@ import com.spring.modules.project.data.PlmProjectInfoData; import com.spring.modules.project.data.PlmProjectPartData; import com.spring.modules.quotation.entity.QuotationInformationEntity; import com.spring.modules.quotation.vo.QuotationInformationVo; +import com.spring.modules.sys.entity.GetParamInData; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.*; +import org.springframework.web.multipart.MultipartFile; +import javax.servlet.http.HttpServletResponse; +import java.io.UnsupportedEncodingException; import java.util.List; import java.util.Map; @@ -306,9 +311,10 @@ public class PartInformationController { * 查询库位列表 */ @PostMapping("/getLocationList") - public R getLocationList(@RequestBody PartInformationEntity data) { + public R getLocationList(@RequestBody LocationInformationVo data) { // 获取当前物料不包含的库位 - List row1 = partInformationService.getLocationList1(data); + //PageUtils row1 = partInformationService.getLocationList1(data); + PageUtils row1 = partInformationService.getLocationListBy(data); // 获取当前物料所包含的库位 List row2 = partInformationService.getLocationList2(data); return R.ok().put("row1", row1).put("row2", row2); @@ -321,8 +327,8 @@ public class PartInformationController { */ @PostMapping("getLocationListBy") public R getLocationListBy(@RequestBody LocationInformationVo data) { - List rows = partInformationService.getLocationListBy(data); - return R.ok().put("rows", rows); + PageUtils page = partInformationService.getLocationListBy(data); + return R.ok().put("page", page); } /** @@ -666,4 +672,38 @@ public class PartInformationController { List list = partInformationService.queryPart(data); return R.ok().put("rows", list); } + + /** + * 项目物料Excel导入 + * @param file + * @param data + * @return + */ + @PostMapping("/uploadProjectPartExcel") + public R uploadProjectPartExcel(@RequestParam(value = "file") MultipartFile file, @ModelAttribute GetParamInData data){ + partInformationService.uploadProjectPartExcel(file, data); + return R.ok(); + } + + /** + * 查询文件ID + * @param data + * @return + */ + @PostMapping("/queryFileId") + public R queryFileId(@RequestBody SysOssEntity data){ + SysOssEntity sysOss = partInformationService.queryFileId(data); + return R.ok().put("data",sysOss); + } + + /** + * 下载文件 + * @param id + * @param response + * @throws UnsupportedEncodingException + */ + @PostMapping(value = "/downLoadFile") + public void downLoadFile(@RequestParam("id") Integer id, HttpServletResponse response) throws UnsupportedEncodingException { + partInformationService.downLoadObjectFile(id,response); + } } diff --git a/src/main/java/com/spring/modules/part/mapper/PartInformationMapper.java b/src/main/java/com/spring/modules/part/mapper/PartInformationMapper.java index 7ae5993a..eba025ed 100644 --- a/src/main/java/com/spring/modules/part/mapper/PartInformationMapper.java +++ b/src/main/java/com/spring/modules/part/mapper/PartInformationMapper.java @@ -4,6 +4,7 @@ import com.baomidou.mybatisplus.core.mapper.BaseMapper; import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.spring.modules.base.data.*; +import com.spring.modules.change.entity.TechnicalSpecificationData; import com.spring.modules.change.vo.ChangeRequestVo; import com.spring.modules.oss.entity.SysOssEntity; import com.spring.modules.part.entity.*; @@ -91,11 +92,11 @@ public interface PartInformationMapper extends BaseMapper List queryCodeNo(PartInformationEntity data); - List getLocationList1(PartInformationEntity data); + IPage getLocationList1(Page technicalSpecificationDataPage, @Param("query") PartInformationEntity data); - List getLocationList2(PartInformationEntity data); + List getLocationList2(LocationInformationVo data); - List getLocationListBy(LocationInformationVo data); + IPage getLocationListBy(Page technicalSpecificationDataPage, @Param("query") LocationInformationVo data); List getDefaultLocation(LocationInformationVo data); @@ -252,4 +253,8 @@ public interface PartInformationMapper extends BaseMapper List queryPartByPartNo(@Param("site") String site, @Param("partNo") String partNo, @Param("partDesc") String partDesc); + + List queryFileId(SysOssEntity data); + + List getFileData(Integer id); } diff --git a/src/main/java/com/spring/modules/part/service/PartInformationService.java b/src/main/java/com/spring/modules/part/service/PartInformationService.java index 4b65e7dc..c08f1dba 100644 --- a/src/main/java/com/spring/modules/part/service/PartInformationService.java +++ b/src/main/java/com/spring/modules/part/service/PartInformationService.java @@ -6,10 +6,15 @@ import com.spring.modules.base.data.PlmPropertiesItemData; import com.spring.modules.base.data.PlmPropertiesModelDetailData; import com.spring.modules.base.data.PlmPropertiesModelHeaderData; import com.spring.modules.change.vo.ChangeRequestVo; +import com.spring.modules.oss.entity.SysOssEntity; import com.spring.modules.part.entity.*; import com.spring.modules.part.vo.*; import com.spring.modules.project.data.PlmProjectPartData; +import com.spring.modules.sys.entity.GetParamInData; +import org.springframework.web.multipart.MultipartFile; +import javax.servlet.http.HttpServletResponse; +import java.io.UnsupportedEncodingException; import java.util.List; import java.util.Map; @@ -73,11 +78,11 @@ public interface PartInformationService { void deletePartItem(PartSubPropertiesValueData inData); - List getLocationList1(PartInformationEntity data); + PageUtils getLocationList1(PartInformationEntity data); - List getLocationList2(PartInformationEntity data); + List getLocationList2(LocationInformationVo data); - List getLocationListBy(LocationInformationVo data); + PageUtils getLocationListBy(LocationInformationVo data); List getDefaultLocation(LocationInformationVo data); @@ -128,4 +133,10 @@ public interface PartInformationService { String getNextPartNo(PartInformationVo data); List queryPart(PartInformationVo data); + + void uploadProjectPartExcel(MultipartFile file, GetParamInData data); + + SysOssEntity queryFileId(SysOssEntity data); + + void downLoadObjectFile(Integer id, HttpServletResponse response) throws UnsupportedEncodingException; } diff --git a/src/main/java/com/spring/modules/part/service/impl/PartInformationServiceImpl.java b/src/main/java/com/spring/modules/part/service/impl/PartInformationServiceImpl.java index bcc31897..ec5b70bf 100644 --- a/src/main/java/com/spring/modules/part/service/impl/PartInformationServiceImpl.java +++ b/src/main/java/com/spring/modules/part/service/impl/PartInformationServiceImpl.java @@ -17,6 +17,7 @@ import com.spring.modules.base.service.TransNoControlService; import com.spring.modules.base.utils.DataUtils; import com.spring.modules.base.utils.HttpClientUtil; import com.spring.modules.base.utils.ResponseData; +import com.spring.modules.change.entity.TechnicalSpecificationData; import com.spring.modules.change.vo.ChangeRequestVo; import com.spring.modules.customer.entity.CustomerGroupInformationEntity; import com.spring.modules.oss.dao.SysOssDao; @@ -35,13 +36,22 @@ import com.spring.modules.part.service.PartInformationService; import com.spring.modules.part.vo.*; import com.spring.modules.project.data.PlmProjectPartData; import com.spring.modules.report.dao.ProcedureDao; +import com.spring.modules.sys.entity.GetParamInData; +import org.apache.poi.xssf.usermodel.XSSFRow; +import org.apache.poi.xssf.usermodel.XSSFSheet; +import org.apache.poi.xssf.usermodel.XSSFWorkbook; import org.springframework.beans.BeanUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import org.springframework.util.StringUtils; +import org.springframework.web.multipart.MultipartFile; +import javax.servlet.ServletOutputStream; +import javax.servlet.http.HttpServletResponse; +import java.io.*; +import java.math.BigDecimal; import java.text.SimpleDateFormat; import java.util.*; import java.util.stream.Collectors; @@ -1064,21 +1074,21 @@ public class PartInformationServiceImpl extends ServiceImpl getLocationList1(PartInformationEntity data) { - List list = partInformationMapper.getLocationList1(data); - return list; + public PageUtils getLocationList1(PartInformationEntity data) { + IPage resultList = this.partInformationMapper.getLocationList1(new Page(data.getPage(), data.getLimit()), data); + return new PageUtils(resultList); } @Override - public List getLocationList2(PartInformationEntity data) { + public List getLocationList2(LocationInformationVo data) { List list = partInformationMapper.getLocationList2(data); return list; } @Override - public List getLocationListBy(LocationInformationVo data) { - List list = partInformationMapper.getLocationListBy(data); - return list; + public PageUtils getLocationListBy(LocationInformationVo data) { + IPage resultList = this.partInformationMapper.getLocationListBy(new Page(data.getPage(), data.getLimit()), data); + return new PageUtils(resultList); } @Override @@ -2292,4 +2302,139 @@ public class PartInformationServiceImpl extends ServiceImpl queryPart(PartInformationVo data) { return baseMapper.queryPart(data); } + + /** + * 项目物料Excel导入 + * @param file + * @param data + */ + @Override + @Transactional + public void uploadProjectPartExcel(MultipartFile file, GetParamInData data) { + try{ + // 转流 + InputStream is = file.getInputStream(); + // 读取工作簿 + XSSFWorkbook workbook = new XSSFWorkbook(is); + // 读取工作表 + XSSFSheet sheet = workbook.getSheetAt(0); + // 获取行数 + int rows = sheet.getPhysicalNumberOfRows(); + // 声明对象 + PartInformationEntity task = null; + // 遍历每一行(从第二行开始) + for (int j = 1; j < rows; j++) { + // 实例化对象 + task = new PartInformationEntity(); + //获得该行 + XSSFRow row = sheet.getRow(j); + // 为对象赋值 + task.setSite(data.getOrderRef1()); // site + task.setProjectId(data.getOrderRef2()); // 项目编码 + task.setCustomerNo(data.getOrderRef3()); // 客户编码 + String no = transNoControlService.transNo(data.getOrderRef1(), "project_part_no"); + if (no == null) { + throw new RuntimeException("请维护编码生成规则(TransNoControl)!"); + } + task.setPartNo(no + "A01"); // 物料编码 + task.setBuNo(row.getCell(0).getStringCellValue()); // BU + task.setPartDesc(row.getCell(1).getStringCellValue()); // 物料描述 + task.setCustomerPartNo(row.getCell(2).getStringCellValue()); // 客户料号 + task.setPartType(row.getCell(3).getStringCellValue()); // 零件类型 + task.setProductGroupId4(row.getCell(4).getStringCellValue()); // 计划人 + task.setUmId(row.getCell(5).getStringCellValue()); // 计量单位 + task.setCodeNo(row.getCell(6).getStringCellValue()); // 属性模板 + task.setUomForWeightNet("kg"); + task.setUomForVolumeNet("m3"); + task.setActive("Y"); + task.setLotTrackingCode("Order Based"); + task.setCreateBy(data.getCreateBy()); + task.setAssetClass("S"); + task.setAbcClass("C"); + task.setFrequencyClass("Very Slow Mover"); + task.setLifecycleStage("Development"); + task.setStatus("N"); + task.setPartStatus("A"); + task.setConfigurationId("*"); + task.setInventoryValuationMethod("Standard Cost"); + task.setInventoryPartCostLevel("Cost Per Part"); + task.setInvoiceConsideration("Ignore Invoice Price"); + task.setZeroCostFlag("Zero Cost Forbidden"); + task.setBackFlushPart("All Locations"); + task.setIssueType("Reserve And Backflush"); + task.setMrpControlFlagDb("Y"); + task.setOverReporting("Allowed"); + + // 调用新增方法 + partInformationSave2(task); + } + } catch (Exception e) { + throw new RuntimeException("导入失败:"+e.getMessage()); + } + } + + /** + * 查询文件ID + * @param data + * @return + */ + @Override + public SysOssEntity queryFileId(SysOssEntity data) { + List list = partInformationMapper.queryFileId(data); + if (list.isEmpty()) { + throw new RuntimeException("未查到该文件ID,请检查数据!"); + } + return list.get(0); + } + + /** + * 下载文件 + * @param id + * @param response + * @throws UnsupportedEncodingException + */ + @Override + public void downLoadObjectFile(Integer id, HttpServletResponse response) throws UnsupportedEncodingException { + // 处理路径和名称 + List getFileData = partInformationMapper.getFileData(id); + if (getFileData.isEmpty()) { + throw new RuntimeException("该文件不存在,请刷新列表"); + } + File file = new File(getFileData.get(0).getUrl()); + //读取缓存1kb + byte[] buffer = new byte[1024]; + FileInputStream fis = null; + BufferedInputStream bis = null; + FileOutputStream fos = null; + BufferedOutputStream bos = null; + response.setContentType("application/force-download;charset=utf-8"); + response.setHeader("Content-disposition", "attachment; filename=" + new String(getFileData.get(0).getFileName().getBytes("gbk"), "iso8859-1")); + try { + //读取文件 + fis = new FileInputStream(file); + //加缓存 + bis = new BufferedInputStream(fis); + //开始读取 + int i = bis.read(buffer); + //设置输出流 + ServletOutputStream os = response.getOutputStream(); + //开始循环读取 + while (i != -1) { + os.write(buffer, 0, i); + i = bis.read(buffer); + } + fis.close(); + fos.close(); + } catch (Exception e) { + throw new RuntimeException(e.getMessage()); + } + } + } + + + + + + + diff --git a/src/main/resources/mapper/part/PartInformationMapper.xml b/src/main/resources/mapper/part/PartInformationMapper.xml index d5ff1162..701e8d8c 100644 --- a/src/main/resources/mapper/part/PartInformationMapper.xml +++ b/src/main/resources/mapper/part/PartInformationMapper.xml @@ -575,12 +575,12 @@ a.update_by, a.location_type FROM location as a - left join plm_part_location as b on a.site = b.site and a.location_id = b.location_id and b.part_no = #{partNo} - where a.site = #{site} and b.part_no is null + left join plm_part_location as b on a.site = b.site and a.location_id = b.location_id and b.part_no = #{query.partNo} + where a.site = #{query.site} and b.part_no is null - SELECT a.site, a.location_id, @@ -611,14 +611,14 @@ a.update_by, a.location_type FROM location as a - left join plm_part_location as b on a.site = b.site and a.location_id = b.location_id and b.part_no = #{partNo} + left join plm_part_location as b on a.site = b.site and a.location_id = b.location_id and b.part_no = #{query.partNo} - a.site = #{site} and b.part_no is null - - AND a.location_id LIKE #{locationId} + a.site = #{query.site} and b.part_no is null + + AND a.location_id LIKE #{query.locationId} - - AND a.location_name LIKE #{locationName} + + AND a.location_name LIKE #{query.locationName} @@ -1790,4 +1790,20 @@ and part_desc like #{partDesc} + + + + +