zhaokai 2025-11-04 14:43:21 +08:00
commit 78820da98b
11 changed files with 100 additions and 71 deletions

View File

@ -1,12 +1,9 @@
package com.zcloud.basic.info.facade;
import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.collection.CollUtil;
import com.alibaba.cola.dto.MultiResponse;
import com.alibaba.cola.dto.SingleResponse;
import com.zcloud.basic.info.api.PostServiceI;
import com.zcloud.basic.info.dto.PostListQry;
import com.zcloud.basic.info.dto.clientobject.DepartmentCO;
import com.zcloud.basic.info.dto.clientobject.PostCO;
import com.zcloud.basic.info.dto.clientobject.PostDepartmentCO;
import com.zcloud.gbscommon.utils.DeepCopyUtil;
@ -22,7 +19,6 @@ import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.stream.Collectors;
/**
* @author SondonYong
@ -44,19 +40,13 @@ public class ZcloudPostFacadeImpl implements ZcloudPostFacade {
return null;
}
// ZcloudPostCO zcloudPostCO = new ZcloudPostCO();
// BeanUtils.copyProperties(postCO.getData(), zcloudPostCO);
// 定义映射关系
Map<Class<?>, Class<?>> mapping = new HashMap<>();
mapping.put(PostDepartmentCO.class, ZcloudPostDepartmentCO.class);
// 单个对象
ZcloudPostCO zcloudPostCO = DeepCopyUtil.deepCopy(postCO.getData(), ZcloudPostCO.class, mapping);
// List<ZcloudPostDepartmentCO> zcloudPostDepartmentCOS = BeanUtil.copyToList(postCO.getData().getDepartmentList(), ZcloudPostDepartmentCO.class);
// zcloudPostCO.setDepartmentList(zcloudPostDepartmentCOS);
return SingleResponse.of(zcloudPostCO);
}
@ -70,30 +60,13 @@ public class ZcloudPostFacadeImpl implements ZcloudPostFacade {
return null;
}
// 定义映射关系
Map<Class<?>, Class<?>> mapping = new HashMap<>();
mapping.put(PostDepartmentCO.class, ZcloudPostDepartmentCO.class);
// 集合
List<ZcloudPostCO> zcloudPostCOList = DeepCopyUtil.copyList(list.getData(), ZcloudPostCO.class, mapping);
// List<ZcloudPostCO> zcloudPostCOList = BeanUtil.copyToList(list.getData(), ZcloudPostCO.class);
// List<ZcloudPostCO> zcloudPostCOList = list.getData().stream()
// .map(postCO -> {
// // 复制基本属性
// ZcloudPostCO zcloudPostCO = BeanUtil.toBean(postCO, ZcloudPostCO.class);
//
// // 手动处理嵌套List
// if (CollUtil.isNotEmpty(postCO.getDepartmentList())) {
// List<ZcloudPostDepartmentCO> deptList = BeanUtil.copyToList(
// postCO.getDepartmentList(),
// ZcloudPostDepartmentCO.class
// );
// zcloudPostCO.setDepartmentList(deptList);
// }
//
// return zcloudPostCO;
// })
// .collect(Collectors.toList());
return MultiResponse.of(zcloudPostCOList);
}
}

View File

@ -1,6 +1,7 @@
package com.zcloud.basic.info.facade;
import com.alibaba.cola.dto.MultiResponse;
import com.alibaba.cola.dto.SingleResponse;
import com.zcloud.gbscommon.zclouduser.facade.ZcloudUserFacade;
import com.zcloud.gbscommon.zclouduser.response.ZcloudUserCo;
import org.apache.dubbo.config.annotation.DubboService;
@ -22,4 +23,9 @@ public class ZcloudUserFacadeImpl implements ZcloudUserFacade {
objects.add(zcloudUserCo);
return MultiResponse.of(objects);
}
@Override
public SingleResponse<ZcloudUserCo> getInfoByUserId(Long aLong) {
return null;
}
}

View File

@ -68,10 +68,10 @@ public class ImgFilesController {
}
@ApiOperation("删除")
@DeleteMapping("/{filePath}")
public Response removeFile(@PathVariable("filePath") String filePath) {
@DeleteMapping("/delete")
public Response removeFile(@RequestParam String filePath) {
imgFilesService.removeFile(filePath);
return SingleResponse.buildSuccess();
return Response.buildSuccess();
}
@ApiOperation("删除多个")

View File

@ -1,11 +1,19 @@
package com.zcloud.basic.info.command;
import com.alibaba.cola.exception.BizException;
import com.zcloud.basic.info.command.convertor.ImgFilesCoConvertor;
import com.zcloud.basic.info.domain.gateway.ImgFilesGateway;
import com.zcloud.basic.info.domain.model.ImgFilesE;
import com.zcloud.basic.info.persistence.dataobject.ImgFilesDO;
import com.zcloud.basic.info.persistence.repository.ImgFilesRepository;
import com.zcloud.gbscommon.utils.Smb;
import lombok.AllArgsConstructor;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;
import java.util.Arrays;
import java.util.List;
/**
* web-app
@ -17,20 +25,29 @@ import org.springframework.transaction.annotation.Transactional;
@AllArgsConstructor
public class ImgFilesRemoveExe {
private final ImgFilesGateway imgFilesGateway;
private final ImgFilesRepository imgFilesRepository;
private final ImgFilesCoConvertor imgFilesCoConvertor;
@Transactional(rollbackFor = Exception.class)
public boolean execute(String filePath) {
// if (!res) {
// throw new BizException("删除失败");
// }
ImgFilesE imgFilesE = new ImgFilesE();
try {
imgFilesE.deleteFile(filePath);
} catch (Exception e) {
throw new BizException("删除失败");
}
return true;
}
@Transactional(rollbackFor = Exception.class)
public boolean execute(Long[] ids) {
boolean res = imgFilesGateway.deletedImgFilesByIds(ids);
if (!res) {
List<ImgFilesDO> imgFilesDOList = imgFilesRepository.listByIds(Arrays.asList(ids));
List<ImgFilesE> imgFilesEList = imgFilesCoConvertor.converDOsToEs(imgFilesDOList);
ImgFilesE imgFilesE = new ImgFilesE();
try {
imgFilesE.deleteFileList(imgFilesEList);
imgFilesRepository.deleteList(ids);
} catch (Exception e) {
throw new BizException("删除失败");
}
return true;

View File

@ -22,6 +22,7 @@ public interface ImgFilesCoConvertor {
*/
List<ImgFilesCO> converDOsToCOs(List<ImgFilesDO> imgFilesDOs);
List<ImgFilesDO> converEsToDOs(List<ImgFilesE> imgFilesEs);
List<ImgFilesE> converDOsToEs(List<ImgFilesDO> imgFilesDOs);
}

