|
@@ -21,6 +21,7 @@ import org.springframework.stereotype.Service;
|
|
import org.springframework.web.client.RestTemplate;
|
|
import org.springframework.web.client.RestTemplate;
|
|
|
|
|
|
import java.io.IOException;
|
|
import java.io.IOException;
|
|
|
|
+import java.math.BigDecimal;
|
|
import java.sql.Timestamp;
|
|
import java.sql.Timestamp;
|
|
import java.text.DecimalFormat;
|
|
import java.text.DecimalFormat;
|
|
import java.text.NumberFormat;
|
|
import java.text.NumberFormat;
|
|
@@ -79,6 +80,10 @@ public class AutoGetErpDataImpl implements IAutoGetErpData {
|
|
private MathUtil mathUtil;
|
|
private MathUtil mathUtil;
|
|
@Autowired
|
|
@Autowired
|
|
private ProdWorkPlanRepo workPlanRepo;
|
|
private ProdWorkPlanRepo workPlanRepo;
|
|
|
|
+ @Autowired
|
|
|
|
+ private ProdImportantIndicatorRepo prodImportantIndicatorRepo;
|
|
|
|
+ @Autowired
|
|
|
|
+ private ProdIndicatorDynamicRepo prodIndicatorDynamicRepo;
|
|
|
|
|
|
/* //PSY
|
|
/* //PSY
|
|
@Override
|
|
@Override
|
|
@@ -1147,7 +1152,7 @@ public class AutoGetErpDataImpl implements IAutoGetErpData {
|
|
log.info("开始取数=" + new Date(System.currentTimeMillis()));
|
|
log.info("开始取数=" + new Date(System.currentTimeMillis()));
|
|
//
|
|
//
|
|
JSONObject outJo = httpClientUtil.doGet(url, paramsMap, timeoutMap);
|
|
JSONObject outJo = httpClientUtil.doGet(url, paramsMap, timeoutMap);
|
|
-// log.info("返回结果="+outJo);
|
|
|
|
|
|
+ log.info("返回结果="+outJo);
|
|
log.info("结束取数=" + new Date(System.currentTimeMillis()));
|
|
log.info("结束取数=" + new Date(System.currentTimeMillis()));
|
|
if (outJo.getBoolean("status")) {
|
|
if (outJo.getBoolean("status")) {
|
|
JSONObject contentJo = outJo.getJSONObject("content");
|
|
JSONObject contentJo = outJo.getJSONObject("content");
|
|
@@ -1169,6 +1174,7 @@ public class AutoGetErpDataImpl implements IAutoGetErpData {
|
|
// 添加入库
|
|
// 添加入库
|
|
for (int a = 0; a < dataJa.size(); a++) {
|
|
for (int a = 0; a < dataJa.size(); a++) {
|
|
JSONObject dataJo = dataJa.getJSONObject(a);
|
|
JSONObject dataJo = dataJa.getJSONObject(a);
|
|
|
|
+ System.out.println((a+1)+" "+dataJo);
|
|
String content = dataJo.getString("xxnr").trim();
|
|
String content = dataJo.getString("xxnr").trim();
|
|
String[] contentArray = content.split("-");
|
|
String[] contentArray = content.split("-");
|
|
String pigfarm = "";
|
|
String pigfarm = "";
|
|
@@ -1258,6 +1264,7 @@ public class AutoGetErpDataImpl implements IAutoGetErpData {
|
|
List<ProdFarmNameEntity> farmNameEntityList = prodFarmNameRepo.findAll();
|
|
List<ProdFarmNameEntity> farmNameEntityList = prodFarmNameRepo.findAll();
|
|
for (int a = 0; a < dataJa.size(); a++) {
|
|
for (int a = 0; a < dataJa.size(); a++) {
|
|
JSONObject dataJo = dataJa.getJSONObject(a);
|
|
JSONObject dataJo = dataJa.getJSONObject(a);
|
|
|
|
+ System.out.println((a+1)+" "+dataJo);
|
|
ProdWorkPlanEntity workPlanEntity = new ProdWorkPlanEntity();
|
|
ProdWorkPlanEntity workPlanEntity = new ProdWorkPlanEntity();
|
|
workPlanEntity.setFarmId(_getFarmIdByFullName(dataJo.getString("mcmc"), farmNameEntityList));
|
|
workPlanEntity.setFarmId(_getFarmIdByFullName(dataJo.getString("mcmc"), farmNameEntityList));
|
|
workPlanEntity.setFarmName(dataJo.getString("mcmc"));
|
|
workPlanEntity.setFarmName(dataJo.getString("mcmc"));
|
|
@@ -1624,7 +1631,117 @@ public class AutoGetErpDataImpl implements IAutoGetErpData {
|
|
addEntity1.setYear(Integer.parseInt(year));
|
|
addEntity1.setYear(Integer.parseInt(year));
|
|
produceRepo.saveAndFlush(addEntity1);
|
|
produceRepo.saveAndFlush(addEntity1);
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ //重点指标表(试点)
|
|
|
|
+ //PSY
|
|
|
|
+ //计算前一个月(年、月)
|
|
|
|
+ Map beforeMonthMap = dateUtil.getBeforeMonth();
|
|
|
|
+
|
|
|
|
+ //计算涨跌
|
|
|
|
+ JSONArray dynamicJa = getBeforeLastMonth(psyJa,beforeMonthMap);
|
|
|
|
+
|
|
|
|
+ //删除当前一个月的数据
|
|
|
|
+ ProdImportantIndicatorEntity delImportantEntity = new ProdImportantIndicatorEntity();
|
|
|
|
+ delImportantEntity.setYear(Integer.parseInt(year));
|
|
|
|
+ delImportantEntity.setMonth(Integer.parseInt(month));
|
|
|
|
+ delImportantEntity.setStockType("psy");
|
|
|
|
+ Example<ProdImportantIndicatorEntity> delExample2 = Example.of(delImportantEntity);
|
|
|
|
+ prodImportantIndicatorRepo.deleteAll(prodImportantIndicatorRepo.findAll(delExample2));
|
|
|
|
+ //
|
|
|
|
+ for(int a=0;a<psyJa.size();a++){
|
|
|
|
+ JSONObject psyJo = psyJa.getJSONObject(a);
|
|
|
|
+ ProdImportantIndicatorEntity addImportantEntity1 = new ProdImportantIndicatorEntity();
|
|
|
|
+ addImportantEntity1.setFarmId(psyJo.getInteger("farm_id"));
|
|
|
|
+ addImportantEntity1.setStockType("psy");
|
|
|
|
+ addImportantEntity1.setStockName("PSY");
|
|
|
|
+ addImportantEntity1.setStockQuantity(psyJo.getString("stock_quantity"));
|
|
|
|
+ addImportantEntity1.setMonth(Integer.valueOf(month));
|
|
|
|
+ addImportantEntity1.setYear(Integer.parseInt(year));
|
|
|
|
+ //涨跌
|
|
|
|
+ addImportantEntity1.setRiseFall(psyJo.getInteger("rise_fall"));
|
|
|
|
+ //幅度
|
|
|
|
+ addImportantEntity1.setRange1(psyJo.getString("range"));
|
|
|
|
+ System.out.println("addImportantEntity1>>"+addImportantEntity1.toString());
|
|
|
|
+ prodImportantIndicatorRepo.saveAndFlush(addImportantEntity1);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ //添加重要指标动态统计表
|
|
|
|
+ //删除旧数据
|
|
|
|
+ ProdIndicatorDynamicEntity delDynamicEntity = new ProdIndicatorDynamicEntity();
|
|
|
|
+ delDynamicEntity.setYear(Integer.parseInt(year));
|
|
|
|
+ delDynamicEntity.setMonth(Integer.parseInt(month));
|
|
|
|
+ Example<ProdIndicatorDynamicEntity> delExample3 = Example.of(delDynamicEntity);
|
|
|
|
+ prodIndicatorDynamicRepo.deleteAll(prodIndicatorDynamicRepo.findAll(delExample3));
|
|
|
|
+ //增加信息数据
|
|
|
|
+ for(int a=0;a<dynamicJa.size();a++){
|
|
|
|
+ JSONObject dynamicJo = dynamicJa.getJSONObject(a);
|
|
|
|
+ ProdIndicatorDynamicEntity addDynamicEntity = new ProdIndicatorDynamicEntity();
|
|
|
|
+ addDynamicEntity.setFarmId(dynamicJo.getInteger("farm_id"));
|
|
|
|
+ addDynamicEntity.setYear(Integer.parseInt(year));
|
|
|
|
+ addDynamicEntity.setMonth(Integer.parseInt(month));
|
|
|
|
+ addDynamicEntity.setTotal(dynamicJo.getInteger("total"));
|
|
|
|
+ addDynamicEntity.setUp(dynamicJo.getInteger("up"));
|
|
|
|
+ addDynamicEntity.setDown(dynamicJo.getInteger("down"));
|
|
|
|
+ addDynamicEntity.setFlat(dynamicJo.getInteger("flat"));
|
|
|
|
+ prodIndicatorDynamicRepo.saveAndFlush(addDynamicEntity);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ //
|
|
|
|
+ private JSONArray getBeforeLastMonth(JSONArray psyJa, Map beforeMonthMap) {
|
|
|
|
+ String beforeMonth = beforeMonthMap.get("month").toString();
|
|
|
|
+ String beforeYear = beforeMonthMap.get("year").toString();
|
|
|
|
+ //查找前一个月的数据
|
|
|
|
+ ProdImportantIndicatorEntity findImportantEntity = new ProdImportantIndicatorEntity();
|
|
|
|
+ findImportantEntity.setYear(Integer.parseInt(beforeYear));
|
|
|
|
+ findImportantEntity.setMonth(Integer.parseInt(beforeMonth));
|
|
|
|
+ findImportantEntity.setStockType("psy");
|
|
|
|
+ Example<ProdImportantIndicatorEntity> delExample2 = Example.of(findImportantEntity);
|
|
|
|
+ List<ProdImportantIndicatorEntity> beforeImportantEntityList = prodImportantIndicatorRepo.findAll(delExample2);
|
|
|
|
+
|
|
|
|
+ JSONArray dynamicJa = new JSONArray();
|
|
|
|
+ int up = 0;
|
|
|
|
+ int down = 0;
|
|
|
|
+ int flat = 0;
|
|
|
|
+ for(int a=0;a<psyJa.size();a++){
|
|
|
|
+ JSONObject psyJo = psyJa.getJSONObject(a);
|
|
|
|
+ boolean isExist = false;
|
|
|
|
+ for(ProdImportantIndicatorEntity beforeImportantEntity:beforeImportantEntityList){
|
|
|
|
+ if(beforeImportantEntity.getFarmId().equals(psyJo.getInteger("farm_id"))){
|
|
|
|
+ isExist = true;
|
|
|
|
+ BigDecimal beforeQuantityBd = new BigDecimal(beforeImportantEntity.getStockQuantity());
|
|
|
|
+ BigDecimal quantityBd = new BigDecimal(psyJo.getString("stock_quantity"));
|
|
|
|
+ if(quantityBd.compareTo(beforeQuantityBd) == 0){
|
|
|
|
+ psyJo.put("rise_fall",1);
|
|
|
|
+ psyJo.put("range","0");
|
|
|
|
+ flat++;
|
|
|
|
+ }else if(quantityBd.compareTo(beforeQuantityBd) == 1){
|
|
|
|
+ psyJo.put("rise_fall",1);
|
|
|
|
+ psyJo.put("range",quantityBd.subtract(beforeQuantityBd));
|
|
|
|
+ up++;
|
|
|
|
+ }else{
|
|
|
|
+ psyJo.put("rise_fall",0);
|
|
|
|
+ psyJo.put("range",beforeQuantityBd.subtract(quantityBd));
|
|
|
|
+ down++;
|
|
|
|
+ }
|
|
|
|
+ break;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ if(!isExist){
|
|
|
|
+ psyJo.put("rise_fall",1);
|
|
|
|
+ psyJo.put("range",psyJo.getString("stock_quantity"));
|
|
|
|
+ up++;
|
|
|
|
+ }
|
|
|
|
+ JSONObject dynamicJo = new JSONObject();
|
|
|
|
+ dynamicJa.add(dynamicJo);
|
|
|
|
+ dynamicJo.put("total",up+down+flat);
|
|
|
|
+ dynamicJo.put("up",up);
|
|
|
|
+ dynamicJo.put("down",down);
|
|
|
|
+ dynamicJo.put("flat",flat);
|
|
|
|
+ dynamicJo.put("farm_id",psyJo.getIntValue("farm_id"));
|
|
}
|
|
}
|
|
|
|
+ return dynamicJa;
|
|
}
|
|
}
|
|
|
|
|
|
@Override
|
|
@Override
|