瀏覽代碼

(大屏)新建重要指标的读取功能。

zhuoning 3 年之前
父節點
當前提交
d6833a96ad

+ 31 - 0
huimv-farm-produce/src/main/java/com/huimv/produce/produce/controller/ImportantDynamicController.java

@@ -0,0 +1,31 @@
+package com.huimv.produce.produce.controller;
+
+import com.huimv.common.utils.Result;
+import com.huimv.common.utils.ResultCode;
+import com.huimv.produce.produce.service.IImportantDynamicService;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RequestMethod;
+import org.springframework.web.bind.annotation.RequestParam;
+import org.springframework.web.bind.annotation.RestController;
+
+/**
+ * @Project : huimv.shiwan
+ * @Package : com.huimv.biosafety.uface.controller
+ * @Description : TODO
+ * @Version : 1.0
+ * @Author : ZhuoNing
+ * @Create : 2020-12-25
+ **/
+@RestController
+@RequestMapping(value = "/importantDynamic")
+public class ImportantDynamicController {
+    @Autowired
+    private IImportantDynamicService importantDynamicService;
+
+    @RequestMapping(value = "/getDynamicData",method = RequestMethod.GET)
+    public Result getDynamicData(@RequestParam(value = "farmId",required = true) Integer farmId){
+        //
+        return importantDynamicService.getImportantDynamicForIndex(farmId);
+    }
+}

+ 241 - 0
huimv-farm-produce/src/main/java/com/huimv/produce/produce/entity/ProdImportantIndicatorEntity.java

@@ -0,0 +1,241 @@
+package com.huimv.produce.produce.entity;
+
+import javax.persistence.*;
+import java.io.Serializable;
+
+@Entity
+@Table(name = "prod_important_indicator")
+public class ProdImportantIndicatorEntity implements Serializable {
+
+    private static final long serialVersionUID = 1L;
+
+    @Id
+    @GeneratedValue(strategy = GenerationType.IDENTITY)
+    @Column(name = "id", nullable = false)
+    private Integer id;
+
+    /**
+     * 存栏类型
+     */
+    @Column(name = "stock_type")
+    private String stockType;
+
+    /**
+     * 存栏名称
+     */
+    @Column(name = "stock_name")
+    private String stockName;
+
+    /**
+     * 存栏数量
+     */
+    @Column(name = "stock_quantity")
+    private String stockQuantity;
+
+    /**
+     * 占比
+     */
+    @Column(name = "rate")
+    private Float rate;
+
+    /**
+     * 月份
+     */
+    @Column(name = "month")
+    private Integer month;
+
+    /**
+     * 年份
+     */
+    @Column(name = "year")
+    private Integer year;
+
+    /**
+     * 牧场id
+     */
+    @Column(name = "farm_id")
+    private Integer farmId;
+
+    /**
+     * 分区id
+     */
+    @Column(name = "subarea_id")
+    private Integer subareaId;
+
+    /**
+     * 涨跌状态(1:上涨 0:下跌)
+     */
+    @Column(name = "rise_fall")
+    private Integer riseFall;
+
+    /**
+     * 涨跌幅度
+     */
+    @Column(name = "range1")
+    private String range1;
+
+    public void setId(Integer id) {
+        this.id = id;
+    }
+
+    public Integer getId() {
+        return id;
+    }
+
+    /**
+     * 存栏类型
+     */
+    public void setStockType(String stockType) {
+        this.stockType = stockType;
+    }
+
+    /**
+     * 存栏类型
+     */
+    public String getStockType() {
+        return stockType;
+    }
+
+    /**
+     * 存栏名称
+     */
+    public void setStockName(String stockName) {
+        this.stockName = stockName;
+    }
+
+    /**
+     * 存栏名称
+     */
+    public String getStockName() {
+        return stockName;
+    }
+
+    /**
+     * 存栏数量
+     */
+    public void setStockQuantity(String stockQuantity) {
+        this.stockQuantity = stockQuantity;
+    }
+
+    /**
+     * 存栏数量
+     */
+    public String getStockQuantity() {
+        return stockQuantity;
+    }
+
+    /**
+     * 占比
+     */
+    public void setRate(Float rate) {
+        this.rate = rate;
+    }
+
+    /**
+     * 占比
+     */
+    public Float getRate() {
+        return rate;
+    }
+
+    /**
+     * 月份
+     */
+    public void setMonth(Integer month) {
+        this.month = month;
+    }
+
+    /**
+     * 月份
+     */
+    public Integer getMonth() {
+        return month;
+    }
+
+    /**
+     * 年份
+     */
+    public void setYear(Integer year) {
+        this.year = year;
+    }
+
+    /**
+     * 年份
+     */
+    public Integer getYear() {
+        return year;
+    }
+
+    /**
+     * 牧场id
+     */
+    public void setFarmId(Integer farmId) {
+        this.farmId = farmId;
+    }
+
+    /**
+     * 牧场id
+     */
+    public Integer getFarmId() {
+        return farmId;
+    }
+
+    /**
+     * 分区id
+     */
+    public void setSubareaId(Integer subareaId) {
+        this.subareaId = subareaId;
+    }
+
+    /**
+     * 分区id
+     */
+    public Integer getSubareaId() {
+        return subareaId;
+    }
+
+    /**
+     * 涨跌状态(1:上涨 0:下跌)
+     */
+    public void setRiseFall(Integer riseFall) {
+        this.riseFall = riseFall;
+    }
+
+    /**
+     * 涨跌状态(1:上涨 0:下跌)
+     */
+    public Integer getRiseFall() {
+        return riseFall;
+    }
+
+    /**
+     * 涨跌幅度
+     */
+    public void setRange1(String range1) {
+        this.range1 = range1;
+    }
+
+    /**
+     * 涨跌幅度
+     */
+    public String getRange1() {
+        return range1;
+    }
+
+    @Override
+    public String toString() {
+        return "ProdImportantIndicatorEntity{" +
+                "id=" + id + '\'' +
+                "stockType=" + stockType + '\'' +
+                "stockName=" + stockName + '\'' +
+                "stockQuantity=" + stockQuantity + '\'' +
+                "rate=" + rate + '\'' +
+                "month=" + month + '\'' +
+                "year=" + year + '\'' +
+                "farmId=" + farmId + '\'' +
+                "subareaId=" + subareaId + '\'' +
+                "riseFall=" + riseFall + '\'' +
+                "range1=" + range1 + '\'' +
+                '}';
+    }
+}

