gongchunyi
2 天以前 cd2aafde048f46bd7123ec6cc773d7200172ee04
Merge remote-tracking branch 'origin/dev_New' into dev_New
已修改14个文件
658 ■■■■ 文件已修改
src/main/java/com/ruoyi/production/controller/SalesLedgerWorkController.java 185 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/ruoyi/production/mapper/ProductionProductMainMapper.java 3 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/ruoyi/production/pojo/ProductionProductInput.java 1 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/ruoyi/production/pojo/ProductionProductOutput.java 3 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/ruoyi/production/pojo/SalesLedgerProductionAccounting.java 20 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/ruoyi/production/service/ProductionProductMainService.java 5 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/ruoyi/production/service/impl/ProductProcessRouteItemServiceImpl.java 8 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/ruoyi/production/service/impl/ProductionProductMainServiceImpl.java 13 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/ruoyi/production/service/impl/SalesLedgerWorkServiceImpl.java 367 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/ruoyi/sales/service/impl/SalesLedgerProductServiceImpl.java 9 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/ruoyi/sales/service/impl/SalesLedgerServiceImpl.java 23 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/resources/mapper/production/ProductOrderMapper.xml 3 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/resources/mapper/production/ProductionProductMainMapper.xml 16 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/resources/mapper/production/SalesLedgerProductionAccountingMapper.xml 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/ruoyi/production/controller/SalesLedgerWorkController.java
@@ -1,93 +1,92 @@
package com.ruoyi.production.controller;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.production.dto.ProcessSchedulingDto;
import com.ruoyi.production.dto.ProductionReportDto;
import com.ruoyi.production.dto.SalesLedgerSchedulingProcessDto;
import com.ruoyi.production.dto.SalesLedgerWorkDto;
import com.ruoyi.production.pojo.SalesLedgerWork;
import com.ruoyi.production.service.SalesLedgerWorkService;
import com.ruoyi.production.service.impl.SalesLedgerWorkServiceImpl;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpServletResponse;
import java.util.List;
/**
 * @author :yys
 * @date : 2025/7/21 14:43
 */
