Browse Source

资产管理系统

lmstack 3 years ago
parent
commit
3581ab92c0

+ 6 - 0
pom.xml

@@ -24,6 +24,7 @@
         <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
         <java.version>1.8</java.version>
         <spring-cloud.version>Greenwich.SR2</spring-cloud.version>
+        <okhttp.version>4.9.0</okhttp.version>
     </properties>
 
     <dependencies>
@@ -32,6 +33,11 @@
             <artifactId>spring-boot-starter-web</artifactId>
         </dependency>
 
+        <dependency>
+            <groupId>com.squareup.okhttp3</groupId>
+            <artifactId>okhttp</artifactId>
+        </dependency>
+
         <dependency>
             <groupId>org.springframework.boot</groupId>
             <artifactId>spring-boot-starter-validation</artifactId>

+ 79 - 0
src/main/java/cn/fastfun/config/OkHttpConfiguration.java

@@ -0,0 +1,79 @@
+package cn.fastfun.config;
+
+import okhttp3.ConnectionPool;
+import okhttp3.OkHttpClient;
+import org.springframework.beans.factory.annotation.Value;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+import javax.net.ssl.*;
+import java.security.*;
+import java.security.cert.CertificateException;
+import java.security.cert.X509Certificate;
+import java.util.concurrent.TimeUnit;
+/**
+ * @author user
+ * @date 2019-04-09
+ */
+@Configuration
+public class OkHttpConfiguration {
+    @Value("${ok.http.connect-timeout}")
+    private Integer connectTimeout;
+    @Value("${ok.http.read-timeout}")
+    private Integer readTimeout;
+    @Value("${ok.http.write-timeout}")
+    private Integer writeTimeout;
+    @Value("${ok.http.max-idle-connections}")
+    private Integer maxIdleConnections;
+    @Value("${ok.http.keep-alive-duration}")
+    private Long keepAliveDuration;
+    @Bean
+    public OkHttpClient okHttpClient() {
+        return new OkHttpClient.Builder()
+                .sslSocketFactory(sslSocketFactory(), x509TrustManager())
+                // 是否开启缓存
+                .retryOnConnectionFailure(false)
+                .connectionPool(pool())
+                .connectTimeout(connectTimeout, TimeUnit.SECONDS)
+                .readTimeout(readTimeout, TimeUnit.SECONDS)
+                .writeTimeout(writeTimeout,TimeUnit.SECONDS)
+                .hostnameVerifier((hostname, session) -> true)
+                // 设置代理
+//      .proxy(new Proxy(Proxy.Type.HTTP, new InetSocketAddress("127.0.0.1", 8888)))
+                // 拦截器
+//    .addInterceptor()
+                .build();
+    }
+    @Bean
+    public X509TrustManager x509TrustManager() {
+        return new X509TrustManager() {
+            @Override
+            public void checkClientTrusted(X509Certificate[] chain, String authType)
+                    throws CertificateException {
+            }
+            @Override
+            public void checkServerTrusted(X509Certificate[] chain, String authType)
+                    throws CertificateException {
+            }
+            @Override
+            public X509Certificate[] getAcceptedIssuers() {
+                return new X509Certificate[0];
+            }
+        };
+    }
+    @Bean
+    public SSLSocketFactory sslSocketFactory() {
+        try {
+            // 信任任何链接
+            SSLContext sslContext = SSLContext.getInstance("TLS");
+            sslContext.init(null, new TrustManager[]{x509TrustManager()}, new SecureRandom());
+            return sslContext.getSocketFactory();
+        } catch (NoSuchAlgorithmException | KeyManagementException e) {
+            e.printStackTrace();
+        }
+        return null;
+    }
+    @Bean
+    public ConnectionPool pool() {
+        return new ConnectionPool(maxIdleConnections, keepAliveDuration, TimeUnit.SECONDS);
+    }
+}

+ 57 - 0
src/main/java/cn/fastfun/controller/api/ApiAssetProfitController.java

