| | |
| | | import com.ruoyi.common.utils.SecurityUtils; |
| | | import com.ruoyi.common.utils.StringUtils; |
| | | import com.ruoyi.common.utils.poi.ExcelUtil; |
| | | import com.ruoyi.framework.web.domain.AjaxResult; |
| | | import com.ruoyi.framework.web.domain.R; |
| | | import com.ruoyi.project.system.domain.SysUser; |
| | | import com.ruoyi.project.system.mapper.SysUserMapper; |
| | | import com.ruoyi.stock.dto.ManufacturerDto; |
| | | import com.ruoyi.stock.execl.ManufacturerExcelDto; |
| | | import com.ruoyi.stock.mapper.ManufacturerMapper; |
| | |
| | | |
| | | private final StockInventoryMapper stockInventoryMapper; |
| | | private final ManufacturerMapper manufacturerMapper; |
| | | private final SysUserMapper sysUserMapper; |
| | | |
| | | /** |
| | | * 厂商新增 |
| | |
| | | LambdaQueryWrapper<Manufacturer> queryWrapper = new LambdaQueryWrapper<>(); |
| | | queryWrapper.eq(Manufacturer::getName,manufacturer.getName()); |
| | | if (baseMapper.selectCount(queryWrapper) > 0) { |
| | | throw new RuntimeException("供应商已存在"); |
| | | throw new RuntimeException("厂家已存在"); |
| | | } |
| | | |
| | | baseMapper.insert(manufacturer); |
| | |
| | | public void manufacturerExport(HttpServletResponse response, ManufacturerDto manufacturerDto) { |
| | | List<ManufacturerExcelDto> list = manufacturerMapper.manufacturerExportList(manufacturerDto); |
| | | ExcelUtil<ManufacturerExcelDto> util = new ExcelUtil<>(ManufacturerExcelDto.class); |
| | | util.exportExcel(response, list, "厂商数据"); |
| | | util.exportExcel(response, list, "厂家数据"); |
| | | } |
| | | |
| | | /** |
| | |
| | | */ |
| | | @Override |
| | | @Transactional |
| | | public Boolean importData(MultipartFile file) { |
| | | public R importData(MultipartFile file) { |
| | | try { |
| | | ExcelUtil<ManufacturerExcelDto> util = new ExcelUtil<>(ManufacturerExcelDto.class); |
| | | List<ManufacturerExcelDto> list = util.importExcel(file.getInputStream()); |
| | | ArrayList<Manufacturer> manufacturers = new ArrayList<>(); |
| | | list.stream().forEach(dto -> { |
| | | Manufacturer manufacturer = new Manufacturer(); |
| | | BeanUtils.copyProperties(dto,manufacturer); |
| | | BeanUtils.copyProperties(dto, manufacturer); |
| | | manufacturer.setMaintainTime(LocalDate.now()); |
| | | manufacturer.setMaintainUserId(SecurityUtils.getLoginUser().getUser().getUserId()); |
| | | |
| | | // 检查厂家名称是否重复 |
| | | LambdaQueryWrapper<Manufacturer> queryWrapper = new LambdaQueryWrapper<>(); |
| | | queryWrapper.eq(Manufacturer::getName, manufacturer.getName()); |
| | | if (baseMapper.selectCount(queryWrapper) > 0) { |
| | | throw new RuntimeException("厂家名称已存在: " + manufacturer.getName()); |
| | | } |
| | | |
| | | if (StringUtils.isEmpty(dto.getMaintainUserName())) { |
| | | manufacturer.setMaintainUserId(SecurityUtils.getLoginUser().getUser().getUserId()); |
| | | } else { |
| | | SysUser sysUser = sysUserMapper.selectOne(new LambdaQueryWrapper<SysUser>().eq(SysUser::getNickName, dto.getMaintainUserName())); |
| | | if (sysUser == null) { |
| | | throw new RuntimeException("维护人不存在: " + dto.getMaintainUserName()); |
| | | } |
| | | manufacturer.setMaintainUserId(sysUser.getUserId()); |
| | | } |
| | | manufacturers.add(manufacturer); |
| | | }); |
| | | this.saveOrUpdateBatch(manufacturers); |
| | | return true; |
| | | return R.ok("导入成功"); |
| | | } catch (Exception e) { |
| | | log.error("导入失败", e); |
| | | return false; |
| | | return R.fail("导入失败: " + e.getMessage()); |
| | | } |
| | | } |
| | | } |