@RestController
@Api(tags = "生产报工(排产记录)")
@RequestMapping("/salesLedger/work")
@Deprecated // 标记该类已弃用
public class SalesLedgerWorkController extends BaseController {
    @Autowired
    private SalesLedgerWorkServiceImpl salesLedgerWorkService;
    @GetMapping("/listPage")
    @Log(title = "生产报工-分页查询", businessType = BusinessType.OTHER)
    @ApiOperation("生产报工-分页查询")
    public AjaxResult listPage(Page page, SalesLedgerWorkDto salesLedgerWorkDto) {
        IPage<SalesLedgerWorkDto> listPage = salesLedgerWorkService.listPage(page, salesLedgerWorkDto);
        return AjaxResult.success(listPage);
    }
    /**
     * 导出
     * @param response
     */
    @PostMapping("/export")
    @ApiOperation("生产管理-生产报工-导出")
    public void export(HttpServletResponse response) {
        Page page = new Page(-1,-1);
        SalesLedgerWorkDto salesLedgerSchedulingDto = new SalesLedgerWorkDto();
        IPage<SalesLedgerWorkDto> result = salesLedgerWorkService.listPage(page,salesLedgerSchedulingDto);
        result.getRecords().forEach(item -> {
            item.setDaiNum(item.getFinishedNum().subtract(item.getSchedulingNum()));
            item.setStatusName(item.getStatus().toString());
        });
        ExcelUtil<SalesLedgerWorkDto> util = new ExcelUtil<>(SalesLedgerWorkDto.class);
        util.exportExcel(response, result.getRecords(), "工序排产");
    }
    @GetMapping("/list")
    @Log(title = "生产报工-查询", businessType = BusinessType.OTHER)
    @ApiOperation("生产报工-查询")
    public AjaxResult list(@RequestParam("id") Long id) {
        List<ProductionReportDto> list = salesLedgerWorkService.getList(id);
        return AjaxResult.success(list);
    }
    @PostMapping("/productionReport")
    @Log(title = "生产管理-生产报工", businessType = BusinessType.INSERT)
    @ApiOperation("生产管理-生产报工")
    @Transactional(rollbackFor = Exception.class)
    public AjaxResult productionReport(@RequestBody ProductionReportDto productionReportDto) {
        int result = salesLedgerWorkService.productionReport(productionReportDto);
        return AjaxResult.success(result);
    }
    @PostMapping("/productionReportUpdate")
    @Log(title = "生产管理-生产报工-修改", businessType = BusinessType.UPDATE)
    @ApiOperation("生产管理-生产报工-修改")
    @Transactional(rollbackFor = Exception.class)
    public AjaxResult productionReportUpdate(@RequestBody ProductionReportDto productionReportDto) {
        int result = salesLedgerWorkService.productionReportUpdate(productionReportDto);
        return AjaxResult.success(result);
    }
}
//package com.ruoyi.production.controller;
//
//import com.baomidou.mybatisplus.core.metadata.IPage;
//import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
//import com.ruoyi.common.utils.poi.ExcelUtil;
//import com.ruoyi.framework.aspectj.lang.annotation.Log;
//import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
//import com.ruoyi.framework.web.controller.BaseController;
//import com.ruoyi.framework.web.domain.AjaxResult;
//import com.ruoyi.production.dto.ProcessSchedulingDto;
//import com.ruoyi.production.dto.ProductionReportDto;
//import com.ruoyi.production.dto.SalesLedgerSchedulingProcessDto;
//import com.ruoyi.production.dto.SalesLedgerWorkDto;
//import com.ruoyi.production.pojo.SalesLedgerWork;
//import com.ruoyi.production.service.SalesLedgerWorkService;
//import io.swagger.annotations.Api;
//import io.swagger.annotations.ApiOperation;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.transaction.annotation.Transactional;
//import org.springframework.web.bind.annotation.*;
//
//import javax.servlet.http.HttpServletResponse;
//import java.util.List;
//
///**
// * @author :yys
// * @date : 2025/7/21 14:43
// */
//@RestController
//@Api(tags = "生产报工(排产记录)")
//@RequestMapping("/salesLedger/work")
//@Deprecated // 标记该类已弃用
//public class SalesLedgerWorkController extends BaseController {
//
//
//    @Autowired
//    private SalesLedgerWorkServiceImpl salesLedgerWorkService;
//
//    @GetMapping("/listPage")
//    @Log(title = "生产报工-分页查询", businessType = BusinessType.OTHER)
//    @ApiOperation("生产报工-分页查询")
//    public AjaxResult listPage(Page page, SalesLedgerWorkDto salesLedgerWorkDto) {
//        IPage<SalesLedgerWorkDto> listPage = salesLedgerWorkService.listPage(page, salesLedgerWorkDto);
//        return AjaxResult.success(listPage);
//    }
//
//    /**
//     * 导出
//     * @param response
//     */
//    @PostMapping("/export")
//    @ApiOperation("生产管理-生产报工-导出")
//    public void export(HttpServletResponse response) {
//        Page page = new Page(-1,-1);
//        SalesLedgerWorkDto salesLedgerSchedulingDto = new SalesLedgerWorkDto();
//        IPage<SalesLedgerWorkDto> result = salesLedgerWorkService.listPage(page,salesLedgerSchedulingDto);
//        result.getRecords().forEach(item -> {
//            item.setDaiNum(item.getFinishedNum().subtract(item.getSchedulingNum()));
//            item.setStatusName(item.getStatus().toString());
//        });
//        ExcelUtil<SalesLedgerWorkDto> util = new ExcelUtil<>(SalesLedgerWorkDto.class);
//        util.exportExcel(response, result.getRecords(), "工序排产");
//    }
//
//    @GetMapping("/list")
//    @Log(title = "生产报工-查询", businessType = BusinessType.OTHER)
//    @ApiOperation("生产报工-查询")
//    public AjaxResult list(@RequestParam("id") Long id) {
//        List<ProductionReportDto> list = salesLedgerWorkService.getList(id);
//        return AjaxResult.success(list);
//    }
//
//    @PostMapping("/productionReport")
//    @Log(title = "生产管理-生产报工", businessType = BusinessType.INSERT)
//    @ApiOperation("生产管理-生产报工")
//    @Transactional(rollbackFor = Exception.class)
//    public AjaxResult productionReport(@RequestBody ProductionReportDto productionReportDto) {
//        int result = salesLedgerWorkService.productionReport(productionReportDto);
//        return AjaxResult.success(result);
//    }
//
//
//    @PostMapping("/productionReportUpdate")
//    @Log(title = "生产管理-生产报工-修改", businessType = BusinessType.UPDATE)
//    @ApiOperation("生产管理-生产报工-修改")
//    @Transactional(rollbackFor = Exception.class)
//    public AjaxResult productionReportUpdate(@RequestBody ProductionReportDto productionReportDto) {
//        int result = salesLedgerWorkService.productionReportUpdate(productionReportDto);
//        return AjaxResult.success(result);
//    }
//
//}
src/main/java/com/ruoyi/production/mapper/ProductionProductMainMapper.java
@@ -10,6 +10,7 @@
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import java.util.ArrayList;
import java.util.List;
@Mapper
@@ -30,4 +31,6 @@
    ProductOrder getOrderByMainId(@Param("productMainId") Long productMainId);
    IPage<ProductionProductMainDto> listProductionDetails(@Param("ew") SalesLedgerProductionAccountingDto salesLedgerProductionAccountingDto, Page page);
    ArrayList<Long> listMain(List<Long> idList);
}
src/main/java/com/ruoyi/production/pojo/ProductionProductInput.java
@@ -24,6 +24,7 @@
    private BigDecimal quantity;
    @ApiModelProperty(value = "创建时间")
    @TableField(fill = FieldFill.INSERT)
    private LocalDateTime createTime;
    @ApiModelProperty(value = "租户ID")
src/main/java/com/ruoyi/production/pojo/ProductionProductOutput.java
@@ -20,10 +20,11 @@
    @ApiModelProperty(value = "产品id")
    private Long productModelId;
    @ApiModelProperty(value = "报工数量")
    @ApiModelProperty(value = "报工数量(总数量)")
    private BigDecimal quantity;
    @ApiModelProperty(value = "创建时间")
    @TableField(fill = FieldFill.INSERT)
    private LocalDateTime createTime;
    @ApiModelProperty(value = "租户ID")
