Просмотр исходного кода

feat: 不动产接口对接价值平台

weijianghai 1 год назад
Родитель
Сommit
f360223e52

+ 3 - 1
src/main/java/com/nokia/financeapi/config/web/MyWebMvcConfigurer.java

@@ -14,7 +14,9 @@ public class MyWebMvcConfigurer implements WebMvcConfigurer {
     @Override
     public void addInterceptors(InterceptorRegistry registry) {
         // 添加请求日志拦截
-        registry.addInterceptor(new RequestLogHandlerInterceptor()).addPathPatterns("/api/**");
+        registry.addInterceptor(new RequestLogHandlerInterceptor()).addPathPatterns("/**").excludePathPatterns("/webjars/**", "/doc**", "/v3/**");
+        // 添加token拦截
+        registry.addInterceptor(new TokenInterceptor()).addPathPatterns("/house-car/**");
     }
 
     /**

+ 56 - 0
src/main/java/com/nokia/financeapi/config/web/TokenInterceptor.java

@@ -0,0 +1,56 @@
+package com.nokia.financeapi.config.web;
+
+import com.google.gson.Gson;
+import com.google.gson.reflect.TypeToken;
+import com.nokia.financeapi.common.R;
+import com.nokia.financeapi.utils.AESUtil;
+import lombok.NoArgsConstructor;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.util.StringUtils;
+import org.springframework.web.servlet.HandlerInterceptor;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import java.io.IOException;
+import java.util.Map;
+
+/**
+ * web登录拦截
+ */
+@Slf4j
+@NoArgsConstructor
+public class TokenInterceptor implements HandlerInterceptor {
+    @Override
+    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
+        String token = request.getHeader("Token");
+        log.info("token: {}", token);
+        if (!StringUtils.hasText(token)) {
+            return forbidden(response);
+        }
+        if ("test_hebei".equals(token)) {
+            return true;
+        }
+        try {
+            String decodeToken = AESUtil.decrypt(token);
+            log.info("decodeToken: {}", decodeToken);
+            Gson gson = new Gson();
+            Map<String, String> map = gson.fromJson(decodeToken, new TypeToken<Map<String, String>>() {
+            }.getType());
+            if (!"FINANCE".equals(map.get("APP_ID")) || !StringUtils.hasText(map.get("LOGIN_ID"))) {
+                return forbidden(response);
+            }
+        } catch (Exception e) {
+            log.warn("token解密失败: {}", token);
+            return forbidden(response);
+        }
+        return true;
+    }
+
+    private boolean forbidden(HttpServletResponse response) throws IOException {
+        response.setCharacterEncoding("UTF-8");
+        response.setContentType("application/json; charset=utf-8");
+        byte[] bytes = new Gson().toJson(R.error().code(403).message("没有权限访问")).getBytes();
+        response.getOutputStream().write(bytes);
+        return false;
+    }
+}

+ 37 - 0
src/main/java/com/nokia/financeapi/controller/house/HouseReportController.java

@@ -0,0 +1,37 @@
+package com.nokia.financeapi.controller.house;
+
+import com.nokia.financeapi.common.R;
+import com.nokia.financeapi.pojo.dto.GetHouseReportDto;
+import com.nokia.financeapi.pojo.vo.GetHouseReportVo;
+import com.nokia.financeapi.service.house.HouseReportService;
+import io.swagger.v3.oas.annotations.Operation;
+import io.swagger.v3.oas.annotations.tags.Tag;
+import org.springframework.web.bind.annotation.PostMapping;
+import org.springframework.web.bind.annotation.RequestBody;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RestController;
+
+import javax.validation.Valid;
+
+@Tag(name = "不动产报告")
+@RestController
+@RequestMapping("/house-car/house/report/api")
+public class HouseReportController {
+    private final HouseReportService houseReportService;
+
+    public HouseReportController(HouseReportService houseReportService) {
+        this.houseReportService = houseReportService;
+    }
+
+    @Operation(summary = "获取不动产报告pdf")
+    @PostMapping("/getReportPdf")
+    public R<GetHouseReportVo> getReportPdf(@Valid @RequestBody GetHouseReportDto dto) {
+        return houseReportService.getReportPdf(dto);
+    }
+
+    @Operation(summary = "获取不动产报告word")
+    @PostMapping("/getReportWord")
+    public R<GetHouseReportVo> getReportWord(@Valid @RequestBody GetHouseReportDto dto) {
+        return houseReportService.getReportWord(dto);
+    }
+}

+ 1 - 1
src/main/java/com/nokia/financeapi/controller/house/HouseResourceMapController.java

