Browse Source

智慧平车记录

recovery
zhizhi wu 4 years ago
parent
commit
99bda20071
  1. 2
      pom.xml
  2. 15
      util/src/main/java/com/ccsens/util/DateUtil.java
  3. 47
      wisdomcar/src/main/java/com/ccsens/wisdomcar/api/RecordController.java
  4. 69
      wisdomcar/src/main/java/com/ccsens/wisdomcar/bean/dto/RecordDto.java
  5. 28
      wisdomcar/src/main/java/com/ccsens/wisdomcar/bean/vo/RecordVo.java
  6. 23
      wisdomcar/src/main/java/com/ccsens/wisdomcar/persist/dao/WisdomCarRecordDao.java
  7. 22
      wisdomcar/src/main/java/com/ccsens/wisdomcar/service/IRecordService.java
  8. 117
      wisdomcar/src/main/java/com/ccsens/wisdomcar/service/RecordService.java
  9. 11
      wisdomcar/src/main/resources/application-dev.yml
  10. 10
      wisdomcar/src/main/resources/application-prod.yml
  11. 9
      wisdomcar/src/main/resources/application-test.yml
  12. 4
      wisdomcar/src/main/resources/application.yml
  13. 14
      wisdomcar/src/main/resources/mapper_dao/WisdomCarRecordDao.xml

2
pom.xml

@ -12,7 +12,7 @@
<!-- <module>ht</module>-->
<!-- <module>game</module>-->
<!-- <module>mt</module>-->
<!-- <module>wisdomcar</module>-->
<module>wisdomcar</module>
<module>beneficiation</module>
<!-- <module>form</module>-->
<!-- <module>signin</module>-->

15
util/src/main/java/com/ccsens/util/DateUtil.java

