|
@@ -1,7 +1,6 @@
|
|
|
package cn.fastfun.service.impl;
|
|
|
|
|
|
-import cn.fastfun.controller.dto.asset.BaseInfoDTO;
|
|
|
-import cn.fastfun.controller.dto.asset.RentInfoDTO;
|
|
|
+import cn.fastfun.controller.dto.asset.*;
|
|
|
import cn.fastfun.controller.param.*;
|
|
|
import cn.fastfun.service.AppDeviceLogService;
|
|
|
import cn.fastfun.service.AppDeviceService;
|
|
@@ -11,6 +10,8 @@ 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.JSON;
|
|
|
+import com.alibaba.fastjson.JSONArray;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
import com.bridge.dto.ApiPageDTO;
|
|
|
import com.bridge.dto.QueryParam;
|
|
@@ -21,6 +22,7 @@ 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.beans.factory.annotation.Value;
|
|
|
import org.springframework.dao.EmptyResultDataAccessException;
|
|
|
import org.springframework.jdbc.core.JdbcTemplate;
|
|
|
import org.springframework.scheduling.annotation.Async;
|
|
@@ -34,6 +36,7 @@ import javax.transaction.Transactional;
|
|
|
import java.math.BigDecimal;
|
|
|
import java.math.BigInteger;
|
|
|
import java.sql.Timestamp;
|
|
|
+import java.text.SimpleDateFormat;
|
|
|
import java.util.*;
|
|
|
import java.util.concurrent.Future;
|
|
|
|
|
@@ -43,6 +46,13 @@ public class AppAssetProfitServiceImpl {
|
|
|
@Autowired
|
|
|
OkHttpCli okHttpCli;
|
|
|
|
|
|
+ @Value("${openapi.ip}")
|
|
|
+ private String openApiIp;
|
|
|
+
|
|
|
+ @Value("${openapi.port}")
|
|
|
+ private String openApiPort;
|
|
|
+
|
|
|
+
|
|
|
//基础信息
|
|
|
@Async
|
|
|
public Future<String> assetBatteryBasicInfo(AssetProfitParam param) {
|
|
@@ -50,7 +60,7 @@ public class AppAssetProfitServiceImpl {
|
|
|
// 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);
|
|
|
+ String response = okHttpCli.doPostTokenJson(String.format("http://%s:%s/admin/v1/assetBatteryBasicInfo", openApiIp, openApiPort), json.toJSONString(), mapHeaders);
|
|
|
Future<String> result = new AsyncResult<>(response);
|
|
|
return result;
|
|
|
}
|
|
@@ -62,19 +72,39 @@ public class AppAssetProfitServiceImpl {
|
|
|
// 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);
|
|
|
+ String response = okHttpCli.doPostTokenJson(String.format("http://%s:%s/admin/v1/getDateLine", openApiIp, openApiPort), json.toJSONString(), mapHeaders);
|
|
|
Future<String> result = new AsyncResult<>(response);
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
- // 租赁信息列表
|
|
|
+ // 租赁信息列表/绘图
|
|
|
@Async
|
|
|
- public Future<String> marketingInformation(AssetProfitParam param) {
|
|
|
+ public Future<String> getDepositAndEnt(AssetProfitParam param) {
|
|
|
Map<String, String> mapHeaders = new HashMap<>();
|
|
|
+ String response;
|
|
|
// 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);
|
|
|
+ // 请求表单
|
|
|
+ if (param.getFigureOrNot() == false) {
|
|
|
+ json.put("sn", param.getSn());
|
|
|
+
|
|
|
+ json.put("pageSize", param.getLength());
|
|
|
+ json.put("pageIndex", param.getIndex());
|
|
|
+
|
|
|
+ if (param.getType() == null || param.getType() == "") {
|
|
|
+ json.put("type", "1,2,3,4,5");
|
|
|
+ } else {
|
|
|
+ json.put("type", param.getType());
|
|
|
+ }
|
|
|
+ response = okHttpCli.doPostTokenJson(String.format("http://%s:%s/admin/v1/getDepositAndEnt", openApiIp, openApiPort), json.toJSONString(), mapHeaders);
|
|
|
+ } else {
|
|
|
+ json.put("sn", param.getSn());
|
|
|
+ json.put("type", "1,2,3,4,5");
|
|
|
+ json.put("startTime", new SimpleDateFormat("yyyy-MM-dd").format(param.getTimeStart()));
|
|
|
+ json.put("endTime", new SimpleDateFormat("yyyy-MM-dd").format(param.getTimeEnd()));
|
|
|
+ response = okHttpCli.doPostTokenJson(String.format("http://%s:%s/admin/v1/getDepositAndEntChart", openApiIp, openApiPort), json.toJSONString(), mapHeaders);
|
|
|
+ }
|
|
|
+
|
|
|
Future<String> result = new AsyncResult<>(response);
|
|
|
return result;
|
|
|
}
|
|
@@ -97,7 +127,7 @@ public class AppAssetProfitServiceImpl {
|
|
|
//每隔200毫秒判断一次
|
|
|
Thread.sleep(200);
|
|
|
}
|
|
|
- for (Future<String> future:futures){
|
|
|
+ for (Future<String> future : futures) {
|
|
|
String string = future.get();
|
|
|
response.add(string);
|
|
|
}
|
|
@@ -106,20 +136,253 @@ public class AppAssetProfitServiceImpl {
|
|
|
throw new Exception("" + e.getMessage());
|
|
|
}
|
|
|
|
|
|
- baseInfo.setSn("");
|
|
|
+ // 开放平台返回数据解析
|
|
|
+ JSONObject baseData = JSONObject.parseObject(response.get(0));
|
|
|
+ BasicAssetDto basicAssetDto = new BasicAssetDto();
|
|
|
+ if (baseData.get("data") != null) {
|
|
|
+ basicAssetDto = JSONObject.parseObject(baseData.get("data").toString(), BasicAssetDto.class);
|
|
|
+ }
|
|
|
+ baseInfo.setSn(basicAssetDto.getSn());
|
|
|
+ baseInfo.setCategory(basicAssetDto.getDeviceTypeText());
|
|
|
+ baseInfo.setType(basicAssetDto.getDeviceType());
|
|
|
+ baseInfo.setFactory(basicAssetDto.getFactory());
|
|
|
+ baseInfo.setCellFactory(basicAssetDto.getElectricCore());
|
|
|
+ baseInfo.setCellType(basicAssetDto.getElectricCoreTypeText());
|
|
|
+ baseInfo.setVoltPlatform(basicAssetDto.getVoltageText());
|
|
|
+ baseInfo.setCapacity(basicAssetDto.getCapacity());
|
|
|
+ baseInfo.setProductTime(basicAssetDto.getCreateTime());
|
|
|
+ baseInfo.setOperationTime(basicAssetDto.getOperationTime());
|
|
|
+ baseInfo.setPrice(basicAssetDto.getPurchasePrice());
|
|
|
+ baseInfo.setStatus(basicAssetDto.getStatusText());
|
|
|
+ baseInfo.setRegion(basicAssetDto.getLocationText());
|
|
|
+ JSONObject dataLine = JSONObject.parseObject(response.get(1));
|
|
|
+ List<DeviceLineDto> deviceLineDtos = new ArrayList<>();
|
|
|
+ if (dataLine.get("data") != null) {
|
|
|
+ deviceLineDtos = JSONArray.parseArray(dataLine.get("data").toString(), DeviceLineDto.class);
|
|
|
+ }
|
|
|
+
|
|
|
+ // 返回时间线
|
|
|
+ BaseInfoDTO.TimeLine deliverTimeline = new BaseInfoDTO.TimeLine();
|
|
|
+ deliverTimeline.setTime("发货时间");
|
|
|
+ BaseInfoDTO.TimeLine storageTimeline = new BaseInfoDTO.TimeLine();
|
|
|
+ storageTimeline.setTime("入库时间");
|
|
|
+ BaseInfoDTO.TimeLine rentTimeline = new BaseInfoDTO.TimeLine();
|
|
|
+ rentTimeline.setTime("首次租赁时间");
|
|
|
+ BaseInfoDTO.TimeLine recallTimeline = new BaseInfoDTO.TimeLine();
|
|
|
+ recallTimeline.setTime("回调时间");
|
|
|
+ Collections.reverse(deviceLineDtos);
|
|
|
+ Boolean storageFlag = false;
|
|
|
+ Boolean rentFlag = false;
|
|
|
+ if (deviceLineDtos.size() > 0) {
|
|
|
+ for (DeviceLineDto d : deviceLineDtos) {
|
|
|
+ // 入库时间
|
|
|
+ if (d.getAction().equals(20) && !storageFlag) {
|
|
|
+ deliverTimeline.setTime(d.getActionTime());
|
|
|
+ storageFlag = true;
|
|
|
+ }
|
|
|
+ // 首次租赁时间
|
|
|
+ if ((d.getAction().equals(7) || d.getAction().equals(8)) && !rentFlag) {
|
|
|
+ rentTimeline.setTime(d.getActionTime());
|
|
|
+ rentFlag = true;
|
|
|
+ }
|
|
|
+ // 回调时间
|
|
|
+ if (d.getAction().equals(22)) {
|
|
|
+ recallTimeline.setTime(d.getActionTime());
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ baseInfo.getTimeLine().add(new BaseInfoDTO.TimeLine() {{
|
|
|
+ setTime(baseInfo.getProductTime());
|
|
|
+ setTime("生产时间");
|
|
|
+ }});
|
|
|
+ baseInfo.getTimeLine().add(deliverTimeline);
|
|
|
+ baseInfo.getTimeLine().add(storageTimeline);
|
|
|
+ baseInfo.getTimeLine().add(new BaseInfoDTO.TimeLine() {{
|
|
|
+ setTime(baseInfo.getOperationTime());
|
|
|
+ setTime("投营时间");
|
|
|
+ }});
|
|
|
+ baseInfo.getTimeLine().add(rentTimeline);
|
|
|
+ baseInfo.getTimeLine().add(recallTimeline);
|
|
|
+
|
|
|
+
|
|
|
+ // 采购和投营时间
|
|
|
+ if (baseInfo.getOperationTime() != null) {
|
|
|
+ SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:MM:SS");
|
|
|
+ Calendar cal = Calendar.getInstance();
|
|
|
+ cal.setTime(sdf.parse(baseInfo.getOperationTime()));
|
|
|
+ long time1 = cal.getTimeInMillis();
|
|
|
+ cal.setTime(new Date());
|
|
|
+ long time2 = cal.getTimeInMillis();
|
|
|
+ long between_days = (time2 - time1) / (1000 * 3600 * 24);
|
|
|
+ baseInfo.setOperationDay(between_days);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+// baseInfo.setDeliverTime();
|
|
|
+
|
|
|
+
|
|
|
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;
|
|
|
+ public Object getRentInfo(AssetProfitParam param) throws Exception {
|
|
|
+ Object result = null;
|
|
|
+ String response;
|
|
|
+ try {
|
|
|
+ Future<String> future;
|
|
|
+ future = getDepositAndEnt(param);
|
|
|
+ //死循环,每隔2000ms执行一次,判断一下这三个异步调用的方法是否全都执行完了。
|
|
|
+ while (true) {
|
|
|
+ //使用Future的isDone()方法返回该方法是否执行完成
|
|
|
+ if (future.isDone()) {
|
|
|
+ //如果异步方法全部执行完,跳出循环
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ //每隔200毫秒判断一次
|
|
|
+ Thread.sleep(200);
|
|
|
+ }
|
|
|
+ response = future.get();
|
|
|
+ } catch (Exception e) {
|
|
|
+ throw new Exception("" + e.getMessage());
|
|
|
+ }
|
|
|
+
|
|
|
+ // 请求的是列表
|
|
|
+ if (param.getFigureOrNot() == false) {
|
|
|
+ RentInfoDTO rentInfoDTO = new RentInfoDTO();
|
|
|
+ JSONObject rentInfo = JSONObject.parseObject(response);
|
|
|
+ SummaryCentAndDepositDto summaryCentAndDepositDto = new SummaryCentAndDepositDto();
|
|
|
+ List<RentAndDepositDto> rentAndDepositDtos = new ArrayList<>();
|
|
|
+ if (rentInfo.get("data") != null && rentInfo.get("data") != "") {
|
|
|
+ JSONObject responseData = JSONObject.parseObject(rentInfo.get("data").toString());
|
|
|
+ if (responseData.get("summary") != null && responseData.get("summary") != "") {
|
|
|
+ summaryCentAndDepositDto = JSONObject.parseObject(responseData.get("summary").toString(), SummaryCentAndDepositDto.class);
|
|
|
+ }
|
|
|
+ if (responseData.get("data") != null && responseData.get("data") != "") {
|
|
|
+ rentAndDepositDtos = JSONArray.parseArray(responseData.get("data").toString(), RentAndDepositDto.class);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ for (RentAndDepositDto r : rentAndDepositDtos) {
|
|
|
+ RentInfoDTO.AllInfo allInfo = new RentInfoDTO.AllInfo();
|
|
|
+ allInfo.setTime(r.getOrderTime());
|
|
|
+ allInfo.setOrder(r.getOrderNo());
|
|
|
+ allInfo.setDescription(r.getRemark());
|
|
|
+ allInfo.setAmount(r.getAmount());
|
|
|
+ switch (r.getType()) {
|
|
|
+ case 1:
|
|
|
+ allInfo.setType("押金-收");
|
|
|
+ break;
|
|
|
+ case 2:
|
|
|
+ allInfo.setType("押金-支");
|
|
|
+ break;
|
|
|
+ case 3:
|
|
|
+ allInfo.setType("租金-收");
|
|
|
+ break;
|
|
|
+ case 4:
|
|
|
+ allInfo.setType("租金-支");
|
|
|
+ break;
|
|
|
+ case 5:
|
|
|
+ allInfo.setType("丢失保障金");
|
|
|
+ break;
|
|
|
+ default:
|
|
|
+ allInfo.setType("");
|
|
|
+ }
|
|
|
+ rentInfoDTO.getAllInfoList().add(allInfo);
|
|
|
+ }
|
|
|
+ rentInfoDTO.setOrderStartTime(summaryCentAndDepositDto.getOrderStartTime());
|
|
|
+ rentInfoDTO.setOrderEndTime(summaryCentAndDepositDto.getOrderEndTime());
|
|
|
+ rentInfoDTO.setRental(summaryCentAndDepositDto.getCurrentCent());
|
|
|
+ rentInfoDTO.setCash(summaryCentAndDepositDto.getCurrentDeposit());
|
|
|
+ rentInfoDTO.setIncome(summaryCentAndDepositDto.getCent());
|
|
|
+ rentInfoDTO.setCashIn(summaryCentAndDepositDto.getDeposit());
|
|
|
+ rentInfoDTO.setSecurityCash(summaryCentAndDepositDto.getSecurity());
|
|
|
+ rentInfoDTO.setNetRental(summaryCentAndDepositDto.getNetIncome());
|
|
|
+ result = (RentInfoDTO)rentInfoDTO;
|
|
|
+ }
|
|
|
+ // 请求的是图表
|
|
|
+ else {
|
|
|
+ RentInfoFigureDTO rentInfoFigureDTO = new RentInfoFigureDTO();
|
|
|
+ JSONObject responseData = JSONObject.parseObject(response);
|
|
|
+ if (responseData.get("data") != null && responseData.get("data") != "") {
|
|
|
+ JSONObject rentFigureInfo = JSONObject.parseObject(responseData.get("data").toString());
|
|
|
+ Boolean timeListDone = false;
|
|
|
+ List<String> timeList = new ArrayList<>();
|
|
|
+ if (rentFigureInfo.get("securityChartList") != null && rentFigureInfo.get("securityChartList") != "") {
|
|
|
+ List<RentAndDepositChartDto> chartList = new ArrayList<>();
|
|
|
+ chartList = JSONArray.parseArray(rentFigureInfo.get("securityChartList").toString(), RentAndDepositChartDto.class);
|
|
|
+ if (chartList.size() > 0){
|
|
|
+ rentInfoFigureDTO.getLegendList().add("丢失保障金");
|
|
|
+ List<BigDecimal> dataList = new ArrayList<>();
|
|
|
+ if (!timeListDone){
|
|
|
+ chartList.forEach(p->timeList.add(p.getMonth()));
|
|
|
+ timeListDone = true;
|
|
|
+ }
|
|
|
+ chartList.forEach(p->dataList.add(p.getAmountMonth()));
|
|
|
+ rentInfoFigureDTO.getDataList().add(dataList);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (rentFigureInfo.get("centReduceChartList") != null && rentFigureInfo.get("centReduceChartList") != "") {
|
|
|
+ List<RentAndDepositChartDto> chartList = new ArrayList<>();
|
|
|
+ chartList = JSONArray.parseArray(rentFigureInfo.get("centReduceChartList").toString(), RentAndDepositChartDto.class);
|
|
|
+ if (chartList.size() > 0){
|
|
|
+ rentInfoFigureDTO.getLegendList().add("租金-支");
|
|
|
+ List<BigDecimal> dataList = new ArrayList<>();
|
|
|
+ if (!timeListDone){
|
|
|
+ chartList.forEach(p->timeList.add(p.getMonth()));
|
|
|
+ timeListDone = true;
|
|
|
+ }
|
|
|
+ chartList.forEach(p->dataList.add(p.getAmountMonth()));
|
|
|
+ rentInfoFigureDTO.getDataList().add(dataList);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (rentFigureInfo.get("centAddChartList") != null && rentFigureInfo.get("centAddChartList") != "") {
|
|
|
+ List<RentAndDepositChartDto> chartList = new ArrayList<>();
|
|
|
+ chartList = JSONArray.parseArray(rentFigureInfo.get("centAddChartList").toString(), RentAndDepositChartDto.class);
|
|
|
+ if (chartList.size() > 0){
|
|
|
+ rentInfoFigureDTO.getLegendList().add("租金-收");
|
|
|
+ List<BigDecimal> dataList = new ArrayList<>();
|
|
|
+ if (!timeListDone){
|
|
|
+ chartList.forEach(p->timeList.add(p.getMonth()));
|
|
|
+ timeListDone = true;
|
|
|
+ }
|
|
|
+ chartList.forEach(p->dataList.add(p.getAmountMonth()));
|
|
|
+ rentInfoFigureDTO.getDataList().add(dataList);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (rentFigureInfo.get("depositReduceChartList") != null && rentFigureInfo.get("depositReduceChartList") != "") {
|
|
|
+ List<RentAndDepositChartDto> chartList = new ArrayList<>();
|
|
|
+ chartList = JSONArray.parseArray(rentFigureInfo.get("depositReduceChartList").toString(), RentAndDepositChartDto.class);
|
|
|
+ if (chartList.size() > 0){
|
|
|
+ rentInfoFigureDTO.getLegendList().add("押金-支");
|
|
|
+ List<BigDecimal> dataList = new ArrayList<>();
|
|
|
+ if (!timeListDone){
|
|
|
+ chartList.forEach(p->timeList.add(p.getMonth()));
|
|
|
+ timeListDone = true;
|
|
|
+ }
|
|
|
+ chartList.forEach(p->dataList.add(p.getAmountMonth()));
|
|
|
+ rentInfoFigureDTO.getDataList().add(dataList);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (rentFigureInfo.get("depositAddChartList") != null && rentFigureInfo.get("depositAddChartList") != "") {
|
|
|
+ List<RentAndDepositChartDto> chartList = new ArrayList<>();
|
|
|
+ chartList = JSONArray.parseArray(rentFigureInfo.get("depositAddChartList").toString(), RentAndDepositChartDto.class);
|
|
|
+ if (chartList.size() > 0){
|
|
|
+ rentInfoFigureDTO.getLegendList().add("押金-收");
|
|
|
+ List<BigDecimal> dataList = new ArrayList<>();
|
|
|
+ if (!timeListDone){
|
|
|
+ chartList.forEach(p->timeList.add(p.getMonth()));
|
|
|
+ timeListDone = true;
|
|
|
+ }
|
|
|
+ chartList.forEach(p->dataList.add(p.getAmountMonth()));
|
|
|
+ rentInfoFigureDTO.getDataList().add(dataList);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ rentInfoFigureDTO.setTimeList(timeList);
|
|
|
+ }
|
|
|
+ result = (RentInfoFigureDTO) rentInfoFigureDTO;
|
|
|
+
|
|
|
+ }
|
|
|
+ return result;
|
|
|
}
|
|
|
+
|
|
|
}
|