|
@@ -0,0 +1,118 @@
|
|
|
|
+package com.huimv.produce.produce.service.impl;
|
|
|
|
+
|
|
|
|
+import com.alibaba.fastjson.JSONArray;
|
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
|
+import com.huimv.common.utils.Result;
|
|
|
|
+import com.huimv.common.utils.ResultCode;
|
|
|
|
+import com.huimv.produce.produce.entity.ProdImportantIndicatorEntity;
|
|
|
|
+import com.huimv.produce.produce.entity.ProdIndicatorDynamicEntity;
|
|
|
|
+import com.huimv.produce.produce.repo.ProdImportantIndicatoRepo;
|
|
|
|
+import com.huimv.produce.produce.repo.ProdIndicatorDynamicRepo;
|
|
|
|
+import com.huimv.produce.produce.service.IImportantDynamicService;
|
|
|
|
+import com.huimv.produce.produce.utils.DateUtil;
|
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
+import org.springframework.data.domain.Example;
|
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
|
+
|
|
|
|
+import java.util.ArrayList;
|
|
|
|
+import java.util.List;
|
|
|
|
+
|
|
|
|
+/**
|
|
|
|
+ * @Project : huimv.shiwan
|
|
|
|
+ * @Package : com.huimv.biosafety.uface.controller
|
|
|
|
+ * @Description : TODO
|
|
|
|
+ * @Version : 1.0
|
|
|
|
+ * @Author : ZhuoNing
|
|
|
|
+ * @Create : 2020-12-25
|
|
|
|
+ **/
|
|
|
|
+@Service
|
|
|
|
+public class ImportantDynamicServiceImpl implements IImportantDynamicService {
|
|
|
|
+ @Autowired
|
|
|
|
+ private DateUtil dateUtil;
|
|
|
|
+ @Autowired
|
|
|
|
+ private ProdIndicatorDynamicRepo indicatorDynamicRepo;
|
|
|
|
+ @Autowired
|
|
|
|
+ private ProdImportantIndicatoRepo importantIndicatoRepo;
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public Result getImportantDynamicForIndex(Integer farmId) {
|
|
|
|
+ //以月为时间单位,进行统计。
|
|
|
|
+ String year = dateUtil.getThisYear();
|
|
|
|
+// String month = dateUtil.getThisMonth();
|
|
|
|
+ String month = "2";
|
|
|
|
+ System.out.println("year>>" + year);
|
|
|
|
+ System.out.println("month>>" + month);
|
|
|
|
+
|
|
|
|
+ //查询动态统计表
|
|
|
|
+ List<ProdIndicatorDynamicEntity> dynamicEntityList = getDynamicCount(farmId,year,month);
|
|
|
|
+
|
|
|
|
+ //查询一周数据
|
|
|
|
+ JSONArray importantJa = getOneWeekImportant(farmId,year,month);
|
|
|
|
+ System.out.println("11 importantJa.size>>" + importantJa.size());
|
|
|
|
+
|
|
|
|
+ JSONObject outJo = new JSONObject();
|
|
|
|
+ outJo.put("count", dynamicEntityList);
|
|
|
|
+ outJo.put("list", importantJa);
|
|
|
|
+
|
|
|
|
+ return new Result(ResultCode.SUCCESS, outJo);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ //查询重要指标一周统计
|
|
|
|
+ private JSONArray getOneWeekImportant(Integer farmId,String year,String month) {
|
|
|
|
+ JSONArray outJa = new JSONArray();
|
|
|
|
+ JSONArray titleJa = getTitle();
|
|
|
|
+
|
|
|
|
+ //查询重要指标详细数据
|
|
|
|
+ List<ProdImportantIndicatorEntity> importantList = importantIndicatoRepo.findAllByFarmIdAndStartAndEndDate(farmId, year, Integer.parseInt(month));
|
|
|
|
+ for (int a = 0; a < titleJa.size(); a++) {
|
|
|
|
+ JSONObject titleJo = titleJa.getJSONObject(a);
|
|
|
|
+ List timeList = new ArrayList();
|
|
|
|
+ List dataList = new ArrayList();
|
|
|
|
+ JSONObject newJo = new JSONObject();
|
|
|
|
+ outJa.add(newJo);
|
|
|
|
+ for (ProdImportantIndicatorEntity importantEntity : importantList) {
|
|
|
|
+ if (titleJo.getString("type").trim().equalsIgnoreCase(importantEntity.getStockType())) {
|
|
|
|
+ if (importantEntity.getYear() == Integer.parseInt(year) && importantEntity.getMonth() == Integer.parseInt(month)) {
|
|
|
|
+ newJo.put("titleNum", importantEntity.getStockQuantity());
|
|
|
|
+ if (importantEntity.getRiseFall() > 0) {
|
|
|
|
+ newJo.put("ifPositive", true);
|
|
|
|
+ newJo.put("subtitleNum", "+"+importantEntity.getRange1());
|
|
|
|
+ } else {
|
|
|
|
+ newJo.put("ifPositive", false);
|
|
|
|
+ newJo.put("subtitleNum", "-"+importantEntity.getRange1());
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ timeList.add(importantEntity.getMonth());
|
|
|
|
+ dataList.add(importantEntity.getStockQuantity());
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ JSONObject dataJo = new JSONObject();
|
|
|
|
+ dataJo.put("timeList",timeList);
|
|
|
|
+ dataJo.put("dataList",dataList);
|
|
|
|
+ newJo.put("data",dataJo);
|
|
|
|
+ }
|
|
|
|
+ return outJa;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private JSONArray getTitle() {
|
|
|
|
+ JSONArray titleJa = new JSONArray();
|
|
|
|
+ JSONObject psyJo = new JSONObject();
|
|
|
|
+ titleJa.add(psyJo);
|
|
|
|
+ psyJo.put("name", "PSY");
|
|
|
|
+ psyJo.put("type", "psy");
|
|
|
|
+ psyJo.put("comment", "");
|
|
|
|
+ return titleJa;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ //查询动态统计数据
|
|
|
|
+ private List<ProdIndicatorDynamicEntity> getDynamicCount(Integer farmId,String year,String month) {
|
|
|
|
+// String thisYear = dateUtil.getThisYear();
|
|
|
|
+// String thisMonth = dateUtil.getThisMonth();
|
|
|
|
+ ProdIndicatorDynamicEntity findDynamicEntity = new ProdIndicatorDynamicEntity();
|
|
|
|
+ findDynamicEntity.setFarmId(farmId);
|
|
|
|
+ findDynamicEntity.setYear(Integer.parseInt(year));
|
|
|
|
+ findDynamicEntity.setMonth(Integer.parseInt(month));
|
|
|
|
+ Example<ProdIndicatorDynamicEntity> findExample = Example.of(findDynamicEntity);
|
|
|
|
+ return indicatorDynamicRepo.findAll(findExample);
|
|
|
|
+ }
|
|
|
|
+}
|