@@ -28,7 +28,7 @@ import java.util.List;
 
 @Tag(name = "不动产资源地图")
 @RestController
-@RequestMapping("/api/house/resourceMap")
+@RequestMapping("/house-car/house/resource-map/api")
 public class HouseResourceMapController {
     private final HouseResourceMapService houseResourceMapService;
 

+ 15 - 11
src/main/java/com/nokia/financeapi/dao/house/HouseResourceMapMapper.java

@@ -51,9 +51,9 @@ where
     </if>
 )
 select
-    round(area_self_use, 2) as area_self_use,
-    round(area_rent, 2) as area_rent,
-    round(area_unused, 2) as area_unused,
+    round(area_self_use / 10000, 2) as area_self_use,
+    round(area_rent / 10000, 2) as area_rent,
+    round(area_unused / 10000, 2) as area_unused,
     round(area_synthesis / area_total * 100, 2) as percent_synthesis,
     round(area_equipment / area_total * 100, 2) as percent_equipment,
     round(area_marketing / area_total * 100, 2) as percent_marketing,
@@ -342,19 +342,23 @@ select
     end as odd_percent
 from
     t1
+),
+t3 as (
+select
+    *
+from t2 left join house.second_unit_sort on t2.city = house.second_unit_sort.second_unit
+order by house.second_unit_sort.sort desc
 )
 select
     city as area_name,
