Browse Source

修改查询折线图接口

logistics
ma 4 years ago
parent
commit
68e4a92146
  1. 2
      logistics/src/main/java/com/ccsens/logistics/Netty/NettyClient.java
  2. 9
      logistics/src/main/java/com/ccsens/logistics/persist/dao/LogisticsCarRecordDao.java
  3. 26
      logistics/src/main/java/com/ccsens/logistics/service/MbpsService.java
  4. 230
      logistics/src/main/resources/mapper_dao/LogisticsCarRecordDao.xml

2
logistics/src/main/java/com/ccsens/logistics/Netty/NettyClient.java

@ -70,7 +70,7 @@ public class NettyClient {
ScheduledExecutorService service = Executors ScheduledExecutorService service = Executors
.newSingleThreadScheduledExecutor(); .newSingleThreadScheduledExecutor();
// 第二个参数为首次执行的延时时间,第三个参数为定时执行的间隔时间 // 第二个参数为首次执行的延时时间,第三个参数为定时执行的间隔时间
service.scheduleAtFixedRate(runnable, 2, 5, TimeUnit.SECONDS); service.scheduleAtFixedRate(runnable, 2, 30, TimeUnit.SECONDS);
// 创建并执行在给定延迟后启用的 ScheduledFuture。 // 创建并执行在给定延迟后启用的 ScheduledFuture。
// 参数: // 参数:
// callable - 要执行的功能 // callable - 要执行的功能

9
logistics/src/main/java/com/ccsens/logistics/persist/dao/LogisticsCarRecordDao.java

@ -2,6 +2,7 @@ package com.ccsens.logistics.persist.dao;
import com.ccsens.logistics.bean.vo.MbpsVo; import com.ccsens.logistics.bean.vo.MbpsVo;
import com.ccsens.logistics.persist.mapper.LogisticsCarRecordMapper; import com.ccsens.logistics.persist.mapper.LogisticsCarRecordMapper;
import io.swagger.models.auth.In;
import org.apache.ibatis.annotations.Param; import org.apache.ibatis.annotations.Param;
import org.springframework.stereotype.Repository; import org.springframework.stereotype.Repository;
@ -49,7 +50,7 @@ public interface LogisticsCarRecordDao extends LogisticsCarRecordMapper {
* @param endTime 结束时间 * @param endTime 结束时间
* @return 该时间车辆吞进量 * @return 该时间车辆吞进量
*/ */
List<MbpsVo.CarOfInByTime> selCarOfInByTime(@Param("queryType") Byte queryType,@Param("startTime") Long startTime,@Param("endTime") Long endTime); List<MbpsVo.CarOfInByTime> selCarOfInByTime(@Param("queryType") Byte queryType, @Param("startTime") Long startTime, @Param("endTime") Long endTime,@Param("countArr") String[] countArr,@Param("nowDate") String nowDate);
/** /**
* 根据时间查询车辆吐出量 * 根据时间查询车辆吐出量
@ -58,7 +59,7 @@ public interface LogisticsCarRecordDao extends LogisticsCarRecordMapper {
* @param endTime 结束时间 * @param endTime 结束时间
* @return 该时间车辆吐出量 * @return 该时间车辆吐出量
*/ */
List<MbpsVo.CarOfOutByTime> selCarOfOutByTime(@Param("queryType") Byte queryType,@Param("startTime") Long startTime,@Param("endTime") Long endTime); List<MbpsVo.CarOfOutByTime> selCarOfOutByTime(@Param("queryType") Byte queryType,@Param("startTime") Long startTime,@Param("endTime") Long endTime,@Param("countArr") String[] countArr,@Param("nowDate") String nowDate);
/** /**
* 根据时间查询入货量 * 根据时间查询入货量
@ -67,7 +68,7 @@ public interface LogisticsCarRecordDao extends LogisticsCarRecordMapper {
* @param endTime 结束时间 * @param endTime 结束时间
* @return 该时间入货量 * @return 该时间入货量
*/ */
List<MbpsVo.WeightOfInByTime> selWeightOfInByTime(@Param("queryType") Byte queryType,@Param("startTime") Long startTime,@Param("endTime") Long endTime); List<MbpsVo.WeightOfInByTime> selWeightOfInByTime(@Param("queryType") Byte queryType,@Param("startTime") Long startTime,@Param("endTime") Long endTime,@Param("countArr") String[] countArr,@Param("nowDate") String nowDate);
/** /**
* 根据时间查询出货量 * 根据时间查询出货量
@ -76,5 +77,5 @@ public interface LogisticsCarRecordDao extends LogisticsCarRecordMapper {
* @param endTime 结束时间 * @param endTime 结束时间
* @return 该时间车辆出货量 * @return 该时间车辆出货量
*/ */
List<MbpsVo.WeightOfOutByTime> selWeightOfOutByTime(@Param("queryType") Byte queryType,@Param("startTime") Long startTime,@Param("endTime") Long endTime); List<MbpsVo.WeightOfOutByTime> selWeightOfOutByTime(@Param("queryType") Byte queryType,@Param("startTime") Long startTime,@Param("endTime") Long endTime,@Param("countArr") String[] countArr,@Param("nowDate") String nowDate);
} }

