diff --git a/aucma-production/src/main/java/com/aucma/production/controller/MrpComponentWeeklyReqController.java b/aucma-production/src/main/java/com/aucma/production/controller/MrpComponentWeeklyReqController.java new file mode 100644 index 0000000..3cd5e46 --- /dev/null +++ b/aucma-production/src/main/java/com/aucma/production/controller/MrpComponentWeeklyReqController.java @@ -0,0 +1,150 @@ +package com.aucma.production.controller; + +import java.util.List; +import javax.servlet.http.HttpServletResponse; + +import com.aucma.common.utils.DateUtils; +import org.springframework.security.access.prepost.PreAuthorize; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.PutMapping; +import org.springframework.web.bind.annotation.DeleteMapping; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; +import org.springframework.web.multipart.MultipartFile; +import com.aucma.common.annotation.Log; +import com.aucma.common.core.controller.BaseController; +import com.aucma.common.core.domain.AjaxResult; +import com.aucma.common.enums.BusinessType; +import com.aucma.production.domain.MrpComponentWeeklyReq; +import com.aucma.production.service.IMrpComponentWeeklyReqService; +import com.aucma.common.utils.poi.ExcelUtil; +import com.aucma.common.core.page.TableDataInfo; + +/** + * 子件物料周需求Controller + * + * @author Yinq + * @date 2026-01-05 + */ +@RestController +@RequestMapping("/production/req" ) +public class MrpComponentWeeklyReqController extends BaseController { + @Autowired + private IMrpComponentWeeklyReqService mrpComponentWeeklyReqService; + + /** + * 查询子件物料周需求列表 + */ + @PreAuthorize("@ss.hasPermi('production:req:list')" ) + @GetMapping("/list" ) + public TableDataInfo list(MrpComponentWeeklyReq mrpComponentWeeklyReq) { + startPage(); + List list = mrpComponentWeeklyReqService.selectMrpComponentWeeklyReqList(mrpComponentWeeklyReq); + return getDataTable(list); + } + + /** + * 导出子件物料周需求列表 + */ + @PreAuthorize("@ss.hasPermi('production:req:export')" ) + @Log(title = "子件物料周需求" , businessType = BusinessType.EXPORT) + @PostMapping("/export" ) + public void export(HttpServletResponse response, MrpComponentWeeklyReq mrpComponentWeeklyReq) { + List list = mrpComponentWeeklyReqService.selectMrpComponentWeeklyReqList(mrpComponentWeeklyReq); + ExcelUtil util = new ExcelUtil(MrpComponentWeeklyReq. class); + util.exportExcel(response, list, "子件物料周需求数据" ); + } + + /** + * 获取子件物料周需求详细信息 + */ + @PreAuthorize("@ss.hasPermi('production:req:query')" ) + @GetMapping(value = "/{id}" ) + public AjaxResult getInfo(@PathVariable("id" ) Long id) { + return success(mrpComponentWeeklyReqService.selectMrpComponentWeeklyReqById(id)); + } + + /** + * 新增子件物料周需求 + */ + @PreAuthorize("@ss.hasPermi('production:req:add')" ) + @Log(title = "子件物料周需求" , businessType = BusinessType.INSERT) + @PostMapping + public AjaxResult add(@RequestBody MrpComponentWeeklyReq mrpComponentWeeklyReq) { + mrpComponentWeeklyReq.setCreatedAt(DateUtils.getNowDate()); + return toAjax(mrpComponentWeeklyReqService.insertMrpComponentWeeklyReq(mrpComponentWeeklyReq)); + } + + /** + * 修改子件物料周需求 + */ + @PreAuthorize("@ss.hasPermi('production:req:edit')" ) + @Log(title = "子件物料周需求" , businessType = BusinessType.UPDATE) + @PutMapping + public AjaxResult edit(@RequestBody MrpComponentWeeklyReq mrpComponentWeeklyReq) { + mrpComponentWeeklyReq.setUpdatedAt(DateUtils.getNowDate()); + return toAjax(mrpComponentWeeklyReqService.updateMrpComponentWeeklyReq(mrpComponentWeeklyReq)); + } + + /** + * 删除子件物料周需求 + */ + @PreAuthorize("@ss.hasPermi('production:req:remove')" ) + @Log(title = "子件物料周需求" , businessType = BusinessType.DELETE) + @DeleteMapping("/{ids}" ) + public AjaxResult remove(@PathVariable Long[] ids) { + return toAjax(mrpComponentWeeklyReqService.deleteMrpComponentWeeklyReqByIds(ids)); + } + + /** + * 批量更新子件物料周需求 + */ + @PreAuthorize("@ss.hasPermi('production:req:edit')" ) + @Log(title = "子件物料周需求" , businessType = BusinessType.UPDATE) + @PutMapping("/batchUpdate" ) + public AjaxResult batchUpdate(@RequestBody List list) { + int count = 0; + for (MrpComponentWeeklyReq item : list) { + item.setUpdatedAt(DateUtils.getNowDate()); + count += mrpComponentWeeklyReqService.updateMrpComponentWeeklyReq(item); + } + return success("成功更新 " + count + " 条数据"); + } + + /** + * 导入子件物料周需求(异步导入,不阻塞前端) + * @param file Excel文件 + * @param updateSupport 是否更新已存在数据 + * @param weekStartDate 周一日期(yyyy-MM-dd格式) + */ + @PreAuthorize("@ss.hasPermi('production:req:import')" ) + @Log(title = "子件物料周需求" , businessType = BusinessType.IMPORT) + @PostMapping("/importData" ) + public AjaxResult importData(MultipartFile file, boolean updateSupport, String weekStartDate) throws Exception { + ExcelUtil util = new ExcelUtil(MrpComponentWeeklyReq.class); + List list = util.importExcel(file.getInputStream()); + + int total = list.size(); + System.out.println("========== 开始异步导入子件物料周需求 =========="); + System.out.println("weekStartDate: " + weekStartDate); + System.out.println("数据量: " + total + " 条"); + + // 异步导入,立即返回 + mrpComponentWeeklyReqService.importDataAsync(list, updateSupport, getUsername(), weekStartDate); + + return success("已提交后台异步导入任务,共 " + total + " 条数据,请稍后刷新页面查看结果。导入进度请查看控制台日志。"); + } + + /** + * 下载导入模板 + */ + @PostMapping("/importTemplate" ) + public void importTemplate(HttpServletResponse response) { + ExcelUtil util = new ExcelUtil(MrpComponentWeeklyReq.class); + util.importTemplateExcel(response, "子件物料周需求模板" ); + } +} diff --git a/aucma-production/src/main/java/com/aucma/production/controller/MrpProdWeeklyPlanController.java b/aucma-production/src/main/java/com/aucma/production/controller/MrpProdWeeklyPlanController.java new file mode 100644 index 0000000..07b1bca --- /dev/null +++ b/aucma-production/src/main/java/com/aucma/production/controller/MrpProdWeeklyPlanController.java @@ -0,0 +1,168 @@ +package com.aucma.production.controller; + +import java.util.List; +import javax.servlet.http.HttpServletResponse; + +import com.aucma.common.utils.DateUtils; +import org.springframework.security.access.prepost.PreAuthorize; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.PutMapping; +import org.springframework.web.bind.annotation.DeleteMapping; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; +import org.springframework.web.multipart.MultipartFile; +import com.aucma.common.annotation.Log; +import com.aucma.common.core.controller.BaseController; +import com.aucma.common.core.domain.AjaxResult; +import com.aucma.common.enums.BusinessType; +import com.aucma.production.domain.MrpProdWeeklyPlan; +import com.aucma.production.service.IMrpProdWeeklyPlanService; +import com.aucma.common.utils.poi.ExcelUtil; +import com.aucma.common.core.page.TableDataInfo; + +/** + * 周排产计划Controller + * + * @author Yinq + * @date 2026-01-05 + */ +@RestController +@RequestMapping("/production/plan" ) +public class MrpProdWeeklyPlanController extends BaseController { + @Autowired + private IMrpProdWeeklyPlanService mrpProdWeeklyPlanService; + + /** + * 查询周排产计划列表 + */ + @PreAuthorize("@ss.hasPermi('production:plan:list')" ) + @GetMapping("/list" ) + public TableDataInfo list(MrpProdWeeklyPlan mrpProdWeeklyPlan) { + startPage(); + List list = mrpProdWeeklyPlanService.selectMrpProdWeeklyPlanList(mrpProdWeeklyPlan); + return getDataTable(list); + } + + /** + * 导出周排产计划列表 + */ + @PreAuthorize("@ss.hasPermi('production:plan:export')" ) + @Log(title = "周排产计划" , businessType = BusinessType.EXPORT) + @PostMapping("/export" ) + public void export(HttpServletResponse response, MrpProdWeeklyPlan mrpProdWeeklyPlan) { + List list = mrpProdWeeklyPlanService.selectMrpProdWeeklyPlanList(mrpProdWeeklyPlan); + ExcelUtil util = new ExcelUtil(MrpProdWeeklyPlan. class); + util.exportExcel(response, list, "周排产计划数据" ); + } + + /** + * 获取周排产计划详细信息 + */ + @PreAuthorize("@ss.hasPermi('production:plan:query')" ) + @GetMapping(value = "/{id}" ) + public AjaxResult getInfo(@PathVariable("id" ) Long id) { + return success(mrpProdWeeklyPlanService.selectMrpProdWeeklyPlanById(id)); + } + + /** + * 新增周排产计划 + */ + @PreAuthorize("@ss.hasPermi('production:plan:add')" ) + @Log(title = "周排产计划" , businessType = BusinessType.INSERT) + @PostMapping + public AjaxResult add(@RequestBody MrpProdWeeklyPlan mrpProdWeeklyPlan) { + mrpProdWeeklyPlan.setCreatedAt(DateUtils.getNowDate()); + return toAjax(mrpProdWeeklyPlanService.insertMrpProdWeeklyPlan(mrpProdWeeklyPlan)); + } + + /** + * 修改周排产计划 + */ + @PreAuthorize("@ss.hasPermi('production:plan:edit')" ) + @Log(title = "周排产计划" , businessType = BusinessType.UPDATE) + @PutMapping + public AjaxResult edit(@RequestBody MrpProdWeeklyPlan mrpProdWeeklyPlan) { + mrpProdWeeklyPlan.setUpdatedAt(DateUtils.getNowDate()); + return toAjax(mrpProdWeeklyPlanService.updateMrpProdWeeklyPlan(mrpProdWeeklyPlan)); + } + + /** + * 删除周排产计划 + */ + @PreAuthorize("@ss.hasPermi('production:plan:remove')" ) + @Log(title = "周排产计划" , businessType = BusinessType.DELETE) + @DeleteMapping("/{ids}" ) + public AjaxResult remove(@PathVariable Long[] ids) { + return toAjax(mrpProdWeeklyPlanService.deleteMrpProdWeeklyPlanByIds(ids)); + } + + /** + * 批量更新周排产计划 + */ + @PreAuthorize("@ss.hasPermi('production:plan:edit')" ) + @Log(title = "周排产计划" , businessType = BusinessType.UPDATE) + @PutMapping("/batchUpdate" ) + public AjaxResult batchUpdate(@RequestBody List list) { + int count = 0; + for (MrpProdWeeklyPlan item : list) { + item.setUpdatedAt(DateUtils.getNowDate()); + count += mrpProdWeeklyPlanService.updateMrpProdWeeklyPlan(item); + } + return success("成功更新 " + count + " 条数据"); + } + + /** + * 导入周排产计划 + * @param file Excel文件 + * @param updateSupport 是否更新已存在数据 + * @param weekStartDate 周一日期(yyyy-MM-dd格式) + */ + @PreAuthorize("@ss.hasPermi('production:plan:import')" ) + @Log(title = "周排产计划" , businessType = BusinessType.IMPORT) + @PostMapping("/importData" ) + public AjaxResult importData(MultipartFile file, boolean updateSupport, String weekStartDate) throws Exception { + System.out.println("========== 开始导入周排产计划 =========="); + System.out.println("weekStartDate: " + weekStartDate); + System.out.println("file name: " + file.getOriginalFilename()); + System.out.println("file size: " + file.getSize()); + + ExcelUtil util = new ExcelUtil(MrpProdWeeklyPlan.class); + List list = null; + try { + list = util.importExcel(file.getInputStream()); + System.out.println("解析Excel成功,共 " + list.size() + " 条数据"); + if (list.size() > 0) { + MrpProdWeeklyPlan first = list.get(0); + System.out.println("第一条数据: seqNo=" + first.getSeqNo() + ", itemCode=" + first.getItemCode() + ", itemDesc=" + first.getItemDesc()); + } + } catch (Exception e) { + System.out.println("解析Excel失败: " + e.getMessage()); + System.out.println("异常类型: " + e.getClass().getName()); + if (e.getCause() != null) { + System.out.println("根本原因: " + e.getCause().getMessage()); + System.out.println("根本原因类型: " + e.getCause().getClass().getName()); + e.getCause().printStackTrace(); + } else { + e.printStackTrace(); + } + throw e; + } + + String message = mrpProdWeeklyPlanService.importData(list, updateSupport, getUsername(), weekStartDate); + System.out.println("导入完成: " + message); + return success(message); + } + + /** + * 下载导入模板 + */ + @PostMapping("/importTemplate" ) + public void importTemplate(HttpServletResponse response) { + ExcelUtil util = new ExcelUtil(MrpProdWeeklyPlan.class); + util.importTemplateExcel(response, "周排产计划模板" ); + } +} diff --git a/aucma-production/src/main/java/com/aucma/production/domain/MrpComponentWeeklyReq.java b/aucma-production/src/main/java/com/aucma/production/domain/MrpComponentWeeklyReq.java new file mode 100644 index 0000000..1a3dbee --- /dev/null +++ b/aucma-production/src/main/java/com/aucma/production/domain/MrpComponentWeeklyReq.java @@ -0,0 +1,237 @@ +package com.aucma.production.domain; + +import java.math.BigDecimal; +import java.util.Date; +import com.fasterxml.jackson.annotation.JsonFormat; +import org.apache.commons.lang3.builder.ToStringBuilder; +import org.apache.commons.lang3.builder.ToStringStyle; +import com.aucma.common.annotation.Excel; +import com.aucma.common.core.domain.BaseEntity; + +/** + * 子件物料周需求对象 mrp_component_weekly_req + * + * @author Yinq + * @date 2026-01-05 + */ +public class MrpComponentWeeklyReq extends BaseEntity + { +private static final long serialVersionUID=1L; + + /** $column.columnComment */ + private Long id; + + /** 年第周(如 202501) */ + @Excel(name = "年第周", type = Excel.Type.EXPORT) + private String yearWeek; + + /** 周一日期 */ + @JsonFormat(pattern = "yyyy-MM-dd") + @Excel(name = "周一日期", width = 15, dateFormat = "yyyy-MM-dd", type = Excel.Type.EXPORT) + private Date weekStartDate; + + /** 子件物料编码 */ + @Excel(name = "子件物料编码", type = Excel.Type.ALL) + private String itemCode; + + /** 子件物料描述 */ + @Excel(name = "子件物料描述", type = Excel.Type.ALL) + private String itemDesc; + + /** 周一需求量 */ + @Excel(name = "周一需求量", type = Excel.Type.ALL) + private BigDecimal reqMon; + + /** 周二需求量 */ + @Excel(name = "周二需求量", type = Excel.Type.ALL) + private BigDecimal reqTue; + + /** 周三需求量 */ + @Excel(name = "周三需求量", type = Excel.Type.ALL) + private BigDecimal reqWed; + + /** 周四需求量 */ + @Excel(name = "周四需求量", type = Excel.Type.ALL) + private BigDecimal reqThu; + + /** 周五需求量 */ + @Excel(name = "周五需求量", type = Excel.Type.ALL) + private BigDecimal reqFri; + + /** 周六需求量 */ + @Excel(name = "周六需求量", type = Excel.Type.ALL) + private BigDecimal reqSat; + + /** 周日需求量 */ + @Excel(name = "周日需求量", type = Excel.Type.ALL) + private BigDecimal reqSun; + + /** 周合计需求量(虚拟列) */ + @Excel(name = "周合计需求量", type = Excel.Type.EXPORT) + private BigDecimal reqWeekTotal; + + /** 创建时间 */ + @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss") + private Date createdAt; + + /** 修改时间 */ + @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss") + private Date updatedAt; + + public void setId(Long id) + { + this.id = id; + } + + public Long getId() + { + return id; + } + public void setYearWeek(String yearWeek) + { + this.yearWeek = yearWeek; + } + + public String getYearWeek() + { + return yearWeek; + } + public void setWeekStartDate(Date weekStartDate) + { + this.weekStartDate = weekStartDate; + } + + public Date getWeekStartDate() + { + return weekStartDate; + } + public void setItemCode(String itemCode) + { + this.itemCode = itemCode; + } + + public String getItemCode() + { + return itemCode; + } + public void setItemDesc(String itemDesc) + { + this.itemDesc = itemDesc; + } + + public String getItemDesc() + { + return itemDesc; + } + public void setReqMon(BigDecimal reqMon) + { + this.reqMon = reqMon; + } + + public BigDecimal getReqMon() + { + return reqMon; + } + public void setReqTue(BigDecimal reqTue) + { + this.reqTue = reqTue; + } + + public BigDecimal getReqTue() + { + return reqTue; + } + public void setReqWed(BigDecimal reqWed) + { + this.reqWed = reqWed; + } + + public BigDecimal getReqWed() + { + return reqWed; + } + public void setReqThu(BigDecimal reqThu) + { + this.reqThu = reqThu; + } + + public BigDecimal getReqThu() + { + return reqThu; + } + public void setReqFri(BigDecimal reqFri) + { + this.reqFri = reqFri; + } + + public BigDecimal getReqFri() + { + return reqFri; + } + public void setReqSat(BigDecimal reqSat) + { + this.reqSat = reqSat; + } + + public BigDecimal getReqSat() + { + return reqSat; + } + public void setReqSun(BigDecimal reqSun) + { + this.reqSun = reqSun; + } + + public BigDecimal getReqSun() + { + return reqSun; + } + public void setReqWeekTotal(BigDecimal reqWeekTotal) + { + this.reqWeekTotal = reqWeekTotal; + } + + public BigDecimal getReqWeekTotal() + { + return reqWeekTotal; + } + public void setCreatedAt(Date createdAt) + { + this.createdAt = createdAt; + } + + public Date getCreatedAt() + { + return createdAt; + } + public void setUpdatedAt(Date updatedAt) + { + this.updatedAt = updatedAt; + } + + public Date getUpdatedAt() + { + return updatedAt; + } + +@Override +public String toString(){ + return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE) + .append("id",getId()) + .append("yearWeek",getYearWeek()) + .append("weekStartDate",getWeekStartDate()) + .append("itemCode",getItemCode()) + .append("itemDesc",getItemDesc()) + .append("reqMon",getReqMon()) + .append("reqTue",getReqTue()) + .append("reqWed",getReqWed()) + .append("reqThu",getReqThu()) + .append("reqFri",getReqFri()) + .append("reqSat",getReqSat()) + .append("reqSun",getReqSun()) + .append("reqWeekTotal",getReqWeekTotal()) + .append("createdAt",getCreatedAt()) + .append("updatedAt",getUpdatedAt()) + .toString(); + } + } diff --git a/aucma-production/src/main/java/com/aucma/production/domain/MrpProdWeeklyPlan.java b/aucma-production/src/main/java/com/aucma/production/domain/MrpProdWeeklyPlan.java new file mode 100644 index 0000000..8c45d0d --- /dev/null +++ b/aucma-production/src/main/java/com/aucma/production/domain/MrpProdWeeklyPlan.java @@ -0,0 +1,293 @@ +package com.aucma.production.domain; + +import java.math.BigDecimal; +import java.util.Date; +import com.fasterxml.jackson.annotation.JsonFormat; +import org.apache.commons.lang3.builder.ToStringBuilder; +import org.apache.commons.lang3.builder.ToStringStyle; +import com.aucma.common.annotation.Excel; +import com.aucma.common.core.domain.BaseEntity; + +/** + * 周排产计划对象 mrp_prod_weekly_plan + * + * @author Yinq + * @date 2026-01-05 + */ +public class MrpProdWeeklyPlan extends BaseEntity + { +private static final long serialVersionUID=1L; + + /** $column.columnComment */ + private Long id; + + /** 年第周(如 202501) */ + @Excel(name = "年第周", type = Excel.Type.EXPORT) + private String yearWeek; + + /** 周一日期 */ + @JsonFormat(pattern = "yyyy-MM-dd") + @Excel(name = "周一日期", width = 15, dateFormat = "yyyy-MM-dd", type = Excel.Type.EXPORT) + private Date weekStartDate; + + /** 序号 */ + @Excel(name = "序号", type = Excel.Type.ALL) + private BigDecimal seqNo; + + /** 编码/型号 */ + @Excel(name = "编码", type = Excel.Type.ALL) + private String itemCode; + + /** 描述 */ + @Excel(name = "描述", type = Excel.Type.ALL) + private String itemDesc; + + /** 工厂 */ + @Excel(name = "工厂", type = Excel.Type.ALL) + private String plantCode; + + /** 订单号 */ + @Excel(name = "订单号", type = Excel.Type.ALL) + private String orderNo; + + /** 行号 */ + @Excel(name = "行号", type = Excel.Type.ALL) + private String orderLineNo; + + /** 1日计划量 */ + @Excel(name = "1日", type = Excel.Type.ALL) + private BigDecimal planD1; + + /** 2日计划量 */ + @Excel(name = "2日", type = Excel.Type.ALL) + private BigDecimal planD2; + + /** 3日计划量 */ + @Excel(name = "3日", type = Excel.Type.ALL) + private BigDecimal planD3; + + /** 4日计划量 */ + @Excel(name = "4日", type = Excel.Type.ALL) + private BigDecimal planD4; + + /** 5日计划量 */ + @Excel(name = "5日", type = Excel.Type.ALL) + private BigDecimal planD5; + + /** 6日计划量 */ + @Excel(name = "6日", type = Excel.Type.ALL) + private BigDecimal planD6; + + /** 7日计划量 */ + @Excel(name = "7日", type = Excel.Type.ALL) + private BigDecimal planD7; + + /** 周合计计划量(虚拟列) */ + @Excel(name = "周合计", type = Excel.Type.EXPORT) + private BigDecimal planWeekTotal; + + /** 创建时间 */ + @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss") + private Date createdAt; + + /** 修改时间 */ + @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss") + private Date updatedAt; + + public void setId(Long id) + { + this.id = id; + } + + public Long getId() + { + return id; + } + public void setYearWeek(String yearWeek) + { + this.yearWeek = yearWeek; + } + + public String getYearWeek() + { + return yearWeek; + } + public void setWeekStartDate(Date weekStartDate) + { + this.weekStartDate = weekStartDate; + } + + public Date getWeekStartDate() + { + return weekStartDate; + } + public void setSeqNo(BigDecimal seqNo) + { + this.seqNo = seqNo; + } + + public BigDecimal getSeqNo() + { + return seqNo; + } + public void setItemCode(String itemCode) + { + this.itemCode = itemCode; + } + + public String getItemCode() + { + return itemCode; + } + public void setItemDesc(String itemDesc) + { + this.itemDesc = itemDesc; + } + + public String getItemDesc() + { + return itemDesc; + } + public void setPlantCode(String plantCode) + { + this.plantCode = plantCode; + } + + public String getPlantCode() + { + return plantCode; + } + public void setOrderNo(String orderNo) + { + this.orderNo = orderNo; + } + + public String getOrderNo() + { + return orderNo; + } + public void setOrderLineNo(String orderLineNo) + { + this.orderLineNo = orderLineNo; + } + + public String getOrderLineNo() + { + return orderLineNo; + } + public void setPlanD1(BigDecimal planD1) + { + this.planD1 = planD1; + } + + public BigDecimal getPlanD1() + { + return planD1; + } + public void setPlanD2(BigDecimal planD2) + { + this.planD2 = planD2; + } + + public BigDecimal getPlanD2() + { + return planD2; + } + public void setPlanD3(BigDecimal planD3) + { + this.planD3 = planD3; + } + + public BigDecimal getPlanD3() + { + return planD3; + } + public void setPlanD4(BigDecimal planD4) + { + this.planD4 = planD4; + } + + public BigDecimal getPlanD4() + { + return planD4; + } + public void setPlanD5(BigDecimal planD5) + { + this.planD5 = planD5; + } + + public BigDecimal getPlanD5() + { + return planD5; + } + public void setPlanD6(BigDecimal planD6) + { + this.planD6 = planD6; + } + + public BigDecimal getPlanD6() + { + return planD6; + } + public void setPlanD7(BigDecimal planD7) + { + this.planD7 = planD7; + } + + public BigDecimal getPlanD7() + { + return planD7; + } + public void setPlanWeekTotal(BigDecimal planWeekTotal) + { + this.planWeekTotal = planWeekTotal; + } + + public BigDecimal getPlanWeekTotal() + { + return planWeekTotal; + } + public void setCreatedAt(Date createdAt) + { + this.createdAt = createdAt; + } + + public Date getCreatedAt() + { + return createdAt; + } + public void setUpdatedAt(Date updatedAt) + { + this.updatedAt = updatedAt; + } + + public Date getUpdatedAt() + { + return updatedAt; + } + +@Override +public String toString(){ + return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE) + .append("id",getId()) + .append("yearWeek",getYearWeek()) + .append("weekStartDate",getWeekStartDate()) + .append("seqNo",getSeqNo()) + .append("itemCode",getItemCode()) + .append("itemDesc",getItemDesc()) + .append("plantCode",getPlantCode()) + .append("orderNo",getOrderNo()) + .append("orderLineNo",getOrderLineNo()) + .append("planD1",getPlanD1()) + .append("planD2",getPlanD2()) + .append("planD3",getPlanD3()) + .append("planD4",getPlanD4()) + .append("planD5",getPlanD5()) + .append("planD6",getPlanD6()) + .append("planD7",getPlanD7()) + .append("planWeekTotal",getPlanWeekTotal()) + .append("createdAt",getCreatedAt()) + .append("updatedAt",getUpdatedAt()) + .toString(); + } + } diff --git a/aucma-production/src/main/java/com/aucma/production/mapper/MrpComponentWeeklyReqMapper.java b/aucma-production/src/main/java/com/aucma/production/mapper/MrpComponentWeeklyReqMapper.java new file mode 100644 index 0000000..45e9d32 --- /dev/null +++ b/aucma-production/src/main/java/com/aucma/production/mapper/MrpComponentWeeklyReqMapper.java @@ -0,0 +1,69 @@ +package com.aucma.production.mapper; + +import java.util.List; +import com.aucma.production.domain.MrpComponentWeeklyReq; + +/** + * 子件物料周需求Mapper接口 + * + * @author Yinq + * @date 2026-01-05 + */ +public interface MrpComponentWeeklyReqMapper +{ + /** + * 查询子件物料周需求 + * + * @param id 子件物料周需求主键 + * @return 子件物料周需求 + */ + public MrpComponentWeeklyReq selectMrpComponentWeeklyReqById(Long id); + + /** + * 查询子件物料周需求列表 + * + * @param mrpComponentWeeklyReq 子件物料周需求 + * @return 子件物料周需求集合 + */ + public List selectMrpComponentWeeklyReqList(MrpComponentWeeklyReq mrpComponentWeeklyReq); + + /** + * 新增子件物料周需求 + * + * @param mrpComponentWeeklyReq 子件物料周需求 + * @return 结果 + */ + public int insertMrpComponentWeeklyReq(MrpComponentWeeklyReq mrpComponentWeeklyReq); + + /** + * 修改子件物料周需求 + * + * @param mrpComponentWeeklyReq 子件物料周需求 + * @return 结果 + */ + public int updateMrpComponentWeeklyReq(MrpComponentWeeklyReq mrpComponentWeeklyReq); + + /** + * 删除子件物料周需求 + * + * @param id 子件物料周需求主键 + * @return 结果 + */ + public int deleteMrpComponentWeeklyReqById(Long id); + + /** + * 批量删除子件物料周需求 + * + * @param ids 需要删除的数据主键集合 + * @return 结果 + */ + public int deleteMrpComponentWeeklyReqByIds(Long[] ids); + + /** + * 批量插入子件物料周需求 + * + * @param list 子件物料周需求列表 + * @return 结果 + */ + public int batchInsert(List list); +} diff --git a/aucma-production/src/main/java/com/aucma/production/mapper/MrpProdWeeklyPlanMapper.java b/aucma-production/src/main/java/com/aucma/production/mapper/MrpProdWeeklyPlanMapper.java new file mode 100644 index 0000000..4b10d7c --- /dev/null +++ b/aucma-production/src/main/java/com/aucma/production/mapper/MrpProdWeeklyPlanMapper.java @@ -0,0 +1,69 @@ +package com.aucma.production.mapper; + +import java.util.List; +import com.aucma.production.domain.MrpProdWeeklyPlan; + +/** + * 周排产计划Mapper接口 + * + * @author Yinq + * @date 2026-01-05 + */ +public interface MrpProdWeeklyPlanMapper +{ + /** + * 查询周排产计划 + * + * @param id 周排产计划主键 + * @return 周排产计划 + */ + public MrpProdWeeklyPlan selectMrpProdWeeklyPlanById(Long id); + + /** + * 查询周排产计划列表 + * + * @param mrpProdWeeklyPlan 周排产计划 + * @return 周排产计划集合 + */ + public List selectMrpProdWeeklyPlanList(MrpProdWeeklyPlan mrpProdWeeklyPlan); + + /** + * 新增周排产计划 + * + * @param mrpProdWeeklyPlan 周排产计划 + * @return 结果 + */ + public int insertMrpProdWeeklyPlan(MrpProdWeeklyPlan mrpProdWeeklyPlan); + + /** + * 修改周排产计划 + * + * @param mrpProdWeeklyPlan 周排产计划 + * @return 结果 + */ + public int updateMrpProdWeeklyPlan(MrpProdWeeklyPlan mrpProdWeeklyPlan); + + /** + * 删除周排产计划 + * + * @param id 周排产计划主键 + * @return 结果 + */ + public int deleteMrpProdWeeklyPlanById(Long id); + + /** + * 批量删除周排产计划 + * + * @param ids 需要删除的数据主键集合 + * @return 结果 + */ + public int deleteMrpProdWeeklyPlanByIds(Long[] ids); + + /** + * 批量插入周排产计划 + * + * @param list 周排产计划列表 + * @return 结果 + */ + public int batchInsert(List list); +} diff --git a/aucma-production/src/main/java/com/aucma/production/service/IMrpComponentWeeklyReqService.java b/aucma-production/src/main/java/com/aucma/production/service/IMrpComponentWeeklyReqService.java new file mode 100644 index 0000000..a4065f2 --- /dev/null +++ b/aucma-production/src/main/java/com/aucma/production/service/IMrpComponentWeeklyReqService.java @@ -0,0 +1,82 @@ +package com.aucma.production.service; + +import java.util.List; +import com.aucma.production.domain.MrpComponentWeeklyReq; + +/** + * 子件物料周需求Service接口 + * + * @author Yinq + * @date 2026-01-05 + */ +public interface IMrpComponentWeeklyReqService +{ + /** + * 查询子件物料周需求 + * + * @param id 子件物料周需求主键 + * @return 子件物料周需求 + */ + public MrpComponentWeeklyReq selectMrpComponentWeeklyReqById(Long id); + + /** + * 查询子件物料周需求列表 + * + * @param mrpComponentWeeklyReq 子件物料周需求 + * @return 子件物料周需求集合 + */ + public List selectMrpComponentWeeklyReqList(MrpComponentWeeklyReq mrpComponentWeeklyReq); + + /** + * 新增子件物料周需求 + * + * @param mrpComponentWeeklyReq 子件物料周需求 + * @return 结果 + */ + public int insertMrpComponentWeeklyReq(MrpComponentWeeklyReq mrpComponentWeeklyReq); + + /** + * 修改子件物料周需求 + * + * @param mrpComponentWeeklyReq 子件物料周需求 + * @return 结果 + */ + public int updateMrpComponentWeeklyReq(MrpComponentWeeklyReq mrpComponentWeeklyReq); + + /** + * 批量删除子件物料周需求 + * + * @param ids 需要删除的子件物料周需求主键集合 + * @return 结果 + */ + public int deleteMrpComponentWeeklyReqByIds(Long[] ids); + + /** + * 删除子件物料周需求信息 + * + * @param id 子件物料周需求主键 + * @return 结果 + */ + public int deleteMrpComponentWeeklyReqById(Long id); + + /** + * 导入子件物料周需求数据 + * + * @param list 数据列表 + * @param updateSupport 是否更新已存在数据 + * @param operName 操作人 + * @param weekStartDate 周一日期(yyyy-MM-dd格式) + * @return 结果信息 + */ + public String importData(List list, boolean updateSupport, String operName, String weekStartDate); + + /** + * 异步导入子件物料周需求数据(不阻塞前端) + * + * @param list 数据列表 + * @param updateSupport 是否更新已存在数据 + * @param operName 操作人 + * @param weekStartDate 周一日期(yyyy-MM-dd格式) + */ + public void importDataAsync(List list, boolean updateSupport, String operName, String weekStartDate); +} diff --git a/aucma-production/src/main/java/com/aucma/production/service/IMrpProdWeeklyPlanService.java b/aucma-production/src/main/java/com/aucma/production/service/IMrpProdWeeklyPlanService.java new file mode 100644 index 0000000..e51f87a --- /dev/null +++ b/aucma-production/src/main/java/com/aucma/production/service/IMrpProdWeeklyPlanService.java @@ -0,0 +1,72 @@ +package com.aucma.production.service; + +import java.util.List; +import com.aucma.production.domain.MrpProdWeeklyPlan; + +/** + * 周排产计划Service接口 + * + * @author Yinq + * @date 2026-01-05 + */ +public interface IMrpProdWeeklyPlanService +{ + /** + * 查询周排产计划 + * + * @param id 周排产计划主键 + * @return 周排产计划 + */ + public MrpProdWeeklyPlan selectMrpProdWeeklyPlanById(Long id); + + /** + * 查询周排产计划列表 + * + * @param mrpProdWeeklyPlan 周排产计划 + * @return 周排产计划集合 + */ + public List selectMrpProdWeeklyPlanList(MrpProdWeeklyPlan mrpProdWeeklyPlan); + + /** + * 新增周排产计划 + * + * @param mrpProdWeeklyPlan 周排产计划 + * @return 结果 + */ + public int insertMrpProdWeeklyPlan(MrpProdWeeklyPlan mrpProdWeeklyPlan); + + /** + * 修改周排产计划 + * + * @param mrpProdWeeklyPlan 周排产计划 + * @return 结果 + */ + public int updateMrpProdWeeklyPlan(MrpProdWeeklyPlan mrpProdWeeklyPlan); + + /** + * 批量删除周排产计划 + * + * @param ids 需要删除的周排产计划主键集合 + * @return 结果 + */ + public int deleteMrpProdWeeklyPlanByIds(Long[] ids); + + /** + * 删除周排产计划信息 + * + * @param id 周排产计划主键 + * @return 结果 + */ + public int deleteMrpProdWeeklyPlanById(Long id); + + /** + * 导入周排产计划数据 + * + * @param list 数据列表 + * @param updateSupport 是否更新已存在数据 + * @param operName 操作人 + * @param weekStartDate 周一日期(yyyy-MM-dd格式) + * @return 结果信息 + */ + public String importData(List list, boolean updateSupport, String operName, String weekStartDate); +} diff --git a/aucma-production/src/main/java/com/aucma/production/service/impl/MrpComponentWeeklyReqServiceImpl.java b/aucma-production/src/main/java/com/aucma/production/service/impl/MrpComponentWeeklyReqServiceImpl.java new file mode 100644 index 0000000..f614db9 --- /dev/null +++ b/aucma-production/src/main/java/com/aucma/production/service/impl/MrpComponentWeeklyReqServiceImpl.java @@ -0,0 +1,288 @@ +package com.aucma.production.service.impl; + +import java.text.SimpleDateFormat; +import java.util.ArrayList; +import java.util.Calendar; +import java.util.Date; +import java.util.List; +import com.aucma.common.exception.ServiceException; +import com.aucma.common.utils.StringUtils; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.scheduling.annotation.Async; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; +import org.springframework.transaction.support.TransactionTemplate; +import com.aucma.production.mapper.MrpComponentWeeklyReqMapper; +import com.aucma.production.domain.MrpComponentWeeklyReq; +import com.aucma.production.service.IMrpComponentWeeklyReqService; + +/** + * 子件物料周需求Service业务层处理 + * + * @author Yinq + * @date 2026-01-05 + */ +@Service +public class MrpComponentWeeklyReqServiceImpl implements IMrpComponentWeeklyReqService +{ + @Autowired + private MrpComponentWeeklyReqMapper mrpComponentWeeklyReqMapper; + + @Autowired + private TransactionTemplate transactionTemplate; + + /** + * 查询子件物料周需求 + * + * @param id 子件物料周需求主键 + * @return 子件物料周需求 + */ + @Override + public MrpComponentWeeklyReq selectMrpComponentWeeklyReqById(Long id) + { + return mrpComponentWeeklyReqMapper.selectMrpComponentWeeklyReqById(id); + } + + /** + * 查询子件物料周需求列表 + * + * @param mrpComponentWeeklyReq 子件物料周需求 + * @return 子件物料周需求 + */ + @Override + public List selectMrpComponentWeeklyReqList(MrpComponentWeeklyReq mrpComponentWeeklyReq) + { + return mrpComponentWeeklyReqMapper.selectMrpComponentWeeklyReqList(mrpComponentWeeklyReq); + } + + /** + * 新增子件物料周需求 + * + * @param mrpComponentWeeklyReq 子件物料周需求 + * @return 结果 + */ + @Override + public int insertMrpComponentWeeklyReq(MrpComponentWeeklyReq mrpComponentWeeklyReq) + { + return mrpComponentWeeklyReqMapper.insertMrpComponentWeeklyReq(mrpComponentWeeklyReq); + } + + /** + * 修改子件物料周需求 + * + * @param mrpComponentWeeklyReq 子件物料周需求 + * @return 结果 + */ + @Override + public int updateMrpComponentWeeklyReq(MrpComponentWeeklyReq mrpComponentWeeklyReq) + { + return mrpComponentWeeklyReqMapper.updateMrpComponentWeeklyReq(mrpComponentWeeklyReq); + } + + /** + * 批量删除子件物料周需求 + * + * @param ids 需要删除的子件物料周需求主键 + * @return 结果 + */ + @Override + public int deleteMrpComponentWeeklyReqByIds(Long[] ids) + { + return mrpComponentWeeklyReqMapper.deleteMrpComponentWeeklyReqByIds(ids); + } + + /** + * 删除子件物料周需求信息 + * + * @param id 子件物料周需求主键 + * @return 结果 + */ + @Override + public int deleteMrpComponentWeeklyReqById(Long id) + { + return mrpComponentWeeklyReqMapper.deleteMrpComponentWeeklyReqById(id); + } + + /** + * 导入子件物料周需求数据(批量插入,事务性) + */ + @Override + @Transactional(rollbackFor = Exception.class) + public String importData(List list, boolean updateSupport, String operName, String weekStartDate) + { + if (StringUtils.isNull(list) || list.size() == 0) + { + throw new ServiceException("导入数据不能为空!"); + } + if (StringUtils.isEmpty(weekStartDate)) + { + throw new ServiceException("请选择周一日期!"); + } + // 解析周一日期并计算年第周 + Date mondayDate; + String yearWeek; + try + { + SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); + mondayDate = sdf.parse(weekStartDate); + Calendar cal = Calendar.getInstance(); + cal.setFirstDayOfWeek(Calendar.MONDAY); + cal.setMinimalDaysInFirstWeek(4); + cal.setTime(mondayDate); + int year = cal.get(Calendar.YEAR); + int week = cal.get(Calendar.WEEK_OF_YEAR); + yearWeek = String.format("%d%02d", year, week); + } + catch (Exception e) + { + throw new ServiceException("周一日期格式错误,请使用yyyy-MM-dd格式!"); + } + + // 预处理数据,校验并填充字段(跳过空行) + List validList = new ArrayList<>(); + int skipNum = 0; + Date now = new Date(); + + for (MrpComponentWeeklyReq item : list) + { + // 跳过物料编码为空的行(视为空行) + if (StringUtils.isEmpty(item.getItemCode())) + { + skipNum++; + continue; + } + // 自动填充年第周和周一日期 + item.setYearWeek(yearWeek); + item.setWeekStartDate(mondayDate); + item.setCreatedAt(now); + validList.add(item); + } + + if (validList.isEmpty()) + { + throw new ServiceException("没有有效的数据可导入!所有行的物料编码都为空。"); + } + + // 逐条插入(Oracle INSERT ALL不支持SEQUENCE.NEXTVAL) + int total = validList.size(); + int count = 0; + long startTime = System.currentTimeMillis(); + System.out.println("开始导入子件物料周需求,共 " + total + " 条数据"); + + for (MrpComponentWeeklyReq item : validList) + { + mrpComponentWeeklyReqMapper.insertMrpComponentWeeklyReq(item); + count++; + // 每500条打印进度 + if (count % 500 == 0) + { + long elapsed = (System.currentTimeMillis() - startTime) / 1000; + System.out.println("已导入 " + count + "/" + total + " 条,耗时 " + elapsed + " 秒"); + } + } + + long totalTime = (System.currentTimeMillis() - startTime) / 1000; + System.out.println("导入完成,共 " + total + " 条,总耗时 " + totalTime + " 秒"); + + String msg = "数据导入成功!共导入 " + total + " 条"; + if (skipNum > 0) + { + msg += ",跳过空行 " + skipNum + " 条"; + } + return msg; + } + + /** + * 异步导入子件物料周需求数据(不阻塞前端) + * 使用分批提交事务,避免长事务导致连接超时 + */ + @Async + @Override + public void importDataAsync(List list, boolean updateSupport, String operName, String weekStartDate) + { + System.out.println("========== 异步导入开始 =========="); + + // 解析周一日期和年第周 + String yearWeek; + Date mondayDate; + try + { + SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); + mondayDate = sdf.parse(weekStartDate); + Calendar cal = Calendar.getInstance(); + cal.setFirstDayOfWeek(Calendar.MONDAY); + cal.setMinimalDaysInFirstWeek(4); + cal.setTime(mondayDate); + int year = cal.get(Calendar.YEAR); + int week = cal.get(Calendar.WEEK_OF_YEAR); + yearWeek = String.format("%d%02d", year, week); + } + catch (Exception e) + { + System.out.println("异步导入失败: 周一日期格式错误"); + return; + } + + // 预处理数据 + List validList = new ArrayList<>(); + Date now = new Date(); + for (MrpComponentWeeklyReq item : list) + { + if (StringUtils.isEmpty(item.getItemCode())) + { + continue; + } + item.setYearWeek(yearWeek); + item.setWeekStartDate(mondayDate); + item.setCreatedAt(now); + validList.add(item); + } + + if (validList.isEmpty()) + { + System.out.println("异步导入失败: 没有有效数据"); + return; + } + + int total = validList.size(); + int batchSize = 500; // 每批500条提交一次事务 + int successCount = 0; + int failCount = 0; + long startTime = System.currentTimeMillis(); + + System.out.println("开始分批导入,共 " + total + " 条,每批 " + batchSize + " 条"); + + // 分批处理,每批独立事务 + for (int i = 0; i < total; i += batchSize) + { + int end = Math.min(i + batchSize, total); + List batch = validList.subList(i, end); + + try + { + // 使用事务模板,每批独立提交 + transactionTemplate.execute(status -> { + for (MrpComponentWeeklyReq item : batch) + { + mrpComponentWeeklyReqMapper.insertMrpComponentWeeklyReq(item); + } + return null; + }); + successCount += batch.size(); + } + catch (Exception e) + { + failCount += batch.size(); + System.out.println("批次 " + (i / batchSize + 1) + " 导入失败: " + e.getMessage()); + } + + // 打印进度 + long elapsed = (System.currentTimeMillis() - startTime) / 1000; + System.out.println("已处理 " + end + "/" + total + " 条,成功 " + successCount + ",失败 " + failCount + ",耗时 " + elapsed + " 秒"); + } + + long totalTime = (System.currentTimeMillis() - startTime) / 1000; + System.out.println("========== 异步导入完成 =========="); + System.out.println("总计: " + total + " 条,成功: " + successCount + ",失败: " + failCount + ",总耗时: " + totalTime + " 秒"); + } +} diff --git a/aucma-production/src/main/java/com/aucma/production/service/impl/MrpProdWeeklyPlanServiceImpl.java b/aucma-production/src/main/java/com/aucma/production/service/impl/MrpProdWeeklyPlanServiceImpl.java new file mode 100644 index 0000000..29bbbeb --- /dev/null +++ b/aucma-production/src/main/java/com/aucma/production/service/impl/MrpProdWeeklyPlanServiceImpl.java @@ -0,0 +1,189 @@ +package com.aucma.production.service.impl; + +import java.text.SimpleDateFormat; +import java.util.ArrayList; +import java.util.Calendar; +import java.util.Date; +import java.util.List; +import com.aucma.common.exception.ServiceException; +import com.aucma.common.utils.StringUtils; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; +import com.aucma.production.mapper.MrpProdWeeklyPlanMapper; +import com.aucma.production.domain.MrpProdWeeklyPlan; +import com.aucma.production.service.IMrpProdWeeklyPlanService; + +/** + * 周排产计划Service业务层处理 + * + * @author Yinq + * @date 2026-01-05 + */ +@Service +public class MrpProdWeeklyPlanServiceImpl implements IMrpProdWeeklyPlanService +{ + @Autowired + private MrpProdWeeklyPlanMapper mrpProdWeeklyPlanMapper; + + /** + * 查询周排产计划 + * + * @param id 周排产计划主键 + * @return 周排产计划 + */ + @Override + public MrpProdWeeklyPlan selectMrpProdWeeklyPlanById(Long id) + { + return mrpProdWeeklyPlanMapper.selectMrpProdWeeklyPlanById(id); + } + + /** + * 查询周排产计划列表 + * + * @param mrpProdWeeklyPlan 周排产计划 + * @return 周排产计划 + */ + @Override + public List selectMrpProdWeeklyPlanList(MrpProdWeeklyPlan mrpProdWeeklyPlan) + { + return mrpProdWeeklyPlanMapper.selectMrpProdWeeklyPlanList(mrpProdWeeklyPlan); + } + + /** + * 新增周排产计划 + * + * @param mrpProdWeeklyPlan 周排产计划 + * @return 结果 + */ + @Override + public int insertMrpProdWeeklyPlan(MrpProdWeeklyPlan mrpProdWeeklyPlan) + { + return mrpProdWeeklyPlanMapper.insertMrpProdWeeklyPlan(mrpProdWeeklyPlan); + } + + /** + * 修改周排产计划 + * + * @param mrpProdWeeklyPlan 周排产计划 + * @return 结果 + */ + @Override + public int updateMrpProdWeeklyPlan(MrpProdWeeklyPlan mrpProdWeeklyPlan) + { + return mrpProdWeeklyPlanMapper.updateMrpProdWeeklyPlan(mrpProdWeeklyPlan); + } + + /** + * 批量删除周排产计划 + * + * @param ids 需要删除的周排产计划主键 + * @return 结果 + */ + @Override + public int deleteMrpProdWeeklyPlanByIds(Long[] ids) + { + return mrpProdWeeklyPlanMapper.deleteMrpProdWeeklyPlanByIds(ids); + } + + /** + * 删除周排产计划信息 + * + * @param id 周排产计划主键 + * @return 结果 + */ + @Override + public int deleteMrpProdWeeklyPlanById(Long id) + { + return mrpProdWeeklyPlanMapper.deleteMrpProdWeeklyPlanById(id); + } + + /** + * 导入周排产计划数据(批量插入,事务性) + */ + @Override + @Transactional(rollbackFor = Exception.class) + public String importData(List list, boolean updateSupport, String operName, String weekStartDate) + { + if (StringUtils.isNull(list) || list.size() == 0) + { + throw new ServiceException("导入数据不能为空!"); + } + if (StringUtils.isEmpty(weekStartDate)) + { + throw new ServiceException("请选择周一日期!"); + } + // 解析周一日期并计算年第周 + Date mondayDate; + String yearWeek; + try + { + SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); + mondayDate = sdf.parse(weekStartDate); + Calendar cal = Calendar.getInstance(); + cal.setFirstDayOfWeek(Calendar.MONDAY); + cal.setMinimalDaysInFirstWeek(4); + cal.setTime(mondayDate); + int year = cal.get(Calendar.YEAR); + int week = cal.get(Calendar.WEEK_OF_YEAR); + yearWeek = String.format("%d%02d", year, week); + } + catch (Exception e) + { + throw new ServiceException("周一日期格式错误,请使用yyyy-MM-dd格式!"); + } + + // 预处理数据,校验并填充字段(跳过空行) + List validList = new ArrayList<>(); + int skipNum = 0; + Date now = new Date(); + + for (MrpProdWeeklyPlan item : list) + { + // 跳过编码为空的行(视为空行) + if (StringUtils.isEmpty(item.getItemCode())) + { + skipNum++; + continue; + } + // 自动填充年第周和周一日期 + item.setYearWeek(yearWeek); + item.setWeekStartDate(mondayDate); + item.setCreatedAt(now); + validList.add(item); + } + + if (validList.isEmpty()) + { + throw new ServiceException("没有有效的数据可导入!所有行的编码都为空。"); + } + + // 逐条插入(Oracle INSERT ALL不支持SEQUENCE.NEXTVAL) + int total = validList.size(); + int count = 0; + long startTime = System.currentTimeMillis(); + System.out.println("开始导入周排产计划,共 " + total + " 条数据"); + + for (MrpProdWeeklyPlan item : validList) + { + mrpProdWeeklyPlanMapper.insertMrpProdWeeklyPlan(item); + count++; + // 每500条打印进度 + if (count % 500 == 0) + { + long elapsed = (System.currentTimeMillis() - startTime) / 1000; + System.out.println("已导入 " + count + "/" + total + " 条,耗时 " + elapsed + " 秒"); + } + } + + long totalTime = (System.currentTimeMillis() - startTime) / 1000; + System.out.println("导入完成,共 " + total + " 条,总耗时 " + totalTime + " 秒"); + + String msg = "数据导入成功!共导入 " + total + " 条"; + if (skipNum > 0) + { + msg += ",跳过空行 " + skipNum + " 条"; + } + return msg; + } +} diff --git a/aucma-production/src/main/resources/mapper/production/MrpComponentWeeklyReqMapper.xml b/aucma-production/src/main/resources/mapper/production/MrpComponentWeeklyReqMapper.xml new file mode 100644 index 0000000..9e8afd0 --- /dev/null +++ b/aucma-production/src/main/resources/mapper/production/MrpComponentWeeklyReqMapper.xml @@ -0,0 +1,137 @@ + + + + + + + + + + + + + + + + + + + + + + + + select id, year_week, week_start_date, item_code, item_desc, req_mon, req_tue, req_wed, req_thu, req_fri, req_sat, req_sun, req_week_total, created_at, updated_at from mrp_component_weekly_req + + + + + + + + + SELECT seq_mrp_component_weekly_req.NEXTVAL as id FROM DUAL + + insert into mrp_component_weekly_req + + id, + year_week, + week_start_date, + item_code, + item_desc, + req_mon, + req_tue, + req_wed, + req_thu, + req_fri, + req_sat, + req_sun, + req_week_total, + created_at, + updated_at, + + + #{id}, + #{yearWeek}, + #{weekStartDate}, + #{itemCode}, + #{itemDesc}, + #{reqMon}, + #{reqTue}, + #{reqWed}, + #{reqThu}, + #{reqFri}, + #{reqSat}, + #{reqSun}, + #{reqWeekTotal}, + #{createdAt}, + #{updatedAt}, + + + + + update mrp_component_weekly_req + + year_week = #{yearWeek}, + week_start_date = #{weekStartDate}, + item_code = #{itemCode}, + item_desc = #{itemDesc}, + req_mon = #{reqMon}, + req_tue = #{reqTue}, + req_wed = #{reqWed}, + req_thu = #{reqThu}, + req_fri = #{reqFri}, + req_sat = #{reqSat}, + req_sun = #{reqSun}, + + created_at = #{createdAt}, + updated_at = #{updatedAt}, + + where id = #{id} + + + + delete from mrp_component_weekly_req where id = #{id} + + + + delete from mrp_component_weekly_req where id in + + #{id,jdbcType=NUMERIC} + + + + + INSERT ALL + + INTO mrp_component_weekly_req (id, year_week, week_start_date, item_code, item_desc, req_mon, req_tue, req_wed, req_thu, req_fri, req_sat, req_sun, created_at) + VALUES (seq_mrp_component_weekly_req.NEXTVAL, #{item.yearWeek,jdbcType=VARCHAR}, #{item.weekStartDate,jdbcType=DATE}, #{item.itemCode,jdbcType=VARCHAR}, #{item.itemDesc,jdbcType=VARCHAR}, #{item.reqMon,jdbcType=NUMERIC}, #{item.reqTue,jdbcType=NUMERIC}, #{item.reqWed,jdbcType=NUMERIC}, #{item.reqThu,jdbcType=NUMERIC}, #{item.reqFri,jdbcType=NUMERIC}, #{item.reqSat,jdbcType=NUMERIC}, #{item.reqSun,jdbcType=NUMERIC}, #{item.createdAt,jdbcType=TIMESTAMP}) + + SELECT 1 FROM DUAL + + \ No newline at end of file diff --git a/aucma-production/src/main/resources/mapper/production/MrpProdWeeklyPlanMapper.xml b/aucma-production/src/main/resources/mapper/production/MrpProdWeeklyPlanMapper.xml new file mode 100644 index 0000000..61c9ef5 --- /dev/null +++ b/aucma-production/src/main/resources/mapper/production/MrpProdWeeklyPlanMapper.xml @@ -0,0 +1,157 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + select id, year_week, week_start_date, seq_no, item_code, item_desc, plant_code, order_no, order_line_no, plan_d1, plan_d2, plan_d3, plan_d4, plan_d5, plan_d6, plan_d7, plan_week_total, created_at, updated_at from mrp_prod_weekly_plan + + + + + + + + + SELECT seq_mrp_prod_weekly_plan.NEXTVAL as id FROM DUAL + + insert into mrp_prod_weekly_plan + + id, + year_week, + week_start_date, + seq_no, + item_code, + item_desc, + plant_code, + order_no, + order_line_no, + plan_d1, + plan_d2, + plan_d3, + plan_d4, + plan_d5, + plan_d6, + plan_d7, + plan_week_total, + created_at, + updated_at, + + + #{id}, + #{yearWeek}, + #{weekStartDate}, + #{seqNo}, + #{itemCode}, + #{itemDesc}, + #{plantCode}, + #{orderNo}, + #{orderLineNo}, + #{planD1}, + #{planD2}, + #{planD3}, + #{planD4}, + #{planD5}, + #{planD6}, + #{planD7}, + #{planWeekTotal}, + #{createdAt}, + #{updatedAt}, + + + + + update mrp_prod_weekly_plan + + year_week = #{yearWeek}, + week_start_date = #{weekStartDate}, + seq_no = #{seqNo}, + item_code = #{itemCode}, + item_desc = #{itemDesc}, + plant_code = #{plantCode}, + order_no = #{orderNo}, + order_line_no = #{orderLineNo}, + plan_d1 = #{planD1}, + plan_d2 = #{planD2}, + plan_d3 = #{planD3}, + plan_d4 = #{planD4}, + plan_d5 = #{planD5}, + plan_d6 = #{planD6}, + plan_d7 = #{planD7}, + + created_at = #{createdAt}, + updated_at = #{updatedAt}, + + where id = #{id} + + + + delete from mrp_prod_weekly_plan where id = #{id} + + + + delete from mrp_prod_weekly_plan where id in + + #{id,jdbcType=NUMERIC} + + + + + INSERT ALL + + INTO mrp_prod_weekly_plan (id, year_week, week_start_date, seq_no, item_code, item_desc, plant_code, order_no, order_line_no, plan_d1, plan_d2, plan_d3, plan_d4, plan_d5, plan_d6, plan_d7, created_at) + VALUES (seq_mrp_prod_weekly_plan.NEXTVAL, #{item.yearWeek,jdbcType=VARCHAR}, #{item.weekStartDate,jdbcType=DATE}, #{item.seqNo,jdbcType=NUMERIC}, #{item.itemCode,jdbcType=VARCHAR}, #{item.itemDesc,jdbcType=VARCHAR}, #{item.plantCode,jdbcType=VARCHAR}, #{item.orderNo,jdbcType=VARCHAR}, #{item.orderLineNo,jdbcType=VARCHAR}, #{item.planD1,jdbcType=NUMERIC}, #{item.planD2,jdbcType=NUMERIC}, #{item.planD3,jdbcType=NUMERIC}, #{item.planD4,jdbcType=NUMERIC}, #{item.planD5,jdbcType=NUMERIC}, #{item.planD6,jdbcType=NUMERIC}, #{item.planD7,jdbcType=NUMERIC}, #{item.createdAt,jdbcType=TIMESTAMP}) + + SELECT 1 FROM DUAL + + \ No newline at end of file