-    round(odd_sum,
+    round(odd_sum / 10000,
     2) as odd_sum,
-    round(total_sum,
+    round(total_sum / 10000,
     2) as total_sum,
     round(odd_percent,
     2) as odd_percent
 from
-    t2
-order by
-    city
+    t3
 """)
     List<GetBuildingRepairStatVo> getCityRepairStat();
 
@@ -397,16 +401,16 @@ from
 )
 select
     district as area_name,
-    round(odd_sum,
+    round(odd_sum / 10000,
     2) as odd_sum,
-    round(total_sum,
+    round(total_sum / 10000,
     2) as total_sum,
     round(odd_percent,
     2) as odd_percent
 from
     t2
 order by
-    district
+    total_sum
 """)
     List<GetBuildingRepairStatVo> getDistrictRepairStat(@Param("dto") GetBuildingRepairStatDto dto);
 

+ 10 - 0
src/main/java/com/nokia/financeapi/pojo/dto/GetHouseReportDto.java

@@ -0,0 +1,10 @@
+package com.nokia.financeapi.pojo.dto;
+
+import io.swagger.v3.oas.annotations.media.Schema;
+import lombok.Data;
+
+@Data
+public class GetHouseReportDto {
+    @Schema(description = "账期", example = "202307")
+    private Integer endDate;
+}

+ 3 - 3
src/main/java/com/nokia/financeapi/pojo/vo/GetBuildingAreaStatVo.java

@@ -7,11 +7,11 @@ import java.math.BigDecimal;
 
 @Data
 public class GetBuildingAreaStatVo {
-    @Schema(description = "自用面积(平方米)")
+    @Schema(description = "自用面积(平方米)")
     private BigDecimal areaSelfUse;
-    @Schema(description = "出租面积(平方米)")
+    @Schema(description = "出租面积(平方米)")
     private BigDecimal areaRent;
-    @Schema(description = "未利用面积(平方米)")
+    @Schema(description = "未利用面积(平方米)")
     private BigDecimal areaUnused;
     @Schema(description = "综合用房占比")
     private BigDecimal percentSynthesis;

+ 2 - 2
src/main/java/com/nokia/financeapi/pojo/vo/GetBuildingRepairStatVo.java

@@ -11,9 +11,9 @@ import java.math.BigDecimal;
 public class GetBuildingRepairStatVo {
     @Schema(description = "地区名称", example = "石家庄")
     private String areaName;
-    @Schema(description = "零星维修费用(元)", example = "1587943.12")
+    @Schema(description = "零星维修费用(元)", example = "158.79")
     private BigDecimal oddSum;
-    @Schema(description = "总维修费用(元)", example = "3153148.81")
+    @Schema(description = "总维修费用(万元)", example = "315.31")
     private BigDecimal totalSum;
     @Schema(description = "零星维修占比", example = "50.36")
     private BigDecimal oddPercent;

+ 10 - 0
src/main/java/com/nokia/financeapi/pojo/vo/GetHouseReportVo.java

@@ -0,0 +1,10 @@
+package com.nokia.financeapi.pojo.vo;
+
+import io.swagger.v3.oas.annotations.media.Schema;
+import lombok.Data;
+
+@Data
+public class GetHouseReportVo {
+    @Schema(description = "报告链接")
+    private String url;
+}

+ 32 - 0
src/main/java/com/nokia/financeapi/service/house/HouseReportService.java

@@ -0,0 +1,32 @@
+package com.nokia.financeapi.service.house;
+
+import com.nokia.financeapi.common.R;
+import com.nokia.financeapi.pojo.dto.GetHouseReportDto;
+import com.nokia.financeapi.pojo.vo.GetHouseReportVo;
+import com.nokia.financeapi.service.common.file.FileService;
+import org.springframework.stereotype.Service;
+
+@Service
+public class HouseReportService {
+    private final FileService fileService;
+
+    public HouseReportService(FileService fileService) {
+        this.fileService = fileService;
+    }
+
+    public R<GetHouseReportVo> getReportWord(GetHouseReportDto dto) {
+        GetHouseReportVo vo = new GetHouseReportVo();
+        String object = "/oss/reports/house/202307.doc";
+        String url = fileService.getDownloadUrl(object);
+        vo.setUrl(url);
+        return R.ok(vo);
+    }
+
+    public R<GetHouseReportVo> getReportPdf(GetHouseReportDto dto) {
+        GetHouseReportVo vo = new GetHouseReportVo();
+        String object = "/oss/reports/house/202307.pdf";
+        String url = fileService.getDownloadUrl(object);
+        vo.setUrl(url);
+        return R.ok(vo);
+    }
+}

+ 12 - 6
src/main/java/com/nokia/financeapi/service/house/HouseResourceMapService.java

@@ -34,6 +34,7 @@ import java.util.Map;
 
 @Service
 public class HouseResourceMapService {
+    static final String DEFAULT_BUILDING_IMG = "/oss/public/default-building-img.png";
     private final HouseResourceMapMapper houseResourceMapMapper;
     private final AreaDao areaDao;
     private final FileService fileService;
@@ -119,14 +120,19 @@ public class HouseResourceMapService {
         // 坐标为空根据区县获取建筑
         if (dto.getLeftLng() == null || dto.getRightLng() == null || dto.getLeftLat() == null || dto.getRightLat() == null) {
             List<GetBuildingMapVo> vo = houseResourceMapMapper.getBuildingByDistrict(dto);
+            vo.forEach(t -> {
+                String buildingImg = fileService.getBucket()
+                        + (StringUtils.hasText(t.getBuildingImg()) ? t.getBuildingImg() : DEFAULT_BUILDING_IMG);
+                t.setBuildingImg(buildingImg);
+            });
             return R.ok(vo);
         }
         // 查询坐标范围内的建筑
         List<GetBuildingMapVo> vo = houseResourceMapMapper.getBuildingByCoordinate(dto);
         vo.forEach(t -> {
-            if (StringUtils.hasText(t.getBuildingImg())) {
-                t.setBuildingImg(fileService.getBucket() + t.getBuildingImg());
-            }
+            String buildingImg = fileService.getBucket()
+                    + (StringUtils.hasText(t.getBuildingImg()) ? t.getBuildingImg() : DEFAULT_BUILDING_IMG);
+            t.setBuildingImg(buildingImg);
         });
         return R.ok(vo);
     }
@@ -243,9 +249,9 @@ public class HouseResourceMapService {
         dto.setStartDate(startDate);
         List<GetBuildingOptionsVo> vo = houseResourceMapMapper.getBuildingOptions(dto);
         vo.forEach(t -> {
-            if (StringUtils.hasText(t.getBuildingImg())) {
-                t.setBuildingImg(fileService.getBucket() + t.getBuildingImg());
-            }
+            String buildingImg = fileService.getBucket()
+                    + (StringUtils.hasText(t.getBuildingImg()) ? t.getBuildingImg() : DEFAULT_BUILDING_IMG);
+            t.setBuildingImg(buildingImg);
         });
         return R.ok(vo);
     }

+ 93 - 0
src/main/java/com/nokia/financeapi/utils/AESUtil.java

@@ -0,0 +1,93 @@
+package com.nokia.financeapi.utils;
+
+import cn.hutool.core.codec.Base64;
+import com.google.gson.Gson;
+
+import javax.crypto.Cipher;
+import javax.crypto.spec.SecretKeySpec;
+import java.text.SimpleDateFormat;
+import java.util.Date;
+import java.util.HashMap;
+
+/**
+ * aes加密解密
+ */
+public class AESUtil {
+    static final String KEY = "2na$$PdV9AW8b#CS";
+    // 固定替换
+    private static final String ADD = "/add/";
+
+    // 加密
+    public static String encrypt(String str, String key) throws Exception {
+        // 加密
+        if (str == null || key == null) {
+            // 加密
+            return null;
+        }
+        // 加密
+        Cipher cipher = Cipher.getInstance("AES/ECB/PKCS5Padding");
+        // 加密
+        cipher.init(Cipher.ENCRYPT_MODE, new SecretKeySpec(key.getBytes("utf-8"), "AES"));
+        // 加密
+        byte[] bytes = cipher.doFinal(str.getBytes("utf-8"));
+        // 加密
+        String result = Base64.encode(bytes);
+//        String result = new BASE64Encoder().encode(bytes);
+        // 加密
+        result = result.replaceAll("\r\n", "");
+        // 加密
+        result = result.replaceAll("\\+", ADD);
+        // 加密
+        return result;
+    }
+
+    // 解密
+    public static String decrypt(String str, String key) throws Exception {
+        // 解密
+        if (str == null || key == null) {
+            // 解密
+            return null;
+        }
+        // 解密
+        str = str.replaceAll("\\\\n", "");
+        // 解密
+        str = str.replaceAll(ADD, "+");
+        // 解密
+        Cipher cipher = Cipher.getInstance("AES/ECB/PKCS5Padding");
+        // 解密
+        cipher.init(Cipher.DECRYPT_MODE, new SecretKeySpec(key.getBytes("utf-8"), "AES"));
+        // 解密
+        byte[] bytes = Base64.decode(str);
+//        byte[] bytes = new BASE64Decoder().decodeBuffer(str);
+        // 解密
+        bytes = cipher.doFinal(bytes);
+        // 解密
+        return new String(bytes);
+    }
+
+    public static String decrypt(String str) throws Exception {
+        return decrypt(str, KEY);
+    }
+
+    public static void main(String[] args) throws Exception {
+// 参数
+        HashMap<String, String> map = new HashMap<>();
+        // 财务系统id, 固定值
+        map.put("APP_ID", "FINANCE");
+        // 时间戳
+        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
+        map.put("TIME_STAMP", sdf.format(new Date()));
+        // 当前登录账号
+        map.put("LOGIN_ID", "loginId");
+        //请求的地址
+        map.put("REQUEST_URL","https://ip:port/aaa");
+
+        // 加密串
+        String encrypt = AESUtil.encrypt(new Gson().toJson(map), "2na$$PdV9AW8b#CS");
+        // 返回
+        System.out.println(encrypt);
+        //解密
+        System.out.println(AESUtil.decrypt(encrypt,"2na$$PdV9AW8b#CS"));
+        System.out.println(AESUtil.decrypt("zoQtYlmhk/add/mBUBZD5mFJB1IXEwaLRS97Uf9z9Hlqdh8eF/add/c2gDUmD3pwGPfA8FQKBNTCB8LPlCPF/vHcU/2tL7Ps/add/6rn6w5rDS98R4GJueGgU01n12YZVS/FNx6pSI/add/BuEy1XyrSg8QBfx7igSozPxmdZ6a235/add/fqZPPSjoQReI","2na$$PdV9AW8b#CS"));
+    }
+}

+ 6 - 6
src/main/resources/application-prod.properties

@@ -4,13 +4,13 @@ spring.datasource.driver-class-name=org.postgresql.Driver
 spring.datasource.url=jdbc:postgresql://172.16.107.5:5432/financialdb
 spring.datasource.username=finance
 spring.datasource.password=Finance@unicom23
-# minio配置
-minio.endpoint=http://133.96.95.30:39000/
-minio.bucket=oss-finance-prod
-minio.accessKey=oss-finance-prod
-minio.secretKey=5Hu18JUQ2vk2SEKfIV6AGt6xr9zq3dYu0NSkkxKF
+# minio配置
+minio.endpoint=http://172.16.107.4:39000/
+minio.bucket=house-car
+minio.accessKey=house-car
+minio.secretKey=pfhJVM9CUitr2rv1iGA0WQbCr4XdGJ2rmB7mgUaG
 minio.expiry=15
-# 关闭接口文档
+# 关闭接口文档
 springdoc.api-docs.enabled=false
 springdoc.swagger-ui.enabled=false
 knife4j.production=true

+ 3 - 3
src/main/resources/application-test.properties

@@ -6,7 +6,7 @@ spring.datasource.username=postgres
 spring.datasource.password=NFQCgBA6YhNvgAqG6THw
 # minio配置
 minio.endpoint=http://192.168.10.7:19000/
-minio.bucket=oss-finance-test
-minio.accessKey=oss-finance-test
-minio.secretKey=JQUqNWuqHq74Q4YV1t19Z6s9or4QIw5S
+minio.bucket=house-car
+minio.accessKey=house-car
+minio.secretKey=EGqIq7zKZwfasMQ5eLIoLId631vmLaal
 minio.expiry=15