Browse Source

修改物流园查询总吞吐量接口,增加生成数据的定时方法

logistics
ma 4 years ago
parent
commit
3ed8e14b45
  1. 4
      logistics/src/main/java/com/ccsens/logistics/Util/Constant.java
  2. 9
      logistics/src/main/java/com/ccsens/logistics/api/CarRecordController.java
  3. 2
      logistics/src/main/java/com/ccsens/logistics/bean/dto/CarRecordDto.java
  4. 8
      logistics/src/main/java/com/ccsens/logistics/bean/dto/MbpsDto.java
  5. 11
      logistics/src/main/java/com/ccsens/logistics/bean/po/LogisticsCarRecord.java
  6. 60
      logistics/src/main/java/com/ccsens/logistics/bean/po/LogisticsCarRecordExample.java
  7. 16
      logistics/src/main/java/com/ccsens/logistics/persist/dao/LogisticsCarRecordDao.java
  8. 17
      logistics/src/main/java/com/ccsens/logistics/scheduled/ScheduledService.java
  9. 4
      logistics/src/main/java/com/ccsens/logistics/service/CarIdentificationService.java
  10. 41
      logistics/src/main/java/com/ccsens/logistics/service/CarRecordService.java
  11. 5
      logistics/src/main/java/com/ccsens/logistics/service/ICarRecordService.java
  12. 26
      logistics/src/main/java/com/ccsens/logistics/service/MbpsService.java
  13. 21
      logistics/src/main/resources/mapper_dao/LogisticsCarRecordDao.xml
  14. 25
      logistics/src/main/resources/mapper_raw/LogisticsCarRecordMapper.xml

4
logistics/src/main/java/com/ccsens/logistics/Util/Constant.java

@ -131,5 +131,9 @@ public class Constant {
public static final Long CAR_WEIGHT_TWENTY = 20L;
/**
* 现海园区五号仓库
*/
public static final Long FIVE_WAREHOUSE = 7L;
}

9
logistics/src/main/java/com/ccsens/logistics/api/CarRecordController.java

@ -40,4 +40,13 @@ public class CarRecordController {
return JsonResponse.newInstance().ok();
}
@ApiOperation(value = "测试定时任务", notes = "mz:测试定时任务")
@RequestMapping(value = "/testTask", method = RequestMethod.POST, produces = {"application/json;charset=UTF-8"})
public JsonResponse testTask() {
log.info("测试定时任务:{}");
iCarRecordService.createXianHaiData();
log.info("测试定时任务:{}");
return JsonResponse.newInstance().ok();
}
}

2
logistics/src/main/java/com/ccsens/logistics/bean/dto/CarRecordDto.java

@ -25,6 +25,8 @@ public class CarRecordDto {
private String licensePlate;
@ApiModelProperty("车辆重量")
private Long carWeight;
@ApiModelProperty("园区id")
private Long parkId;
}

8
logistics/src/main/java/com/ccsens/logistics/bean/dto/MbpsDto.java

