| | |
| | | import java.math.BigDecimal; |
| | | import java.time.LocalDate; |
| | | import java.time.LocalDateTime; |
| | | import java.time.format.DateTimeParseException; |
| | | import java.util.List; |
| | | |
| | | @Service |
| | |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public Boolean singleAdjust(ProductionAccountDto dto) { |
| | | if (dto == null || dto.getSchedulingUserId() == null) { |
| | | if (dto == null || (dto.getProductionProductMainId() == null && dto.getSchedulingUserId() == null)) { |
| | | throw new ServiceException("请选择需要修正的人员"); |
| | | } |
| | | BigDecimal adjustAmount = dto.getAdjustAmount(); |
| | | if (adjustAmount == null || adjustAmount.compareTo(BigDecimal.ZERO) == 0) { |
| | | throw new ServiceException("修正金额不能为空"); |
| | | } |
| | | ProductionAccount account = new ProductionAccount(); |
| | | account.setSchedulingUserId(dto.getSchedulingUserId()); |
| | | account.setSchedulingUserName(dto.getSchedulingUserName()); |
| | | account.setTechnologyOperationName("工资修正"); |
| | | account.setAdjustAmount(adjustAmount); |
| | | account.setAdjustRemark(dto.getAdjustRemark()); |
| | | account.setAdjustUser(dto.getAdjustUser()); |
| | | account.setAdjustTime(LocalDateTime.now()); |
| | | account.setSchedulingDate(LocalDateTime.now()); |
| | | account.setWorkHours(BigDecimal.ZERO); |
| | | account.setFinishedNum(BigDecimal.ZERO); |
| | | account.setAccountingBatchNo("ADJ-" + LocalDate.now()); |
| | | baseMapper.insert(account); |
| | | if (dto.getProductionProductMainId() != null) { |
| | | ProductionAccount account = new ProductionAccount(); |
| | | account.setAdjustAmount(adjustAmount); |
| | | account.setAdjustRemark(dto.getAdjustRemark()); |
| | | account.setAdjustUser(dto.getAdjustUser()); |
| | | account.setAdjustTime(LocalDateTime.now()); |
| | | baseMapper.update(account, new LambdaQueryWrapper<ProductionAccount>() |
| | | .eq(ProductionAccount::getProductionProductMainId, dto.getProductionProductMainId())); |
| | | } else { |
| | | ProductionAccount account = new ProductionAccount(); |
| | | account.setSchedulingUserId(dto.getSchedulingUserId()); |
| | | account.setSchedulingUserName(dto.getSchedulingUserName()); |
| | | account.setTechnologyOperationName("工资修正"); |
| | | account.setAdjustAmount(adjustAmount); |
| | | account.setAdjustRemark(dto.getAdjustRemark()); |
| | | account.setAdjustUser(dto.getAdjustUser()); |
| | | account.setAdjustTime(LocalDateTime.now()); |
| | | account.setSchedulingDate(LocalDateTime.now()); |
| | | account.setWorkHours(BigDecimal.ZERO); |
| | | account.setFinishedNum(BigDecimal.ZERO); |
| | | account.setAccountingBatchNo("ADJ-" + LocalDate.now()); |
| | | baseMapper.insert(account); |
| | | } |
| | | return Boolean.TRUE; |
| | | } |
| | | |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public Boolean rebuildByProductionProductMainId(Long productionProductMainId) { |
| | | if (productionProductMainId == null) { |
| | | return Boolean.FALSE; |
| | | } |
| | | ProductionProductMain productionProductMain = productionProductMainMapper.selectById(productionProductMainId); |
| | | if (productionProductMain == null) { |
| | | return Boolean.FALSE; |
| | | } |
| | | if (productionProductMain.getAuditStatus() == null || productionProductMain.getAuditStatus() != 1) { |
| | | productionAccountDelete(productionProductMainId); |
| | | return Boolean.FALSE; |
| | | } |
| | | if (productionProductMain.getReportType() == null || productionProductMain.getReportType() != 0) { |
| | | productionAccountDelete(productionProductMainId); |
| | | return Boolean.FALSE; |
| | | } |
| | | rebuildAccount(productionProductMain); |
| | | return Boolean.TRUE; |
| | | } |
| | | |
| | |
| | | if (productionProductMain == null || productionProductMain.getId() == null) { |
| | | return; |
| | | } |
| | | ProductionAccount existedAccount = baseMapper.selectOne(Wrappers.<ProductionAccount>lambdaQuery() |
| | | .eq(ProductionAccount::getProductionProductMainId, productionProductMain.getId()) |
| | | .last("limit 1")); |
| | | BigDecimal existedAdjustAmount = existedAccount == null ? null : existedAccount.getAdjustAmount(); |
| | | String existedAdjustRemark = existedAccount == null ? null : existedAccount.getAdjustRemark(); |
| | | Long existedAdjustUser = existedAccount == null ? null : existedAccount.getAdjustUser(); |
| | | LocalDateTime existedAdjustTime = existedAccount == null ? null : existedAccount.getAdjustTime(); |
| | | |
| | | productionAccountDelete(productionProductMain.getId()); |
| | | ProductionProductOutput output = productionProductOutputMapper.selectOne( |
| | | Wrappers.<ProductionProductOutput>lambdaQuery() |
| | |
| | | account.setTechnologyOperationName(technologyOperation == null ? null : technologyOperation.getName()); |
| | | account.setSchedulingDate(LocalDateTime.now()); |
| | | account.setAccountingBatchNo("BATCH-" + LocalDate.now()); |
| | | account.setAdjustAmount(existedAdjustAmount); |
| | | account.setAdjustRemark(existedAdjustRemark); |
| | | account.setAdjustUser(existedAdjustUser); |
| | | account.setAdjustTime(existedAdjustTime); |
| | | baseMapper.insert(account); |
| | | } |
| | | |
| | |
| | | if (dto == null) { |
| | | return new ProductionAccountDto(); |
| | | } |
| | | LocalDate[] dateRange = dto.getDateRange(); |
| | | if ((dto.getEntryDateStart() == null || dto.getEntryDateEnd() == null) |
| | | && dateRange != null |
| | | && dateRange.length > 0) { |
| | | && dto.getDateRange() != null |
| | | && dto.getDateRange().length > 0) { |
| | | LocalDate rangeStart = parseDate(dto.getDateRange()[0]); |
| | | LocalDate rangeEnd = dto.getDateRange().length > 1 ? parseDate(dto.getDateRange()[1]) : rangeStart; |
| | | if (dto.getEntryDateStart() == null) { |
| | | dto.setEntryDateStart(dateRange[0]); |
| | | dto.setEntryDateStart(rangeStart); |
| | | } |
| | | if (dto.getEntryDateEnd() == null) { |
| | | dto.setEntryDateEnd(dateRange.length > 1 ? dateRange[1] : dateRange[0]); |
| | | dto.setEntryDateEnd(rangeEnd); |
| | | } |
| | | } |
| | | |
| | | String dateType = dto.getDateType(); |
| | | if ("day".equalsIgnoreCase(dateType)) { |
| | | if (dto.getEntryDate() == null && dateRange != null && dateRange.length > 0) { |
| | | dto.setEntryDate(dateRange[0]); |
| | | if (dto.getEntryDate() == null && dto.getDateRange() != null && dto.getDateRange().length > 0) { |
| | | dto.setEntryDate(parseDate(dto.getDateRange()[0])); |
| | | } |
| | | if (dto.getEntryDate() == null) { |
| | | dto.setEntryDate(dto.getEntryDateStart()); |
| | |
| | | return dto; |
| | | } |
| | | |
| | | private LocalDate parseDate(String dateValue) { |
| | | if (dateValue == null || dateValue.isEmpty()) { |
| | | return null; |
| | | } |
| | | try { |
| | | return LocalDate.parse(dateValue); |
| | | } catch (DateTimeParseException e) { |
| | | throw new ServiceException("日期格式错误,请使用 yyyy-MM-dd"); |
| | | } |
| | | } |
| | | |
| | | } |