diff --git a/sql/mysql/test.md b/sql/mysql/test.md new file mode 100644 index 000000000..c24286ee4 --- /dev/null +++ b/sql/mysql/test.md @@ -0,0 +1,49 @@ +```mysql +CREATE VIEW `mes_view_report_plan_detail` AS SELECT +`wp`.`id` AS `id`, +`wp`.`report_id` AS `report_id`, +`wp`.`plan_id` AS `plan_id`, +`wp`.`product_id` AS `product_id`, +`wp`.`quality_number_plan` AS `quality_number_plan`, +`wp`.`waste_number_plan` AS `waste_number_plan`, +`pd`.`user_id` AS `user_id`, + +`pd`.`org_type` AS `org_type`, +`pd`.`org_id` AS `org_id`, + +`pd`.`report_date` AS `report_date`, + +FROM + ( + `mes_work_report_plan` `wp` + JOIN `mes_produce_report_detail` `pd` ON (( + `wp`.`report_id` = `pd`.`id` + ))) +``` +存在视图,显示工人生产报工产品数量分配给计划的详细情况, +report_id是报工单id,plan_id是计划id,product_id是产品id,quality_number_plan是分配给计划的合格产品数量, +waste_number_plan是分配给计划的不合格产品数量,user_id是工人id,org_type是工序类别,report_date是报工日期 +现在请你编写mysql的sql语句,基于这个视图创建另一个视图,汇总同一个计划,同一个产品,同一个工序的合格产品数和不合格产品数, + +要基于现有的mes_view_report_plan_detail视图创建另一个视图,汇总同一个计划、同一个产品和同一个工序的合格产品数和不合格产品数,你可以使用MySQL的GROUP BY和聚合函数来实现。以下是编写的SQL语句示例: + +```mysql +CREATE VIEW `mes_view_summary_report` AS +SELECT +`plan_id`, +`product_id`, +`org_type`, +SUM(`quality_number_plan`) AS `total_quality_number`, +SUM(`waste_number_plan`) AS `total_waste_number` +FROM +`mes_view_report_plan_detail` +GROUP BY +`plan_id`, `product_id`, `org_type`; +``` +在这个SQL语句中: + +创建了一个名为mes_view_summary_report的新视图。 +从现有的mes_view_report_plan_detail视图中选择plan_id、product_id、org_type以及分配给计划的合格产品数量和不合格产品数量字段。 +使用SUM()函数对合格产品数量和不合格产品数量进行求和,得到同一个计划、同一个产品和同一个工序的总合格产品数和不合格产品数。 +最后,使用GROUP BY子句按plan_id、product_id和org_type分组,确保针对相同计划、产品和工序的记录被聚合在一起。 +通过这个SQL语句,你可以创建一个新的视图mes_view_summary_report,用于汇总同一个计划、同一个产品和同一个工序的合格产品数和不合格产品数的信息 \ No newline at end of file diff --git a/sql/mysql/view.sql b/sql/mysql/view.sql new file mode 100644 index 000000000..e551b5527 --- /dev/null +++ b/sql/mysql/view.sql @@ -0,0 +1,30 @@ +CREATE VIEW `mes_view_report_plan_detail` AS +SELECT `wp`.`id` AS `id`, + `wp`.`report_id` AS `report_id`, + `wp`.`plan_id` AS `plan_id`, + `wp`.`product_id` AS `product_id`, + `wp`.`quality_number_plan` AS `quality_number_plan`, + `wp`.`waste_number_plan` AS `waste_number_plan`, + `wp`.`report_time_plan` AS `report_time_plan`, + `wp`.`total_time_plan` AS `total_time_plan`, + `wp`.`creator` AS `creator`, + `wp`.`create_time` AS `create_time`, + `wp`.`updater` AS `updater`, + `wp`.`update_time` AS `update_time`, + `wp`.`deleted` AS `deleted`, + `wp`.`tenant_id` AS `tenant_id`, + `pd`.`user_id` AS `user_id`, + `pd`.`report_type` AS `report_type`, + `pd`.`group_type` AS `group_type`, + `pd`.`org_type` AS `org_type`, + `pd`.`org_id` AS `org_id`, + `pd`.`quality_number` AS `quality_number`, + `pd`.`waste_number` AS `waste_number`, + `pd`.`report_date` AS `report_date`, + `pd`.`report_status` AS `report_status`, + `pd`.`creator` AS `report_creator` +FROM ( + `mes_work_report_plan` `wp` + JOIN `mes_produce_report_detail` `pd` ON (( + `wp`.`report_id` = `pd`.`id` + ))) \ No newline at end of file diff --git a/yudao-module-mes/yudao-module-mes-api/src/main/java/cn/iocoder/yudao/module/mes/enums/ErrorCodeConstants.java b/yudao-module-mes/yudao-module-mes-api/src/main/java/cn/iocoder/yudao/module/mes/enums/ErrorCodeConstants.java index 12d1216f3..b0355cb41 100644 --- a/yudao-module-mes/yudao-module-mes-api/src/main/java/cn/iocoder/yudao/module/mes/enums/ErrorCodeConstants.java +++ b/yudao-module-mes/yudao-module-mes-api/src/main/java/cn/iocoder/yudao/module/mes/enums/ErrorCodeConstants.java @@ -60,4 +60,5 @@ public interface ErrorCodeConstants { ErrorCode PRODUCE_REPORT_CHANGE_RECORD_NOT_EXISTS = new ErrorCode(5_0084, "报工变更记录不存在"); ErrorCode WORK_REPORT_PLAN_NOT_EXISTS = new ErrorCode(5_0085, "报工分配计划不存在"); + } diff --git a/yudao-module-mes/yudao-module-mes-biz/src/main/java/cn/iocoder/yudao/module/mes/controller/admin/orgworker/OrgWorkerController.java b/yudao-module-mes/yudao-module-mes-biz/src/main/java/cn/iocoder/yudao/module/mes/controller/admin/orgworker/OrgWorkerController.java index 6559ea540..fd4530721 100644 --- a/yudao-module-mes/yudao-module-mes-biz/src/main/java/cn/iocoder/yudao/module/mes/controller/admin/orgworker/OrgWorkerController.java +++ b/yudao-module-mes/yudao-module-mes-biz/src/main/java/cn/iocoder/yudao/module/mes/controller/admin/orgworker/OrgWorkerController.java @@ -6,6 +6,7 @@ import cn.iocoder.yudao.framework.common.pojo.PageParam; import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.framework.common.util.object.BeanUtils; import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils; +import cn.iocoder.yudao.module.mes.controller.admin.organization.vo.OrganizationListReqVO; import cn.iocoder.yudao.module.mes.controller.admin.orgworker.vo.OrgWorkerPageReqVO; import cn.iocoder.yudao.module.mes.controller.admin.orgworker.vo.OrgWorkerRespVO; import cn.iocoder.yudao.module.mes.controller.admin.orgworker.vo.OrgWorkerSaveReqVO; @@ -167,20 +168,22 @@ public class OrgWorkerController { pageReqVO.setWorkDate(localDateTimes); pageReqVO.setWorkerId(reqVO.getUserId()); - Long userId = getLoginUserId(); - List detailDOList = workTeamService.getUserWorkTeamDetail(userId, WorkTeamUserRoleEnum.组长.getValue()); - //组长的话把这些组的工人列表都查上,其他人所有人都查 - List workTeamIds =null; - if(detailDOList!=null && detailDOList.size()>0){ - workTeamIds = detailDOList.stream().map(WorkTeamDetailDO::getWorkTeamId).collect(Collectors.toList()); - } - List workTeamDetailDOS = workTeamService.getDetailByWorkTeamIds(workTeamIds); - Set idsSet = convertSet(workTeamDetailDOS, WorkTeamDetailDO::getUserId); - - List ids = new ArrayList<>(); - if(idsSet!=null && idsSet.size()>0){ - ids = new ArrayList<>(idsSet); - } + OrganizationListReqVO listReqVO = new OrganizationListReqVO().setOrgType(reqVO.getOrgType()); + List orgList = organizationService.getOrganizationList(listReqVO); + List orgIds = orgList.stream().map(OrganizationDO::getId).collect(Collectors.toList()); + pageReqVO.setOrgIds(orgIds); +// Long userId = getLoginUserId(); +// List detailDOList = workTeamService.getUserWorkTeamDetail(userId, WorkTeamUserRoleEnum.组长.getValue()); +// //组长的话把这些组的工人列表都查上,其他人所有人都查 +// List workTeamIds =null; +// if(detailDOList!=null && detailDOList.size()>0){ +// workTeamIds = detailDOList.stream().map(WorkTeamDetailDO::getWorkTeamId).collect(Collectors.toList()); +// } +// List workTeamDetailDOS = workTeamService.getDetailByWorkTeamIds(workTeamIds); +// Set idsSet = convertSet(workTeamDetailDOS, WorkTeamDetailDO::getUserId); + + List list = orgWorkerService.getOrgWorkerByReportResVo(pageReqVO); + List ids = list.stream().map(OrgWorkerDO::getWorkerId).collect(Collectors.toList()); Map userMap = adminUserApi.getUserMap(ids); return success(new ArrayList<>(userMap.values())); } diff --git a/yudao-module-mes/yudao-module-mes-biz/src/main/java/cn/iocoder/yudao/module/mes/controller/admin/plan/vo/PlanRespVO.java b/yudao-module-mes/yudao-module-mes-biz/src/main/java/cn/iocoder/yudao/module/mes/controller/admin/plan/vo/PlanRespVO.java index 9945fecd3..ee3d759f4 100644 --- a/yudao-module-mes/yudao-module-mes-biz/src/main/java/cn/iocoder/yudao/module/mes/controller/admin/plan/vo/PlanRespVO.java +++ b/yudao-module-mes/yudao-module-mes-biz/src/main/java/cn/iocoder/yudao/module/mes/controller/admin/plan/vo/PlanRespVO.java @@ -95,4 +95,10 @@ public class PlanRespVO { */ @Schema(description = "派工单ID") private Long requisitionId; + + /** + * 优先级,同种产品的优先级,数字越大,排序越靠前,越早分配完成数量 + */ + @Schema(description = "优先级") + private Long priorityNum; } \ No newline at end of file diff --git a/yudao-module-mes/yudao-module-mes-biz/src/main/java/cn/iocoder/yudao/module/mes/controller/admin/plan/vo/PlanSaveReqVO.java b/yudao-module-mes/yudao-module-mes-biz/src/main/java/cn/iocoder/yudao/module/mes/controller/admin/plan/vo/PlanSaveReqVO.java index 8f813d623..2afafc212 100644 --- a/yudao-module-mes/yudao-module-mes-biz/src/main/java/cn/iocoder/yudao/module/mes/controller/admin/plan/vo/PlanSaveReqVO.java +++ b/yudao-module-mes/yudao-module-mes-biz/src/main/java/cn/iocoder/yudao/module/mes/controller/admin/plan/vo/PlanSaveReqVO.java @@ -61,4 +61,10 @@ public class PlanSaveReqVO { private Boolean isEnable; @Schema(description = "制浆线") private String feedingPipeline; + + /** + * 优先级,同种产品的优先级,数字越大,排序越靠前,越早分配完成数量 + */ + @Schema(description = "优先级") + private Long priorityNum; } \ No newline at end of file diff --git a/yudao-module-mes/yudao-module-mes-biz/src/main/java/cn/iocoder/yudao/module/mes/controller/admin/producereportplan/WorkReportPlanController.java b/yudao-module-mes/yudao-module-mes-biz/src/main/java/cn/iocoder/yudao/module/mes/controller/admin/producereportplan/WorkReportPlanController.java index 188c81a79..a400484d1 100644 --- a/yudao-module-mes/yudao-module-mes-biz/src/main/java/cn/iocoder/yudao/module/mes/controller/admin/producereportplan/WorkReportPlanController.java +++ b/yudao-module-mes/yudao-module-mes-biz/src/main/java/cn/iocoder/yudao/module/mes/controller/admin/producereportplan/WorkReportPlanController.java @@ -6,15 +6,12 @@ import cn.iocoder.yudao.framework.common.pojo.PageParam; import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.framework.common.util.object.BeanUtils; import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils; -import cn.iocoder.yudao.module.mes.controller.admin.producereportplan.vo.WorkReportPlanPageReqVO; -import cn.iocoder.yudao.module.mes.controller.admin.producereportplan.vo.WorkReportPlanRespVO; -import cn.iocoder.yudao.module.mes.controller.admin.producereportplan.vo.WorkReportPlanSaveReqVO; +import cn.iocoder.yudao.module.mes.controller.admin.producereportplan.vo.*; import cn.iocoder.yudao.module.mes.dal.dataobject.workreportplan.WorkReportPlanDO; import cn.iocoder.yudao.module.mes.service.workreportplan.WorkReportPlanService; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.Parameter; import io.swagger.v3.oas.annotations.tags.Tag; -import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.*; @@ -38,14 +35,14 @@ public class WorkReportPlanController { @PostMapping("/create") @Operation(summary = "创建报工分配计划") - @PreAuthorize("@ss.hasPermission('mes:work-report-plan:create')") + //@PreAuthorize("@ss.hasPermission('mes:work-report-plan:create')") public CommonResult createWorkReportPlan(@Valid @RequestBody WorkReportPlanSaveReqVO createReqVO) { return success(workReportPlanService.createWorkReportPlan(createReqVO)); } @PutMapping("/update") @Operation(summary = "更新报工分配计划") - @PreAuthorize("@ss.hasPermission('mes:work-report-plan:update')") + //@PreAuthorize("@ss.hasPermission('mes:work-report-plan:update')") public CommonResult updateWorkReportPlan(@Valid @RequestBody WorkReportPlanSaveReqVO updateReqVO) { workReportPlanService.updateWorkReportPlan(updateReqVO); return success(true); @@ -54,7 +51,7 @@ public class WorkReportPlanController { @DeleteMapping("/delete") @Operation(summary = "删除报工分配计划") @Parameter(name = "id", description = "编号", required = true) - @PreAuthorize("@ss.hasPermission('mes:work-report-plan:delete')") + //@PreAuthorize("@ss.hasPermission('mes:work-report-plan:delete')") public CommonResult deleteWorkReportPlan(@RequestParam("id") Long id) { workReportPlanService.deleteWorkReportPlan(id); return success(true); @@ -63,7 +60,7 @@ public class WorkReportPlanController { @GetMapping("/get") @Operation(summary = "获得报工分配计划") @Parameter(name = "id", description = "编号", required = true, example = "1024") - @PreAuthorize("@ss.hasPermission('mes:work-report-plan:query')") + //@PreAuthorize("@ss.hasPermission('mes:work-report-plan:query')") public CommonResult getWorkReportPlan(@RequestParam("id") Long id) { WorkReportPlanDO workReportPlan = workReportPlanService.getWorkReportPlan(id); return success(BeanUtils.toBean(workReportPlan, WorkReportPlanRespVO.class)); @@ -71,15 +68,22 @@ public class WorkReportPlanController { @GetMapping("/page") @Operation(summary = "获得报工分配计划分页") - @PreAuthorize("@ss.hasPermission('mes:work-report-plan:query')") + //@PreAuthorize("@ss.hasPermission('mes:work-report-plan:query')") public CommonResult> getWorkReportPlanPage(@Valid WorkReportPlanPageReqVO pageReqVO) { PageResult pageResult = workReportPlanService.getWorkReportPlanPage(pageReqVO); return success(BeanUtils.toBean(pageResult, WorkReportPlanRespVO.class)); + } + @GetMapping("/pageView") + @Operation(summary = "获得报工分配计划分页") + //@PreAuthorize("@ss.hasPermission('mes:work-report-plan:query')") + public CommonResult> pageView(@Valid ReportPlanViewReqVO pageReqVO) { + PageResult pageResult = workReportPlanService.getReportPlanViewPage(pageReqVO); + return success(pageResult); } @GetMapping("/export-excel") @Operation(summary = "导出报工分配计划 Excel") - @PreAuthorize("@ss.hasPermission('mes:work-report-plan:export')") + //@PreAuthorize("@ss.hasPermission('mes:work-report-plan:export')") @ApiAccessLog(operateType = EXPORT) public void exportWorkReportPlanExcel(@Valid WorkReportPlanPageReqVO pageReqVO, HttpServletResponse response) throws IOException { diff --git a/yudao-module-mes/yudao-module-mes-biz/src/main/java/cn/iocoder/yudao/module/mes/controller/admin/producereportplan/vo/ReportPlanViewReqVO.java b/yudao-module-mes/yudao-module-mes-biz/src/main/java/cn/iocoder/yudao/module/mes/controller/admin/producereportplan/vo/ReportPlanViewReqVO.java index be79fd2a0..3c7616a34 100644 --- a/yudao-module-mes/yudao-module-mes-biz/src/main/java/cn/iocoder/yudao/module/mes/controller/admin/producereportplan/vo/ReportPlanViewReqVO.java +++ b/yudao-module-mes/yudao-module-mes-biz/src/main/java/cn/iocoder/yudao/module/mes/controller/admin/producereportplan/vo/ReportPlanViewReqVO.java @@ -34,7 +34,7 @@ public class ReportPlanViewReqVO extends PageParam { private BigDecimal wasteNumberPlan; @Schema(description = "计件时间") - private String reportTimePlan; + private BigDecimal reportTimePlan; @Schema(description = "总时长") private BigDecimal totalTimePlan; diff --git a/yudao-module-mes/yudao-module-mes-biz/src/main/java/cn/iocoder/yudao/module/mes/controller/admin/producereportplan/vo/ReportPlanViewRespVO.java b/yudao-module-mes/yudao-module-mes-biz/src/main/java/cn/iocoder/yudao/module/mes/controller/admin/producereportplan/vo/ReportPlanViewRespVO.java index f10a107c6..442f25696 100644 --- a/yudao-module-mes/yudao-module-mes-biz/src/main/java/cn/iocoder/yudao/module/mes/controller/admin/producereportplan/vo/ReportPlanViewRespVO.java +++ b/yudao-module-mes/yudao-module-mes-biz/src/main/java/cn/iocoder/yudao/module/mes/controller/admin/producereportplan/vo/ReportPlanViewRespVO.java @@ -24,8 +24,10 @@ public class ReportPlanViewRespVO { private Long reportId; @Schema(description = "计划id", example = "30035") - @ExcelProperty("计划id") private Long planId; + @Schema(description = "计划id", example = "30035") + @ExcelProperty("计划") + private String planCode; @Schema(description = "产品ID", requiredMode = Schema.RequiredMode.REQUIRED, example = "14517") private Long productId; @@ -43,7 +45,7 @@ public class ReportPlanViewRespVO { @Schema(description = "计件时间") @ExcelProperty("计件时间") - private String reportTimePlan; + private BigDecimal reportTimePlan; @Schema(description = "总时长") @ExcelProperty("总时长") diff --git a/yudao-module-mes/yudao-module-mes-biz/src/main/java/cn/iocoder/yudao/module/mes/controller/admin/producereportplan/vo/WorkReportPlanPageReqVO.java b/yudao-module-mes/yudao-module-mes-biz/src/main/java/cn/iocoder/yudao/module/mes/controller/admin/producereportplan/vo/WorkReportPlanPageReqVO.java index 9b613c96b..d04aed996 100644 --- a/yudao-module-mes/yudao-module-mes-biz/src/main/java/cn/iocoder/yudao/module/mes/controller/admin/producereportplan/vo/WorkReportPlanPageReqVO.java +++ b/yudao-module-mes/yudao-module-mes-biz/src/main/java/cn/iocoder/yudao/module/mes/controller/admin/producereportplan/vo/WorkReportPlanPageReqVO.java @@ -34,7 +34,7 @@ public class WorkReportPlanPageReqVO extends PageParam { private BigDecimal wasteNumberPlan; @Schema(description = "计件时间") - private String reportTimePlan; + private BigDecimal reportTimePlan; @Schema(description = "总时长") private BigDecimal totalTimePlan; diff --git a/yudao-module-mes/yudao-module-mes-biz/src/main/java/cn/iocoder/yudao/module/mes/controller/admin/producereportplan/vo/WorkReportPlanRespVO.java b/yudao-module-mes/yudao-module-mes-biz/src/main/java/cn/iocoder/yudao/module/mes/controller/admin/producereportplan/vo/WorkReportPlanRespVO.java index 22a545c74..4b5f1f470 100644 --- a/yudao-module-mes/yudao-module-mes-biz/src/main/java/cn/iocoder/yudao/module/mes/controller/admin/producereportplan/vo/WorkReportPlanRespVO.java +++ b/yudao-module-mes/yudao-module-mes-biz/src/main/java/cn/iocoder/yudao/module/mes/controller/admin/producereportplan/vo/WorkReportPlanRespVO.java @@ -18,16 +18,22 @@ public class WorkReportPlanRespVO { private Long id; @Schema(description = "报工单id", example = "27172") - @ExcelProperty("报工单id") private Long reportId; + @Schema(description = "报工单", example = "27172") + @ExcelProperty("报工单") + private String reportCode; @Schema(description = "计划id", example = "30035") - @ExcelProperty("计划id") private Long planId; + @Schema(description = "计划id", example = "30035") + @ExcelProperty("计划") + private String planCode; @Schema(description = "产品ID", example = "9987") - @ExcelProperty("产品ID") private Long productId; + @Schema(description = "产品ID", example = "9987") + @ExcelProperty("产品") + private String productName; @Schema(description = "成品数量") @ExcelProperty("成品数量") @@ -39,7 +45,7 @@ public class WorkReportPlanRespVO { @Schema(description = "计件时间") @ExcelProperty("计件时间") - private String reportTimePlan; + private BigDecimal reportTimePlan; @Schema(description = "总时长") @ExcelProperty("总时长") diff --git a/yudao-module-mes/yudao-module-mes-biz/src/main/java/cn/iocoder/yudao/module/mes/controller/admin/producereportplan/vo/WorkReportPlanSaveReqVO.java b/yudao-module-mes/yudao-module-mes-biz/src/main/java/cn/iocoder/yudao/module/mes/controller/admin/producereportplan/vo/WorkReportPlanSaveReqVO.java index 3efaa221a..0625d5741 100644 --- a/yudao-module-mes/yudao-module-mes-biz/src/main/java/cn/iocoder/yudao/module/mes/controller/admin/producereportplan/vo/WorkReportPlanSaveReqVO.java +++ b/yudao-module-mes/yudao-module-mes-biz/src/main/java/cn/iocoder/yudao/module/mes/controller/admin/producereportplan/vo/WorkReportPlanSaveReqVO.java @@ -28,7 +28,7 @@ public class WorkReportPlanSaveReqVO { private BigDecimal wasteNumberPlan; @Schema(description = "计件时间") - private String reportTimePlan; + private BigDecimal reportTimePlan; @Schema(description = "总时长") private BigDecimal totalTimePlan; diff --git a/yudao-module-mes/yudao-module-mes-biz/src/main/java/cn/iocoder/yudao/module/mes/controller/admin/stockindetail/StockInDetailController.java b/yudao-module-mes/yudao-module-mes-biz/src/main/java/cn/iocoder/yudao/module/mes/controller/admin/stockindetail/StockInDetailController.java index 848d8299e..7bed19c5e 100644 --- a/yudao-module-mes/yudao-module-mes-biz/src/main/java/cn/iocoder/yudao/module/mes/controller/admin/stockindetail/StockInDetailController.java +++ b/yudao-module-mes/yudao-module-mes-biz/src/main/java/cn/iocoder/yudao/module/mes/controller/admin/stockindetail/StockInDetailController.java @@ -92,4 +92,12 @@ public class StockInDetailController { BeanUtils.toBean(list, StockInDetailRespVO.class)); } + @PutMapping("/updateStockInStatus") + @Operation(summary = "更新生产入库单的状态") + @PreAuthorize("@ss.hasPermission('erp:stock-in:update-status')") + public CommonResult updateStockInStatus(@RequestParam("id") Long id, + @RequestParam("status") Integer status) { + stockInDetailService.updateStockInStatus(id, status); + return success(true); + } } \ No newline at end of file diff --git a/yudao-module-mes/yudao-module-mes-biz/src/main/java/cn/iocoder/yudao/module/mes/controller/admin/stockworkshop/vo/StockWorkshopDetailRespVO.java b/yudao-module-mes/yudao-module-mes-biz/src/main/java/cn/iocoder/yudao/module/mes/controller/admin/stockworkshop/vo/StockWorkshopDetailRespVO.java index 3a548e810..1082707e3 100644 --- a/yudao-module-mes/yudao-module-mes-biz/src/main/java/cn/iocoder/yudao/module/mes/controller/admin/stockworkshop/vo/StockWorkshopDetailRespVO.java +++ b/yudao-module-mes/yudao-module-mes-biz/src/main/java/cn/iocoder/yudao/module/mes/controller/admin/stockworkshop/vo/StockWorkshopDetailRespVO.java @@ -65,6 +65,9 @@ public class StockWorkshopDetailRespVO { @Schema(description = "操作人员", requiredMode = Schema.RequiredMode.REQUIRED, example = "26362") @ExcelProperty("操作人员") private String userName; + @Schema(description = "操作人员", requiredMode = Schema.RequiredMode.REQUIRED, example = "26362") + @ExcelProperty("操作人员") + private String creator; @Schema(description = "单据时间") @ExcelProperty("单据时间") diff --git a/yudao-module-mes/yudao-module-mes-biz/src/main/java/cn/iocoder/yudao/module/mes/dal/dataobject/plan/PlanDO.java b/yudao-module-mes/yudao-module-mes-biz/src/main/java/cn/iocoder/yudao/module/mes/dal/dataobject/plan/PlanDO.java index acbab4dde..a9465e102 100644 --- a/yudao-module-mes/yudao-module-mes-biz/src/main/java/cn/iocoder/yudao/module/mes/dal/dataobject/plan/PlanDO.java +++ b/yudao-module-mes/yudao-module-mes-biz/src/main/java/cn/iocoder/yudao/module/mes/dal/dataobject/plan/PlanDO.java @@ -94,4 +94,9 @@ public class PlanDO extends BaseDO { * 对应的派工单ID */ private Long requisitionId; + + /** + * 优先级,同种产品的优先级,数字越大,排序越靠前,越早分配完成数量 + */ + private Long priorityNum; } \ No newline at end of file diff --git a/yudao-module-mes/yudao-module-mes-biz/src/main/java/cn/iocoder/yudao/module/mes/dal/dataobject/producereport/ProduceReportDetailDO.java b/yudao-module-mes/yudao-module-mes-biz/src/main/java/cn/iocoder/yudao/module/mes/dal/dataobject/producereport/ProduceReportDetailDO.java index 633d7ad20..79ed065b8 100644 --- a/yudao-module-mes/yudao-module-mes-biz/src/main/java/cn/iocoder/yudao/module/mes/dal/dataobject/producereport/ProduceReportDetailDO.java +++ b/yudao-module-mes/yudao-module-mes-biz/src/main/java/cn/iocoder/yudao/module/mes/dal/dataobject/producereport/ProduceReportDetailDO.java @@ -101,7 +101,7 @@ public class ProduceReportDetailDO extends BaseDO { /** * 计件时间 */ - private String reportTime; + private BigDecimal reportTime; /** * 报工状态 *

diff --git a/yudao-module-mes/yudao-module-mes-biz/src/main/java/cn/iocoder/yudao/module/mes/dal/dataobject/workreportplan/ReportPlanSummaryDO.java b/yudao-module-mes/yudao-module-mes-biz/src/main/java/cn/iocoder/yudao/module/mes/dal/dataobject/workreportplan/ReportPlanSummaryDO.java new file mode 100644 index 000000000..0886e7291 --- /dev/null +++ b/yudao-module-mes/yudao-module-mes-biz/src/main/java/cn/iocoder/yudao/module/mes/dal/dataobject/workreportplan/ReportPlanSummaryDO.java @@ -0,0 +1,53 @@ +package cn.iocoder.yudao.module.mes.dal.dataobject.workreportplan; + +import com.baomidou.mybatisplus.annotation.KeySequence; +import com.baomidou.mybatisplus.annotation.TableName; +import lombok.*; + +import java.math.BigDecimal; + +/** + * 报工分配计划 DO + * + * @author 内蒙必硕 + */ +@TableName("mes_view_report_plan_summary") +@KeySequence("mes_view_report_plan_summary_seq") // 用于 Oracle、PostgreSQL、Kingbase、DB2、H2 数据库的主键自增。如果是 MySQL 等数据库,可不写。 +@Data +@ToString(callSuper = true) +@Builder +@NoArgsConstructor +@AllArgsConstructor +public class ReportPlanSummaryDO { + + /** + * 计划id + */ + private Long planId; + /** + * 产品ID + */ + private Long productId; + /** + * 工序类型 + */ + private String orgType; + /** + * 成品数量 + */ + private BigDecimal totalQualityNumber; + /** + * 废品数量 + */ + private BigDecimal totalWasteNumber; + /** + * 计件时间 + */ + private BigDecimal reportTimeSummary; + /** + * 总时长 + */ + private BigDecimal totalTimeSummary; + + +} \ No newline at end of file diff --git a/yudao-module-mes/yudao-module-mes-biz/src/main/java/cn/iocoder/yudao/module/mes/dal/dataobject/workreportplan/ReportPlanViewDO.java b/yudao-module-mes/yudao-module-mes-biz/src/main/java/cn/iocoder/yudao/module/mes/dal/dataobject/workreportplan/ReportPlanViewDO.java index 7db0127a7..bf25115dd 100644 --- a/yudao-module-mes/yudao-module-mes-biz/src/main/java/cn/iocoder/yudao/module/mes/dal/dataobject/workreportplan/ReportPlanViewDO.java +++ b/yudao-module-mes/yudao-module-mes-biz/src/main/java/cn/iocoder/yudao/module/mes/dal/dataobject/workreportplan/ReportPlanViewDO.java @@ -51,7 +51,7 @@ public class ReportPlanViewDO extends BaseDO { /** * 计件时间 */ - private String reportTimePlan; + private BigDecimal reportTimePlan; /** * 总时长 */ @@ -73,18 +73,7 @@ public class ReportPlanViewDO extends BaseDO { * 报工类型 */ private String reportType; - /** - * 成品率 - */ - private BigDecimal qualityRate; - /** - * 备注 - */ - private String wasteReason; - /** - * 总时长 - */ - private BigDecimal totalTime; + /** @@ -100,10 +89,7 @@ public class ReportPlanViewDO extends BaseDO { * 报工日期 */ private LocalDateTime reportDate; - /** - * 计件时间 - */ - private String reportTime; + /** * 报工状态 *

diff --git a/yudao-module-mes/yudao-module-mes-biz/src/main/java/cn/iocoder/yudao/module/mes/dal/dataobject/workreportplan/WorkReportPlanDO.java b/yudao-module-mes/yudao-module-mes-biz/src/main/java/cn/iocoder/yudao/module/mes/dal/dataobject/workreportplan/WorkReportPlanDO.java index 4e87f2b29..5db16bd7a 100644 --- a/yudao-module-mes/yudao-module-mes-biz/src/main/java/cn/iocoder/yudao/module/mes/dal/dataobject/workreportplan/WorkReportPlanDO.java +++ b/yudao-module-mes/yudao-module-mes-biz/src/main/java/cn/iocoder/yudao/module/mes/dal/dataobject/workreportplan/WorkReportPlanDO.java @@ -1,14 +1,12 @@ package cn.iocoder.yudao.module.mes.dal.dataobject.workreportplan; +import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO; +import com.baomidou.mybatisplus.annotation.KeySequence; +import com.baomidou.mybatisplus.annotation.TableId; +import com.baomidou.mybatisplus.annotation.TableName; import lombok.*; -import java.util.*; -import java.math.BigDecimal; -import java.math.BigDecimal; + import java.math.BigDecimal; -import java.time.LocalDateTime; -import java.time.LocalDateTime; -import com.baomidou.mybatisplus.annotation.*; -import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO; /** * 报工分配计划 DO @@ -53,7 +51,7 @@ public class WorkReportPlanDO extends BaseDO { /** * 计件时间 */ - private String reportTimePlan; + private BigDecimal reportTimePlan; /** * 总时长 */ diff --git a/yudao-module-mes/yudao-module-mes-biz/src/main/java/cn/iocoder/yudao/module/mes/dal/mysql/orgworker/OrgWorkerMapper.java b/yudao-module-mes/yudao-module-mes-biz/src/main/java/cn/iocoder/yudao/module/mes/dal/mysql/orgworker/OrgWorkerMapper.java index 09f652c58..33f86ac4d 100644 --- a/yudao-module-mes/yudao-module-mes-biz/src/main/java/cn/iocoder/yudao/module/mes/dal/mysql/orgworker/OrgWorkerMapper.java +++ b/yudao-module-mes/yudao-module-mes-biz/src/main/java/cn/iocoder/yudao/module/mes/dal/mysql/orgworker/OrgWorkerMapper.java @@ -35,6 +35,8 @@ public interface OrgWorkerMapper extends BaseMapperX { .eqIfPresent(OrgWorkerDO::getGroupType, reqVO.getGroupType()) .betweenIfPresent(OrgWorkerDO::getWorkDate, reqVO.getWorkDate()) .betweenIfPresent(OrgWorkerDO::getCreateTime, reqVO.getCreateTime()) + .in(reqVO.getOrgIds()!=null&&reqVO.getOrgIds().size()>0, + OrgWorkerDO::getOrgId, reqVO.getOrgIds()) .in(reqVO.getWorkerIds()!=null&&reqVO.getWorkerIds().size()>0, OrgWorkerDO::getWorkerId, reqVO.getWorkerIds()) .orderByAsc(OrgWorkerDO::getId)); diff --git a/yudao-module-mes/yudao-module-mes-biz/src/main/java/cn/iocoder/yudao/module/mes/dal/mysql/plan/PlanMapper.java b/yudao-module-mes/yudao-module-mes-biz/src/main/java/cn/iocoder/yudao/module/mes/dal/mysql/plan/PlanMapper.java index 81742d371..4ea09b87b 100644 --- a/yudao-module-mes/yudao-module-mes-biz/src/main/java/cn/iocoder/yudao/module/mes/dal/mysql/plan/PlanMapper.java +++ b/yudao-module-mes/yudao-module-mes-biz/src/main/java/cn/iocoder/yudao/module/mes/dal/mysql/plan/PlanMapper.java @@ -41,8 +41,8 @@ public interface PlanMapper extends BaseMapperX { .betweenIfPresent(PlanDO::getEndTime, reqVO.getEndTime()) .eqIfPresent(PlanDO::getProductionManagerId, reqVO.getProductionManagerId()) .eqIfPresent(PlanDO::getRemark, reqVO.getRemark()) - .eqIfPresent(PlanDO::getIsEnable, reqVO.getIsEnable()) .betweenIfPresent(PlanDO::getCreateTime, reqVO.getCreateTime()) + .orderByDesc(PlanDO::getPriorityNum) .orderByAsc(PlanDO::getPlanStartTime) .orderByAsc(PlanDO::getPlanEndTime)); } @@ -84,6 +84,7 @@ public interface PlanMapper extends BaseMapperX { return selectList(new LambdaQueryWrapperX() .eqIfPresent(PlanDO::getProductId, productId) .inIfPresent(PlanDO::getStatus, statusList) + .orderByDesc(PlanDO::getPriorityNum) .orderByDesc(PlanDO::getStartTime)); } diff --git a/yudao-module-mes/yudao-module-mes-biz/src/main/java/cn/iocoder/yudao/module/mes/dal/mysql/workreportplan/ReportPlanSummaryMapper.java b/yudao-module-mes/yudao-module-mes-biz/src/main/java/cn/iocoder/yudao/module/mes/dal/mysql/workreportplan/ReportPlanSummaryMapper.java new file mode 100644 index 000000000..2619c27c5 --- /dev/null +++ b/yudao-module-mes/yudao-module-mes-biz/src/main/java/cn/iocoder/yudao/module/mes/dal/mysql/workreportplan/ReportPlanSummaryMapper.java @@ -0,0 +1,50 @@ +package cn.iocoder.yudao.module.mes.dal.mysql.workreportplan; + +import cn.iocoder.yudao.framework.common.pojo.PageParam; +import cn.iocoder.yudao.framework.common.pojo.PageResult; +import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX; +import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX; +import cn.iocoder.yudao.module.mes.dal.dataobject.workreportplan.ReportPlanSummaryDO; +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; +import org.apache.ibatis.annotations.Mapper; + +import java.util.List; + +/** + * 报工分配计划 Mapper + * + * @author 内蒙必硕 + */ +@Mapper +public interface ReportPlanSummaryMapper extends BaseMapperX { + + default PageResult selectPage(PageParam param, ReportPlanSummaryDO reqVO) { + LambdaQueryWrapper wrapper = new LambdaQueryWrapperX() + .eqIfPresent(ReportPlanSummaryDO::getPlanId, reqVO.getPlanId()) + .eqIfPresent(ReportPlanSummaryDO::getProductId, reqVO.getProductId()) + .eqIfPresent(ReportPlanSummaryDO::getOrgType, reqVO.getOrgType()) + .orderByDesc(ReportPlanSummaryDO::getOrgType); + return selectPage(param,wrapper ); + } + + //查询计划某工序已经报工的总数 + default List selectList(ReportPlanSummaryDO reqVO) { + LambdaQueryWrapper wrapper = new LambdaQueryWrapperX() + .eqIfPresent(ReportPlanSummaryDO::getPlanId, reqVO.getPlanId()) + .eqIfPresent(ReportPlanSummaryDO::getProductId, reqVO.getProductId()) + .eqIfPresent(ReportPlanSummaryDO::getOrgType, reqVO.getOrgType()) + .orderByDesc(ReportPlanSummaryDO::getOrgType); + List list = selectList(wrapper); + return list; + } + default ReportPlanSummaryDO selectOne(ReportPlanSummaryDO reqVO) { + LambdaQueryWrapper wrapper = new LambdaQueryWrapperX() + .eqIfPresent(ReportPlanSummaryDO::getPlanId, reqVO.getPlanId()) + .eqIfPresent(ReportPlanSummaryDO::getProductId, reqVO.getProductId()) + .eqIfPresent(ReportPlanSummaryDO::getOrgType, reqVO.getOrgType()) + .orderByDesc(ReportPlanSummaryDO::getOrgType); + List list = selectList(wrapper); + if (list!=null && list.size()>0)return list.get(0); + return null; + } +} \ No newline at end of file diff --git a/yudao-module-mes/yudao-module-mes-biz/src/main/java/cn/iocoder/yudao/module/mes/dal/mysql/workreportplan/ReportPlanViewMapper.java b/yudao-module-mes/yudao-module-mes-biz/src/main/java/cn/iocoder/yudao/module/mes/dal/mysql/workreportplan/ReportPlanViewMapper.java index 6b20719b2..680ceeb9b 100644 --- a/yudao-module-mes/yudao-module-mes-biz/src/main/java/cn/iocoder/yudao/module/mes/dal/mysql/workreportplan/ReportPlanViewMapper.java +++ b/yudao-module-mes/yudao-module-mes-biz/src/main/java/cn/iocoder/yudao/module/mes/dal/mysql/workreportplan/ReportPlanViewMapper.java @@ -31,7 +31,10 @@ public interface ReportPlanViewMapper extends BaseMapperX { .eqIfPresent(ReportPlanViewDO::getWasteNumberPlan, reqVO.getWasteNumberPlan()) .eqIfPresent(ReportPlanViewDO::getReportTimePlan, reqVO.getReportTimePlan()) .eqIfPresent(ReportPlanViewDO::getOrgType, reqVO.getOrgType()) + .eqIfPresent(ReportPlanViewDO::getGroupType, reqVO.getGroupType()) + .eqIfPresent(ReportPlanViewDO::getReportType, reqVO.getReportType()) .eqIfPresent(ReportPlanViewDO::getTotalTimePlan, reqVO.getTotalTimePlan()) + .betweenIfPresent(ReportPlanViewDO::getReportDate, reqVO.getReportDate()) .betweenIfPresent(ReportPlanViewDO::getCreateTime, reqVO.getCreateTime()) .orderByDesc(ReportPlanViewDO::getId)); } diff --git a/yudao-module-mes/yudao-module-mes-biz/src/main/java/cn/iocoder/yudao/module/mes/service/plan/PlanServiceImpl.java b/yudao-module-mes/yudao-module-mes-biz/src/main/java/cn/iocoder/yudao/module/mes/service/plan/PlanServiceImpl.java index 9e4a9a379..5ec74f651 100644 --- a/yudao-module-mes/yudao-module-mes-biz/src/main/java/cn/iocoder/yudao/module/mes/service/plan/PlanServiceImpl.java +++ b/yudao-module-mes/yudao-module-mes-biz/src/main/java/cn/iocoder/yudao/module/mes/service/plan/PlanServiceImpl.java @@ -66,6 +66,7 @@ public class PlanServiceImpl implements PlanService { plan.setCode(no); } if (plan.getIsEnable() == null) plan.setIsEnable(true); + if(plan.getPriorityNum()==null) plan.setPriorityNum(1L); planMapper.insert(plan); // 返回 return plan.getId(); diff --git a/yudao-module-mes/yudao-module-mes-biz/src/main/java/cn/iocoder/yudao/module/mes/service/producereport/ProduceReportDetailServiceImpl.java b/yudao-module-mes/yudao-module-mes-biz/src/main/java/cn/iocoder/yudao/module/mes/service/producereport/ProduceReportDetailServiceImpl.java index 8a899c5cf..57dc3402b 100644 --- a/yudao-module-mes/yudao-module-mes-biz/src/main/java/cn/iocoder/yudao/module/mes/service/producereport/ProduceReportDetailServiceImpl.java +++ b/yudao-module-mes/yudao-module-mes-biz/src/main/java/cn/iocoder/yudao/module/mes/service/producereport/ProduceReportDetailServiceImpl.java @@ -172,13 +172,14 @@ public class ProduceReportDetailServiceImpl implements ProduceReportDetailServic BigDecimal planNumber = reportDetailDO.getQualityNumber().multiply(BigDecimal.valueOf(planNeed/totalNeed),mc); BigDecimal wasteNumber = reportDetailDO.getWasteNumber().multiply(BigDecimal.valueOf(planNeed/totalNeed),mc); BigDecimal totalTime = reportDetailDO.getTotalTime().multiply(BigDecimal.valueOf(planNeed/totalNeed),mc); + BigDecimal reportTime = reportDetailDO.getReportTime().multiply(BigDecimal.valueOf(planNeed/totalNeed),mc); WorkReportPlanSaveReqVO saveReqVO = new WorkReportPlanSaveReqVO() .setReportId(id).setPlanId(planId) .setProductId(reportDetailDO.getProductId()) .setQualityNumberPlan(planNumber) .setWasteNumberPlan(wasteNumber) - .setReportTimePlan(reportDetailDO.getReportTime()) + .setReportTimePlan(reportTime) .setTotalTimePlan(totalTime); workReportPlanService.createWorkReportPlan(saveReqVO); } diff --git a/yudao-module-mes/yudao-module-mes-biz/src/main/java/cn/iocoder/yudao/module/mes/service/stockindetail/StockInDetailService.java b/yudao-module-mes/yudao-module-mes-biz/src/main/java/cn/iocoder/yudao/module/mes/service/stockindetail/StockInDetailService.java index 2c503567c..83b9019ac 100644 --- a/yudao-module-mes/yudao-module-mes-biz/src/main/java/cn/iocoder/yudao/module/mes/service/stockindetail/StockInDetailService.java +++ b/yudao-module-mes/yudao-module-mes-biz/src/main/java/cn/iocoder/yudao/module/mes/service/stockindetail/StockInDetailService.java @@ -1,11 +1,12 @@ package cn.iocoder.yudao.module.mes.service.stockindetail; -import java.util.*; -import javax.validation.*; -import cn.iocoder.yudao.module.mes.controller.admin.stockindetail.vo.*; -import cn.iocoder.yudao.module.mes.dal.dataobject.stockindetail.StockInDetailDO; import cn.iocoder.yudao.framework.common.pojo.PageResult; -import cn.iocoder.yudao.framework.common.pojo.PageParam; +import cn.iocoder.yudao.module.mes.controller.admin.stockindetail.vo.StockInDetailPageReqVO; +import cn.iocoder.yudao.module.mes.controller.admin.stockindetail.vo.StockInDetailSaveReqVO; +import cn.iocoder.yudao.module.mes.dal.dataobject.stockindetail.StockInDetailDO; + +import javax.validation.Valid; +import java.math.BigDecimal; /** * 生产入库分配明细 Service 接口 @@ -51,5 +52,14 @@ public interface StockInDetailService { * @return 生产入库分配明细分页 */ PageResult getStockInDetailPage(StockInDetailPageReqVO pageReqVO); + BigDecimal selectSumBy(Long planId); + + /** + * 更新生产入库单的状态 + * + * @param id 编号 + * @param status 状态 + */ + void updateStockInStatus(Long id, Integer status); } \ No newline at end of file diff --git a/yudao-module-mes/yudao-module-mes-biz/src/main/java/cn/iocoder/yudao/module/mes/service/stockindetail/StockInDetailServiceImpl.java b/yudao-module-mes/yudao-module-mes-biz/src/main/java/cn/iocoder/yudao/module/mes/service/stockindetail/StockInDetailServiceImpl.java index 750ad3202..55fc920d3 100644 --- a/yudao-module-mes/yudao-module-mes-biz/src/main/java/cn/iocoder/yudao/module/mes/service/stockindetail/StockInDetailServiceImpl.java +++ b/yudao-module-mes/yudao-module-mes-biz/src/main/java/cn/iocoder/yudao/module/mes/service/stockindetail/StockInDetailServiceImpl.java @@ -2,16 +2,39 @@ package cn.iocoder.yudao.module.mes.service.stockindetail; import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.framework.common.util.object.BeanUtils; +import cn.iocoder.yudao.module.erp.dal.dataobject.product.ErpProductDO; +import cn.iocoder.yudao.module.erp.dal.dataobject.stock.ErpStockInDO; +import cn.iocoder.yudao.module.erp.dal.dataobject.stock.ErpStockInItemDO; +import cn.iocoder.yudao.module.erp.dal.mysql.stock.ErpStockInItemMapper; +import cn.iocoder.yudao.module.erp.dal.mysql.stock.ErpStockInMapper; +import cn.iocoder.yudao.module.erp.enums.ErpAuditStatus; +import cn.iocoder.yudao.module.erp.enums.stock.ErpStockRecordBizTypeEnum; +import cn.iocoder.yudao.module.erp.service.product.ErpProductService; +import cn.iocoder.yudao.module.erp.service.stock.ErpStockInService; +import cn.iocoder.yudao.module.erp.service.stock.ErpStockRecordService; +import cn.iocoder.yudao.module.erp.service.stock.bo.ErpStockRecordCreateReqBO; +import cn.iocoder.yudao.module.mes.controller.admin.plan.vo.PlanStatusEnum; import cn.iocoder.yudao.module.mes.controller.admin.stockindetail.vo.StockInDetailPageReqVO; import cn.iocoder.yudao.module.mes.controller.admin.stockindetail.vo.StockInDetailSaveReqVO; +import cn.iocoder.yudao.module.mes.dal.dataobject.plan.PlanDO; import cn.iocoder.yudao.module.mes.dal.dataobject.stockindetail.StockInDetailDO; import cn.iocoder.yudao.module.mes.dal.mysql.stockindetail.StockInDetailMapper; +import cn.iocoder.yudao.module.mes.service.plan.PlanService; import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; import org.springframework.validation.annotation.Validated; import javax.annotation.Resource; +import java.math.BigDecimal; +import java.math.MathContext; +import java.math.RoundingMode; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; +import static cn.iocoder.yudao.module.erp.enums.ErrorCodeConstants.*; import static cn.iocoder.yudao.module.mes.enums.ErrorCodeConstants.STOCK_IN_DETAIL_NOT_EXISTS; /** @@ -67,5 +90,113 @@ public class StockInDetailServiceImpl implements StockInDetailService { public PageResult getStockInDetailPage(StockInDetailPageReqVO pageReqVO) { return stockInDetailMapper.selectPage(pageReqVO); } + @Override + public BigDecimal selectSumBy(Long planId){ + return stockInDetailMapper.selectSumBy(planId); + } + @Resource + private ErpStockInMapper stockInMapper; + @Resource + private ErpStockInItemMapper stockInItemMapper; + + @Resource + private ErpProductService productService; + @Resource + private ErpStockRecordService stockRecordService; + @Resource + private ErpStockInService stockInService; + @Resource + private PlanService planService; + @Override + @Transactional(rollbackFor = Exception.class) + public void updateStockInStatus(Long id, Integer status) { + boolean approve = ErpAuditStatus.APPROVE.getStatus().equals(status); + // 1.1 校验存在 + ErpStockInDO stockIn =validateStockInExists(id); + // 1.2 校验状态 + if (stockIn.getStatus().equals(status)) { + throw exception(approve ? STOCK_IN_APPROVE_FAIL : STOCK_IN_PROCESS_FAIL); + } + + // 2. 更新状态 + int updateCount = stockInMapper.updateByIdAndStatus(id, stockIn.getStatus(), + new ErpStockInDO().setStatus(status)); + if (updateCount == 0) { + throw exception(approve ? STOCK_IN_APPROVE_FAIL : STOCK_IN_PROCESS_FAIL); + } + // 3. 变更库存 + List stockInItems = stockInItemMapper.selectListByInId(id); + Integer bizType = approve ? ErpStockRecordBizTypeEnum.OTHER_IN.getType() + : ErpStockRecordBizTypeEnum.OTHER_IN_CANCEL.getType(); + stockInItems.forEach(stockInItem -> { + BigDecimal count = approve ? stockInItem.getCount() : stockInItem.getCount().negate(); + ErpProductDO productDO = productService.getProduct(stockInItem.getProductId()); + stockRecordService.createStockRecord(new ErpStockRecordCreateReqBO( + stockInItem.getProductId(),productDO.getCategoryId(), stockInItem.getWarehouseId(), count, + bizType, stockInItem.getInId(), stockInItem.getId(), stockIn.getNo())); + }); + List statusList = new ArrayList<>(); + statusList.add(PlanStatusEnum.开工.getValue()); + statusList.add(PlanStatusEnum.完工.getValue()); + List resultList = new ArrayList<>(); + //入库产品分配给计划 + for (ErpStockInItemDO inItem : stockInItems) { + //查找开工、完工的计划 + List planList = planService.getPlanByStatusAndProduct(statusList,inItem.getProductId()); + if(planList!=null&& planList.size()>0){ + if(planList.size()==1){ + StockInDetailDO detailDO = new StockInDetailDO() + .setStockInId(stockIn.getId()).setStockInNo(stockIn.getNo()) + .setProductId(inItem.getProductId()).setStockInItemId(inItem.getId()) + .setNumber(inItem.getCount()).setPlanId(planList.get(0).getId()); + resultList.add(detailDO); + } + else + resultList.addAll(stockInToPlan(stockIn,inItem,planList)); + } + else{ + StockInDetailDO detailDO = new StockInDetailDO() + .setStockInId(stockIn.getId()).setStockInNo(stockIn.getNo()) + .setProductId(inItem.getProductId()).setStockInItemId(inItem.getId()) + .setNumber(inItem.getCount()).setPlanId(null); + resultList.add(detailDO); + } + } + if(resultList.size()>0) + stockInDetailMapper.insertBatch(resultList); + } + private ErpStockInDO validateStockInExists(Long id) { + ErpStockInDO stockIn = stockInMapper.selectById(id); + if (stockIn == null) { + throw exception(STOCK_IN_NOT_EXISTS); + } + return stockIn; + } + //该产品有多个计划在开工 + private List stockInToPlan(ErpStockInDO stockIn, ErpStockInItemDO inItem,List planList){ + List detailDOS = new ArrayList<>(); + MathContext mc = new MathContext(0, RoundingMode.HALF_UP); + long totalNeed = 0; + Map planDOMap = new HashMap<>(); + for (PlanDO plan : planList) { + BigDecimal finishNumber = stockInDetailMapper.selectSumBy(plan.getId()); + long planNeed = plan.getPlanNumber() > finishNumber.longValue() ? plan.getPlanNumber() - finishNumber.longValue(): 0; + totalNeed += planNeed; + planDOMap.put(plan.getId(), planNeed); + } + //根据计划各自的需求比例分配给计划 + for (Long planId : planDOMap.keySet()) { + Long planNeed = planDOMap.get(planId); + if(planNeed>0){ + BigDecimal planNumber = inItem.getCount().multiply(BigDecimal.valueOf(planNeed/totalNeed),mc); + StockInDetailDO detailDO = new StockInDetailDO() + .setStockInId(stockIn.getId()).setStockInNo(stockIn.getNo()) + .setProductId(inItem.getProductId()).setStockInItemId(inItem.getId()) + .setNumber(planNumber).setPlanId(planId); + detailDOS.add(detailDO); + } + } + return detailDOS; + } } \ No newline at end of file diff --git a/yudao-module-mes/yudao-module-mes-biz/src/main/java/cn/iocoder/yudao/module/mes/service/stockworkshop/StockWorkshopDetailServiceImpl.java b/yudao-module-mes/yudao-module-mes-biz/src/main/java/cn/iocoder/yudao/module/mes/service/stockworkshop/StockWorkshopDetailServiceImpl.java index 62637d55e..1afb1474a 100644 --- a/yudao-module-mes/yudao-module-mes-biz/src/main/java/cn/iocoder/yudao/module/mes/service/stockworkshop/StockWorkshopDetailServiceImpl.java +++ b/yudao-module-mes/yudao-module-mes-biz/src/main/java/cn/iocoder/yudao/module/mes/service/stockworkshop/StockWorkshopDetailServiceImpl.java @@ -105,7 +105,7 @@ public class StockWorkshopDetailServiceImpl implements StockWorkshopDetailServic product -> item.setItemName(product.getName())); MapUtils.findAndThen(unitMap, item.getUnitId(), unit -> item.setUnitName(unit.getName())); - MapUtils.findAndThen(userMap, item.getUserId(), + MapUtils.findAndThen(userMap, Long.valueOf(item.getCreator()), user -> item.setUserName(user.getNickname())); }); } diff --git a/yudao-module-mes/yudao-module-mes-biz/src/main/java/cn/iocoder/yudao/module/mes/service/task/TaskServiceImpl.java b/yudao-module-mes/yudao-module-mes-biz/src/main/java/cn/iocoder/yudao/module/mes/service/task/TaskServiceImpl.java index 75d01641e..d0949ef88 100644 --- a/yudao-module-mes/yudao-module-mes-biz/src/main/java/cn/iocoder/yudao/module/mes/service/task/TaskServiceImpl.java +++ b/yudao-module-mes/yudao-module-mes-biz/src/main/java/cn/iocoder/yudao/module/mes/service/task/TaskServiceImpl.java @@ -270,6 +270,7 @@ public class TaskServiceImpl implements TaskService { else planDO.setPlanNumber((long) totalNumber); totalNumber = totalNumber - productsOfPlan; planDO.setCode(noRedisDAO.generate3(MesNoRedisDAO.PLAN_NO_PREFIX)); + planDO.setPriorityNum(1L); list.add(planDO); } return list; diff --git a/yudao-module-mes/yudao-module-mes-biz/src/main/java/cn/iocoder/yudao/module/mes/service/workreportplan/WorkReportPlanService.java b/yudao-module-mes/yudao-module-mes-biz/src/main/java/cn/iocoder/yudao/module/mes/service/workreportplan/WorkReportPlanService.java index 23fac458c..3eefe2f79 100644 --- a/yudao-module-mes/yudao-module-mes-biz/src/main/java/cn/iocoder/yudao/module/mes/service/workreportplan/WorkReportPlanService.java +++ b/yudao-module-mes/yudao-module-mes-biz/src/main/java/cn/iocoder/yudao/module/mes/service/workreportplan/WorkReportPlanService.java @@ -1,12 +1,13 @@ package cn.iocoder.yudao.module.mes.service.workreportplan; import cn.iocoder.yudao.framework.common.pojo.PageResult; -import cn.iocoder.yudao.module.mes.controller.admin.producereportplan.vo.WorkReportPlanPageReqVO; -import cn.iocoder.yudao.module.mes.controller.admin.producereportplan.vo.WorkReportPlanSaveReqVO; +import cn.iocoder.yudao.module.mes.controller.admin.producereportplan.vo.*; +import cn.iocoder.yudao.module.mes.dal.dataobject.workreportplan.ReportPlanViewDO; import cn.iocoder.yudao.module.mes.dal.dataobject.workreportplan.WorkReportPlanDO; import javax.validation.Valid; import java.math.BigDecimal; +import java.util.List; /** * 报工分配计划 Service 接口 @@ -53,4 +54,10 @@ public interface WorkReportPlanService { */ PageResult getWorkReportPlanPage(WorkReportPlanPageReqVO pageReqVO); BigDecimal selectSumBy(Long planId, String orgType); + + public List buildVOList(List list); + + public List getReportPlanViewList(); + public PageResult getReportPlanViewPage(ReportPlanViewReqVO reqVO); + List buildViewList(List list); } \ No newline at end of file diff --git a/yudao-module-mes/yudao-module-mes-biz/src/main/java/cn/iocoder/yudao/module/mes/service/workreportplan/WorkReportPlanServiceImpl.java b/yudao-module-mes/yudao-module-mes-biz/src/main/java/cn/iocoder/yudao/module/mes/service/workreportplan/WorkReportPlanServiceImpl.java index 8ad1e22b3..41978bd6f 100644 --- a/yudao-module-mes/yudao-module-mes-biz/src/main/java/cn/iocoder/yudao/module/mes/service/workreportplan/WorkReportPlanServiceImpl.java +++ b/yudao-module-mes/yudao-module-mes-biz/src/main/java/cn/iocoder/yudao/module/mes/service/workreportplan/WorkReportPlanServiceImpl.java @@ -1,20 +1,29 @@ package cn.iocoder.yudao.module.mes.service.workreportplan; +import cn.hutool.core.collection.CollUtil; import cn.iocoder.yudao.framework.common.pojo.PageResult; +import cn.iocoder.yudao.framework.common.util.collection.MapUtils; import cn.iocoder.yudao.framework.common.util.object.BeanUtils; -import cn.iocoder.yudao.module.mes.controller.admin.producereportplan.vo.WorkReportPlanPageReqVO; -import cn.iocoder.yudao.module.mes.controller.admin.producereportplan.vo.WorkReportPlanSaveReqVO; +import cn.iocoder.yudao.module.erp.dal.dataobject.product.ErpProductDO; +import cn.iocoder.yudao.module.erp.service.product.ErpProductService; +import cn.iocoder.yudao.module.mes.controller.admin.producereportplan.vo.*; +import cn.iocoder.yudao.module.mes.dal.dataobject.plan.PlanDO; +import cn.iocoder.yudao.module.mes.dal.dataobject.workreportplan.ReportPlanViewDO; import cn.iocoder.yudao.module.mes.dal.dataobject.workreportplan.WorkReportPlanDO; import cn.iocoder.yudao.module.mes.dal.mysql.workreportplan.ReportPlanViewMapper; import cn.iocoder.yudao.module.mes.dal.mysql.workreportplan.WorkReportPlanMapper; +import cn.iocoder.yudao.module.mes.service.plan.PlanService; import org.springframework.stereotype.Service; import org.springframework.validation.annotation.Validated; import javax.annotation.Resource; - import java.math.BigDecimal; +import java.util.Collections; +import java.util.List; +import java.util.Map; import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; +import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertSet; import static cn.iocoder.yudao.module.mes.enums.ErrorCodeConstants.WORK_REPORT_PLAN_NOT_EXISTS; /** @@ -30,6 +39,10 @@ public class WorkReportPlanServiceImpl implements WorkReportPlanService { private WorkReportPlanMapper workReportPlanMapper; @Resource private ReportPlanViewMapper reportPlanViewMapper; + @Resource + private ErpProductService productService; + @Resource + private PlanService planService; @Override public Long createWorkReportPlan(WorkReportPlanSaveReqVO createReqVO) { // 插入 @@ -76,4 +89,50 @@ public class WorkReportPlanServiceImpl implements WorkReportPlanService { public BigDecimal selectSumBy(Long planId, String orgType){ return reportPlanViewMapper.selectSumBy(planId, orgType); } + + @Override + public List buildVOList(List list) { + if (CollUtil.isEmpty(list)) { + return Collections.emptyList(); + } + Map map = productService.getProductMap( + convertSet(list, WorkReportPlanDO::getProductId)); + Map planMap = planService.getPlanMap( + convertSet(list, WorkReportPlanDO::getPlanId)); + return BeanUtils.toBean(list, WorkReportPlanRespVO.class, item -> { + MapUtils.findAndThen(map, item.getProductId(), + product -> item.setProductName(product.getName())); + MapUtils.findAndThen(planMap, item.getPlanId(), + plan -> item.setPlanCode(plan.getCode())); + + }); + } + + @Override + public List getReportPlanViewList() { + return reportPlanViewMapper.selectList(); + } + @Override + public PageResult getReportPlanViewPage(ReportPlanViewReqVO reqVO) { + PageResult pageResult = reportPlanViewMapper.selectPage(reqVO); + return new PageResult<>(buildViewList(pageResult.getList()), pageResult.getTotal()); + } + @Override + public List buildViewList(List list) { + if (CollUtil.isEmpty(list)) { + return Collections.emptyList(); + } + Map map = productService.getProductMap( + convertSet(list, ReportPlanViewDO::getProductId)); + Map planMap = planService.getPlanMap( + convertSet(list, ReportPlanViewDO::getPlanId)); + + return BeanUtils.toBean(list, ReportPlanViewRespVO.class, item -> { + MapUtils.findAndThen(map, item.getProductId(), + product -> item.setProductName(product.getName())); + MapUtils.findAndThen(planMap, item.getPlanId(), + plan -> item.setPlanCode(plan.getCode())); + + }); + } } \ No newline at end of file diff --git a/yudao-module-mes/yudao-module-mes-biz/src/test/java/cn/iocoder/yudao/module/mes/service/workreportplan/WorkReportPlanServiceImplTest.java b/yudao-module-mes/yudao-module-mes-biz/src/test/java/cn/iocoder/yudao/module/mes/service/workreportplan/WorkReportPlanServiceImplTest.java index 2776b7e3a..2f76b90d0 100644 --- a/yudao-module-mes/yudao-module-mes-biz/src/test/java/cn/iocoder/yudao/module/mes/service/workreportplan/WorkReportPlanServiceImplTest.java +++ b/yudao-module-mes/yudao-module-mes-biz/src/test/java/cn/iocoder/yudao/module/mes/service/workreportplan/WorkReportPlanServiceImplTest.java @@ -1,23 +1,24 @@ package cn.iocoder.yudao.module.mes.service.workreportplan; -import org.junit.jupiter.api.Disabled; -import org.junit.jupiter.api.Test; - -import javax.annotation.Resource; - +import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.framework.test.core.ut.BaseDbUnitTest; - -import cn.iocoder.yudao.module.mes.controller.admin.producereportplan.vo.*; +import cn.iocoder.yudao.module.mes.controller.admin.producereportplan.vo.WorkReportPlanPageReqVO; +import cn.iocoder.yudao.module.mes.controller.admin.producereportplan.vo.WorkReportPlanSaveReqVO; import cn.iocoder.yudao.module.mes.dal.dataobject.workreportplan.WorkReportPlanDO; import cn.iocoder.yudao.module.mes.dal.mysql.workreportplan.WorkReportPlanMapper; -import cn.iocoder.yudao.framework.common.pojo.PageResult; - +import org.junit.jupiter.api.Disabled; +import org.junit.jupiter.api.Test; import org.springframework.context.annotation.Import; -import static cn.iocoder.yudao.framework.test.core.util.AssertUtils.*; -import static cn.iocoder.yudao.framework.test.core.util.RandomUtils.*; -import static cn.iocoder.yudao.framework.common.util.date.LocalDateTimeUtils.*; -import static cn.iocoder.yudao.framework.common.util.object.ObjectUtils.*; +import javax.annotation.Resource; + +import static cn.iocoder.yudao.framework.common.util.date.LocalDateTimeUtils.buildBetweenTime; +import static cn.iocoder.yudao.framework.common.util.object.ObjectUtils.cloneIgnoreId; +import static cn.iocoder.yudao.framework.test.core.util.AssertUtils.assertPojoEquals; +import static cn.iocoder.yudao.framework.test.core.util.AssertUtils.assertServiceException; +import static cn.iocoder.yudao.framework.test.core.util.RandomUtils.randomLongId; +import static cn.iocoder.yudao.framework.test.core.util.RandomUtils.randomPojo; +import static cn.iocoder.yudao.module.mes.enums.ErrorCodeConstants.WORK_REPORT_PLAN_NOT_EXISTS; import static org.junit.jupiter.api.Assertions.*; /**