Browse Source

投药报表,小时||天维度

Davidliu 2 days ago
parent
commit
f2333b8340

+ 62 - 0
src/main/java/com/xlht/xlhtproject/controller/TXlhtAddRecordController.java

@@ -0,0 +1,62 @@
+package com.xlht.xlhtproject.controller;
+
+import com.xlht.xlhtproject.domain.TXlhtAddRecord;
+import com.xlht.xlhtproject.respParse.bean.R;
+import com.xlht.xlhtproject.service.ITXlhtAddRecordService;
+import com.xlht.xlhtproject.utils.DateUtils;
+import com.xlht.xlhtproject.utils.StringUtils;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RequestParam;
+import org.springframework.web.bind.annotation.RestController;
+
+import java.util.Date;
+import java.util.List;
+
+/**
+ * 投药报表相关
+ */
+@RestController
+@RequestMapping("/business/addRecord")
+@Slf4j
+public class TXlhtAddRecordController extends BaseController{
+
+    @Autowired
+    private ITXlhtAddRecordService txlhtAddRecordService;
+
+    /**
+     *首页-小时维度投药聚合报表
+     * @return
+     */
+    @GetMapping("/hourList")
+    public R<List<TXlhtAddRecord>> hourList(@RequestParam(required = false, name = "timeBegin") String timeBegin, @RequestParam(required = false, name = "timeEnd") String timeEnd)
+    {
+        log.info("进入了 修改碳源投加 首页-报表信息 接口");
+        //2024年10月24日17:24:13 如果没有指定日期,那么这里给默认15天的数据
+        Date nowDate = DateUtils.getNowDate();
+        Date dayBefore14 = DateUtils.plusDate(-14, nowDate);
+        timeEnd = StringUtils.isBlank(timeEnd) ? DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD, nowDate) : timeEnd;
+        timeBegin = StringUtils.isBlank(timeBegin) ? DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD, dayBefore14) : timeBegin;
+        TXlhtAddRecord req = TXlhtAddRecord.builder().timeBegin(timeBegin).timeEnd(timeEnd).build();
+        return R.ok(this.txlhtAddRecordService.selectTXlhtAddRecordHourList(req));
+    }
+
+    /**
+     *首页-小时维度投药聚合报表
+     * @return
+     */
+    @GetMapping("/dayList")
+    public R<List<TXlhtAddRecord>> dayList(@RequestParam(required = false, name = "timeBegin") String timeBegin, @RequestParam(required = false, name = "timeEnd") String timeEnd)
+    {
+        log.info("进入了 修改碳源投加 首页-报表信息 接口");
+        //2024年10月24日17:24:13 如果没有指定日期,那么这里给默认15天的数据
+        Date nowDate = DateUtils.getNowDate();
+        Date dayBefore14 = DateUtils.plusDate(-14, nowDate);
+        timeEnd = StringUtils.isBlank(timeEnd) ? DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD, nowDate) : timeEnd;
+        timeBegin = StringUtils.isBlank(timeBegin) ? DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD, dayBefore14) : timeBegin;
+        TXlhtAddRecord req = TXlhtAddRecord.builder().timeBegin(timeBegin).timeEnd(timeEnd).build();
+        return R.ok(this.txlhtAddRecordService.selectTXlhtAddRecordDayList(req));
+    }
+}

+ 6 - 0
src/main/java/com/xlht/xlhtproject/domain/TXlhtAddRecord.java

@@ -38,6 +38,12 @@ public class TXlhtAddRecord extends BaseEntity
     /** 二池投药量 */
     private BigDecimal twoAmount;
 
+    /** 一池投药量 */
+    private BigDecimal instantOneAmount;
+
+    /** 二池投药量 */
+    private BigDecimal instantTwoAmount;
+
     /** 一池没设置下限投药量 */
     private BigDecimal tmpOneAmount;
 

+ 16 - 0
src/main/java/com/xlht/xlhtproject/mapper/TXlhtAddRecordMapper.java

@@ -28,6 +28,22 @@ public interface TXlhtAddRecordMapper
      */
     public List<TXlhtAddRecord> selectTXlhtAddRecordList(TXlhtAddRecord tXlhtAddRecord);
 