@@ -0,0 +1,57 @@
+package cn.fastfun.controller.api;
+
+import cn.fastfun.controller.dto.asset.BaseInfoDTO;
+import cn.fastfun.controller.dto.asset.RentInfoDTO;
+import cn.fastfun.controller.param.*;
+import cn.fastfun.service.impl.AppAssetProfitServiceImpl;
+import com.bridge.dto.*;
+import io.swagger.annotations.Api;
+import io.swagger.annotations.ApiOperation;
+import io.swagger.annotations.ApiParam;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.*;
+
+import java.util.List;
+
+/**
+ * @author Bridge AutoGen
+ */
+@Slf4j
+@Api(tags = {"2.0 资产收益分析"})
+@RestController
+@RequestMapping("/api/v1/appassetprofit")
+public class ApiAssetProfitController {
+
+    @Autowired
+    AppAssetProfitServiceImpl appAssetService;
+
+    @ApiOperation(value = "基础信息")
+    @RequestMapping(value = "getBaseInfo", method = RequestMethod.POST)
+    public ApiDTO getBaseInfo(@RequestBody @ApiParam(name = "设备信息对象", value = "传入json格式", required = true) AssetProfitParam param) throws Exception {
+
+
+
+        BaseInfoDTO baseInfo = appAssetService.getBaseInfo(param);
+        return ApiDTO.ok("成功", baseInfo);
+    }
+
+    @ApiOperation(value = "其他信息")
+    @RequestMapping(value = "getProfitInfo", method = RequestMethod.POST)
+    public ApiDTO getAssetProfitInfo(@RequestBody @ApiParam(name = "设备信息对象", value = "传入json格式", required = true) AssetProfitParam param) {
+
+        // 租赁信息
+        Object response = null;
+        if (param.getTableOrder() != null && param.getTableOrder().equals(1)){
+            RentInfoDTO rentInfoDTO = appAssetService.getRentInfo(param.getSn(), param.getTimeStart().toString(), param.getTimeEnd().toString(), param.getLength(), param.getIndex());
+            response = (RentInfoDTO) rentInfoDTO;
+        }
+
+        return ApiDTO.ok("成功", response);
+    }
+
+
+
+
+
+}

+ 74 - 0
src/main/java/cn/fastfun/controller/api/AssetApiController.java

@@ -0,0 +1,74 @@
+package cn.fastfun.controller.api;
+
+
+import lombok.extern.slf4j.Slf4j;
+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.annotation.Resource;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * @author user
+ */
+@Slf4j
+@RequestMapping("/admin/v1/")
+@RestController
+public class AssetApiController {
+
+
+//    @Resource
+//    BatteryAssetService batteryAssetService;
+//
+//
+//    /**
+//     * 资产管理-查询电池基本信息
+//     * @param param sn号
+//     * @return BasicAssetDto
+//     */
+//    @PostMapping("/assetBatteryBasicInfo")
+//    public ApiDTO assetBatteryBasicInfo(@RequestBody OrgSnParam param) {
+//        if (null != param) {
+//            BasicAssetDto basicAssetDto = batteryAssetService.assetBatteryBasicInfo(param);
+//            return ApiDTO.ok(basicAssetDto);
+//        }else {
+//            return ApiDTO.error("缺失sn号");
+//        }
+//    }
+//
+//    /**
+//     * 资产管理-电池时间线
+//     * @param param sn号
+//     * @return BasicAssetDto
+//     */
+//    @PostMapping("/getDateLine")
+//    public ApiDTO getDateLine(@RequestBody OrgSnParam param) {
+//        if (null != param) {
+//            List<DeviceLineDto> result = batteryAssetService.getDateLine(param.getSn());
+//            return ApiDTO.ok(result);
+//        }else {
+//            return ApiDTO.error("缺失sn号");
+//        }
+//    }
+//
+//
+//
+//    /**
+//     * 资产管理-营销信息
+//     *
+//     * @param param
+//     * @return BasicAssetDto
+//     */
+//    @PostMapping("/marketingInformation")
+//    public ApiDTO getMarketingInformation(@RequestBody OrgSnParam param) {
+//        if (null != param) {
+//            Map<String,Object> result = batteryAssetService.getMarketingInformation(param);
+//            return ApiDTO.ok(result);
+//        }else {
+//            return ApiDTO.error("缺失sn号");
+//        }
+//    }
+}

+ 0 - 1
src/main/java/cn/fastfun/controller/api/ProductController.java

