| | |
| | | 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.framework.web.domain.AjaxResult; |
| | | 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 lombok.RequiredArgsConstructor; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.springframework.beans.BeanUtils; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.util.CollectionUtils; |
| | | |
| | | import java.time.LocalDate; |
| | | import java.time.format.DateTimeFormatter; |
| | | 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 SalesLedgerProductionAccountingMapper salesLedgerProductionAccountingMapper; |
| | | |
| | | @Override |
| | | public IPage<SalesLedgerWorkDto> listPage(Page page, SalesLedgerWorkDto salesLedgerWorkDto) { |
| | | IPage<SalesLedgerWorkDto> iPage = salesLedgerWorkMapper.listPage(page, salesLedgerWorkDto); |
| | | return iPage; |
| | | } |
| | | |
| | | @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(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()); |
| | | 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()); |
| | | // } |
| | | //} |