|
@@ -1,6 +1,10 @@
|
|
|
package org.king.modules.ad.controller;
|
|
|
|
|
|
+import cn.hutool.http.HttpUtil;
|
|
|
+import com.alibaba.fastjson.JSONArray;
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
|
+
|
|
|
import io.swagger.annotations.Api;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.king.common.api.vo.Result;
|
|
@@ -11,6 +15,7 @@ import org.springframework.web.bind.annotation.GetMapping;
|
|
|
import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
import org.springframework.web.bind.annotation.RestController;
|
|
|
|
|
|
+import java.io.*;
|
|
|
import java.text.SimpleDateFormat;
|
|
|
import java.util.ArrayList;
|
|
|
import java.util.Date;
|
|
@@ -33,6 +38,9 @@ public class StaticalController {
|
|
|
@Autowired
|
|
|
private IAdChargingRecordService adChargingRecordService;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private IBaseShipInfoService baseShipInfoService;
|
|
|
+
|
|
|
@GetMapping(value = "/getDeviceCount")
|
|
|
public Result<?> getDeviceCount() {
|
|
|
AdDeviceCount count =staticalService.getDeviceCount();
|
|
@@ -59,16 +67,67 @@ public class StaticalController {
|
|
|
|
|
|
@GetMapping(value = "/getChargeRecord")
|
|
|
public Result<?> getChargeRecord(){
|
|
|
- SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");
|
|
|
- List<String> list = new ArrayList<String>();
|
|
|
- List<AdChargingRecord> chargelist = adChargingRecordService.list(Wrappers.<AdChargingRecord>lambdaQuery().apply("date_format(create_time,'%Y-%m-%d') = '"+df.format(new Date())+"'"));
|
|
|
- List<AdShipFaultReport> shiplist =adShipFaultReportService.list(Wrappers.<AdShipFaultReport>lambdaQuery().apply("date_format(create_time,'%Y-%m-%d') = '"+df.format(new Date())+"'"));
|
|
|
- for(AdChargingRecord obj:chargelist){
|
|
|
- list.add(obj.getShipId());
|
|
|
+// String json = HttpUtil.get("http://36.154.210.106:8090/ybl/czs/ship/anchorOverTwoHours");
|
|
|
+ List<BaseShipInfo> shipInfos = new ArrayList<BaseShipInfo>();
|
|
|
+ String json = readJsonFile("d://ad.json");
|
|
|
+ JSONObject jsonObject = JSONObject.parseObject(json);
|
|
|
+ if(jsonObject.get("code").toString().equals("200")){
|
|
|
+ SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");
|
|
|
+ List<String> list = new ArrayList<String>();
|
|
|
+ List<AdChargingRecord> chargelist = adChargingRecordService.list(Wrappers.<AdChargingRecord>lambdaQuery().apply("date_format(create_time,'%Y-%m-%d') = '"+df.format(new Date())+"'"));
|
|
|
+ List<AdShipFaultReport> shiplist =adShipFaultReportService.list(Wrappers.<AdShipFaultReport>lambdaQuery().apply("date_format(create_time,'%Y-%m-%d') = '"+df.format(new Date())+"'"));
|
|
|
+ for(AdChargingRecord obj:chargelist){
|
|
|
+ list.add(obj.getShipId());
|
|
|
+ }
|
|
|
+ for(AdShipFaultReport obj:shiplist){
|
|
|
+ list.add(obj.getShipId());
|
|
|
+ }
|
|
|
+ JSONArray result= JSONArray.parseArray(jsonObject.get("result").toString());
|
|
|
+ String[] ships = new String[result.size()];
|
|
|
+ for(int i=0;i<result.size();i++) {
|
|
|
+// System.out.println(result.getJSONObject(i).get("id"));
|
|
|
+ ships[i] = result.getJSONObject(i).get("id").toString();
|
|
|
+ }
|
|
|
+ List<BaseShipInfo> yujinList = baseShipInfoService.getListBymmsi(ships);
|
|
|
+ for(BaseShipInfo baseShipInfo:yujinList ){
|
|
|
+ if(baseShipInfo.getShipId() != null){
|
|
|
+ int i = 0;
|
|
|
+ for(String shipid:list ){
|
|
|
+ if(baseShipInfo.getShipId().equals(shipid)){
|
|
|
+ i = 1;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if(i == 0){
|
|
|
+ shipInfos.add(baseShipInfo);
|
|
|
+ }
|
|
|
+ }
|
|
|
+// shipInfos.add(baseShipInfo);
|
|
|
+ }
|
|
|
+ return Result.ok(shipInfos);
|
|
|
+ }else{
|
|
|
+ return Result.error("预警接口访问失败,错误码"+jsonObject.get("code").toString());
|
|
|
}
|
|
|
- for(AdShipFaultReport obj:shiplist){
|
|
|
- list.add(obj.getShipId());
|
|
|
+ }
|
|
|
+
|
|
|
+ public static String readJsonFile(String fileName) {
|
|
|
+ String jsonStr = "";
|
|
|
+ try {
|
|
|
+ File jsonFile = new File(fileName);
|
|
|
+ FileReader fileReader = new FileReader(jsonFile);
|
|
|
+ Reader reader = new InputStreamReader(new FileInputStream(jsonFile),"utf-8");
|
|
|
+ int ch = 0;
|
|
|
+ StringBuffer sb = new StringBuffer();
|
|
|
+ while ((ch = reader.read()) != -1) {
|
|
|
+ sb.append((char) ch);
|
|
|
+ }
|
|
|
+ fileReader.close();
|
|
|
+ reader.close();
|
|
|
+ jsonStr = sb.toString();
|
|
|
+ return jsonStr;
|
|
|
+ } catch (IOException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ return null;
|
|
|
}
|
|
|
- return Result.ok(list);
|
|
|
}
|
|
|
+
|
|
|
}
|