package com.by4cloud.platformx.business.controller; import cn.hutool.core.util.ArrayUtil; import cn.hutool.core.collection.CollUtil; import cn.hutool.core.util.StrUtil; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.toolkit.Wrappers; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.by4cloud.platformx.business.entity.ContractSubjectMatter; import com.by4cloud.platformx.business.service.ContractSubjectMatterService; import com.by4cloud.platformx.common.core.util.R; import com.by4cloud.platformx.common.data.mybatis.BaseModel; import com.by4cloud.platformx.common.log.annotation.SysLog; import com.by4cloud.platformx.business.entity.ProductionPlan; import com.by4cloud.platformx.business.service.ProductionPlanService; import org.springframework.security.access.prepost.PreAuthorize; import com.by4cloud.platformx.common.excel.annotation.ResponseExcel; import io.swagger.v3.oas.annotations.security.SecurityRequirement; import org.springdoc.core.annotations.ParameterObject; import org.springframework.http.HttpHeaders; import io.swagger.v3.oas.annotations.tags.Tag; import io.swagger.v3.oas.annotations.Operation; import lombok.RequiredArgsConstructor; import org.springframework.web.bind.annotation.*; import java.util.ArrayList; import java.util.List; import java.util.Objects; import java.util.stream.Collectors; /** * 排产计划 * * @author platformx * @date 2026-05-07 10:27:42 */ @RestController @RequiredArgsConstructor @RequestMapping("/productionPlan" ) @Tag(description = "productionPlan" , name = "排产计划管理" ) @SecurityRequirement(name = HttpHeaders.AUTHORIZATION) public class ProductionPlanController { private final ProductionPlanService productionPlanService; private final ContractSubjectMatterService contractSubjectMatterService; /** * 分页查询 * @param page 分页对象 * @param productionPlan 排产计划 * @return */ @Operation(summary = "分页查询" , description = "分页查询" ) @GetMapping("/page" ) @PreAuthorize("@pms.hasPermission('business_productionPlan_view')" ) public R getProductionPlanPage(@ParameterObject Page page, @ParameterObject ProductionPlan productionPlan) { LambdaQueryWrapper wrapper = Wrappers.lambdaQuery(); wrapper.like(StrUtil.isNotEmpty(productionPlan.getProductionPlanName()),ProductionPlan::getProductionPlanName,productionPlan.getProductionPlanName()); wrapper.eq(productionPlan.getPartyaid()!=null,ProductionPlan::getPartyaid,productionPlan.getPartyaid()); wrapper.eq(productionPlan.getPartybid()!=null,ProductionPlan::getPartybid,productionPlan.getPartybid()); wrapper.eq(productionPlan.getStatus()!=null,ProductionPlan::getStatus,productionPlan.getStatus()); Page page1 = productionPlanService.page(page, wrapper); List list = page1.getRecords(); for(ProductionPlan plan : list){ List metterList = contractSubjectMatterService.list(new LambdaQueryWrapper() .eq(ContractSubjectMatter::getProductionPlanId,plan.getId()) ); plan.setContractSubjectMatterList(metterList); } page1.setRecords(list); return R.ok(page1); } /** * 分页查询 * @param productionPlan 排产计划 * @return */ @Operation(summary = "分页查询" , description = "分页查询" ) @GetMapping("/list" ) @PreAuthorize("@pms.hasPermission('business_productionPlan_view')" ) public R getProductionPlanList(@ParameterObject ProductionPlan productionPlan) { LambdaQueryWrapper wrapper = Wrappers.lambdaQuery(); return R.ok(productionPlanService.list(wrapper)); } /** * 通过id查询排产计划 * @param id id * @return R */ @Operation(summary = "通过id查询" , description = "通过id查询" ) @GetMapping("/{id}" ) @PreAuthorize("@pms.hasPermission('business_productionPlan_view')" ) public R getById(@PathVariable("id" ) Long id) { ProductionPlan productionPlan = productionPlanService.getById(id); if(productionPlan==null){ return R.failed("id错误!"); } List list = contractSubjectMatterService.list(new LambdaQueryWrapper() .eq(ContractSubjectMatter::getProductionPlanId,productionPlan.getId()) ); productionPlan.setContractSubjectMatterList(list); return R.ok(productionPlan); } /** * 新增排产计划 * @param productionPlan 排产计划 * @return R */ @Operation(summary = "新增排产计划" , description = "新增排产计划" ) @SysLog("新增排产计划" ) @PostMapping @PreAuthorize("@pms.hasPermission('business_productionPlan_add')" ) public R save(@RequestBody ProductionPlan productionPlan) { if(StrUtil.isEmpty(productionPlan.getProductionPlanName())){ return R.failed("排产计划名称不能为空!"); } productionPlanService.save(productionPlan); if(productionPlan.getContractSubjectMatterList()!=null){ for(ContractSubjectMatter matter1 : productionPlan.getContractSubjectMatterList()){ matter1.setProductionPlanId(productionPlan.getId()); matter1.setProductionPlanName(productionPlan.getProductionPlanName()); } contractSubjectMatterService.saveBatch(productionPlan.getContractSubjectMatterList()); } return R.ok(true); } /** * 修改排产计划 * @param productionPlan 排产计划 * @return R */ @Operation(summary = "修改排产计划" , description = "修改排产计划" ) @SysLog("修改排产计划" ) @PutMapping @PreAuthorize("@pms.hasPermission('business_productionPlan_edit')" ) public R updateById(@RequestBody ProductionPlan productionPlan) { List list = contractSubjectMatterService.list(new LambdaQueryWrapper() .eq(ContractSubjectMatter::getProductionPlanId,productionPlan.getId()) ); List idsO = new ArrayList<>(); if(list!=null){ if(!list.isEmpty()){ idsO = list.stream().map(BaseModel::getId).collect(Collectors.toList()); } } if(productionPlan.getContractSubjectMatterList()!=null){ List idsN = new ArrayList<>(); for(ContractSubjectMatter matter : productionPlan.getContractSubjectMatterList()){ if(matter.getId()==null){ matter.setProductionPlanId(productionPlan.getId()); matter.setProductionPlanName(productionPlan.getProductionPlanName()); }else{ idsN.add(matter.getId()); } } contractSubjectMatterService.saveOrUpdateBatch(productionPlan.getContractSubjectMatterList()); if(!idsO.isEmpty()) { for (Long id : idsO) { if (!idsN.contains(id)) { contractSubjectMatterService.removeById(id); } } } } return R.ok(productionPlanService.updateById(productionPlan)); } /** * 通过id删除排产计划 * @param ids id列表 * @return R */ @Operation(summary = "通过id删除排产计划" , description = "通过id删除排产计划" ) @SysLog("通过id删除排产计划" ) @DeleteMapping @PreAuthorize("@pms.hasPermission('business_productionPlan_del')" ) public R removeById(@RequestBody Long[] ids) { return R.ok(productionPlanService.removeBatchByIds(CollUtil.toList(ids))); } /** * 导出excel 表格 * @param productionPlan 查询条件 * @param ids 导出指定ID * @return excel 文件流 */ @ResponseExcel @GetMapping("/export") @PreAuthorize("@pms.hasPermission('business_productionPlan_export')" ) public List export(ProductionPlan productionPlan,Long[] ids) { return productionPlanService.list(Wrappers.lambdaQuery(productionPlan).in(ArrayUtil.isNotEmpty(ids), ProductionPlan::getId, ids)); } }