+    /**
+     * 查询锡林浩特投药记录小时级别列表
+     *
+     * @param tXlhtAddRecord 锡林浩特投药记录
+     * @return 锡林浩特投药记录集合
+     */
+    public List<TXlhtAddRecord> selectTXlhtAddRecordHourList(TXlhtAddRecord tXlhtAddRecord);
+
+    /**
+     * 查询锡林浩特投药记录天级别列表
+     *
+     * @param tXlhtAddRecord 锡林浩特投药记录
+     * @return 锡林浩特投药记录集合
+     */
+    public List<TXlhtAddRecord> selectTXlhtAddRecordDayList(TXlhtAddRecord tXlhtAddRecord);
+
     /**
      * 新增锡林浩特投药记录
      * 

+ 4 - 0
src/main/java/com/xlht/xlhtproject/service/ITXlhtAddRecordService.java

@@ -28,6 +28,10 @@ public interface ITXlhtAddRecordService
      */
     public List<TXlhtAddRecord> selectTXlhtAddRecordList(TXlhtAddRecord tXlhtAddRecord);
 
+    List<TXlhtAddRecord> selectTXlhtAddRecordHourList(TXlhtAddRecord tXlhtAddRecord);
+
+    List<TXlhtAddRecord> selectTXlhtAddRecordDayList(TXlhtAddRecord tXlhtAddRecord);
+
     /**
      * 新增锡林浩特投药记录
      * 

+ 24 - 0
src/main/java/com/xlht/xlhtproject/service/impl/TXlhtAddRecordServiceImpl.java

@@ -45,6 +45,30 @@ public class TXlhtAddRecordServiceImpl implements ITXlhtAddRecordService
         return tXlhtAddRecordMapper.selectTXlhtAddRecordList(tXlhtAddRecord);
     }
 
+    /**
+     * 查询锡林浩特投药记录小时级别列表
+     *
+     * @param tXlhtAddRecord 锡林浩特投药记录
+     * @return 锡林浩特投药记录
+     */
+    @Override
+    public List<TXlhtAddRecord> selectTXlhtAddRecordHourList(TXlhtAddRecord tXlhtAddRecord)
+    {
+        return tXlhtAddRecordMapper.selectTXlhtAddRecordHourList(tXlhtAddRecord);
+    }
+
+    /**
+     * 查询锡林浩特投药记录小时级别列表
+     *
+     * @param tXlhtAddRecord 锡林浩特投药记录
+     * @return 锡林浩特投药记录
+     */
+    @Override
+    public List<TXlhtAddRecord> selectTXlhtAddRecordDayList(TXlhtAddRecord tXlhtAddRecord)
+    {
+        return tXlhtAddRecordMapper.selectTXlhtAddRecordDayList(tXlhtAddRecord);
+    }
+
     /**
      * 新增锡林浩特投药记录
      * 

+ 92 - 0
src/main/resources/mapper/TXlhtAddRecordMapper.xml

@@ -8,6 +8,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
         <result property="id"    column="id"    />
         <result property="oneSystemAdd"    column="one_system_add"    />
         <result property="twoSystemAdd"    column="two_system_add"    />
+        <result property="instantOneAmount"    column="instant_one_amount"    />
+        <result property="instantTwoAmount"    column="instant_two_amount"    />
         <result property="oneAmount"    column="one_amount"    />
         <result property="twoAmount"    column="two_amount"    />
         <result property="tmpOneAmount"    column="tmp_one_amount"    />
@@ -137,4 +139,94 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
     <select id="getNAddRecords" resultMap="TXlhtAddRecordResult">
         select top ${counts} id, one_system_add, two_system_add, one_amount, two_amount, tmp_one_amount, tmp_two_amount, real_one_amount, real_two_amount, del_flag, revision, create_by, create_time, update_by, update_time, remark from t_xlht_add_record order by id desc
     </select>
+
+
+    <select id="selectTXlhtAddRecordHourList" parameterType="TXlhtAddRecord" resultMap="TXlhtAddRecordResult">
+        SELECT
+            rec_hour.hour_time AS create_time,
+            sec_hour.instant_one_amount,
+            sec_hour.instant_two_amount,
+            rec_hour.one_amount,
+            rec_hour.two_amount,
+            rec_hour.tmp_one_amount,
+            rec_hour.tmp_two_amount,
+            rec_hour.real_one_amount,
+            rec_hour.real_two_amount
+        FROM (
+                 SELECT
+                     DATEADD(HOUR, DATEDIFF(HOUR, 0, create_time), 0) AS hour_time,
+                     avg(one_amount) AS one_amount,
+                     avg(two_amount) AS two_amount,
+                     avg(tmp_one_amount) AS tmp_one_amount,
+                     avg(tmp_two_amount) AS tmp_two_amount,
+                     avg(real_one_amount) AS real_one_amount,
+                     avg(real_two_amount) AS real_two_amount
+                 FROM t_xlht_add_record
+                <where>
+                1 = 1
+                <if test="timeBegin != null  and timeBegin != ''"> and create_time &gt;= #{timeBegin}</if>
+                <if test="timeEnd != null  and timeEnd != ''"> and create_time &lt;= #{timeEnd}</if>
+                </where>
+                 GROUP BY DATEADD(HOUR, DATEDIFF(HOUR, 0, create_time), 0)
+             ) AS rec_hour
+                 LEFT JOIN (
+            SELECT
+                DATEADD(HOUR, DATEDIFF(HOUR, 0, create_time), 0) AS hour_time,
+                AVG(one_amount) AS instant_one_amount,
+                AVG(two_amount) AS instant_two_amount
+            FROM t_xlht_add_record_sec
+            <where>
+                1 = 1
+                <if test="timeBegin != null  and timeBegin != ''"> and create_time &gt;= #{timeBegin}</if>
+                <if test="timeEnd != null  and timeEnd != ''"> and create_time &lt;= #{timeEnd}</if>
+            </where>
+            GROUP BY DATEADD(HOUR, DATEDIFF(HOUR, 0, create_time), 0)
+        ) AS sec_hour
+        ON sec_hour.hour_time = rec_hour.hour_time
+        order by rec_hour.hour_time desc
+    </select>
+    <select id="selectTXlhtAddRecordDayList" parameterType="TXlhtAddRecord" resultMap="TXlhtAddRecordResult">
+        SELECT
+        rec_day.day_time AS create_time,
+        sec_day.instant_one_amount,
+        sec_day.instant_two_amount,
+        rec_day.one_amount,
+        rec_day.two_amount,
+        rec_day.tmp_one_amount,
+        rec_day.tmp_two_amount,
+        rec_day.real_one_amount,
+        rec_day.real_two_amount
+        FROM (
+        SELECT
+        CAST(create_time AS DATE) AS day_time,
+        avg(one_amount) AS one_amount,
+        avg(two_amount) AS two_amount,
+        avg(tmp_one_amount) AS tmp_one_amount,
+        avg(tmp_two_amount) AS tmp_two_amount,
+        avg(real_one_amount) AS real_one_amount,
+        avg(real_two_amount) AS real_two_amount
+        FROM t_xlht_add_record
+        <where>
+            1 = 1
+            <if test="timeBegin != null  and timeBegin != ''"> and create_time &gt;= #{timeBegin}</if>
+            <if test="timeEnd != null  and timeEnd != ''"> and create_time &lt;= #{timeEnd}</if>
+        </where>
+        GROUP BY CAST(create_time AS DATE)
+        ) AS rec_day
+        LEFT JOIN (
+        SELECT
+        CAST(create_time AS DATE) AS day_time,
+        AVG(one_amount) AS instant_one_amount,
+        AVG(two_amount) AS instant_two_amount
+        FROM t_xlht_add_record_sec
+        <where>
+            1 = 1
+            <if test="timeBegin != null  and timeBegin != ''"> and create_time &gt;= #{timeBegin}</if>
+            <if test="timeEnd != null  and timeEnd != ''"> and create_time &lt;= #{timeEnd}</if>
+        </where>
+        GROUP BY CAST(create_time AS DATE)
+        ) AS sec_day
+        ON sec_day.day_time = rec_day.day_time
+        order by rec_day.day_time desc;
+    </select>
 </mapper>