|
@@ -7,18 +7,23 @@ import com.alibaba.fastjson.JSONArray;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
//import com.huimv.common.date.DateUtil;
|
|
|
import com.huimv.production.autoGetData.entity.IndexParameter;
|
|
|
+import com.huimv.production.autoGetData.entity.ProdWarningMsgEntity;
|
|
|
import com.huimv.production.autoGetData.entity.ProductionGroup;
|
|
|
import com.huimv.production.autoGetData.repo.IndexParameterRepository;
|
|
|
+import com.huimv.production.autoGetData.repo.ProdWarningMsgRepo;
|
|
|
import com.huimv.production.autoGetData.repo.ProductionGroupRepo;
|
|
|
import com.huimv.production.autoGetData.service.IAutoGetErpData;
|
|
|
import com.huimv.production.autoGetData.utils.HttpTemplete;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
|
+import org.springframework.data.domain.Example;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.web.client.RestTemplate;
|
|
|
|
|
|
import java.io.IOException;
|
|
|
+import java.sql.Timestamp;
|
|
|
+import java.text.ParseException;
|
|
|
import java.util.*;
|
|
|
|
|
|
/**
|
|
@@ -54,6 +59,8 @@ public class AutoGetErpDataImpl implements IAutoGetErpData {
|
|
|
private ProductionGroupRepo productionGroupRepo;
|
|
|
@Autowired
|
|
|
private com.huimv.production.autoGetData.utils.DateUtil dateUtil;
|
|
|
+ @Autowired
|
|
|
+ private ProdWarningMsgRepo warningMsgRepo;
|
|
|
|
|
|
//PSY
|
|
|
@Override
|
|
@@ -520,11 +527,12 @@ public class AutoGetErpDataImpl implements IAutoGetErpData {
|
|
|
public void getCostWithManyFarm() throws IOException {
|
|
|
//
|
|
|
String token = getRemoteToken();
|
|
|
+ //
|
|
|
Map<String, String> paramsMap = new HashMap<String, String>();
|
|
|
paramsMap.put("accessToken", token);
|
|
|
paramsMap.put("year", dateUtil.getThisYear());
|
|
|
paramsMap.put("month", dateUtil.getThisMonth());
|
|
|
- System.out.println("paramsMap>>"+paramsMap);
|
|
|
+ //
|
|
|
Map<String, Integer> timeoutMap = new HashMap<String, Integer>();
|
|
|
timeoutMap.put("connectTimeout", 120000);
|
|
|
timeoutMap.put("requestTimeout", 120000);
|
|
@@ -558,6 +566,82 @@ public class AutoGetErpDataImpl implements IAutoGetErpData {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * @Method : getWarningMessage
|
|
|
+ * @Description :
|
|
|
+ * @Params : []
|
|
|
+ * @Return : void
|
|
|
+ *
|
|
|
+ * @Author : ZhuoNing
|
|
|
+ * @Date : 2021/11/19
|
|
|
+ * @Time : 15:48
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public void getWarningMessage() throws IOException, ParseException {
|
|
|
+ //
|
|
|
+ String token = getRemoteToken();
|
|
|
+ //
|
|
|
+ Map<String, String> paramsMap = new HashMap<String, String>();
|
|
|
+ paramsMap.put("accessToken", token);
|
|
|
+ //
|
|
|
+ Map<String, Integer> timeoutMap = new HashMap<String, Integer>();
|
|
|
+ timeoutMap.put("connectTimeout", 120000);
|
|
|
+ timeoutMap.put("requestTimeout", 120000);
|
|
|
+ timeoutMap.put("socketTimeout", 120000);
|
|
|
+ String url = apiIp + apiPort + serviceName +"/getWarningMessage";
|
|
|
+ log.info("获取预警数据访问地址="+url);
|
|
|
+ log.info("业务请求参数="+paramsMap.toString());
|
|
|
+ log.info("超时参数="+timeoutMap.toString());
|
|
|
+ log.info("开始取数="+new Date(System.currentTimeMillis()));
|
|
|
+ //
|
|
|
+ JSONObject outJo = httpClientUtil.doGet(url,paramsMap,timeoutMap);
|
|
|
+ log.info("返回结果="+outJo);
|
|
|
+ log.info("结束取数="+new Date(System.currentTimeMillis()));
|
|
|
+ if(outJo.getBoolean("status")){
|
|
|
+ JSONObject contentJo = outJo.getJSONObject("content");
|
|
|
+ if(contentJo.getBoolean("success")){
|
|
|
+ JSONArray dataJa = contentJo.getJSONArray("data");
|
|
|
+ if(dataJa.size()==0){
|
|
|
+ log.info("未取到数据 。");
|
|
|
+ }
|
|
|
+ //删除当天旧数据
|
|
|
+ ProdWarningMsgEntity delWarningMsgEntity = new ProdWarningMsgEntity();
|
|
|
+ delWarningMsgEntity.setAddTime(dateUtil.getTodayDate());
|
|
|
+ Example<ProdWarningMsgEntity> example = Example.of(delWarningMsgEntity);
|
|
|
+ warningMsgRepo.deleteAll(warningMsgRepo.findAll(example));
|
|
|
+
|
|
|
+ // 添加入库
|
|
|
+ for(int a=0;a<dataJa.size();a++){
|
|
|
+ JSONObject dataJo = dataJa.getJSONObject(a);
|
|
|
+ String content = dataJo.getString("xxnr").trim();
|
|
|
+ String[] contentArray = content.split("-");
|
|
|
+ String pigfarm = "";
|
|
|
+ String message = "";
|
|
|
+ if(contentArray.length>=2){
|
|
|
+ pigfarm = contentArray[0];
|
|
|
+ message = content.replace(pigfarm+"-","").trim();
|
|
|
+ }else{
|
|
|
+ pigfarm = content.substring(0,3);
|
|
|
+ message= content.substring(3,content.length());;
|
|
|
+ }
|
|
|
+// System.out.println((a+1)+" "+dateUtil.formatDateTime(dataJo.getString("tsrq"))+","+pigfarm+","+message+" length="+contentArray.length);
|
|
|
+ ProdWarningMsgEntity newWarningMsgEntity = new ProdWarningMsgEntity();
|
|
|
+ newWarningMsgEntity.setTipTime(dateUtil.formatDateTime(dataJo.getString("tsrq")));
|
|
|
+ newWarningMsgEntity.setFarmName(pigfarm);
|
|
|
+ newWarningMsgEntity.setWarningContent(message);
|
|
|
+ newWarningMsgEntity.setFarmId(0);
|
|
|
+ newWarningMsgEntity.setAddTime(new Timestamp(new Date().getTime()));
|
|
|
+ newWarningMsgEntity.setHandleState(0);
|
|
|
+ ProdWarningMsgEntity outWarningMsgEntity = warningMsgRepo.saveAndFlush(newWarningMsgEntity);
|
|
|
+ }
|
|
|
+ }else{
|
|
|
+ System.out.println("取数失败");
|
|
|
+ }
|
|
|
+ }else{
|
|
|
+ System.out.println("取数失败");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
/* public static void main(String[] args) {
|
|
|
RestTemplate restTemplate = new RestTemplate();
|
|
|
|