@@ -57,7 +57,6 @@ public class ProductController {
 //            return ApiDTO.ok("保存成功,未保存的规则行id为null",productSpecificationResults);
 //        }
 
-
         // 校验输入的SN类型对应的编号
         String checkSnTypeCodeResult = VerifyUtil.checkSnTypeCode(product);
         List<Product> checkDuplicatedResult = productService.findAll(

+ 7 - 7
src/main/java/cn/fastfun/controller/api/SnController.java

@@ -32,25 +32,25 @@ public class SnController {
 
         Product productTypeCheckResult =  productService.getOne(
                 Arrays.asList(QueryParamExp.eq("snTypeCode",snSplitResult.get("产品类型代码")),
-                        QueryParamExp.eq("snType","产品类型")));
+                        QueryParamExp.eq("snTypeEn",1)));
         Product packManufacturerCheckResult =  productService.getOne(
                 Arrays.asList(QueryParamExp.eq("snTypeCode",snSplitResult.get("pack制造商代码")),
-                        QueryParamExp.eq("snType","PACK制造商")));
+                        QueryParamExp.eq("snTypeEn",2)));
         Product cellManufacturerCheckResult =  productService.getOne(
                 Arrays.asList(QueryParamExp.eq("snTypeCode",snSplitResult.get("电芯厂家代码")),
-                        QueryParamExp.eq("snType","电芯厂家")));
+                        QueryParamExp.eq("snTypeEn",3)));
         Product ChemicalSystemCheckResult =  productService.getOne(
                 Arrays.asList(QueryParamExp.eq("snTypeCode",snSplitResult.get("化学体系代码")),
-                        QueryParamExp.eq("snType","化学体系")));
+                        QueryParamExp.eq("snTypeEn",4)));
         Product batteryPlatformCheckResult =  productService.getOne(
                 Arrays.asList(QueryParamExp.eq("snTypeCode",snSplitResult.get("电池平台代码")),
-                        QueryParamExp.eq("snType","电池平台")));
+                        QueryParamExp.eq("snTypeEn",5)));
         Product CapacityCheckResult =  productService.getOne(
                 Arrays.asList(QueryParamExp.eq("snTypeCode",snSplitResult.get("容量代码")),
-                        QueryParamExp.eq("snType","容量")));
+                        QueryParamExp.eq("snTypeEn",6)));
         Product productExpansionCheckResult =  productService.getOne(
                 Arrays.asList(QueryParamExp.eq("snTypeCode",snSplitResult.get("产品扩展代码")),
-                        QueryParamExp.eq("snType","产品扩展")));
+                        QueryParamExp.eq("snTypeEn",7)));
         String productionDate = snSplitResult.get("生产日期代码");
         String productionDateCheckResult = ResolveUtil.resolveDate(productionDate);
 

+ 74 - 0
src/main/java/cn/fastfun/controller/dto/asset/BaseInfoDTO.java

@@ -0,0 +1,74 @@
+package cn.fastfun.controller.dto.asset;
+
+import lombok.Getter;
+import lombok.NoArgsConstructor;
+import lombok.Setter;
+
+import java.math.BigDecimal;
+
+@Setter
+@Getter
+@NoArgsConstructor
+public class BaseInfoDTO {
+
+    // 设备编号
+    private String sn;
+
+    // 产品类别
+    private String category;
+
+    // 产品类型
+    private String type;
+
+    // 厂家
+    private String factory;
+
+    // 电芯
+    private String cellFactory;
+
+    // 电芯类型
+    private String cellType;
+
+    // 电压平台
+    private String voltPlatform;
+
+    // 容量
+    private Float capacity;
+
+    // 生产时间
+    private String productTime;
+
+    // 发货时间
+    private String deliverTime;
+
+    // 入库时间
+    private String storageTime;
+
+    // 投营时间
+    private String operationTime;
+
+    // 首次租赁时间
+    private String firstRentTime;
+
+    // 回调时间
+    private String recallTime;
+
+    // 采购价格
+    private BigDecimal price;
+
+    // 业务状态
+    private String status;
+
+    // 投营地区
+    private String region;
+
+    // 已采购天数
+    private Integer purchaseDay;
+
+    // 已投营天数
+    private Integer operationDay;
+
+
+
+
+}

+ 113 - 0
src/main/java/cn/fastfun/controller/dto/asset/BasicAssetDto.java

@@ -0,0 +1,113 @@
+package cn.fastfun.controller.dto.asset;
+
+import lombok.Data;
+
+import java.io.Serializable;
+import java.math.BigDecimal;
+
+/**
+ * 资产基础信息
+ * @author user
+ */
+@Data
+public class BasicAssetDto implements Serializable {
+
+    private static final long serialVersionUID = -1821068317406106793L;
+
+    /**
+     * id
+     */
+    private String id;
+    /**
+     * imei
+     */
+    private String imei;
+    /**
+     * 产品类别编码
+     */
+    private String deviceType;
+    /**
+     * 产品类别:电池
+     */
+    private String deviceTypeText;
+    /**
+     * 厂家:格林美
+     */
+    private String factory;
+    /**
+     * 电芯:宁德
+     */
+    private String electricCore;
+    /**
+     * 设备编号:PK504B10000003457
+     */
+    private String sn;
+    /**
+     * 产品类型编码
+     */
+    private String productType;
+    /**
+     * 产品类型:两轮车
+     */
+    private String productTypeText;
+    /**
+     * 电芯类型编码 化学成分
+     */
+    private String electricCoreType;
+    /**
+     * 电芯类型:三元锂
+     */
+    private String electricCoreTypeText;
+    /**
+     * 扩展
+     */
+    private String extend;
+    /**
+     * 扩展
+     */
+    private String extendText;
+    /**
+     * 电压平台:72V
+     */
+    private Integer voltage;
+    /**
+     * 电压平台:72V
+     */
+    private String voltageText;
+    /**
+     * 容量:50Ah
+     */
+    private Integer capacity;
+    /**
+     * 容量:50Ah
+     */
+    private String capacityText;
+    /**
+     * 生产时间:2021-8-6
+     */
+    private String createTime;
+    /**
+     * 投营时间:2021-8-15
+     */
+    private String operationTime;
+    /**
+     * 采购价格:3250元
+     */
+    private BigDecimal purchasePrice;
+    /**
+     * 业务p状态编码
+     */
+    private Integer status;
+    /**
+     * 业务p状态名称:库存/在租/故障/返修
+     */
+    private String statusText;
+    /**
+     * 投营地区编码
+     */
+    private String location;
+    /**
+     * 投营地区名称:北京
+     */
+    private String locationText;
+}