View File

@ -37,6 +37,15 @@ public class ImgFilesCO extends ClientObject {
//企业id
@ApiModelProperty(value = "企业id")
private Long corpinfoId;
@ApiModelProperty(value = "文件列表")
private List<ImgFilesCO> fileList;
@ApiModelProperty(value = "md5")
private String md5;
//乐观锁
@ApiModelProperty(value = "乐观锁")
private Integer version;
@ -73,8 +82,6 @@ public class ImgFilesCO extends ClientObject {
//环境
@ApiModelProperty(value = "环境")
private String env;
@ApiModelProperty
private List<ImgFilesCO> fileList;
}

View File

@ -1,10 +1,8 @@
package com.zcloud.basic.info.domain.model;
import com.jjb.saas.framework.domain.model.BaseE;
import com.zcloud.gbscommon.utils.DateUtil;
import com.zcloud.gbscommon.utils.FileUpload;
import com.zcloud.gbscommon.utils.*;
//import com.zcloud.gbscommon.utils.Smb;
import com.zcloud.gbscommon.utils.Tools;
import lombok.Data;
import org.apache.commons.beanutils.BeanUtils;
import org.springframework.util.ObjectUtils;
@ -41,6 +39,8 @@ public class ImgFilesE extends BaseE {
private String path;
private MultipartFile[] files;
private String md5;
//乐观锁
private Integer version;
//创建人
@ -66,15 +66,11 @@ public class ImgFilesE extends BaseE {
//环境
private String env;
public String initAdd(Long tenantId, ImgFilesE baseImgFilesE) throws InvocationTargetException, IllegalAccessException {
public String initAdd(Long tenantId, ImgFilesE baseImgFilesE) {
MultipartFile[] files = baseImgFilesE.getFiles();
List<ImgFilesE> imgFilesList = new ArrayList<ImgFilesE>();
String foreignKey = ObjectUtils.isEmpty(baseImgFilesE.getForeignKey()) ? Tools.get32UUID() : baseImgFilesE.getForeignKey();
Long corpinfoId = ObjectUtils.isEmpty(baseImgFilesE.getCorpinfoId()) ? tenantId : baseImgFilesE.getCorpinfoId();
String filePath = corpinfoId.toString() + "/" + DateUtil.getMonth() + "/" + baseImgFilesE.getPath();
ImgFilesE imgFile = new ImgFilesE();
BeanUtils.copyProperties(baseImgFilesE, imgFile);
String filePath = corpinfoId.toString() + "/" + DateUtil.getMonth() + "/" + baseImgFilesE.getPath()+ "/";
// 文件上传并获取上传路径
String resultFilePath = FileUpload.fileUp(files[0], filePath, Tools.get32UUID());
return filePath + resultFilePath;
@ -89,19 +85,30 @@ public class ImgFilesE extends BaseE {
for (MultipartFile file : files) {
ImgFilesE imgFile = new ImgFilesE();
BeanUtils.copyProperties(baseImgFilesE, imgFile);
BeanUtils.copyProperties(imgFile, baseImgFilesE);
// 文件上传并获取上传路径
// Smb.saveFile(file, filePath);
String resultFilePath = Smb.saveFile(file, filePath);
imgFile.setImgFilesId(Tools.get32UUID());
// imgFile.setFilePath(filePath+);
imgFile.setFilePath(resultFilePath);
imgFile.setType(baseImgFilesE.getType());
imgFile.setForeignKey(foreignKey);
imgFile.setFileName(file.getOriginalFilename());
imgFile.setCorpinfoId(corpinfoId);
// imgFile.setMd5(FileUtil.getMD5(file));
imgFilesList.add(imgFile);
}
baseImgFilesE.setForeignKey(foreignKey);
return imgFilesList;
}
public void deleteFile(String filePath) throws Exception {
Smb.deleteFile(filePath);
}
public void deleteFileList(List<ImgFilesE> imgFilesEList) throws Exception {
for (ImgFilesE imgFilesE: imgFilesEList) {
Smb.deleteFile(imgFilesE.getFilePath());
}
}
}

View File

@ -44,6 +44,7 @@ public class ImgFilesGatewayImpl implements ImgFilesGateway {
@Override
public Boolean deletedImgFilesByIds(Long[] ids) {
return imgFilesRepository.removeByIds(Arrays.asList(ids));
}
}

View File

@ -8,10 +8,11 @@ import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;
/**
* web-infrastructure
* @Author zhangyue
* @Date 2025-10-30 16:10:06
*/
* web-infrastructure
*
* @Author zhangyue
* @Date 2025-10-30 16:10:06
*/
@Data
@TableName("img_files")
@NoArgsConstructor
@ -35,6 +36,9 @@ public class ImgFilesDO extends BaseDO {
//企业id
@ApiModelProperty(value = "企业id")
private Long corpinfoId;
//企业id
@ApiModelProperty(value = "md5")
private String md5;
public ImgFilesDO(String imgFilesId) {
this.imgFilesId = imgFilesId;

View File

@ -18,5 +18,8 @@ public interface ImgFilesRepository extends BaseRepository<ImgFilesDO> {
List<ImgFilesDO> listAll(Map<String,Object> parmas);
void deleteList(Long[] ids);
}

View File

@ -3,6 +3,7 @@ package com.zcloud.basic.info.persistence.repository.impl;
import com.alibaba.cola.dto.MultiResponse;
import com.alibaba.cola.dto.PageResponse;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.jjb.saas.framework.repository.common.PageHelper;
import com.jjb.saas.framework.repository.repo.impl.BaseRepositoryImpl;
@ -46,5 +47,14 @@ public class ImgFilesRepositoryImpl extends BaseRepositoryImpl<ImgFilesMapper, I
// queryWrapper.select("id", "img_files_id", "file_path", "type", "foreign_key", "file_name", "corpinfo_id");
return imgFilesMapper.selectList(queryWrapper);
}
@Override
public void deleteList(Long[] ids) {
UpdateWrapper<ImgFilesDO> updateWrapper = new UpdateWrapper<>();
updateWrapper.in("id", ids);
updateWrapper.eq("delete_enum" ,"FALSE");
updateWrapper.set("delete_enum", "TRUE");
imgFilesMapper.update(null, updateWrapper);
}
}