浏览代码

添加图片上传功能优化

吕宣芝 1 年之前
父节点
当前提交
9184d17b84

+ 8 - 2
src/main/java/com/sooka/sponest/data/digitalagriculture/domain/CenterdataTFarmPesticideInformation.java

@@ -70,9 +70,15 @@ public class CenterdataTFarmPesticideInformation extends BaseBusinessEntity {
     private String realityUsage;
 
     /**
-     * 图片上传
+     * 图片上传路径
      */
-    @ApiModelProperty(value = "图片上传", required = false)
+    @ApiModelProperty(value = "图片上传路径", required = false)
     private String attachPaths;
 
+    /**
+     * 图片来源
+     */
+    @ApiModelProperty(value = "图片来源", required = false)
+    private String busSource;
+
 }

+ 2 - 2
src/main/java/com/sooka/sponest/data/digitalagriculture/service/impl/CenterdataTFarmPesticideInformationServiceImpl.java

@@ -64,7 +64,7 @@ public class CenterdataTFarmPesticideInformationServiceImpl extends BaseServiceI
         centerdataTFarmPesticideInformation.setCreateBy(SecurityUtils.getUserId().toString());
         centerdataTFarmPesticideInformation.setCreateName(SecurityUtils.getLoginUser().getSysUser().getNickName());
         centerdataTFarmPesticideInformation.setCreateTime(DateUtils.getNowDate());
-        DataAttachUtil.dataAttachUpload(centerdataTFarmPesticideInformation.getId(),centerdataTFarmPesticideInformation.getAttachPaths(),"farm");
+        DataAttachUtil.dataAttachUpload(centerdataTFarmPesticideInformation.getId(),centerdataTFarmPesticideInformation.getAttachPaths(),"farm", centerdataTFarmPesticideInformation.getBusSource());
         return centerdataTFarmPesticideInformationMapper.insertCenterdataTFarmPesticideInformation(centerdataTFarmPesticideInformation);
     }
 
@@ -79,7 +79,7 @@ public class CenterdataTFarmPesticideInformationServiceImpl extends BaseServiceI
         centerdataTFarmPesticideInformation.setUpdateBy(SecurityUtils.getLoginUser().getUserid());
         centerdataTFarmPesticideInformation.setUpdateName(SecurityUtils.getLoginUser().getSysUser().getNickName());
         centerdataTFarmPesticideInformation.setUpdateTime(DateUtils.getNowDate());
-        DataAttachUtil.dataAttachUpload(centerdataTFarmPesticideInformation.getId(),centerdataTFarmPesticideInformation.getAttachPaths(),"farm");
+        DataAttachUtil.dataAttachUpload(centerdataTFarmPesticideInformation.getId(),centerdataTFarmPesticideInformation.getAttachPaths(),"farm", centerdataTFarmPesticideInformation.getBusSource());
         return centerdataTFarmPesticideInformationMapper.updateCenterdataTFarmPesticideInformation(centerdataTFarmPesticideInformation);
     }
 

+ 9 - 5
src/main/java/com/sooka/sponest/data/utils/DataAttachUtil.java

@@ -13,7 +13,7 @@ import java.util.stream.Collectors;
 
 public class DataAttachUtil {
 
-    public static void dataAttachUpload(String busId, String newAttachPaths, String busIndx){
+    public static void dataAttachUpload(String busId, String newAttachPaths, String busIndx, String busSource){
         ICenterdataTAttachService bean = SpringUtils.getBean(ICenterdataTAttachService.class);
         if (newAttachPaths != null){
             String[] pathArray = newAttachPaths.split(",");
@@ -47,12 +47,12 @@ public class DataAttachUtil {
 
             // 批量添加附件地址
             if (StringUtils.isNotEmpty(addList)){
-                List<CenterdataTAttach> attachList = toAttachList(busId, addList, busIndx);
+                List<CenterdataTAttach> attachList = toAttachList(busId, addList, busIndx, busSource);
                 bean.insertListCenterdataTAttach(attachList);
             }
             // 批量删除附件地址
             if (StringUtils.isNotEmpty(delList)){
-                List<CenterdataTAttach> attachList = toAttachList(busId, delList, busIndx);
+                List<CenterdataTAttach> attachList = toAttachList(busId, delList, busIndx, busSource);
                 bean.deleteListCenterdataTAttach(busId,attachList);
             }
 
@@ -60,14 +60,18 @@ public class DataAttachUtil {
         }
     }
 
-    private static List<CenterdataTAttach> toAttachList(String busId, List<String> addList, String busIndx) {
+    private static List<CenterdataTAttach> toAttachList(String busId, List<String> addList, String busIndx, String busSource) {
         List<CenterdataTAttach> list = new ArrayList<>();
         for (String addPath : addList){
             CenterdataTAttach centerdataTAttach = new CenterdataTAttach();
             centerdataTAttach.setBusId(busId);
             centerdataTAttach.setAttachPath(addPath);
             centerdataTAttach.setBusIndx(busIndx);
-            centerdataTAttach.setBusSource("PC");
+            if (StringUtils.isNotEmpty(busSource)){
+                centerdataTAttach.setBusSource(busSource);
+            }else {
+                centerdataTAttach.setBusSource("PC");
+            }
             centerdataTAttach.setFileName(null);
             centerdataTAttach.setFileType("image");
             list.add(centerdataTAttach);