| | |
| | | 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; |
| | |
| | | |
| | | 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])){ |
| | | // 计算损耗 |
| | | BigDecimal divide = new BigDecimal(split[0]) |
| | | .multiply(new BigDecimal(split[1])) |
| | | .multiply(item.getFinishedNum()) |
| | | .multiply(losses.get(0).getRate()) |
| | | .divide(new BigDecimal(100), 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 |