26
logistics/src/main/java/com/ccsens/logistics/service/MbpsService.java

@ -16,6 +16,8 @@ import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import javax.annotation.Resource; import javax.annotation.Resource;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List; import java.util.List;
/** /**
@ -55,18 +57,34 @@ public class MbpsService implements IMbpsService {
@Override @Override
public MbpsVo.SelMbpsByTime selMbpsByTime(MbpsDto.SelMbpsByTime param) { public MbpsVo.SelMbpsByTime selMbpsByTime(MbpsDto.SelMbpsByTime param) {
String[] countArr = new String[10];
//查找当前时间
Date date = new Date();
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
String nowDate = format.format(date);
MbpsVo.SelMbpsByTime selMbpsByTime = new MbpsVo.SelMbpsByTime(); MbpsVo.SelMbpsByTime selMbpsByTime = new MbpsVo.SelMbpsByTime();
//查询吞进量 //查询吞进量
List<MbpsVo.CarOfInByTime> carOfInByTimeList = carRecordDao.selCarOfInByTime(param.getQueryType(),param.getStartTime(),param.getEndTime()); List<MbpsVo.CarOfInByTime> carOfInByTimeList = carRecordDao.selCarOfInByTime(param.getQueryType(),param.getStartTime(),param.getEndTime(),countArr,nowDate);
selMbpsByTime.getCarOfInsByTime().addAll(carOfInByTimeList); selMbpsByTime.getCarOfInsByTime().addAll(carOfInByTimeList);
//查询吐出量 //查询吐出量
List<MbpsVo.CarOfOutByTime> carOfOutByTimeList = carRecordDao.selCarOfOutByTime(param.getQueryType(),param.getStartTime(),param.getEndTime()); List<MbpsVo.CarOfOutByTime> carOfOutByTimeList = carRecordDao.selCarOfOutByTime(param.getQueryType(),param.getStartTime(),param.getEndTime(),countArr,nowDate);
selMbpsByTime.getCarOfOutsByTime().addAll(carOfOutByTimeList); selMbpsByTime.getCarOfOutsByTime().addAll(carOfOutByTimeList);
//查询入库吨数 //查询入库吨数
List<MbpsVo.WeightOfInByTime> weightOfInByTimeList = carRecordDao.selWeightOfInByTime(param.getQueryType(),param.getStartTime(),param.getEndTime()); List<MbpsVo.WeightOfInByTime> weightOfInByTimeList = carRecordDao.selWeightOfInByTime(param.getQueryType(),param.getStartTime(),param.getEndTime(),countArr,nowDate);
for (MbpsVo.WeightOfInByTime weightOfInByTime : weightOfInByTimeList) {
if (ObjectUtil.isNull(weightOfInByTime.getWeightOfIn())){
weightOfInByTime.setWeightOfIn(0L);
}
}
selMbpsByTime.getWeightOfInsByTime().addAll(weightOfInByTimeList); selMbpsByTime.getWeightOfInsByTime().addAll(weightOfInByTimeList);
//查询出货吨数 //查询出货吨数
List<MbpsVo.WeightOfOutByTime> weightOfOutByTimeList =carRecordDao.selWeightOfOutByTime(param.getQueryType(),param.getStartTime(),param.getEndTime()); List<MbpsVo.WeightOfOutByTime> weightOfOutByTimeList =carRecordDao.selWeightOfOutByTime(param.getQueryType(),param.getStartTime(),param.getEndTime(),countArr,nowDate);
for (MbpsVo.WeightOfOutByTime weightOfOutByTime : weightOfOutByTimeList) {
if (ObjectUtil.isNull(weightOfOutByTime.getWeightOfOut())){
weightOfOutByTime.setWeightOfOut(0L);
}
}
selMbpsByTime.getWeightOfOutsByTime().addAll(weightOfOutByTimeList); selMbpsByTime.getWeightOfOutsByTime().addAll(weightOfOutByTimeList);
return selMbpsByTime; return selMbpsByTime;
} }

230
logistics/src/main/resources/mapper_dao/LogisticsCarRecordDao.xml

@ -32,110 +32,166 @@
<select id="selCarOfInByTime" resultType="com.ccsens.logistics.bean.vo.MbpsVo$CarOfInByTime"> <select id="selCarOfInByTime" resultType="com.ccsens.logistics.bean.vo.MbpsVo$CarOfInByTime">
SELECT SELECT
FROM_UNIXTIME(cr.record_time/1000, '%Y-%m-%d') AS time, s.date AS time,
COUNT(cr.id) AS carOfIn COUNT(cr.id) AS carOfIn
FROM FROM
t_logistics_car_record AS cr (SELECT
WHERE <if test="queryType==0">
cr.in_out = 0 AND cr.rec_status = 0 date_add( #{nowDate}, INTERVAL @i := @i - 1 DAY ) AS date
AND cr.record_time BETWEEN #{startTime} AND #{endTime} </if>
<if test="queryType==0"> <if test="queryType==1">
GROUP BY DATE_FORMAT((date_add(#{nowDate},interval @i:=@i-1 week)),'%Y-%u') as date
DAY(FROM_UNIXTIME(cr.record_time/1000, '%Y-%m-%d')); </if>
</if> <if test="queryType==2">
<if test="queryType==1"> DATE_FORMAT((date_add(#{nowDate},interval @i:=@i-1 month)),'%Y-%m') as date
GROUP BY </if>
WEEK(FROM_UNIXTIME(cr.record_time/1000, '%Y-%m-%d')); <if test="queryType==3">
</if> DATE_FORMAT((date_add(#{nowDate},interval @i:=@i-1 year)),'%Y') as date
<if test="queryType==2"> </if>
GROUP BY FROM
MONTH(FROM_UNIXTIME(cr.record_time/1000, '%Y-%m-%d')); (
</if> SELECT 1
<if test="queryType==3"> <foreach item="index" collection="countArr">
GROUP BY union all select 1
YEAR(FROM_UNIXTIME(cr.record_time/1000, '%Y-%m-%d')); </foreach>
</if> ) AS tmp,
( SELECT @i := + 1 ) t ) AS s LEFT JOIN t_logistics_car_record AS cr ON
<if test="queryType==0">
FROM_UNIXTIME( cr.record_time / 1000, '%Y-%m-%d' ) = s.date AND cr.in_out = 0 AND cr.rec_status = 0
</if>
<if test="queryType==1">
FROM_UNIXTIME(cr.record_time/1000,'%Y-%u') = s.date AND cr.in_out = 0 AND cr.rec_status =0
</if>
<if test="queryType==2">
FROM_UNIXTIME(cr.record_time/1000,'%Y-%m') = s.date AND cr.in_out = 0 AND cr.rec_status =0
</if>
<if test="queryType==3">
FROM_UNIXTIME(cr.record_time/1000,'%Y') = s.date AND cr.in_out = 0 AND cr.rec_status =0
</if>
GROUP BY s.date ORDER BY s.date DESC
</select> </select>
<select id="selCarOfOutByTime" resultType="com.ccsens.logistics.bean.vo.MbpsVo$CarOfOutByTime"> <select id="selCarOfOutByTime" resultType="com.ccsens.logistics.bean.vo.MbpsVo$CarOfOutByTime">
SELECT SELECT
FROM_UNIXTIME(cr.record_time/1000, '%Y-%m-%d') AS time, s.date AS time,
COUNT(cr.id) AS carOfOut COUNT(cr.id) AS carOfOut
FROM FROM
t_logistics_car_record AS cr (SELECT
WHERE <if test="queryType==0">
cr.in_out = 1 AND cr.rec_status = 0 date_add( #{nowDate}, INTERVAL @i := @i - 1 DAY ) AS date
AND cr.record_time BETWEEN #{startTime} AND #{endTime} </if>
<if test="queryType==0"> <if test="queryType==1">
GROUP BY DATE_FORMAT((date_add(#{nowDate},interval @i:=@i-1 week)),'%Y-%u') as date
DAY(FROM_UNIXTIME(cr.record_time/1000, '%Y-%m-%d')); </if>
</if> <if test="queryType==2">
<if test="queryType==1"> DATE_FORMAT((date_add(#{nowDate},interval @i:=@i-1 month)),'%Y-%m') as date
GROUP BY </if>
WEEK(FROM_UNIXTIME(cr.record_time/1000, '%Y-%m-%d')); <if test="queryType==3">
</if> DATE_FORMAT((date_add(#{nowDate},interval @i:=@i-1 year)),'%Y') as date
<if test="queryType==2"> </if>
GROUP BY FROM
MONTH(FROM_UNIXTIME(cr.record_time/1000, '%Y-%m-%d')); (
</if> SELECT 1
<if test="queryType==3"> <foreach item="index" collection="countArr">
GROUP BY union all select 1
YEAR(FROM_UNIXTIME(cr.record_time/1000, '%Y-%m-%d')); </foreach>
</if> ) AS tmp,
( SELECT @i := + 1 ) t ) AS s LEFT JOIN t_logistics_car_record AS cr ON
<if test="queryType==0">
FROM_UNIXTIME( cr.record_time / 1000, '%Y-%m-%d' ) = s.date AND cr.in_out = 1 AND cr.rec_status = 0
</if>
<if test="queryType==1">
FROM_UNIXTIME(cr.record_time/1000,'%Y-%u') = s.date AND cr.in_out = 1 AND cr.rec_status =0
</if>
<if test="queryType==2">
FROM_UNIXTIME(cr.record_time/1000,'%Y-%m') = s.date AND cr.in_out = 1 AND cr.rec_status =0
</if>
<if test="queryType==3">
FROM_UNIXTIME(cr.record_time/1000,'%Y') = s.date AND cr.in_out = 1 AND cr.rec_status =0
</if>
GROUP BY s.date ORDER BY s.date DESC
</select> </select>
<select id="selWeightOfInByTime" resultType="com.ccsens.logistics.bean.vo.MbpsVo$WeightOfInByTime"> <select id="selWeightOfInByTime" resultType="com.ccsens.logistics.bean.vo.MbpsVo$WeightOfInByTime">
SELECT SELECT
FROM_UNIXTIME(cr.record_time/1000, '%Y-%m-%d') AS time, s.date AS time,
SUM(cr.car_weight) AS weightOfIn SUM(cr.car_weight) AS weightOfIn
FROM FROM
t_logistics_car_record AS cr (SELECT
WHERE <if test="queryType==0">
cr.in_out = 0 AND cr.rec_status = 0 date_add( #{nowDate}, INTERVAL @i := @i - 1 DAY ) AS date
AND cr.record_time BETWEEN #{startTime} AND #{endTime} </if>
<if test="queryType==0"> <if test="queryType==1">
GROUP BY DATE_FORMAT((date_add(#{nowDate},interval @i:=@i-1 week)),'%Y-%u') as date
DAY(FROM_UNIXTIME(cr.record_time/1000, '%Y-%m-%d')); </if>
</if> <if test="queryType==2">
<if test="queryType==1"> DATE_FORMAT((date_add(#{nowDate},interval @i:=@i-1 month)),'%Y-%m') as date
GROUP BY </if>
WEEK(FROM_UNIXTIME(cr.record_time/1000, '%Y-%m-%d')); <if test="queryType==3">
</if> DATE_FORMAT((date_add(#{nowDate},interval @i:=@i-1 year)),'%Y') as date
<if test="queryType==2"> </if>
GROUP BY FROM
MONTH(FROM_UNIXTIME(cr.record_time/1000, '%Y-%m-%d')); (
</if> SELECT 1
<if test="queryType==3"> <foreach item="index" collection="countArr">
GROUP BY union all select 1
YEAR(FROM_UNIXTIME(cr.record_time/1000, '%Y-%m-%d')); </foreach>
</if> ) AS tmp,
( SELECT @i := + 1 ) t ) AS s LEFT JOIN t_logistics_car_record AS cr ON
<if test="queryType==0">
FROM_UNIXTIME( cr.record_time / 1000, '%Y-%m-%d' ) = s.date AND cr.in_out = 0 AND cr.rec_status = 0
</if>
<if test="queryType==1">
FROM_UNIXTIME(cr.record_time/1000,'%Y-%u') = s.date AND cr.in_out = 0 AND cr.rec_status =0
</if>
<if test="queryType==2">
FROM_UNIXTIME(cr.record_time/1000,'%Y-%m') = s.date AND cr.in_out = 0 AND cr.rec_status =0
</if>
<if test="queryType==3">
FROM_UNIXTIME(cr.record_time/1000,'%Y') = s.date AND cr.in_out = 0 AND cr.rec_status =0
</if>
GROUP BY s.date ORDER BY s.date DESC
</select> </select>
<select id="selWeightOfOutByTime" resultType="com.ccsens.logistics.bean.vo.MbpsVo$WeightOfOutByTime"> <select id="selWeightOfOutByTime" resultType="com.ccsens.logistics.bean.vo.MbpsVo$WeightOfOutByTime">
SELECT SELECT
FROM_UNIXTIME(cr.record_time/1000, '%Y-%m-%d') AS time, s.date AS time,
SUM(cr.car_weight) AS weightOfOut SUM(cr.car_weight) AS weightOfOut
FROM FROM
t_logistics_car_record AS cr (SELECT
WHERE <if test="queryType==0">
cr.in_out = 1 AND cr.rec_status = 0 date_add( #{nowDate}, INTERVAL @i := @i - 1 DAY ) AS date
AND cr.record_time BETWEEN #{startTime} AND #{endTime} </if>
<if test="queryType==0"> <if test="queryType==1">
GROUP BY DATE_FORMAT((date_add(#{nowDate},interval @i:=@i-1 week)),'%Y-%u') as date
DAY(FROM_UNIXTIME(cr.record_time/1000, '%Y-%m-%d')); </if>
</if> <if test="queryType==2">
<if test="queryType==1"> DATE_FORMAT((date_add(#{nowDate},interval @i:=@i-1 month)),'%Y-%m') as date
GROUP BY </if>
WEEK(FROM_UNIXTIME(cr.record_time/1000, '%Y-%m-%d')); <if test="queryType==3">
</if> DATE_FORMAT((date_add(#{nowDate},interval @i:=@i-1 year)),'%Y') as date
<if test="queryType==2"> </if>
GROUP BY FROM
MONTH(FROM_UNIXTIME(cr.record_time/1000, '%Y-%m-%d')); (
</if> SELECT 1
<if test="queryType==3"> <foreach item="index" collection="countArr">
GROUP BY union all select 1
YEAR(FROM_UNIXTIME(cr.record_time/1000, '%Y-%m-%d')); </foreach>
</if> ) AS tmp,
( SELECT @i := + 1 ) t ) AS s LEFT JOIN t_logistics_car_record AS cr ON
<if test="queryType==0">
FROM_UNIXTIME( cr.record_time / 1000, '%Y-%m-%d' ) = s.date AND cr.in_out = 1 AND cr.rec_status = 0
</if>
<if test="queryType==1">
FROM_UNIXTIME(cr.record_time/1000,'%Y-%u') = s.date AND cr.in_out = 1 AND cr.rec_status =0
</if>
<if test="queryType==2">
FROM_UNIXTIME(cr.record_time/1000,'%Y-%m') = s.date AND cr.in_out = 1 AND cr.rec_status =0
</if>
<if test="queryType==3">
FROM_UNIXTIME(cr.record_time/1000,'%Y') = s.date AND cr.in_out = 1 AND cr.rec_status =0
</if>
GROUP BY s.date ORDER BY s.date DESC
</select> </select>
</mapper> </mapper>
Loading…
Cancel
Save