+ 63 - 0
src/main/java/cn/fastfun/controller/dto/asset/RentInfoDTO.java

@@ -0,0 +1,63 @@
+package cn.fastfun.controller.dto.asset;
+
+import com.fasterxml.jackson.annotation.JsonIgnore;
+import com.fasterxml.jackson.annotation.JsonIgnoreType;
+import lombok.Getter;
+import lombok.NoArgsConstructor;
+import lombok.Setter;
+
+import java.math.BigDecimal;
+import java.util.ArrayList;
+import java.util.List;
+
+@Setter
+@Getter
+@NoArgsConstructor
+public class RentInfoDTO {
+    private static final long serialVersionUID = -1821068317406106793L;
+
+    @JsonIgnoreType
+    @Setter
+    @Getter
+    public static class AllInfo{
+        // 时间
+        private String time;
+
+        // 类型
+        private String type;
+
+        // 金额
+        private BigDecimal amount;
+
+        // 关联订单
+        private String order;
+
+        // 说明
+        private String description;
+    }
+
+    private List<AllInfo> allInfoList = new ArrayList<>();
+
+    // 当前租期
+    private String time;
+
+    // 当前租金
+    private BigDecimal rental;
+
+    // 当前押金
+    private BigDecimal cash;
+
+    // 租金收入
+    private BigDecimal income;
+
+    // 押金收取
+    private BigDecimal cashIn;
+
+    // 丢失保障金
+    private BigDecimal securityCash;
+
+    // 净租金
+    private BigDecimal netRental;
+
+
+}

+ 39 - 0
src/main/java/cn/fastfun/controller/param/AssetProfitParam.java

@@ -0,0 +1,39 @@
+package cn.fastfun.controller.param;
+
+import com.bridge.dto.QueryParam;
+
+import com.bridge.dto.QueryParamExp;
+import com.fasterxml.jackson.annotation.JsonFormat;
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Getter;
+import lombok.Setter;
+import org.springframework.format.annotation.DateTimeFormat;
+import org.springframework.util.StringUtils;
+
+import java.util.Date;
+
+@Setter
+@Getter
+public class AssetProfitParam extends QueryParam {
+
+    @ApiModelProperty(value = "sn", name = "sn", required = true)
+    private String sn;
+
+
+    @ApiModelProperty(value = "起始时间", name = "timeStart", required = true)
+    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
+    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
+    private Date timeStart;
+
+    @ApiModelProperty(value = "结束时间", name = "timeEnd", required = true)
+    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
+    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
+    private Date timeEnd;
+
+    @ApiModelProperty(value = "table页编号(1:租赁信息", name = "table_order", required = true)
+    private Integer tableOrder;
+
+    @ApiModelProperty(value = "类型(1:押金收, 2:押金支, 3:租金收, 4:租金支, 5:丢失保障金, 多个用逗号隔开", name = "type", required = true)
+    private String type;
+
+}

+ 4 - 0
src/main/java/cn/fastfun/service/entity/Product.java