src/main/java/com/ruoyi/production/pojo/SalesLedgerProductionAccounting.java
@@ -23,24 +23,9 @@
    private Long id;
    /**
     * 销售排产-报工表id
     * 报工表id
     */
    private Long salesLedgerWorkId;
    /**
     * 销售排产表id
     */
    private Long salesLedgerSchedulingId;
    /**
     * 销售台账id
     */
    private Long salesLedgerId;
    /**
     * 销售产品id
     */
    private Long salesLedgerProductId;
    private Long productMainId;
    /**
     * 生产人id
@@ -101,6 +86,5 @@
    @TableField(fill = FieldFill.INSERT)
    private Long tenantId;
    private Long ProductMainId;
}
src/main/java/com/ruoyi/production/service/ProductionProductMainService.java
@@ -6,10 +6,15 @@
import com.ruoyi.production.dto.ProductionProductMainDto;
import com.ruoyi.production.pojo.ProductionProductMain;
import java.util.ArrayList;
import java.util.List;
public interface ProductionProductMainService extends IService<ProductionProductMain> {
    IPage<ProductionProductMainDto> listPageProductionProductMainDto(Page page, ProductionProductMainDto productionProductMainDto);
    Boolean addProductMain(ProductionProductMainDto productionProductMainDto);
    Boolean removeProductMain(Long id);
    ArrayList<Long> listMain(List<Long> idList);
}
src/main/java/com/ruoyi/production/service/impl/ProductProcessRouteItemServiceImpl.java
@@ -101,14 +101,12 @@
//                    // 删除质检
//                    qualityInspectMapper.delete(new LambdaQueryWrapper<QualityInspect>()
//                            .eq(QualityInspect::getProductMainId, mainId));
                    salesLedgerProductionAccountingMapper.delete(new LambdaQueryWrapper<SalesLedgerProductionAccounting>()
                            .eq(SalesLedgerProductionAccounting::getProductMainId, main.getId()));
                }
            }
            // 查询订单 + 删除核算
            ProductOrder productOrder = productOrderMapper.selectById(productOrderId);
            if (productOrder != null && productOrder.getSalesLedgerId() != null) {
                salesLedgerProductionAccountingMapper.delete(new LambdaQueryWrapper<SalesLedgerProductionAccounting>()
                        .eq(SalesLedgerProductionAccounting::getSalesLedgerId, productOrder.getSalesLedgerId()));
            }
            // 删除关联工单
            productWorkOrderMapper.delete(new LambdaQueryWrapper<ProductWorkOrder>()
                    .eq(ProductWorkOrder::getProductProcessRouteItemId, routeItemId));
src/main/java/com/ruoyi/production/service/impl/ProductionProductMainServiceImpl.java
@@ -33,6 +33,7 @@
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
@@ -229,10 +230,7 @@
            productOrderMapper.updateById(productOrder);
            /*添加生产核算*/
            SalesLedgerProductionAccounting salesLedgerProductionAccounting = SalesLedgerProductionAccounting.builder()
                    .salesLedgerWorkId(productionProductMain.getId())
                    .salesLedgerSchedulingId(0L)
                    .salesLedgerId(productOrder.getSalesLedgerId())
                    .salesLedgerProductId(productOrder.getSaleLedgerProductId())
                    .productMainId(productionProductMain.getId())
                    .schedulingUserId(user.getUserId())
                    .schedulingUserName(user.getNickName())
                    .finishedNum(productQty)
@@ -261,7 +259,7 @@
        /*删除核算*/
        salesLedgerProductionAccountingMapper.delete(
                new LambdaQueryWrapper<SalesLedgerProductionAccounting>()
                        .eq(SalesLedgerProductionAccounting::getSalesLedgerWorkId, productionProductMain.getId())
                        .eq(SalesLedgerProductionAccounting::getProductMainId, productionProductMain.getId())
        );
        /*更新工单和生产订单*/
        ProductWorkOrder productWorkOrder = productWorkOrderMapper.selectById(productionProductMain.getWorkOrderId());
@@ -302,4 +300,9 @@
        productionProductMainMapper.deleteById(productionProductMain.getId());
        return true;
    }
    @Override
    public ArrayList<Long> listMain(List<Long> idList) {
        return productionProductMainMapper.listMain(idList);
    }
}
src/main/java/com/ruoyi/production/service/impl/SalesLedgerWorkServiceImpl.java
@@ -1,185 +1,182 @@
package com.ruoyi.production.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.framework.security.LoginUser;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.procurementrecord.dto.Details;
import com.ruoyi.procurementrecord.dto.ProcurementAddDto;
import com.ruoyi.procurementrecord.dto.ProcurementRecordOutAdd;
import com.ruoyi.procurementrecord.service.impl.ProcurementRecordOutServiceImpl;
import com.ruoyi.procurementrecord.service.impl.ProcurementRecordServiceImpl;
import com.ruoyi.production.dto.ProductionReportDto;
import com.ruoyi.production.dto.SalesLedgerWorkDto;
import com.ruoyi.production.mapper.SalesLedgerProductionAccountingMapper;
import com.ruoyi.production.mapper.SalesLedgerWorkMapper;
import com.ruoyi.production.pojo.SalesLedgerProductionAccounting;
import com.ruoyi.production.pojo.SalesLedgerWork;
import com.ruoyi.production.service.SalesLedgerProductionAccountingService;
import com.ruoyi.production.service.SalesLedgerWorkService;
import com.ruoyi.project.system.domain.SysUser;
import com.ruoyi.project.system.mapper.SysUserMapper;
import com.ruoyi.sales.mapper.LossMapper;
import com.ruoyi.sales.pojo.Loss;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
/**
 * @author :yys
 * @date : 2025/7/21 14:40
 */
