Selaa lähdekoodia

修改生成id的接口

houweiyu 4 vuotta sitten
vanhempi
commit
cbdecb9d27

+ 1 - 1
README.md

@@ -16,7 +16,7 @@
  tomcat: /root/user/java/tomcat_kanfang_8084
  
  doc api
- url: http://39.108.220.65:8084/fdkanfang/doc.html
+ url: http://120.25.146.52/:8084/fdkanfang/doc.html
  
  web-ui
  http://39.108.220.65:8084/fdkanfang/back/index.html#/login

+ 10 - 0
fdkanfang-domain/src/main/java/com/fdkanfang/domain/dto/HouseDto.java

@@ -5,6 +5,7 @@ import lombok.Data;
 import org.springframework.web.multipart.MultipartFile;
 
 import javax.validation.constraints.*;
+import java.util.List;
 
 /**
  * Created by owen on 2020/3/2 0002 14:09
@@ -44,12 +45,21 @@ public class HouseDto {
     @ApiModelProperty(value = "多文件", required = true )
     private MultipartFile[] files;
 
+    @ApiModelProperty(value = "多文件", required = true )
+    private List<String> fileNames;
+
     @ApiModelProperty(value = "制作要求", required = false )
     private String requirement;
 
     @ApiModelProperty(value = "图片最大像素", required = false )
     private String imageMaxRate;
 
+    @ApiModelProperty(value = "场景码", required = true )
+    private String sceneCode;
+
+    @ApiModelProperty(value = "房源编号", required = false )
+    private Integer num;
+
     // 以下好像没有用到
 
     // 操作者

+ 50 - 8
fdkanfang-web/src/main/java/com/fdkanfang/web/backend/HouseController.java

@@ -192,11 +192,9 @@ public class HouseController extends BaseController {
             return new R(MsgCode.e_COMMON_3001, "楼层/户型/面积/朝向不能为空");
         }
 
-        // 处理上传图片
-        MultipartFile[] files = param.getFiles();
-        if (files == null || files.length <= 0) {
-            log.info("文件为空");
-            return new R(MsgCode.e_COMMON_3100, MsgCode.msg_COMMON_3100);
+        List<String> fileNames = param.getFileNames();
+        if(CollectionUtils.isEmpty(fileNames)){
+            return new R(MsgCode.e_COMMON_3001, "照片名称列表不能为空");
         }
         boolean isNewAdd = false;
         HouseEntity house = null;
@@ -215,9 +213,7 @@ public class HouseController extends BaseController {
             HashMap<String, String> ossVerticalImageLowMap = new HashMap<>();
             String imageHighPath = null;
             String imageLowPath = null;
-            ImageResolutionRate maxResolutionRate = null;
-            for (MultipartFile file : files) {
-                String filename = file.getOriginalFilename();
+            for (String filename : fileNames) {
                 filename = checkAndChangeFileName(filename);
                 imageHighPath = OUTPATH + sceneCode + "/output_img/" + filename;
                 imageLowPath = OUTPATH + sceneCode + "/output_img_low/" + filename;
@@ -259,6 +255,14 @@ public class HouseController extends BaseController {
         return new R(MsgCode.SUCCESS_CODE, house);
     }
 
+//    @RequiresRoles(value = {"admin", "edit", "upload"}, logical = Logical.OR)
+    @ApiOperation("生成houseId和场景码")
+    @PostMapping(value = "addPosition")
+    @Transactional(rollbackFor = Exception.class)
+    public R addPosition(){
+       return new R(MsgCode.SUCCESS_CODE, generateHouseIdAndSceneNum());
+    }
+
     @ApiOperation("上传照片")
     @PostMapping(value = "uploadImages")
     @Transactional(rollbackFor = Exception.class)
@@ -418,6 +422,33 @@ public class HouseController extends BaseController {
         return filename;
     }
 
+    private Map<String , Object> generateHouseIdAndSceneNum(){
+        Map<String ,Object> result = new HashMap<>();
+        Integer byMaxNum = houseService2.findByMaxNum();
+        // 用于第一条数据
+        byMaxNum = (byMaxNum == null)? 10000:byMaxNum;
+        byMaxNum += 1;
+        String sceneCode = getSceneCode();
+        HouseEntity house = new HouseEntity();
+        UserEntity user  = userUtils.getUserByToken(getToken());
+        house.setUserId(user.getId());
+        house.setNum(byMaxNum + 1);
+        house.setSceneCode(sceneCode);
+        house.setWebSite(domain+"?m="+sceneCode);
+        house.setFilePath(OUTPATH + sceneCode);
+        int insert = houseService2.save(house);
+        if(insert != 1){
+            log.error("新增房源失败");
+            return result;
+        }
+        HouseEntity dbHouse = houseService2.findBySceneCode(sceneCode);
+        if(null != dbHouse){
+            result.put("id" , dbHouse.getId());
+            result.put("sceneCode" , sceneCode);
+        }
+        return result;
+    }
+
     @Transactional(rollbackFor = Exception.class)
     public HouseEntity updateOrInsertHouse(HouseDto param){
         if(null == param){
@@ -446,6 +477,17 @@ public class HouseController extends BaseController {
                  throw new CommonBaseException(ResultCodeEnum.D101 , "房源不存在");
             }
             BeanUtils.copyProperties(param, house);
+            if(StringUtils.isBlank(house.getSceneCode())){
+                house.setSceneCode(param.getSceneCode());
+            }
+
+            if(StringUtils.isBlank(house.getWebSite())){
+                house.setWebSite(domain+"?m=" + param.getSceneCode());
+            }
+
+            if(StringUtils.isBlank(house.getFilePath())){
+                house.setFilePath(OUTPATH + param.getSceneCode());
+            }
             house.setUpdateTime(new Date());
             houseService2.update(house);
         }