| | |
| | | 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.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; |
| | | |
| | |
| | | |
| | | 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) { |
| | |
| | | .salesLedgerWorkId(salesLedgerWork.getId()) |
| | | .salesLedgerSchedulingId(salesLedgerWork.getSalesLedgerSchedulingId()) |
| | | .salesLedgerId(salesLedgerWork.getSalesLedgerId()) |
| | | .salesLedgerProductId(salesLedgerWork.getSalesLedgerProductId()) |
| | | .salesLedgerProductId((long)salesLedgerWork.getSalesLedgerProductId()) |
| | | .schedulingUserId(sysUser.getUserId()) |
| | | .schedulingUserName(sysUser.getNickName()) |
| | | .finishedNum(productionReportDto.getFinishedNum()) |
| | |
| | | .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())); |
| | | details.add(details1); |
| | | procurementRecordOutAdd.setDetails(details); |
| | | procurementRecordService.add(procurementRecordOutAdd); |
| | | |
| | | return 0; |
| | | } |
| | | |
| | | @Override |
| | | public int productionReportUpdate(ProductionReportDto productionReportDto) { |
| | | SalesLedgerWork salesLedgerWork = salesLedgerWorkMapper.selectById(productionReportDto.getId()); |
| | | if(salesLedgerWork == null) throw new RuntimeException("报工数据不存在"); |
| | | 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); |
| | |
| | | salesLedgerWork.setSchedulingUserName(sysUser.getNickName()); |
| | | salesLedgerWork.setSchedulingDate(LocalDate.parse(productionReportDto.getSchedulingDate(), DateTimeFormatter.ISO_LOCAL_DATE)); |
| | | salesLedgerWorkMapper.updateById(salesLedgerWork); |
| | | |
| | | // 更新核算数据 |
| | | LambdaQueryWrapper<SalesLedgerProductionAccounting> salesLedgerProductionAccountingLambdaQueryWrapper = new LambdaQueryWrapper<>(); |
| | | salesLedgerProductionAccountingLambdaQueryWrapper.eq(SalesLedgerProductionAccounting::getSalesLedgerWorkId, salesLedgerWork.getId()) |
| | | .orderByDesc(SalesLedgerProductionAccounting::getCreateTime) |
| | | .last("limit 1"); |
| | | SalesLedgerProductionAccounting salesLedgerProductionAccounting = salesLedgerProductionAccountingMapper.selectOne(salesLedgerProductionAccountingLambdaQueryWrapper); |
| | | if(salesLedgerProductionAccounting != null){ |
| | | 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); |
| | | } |
| | | return 0; |
| | | } |
| | | |