| | |
| | | import org.springframework.beans.BeanUtils; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | import org.springframework.util.Assert; |
| | | import org.springframework.util.CollectionUtils; |
| | | |
| | | import java.util.List; |
| | | import java.util.stream.Collectors; |
| | |
| | | entity.setUpdateBy(userId); |
| | | baseMapper.insert(entity); |
| | | //添加文件 |
| | | List<File> fileList = form.getFileList(); |
| | | fileList.forEach(item->{ |
| | | item.setId(null); |
| | | item.setBusId(entity.getId()); |
| | | item.setType(FileTypeEnum.INVEST_POLICY); |
| | | }); |
| | | fileService.saveBatch(fileList); |
| | | if (!CollectionUtils.isEmpty(form.getFileList())) { |
| | | List<File> fileList = form.getFileList(); |
| | | fileList.forEach(item -> { |
| | | item.setId(null); |
| | | item.setBusId(entity.getId()); |
| | | item.setType(FileTypeEnum.INVEST_POLICY); |
| | | }); |
| | | fileService.saveBatch(fileList); |
| | | } |
| | | //避免新增一个后重复新增返回id给前端判断 |
| | | return Result.ok("添加成功").data(entity.getId()); |
| | | } |
| | |
| | | Long userId = SecurityUtils.getUserId(); |
| | | entity.setUpdateBy(userId); |
| | | baseMapper.updateById(entity); |
| | | List<File> fileList = form.getFileList(); |
| | | fileList.forEach(item->{ |
| | | item.setId(null); |
| | | item.setBusId(entity.getId()); |
| | | item.setType(FileTypeEnum.INVEST_POLICY); |
| | | }); |
| | | //删除原有文件 |
| | | QueryWrapper<File> fileQueryWrapper = new QueryWrapper<>(); |
| | | fileQueryWrapper.eq("type",FileTypeEnum.INVEST_POLICY.getType()); |
| | | fileQueryWrapper.eq("bus_id",entity.getId()); |
| | | fileMapper.delete(fileQueryWrapper); |
| | | //替换成现有 |
| | | fileService.saveBatch(fileList); |
| | | if (!CollectionUtils.isEmpty(form.getFileList())) { |
| | | List<File> fileList = form.getFileList(); |
| | | fileList.forEach(item->{ |
| | | item.setId(null); |
| | | item.setBusId(entity.getId()); |
| | | item.setType(FileTypeEnum.INVEST_POLICY); |
| | | }); |
| | | //删除原有文件 |
| | | QueryWrapper<File> fileQueryWrapper = new QueryWrapper<>(); |
| | | fileQueryWrapper.eq("type",FileTypeEnum.INVEST_POLICY.getType()); |
| | | fileQueryWrapper.eq("bus_id",entity.getId()); |
| | | fileMapper.delete(fileQueryWrapper); |
| | | //替换成现有 |
| | | fileService.saveBatch(fileList); |
| | | } |
| | | return Result.ok("修改成功"); |
| | | } |
| | | |