@@ -19,6 +19,10 @@ public class Product extends DateEntity {
     @Column(name="sn_type")
     private String snType;
 
+    @ApiModelProperty(value = "sn切片对应的类型编号", name = "sn_type", required = true)
+    @Column(name="sn_type_en")
+    private Integer snTypeEn;
+
     @ApiModelProperty(value = "sn切片对应类型的实际数据描述", name = "sn_type_desc", required = true)
     @Column(name="sn_type_desc")
     private String snTypeDesc;

+ 60 - 0
src/main/java/cn/fastfun/service/enums/EnumDeviceAction.java

@@ -0,0 +1,60 @@
+package cn.fastfun.service.enums;
+
+/**
+ * @author user
+ * @Project:boss
+ * @ClassName:设备动作
+ * @Describe:TODO
+ */
+public enum EnumDeviceAction {
+    /**
+     * 设备动作
+     */
+    PRODUCTION(0, "生产"),
+    STORAGE_TRANSPORTATION(1, "入库运输"),
+    STORAGE(2, "入库"),
+    TO_STORE(3, "发货至网点"),
+    TO_MERCHANT(4, "发货至商户"),
+    STORE_RECEIVED(5, "网点到货"),
+    MERCHANT_RECEIVED(6, "商户到货"),
+    STORE_RENT(7, "网点出租"),
+    STORE_RETURN(8, "网点归还"),
+    MERCHANT_RENT(9, "商户出租"),
+    MERCHANT_RETURN(10, "商户归还"),
+    STORE_REPLACE(11, "网点设备更换"),
+    RECALL(12, "回调"),
+    REPAIR(13, "送修"),
+    REPAIR_START(14, "维修开始"),
+    REPAIR_DONE(15, "维修完成"),
+    TO_STORE_AFTER_REPAIR(16, "维修完成送回网点"),
+    TO_PLATFORM_AFTER_REPAIR(17, "维修完成送回平台"),
+    SCRAP(18, "报废"),
+    LOSE(19, "丢失"),
+
+
+    ;
+    Integer value;
+    String text;
+
+    EnumDeviceAction(Integer value, String text) {
+        this.value = value;
+        this.text = text;
+    }
+
+    public Integer getValue() {
+        return value;
+    }
+
+    public void setValue(Integer value) {
+        this.value = value;
+    }
+
+    public String getText() {
+        return text;
+    }
+
+    public void setText(String text) {
+        this.text = text;
+    }
+
+}

+ 52 - 0
src/main/java/cn/fastfun/service/enums/EnumDeviceStatus.java

@@ -0,0 +1,52 @@
+package cn.fastfun.service.enums;
+
+/**
+ * @Project:boss
+ * @ClassName:设备状态
+ * @Describe:TODO
+ * @author user
+ */
+public enum EnumDeviceStatus {
+    /**
+     * 设备状态
+     */
+    PRODUCTION(0, "生产"),
+    STORAGE_TRANSPORTATION(1, "入库运输中"),
+    PLATFORM_INVENTORY(2, "平台库存"),
+    TO_STORE_TRANSPORTATION(3, "发货至网点运输中"),
+    TO_MERCHANT_TRANSPORTATION(4, "发货至商户运输中"),
+    STORE_INVENTORY(5, "网点库存"),
+    MERCHANT_INVENTORY(6, "商户库存"),
+    STORE_USER_INUSE(7, "网点用户使用中"),
+    MERCHANT_USER_INUSE(8, "商户用户使用中"),
+    REPAIR_TRANSPORTATION(9, "送修运输中"),
+    IN_REPAIR(10, "维修中"),
+    REPAIR_DONE(11, "维修完成"),
+    SCRAP(12, "报废"),
+    LOSE(13, "丢失"),
+    ;
+    Integer value;
+    String text;
+
+    EnumDeviceStatus(Integer value, String text) {
+        this.value = value;
+        this.text = text;
+    }
+
+    public Integer getValue() {
+        return value;
+    }
+
+    public void setValue(Integer value) {
+        this.value = value;
+    }
+
+    public String getText() {
+        return text;
+    }
+
+    public void setText(String text) {
+        this.text = text;
+    }
+}
+

+ 125 - 0
src/main/java/cn/fastfun/service/impl/AppAssetProfitServiceImpl.java

@@ -0,0 +1,125 @@
+package cn.fastfun.service.impl;
+
+import cn.fastfun.controller.dto.asset.BaseInfoDTO;
+import cn.fastfun.controller.dto.asset.RentInfoDTO;
+import cn.fastfun.controller.param.*;
+import cn.fastfun.service.AppDeviceLogService;
+import cn.fastfun.service.AppDeviceService;
+import cn.fastfun.service.UtilService;
+import cn.fastfun.service.entity.AppDevice;
+import cn.fastfun.service.entity.AppDeviceLog;
+import cn.fastfun.service.entity.AppImeiHistory;
+import cn.fastfun.util.ObjectUtil;
+import cn.fastfun.util.OkHttpCli;
+import com.alibaba.fastjson.JSONObject;
+import com.bridge.dto.ApiPageDTO;
+import com.bridge.dto.QueryParam;
+import com.bridge.dto.QueryParamExp;
+import com.bridge.exception.ApiRuntimeException;
+import com.bridge.service.JpaService;
+import com.bridge.service.impl.JpaServiceImp;
+import lombok.extern.slf4j.Slf4j;
+import org.apache.commons.lang3.BooleanUtils;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.dao.EmptyResultDataAccessException;
+import org.springframework.jdbc.core.JdbcTemplate;
+import org.springframework.scheduling.annotation.Async;
+import org.springframework.scheduling.annotation.AsyncResult;
+import org.springframework.stereotype.Service;
+import org.springframework.util.CollectionUtils;
+import org.springframework.util.StringUtils;
+
+import javax.annotation.Resource;
+import javax.transaction.Transactional;
+import java.math.BigDecimal;
+import java.math.BigInteger;
+import java.sql.Timestamp;
+import java.util.*;
+import java.util.concurrent.Future;
+
+@Slf4j
+@Service
+public class AppAssetProfitServiceImpl {
+    @Autowired
+    OkHttpCli okHttpCli;
+
+    //基础信息
+    @Async
+    public Future<String> assetBatteryBasicInfo(AssetProfitParam param) {
+        Map<String, String> mapHeaders = new HashMap<>();
+//        mapHeaders.put("Cookie", cookie);
+        JSONObject json = new JSONObject();
+        json.put("sn", param.getSn());
+        String response = okHttpCli.doPostTokenJson("http://192.168.0.131:8082/admin/v1/assetBatteryBasicInfo", json.toJSONString(), mapHeaders);
+        Future<String> result = new AsyncResult<>(response);
+        return result;
+    }
+
+    // 时间线信息
+    @Async
+    public Future<String> getDateLine(AssetProfitParam param) {
+        Map<String, String> mapHeaders = new HashMap<>();
+//        mapHeaders.put("Cookie", cookie);
+        JSONObject json = new JSONObject();
+        json.put("sn", param.getSn());
+        String response = okHttpCli.doPostTokenJson("http://192.168.0.131:8082/admin/v1/getDateLine", json.toJSONString(), mapHeaders);
+        Future<String> result = new AsyncResult<>(response);
+        return result;
+    }
+
+    // 租赁信息列表
+    @Async
+    public Future<String> marketingInformation(AssetProfitParam param) {
+        Map<String, String> mapHeaders = new HashMap<>();
+//        mapHeaders.put("Cookie", cookie);
+        JSONObject json = new JSONObject();
+        json.put("sn", param.getSn());
+        String response = okHttpCli.doPostTokenJson("http://192.168.0.131:8082/admin/v1/marketingInformation", json.toJSONString(), mapHeaders);
+        Future<String> result = new AsyncResult<>(response);
+        return result;
+    }
+
+    // 资产基础信息
+    public BaseInfoDTO getBaseInfo(AssetProfitParam param) throws Exception {
+        BaseInfoDTO baseInfo = new BaseInfoDTO();
+        List<String> response = new ArrayList<>();
+        try {
+            List<Future<String>> futures = new ArrayList<>();
+            futures.add(assetBatteryBasicInfo(param));
+            futures.add(getDateLine(param));
+            //死循环,每隔2000ms执行一次,判断一下这三个异步调用的方法是否全都执行完了。
+            while (true) {
+                //使用Future的isDone()方法返回该方法是否执行完成
+                if (futures.get(0).isDone() && futures.get(1).isDone()) {
+                    //如果异步方法全部执行完,跳出循环
+                    break;
+                }
+                //每隔200毫秒判断一次
+                Thread.sleep(200);
+            }
+            for (Future<String> future:futures){
+                String string = future.get();
+                response.add(string);
+            }
+//            JSONObject jsonObject = JSONObject.parseObject(string);
+        } catch (Exception e) {
+            throw new Exception("" + e.getMessage());
+        }
+
+        baseInfo.setSn("");
+        return baseInfo;
+    }
+
+    // 租赁信息
+    public RentInfoDTO getRentInfo(String sn, String startTime, String endTime, Integer pageSize, Integer pageIndex){
+        RentInfoDTO rentInfo = new RentInfoDTO();
+        RentInfoDTO.AllInfo allInfo = new RentInfoDTO.AllInfo();
+        allInfo.setAmount(new BigDecimal(10));
+        allInfo.setTime("2021-10-21:00:00:00");
+        allInfo.setDescription("测试");
+        allInfo.setOrder("R123456");
+        allInfo.setType("押金-收");
+        rentInfo.getAllInfoList().add(allInfo);
+        return rentInfo;
+    }
+}

+ 47 - 0
src/main/java/cn/fastfun/util/EmptyUtils.java

@@ -0,0 +1,47 @@
+package cn.fastfun.util;
+
+import java.lang.reflect.Array;
+import java.util.Collection;
+import java.util.Map;
+
+public class EmptyUtils {
+    private EmptyUtils() {
+        throw new UnsupportedOperationException("u can't instantiate me...");
+    }
+
+    /**
+     * 判断对象是否为空
+     *
+     * @param obj 对象
+     * @return {@code true}: 为空<br>{@code false}: 不为空
+     */
+    public static boolean isEmpty(Object obj) {
+        if (obj == null) {
+            return true;
+        }
+        if (obj instanceof String && obj.toString().length() == 0) {
+            return true;
+        }
+        if (obj.getClass().isArray() && Array.getLength(obj) == 0) {
+            return true;
+        }
+        if (obj instanceof Collection && ((Collection) obj).isEmpty()) {
+            return true;
+        }
+        if (obj instanceof Map && ((Map) obj).isEmpty()) {
+            return true;
+        }
+
+        return false;
+    }
+
+    /**
+     * 判断对象是否非空
+     *
+     * @param obj 对象
+     * @return {@code true}: 非空<br>{@code false}: 空
+     */
+    public static boolean isNotEmpty(Object obj) {
+        return !isEmpty(obj);
+    }
+}

+ 252 - 0
src/main/java/cn/fastfun/util/OkHttpCli.java

@@ -0,0 +1,252 @@
+package cn.fastfun.util;
+
+import lombok.extern.slf4j.Slf4j;
+import okhttp3.*;
+import org.apache.commons.lang3.exception.ExceptionUtils;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Component;
+
+import javax.annotation.Resource;
+import java.io.IOException;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.Objects;
+
+/**
+ * @author Answer.AI.L
+ * @date 2019-04-09
+ */
+@Slf4j
+@Component
+public class OkHttpCli {
+    private static final MediaType JSON = MediaType.parse("application/json; charset=utf-8");
+    private static final MediaType XML = MediaType.parse("application/xml; charset=utf-8");
+
+    @Resource
+    private OkHttpClient okHttpClient;
+
+    /**
+     * get 请求
+     *
+     * @param url 请求url地址
+     * @return string
+     */
+    public String doGet(String url) {
+        return doGet(url, null, null);
+    }
+
+    /**
+     * get 请求
+     *
+     * @param url    请求url地址
+     * @param params 请求参数 map
+     * @return string
+     */
+    public String doGet(String url, Map<String, String> params) {
+        return doGet(url, params, null);
+    }
+
+    /**
+     * get 请求
+     *
+     * @param url     请求url地址
+     * @param headers 请求头字段 {k1, v1 k2, v2, ...}
+     * @return string
+     */
+    public String doGet(String url, String[] headers) {
+        return doGet(url, null, headers);
+    }
+
+    /**
+     * get 请求
+     *
+     * @param url     请求url地址
+     * @param params  请求参数 map
+     * @param headers 请求头字段 {k1, v1 k2, v2, ...}
+     * @return string
+     */
+    public String doGet(String url, Map<String, String> params, String[] headers) {
+        StringBuilder sb = new StringBuilder(url);
+        if (params != null && params.keySet().size() > 0) {
+            boolean firstFlag = true;
+            for (String key : params.keySet()) {
+                if (firstFlag) {
+                    sb.append("?").append(key).append("=").append(params.get(key));
+                    firstFlag = false;
+                } else {
+                    sb.append("&").append(key).append("=").append(params.get(key));
+                }
+            }
+        }
+        Request.Builder builder = new Request.Builder();
+        if (headers != null && headers.length > 0) {
+            if (headers.length % 2 == 0) {
+                for (int i = 0; i < headers.length; i = i + 2) {
+                    builder.addHeader(headers[i], headers[i + 1]);
+                }
+            } else {
+                log.warn("headers's length[{}] is error.", headers.length);
+            }
+        }
+        Request request = builder.url(sb.toString()).build();
+        log.info("do get request and url[{}]", sb.toString());
+        return execute(request);
+    }
+
+    /**
+     * post 请求
+     *
+     * @param url    请求url地址
+     * @param params 请求参数 map
+     * @return string
+     */
+    public String doPost(String url, Map<String, String> params) {
+        FormBody.Builder builder = new FormBody.Builder();
+        if (params != null && params.keySet().size() > 0) {
+            for (String key : params.keySet()) {
+                builder.add(key, params.get(key));
+            }
+        }
+        Request request = new Request.Builder().url(url).post(builder.build()).build();
+        log.info("do post request and url[{}]", url);
+        return execute(request);
+    }
+
+    /**
+     * post 请求, 请求数据为 json 的字符串
+     *
+     * @param url  请求url地址
+     * @param json 请求数据, json 字符串
+     * @return string
+     */
+    public String doPostJson(String url, String json) {
+        log.info("do post request and url[{}]", url);
+        return executePost(url, json, JSON);
+    }
+
+    /**
+     * post 请求, 请求数据为 json 的字符串
+     *
+     * @param url  请求url地址
+     * @param json 请求数据, json 字符串
+     * @return string
+     */
+    public String doPostTokenJson(String url, String json, Map<String,String> mapHeaders) {
+        log.info("do post request and url[{}]", url);
+        return executeTokenPost(url, json, JSON, mapHeaders);
+    }
+
+    /**
+     * post 请求, 请求数据为 xml 的字符串
+     *
+     * @param url 请求url地址
+     * @param xml 请求数据, xml 字符串
+     * @return string
+     */
+    public String doPostXml(String url, String xml) {
+        log.info("do post request and url[{}]", url);
+        return executePost(url, xml, XML);
+    }
+
+    private String executePost(String url, String data, MediaType contentType) {
+        RequestBody requestBody = RequestBody.create(contentType,data);
+        Request request = new Request.Builder()
+                .url(url)
+                .post(requestBody)
+                .build();
+        return execute(request);
+    }
+
+    private String executeTokenPost(String url, String data, MediaType contentType,Map<String,String> mapHeaders) {
+        RequestBody requestBody = RequestBody.create(contentType, data);
+        Headers headers = setHeaders(mapHeaders);
+
+        Request request = new Request.Builder()
+                .url(url)
+                .headers(headers)
+                .post(requestBody)
+                .build();
+        return execute(request);
+    }
+    public String executeCookiePost(String url, String data, MediaType contentType,Map<String,String> map) {
+        RequestBody requestBody = RequestBody.create(contentType, data);
+        Headers headers = setHeaders(map);
+        Request request = new Request.Builder()
+                .url(url)
+                .headers(headers)
+                .post(requestBody)
+                .header("Cookie", map.get("Cookie"))
+                .build();
+        return executeCookie(request);
+    }
+
+    private String execute(Request request) {
+        Response response = null;
+        String result = null;
+        try {
+            response = okHttpClient.newCall(request).execute();
+            if (response.isSuccessful()) {
+                result = response.body().string();
+            }else{
+                result = String.format("调用失败:{}",response.body().string());
+            }
+        } catch (Exception e) {
+            log.error(ExceptionUtils.getStackTrace(e));
+        } finally {
+            if (response != null) {
+                response.close();
+            }
+        }
+        return result;
+    }
+
+    private String executeCookie(Request request) {
+        /**/Response response = null;
+        try {
+            response = okHttpClient.newCall(request).execute();
+            if (response.isSuccessful()) {
+                String result = Objects.requireNonNull(response.body()).string();
+                System.out.println(result);
+                return result;
+            }
+        } catch (Exception e) {
+            log.error(ExceptionUtils.getStackTrace(e));
+        } finally {
+            if (response != null) {
+                response.close();
+            }
+        }
+
+        //、把请求对象传递给Call,创建call网络请求
+        /*Call call = okHttpClient.newCall(request);
+        call.enqueue(new Callback() {
+            @Override
+            public void onFailure(Call call, IOException e) {
+                log.error(ExceptionUtils.getStackTrace(e));
+            }
+
+            @Override
+            public void onResponse(Call call, Response response) throws IOException {
+                String string = Objects.requireNonNull(response.body()).string();
+                System.out.println(string);
+            }
+        });*/
+
+        return "";
+    }
+
+    private static Headers setHeaders(Map<String, String> headersParams) {
+        Headers headers = null;
+        okhttp3.Headers.Builder headersbuilder = new okhttp3.Headers.Builder();
+        if (EmptyUtils.isNotEmpty(headersParams)) {
+            Iterator<String> iterator = headersParams.keySet().iterator();
+            String key = "";
+            while (iterator.hasNext()) {
+                key = iterator.next();
+                headersbuilder.add(key, headersParams.get(key));
+            }
+        }
+        headers = headersbuilder.build();
+        return headers;
+    }
+}

+ 11 - 1
src/main/resources/application-dev.yml

@@ -29,4 +29,14 @@ logging:
 
 project:
   token-time: 360000
-  secret-key: pdms-oss-api
+  secret-key: pdms-oss-api
+
+ok:
+  http:
+    connect-timeout: 30
+    read-timeout: 30
+    write-timeout: 30
+    # 连接池中整体的空闲连接的最大数量
+    max-idle-connections: 200
+    # 连接空闲时间最多为 300 秒
+    keep-alive-duration: 300