@Service
@RequiredArgsConstructor
@Slf4j
public class SalesLedgerWorkServiceImpl extends ServiceImpl<SalesLedgerWorkMapper, SalesLedgerWork> implements SalesLedgerWorkService {
    private final SalesLedgerWorkMapper salesLedgerWorkMapper;
    private final SysUserMapper sysUserMapper;
    private final LossMapper lossMapper;
    private final SalesLedgerProductionAccountingMapper salesLedgerProductionAccountingMapper;
    @Override
    public IPage<SalesLedgerWorkDto> listPage(Page page, SalesLedgerWorkDto salesLedgerWorkDto) {
        IPage<SalesLedgerWorkDto> iPage = salesLedgerWorkMapper.listPage(page, salesLedgerWorkDto);
        List<Loss> losses = lossMapper.selectList(null);
        if(!CollectionUtils.isEmpty(losses)){
            iPage.getRecords().forEach(item -> {
                String[] split = item.getSpecificationModel().split("\\*");
                if(split.length == 2 && isNumeric(split[1]) && isNumeric(split[0])){
                    // 计算损耗(100000代表 损耗的 100 和 单位转换的1000)
                    BigDecimal divide = new BigDecimal(split[0])
                            .multiply(new BigDecimal(split[1]))
                            .multiply(item.getFinishedNum())
                            .multiply(losses.get(0).getRate())
                            .divide(new BigDecimal(100000), 2, RoundingMode.HALF_UP);
                    item.setLoss(divide.toString());
                }
            });
        }
        return iPage;
    }
    public static boolean isNumeric(String str) {
        if (str == null || str.isEmpty()) {
            return false;
        }
        // 遍历字符串的每个字符,检查是否为数字
        for (int i = 0; i < str.length(); i++) {
            if (!Character.isDigit(str.charAt(i))) {
                return false;
            }
        }
        return true;
    }
    private final ProcurementRecordServiceImpl procurementRecordService;
    @Override
    public int productionReport(ProductionReportDto productionReportDto) {
        SalesLedgerWork salesLedgerWork = salesLedgerWorkMapper.selectById(productionReportDto.getId());
        SysUser sysUser = sysUserMapper.selectUserById(productionReportDto.getSchedulingUserId());
        if (salesLedgerWork == null) throw new RuntimeException("报工数据不存在");
        if (salesLedgerWork.getStatus() == 3) throw new RuntimeException("报工已完成");
        if (sysUser == null) throw new RuntimeException("生产人不存在");
        salesLedgerWork.setFinishedNum(salesLedgerWork.getFinishedNum().add(productionReportDto.getFinishedNum()));
        if(salesLedgerWork.getSchedulingNum().compareTo(salesLedgerWork.getFinishedNum()) <= 0){
            salesLedgerWork.setStatus(3);
        }else{
            salesLedgerWork.setStatus(2);
        }
        salesLedgerWorkMapper.updateById(salesLedgerWork);
        // 新增报工数据
        SalesLedgerProductionAccounting.SalesLedgerProductionAccountingBuilder builder = SalesLedgerProductionAccounting.builder()
                .salesLedgerWorkId(salesLedgerWork.getId())
                .salesLedgerSchedulingId(salesLedgerWork.getSalesLedgerSchedulingId())
                .salesLedgerId(salesLedgerWork.getSalesLedgerId())
                .salesLedgerProductId((long)salesLedgerWork.getSalesLedgerProductId())
                .schedulingUserId(sysUser.getUserId())
                .schedulingUserName(sysUser.getNickName())
                .finishedNum(productionReportDto.getFinishedNum())
                .workHours(salesLedgerWork.getWorkHours())
                .process(salesLedgerWork.getProcess())
                .schedulingDate(LocalDate.parse(productionReportDto.getSchedulingDate(), DateTimeFormatter.ISO_LOCAL_DATE));
        salesLedgerProductionAccountingMapper.insert(builder.build());
        // 生产报工成功 -> 入库
        LoginUser loginUser = SecurityUtils.getLoginUser();
        ProcurementAddDto procurementRecordOutAdd = new ProcurementAddDto();
        procurementRecordOutAdd.setType(2);
        procurementRecordOutAdd.setTypeName("生产入库");
        procurementRecordOutAdd.setNickName(loginUser.getNickName());
        List<Details> details = new ArrayList<>();
        Details details1 = new Details();
        details1.setInboundQuantity(productionReportDto.getFinishedNum());
        details1.setId(Integer.parseInt(salesLedgerWork.getSalesLedgerProductId().toString()));
        details1.setUnitPrice(productionReportDto.getUnitPrice());
        details1.setTotalPrice(productionReportDto.getTotalPrice());
        details.add(details1);
        procurementRecordOutAdd.setDetails(details);
        procurementRecordService.add(procurementRecordOutAdd);
        return 0;
    }
    @Override
    public int productionReportUpdate(ProductionReportDto productionReportDto) {
        SalesLedgerProductionAccounting salesLedgerProductionAccounting = salesLedgerProductionAccountingMapper.selectById(productionReportDto.getId());
        if(salesLedgerProductionAccounting == null) throw new RuntimeException("报工数据不存在");
        SysUser sysUser = sysUserMapper.selectUserById(productionReportDto.getSchedulingUserId());
        if(sysUser == null) throw new RuntimeException("生产人不存在");
        salesLedgerProductionAccounting.setFinishedNum(productionReportDto.getFinishedNum());
        salesLedgerProductionAccounting.setSchedulingUserId(sysUser.getUserId());
        salesLedgerProductionAccounting.setSchedulingUserName(sysUser.getNickName());
        salesLedgerProductionAccounting.setSchedulingDate(LocalDate.parse(productionReportDto.getSchedulingDate(), DateTimeFormatter.ISO_LOCAL_DATE));
        salesLedgerProductionAccountingMapper.updateById(salesLedgerProductionAccounting);
        // 更新报工数据
        SalesLedgerWork salesLedgerWork = salesLedgerWorkMapper.selectById(salesLedgerProductionAccounting.getSalesLedgerWorkId());
        if(salesLedgerWork == null) throw new RuntimeException("报工数据不存在");
        salesLedgerWork.setFinishedNum(productionReportDto.getFinishedNum());
        if(salesLedgerWork.getSchedulingNum().compareTo(salesLedgerWork.getFinishedNum()) <= 0){
            salesLedgerWork.setStatus(3);
        }else{
            salesLedgerWork.setStatus(2);
        }
        salesLedgerWork.setSchedulingUserId(sysUser.getUserId());
        salesLedgerWork.setSchedulingUserName(sysUser.getNickName());
        salesLedgerWork.setSchedulingDate(LocalDate.parse(productionReportDto.getSchedulingDate(), DateTimeFormatter.ISO_LOCAL_DATE));
        salesLedgerWorkMapper.updateById(salesLedgerWork);
        return 0;
    }
    @Override
    public List<ProductionReportDto> getList(Long id) {
        SalesLedgerWork salesLedgerWork = salesLedgerWorkMapper.selectById(id);
        if(salesLedgerWork == null) throw new RuntimeException("报工数据不存在");
        LambdaQueryWrapper<SalesLedgerProductionAccounting> salesLedgerProductionAccountingLambdaQueryWrapper = new LambdaQueryWrapper<>();
        salesLedgerProductionAccountingLambdaQueryWrapper.eq(SalesLedgerProductionAccounting::getSalesLedgerWorkId, id);
        List<SalesLedgerProductionAccounting> salesLedgerProductionAccountingList = salesLedgerProductionAccountingMapper.selectList(salesLedgerProductionAccountingLambdaQueryWrapper);
        if(CollectionUtils.isEmpty(salesLedgerProductionAccountingList)) throw new RuntimeException("没有生产记录数据");
        return salesLedgerProductionAccountingList.stream().map(salesLedgerProductionAccounting -> {
            ProductionReportDto productionReportDto = new ProductionReportDto();
            BeanUtils.copyProperties(salesLedgerProductionAccounting, productionReportDto);
            productionReportDto.setSchedulingDate(salesLedgerProductionAccounting.getSchedulingDate().format(DateTimeFormatter.ISO_LOCAL_DATE));
            productionReportDto.setSchedulingNum(salesLedgerWork.getSchedulingNum());
            return productionReportDto;
        }).collect(Collectors.toList());
    }
}
//package com.ruoyi.production.service.impl;
//
//import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
//import com.baomidou.mybatisplus.core.metadata.IPage;
//import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
//import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
//import com.ruoyi.common.utils.SecurityUtils;
//import com.ruoyi.framework.security.LoginUser;
//import com.ruoyi.framework.web.domain.AjaxResult;
//import com.ruoyi.procurementrecord.dto.Details;
//import com.ruoyi.procurementrecord.dto.ProcurementAddDto;
//import com.ruoyi.procurementrecord.dto.ProcurementRecordOutAdd;
//import com.ruoyi.procurementrecord.service.impl.ProcurementRecordOutServiceImpl;
//import com.ruoyi.procurementrecord.service.impl.ProcurementRecordServiceImpl;
//import com.ruoyi.production.dto.ProductionReportDto;
//import com.ruoyi.production.dto.SalesLedgerWorkDto;
//import com.ruoyi.production.mapper.SalesLedgerProductionAccountingMapper;
//import com.ruoyi.production.mapper.SalesLedgerWorkMapper;
//import com.ruoyi.production.pojo.SalesLedgerProductionAccounting;
//import com.ruoyi.production.pojo.SalesLedgerWork;
//import com.ruoyi.production.service.SalesLedgerProductionAccountingService;
//import com.ruoyi.production.service.SalesLedgerWorkService;
//import com.ruoyi.project.system.domain.SysUser;
//import com.ruoyi.project.system.mapper.SysUserMapper;
//import com.ruoyi.sales.mapper.LossMapper;
//import com.ruoyi.sales.pojo.Loss;
//import lombok.RequiredArgsConstructor;
//import lombok.extern.slf4j.Slf4j;
//import org.springframework.beans.BeanUtils;
//import org.springframework.stereotype.Service;
//import org.springframework.util.CollectionUtils;
//
//import java.math.BigDecimal;
//import java.math.RoundingMode;
//import java.time.LocalDate;
//import java.time.format.DateTimeFormatter;
//import java.util.ArrayList;
//import java.util.List;
//import java.util.stream.Collectors;
//
///**
// * @author :yys
// * @date : 2025/7/21 14:40
// */
//@Service
//@RequiredArgsConstructor
//@Slf4j
//public class SalesLedgerWorkServiceImpl extends ServiceImpl<SalesLedgerWorkMapper, SalesLedgerWork> implements SalesLedgerWorkService {
//
//    private final SalesLedgerWorkMapper salesLedgerWorkMapper;
//
//    private final SysUserMapper sysUserMapper;
//
//    private final LossMapper lossMapper;
//
//    private final SalesLedgerProductionAccountingMapper salesLedgerProductionAccountingMapper;
//
//    @Override
//    public IPage<SalesLedgerWorkDto> listPage(Page page, SalesLedgerWorkDto salesLedgerWorkDto) {
//        IPage<SalesLedgerWorkDto> iPage = salesLedgerWorkMapper.listPage(page, salesLedgerWorkDto);
//        List<Loss> losses = lossMapper.selectList(null);
//        if(!CollectionUtils.isEmpty(losses)){
//            iPage.getRecords().forEach(item -> {
//                String[] split = item.getSpecificationModel().split("\\*");
//                if(split.length == 2 && isNumeric(split[1]) && isNumeric(split[0])){
//                    // 计算损耗(100000代表 损耗的 100 和 单位转换的1000)
//                    BigDecimal divide = new BigDecimal(split[0])
//                            .multiply(new BigDecimal(split[1]))
//                            .multiply(item.getFinishedNum())
//                            .multiply(losses.get(0).getRate())
//                            .divide(new BigDecimal(100000), 2, RoundingMode.HALF_UP);
//                    item.setLoss(divide.toString());
//                }
//
//            });
//        }
//        return iPage;
//    }
//
//    public static boolean isNumeric(String str) {
//        if (str == null || str.isEmpty()) {
//            return false;
//        }
//        // 遍历字符串的每个字符,检查是否为数字
//        for (int i = 0; i < str.length(); i++) {
//            if (!Character.isDigit(str.charAt(i))) {
//                return false;
//            }
//        }
//        return true;
//    }
//
//    private final ProcurementRecordServiceImpl procurementRecordService;
//
//    @Override
//    public int productionReport(ProductionReportDto productionReportDto) {
//        SalesLedgerWork salesLedgerWork = salesLedgerWorkMapper.selectById(productionReportDto.getId());
//        SysUser sysUser = sysUserMapper.selectUserById(productionReportDto.getSchedulingUserId());
//        if (salesLedgerWork == null) throw new RuntimeException("报工数据不存在");
//        if (salesLedgerWork.getStatus() == 3) throw new RuntimeException("报工已完成");
//        if (sysUser == null) throw new RuntimeException("生产人不存在");
//        salesLedgerWork.setFinishedNum(salesLedgerWork.getFinishedNum().add(productionReportDto.getFinishedNum()));
//        if(salesLedgerWork.getSchedulingNum().compareTo(salesLedgerWork.getFinishedNum()) <= 0){
//            salesLedgerWork.setStatus(3);
//        }else{
//            salesLedgerWork.setStatus(2);
//        }
//        salesLedgerWorkMapper.updateById(salesLedgerWork);
//        // 新增报工数据
//        SalesLedgerProductionAccounting.SalesLedgerProductionAccountingBuilder builder = SalesLedgerProductionAccounting.builder()
//                .productMainId(null)
//                .schedulingUserId(sysUser.getUserId())
//                .schedulingUserName(sysUser.getNickName())
//                .finishedNum(productionReportDto.getFinishedNum())
//                .workHours(salesLedgerWork.getWorkHours())
//                .process(salesLedgerWork.getProcess())
//                .schedulingDate(LocalDate.parse(productionReportDto.getSchedulingDate(), DateTimeFormatter.ISO_LOCAL_DATE));
//        salesLedgerProductionAccountingMapper.insert(builder.build());
//        // 生产报工成功 -> 入库
//        LoginUser loginUser = SecurityUtils.getLoginUser();
//        ProcurementAddDto procurementRecordOutAdd = new ProcurementAddDto();
//        procurementRecordOutAdd.setType(2);
//        procurementRecordOutAdd.setTypeName("生产入库");
//        procurementRecordOutAdd.setNickName(loginUser.getNickName());
//        List<Details> details = new ArrayList<>();
//        Details details1 = new Details();
//        details1.setInboundQuantity(productionReportDto.getFinishedNum());
//        details1.setId(Integer.parseInt(salesLedgerWork.getSalesLedgerProductId().toString()));
//        details1.setUnitPrice(productionReportDto.getUnitPrice());
//        details1.setTotalPrice(productionReportDto.getTotalPrice());
//        details.add(details1);
//        procurementRecordOutAdd.setDetails(details);
//        procurementRecordService.add(procurementRecordOutAdd);
//
//        return 0;
//    }
//
//    @Override
//    public int productionReportUpdate(ProductionReportDto productionReportDto) {
//        SalesLedgerProductionAccounting salesLedgerProductionAccounting = salesLedgerProductionAccountingMapper.selectById(productionReportDto.getId());
//        if(salesLedgerProductionAccounting == null) throw new RuntimeException("报工数据不存在");
//        SysUser sysUser = sysUserMapper.selectUserById(productionReportDto.getSchedulingUserId());
//        if(sysUser == null) throw new RuntimeException("生产人不存在");
//        salesLedgerProductionAccounting.setFinishedNum(productionReportDto.getFinishedNum());
//        salesLedgerProductionAccounting.setSchedulingUserId(sysUser.getUserId());
//        salesLedgerProductionAccounting.setSchedulingUserName(sysUser.getNickName());
//        salesLedgerProductionAccounting.setSchedulingDate(LocalDate.parse(productionReportDto.getSchedulingDate(), DateTimeFormatter.ISO_LOCAL_DATE));
//        salesLedgerProductionAccountingMapper.updateById(salesLedgerProductionAccounting);
//
//        // 更新报工数据
//        SalesLedgerWork salesLedgerWork = salesLedgerWorkMapper.selectById(salesLedgerProductionAccounting.getSalesLedgerWorkId());
//        if(salesLedgerWork == null) throw new RuntimeException("报工数据不存在");
//        salesLedgerWork.setFinishedNum(productionReportDto.getFinishedNum());
//        if(salesLedgerWork.getSchedulingNum().compareTo(salesLedgerWork.getFinishedNum()) <= 0){
//            salesLedgerWork.setStatus(3);
//        }else{
//            salesLedgerWork.setStatus(2);
//        }
//        salesLedgerWork.setSchedulingUserId(sysUser.getUserId());
//        salesLedgerWork.setSchedulingUserName(sysUser.getNickName());
//        salesLedgerWork.setSchedulingDate(LocalDate.parse(productionReportDto.getSchedulingDate(), DateTimeFormatter.ISO_LOCAL_DATE));
//        salesLedgerWorkMapper.updateById(salesLedgerWork);
//        return 0;
//    }
//
//    @Override
//    public List<ProductionReportDto> getList(Long id) {
//        SalesLedgerWork salesLedgerWork = salesLedgerWorkMapper.selectById(id);
//        if(salesLedgerWork == null) throw new RuntimeException("报工数据不存在");
//        LambdaQueryWrapper<SalesLedgerProductionAccounting> salesLedgerProductionAccountingLambdaQueryWrapper = new LambdaQueryWrapper<>();
//        salesLedgerProductionAccountingLambdaQueryWrapper.eq(SalesLedgerProductionAccounting::getSalesLedgerWorkId, id);
//        List<SalesLedgerProductionAccounting> salesLedgerProductionAccountingList = salesLedgerProductionAccountingMapper.selectList(salesLedgerProductionAccountingLambdaQueryWrapper);
//        if(CollectionUtils.isEmpty(salesLedgerProductionAccountingList)) throw new RuntimeException("没有生产记录数据");
//        return salesLedgerProductionAccountingList.stream().map(salesLedgerProductionAccounting -> {
//            ProductionReportDto productionReportDto = new ProductionReportDto();
//            BeanUtils.copyProperties(salesLedgerProductionAccounting, productionReportDto);
//            productionReportDto.setSchedulingDate(salesLedgerProductionAccounting.getSchedulingDate().format(DateTimeFormatter.ISO_LOCAL_DATE));
//            productionReportDto.setSchedulingNum(salesLedgerWork.getSchedulingNum());
//            return productionReportDto;
//        }).collect(Collectors.toList());
//    }
//}
src/main/java/com/ruoyi/sales/service/impl/SalesLedgerProductServiceImpl.java
@@ -15,6 +15,7 @@
import com.ruoyi.production.dto.ProductStructureDto;
import com.ruoyi.production.mapper.*;
import com.ruoyi.production.pojo.*;
import com.ruoyi.production.service.impl.SalesLedgerProductionAccountingServiceImpl;
import com.ruoyi.purchase.mapper.PurchaseLedgerMapper;
import com.ruoyi.purchase.pojo.PurchaseLedger;
import com.ruoyi.quality.mapper.QualityInspectMapper;
@@ -92,6 +93,8 @@
    private ProductStructureMapper productStructureMapper;
    @Autowired
    private StockInventoryMapper stockInventoryMapper;
    @Autowired
    private SalesLedgerProductionAccountingServiceImpl salesLedgerProductionAccountingServiceImpl;
    @Override
    public SalesLedgerProduct selectSalesLedgerProductById(Long id) {
@@ -228,9 +231,7 @@
            /*删除对应的生产数据并重新新增*/
            deleteProductionData(Arrays.asList(salesLedgerProduct.getId()));
            // 删除生产核算数据
            LambdaQueryWrapper<SalesLedgerProductionAccounting> reportWrapper = new LambdaQueryWrapper<>();
            reportWrapper.in(SalesLedgerProductionAccounting::getSalesLedgerId, salesLedgerId);
            salesLedgerProductionAccountingMapper.delete(reportWrapper);
            addProductionData(salesLedgerProduct);
        }