@ -20,6 +20,9 @@ public class MbpsDto {
public static class SelAllMbpsSerch{
@ApiModelProperty("仓库id")
private Long warehouseId;
@NotNull(message = "请选择园区")
@ApiModelProperty("园区id(0现海园区,1晋恒通园区)")
private Long parkId;
}
@Data
@ -32,6 +35,11 @@ public class MbpsDto {
private Byte queryType;
@ApiModelProperty("查询的天数")
private Integer queryOfDay = 10;
@ApiModelProperty("仓库id")
private Long warehouseId;
@NotNull(message = "请选择园区")
@ApiModelProperty("园区id(0现海园区,1晋恒通园区)")
private Long parkId;
}
@Data

11
logistics/src/main/java/com/ccsens/logistics/bean/po/LogisticsCarRecord.java

@ -36,6 +36,8 @@ public class LogisticsCarRecord implements Serializable {
private Byte recStatus;
private Long parkId;
private static final long serialVersionUID = 1L;
public Long getId() {
@ -166,6 +168,14 @@ public class LogisticsCarRecord implements Serializable {
this.recStatus = recStatus;
}
public Long getParkId() {
return parkId;
}
public void setParkId(Long parkId) {
this.parkId = parkId;
}
@Override
public String toString() {
StringBuilder sb = new StringBuilder();
@ -188,6 +198,7 @@ public class LogisticsCarRecord implements Serializable {
sb.append(", createdAt=").append(createdAt);
sb.append(", updatedAt=").append(updatedAt);
sb.append(", recStatus=").append(recStatus);
sb.append(", parkId=").append(parkId);
sb.append("]");
return sb.toString();
}

60
logistics/src/main/java/com/ccsens/logistics/bean/po/LogisticsCarRecordExample.java

@ -1144,6 +1144,66 @@ public class LogisticsCarRecordExample {
addCriterion("rec_status not between", value1, value2, "recStatus");
return (Criteria) this;
}
public Criteria andParkIdIsNull() {
addCriterion("park_id is null");
return (Criteria) this;
}
public Criteria andParkIdIsNotNull() {
addCriterion("park_id is not null");
return (Criteria) this;
}
public Criteria andParkIdEqualTo(Long value) {
addCriterion("park_id =", value, "parkId");
return (Criteria) this;
}
public Criteria andParkIdNotEqualTo(Long value) {
addCriterion("park_id <>", value, "parkId");
return (Criteria) this;
}
public Criteria andParkIdGreaterThan(Long value) {
addCriterion("park_id >", value, "parkId");
return (Criteria) this;
}
public Criteria andParkIdGreaterThanOrEqualTo(Long value) {
addCriterion("park_id >=", value, "parkId");
return (Criteria) this;
}
public Criteria andParkIdLessThan(Long value) {
addCriterion("park_id <", value, "parkId");
return (Criteria) this;
}
public Criteria andParkIdLessThanOrEqualTo(Long value) {
addCriterion("park_id <=", value, "parkId");
return (Criteria) this;
}
public Criteria andParkIdIn(List<Long> values) {
addCriterion("park_id in", values, "parkId");
return (Criteria) this;
}
public Criteria andParkIdNotIn(List<Long> values) {
addCriterion("park_id not in", values, "parkId");
return (Criteria) this;
}
public Criteria andParkIdBetween(Long value1, Long value2) {
addCriterion("park_id between", value1, value2, "parkId");
return (Criteria) this;
}
public Criteria andParkIdNotBetween(Long value1, Long value2) {
addCriterion("park_id not between", value1, value2, "parkId");
return (Criteria) this;
}
}
public static class Criteria extends GeneratedCriteria {

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

@ -18,31 +18,31 @@ public interface LogisticsCarRecordDao extends LogisticsCarRecordMapper {
/**
* 查询车辆吞进量
* @param warehouseId 仓库id
* @param parkId 园区id
* @return 车辆吞进量
*/
Long selCarOfIn(@Param("warehouseId") Long warehouseId);
Long selCarOfIn(@Param("parkId") Long parkId);
/**
* 查询车辆吐出量
* @param warehouseId 仓库id
* @param parkId 园区id
* @return 车辆吐出量
*/
Long selCarOfOut(@Param("warehouseId") Long warehouseId);
Long selCarOfOut(@Param("parkId") Long parkId);
/**
* 查询入库吨数
* @param warehouseId 仓库id
* @param parkId 园区id
* @return 入库吨数
*/
Long selWeightOfIn(@Param("warehouseId") Long warehouseId);
Long selWeightOfIn(@Param("parkId") Long parkId);
/**
* 查询出货吨数
* @param warehouseId 仓库id
* @param parkId 园区id
* @return 出货吨数
*/
Long selWeightOfOut(@Param("warehouseId") Long warehouseId);
Long selWeightOfOut(@Param("parkId") Long parkId);
/**
* 根据时间查询车辆吞进量

17
logistics/src/main/java/com/ccsens/logistics/scheduled/ScheduledService.java

@ -2,6 +2,7 @@ package com.ccsens.logistics.scheduled;
import com.ccsens.logistics.service.ICarIdentificationService;
import com.ccsens.logistics.service.ICarRecordService;
import com.ccsens.logistics.service.IHttpService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.scheduling.annotation.EnableScheduling;
@ -25,12 +26,20 @@ public class ScheduledService {
private IHttpService iHttpService;
@Resource
private ICarIdentificationService carIdentificationService;
@Resource
private ICarRecordService carRecordService;
/**
* 每三十秒获取温湿度设备数据
*/
@Scheduled(cron = "*/30 * * * * ?")
public void runfirst(){
iHttpService.getTemperatureAndHumidity();
}
/**
* 每十分钟从物流园停车平台获取车辆数据
*/
@Scheduled(cron = "0 */10 * * * ?")
public void runSaveCarRecord(){
try {
@ -40,4 +49,12 @@ public class ScheduledService {
log.info("查询保存车辆记录的定时任务异常",e);
}
}
/**
* 创建现海园区吞吐量数据
*/
@Scheduled(cron = "0 */10 * * * ?")
public void createXianHaiData(){
carRecordService.createXianHaiData();
}
}

4
logistics/src/main/java/com/ccsens/logistics/service/CarIdentificationService.java

@ -132,6 +132,7 @@ public class CarIdentificationService implements ICarIdentificationService{
//查询停车记录
List<CarRecordDto.AddCarRecord> carData = getCarData(httpClient, token, carType);
//保存停车信息
carRecordDao.insertRecordList(carData);
}
@ -236,12 +237,15 @@ public class CarIdentificationService implements ICarIdentificationService{
inCar.setCarType(carType.get(row.getString("cartype")));
inCar.setLicensePlate(row.getString("vehicle_no"));
inCar.setRecordTime(row.getLong("intime")*1000);
inCar.setParkId(1L);
//添加出的车
outCar.setRecordId(snowflake.nextId());
outCar.setInOut((byte)1);
outCar.setCarType(carType.get(row.getString("cartype")));
outCar.setLicensePlate(row.getString("vehicle_no"));
outCar.setRecordTime(row.getLong("outtime")*1000);
outCar.setParkId(1L);
switch (carType.get(row.getString("cartype"))){

41
logistics/src/main/java/com/ccsens/logistics/service/CarRecordService.java

@ -4,6 +4,7 @@ import cn.hutool.core.lang.Snowflake;
import cn.hutool.core.util.StrUtil;
import com.ccsens.logistics.bean.dto.CarRecordDto;
import com.ccsens.logistics.bean.po.LogisticsCarRecord;
import com.ccsens.logistics.bean.vo.CarRecordVo;
import com.ccsens.logistics.persist.dao.LogisticsCarRecordDao;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
@ -11,6 +12,9 @@ import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;
/**
* @author
@ -50,4 +54,41 @@ public class CarRecordService implements ICarRecordService {
carRecordDao.insertSelective(carRecord);
}
@Override
public void createXianHaiData() {
long currentTime = System.currentTimeMillis();
List<CarRecordDto.AddCarRecord> carRecords = new ArrayList<>();
//生成十条随机数据
for (int i = 0; i < 5; i++) {
CarRecordDto.AddCarRecord inCar = new CarRecordDto.AddCarRecord();
CarRecordDto.AddCarRecord outCar = new CarRecordDto.AddCarRecord();
//添加进的车
inCar.setRecordId(snowflake.nextId());
inCar.setCarWeight((long)(Math.random()*20));
inCar.setInOut((byte)0);
if ((int) (Math.random() * 10) > 5) {
inCar.setRecordTime(currentTime - new Random().nextInt(3600000));
} else {
inCar.setRecordTime(currentTime + new Random().nextInt(3600000));
}
inCar.setParkId(0L);
carRecords.add(inCar);
//添加出的车
outCar.setRecordId(snowflake.nextId());
outCar.setInOut((byte)1);
outCar.setCarWeight((long)(Math.random()*20));
outCar.setParkId(0L);
if ((int) (Math.random() * 10) > 5) {
outCar.setRecordTime(currentTime - new Random().nextInt(3600000));
} else {
outCar.setRecordTime(currentTime + new Random().nextInt(3600000));
}
carRecords.add(outCar);
}
carRecordDao.insertRecordList(carRecords);
}
}

5
logistics/src/main/java/com/ccsens/logistics/service/ICarRecordService.java

@ -12,4 +12,9 @@ public interface ICarRecordService {
* @param param 车辆类型 记录时间
*/
void addCarRecord(CarRecordDto.AddCarRecord param);
/**
* 创建现海园区的车辆记录数据
*/
void createXianHaiData();
}

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

@ -2,6 +2,7 @@ package com.ccsens.logistics.service;
import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.util.ObjectUtil;
import com.ccsens.logistics.Util.Constant;
import com.ccsens.logistics.bean.dto.MbpsDto;
import com.ccsens.logistics.bean.po.LogisticsWarehouse;
import com.ccsens.logistics.bean.po.LogisticsWarehouseExample;
@ -42,33 +43,50 @@ public class MbpsService implements IMbpsService {
public MbpsVo.AllMbps selAllMbps(MbpsDto.SelAllMbpsSerch param) {
MbpsVo.AllMbps allMbps = new MbpsVo.AllMbps();
//查询吞进量
Long carOfIn = carRecordDao.selCarOfIn(param.getWarehouseId());
Long carOfIn = carRecordDao.selCarOfIn(param.getParkId());
if (null == carOfIn){
allMbps.setCarOfIn(0L);
}else{
if (ObjectUtil.isNotNull(param.getWarehouseId())){
carOfIn = carOfIn/7;
}
allMbps.setCarOfIn(carOfIn);
}
//查询吐出量
Long carOfOut = carRecordDao.selCarOfOut(param.getWarehouseId());
Long carOfOut = carRecordDao.selCarOfOut(param.getParkId());
if (null == carOfOut){
allMbps.setCarOfOut(0L);
}else {
if (ObjectUtil.isNotNull(param.getWarehouseId())){
carOfOut = carOfOut/7;
}
allMbps.setCarOfOut(carOfOut);
}
//查询入库吨数
Long weightOfIn = carRecordDao.selWeightOfIn(param.getWarehouseId());
Long weightOfIn = carRecordDao.selWeightOfIn(param.getParkId());
if (null == weightOfIn){
allMbps.setWeightOfIn(0L);
}else {
if (ObjectUtil.isNotNull(param.getWarehouseId())){
weightOfIn = weightOfIn/7;
if (Constant.FIVE_WAREHOUSE.equals(param.getWarehouseId())){
weightOfIn = weightOfIn*5;
}
}
allMbps.setWeightOfIn(weightOfIn);
}
//查询出货吨数
Long weightOfOut = carRecordDao.selWeightOfOut(param.getWarehouseId());
Long weightOfOut = carRecordDao.selWeightOfOut(param.getParkId());
if (null == weightOfOut){
allMbps.setWeightOfOut(0L);
}else {
if (ObjectUtil.isNotNull(param.getWarehouseId())){
weightOfOut = weightOfOut/7;
}
allMbps.setWeightOfOut(weightOfOut);
}
return allMbps;
}

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

@ -4,29 +4,29 @@
<select id="selCarOfIn" resultType="java.lang.Long">
SELECT COUNT(cr.id) FROM t_logistics_car_record AS cr WHERE cr.in_out = 0 AND cr.rec_status = 0
<if test="warehouseId!=null">
AND cr.warehouse_id = #{warehouseId}
<if test="parkId!=null">
AND cr.park_id = #{parkId}
</if>
</select>
<select id="selCarOfOut" resultType="java.lang.Long">
SELECT COUNT(cr.id) FROM t_logistics_car_record AS cr WHERE cr.in_out = 1 AND cr.rec_status = 0
<if test="warehouseId!=null">
AND cr.warehouse_id = #{warehouseId}
<if test="parkId!=null">
AND cr.park_id = #{parkId}
</if>
</select>
<select id="selWeightOfIn" resultType="java.lang.Long">
SELECT SUM(cr.car_weight) FROM t_logistics_car_record AS cr WHERE cr.in_out = 0 AND cr.rec_status = 0
<if test="warehouseId!=null">
AND cr.warehouse_id = #{warehouseId}
<if test="parkId!=null">
AND cr.park_id = #{parkId}
</if>
</select>
<select id="selWeightOfOut" resultType="java.lang.Long">
SELECT SUM(cr.car_weight) FROM t_logistics_car_record AS cr WHERE cr.in_out = 1 AND cr.rec_status = 0
<if test="warehouseId!=null">
AND cr.warehouse_id = #{warehouseId}
<if test="parkId!=null">
AND cr.park_id = #{parkId}
</if>
</select>
@ -202,11 +202,12 @@
car_type,
license_plate,
car_weight,
record_time
record_time,
park_id
)
VALUES
<foreach collection="list" item="item" separator=",">
(#{item.recordId},#{item.inOut},#{item.carType},#{item.licensePlate},#{item.carWeight},#{item.recordTime})
(#{item.recordId},#{item.inOut},#{item.carType},#{item.licensePlate},#{item.carWeight},#{item.recordTime},#{item.parkId})
</foreach>
</insert>

25
logistics/src/main/resources/mapper_raw/LogisticsCarRecordMapper.xml

@ -18,6 +18,7 @@
<result column="created_at" jdbcType="TIMESTAMP" property="createdAt" />
<result column="updated_at" jdbcType="TIMESTAMP" property="updatedAt" />
<result column="rec_status" jdbcType="TINYINT" property="recStatus" />
<result column="park_id" jdbcType="BIGINT" property="parkId" />
</resultMap>
<sql id="Example_Where_Clause">
<where>
@ -80,7 +81,7 @@
<sql id="Base_Column_List">
id, car_type, license_plate, plate_type, files_id, car_weight, in_out, car_brand,
picture, closeup_pic, cam_id, warehouse_id, record_time, created_at, updated_at,
rec_status
rec_status, park_id
</sql>
<select id="selectByExample" parameterType="com.ccsens.logistics.bean.po.LogisticsCarRecordExample" resultMap="BaseResultMap">
select
@ -118,13 +119,13 @@
in_out, car_brand, picture,
closeup_pic, cam_id, warehouse_id,
record_time, created_at, updated_at,
rec_status)
rec_status, park_id)
values (#{id,jdbcType=BIGINT}, #{carType,jdbcType=VARCHAR}, #{licensePlate,jdbcType=VARCHAR},
#{plateType,jdbcType=VARCHAR}, #{filesId,jdbcType=VARCHAR}, #{carWeight,jdbcType=BIGINT},
#{inOut,jdbcType=TINYINT}, #{carBrand,jdbcType=VARCHAR}, #{picture,jdbcType=VARCHAR},
#{closeupPic,jdbcType=VARCHAR}, #{camId,jdbcType=VARCHAR}, #{warehouseId,jdbcType=BIGINT},
#{recordTime,jdbcType=BIGINT}, #{createdAt,jdbcType=TIMESTAMP}, #{updatedAt,jdbcType=TIMESTAMP},
#{recStatus,jdbcType=TINYINT})
#{recStatus,jdbcType=TINYINT}, #{parkId,jdbcType=BIGINT})
</insert>
<insert id="insertSelective" parameterType="com.ccsens.logistics.bean.po.LogisticsCarRecord">
insert into t_logistics_car_record
@ -177,6 +178,9 @@
<if test="recStatus != null">
rec_status,
</if>
<if test="parkId != null">
park_id,
</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="id != null">
@ -227,6 +231,9 @@
<if test="recStatus != null">
#{recStatus,jdbcType=TINYINT},
</if>
<if test="parkId != null">
#{parkId,jdbcType=BIGINT},
</if>
</trim>
</insert>
<select id="countByExample" parameterType="com.ccsens.logistics.bean.po.LogisticsCarRecordExample" resultType="java.lang.Long">
@ -286,6 +293,9 @@
<if test="record.recStatus != null">
rec_status = #{record.recStatus,jdbcType=TINYINT},
</if>
<if test="record.parkId != null">
park_id = #{record.parkId,jdbcType=BIGINT},
</if>
</set>
<if test="_parameter != null">
<include refid="Update_By_Example_Where_Clause" />
@ -308,7 +318,8 @@
record_time = #{record.recordTime,jdbcType=BIGINT},
created_at = #{record.createdAt,jdbcType=TIMESTAMP},
updated_at = #{record.updatedAt,jdbcType=TIMESTAMP},
rec_status = #{record.recStatus,jdbcType=TINYINT}
rec_status = #{record.recStatus,jdbcType=TINYINT},
park_id = #{record.parkId,jdbcType=BIGINT}
<if test="_parameter != null">
<include refid="Update_By_Example_Where_Clause" />
</if>
@ -361,6 +372,9 @@
<if test="recStatus != null">
rec_status = #{recStatus,jdbcType=TINYINT},
</if>
<if test="parkId != null">
park_id = #{parkId,jdbcType=BIGINT},
</if>
</set>
where id = #{id,jdbcType=BIGINT}
</update>
@ -380,7 +394,8 @@
record_time = #{recordTime,jdbcType=BIGINT},
created_at = #{createdAt,jdbcType=TIMESTAMP},
updated_at = #{updatedAt,jdbcType=TIMESTAMP},
rec_status = #{recStatus,jdbcType=TINYINT}
rec_status = #{recStatus,jdbcType=TINYINT},
park_id = #{parkId,jdbcType=BIGINT}
where id = #{id,jdbcType=BIGINT}
</update>
</mapper>
Loading…
Cancel
Save