李白
2 天以前 786ed98c279190ae0c4e09fecb42689b80ed714e
platformx-business-finance-biz/src/main/java/com/by4cloud/platformx/business/controller/ProductionPlanController.java
@@ -6,7 +6,10 @@
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;
@@ -20,8 +23,10 @@
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;
/**
 * 排产计划
@@ -37,6 +42,7 @@
public class ProductionPlanController {
    private final  ProductionPlanService productionPlanService;
    private final ContractSubjectMatterService contractSubjectMatterService;
    /**
     * 分页查询
@@ -53,7 +59,16 @@
        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());
        return R.ok(productionPlanService.page(page, wrapper));
        Page<ProductionPlan> page1 = productionPlanService.page(page, wrapper);
        List<ProductionPlan> list = page1.getRecords();
        for(ProductionPlan plan : list){
            List<ContractSubjectMatter> metterList = contractSubjectMatterService.list(new LambdaQueryWrapper<ContractSubjectMatter>()
                    .eq(ContractSubjectMatter::getProductionPlanId,plan.getId())
            );
            plan.setContractSubjectMatterList(metterList);
        }
        page1.setRecords(list);
        return R.ok(page1);
    }
    /**
@@ -78,7 +93,15 @@
    @GetMapping("/{id}" )
    @PreAuthorize("@pms.hasPermission('business_productionPlan_view')" )
    public R getById(@PathVariable("id" ) Long id) {
        return R.ok(productionPlanService.getById(id));
        ProductionPlan productionPlan = productionPlanService.getById(id);
        if(productionPlan==null){
            return R.failed("id错误!");
        }
        List<ContractSubjectMatter> list = contractSubjectMatterService.list(new LambdaQueryWrapper<ContractSubjectMatter>()
                .eq(ContractSubjectMatter::getProductionPlanId,productionPlan.getId())
        );
        productionPlan.setContractSubjectMatterList(list);
        return R.ok(productionPlan);
    }
    /**
@@ -91,7 +114,20 @@
    @PostMapping
    @PreAuthorize("@pms.hasPermission('business_productionPlan_add')" )
    public R save(@RequestBody ProductionPlan productionPlan) {
        return R.ok(productionPlanService.save(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);
    }
    /**
@@ -104,6 +140,36 @@
    @PutMapping
    @PreAuthorize("@pms.hasPermission('business_productionPlan_edit')" )
    public R updateById(@RequestBody ProductionPlan productionPlan) {
        List<ContractSubjectMatter> list = contractSubjectMatterService.list(new LambdaQueryWrapper<ContractSubjectMatter>()
                .eq(ContractSubjectMatter::getProductionPlanId,productionPlan.getId())
        );
        List<Long> idsO = new ArrayList<>();
        if(list!=null){
            if(!list.isEmpty()){
                idsO = list.stream().map(BaseModel::getId).collect(Collectors.toList());
            }
        }
        if(productionPlan.getContractSubjectMatterList()!=null){
            List<Long> 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));
    }