@@ -407,6 +408,8 @@
                            }
                        });
                        qualityInspectMapper.deleteByProductMainIds(productMainIds);
                        salesLedgerProductionAccountingMapper.delete(new LambdaQueryWrapper<SalesLedgerProductionAccounting>()
                                .in(SalesLedgerProductionAccounting::getProductMainId, productMainIds));
                    }
                    // 删除生产主表数据
src/main/java/com/ruoyi/sales/service/impl/SalesLedgerServiceImpl.java
@@ -25,6 +25,8 @@
import com.ruoyi.other.pojo.TempFile;
import com.ruoyi.production.mapper.*;
import com.ruoyi.production.pojo.*;
import com.ruoyi.production.service.ProductionProductMainService;
import com.ruoyi.production.service.impl.ProductionProductMainServiceImpl;
import com.ruoyi.project.system.domain.SysDept;
import com.ruoyi.project.system.domain.SysUser;
import com.ruoyi.project.system.mapper.SysDeptMapper;
@@ -146,6 +148,8 @@
    private ProductMapper productMapper;
    @Autowired
    private ProductStructureMapper productStructureMapper;
    @Autowired
    private ProductionProductMainService productionProductMainService;
;
    @Override
@@ -560,18 +564,13 @@
        commonFileService.deleteByBusinessIds(idList, FileNameType.SALE.getValue());
        // 删除生产管控数据
        // 删除生产订单数据
        LambdaQueryWrapper<SalesLedgerScheduling> in = new LambdaQueryWrapper<SalesLedgerScheduling>()
                .in(SalesLedgerScheduling::getSalesLedgerId, idList);
        salesLedgerSchedulingMapper.delete(in);
        // 删除生产派工数据
        LambdaQueryWrapper<SalesLedgerWork> workOrderWrapper = new LambdaQueryWrapper<>();
        workOrderWrapper.in(SalesLedgerWork::getSalesLedgerId, idList);
        salesLedgerWorkMapper.delete(workOrderWrapper);
        // 删除生产核算数据
        LambdaQueryWrapper<SalesLedgerProductionAccounting> reportWrapper = new LambdaQueryWrapper<>();
        reportWrapper.in(SalesLedgerProductionAccounting::getSalesLedgerId, idList);
        salesLedgerProductionAccountingMapper.delete(reportWrapper);
        //查询生产报工id
        ArrayList<Long> mainIdList = productionProductMainService.listMain(idList);
        if (CollectionUtils.isNotEmpty(mainIdList)) {
            mainIdList.stream().forEach(mainId -> {
                productionProductMainService.removeProductMain(mainId);
            });
        }
        // 2. 再删除主表数据
        return salesLedgerMapper.deleteBatchIds(idList);
    }
