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
.newSingleThreadScheduledExecutor();
// 第二个参数为首次执行的延时时间,第三个参数为定时执行的间隔时间
service.scheduleAtFixedRate(runnable, 2, 5, TimeUnit.SECONDS);
service.scheduleAtFixedRate(runnable, 2, 30, TimeUnit.SECONDS);
// 创建并执行在给定延迟后启用的 ScheduledFuture。
// 参数:
// 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.persist.mapper.LogisticsCarRecordMapper;
import io.swagger.models.auth.In;
import org.apache.ibatis.annotations.Param;
import org.springframework.stereotype.Repository;
@ -49,7 +50,7 @@ public interface LogisticsCarRecordDao extends LogisticsCarRecordMapper {
* @param endTime 结束时间
* @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 结束时间
* @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 结束时间
* @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 结束时间
* @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 javax.annotation.Resource;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
/**
@ -55,18 +57,34 @@ public class MbpsService implements IMbpsService {
@Override
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();
//查询吞进量
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);
//查询吐出量
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);
//查询入库吨数
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);
//查询出货吨数
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);
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
FROM_UNIXTIME(cr.record_time/1000, '%Y-%m-%d') AS time,
s.date AS time,
COUNT(cr.id) AS carOfIn
FROM
t_logistics_car_record AS cr
WHERE
cr.in_out = 0 AND cr.rec_status = 0
AND cr.record_time BETWEEN #{startTime} AND #{endTime}
<if test="queryType==0">
GROUP BY
DAY(FROM_UNIXTIME(cr.record_time/1000, '%Y-%m-%d'));
</if>
<if test="queryType==1">
GROUP BY
WEEK(FROM_UNIXTIME(cr.record_time/1000, '%Y-%m-%d'));
</if>
<if test="queryType==2">
GROUP BY
MONTH(FROM_UNIXTIME(cr.record_time/1000, '%Y-%m-%d'));
</if>
<if test="queryType==3">
GROUP BY
YEAR(FROM_UNIXTIME(cr.record_time/1000, '%Y-%m-%d'));
</if>
(SELECT
<if test="queryType==0">
date_add( #{nowDate}, INTERVAL @i := @i - 1 DAY ) AS date
</if>
<if test="queryType==1">
DATE_FORMAT((date_add(#{nowDate},interval @i:=@i-1 week)),'%Y-%u') as date
</if>
<if test="queryType==2">
DATE_FORMAT((date_add(#{nowDate},interval @i:=@i-1 month)),'%Y-%m') as date
</if>
<if test="queryType==3">
DATE_FORMAT((date_add(#{nowDate},interval @i:=@i-1 year)),'%Y') as date
</if>
FROM
(
SELECT 1
<foreach item="index" collection="countArr">
union all select 1
</foreach>
) 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 id="selCarOfOutByTime" resultType="com.ccsens.logistics.bean.vo.MbpsVo$CarOfOutByTime">
SELECT
FROM_UNIXTIME(cr.record_time/1000, '%Y-%m-%d') AS time,
COUNT(cr.id) AS carOfOut
s.date AS time,
COUNT(cr.id) AS carOfOut
FROM
t_logistics_car_record AS cr
WHERE
cr.in_out = 1 AND cr.rec_status = 0
AND cr.record_time BETWEEN #{startTime} AND #{endTime}
<if test="queryType==0">
GROUP BY
DAY(FROM_UNIXTIME(cr.record_time/1000, '%Y-%m-%d'));
</if>
<if test="queryType==1">
GROUP BY
WEEK(FROM_UNIXTIME(cr.record_time/1000, '%Y-%m-%d'));
</if>
<if test="queryType==2">
GROUP BY
MONTH(FROM_UNIXTIME(cr.record_time/1000, '%Y-%m-%d'));
</if>
<if test="queryType==3">
GROUP BY
YEAR(FROM_UNIXTIME(cr.record_time/1000, '%Y-%m-%d'));
</if>
(SELECT
<if test="queryType==0">
date_add( #{nowDate}, INTERVAL @i := @i - 1 DAY ) AS date
</if>
<if test="queryType==1">
DATE_FORMAT((date_add(#{nowDate},interval @i:=@i-1 week)),'%Y-%u') as date
</if>
<if test="queryType==2">
DATE_FORMAT((date_add(#{nowDate},interval @i:=@i-1 month)),'%Y-%m') as date
</if>
<if test="queryType==3">
DATE_FORMAT((date_add(#{nowDate},interval @i:=@i-1 year)),'%Y') as date
</if>
FROM
(
SELECT 1
<foreach item="index" collection="countArr">
union all select 1
</foreach>
) 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 id="selWeightOfInByTime" resultType="com.ccsens.logistics.bean.vo.MbpsVo$WeightOfInByTime">
SELECT
FROM_UNIXTIME(cr.record_time/1000, '%Y-%m-%d') AS time,
SUM(cr.car_weight) AS weightOfIn
s.date AS time,
SUM(cr.car_weight) AS weightOfIn
FROM
t_logistics_car_record AS cr
WHERE
cr.in_out = 0 AND cr.rec_status = 0
AND cr.record_time BETWEEN #{startTime} AND #{endTime}
<if test="queryType==0">
GROUP BY
DAY(FROM_UNIXTIME(cr.record_time/1000, '%Y-%m-%d'));
</if>
<if test="queryType==1">
GROUP BY
WEEK(FROM_UNIXTIME(cr.record_time/1000, '%Y-%m-%d'));
</if>
<if test="queryType==2">
GROUP BY
MONTH(FROM_UNIXTIME(cr.record_time/1000, '%Y-%m-%d'));
</if>
<if test="queryType==3">
GROUP BY
YEAR(FROM_UNIXTIME(cr.record_time/1000, '%Y-%m-%d'));
</if>
(SELECT
<if test="queryType==0">
date_add( #{nowDate}, INTERVAL @i := @i - 1 DAY ) AS date
</if>
<if test="queryType==1">
DATE_FORMAT((date_add(#{nowDate},interval @i:=@i-1 week)),'%Y-%u') as date
</if>
<if test="queryType==2">
DATE_FORMAT((date_add(#{nowDate},interval @i:=@i-1 month)),'%Y-%m') as date
</if>
<if test="queryType==3">
DATE_FORMAT((date_add(#{nowDate},interval @i:=@i-1 year)),'%Y') as date
</if>
FROM
(
SELECT 1
<foreach item="index" collection="countArr">
union all select 1
</foreach>
) 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 id="selWeightOfOutByTime" resultType="com.ccsens.logistics.bean.vo.MbpsVo$WeightOfOutByTime">
SELECT
FROM_UNIXTIME(cr.record_time/1000, '%Y-%m-%d') AS time,
SUM(cr.car_weight) AS weightOfOut
s.date AS time,
SUM(cr.car_weight) AS weightOfOut
FROM
t_logistics_car_record AS cr
WHERE
cr.in_out = 1 AND cr.rec_status = 0
AND cr.record_time BETWEEN #{startTime} AND #{endTime}
<if test="queryType==0">
GROUP BY
DAY(FROM_UNIXTIME(cr.record_time/1000, '%Y-%m-%d'));
</if>
<if test="queryType==1">
GROUP BY
WEEK(FROM_UNIXTIME(cr.record_time/1000, '%Y-%m-%d'));
</if>
<if test="queryType==2">
GROUP BY
MONTH(FROM_UNIXTIME(cr.record_time/1000, '%Y-%m-%d'));
</if>
<if test="queryType==3">
GROUP BY
YEAR(FROM_UNIXTIME(cr.record_time/1000, '%Y-%m-%d'));
</if>
(SELECT
<if test="queryType==0">
date_add( #{nowDate}, INTERVAL @i := @i - 1 DAY ) AS date
</if>
<if test="queryType==1">
DATE_FORMAT((date_add(#{nowDate},interval @i:=@i-1 week)),'%Y-%u') as date
</if>
<if test="queryType==2">
DATE_FORMAT((date_add(#{nowDate},interval @i:=@i-1 month)),'%Y-%m') as date
</if>
<if test="queryType==3">
DATE_FORMAT((date_add(#{nowDate},interval @i:=@i-1 year)),'%Y') as date
</if>
FROM
(
SELECT 1
<foreach item="index" collection="countArr">
union all select 1
</foreach>
) 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>
</mapper>
Loading…
Cancel
Save