@ -1,6 +1,5 @@
package com.ccsens.util;
import cn.hutool.core.date.DateTime;
import cn.hutool.core.util.StrUtil;
import com.ccsens.util.exception.BaseException;
@ -9,6 +8,20 @@ import java.text.SimpleDateFormat;
import java.util.*;
public class DateUtil extends cn.hutool.core.date.DateUtil {
/**年月日时分秒*/
public static final String yyyyMMddHHmmss="yyyyMMddHHmmss";
/**
* 时间格式转换
* @param date date
* @param format 格式
* @return 时间字符串
*/
public static String format(Date date, String format) {
SimpleDateFormat sdf = new SimpleDateFormat(format);
return sdf.format(date);
}
public static Long dateBeginSeconds(Long seconds){
if(seconds == null) {
seconds = currentSeconds();

47
wisdomcar/src/main/java/com/ccsens/wisdomcar/api/RecordController.java

@ -1,10 +1,30 @@
package com.ccsens.wisdomcar.api;
import cn.hutool.core.util.CharsetUtil;
import com.ccsens.util.DateUtil;
import com.ccsens.util.JsonResponse;
import com.ccsens.util.bean.dto.QueryDto;
import com.ccsens.wisdomcar.bean.dto.RecordDto;
import com.ccsens.wisdomcar.bean.vo.RecordVo;
import com.ccsens.wisdomcar.service.IRecordService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.apache.poi.ss.usermodel.Workbook;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.net.URLEncoder;
import java.util.Date;
import java.util.List;
/**
* @author
*/
@ -13,4 +33,31 @@ import org.springframework.web.bind.annotation.RestController;
@RestController
@RequestMapping("/record")
public class RecordController {
@Resource
private IRecordService recordService;
@ApiOperation(value = "查询智慧平车称重和rfid记录", notes = "")
@RequestMapping(value = "/weightList", method = RequestMethod.POST, produces = {"application/json;charset=UTF-8"})
public JsonResponse<RecordVo.WeightAndRfid> timeList(@ApiParam @Validated @RequestBody QueryDto<RecordDto.WeightAndRfid> params){
log.info("查询智慧平车称重和rfid记录:{}", params);
List<RecordVo.WeightAndRfid> list = recordService.queryWeightAndRfid(params.getParam(), params.getUserId());
log.info("查询智慧平车称重和rfid记录结果:{}",list);
return JsonResponse.newInstance().ok(list);
}
@ApiOperation(value = "智慧平车称重和rfid记录导出", notes = "")
@RequestMapping(value = "/weightExport", method = RequestMethod.GET, produces = {"application/json;charset=UTF-8"})
public void weightExport(@ApiParam @Validated RecordDto.WeightAndRfidExport param, HttpServletResponse response) throws IOException {
log.info("导出智慧平车称重和rfid记录:{}", param);
Workbook workbook = recordService.exportWeightAndRfid(param);
log.info("导出智慧平车称重和rfid记录结果结束");
Date start = new Date();
start.setTime(param.getStartTime());
Date end = new Date();
end.setTime(param.getEndTime());
String fileName = "智慧平车记录"+ DateUtil.format(start, DateUtil.yyyyMMddHHmmss) + "-" + DateUtil.format(end, DateUtil.yyyyMMddHHmmss) +".xlsx";
response.setHeader("Content-Disposition", "attachment;filename=" + URLEncoder.encode(fileName, CharsetUtil.UTF_8));
workbook.write(response.getOutputStream());
}
}

69
wisdomcar/src/main/java/com/ccsens/wisdomcar/bean/dto/RecordDto.java

@ -0,0 +1,69 @@
package com.ccsens.wisdomcar.bean.dto;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import javax.validation.constraints.Max;
import javax.validation.constraints.Min;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
/**
* @description: 数据记录
* @author: whj
* @time: 2021/3/5 13:59
*/
@Data
public class RecordDto {
@Data
@ApiModel("称重和rfid记录的请求参数")
public static class WeightAndRfid{
@ApiModelProperty("平车ID,默认1")
private Long carId = 1L;
@ApiModelProperty("开始时间, 默认今天0点")
private Long startTime;
@ApiModelProperty("结束时间, 默认当前时间")
private Long endTime;
// @ApiModelProperty("当前页,默认1")
// private int pageNum=1;
// @ApiModelProperty("每页数量,默认100")
// @Min(value = 1)
// @Max(value=10000)
// private int pageSize = 100;
{
endTime = System.currentTimeMillis();
Date today = new Date();
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
try {
startTime = sdf.parse(sdf.format(today)).getTime();
} catch (ParseException e) {
}
}
}
@Data
@ApiModel("称重和rfid记录导出的请求参数")
public static class WeightAndRfidExport{
@ApiModelProperty("平车ID,默认1")
private Long carId = 1L;
@ApiModelProperty("开始时间, 默认今天0点")
private Long startTime;
@ApiModelProperty("结束时间, 默认当前时间")
private Long endTime;
{
endTime = System.currentTimeMillis();
Date today = new Date();
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
try {
startTime = sdf.parse(sdf.format(today)).getTime();
} catch (ParseException e) {
}
}
}
}

28
wisdomcar/src/main/java/com/ccsens/wisdomcar/bean/vo/RecordVo.java

@ -0,0 +1,28 @@
package com.ccsens.wisdomcar.bean.vo;
import com.fasterxml.jackson.annotation.JsonFormat;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.util.Date;
/**
* @description: 数据记录
* @author: whj
* @time: 2021/3/5 13:59
*/
@Data
public class RecordVo {
@Data
@ApiModel("称重和rfid记录的响应结果")
public static class WeightAndRfid{
@ApiModelProperty("时间")
private Long time;
@ApiModelProperty("类型:1体重 2rfid")
private Byte type;
private String value;
private String name;
}
}

23
wisdomcar/src/main/java/com/ccsens/wisdomcar/persist/dao/WisdomCarRecordDao.java

@ -0,0 +1,23 @@
package com.ccsens.wisdomcar.persist.dao;
import com.ccsens.wisdomcar.bean.vo.RecordVo;
import com.ccsens.wisdomcar.persist.mapper.WisdomCarRecordMapper;
import org.apache.ibatis.annotations.Param;
import java.util.Date;
import java.util.List;
/**
*
* @author whj
*/
public interface WisdomCarRecordDao extends WisdomCarRecordMapper {
/**
* 查询平车的称重和rfid记录
* @param carId 平车ID
* @param startTime 开始时间
* @param endTime 结束时间
* @return 称重和rfid记录
*/
List<RecordVo.WeightAndRfid> queryWeightAndRfid(@Param("carId") Long carId, @Param("startTime") Long startTime, @Param("endTime") Long endTime);
}

22
wisdomcar/src/main/java/com/ccsens/wisdomcar/service/IRecordService.java

@ -1,7 +1,15 @@
package com.ccsens.wisdomcar.service;
import com.ccsens.wisdomcar.bean.dto.Message.CarRecordMessageDto;
import com.ccsens.wisdomcar.bean.dto.RecordDto;
import com.ccsens.wisdomcar.bean.vo.RecordVo;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.github.pagehelper.PageInfo;
import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
import org.apache.poi.ss.usermodel.Workbook;
import java.io.IOException;
import java.util.List;
public interface IRecordService {
@ -11,4 +19,18 @@ public interface IRecordService {
* @throws Exception
*/
void disposeMessage(CarRecordMessageDto carRecordMessageDto) throws Exception;
/**
* 查询称重和Rfid记录
* @param param 查询条件
* @param userId 查询用户ID
* @return 记录
*/
List<RecordVo.WeightAndRfid> queryWeightAndRfid(RecordDto.WeightAndRfid param, Long userId);
/**
* 导出称重和Rfid记录
* @param param 查询条件
*/
Workbook exportWeightAndRfid(RecordDto.WeightAndRfidExport param) ;
}

117
wisdomcar/src/main/java/com/ccsens/wisdomcar/service/RecordService.java

@ -5,28 +5,33 @@ import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.lang.Snowflake;
import cn.hutool.core.util.ObjectUtil;
import com.ccsens.util.JacksonUtil;
import com.ccsens.util.PoiUtil;
import com.ccsens.util.RedisUtil;
import com.ccsens.util.bean.message.common.InMessage;
import com.ccsens.util.bean.message.common.MessageConstant;
import com.ccsens.util.bean.message.common.MessageRule;
import com.ccsens.wisdomcar.bean.dto.Message.CarRecordMessageDto;
import com.ccsens.wisdomcar.bean.dto.RecordDto;
import com.ccsens.wisdomcar.bean.po.*;
import com.ccsens.wisdomcar.bean.vo.Message.CarRecordMessageVo;
import com.ccsens.wisdomcar.bean.vo.RecordVo;
import com.ccsens.wisdomcar.bean.vo.StepVo;
import com.ccsens.wisdomcar.persist.dao.StepDao;
import com.ccsens.wisdomcar.persist.dao.WisdomCarRecordDao;
import com.ccsens.wisdomcar.persist.mapper.*;
import com.ccsens.wisdomcar.util.Constant;
import lombok.extern.slf4j.Slf4j;
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import javax.annotation.Resource;
import java.math.BigDecimal;
import java.util.HashSet;
import java.util.List;
import java.util.Random;
import java.util.Set;
import java.text.SimpleDateFormat;
import java.util.*;
/**
* @author
@ -53,6 +58,12 @@ public class RecordService implements IRecordService{
private ScreenMapper screenMapper;
@Resource
private RedisUtil redisUtil;
@Resource
private WisdomCarRecordDao wisdomCarRecordDao;
@Value("#{T(java.lang.Long).parseLong('${wisdom.weight:10000}')}")
private Long weightMinus;
@Value("#{T(java.lang.Long).parseLong('${wisdom.time:300000}')}")
private Long timeMinus;
@Override
public void disposeMessage(CarRecordMessageDto carRecordMessageDto) throws Exception {
@ -138,6 +149,104 @@ public class RecordService implements IRecordService{
saveAidRecord(carRecordMessageDto, wisdomCar.getId(),step,userIdSet);
}
@Override
public List<RecordVo.WeightAndRfid> queryWeightAndRfid(RecordDto.WeightAndRfid param, Long userId) {
List<RecordVo.WeightAndRfid> list = queryWeightAndRfid(param.getCarId(), param.getStartTime(), param.getEndTime());
return list;
}
/**
* 查询数据
* @param carId 平车ID
* @param startTime 开始时间
* @param endTime 结束时间
* @return 记录
*/
private List<RecordVo.WeightAndRfid> queryWeightAndRfid(Long carId, Long startTime, Long endTime) {
RecordVo.WeightAndRfid weight = null;
RecordVo.WeightAndRfid rfid = null;
List<RecordVo.WeightAndRfid> list = wisdomCarRecordDao.queryWeightAndRfid(carId, startTime, endTime);
Iterator<RecordVo.WeightAndRfid> iterator = list.iterator();
while (iterator.hasNext()) {
RecordVo.WeightAndRfid next = iterator.next();
if (next.getType() == Constant.CAR_RECORD_WEIGHT) {
// 称重
if (weight == null) {
weight = next;
continue;
}
// 体重变化和上一条体重相似且间隔时间较短,删除
if (Integer.parseInt(next.getValue()) - Integer.parseInt(weight.getValue()) <= weightMinus && next.getTime() - weight.getTime() <= timeMinus) {
iterator.remove();
} else {
weight = next;
}
} else {
if (weight != null) {
next.setValue(weight.getValue());
}
// rfid
if (rfid == null) {
rfid = next;
continue;
}
// rfid和上一个一样且间隔时间较短,删除
if (next.getValue().equals(rfid.getValue()) && next.getTime() - rfid.getTime() <= timeMinus) {
iterator.remove();
} else {
rfid = next;
}
}
}
return list;
}
@Override
public Workbook exportWeightAndRfid(RecordDto.WeightAndRfidExport param) {
log.info("数据导出:{}", param);
List<RecordVo.WeightAndRfid> list = queryWeightAndRfid(param.getCarId(), param.getStartTime(), param.getEndTime());
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
// 参数封装
List<List<PoiUtil.PoiUtilCell>> rows = new ArrayList<>();
// 标题
List<PoiUtil.PoiUtilCell> headRow = new ArrayList<>();
PoiUtil.PoiUtilCell headCell = new PoiUtil.PoiUtilCell();
headCell.setColspan(4);
headCell.setValue("智慧平车记录");
headRow.add(headCell);
rows.add(headRow);
log.info("标题:{}", headCell);
// 表头
List<PoiUtil.PoiUtilCell> titleRow = new ArrayList<>();
titleRow.add(new PoiUtil.PoiUtilCell("序号"));
titleRow.add(new PoiUtil.PoiUtilCell("时间"));
titleRow.add(new PoiUtil.PoiUtilCell("类型"));
titleRow.add(new PoiUtil.PoiUtilCell("数据"));
rows.add(titleRow);
log.info("表头:{}", titleRow);
for (int i = 0; i < list.size(); i++) {
RecordVo.WeightAndRfid record = list.get(i);
List<PoiUtil.PoiUtilCell> row = new ArrayList<>();
row.add(new PoiUtil.PoiUtilCell("" + (i + 1)));
Date time = new Date();
time.setTime(record.getTime());
row.add(new PoiUtil.PoiUtilCell(sdf.format(time)));
row.add(new PoiUtil.PoiUtilCell(record.getType() == Constant.CAR_RECORD_WEIGHT ? "称重" : "rfid"));
row.add(new PoiUtil.PoiUtilCell(record.getType() == Constant.CAR_RECORD_WEIGHT ? new BigDecimal(record.getValue()).divide(new BigDecimal(1000), 3).toString() + "Kg" : record.getName()));
rows.add(row);
}
log.info("数据:{}", list.size());
//生成一个excel文件
Workbook workbook = new XSSFWorkbook();
PoiUtil.exportWB("智慧平车记录",rows, workbook);
return workbook;
}
private void doseAndSensorMessage(CarRecordMessageDto carRecordMessageDto, Set<String> userIdSet) throws Exception {
//体重 单位g
BigDecimal weightInt = BigDecimal.valueOf(Double.parseDouble(carRecordMessageDto.getValue()));

11
wisdomcar/src/main/resources/application-dev.yml

@ -29,10 +29,13 @@ spring:
swagger:
enable: true
file:
path: /home/cloud/mt/uploads/
path: /home/cloud/wisdomcar/uploads/
signUpUrl: https://test.tall.wiki/compete/
domain: https://test.tall.wiki/gateway/mt/
imgDomain: https://test.tall.wiki/gateway/mt/uploads/
domain: https://test.tall.wiki/gateway/wisdomcar/
imgDomain: https://test.tall.wiki/gateway/wisdomcar/uploads/
#gameMqName: game_status_wisdom
logging:
path:
path:
wisdom:
weight: 10000
time: 600000

10
wisdomcar/src/main/resources/application-prod.yml

@ -34,7 +34,11 @@ eureka:
gatewayUrl: https://www.tall.wiki/gateway/
notGatewayUrl: https://www.tall.wiki/
file:
path: /home/cloud/mt/uploads/
path: /home/cloud/wisdomcar/uploads/
signUpUrl: https://www.tall.wiki/compete/
domain: https://www.tall.wiki/gateway/mt/
imgDomain: https://www.tall.wiki/gateway/mt/uploads/
domain: https://www.tall.wiki/gateway/wisdomcar/
imgDomain: https://www.tall.wiki/gateway/wisdomcar/uploads/
wisdom:
weight: 10000
time: 600000

9
wisdomcar/src/main/resources/application-test.yml

@ -30,7 +30,10 @@ eureka:
instance:
ip-address: 192.168.0.99
file:
path: /home/cloud/mt/uploads/
path: /home/cloud/wisdomcar/uploads/
signUpUrl: https://test.tall.wiki/compete/
domain: https://test.tall.wiki/gateway/mt/
imgDomain: https://test.tall.wiki/gateway/mt/uploads/
domain: https://test.tall.wiki/gateway/wisdomcar/
imgDomain: https://test.tall.wiki/gateway/wisdomcar/uploads/
wisdom:
weight: 10000
time: 600000

4
wisdomcar/src/main/resources/application.yml

@ -1,6 +1,6 @@
spring:
profiles:
active: dev
include: common, util-dev
active: prod
include: common, util-prod

14
wisdomcar/src/main/resources/mapper_dao/WisdomCarRecordDao.xml

@ -0,0 +1,14 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.ccsens.wisdomcar.persist.dao.WisdomCarRecordDao">
<select id="queryWeightAndRfid" resultType="com.ccsens.wisdomcar.bean.vo.RecordVo$WeightAndRfid">
select * from (
select r.time, r.type, r.value, '称重' as name from t_wisdom_car_record r where r.car_id = #{carId} and r.type = 1 and r.time &gt;= #{startTime} and r.time &lt; #{endTime} and r.value &lt;= 200000 and r.rec_status = 0
union
select r.time, r.type, r.value, s.name from t_wisdom_car_record r, t_rfid rfid, t_step s where r.car_id = #{carId} and r.value = rfid.id and rfid.step_id = s.id and r.type = 2 and r.time &gt;= #{startTime} and r.time &lt; #{endTime} and r.rec_status = 0
) t
order by time
</select>
</mapper>
Loading…
Cancel
Save