src/main/resources/mapper/production/ProductOrderMapper.xml
@@ -66,8 +66,7 @@
        select pr.*
        from process_route pr
                 left join product_model pm on pr.product_model_id = pm.id
                 left join sales_ledger_product slp on pm.id = slp.product_model_id
        where slp.id = #{productModelId}
        where pm.id = #{productModelId}
    </select>
    <select id="listProcessBom" resultType="com.ruoyi.production.dto.ProductStructureDto">
        select ps.id,
src/main/resources/mapper/production/ProductionProductMainMapper.xml
@@ -71,7 +71,7 @@
        slpa.work_hours * slpa.finished_num AS wages
        FROM
        production_product_main ppm
        LEFT JOIN sales_ledger_production_accounting slpa ON slpa.sales_ledger_work_id = ppm.id
        LEFT JOIN sales_ledger_production_accounting slpa ON slpa.product_main_id = ppm.id
        LEFT JOIN production_product_output ppo ON ppm.id = ppo.product_main_id
        LEFT JOIN product_work_order pwo ON pwo.id = ppm.work_order_id
        LEFT JOIN product_order po ON po.id = pwo.product_order_id
@@ -93,6 +93,20 @@
            </if>
        </where>
    </select>
    <select id="listMain" resultType="java.lang.Long">
        SELECT ppm.id FROM production_product_main ppm
            left join product_work_order pwo on pwo.id = ppm.work_order_id
                  left join product_order po on po.id = pwo.product_order_id
                  left join sales_ledger sl on sl.id = po.sales_ledger_id
        <where>
            <if test="idList != null and idList.size() > 0">
                and sl.id in
                <foreach item="id" collection="idList" open="(" separator="," close=")">
                    #{id}
                </foreach>
            </if>
        </where>
    </select>
    <delete id="deleteByWorkOrderIds" parameterType="java.util.List">
        DELETE FROM production_product_main
src/main/resources/mapper/production/SalesLedgerProductionAccountingMapper.xml
@@ -68,7 +68,7 @@
        '%'
        ) as output_rate
        FROM sales_ledger_production_accounting slpa
        LEFT JOIN production_product_main ppm ON slpa.sales_ledger_work_id = ppm.id
        LEFT JOIN production_product_main ppm ON slpa.product_main_id = ppm.id
        LEFT JOIN production_product_output ppout ON ppm.id = ppout.product_main_id
        <where>
            <if test="ew.schedulingUserName != null and ew.schedulingUserName !=''">