+ 115 - 0
huimv-farm-produce/src/main/java/com/huimv/produce/produce/entity/ProdIndicatorDynamicEntity.java

@@ -0,0 +1,115 @@
+package com.huimv.produce.produce.entity;
+
+import javax.persistence.*;
+import java.io.Serializable;
+
+@Entity
+@Table(name = "prod_indicator_dynamic")
+public class ProdIndicatorDynamicEntity implements Serializable {
+
+    private static final long serialVersionUID = 1L;
+
+    @Id
+    @GeneratedValue(strategy = GenerationType.IDENTITY)
+    @Column(name = "id", nullable = false)
+    private Integer id;
+
+    @Column(name = "total")
+    private Integer total;
+
+    @Column(name = "up")
+    private Integer up;
+
+    @Column(name = "down")
+    private Integer down;
+
+    @Column(name = "flat")
+    private Integer flat;
+
+    @Column(name = "farm_id")
+    private Integer farmId;
+
+    @Column(name = "year")
+    private Integer year;
+
+    @Column(name = "month")
+    private Integer month;
+
+    public void setId(Integer id) {
+        this.id = id;
+    }
+
+    public Integer getId() {
+        return id;
+    }
+
+    public void setTotal(Integer total) {
+        this.total = total;
+    }
+
+    public Integer getTotal() {
+        return total;
+    }
+
+    public void setUp(Integer up) {
+        this.up = up;
+    }
+
+    public Integer getUp() {
+        return up;
+    }
+
+    public void setDown(Integer down) {
+        this.down = down;
+    }
+
+    public Integer getDown() {
+        return down;
+    }
+
+    public void setFlat(Integer flat) {
+        this.flat = flat;
+    }
+
+    public Integer getFlat() {
+        return flat;
+    }
+
+    public void setFarmId(Integer farmId) {
+        this.farmId = farmId;
+    }
+
+    public Integer getFarmId() {
+        return farmId;
+    }
+
+    public void setYear(Integer year) {
+        this.year = year;
+    }
+
+    public Integer getYear() {
+        return year;
+    }
+
+    public void setMonth(Integer month) {
+        this.month = month;
+    }
+
+    public Integer getMonth() {
+        return month;
+    }
+
+    @Override
+    public String toString() {
+        return "ProdIndicatorDynamicEntity{" +
+                "id=" + id + '\'' +
+                "total=" + total + '\'' +
+                "up=" + up + '\'' +
+                "down=" + down + '\'' +
+                "flat=" + flat + '\'' +
+                "farmId=" + farmId + '\'' +
+                "year=" + year + '\'' +
+                "month=" + month + '\'' +
+                '}';
+    }
+}

+ 15 - 0
huimv-farm-produce/src/main/java/com/huimv/produce/produce/repo/ProdImportantIndicatoRepo.java

@@ -0,0 +1,15 @@
+package com.huimv.produce.produce.repo;
+
+import com.huimv.produce.produce.entity.ProdImportantIndicatorEntity;
+import org.springframework.data.jpa.repository.JpaRepository;
+import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
+import org.springframework.data.jpa.repository.Query;
+
+import java.util.List;
+
+public interface ProdImportantIndicatoRepo extends JpaRepository<ProdImportantIndicatorEntity, Integer>, JpaSpecificationExecutor<ProdImportantIndicatorEntity> {
+
+    //
+    @Query(nativeQuery = true,value = "SELECT * FROM prod_important_indicator WHERE farm_id=?1 AND year=?2 AND month between 1 AND ?3 ORDER BY month ASC")
+    List<ProdImportantIndicatorEntity> findAllByFarmIdAndStartAndEndDate(Integer farmId, String year, Integer month);
+}

+ 9 - 0
huimv-farm-produce/src/main/java/com/huimv/produce/produce/repo/ProdIndicatorDynamicRepo.java

@@ -0,0 +1,9 @@
+package com.huimv.produce.produce.repo;
+
+import com.huimv.produce.produce.entity.ProdIndicatorDynamicEntity;
+import org.springframework.data.jpa.repository.JpaRepository;
+import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
+
+public interface ProdIndicatorDynamicRepo extends JpaRepository<ProdIndicatorDynamicEntity, Integer>, JpaSpecificationExecutor<ProdIndicatorDynamicEntity> {
+
+}

+ 8 - 0
huimv-farm-produce/src/main/java/com/huimv/produce/produce/service/IImportantDynamicService.java

@@ -0,0 +1,8 @@
+package com.huimv.produce.produce.service;
+
+import com.huimv.common.utils.Result;
+
+public interface IImportantDynamicService {
+    //
+    Result getImportantDynamicForIndex(Integer farmId);
+}

+ 118 - 0
huimv-farm-produce/src/main/java/com/huimv/produce/produce/service/impl/ImportantDynamicServiceImpl.java

@@ -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);
+    }
+}