| | |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | | import com.ruoyi.common.utils.DateUtils; |
| | | import com.ruoyi.common.utils.SecurityUtils; |
| | | import com.ruoyi.common.utils.StringUtils; |
| | | import com.ruoyi.common.utils.bean.BeanUtils; |
| | | import com.ruoyi.common.utils.poi.ExcelUtil; |
| | | import com.ruoyi.device.dto.DeviceLedgerDto; |
| | |
| | | import java.util.ArrayList; |
| | | import java.util.Arrays; |
| | | import java.util.List; |
| | | import java.time.format.DateTimeFormatter; |
| | | import java.time.LocalDate; |
| | | |
| | | @Service |
| | | @RequiredArgsConstructor |
| | |
| | | } |
| | | DeviceLedger deviceLedger = new DeviceLedger(); |
| | | BeanUtils.copyProperties(deviceLedgerDto, deviceLedger); |
| | | |
| | | if (StringUtils.isEmpty(deviceLedger.getUniqueCode())) { |
| | | String dateStr = LocalDate.now().format(DateTimeFormatter.ofPattern("yyyyMMdd")); |
| | | LambdaQueryWrapper<DeviceLedger> queryWrapper = new LambdaQueryWrapper<>(); |
| | | queryWrapper.likeRight(DeviceLedger::getUniqueCode, "SB" + dateStr); |
| | | queryWrapper.orderByDesc(DeviceLedger::getUniqueCode); |
| | | queryWrapper.last("limit 1"); |
| | | DeviceLedger lastRecord = this.getOne(queryWrapper); |
| | | int sequence = 1; |
| | | if (lastRecord != null && StringUtils.isNotEmpty(lastRecord.getUniqueCode()) && lastRecord.getUniqueCode().length() >= 13) { |
| | | String lastSeqStr = lastRecord.getUniqueCode().substring(10); |
| | | try { |
| | | sequence = Integer.parseInt(lastSeqStr) + 1; |
| | | } catch (NumberFormatException ignored) {} |
| | | } |
| | | deviceLedger.setUniqueCode("SB" + dateStr + String.format("%03d", sequence)); |
| | | } |
| | | |
| | | if (this.count(new LambdaQueryWrapper<DeviceLedger>().eq(DeviceLedger::getUniqueCode, deviceLedger.getUniqueCode())) > 0) { |
| | | return AjaxResult.error("设备编号已存在:" + deviceLedger.getUniqueCode()); |
| | | } |
| | | |
| | | boolean save = this.save(deviceLedger); |
| | | if (save){ |
| | | if (deviceLedgerDto.getStorageBlobDTOs() != null) { |
| | |
| | | |
| | | @Override |
| | | public AjaxResult updateDeviceLedger(DeviceLedgerDto deviceLedgerDto) { |
| | | if (StringUtils.isNotEmpty(deviceLedgerDto.getUniqueCode())) { |
| | | if (this.count(new LambdaQueryWrapper<DeviceLedger>() |
| | | .eq(DeviceLedger::getUniqueCode, deviceLedgerDto.getUniqueCode()) |
| | | .ne(DeviceLedger::getId, deviceLedgerDto.getId())) > 0) { |
| | | return AjaxResult.error("设备编号已存在:" + deviceLedgerDto.getUniqueCode()); |
| | | } |
| | | } |
| | | |
| | | DeviceLedger deviceLedger = new DeviceLedger(); |
| | | BeanUtils.copyProperties(deviceLedgerDto, deviceLedger); |
| | | if (this.updateById(deviceLedger)) { |
| | |
| | | public Boolean importData(MultipartFile file) throws IOException { |
| | | ExcelUtil<DeviceLedgerExeclDto> util = new ExcelUtil<DeviceLedgerExeclDto>(DeviceLedgerExeclDto.class); |
| | | List<DeviceLedgerExeclDto> userList = util.importExcel(file.getInputStream()); |
| | | |
| | | String dateStr = LocalDate.now().format(DateTimeFormatter.ofPattern("yyyyMMdd")); |
| | | LambdaQueryWrapper<DeviceLedger> queryWrapper = new LambdaQueryWrapper<>(); |
| | | queryWrapper.likeRight(DeviceLedger::getUniqueCode, "SB" + dateStr); |
| | | queryWrapper.orderByDesc(DeviceLedger::getUniqueCode); |
| | | queryWrapper.last("limit 1"); |
| | | DeviceLedger lastRecord = this.getOne(queryWrapper); |
| | | |
| | | // 应对Java lambda表达式内变量必须是final的问题,用数组或类的成员包裹 |
| | | final int[] maxSequence = {0}; |
| | | if (lastRecord != null && StringUtils.isNotEmpty(lastRecord.getUniqueCode()) && lastRecord.getUniqueCode().length() >= 13) { |
| | | String lastSeqStr = lastRecord.getUniqueCode().substring(10); |
| | | try { |
| | | maxSequence[0] = Integer.parseInt(lastSeqStr); |
| | | } catch (NumberFormatException ignored) {} |
| | | } |
| | | |
| | | List<String> importUniqueCodes = new ArrayList<>(); |
| | | |
| | | userList.forEach(c -> { |
| | | DeviceLedger deviceLedger = new DeviceLedger(); |
| | | SysUser sysUser = sysUserMapper.selectUserByUserName(c.getCreateUser()); |
| | |
| | | deviceLedger.setCreateUser(SecurityUtils.getUserId().intValue()); |
| | | } |
| | | BeanUtils.copyProperties(c,deviceLedger); |
| | | |
| | | if (StringUtils.isEmpty(deviceLedger.getUniqueCode())) { |
| | | maxSequence[0]++; |
| | | deviceLedger.setUniqueCode("SB" + dateStr + String.format("%03d", maxSequence[0])); |
| | | } |
| | | if (importUniqueCodes.contains(deviceLedger.getUniqueCode())) { |
| | | throw new RuntimeException("导入文件中存在重复的设备编号:" + deviceLedger.getUniqueCode()); |
| | | } |
| | | if (this.count(new LambdaQueryWrapper<DeviceLedger>().eq(DeviceLedger::getUniqueCode, deviceLedger.getUniqueCode())) > 0) { |
| | | throw new RuntimeException("设备编号已存在:" + deviceLedger.getUniqueCode()); |
| | | } |
| | | importUniqueCodes.add(deviceLedger.getUniqueCode()); |
| | | // 通过含税单价、数量、税率计算含税总价,不含税总价 |
| | | deviceLedger.setTaxIncludingPriceTotal(c.getTaxIncludingPriceUnit()); |
| | | deviceLedger.setNumber(BigDecimal.ONE); |
| | |
| | | if (deviceLedger.getTaxIncludingPriceTotal() != null && c.getTaxRate() != null) { |
| | | deviceLedger.setUnTaxIncludingPriceTotal(deviceLedger.getTaxIncludingPriceTotal().divide(BigDecimal.ONE.add(c.getTaxRate()), 2, RoundingMode.HALF_UP)); |
| | | } |
| | | |
| | | if (c.getPurchaseDate() != null) { |
| | | deviceLedger.setPurchaseDate(DateUtils.toLocalDate(c.getPurchaseDate())); |
| | | } |
| | | if (c.getActivationDate() != null) { |
| | | deviceLedger.setActivationDate(DateUtils.toLocalDate(c.getActivationDate())); |
| | | } |
| | | if (c.getFilingDate() != null) { |
| | | deviceLedger.setFilingDate(DateUtils.toLocalDate(c.getFilingDate())); |
| | | } |
| | | |
| | | deviceLedgerMapper.insert(deviceLedger); |
| | | }); |
| | | |