add work report to plan

plp
chenshuichuan 2 years ago
parent 9cad2e1fce
commit c0dd61f306

@ -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是报工单idplan_id是计划idproduct_id是产品idquality_number_plan是分配给计划的合格产品数量
waste_number_plan是分配给计划的不合格产品数量user_id是工人idorg_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用于汇总同一个计划、同一个产品和同一个工序的合格产品数和不合格产品数的信息

@ -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`
)))

@ -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, "报工分配计划不存在");
}

@ -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<WorkTeamDetailDO> detailDOList = workTeamService.getUserWorkTeamDetail(userId, WorkTeamUserRoleEnum..getValue());
//组长的话把这些组的工人列表都查上,其他人所有人都查
List<Long> workTeamIds =null;
if(detailDOList!=null && detailDOList.size()>0){
workTeamIds = detailDOList.stream().map(WorkTeamDetailDO::getWorkTeamId).collect(Collectors.toList());
}
List<WorkTeamDetailDO> workTeamDetailDOS = workTeamService.getDetailByWorkTeamIds(workTeamIds);
Set<Long> idsSet = convertSet(workTeamDetailDOS, WorkTeamDetailDO::getUserId);
List<Long> ids = new ArrayList<>();
if(idsSet!=null && idsSet.size()>0){
ids = new ArrayList<>(idsSet);
}
OrganizationListReqVO listReqVO = new OrganizationListReqVO().setOrgType(reqVO.getOrgType());
List<OrganizationDO> orgList = organizationService.getOrganizationList(listReqVO);
List<Long> orgIds = orgList.stream().map(OrganizationDO::getId).collect(Collectors.toList());
pageReqVO.setOrgIds(orgIds);
// Long userId = getLoginUserId();
// List<WorkTeamDetailDO> detailDOList = workTeamService.getUserWorkTeamDetail(userId, WorkTeamUserRoleEnum.组长.getValue());
// //组长的话把这些组的工人列表都查上,其他人所有人都查
// List<Long> workTeamIds =null;
// if(detailDOList!=null && detailDOList.size()>0){
// workTeamIds = detailDOList.stream().map(WorkTeamDetailDO::getWorkTeamId).collect(Collectors.toList());
// }
// List<WorkTeamDetailDO> workTeamDetailDOS = workTeamService.getDetailByWorkTeamIds(workTeamIds);
// Set<Long> idsSet = convertSet(workTeamDetailDOS, WorkTeamDetailDO::getUserId);
List<OrgWorkerDO> list = orgWorkerService.getOrgWorkerByReportResVo(pageReqVO);
List<Long> ids = list.stream().map(OrgWorkerDO::getWorkerId).collect(Collectors.toList());
Map<Long, AdminUserRespDTO> userMap = adminUserApi.getUserMap(ids);
return success(new ArrayList<>(userMap.values()));
}

@ -95,4 +95,10 @@ public class PlanRespVO {
*/
@Schema(description = "派工单ID")
private Long requisitionId;
/**
*
*/
@Schema(description = "优先级")
private Long priorityNum;
}

@ -61,4 +61,10 @@ public class PlanSaveReqVO {
private Boolean isEnable;
@Schema(description = "制浆线")
private String feedingPipeline;
/**
*
*/
@Schema(description = "优先级")
private Long priorityNum;
}

@ -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<Long> 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<Boolean> 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<Boolean> 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<WorkReportPlanRespVO> 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<PageResult<WorkReportPlanRespVO>> getWorkReportPlanPage(@Valid WorkReportPlanPageReqVO pageReqVO) {
PageResult<WorkReportPlanDO> 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<PageResult<ReportPlanViewRespVO>> pageView(@Valid ReportPlanViewReqVO pageReqVO) {
PageResult<ReportPlanViewRespVO> 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 {

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

@ -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("总时长")

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

@ -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("总时长")

@ -28,7 +28,7 @@ public class WorkReportPlanSaveReqVO {
private BigDecimal wasteNumberPlan;
@Schema(description = "计件时间")
private String reportTimePlan;
private BigDecimal reportTimePlan;
@Schema(description = "总时长")
private BigDecimal totalTimePlan;

@ -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<Boolean> updateStockInStatus(@RequestParam("id") Long id,
@RequestParam("status") Integer status) {
stockInDetailService.updateStockInStatus(id, status);
return success(true);
}
}

@ -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("单据时间")

@ -94,4 +94,9 @@ public class PlanDO extends BaseDO {
* ID
*/
private Long requisitionId;
/**
*
*/
private Long priorityNum;
}

@ -101,7 +101,7 @@ public class ProduceReportDetailDO extends BaseDO {
/**
*
*/
private String reportTime;
private BigDecimal reportTime;
/**
*
* <p>

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

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

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

@ -35,6 +35,8 @@ public interface OrgWorkerMapper extends BaseMapperX<OrgWorkerDO> {
.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));

@ -41,8 +41,8 @@ public interface PlanMapper extends BaseMapperX<PlanDO> {
.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<PlanDO> {
return selectList(new LambdaQueryWrapperX<PlanDO>()
.eqIfPresent(PlanDO::getProductId, productId)
.inIfPresent(PlanDO::getStatus, statusList)
.orderByDesc(PlanDO::getPriorityNum)
.orderByDesc(PlanDO::getStartTime));
}

@ -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<ReportPlanSummaryDO> {
default PageResult<ReportPlanSummaryDO> selectPage(PageParam param, ReportPlanSummaryDO reqVO) {
LambdaQueryWrapper<ReportPlanSummaryDO> wrapper = new LambdaQueryWrapperX<ReportPlanSummaryDO>()
.eqIfPresent(ReportPlanSummaryDO::getPlanId, reqVO.getPlanId())
.eqIfPresent(ReportPlanSummaryDO::getProductId, reqVO.getProductId())
.eqIfPresent(ReportPlanSummaryDO::getOrgType, reqVO.getOrgType())
.orderByDesc(ReportPlanSummaryDO::getOrgType);
return selectPage(param,wrapper );
}
//查询计划某工序已经报工的总数
default List<ReportPlanSummaryDO> selectList(ReportPlanSummaryDO reqVO) {
LambdaQueryWrapper<ReportPlanSummaryDO> wrapper = new LambdaQueryWrapperX<ReportPlanSummaryDO>()
.eqIfPresent(ReportPlanSummaryDO::getPlanId, reqVO.getPlanId())
.eqIfPresent(ReportPlanSummaryDO::getProductId, reqVO.getProductId())
.eqIfPresent(ReportPlanSummaryDO::getOrgType, reqVO.getOrgType())
.orderByDesc(ReportPlanSummaryDO::getOrgType);
List<ReportPlanSummaryDO> list = selectList(wrapper);
return list;
}
default ReportPlanSummaryDO selectOne(ReportPlanSummaryDO reqVO) {
LambdaQueryWrapper<ReportPlanSummaryDO> wrapper = new LambdaQueryWrapperX<ReportPlanSummaryDO>()
.eqIfPresent(ReportPlanSummaryDO::getPlanId, reqVO.getPlanId())
.eqIfPresent(ReportPlanSummaryDO::getProductId, reqVO.getProductId())
.eqIfPresent(ReportPlanSummaryDO::getOrgType, reqVO.getOrgType())
.orderByDesc(ReportPlanSummaryDO::getOrgType);
List<ReportPlanSummaryDO> list = selectList(wrapper);
if (list!=null && list.size()>0)return list.get(0);
return null;
}
}

@ -31,7 +31,10 @@ public interface ReportPlanViewMapper extends BaseMapperX<ReportPlanViewDO> {
.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));
}

@ -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();

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

@ -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<StockInDetailDO> getStockInDetailPage(StockInDetailPageReqVO pageReqVO);
BigDecimal selectSumBy(Long planId);
/**
*
*
* @param id
* @param status
*/
void updateStockInStatus(Long id, Integer status);
}

@ -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<StockInDetailDO> 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<ErpStockInItemDO> 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<Integer> statusList = new ArrayList<>();
statusList.add(PlanStatusEnum..getValue());
statusList.add(PlanStatusEnum..getValue());
List<StockInDetailDO> resultList = new ArrayList<>();
//入库产品分配给计划
for (ErpStockInItemDO inItem : stockInItems) {
//查找开工、完工的计划
List<PlanDO> 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<StockInDetailDO> stockInToPlan(ErpStockInDO stockIn, ErpStockInItemDO inItem,List<PlanDO> planList){
List<StockInDetailDO> detailDOS = new ArrayList<>();
MathContext mc = new MathContext(0, RoundingMode.HALF_UP);
long totalNeed = 0;
Map<Long, Long> 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;
}
}

@ -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()));
});
}

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

@ -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<WorkReportPlanDO> getWorkReportPlanPage(WorkReportPlanPageReqVO pageReqVO);
BigDecimal selectSumBy(Long planId, String orgType);
public List<WorkReportPlanRespVO> buildVOList(List<WorkReportPlanDO> list);
public List<ReportPlanViewDO> getReportPlanViewList();
public PageResult<ReportPlanViewRespVO> getReportPlanViewPage(ReportPlanViewReqVO reqVO);
List<ReportPlanViewRespVO> buildViewList(List<ReportPlanViewDO> list);
}

@ -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<WorkReportPlanRespVO> buildVOList(List<WorkReportPlanDO> list) {
if (CollUtil.isEmpty(list)) {
return Collections.emptyList();
}
Map<Long, ErpProductDO> map = productService.getProductMap(
convertSet(list, WorkReportPlanDO::getProductId));
Map<Long, PlanDO> 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<ReportPlanViewDO> getReportPlanViewList() {
return reportPlanViewMapper.selectList();
}
@Override
public PageResult<ReportPlanViewRespVO> getReportPlanViewPage(ReportPlanViewReqVO reqVO) {
PageResult<ReportPlanViewDO> pageResult = reportPlanViewMapper.selectPage(reqVO);
return new PageResult<>(buildViewList(pageResult.getList()), pageResult.getTotal());
}
@Override
public List<ReportPlanViewRespVO> buildViewList(List<ReportPlanViewDO> list) {
if (CollUtil.isEmpty(list)) {
return Collections.emptyList();
}
Map<Long, ErpProductDO> map = productService.getProductMap(
convertSet(list, ReportPlanViewDO::getProductId));
Map<Long, PlanDO> 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()));
});
}
}

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

Loading…
Cancel
Save