Browse Source

Merge branch 'pt' of dd.tall.wiki:ccsens_wiki/ccsenscloud into pt

recovery
wang0018 4 years ago
parent
commit
30a79ca589
  1. 2
      beneficiation/src/main/java/com/ccsens/beneficiation/api/ParameterController.java
  2. 2
      beneficiation/src/main/java/com/ccsens/beneficiation/bean/dto/ParameterDto.java
  3. 7
      beneficiation/src/main/java/com/ccsens/beneficiation/service/IMessageService.java
  4. 3
      beneficiation/src/main/java/com/ccsens/beneficiation/service/IParameterService.java
  5. 28
      beneficiation/src/main/java/com/ccsens/beneficiation/service/MessageService.java
  6. 183
      beneficiation/src/main/java/com/ccsens/beneficiation/service/ParameterService.java
  7. 56
      beneficiation/src/main/java/com/ccsens/beneficiation/util/Constant.java
  8. 4
      beneficiation/src/main/resources/application.yml
  9. 2
      pom.xml
  10. 17
      util/src/main/java/com/ccsens/util/DateUtil.java
  11. 47
      wisdomcar/src/main/java/com/ccsens/wisdomcar/api/RecordController.java
  12. 69
      wisdomcar/src/main/java/com/ccsens/wisdomcar/bean/dto/RecordDto.java
  13. 28
      wisdomcar/src/main/java/com/ccsens/wisdomcar/bean/vo/RecordVo.java
  14. 23
      wisdomcar/src/main/java/com/ccsens/wisdomcar/persist/dao/WisdomCarRecordDao.java
  15. 22
      wisdomcar/src/main/java/com/ccsens/wisdomcar/service/IRecordService.java
  16. 117
      wisdomcar/src/main/java/com/ccsens/wisdomcar/service/RecordService.java
  17. 11
      wisdomcar/src/main/resources/application-dev.yml
  18. 10
      wisdomcar/src/main/resources/application-prod.yml
  19. 9
      wisdomcar/src/main/resources/application-test.yml
  20. 4
      wisdomcar/src/main/resources/application.yml
  21. 14
      wisdomcar/src/main/resources/mapper_dao/WisdomCarRecordDao.xml

2
beneficiation/src/main/java/com/ccsens/beneficiation/api/ParameterController.java

@ -44,7 +44,7 @@ public class ParameterController {
@MustLogin
@ApiOperation(value = "修改设备的参数", notes = "")
@RequestMapping(value = "/update", method = RequestMethod.POST, produces = {"application/json;charset=UTF-8"})
public JsonResponse updateParameter(@ApiParam @Validated @RequestBody QueryDto<ParameterDto.ParameterInfo> params) {
public JsonResponse updateParameter(@ApiParam @Validated @RequestBody QueryDto<ParameterDto.ParameterInfo> params) throws Exception {
log.info("修改设备的参数:{}",params);
parameterService.updateParameter(params.getParam());
log.info("修改设备的参数成功");

2
beneficiation/src/main/java/com/ccsens/beneficiation/bean/dto/ParameterDto.java

@ -62,7 +62,7 @@ public class ParameterDto {
public static class Threshold{
@ApiModelProperty("最小")
private BigDecimal minValue;
@ApiModelProperty("最")
@ApiModelProperty("最")
private BigDecimal maxValue;
}

7
beneficiation/src/main/java/com/ccsens/beneficiation/service/IMessageService.java

@ -0,0 +1,7 @@
package com.ccsens.beneficiation.service;
import com.ccsens.util.bean.message.common.InMessage;
public interface IMessageService {
void sendToCarRecord(InMessage inMessage) throws Exception;
}

3
beneficiation/src/main/java/com/ccsens/beneficiation/service/IParameterService.java

@ -2,6 +2,7 @@ package com.ccsens.beneficiation.service;
import com.ccsens.beneficiation.bean.dto.ParameterDto;
import com.ccsens.beneficiation.bean.vo.ParameterVo;
import com.fasterxml.jackson.core.JsonProcessingException;
/**
* @author
@ -18,5 +19,5 @@ public interface IParameterService {
* 修改一起的参数
* @param param 参数
*/
void updateParameter(ParameterDto.ParameterInfo param);
void updateParameter(ParameterDto.ParameterInfo param) throws JsonProcessingException, Exception;
}

28
beneficiation/src/main/java/com/ccsens/beneficiation/service/MessageService.java

@ -0,0 +1,28 @@
package com.ccsens.beneficiation.service;
import com.ccsens.util.JacksonUtil;
import com.ccsens.util.bean.message.common.InMessage;
import com.ccsens.util.config.RabbitMQConfig;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.core.AmqpTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
@Slf4j
@Service
@Transactional(propagation = Propagation.REQUIRED, rollbackFor = Exception.class)
public class MessageService implements IMessageService{
@Autowired
private AmqpTemplate rabbitTemplate;
@Override
public void sendToCarRecord(InMessage inMessage) throws Exception{
// log.info(JacksonUtil.beanToJson(inMessage));
//FixMe 发送到消息队列
rabbitTemplate.convertAndSend(RabbitMQConfig.MESSAGE_QUEUE_NAME,
JacksonUtil.beanToJson(inMessage));
log.info("发送到消息队列:{}",JacksonUtil.beanToJson(inMessage));
}
}

183
beneficiation/src/main/java/com/ccsens/beneficiation/service/ParameterService.java

@ -8,16 +8,18 @@ import com.ccsens.beneficiation.bean.po.EquipmentTypeExample;
import com.ccsens.beneficiation.bean.vo.ParameterVo;
import com.ccsens.beneficiation.persist.dao.RecordDao;
import com.ccsens.beneficiation.persist.mapper.EquipmentTypeMapper;
import com.ccsens.beneficiation.util.Constant;
import com.ccsens.util.CRCUtil;
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 lombok.extern.slf4j.Slf4j;
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.ArrayList;
import java.util.List;
import java.util.*;
/**
* @author
@ -30,6 +32,8 @@ public class ParameterService implements IParameterService{
private RecordDao recordDao;
@Resource
private EquipmentTypeMapper equipmentTypeMapper;
@Resource
private IMessageService messageService;
@Override
public ParameterVo.QueryParameter queryParameter(Object param) {
@ -94,72 +98,137 @@ public class ParameterService implements IParameterService{
}
@Override
public void updateParameter(ParameterDto.ParameterInfo param) {
public void updateParameter(ParameterDto.ParameterInfo param) throws Exception {
if(ObjectUtil.isNull(param)){
return;
}
byte[] header = new byte[]{(byte)0xff,(byte)0xfe,(byte)0x00};
//电磁阀1
ParameterDto.Parameter solenoidValue1 = param.getSolenoidValue1();
if(ObjectUtil.isNotNull(solenoidValue1)){
if(ObjectUtil.isNotNull(solenoidValue1.getSettingValue())){
//根据id和数据类型 查找该设备的addr 设置值是1
EquipmentTypeExample equipmentTypeExample = new EquipmentTypeExample();
equipmentTypeExample.createCriteria().andEquipmentIdEqualTo(solenoidValue1.getId()).andTypeEqualTo((byte) 1);
List<EquipmentType> equipmentTypes = equipmentTypeMapper.selectByExample(equipmentTypeExample);
if(CollectionUtil.isNotEmpty(equipmentTypes)){
EquipmentType equipmentType = equipmentTypes.get(0);
//计算value的高低值
byte uc1 = (byte) (solenoidValue1.getSettingValue().intValue() >> 8);
byte uc2 = (byte) (solenoidValue1.getSettingValue().intValue() & 0xff);
//计算addr的高低值
byte addr1 = (byte) (equipmentType.getAddr() >> 8);
byte addr2 = (byte) (equipmentType.getAddr() & 0xff);
//TODO 长度未处理 传感器地址未处理
byte[] center = new byte[]{(byte)0x00,(byte)0x06,addr1,addr2,uc1,uc2};
byte[] crc = new byte[2];
CRCUtil.crc16(crc,center,0,center.length);
byte[] all = new byte[header.length + center.length + crc.length];
System.arraycopy(header,0,all,0,header.length);
System.arraycopy(center,0,all,header.length,center.length);
System.arraycopy(crc,0,all,header.length + center.length,crc.length);
all[2] = (byte) (all.length - 3);
transducer(solenoidValue1);
//电磁阀2
ParameterDto.Parameter solenoidValue2 = param.getSolenoidValue2();
transducer(solenoidValue2);
//变频器1
ParameterDto.Parameter transducer1 = param.getTransducer1();
transducer(transducer1);
//变频器2
ParameterDto.Parameter transducer2 = param.getTransducer1();
transducer(transducer2);
//变频器3
ParameterDto.Parameter transducer3 = param.getTransducer1();
transducer(transducer3);
//变频器4
ParameterDto.Parameter transducer4 = param.getTransducer1();
transducer(transducer4);
//电耳1
ParameterDto.ParameterThreshold electricEar1 = param.getElectricEar1();
electric(electricEar1);
//电耳2
ParameterDto.ParameterThreshold electricEar2 = param.getElectricEar2();
electric(electricEar2);
}
private void transducer(ParameterDto.Parameter transducer3) throws Exception {
if (ObjectUtil.isNotNull(transducer3)) {
if (ObjectUtil.isNotNull(transducer3.getSettingValue())) {
getBytes(transducer3.getId(), transducer3.getSettingValue().intValue(), Constant.Type.SET_VALUE);
}
}
}
private void electric(ParameterDto.ParameterThreshold electricEar) throws Exception {
if (ObjectUtil.isNotNull(electricEar)) {
//最低值
if (ObjectUtil.isNotNull(electricEar.getThresholdValue1())) {
ParameterDto.Threshold threshold = electricEar.getThresholdValue1();
//低
if (ObjectUtil.isNotNull(threshold.getMinValue())) {
getBytes(electricEar.getId(), threshold.getMinValue().intValue(), Constant.Type.MINIMUM_VALUE_MIN);
}
//高
if (ObjectUtil.isNotNull(threshold.getMaxValue())) {
getBytes(electricEar.getId(), threshold.getMaxValue().intValue(), Constant.Type.MINIMUM_VALUE_MAX);
}
}
//理想值
if (ObjectUtil.isNotNull(electricEar.getThresholdValue2())) {
ParameterDto.Threshold threshold = electricEar.getThresholdValue2();
//低
if (ObjectUtil.isNotNull(threshold.getMinValue())) {
getBytes(electricEar.getId(), threshold.getMinValue().intValue(), Constant.Type.MINIMUM_VALUE_MIN);
}
//高
if (ObjectUtil.isNotNull(threshold.getMaxValue())) {
getBytes(electricEar.getId(), threshold.getMaxValue().intValue(), Constant.Type.MINIMUM_VALUE_MAX);
}
}
//最高值
if (ObjectUtil.isNotNull(electricEar.getThresholdValue3())) {
ParameterDto.Threshold threshold = electricEar.getThresholdValue3();
//低
if (ObjectUtil.isNotNull(threshold.getMinValue())) {
getBytes(electricEar.getId(), threshold.getMinValue().intValue(), Constant.Type.MINIMUM_VALUE_MIN);
}
//高
if (ObjectUtil.isNotNull(threshold.getMaxValue())) {
getBytes(electricEar.getId(), threshold.getMaxValue().intValue(), Constant.Type.MINIMUM_VALUE_MAX);
}
}
}
// //电磁阀1
// ParameterDto.Parameter solenoidValue1 = param.getSolenoidValue1();
// if(ObjectUtil.isNotNull(solenoidValue1)){
//
// }
// //电磁阀1
// ParameterDto.Parameter solenoidValue1 = param.getSolenoidValue1();
// if(ObjectUtil.isNotNull(solenoidValue1)){
//
// }
// //电磁阀1
// ParameterDto.Parameter solenoidValue1 = param.getSolenoidValue1();
// if(ObjectUtil.isNotNull(solenoidValue1)){
//
// }
// //电磁阀1
// ParameterDto.Parameter solenoidValue1 = param.getSolenoidValue1();
// if(ObjectUtil.isNotNull(solenoidValue1)){
//
// }
// //电磁阀1
// ParameterDto.Parameter solenoidValue1 = param.getSolenoidValue1();
// if(ObjectUtil.isNotNull(solenoidValue1)){
//
// }
//生成数组
}
/**
* 获取设置值的byte数组 并发送消息
*/
private void getBytes(Long id, int value,byte type) throws Exception {
//根据id和数据类型 查找该设备的addr 设置值是1
EquipmentTypeExample equipmentTypeExample = new EquipmentTypeExample();
equipmentTypeExample.createCriteria().andEquipmentIdEqualTo(id).andTypeEqualTo(type);
List<EquipmentType> equipmentTypes = equipmentTypeMapper.selectByExample(equipmentTypeExample);
if(CollectionUtil.isNotEmpty(equipmentTypes)){
EquipmentType equipmentType = equipmentTypes.get(0);
log.info("查找设备配置信息:{}",equipmentType);
byte[] header = new byte[]{(byte)0xff,(byte)0xfe,(byte)0x00};
byte uc1 = (byte) (value >> 8);
byte uc2 = (byte) (value & 0xff);
log.info("计算value的高低值:{}---{}",uc1,uc2);
byte addr1 = (byte) (equipmentType.getAddr() >> 8);
byte addr2 = (byte) (equipmentType.getAddr() & 0xff);
log.info("计算addr的高低值:{}---{}",addr1,addr2);
byte[] center = new byte[]{(byte)0x10,(byte)0x06,addr1,addr2,uc1,uc2};
byte[] crc = new byte[2];
CRCUtil.crc16(crc,center,0,center.length);
log.info("计算crc校验:{}---{}",crc[0],crc[1]);
byte[] all = new byte[header.length + center.length + crc.length];
System.arraycopy(header,0,all,0,header.length);
System.arraycopy(center,0,all,header.length,center.length);
System.arraycopy(crc,0,all,header.length + center.length,crc.length);
all[2] = (byte) (all.length - 3);
sendInMessage(all);
}
}
/**
* 生成InMessage消息并发送
*/
private void sendInMessage(byte[] all) throws Exception {
Set<String> userIdSet = new HashSet<>();
userIdSet.add(String.valueOf(2));
MessageRule messageRule = MessageRule.defaultRule(MessageConstant.DomainType.User);
messageRule.setAckRule(MessageRule.AckRule.NONE);
messageRule.setOfflineDiscard((byte) 1);
String s = Arrays.toString(all);
InMessage inMessage = InMessage.newToUserMessage(null,userIdSet,null,messageRule,s);
//发送消息
messageService.sendToCarRecord(inMessage);
}
}

56
beneficiation/src/main/java/com/ccsens/beneficiation/util/Constant.java

@ -0,0 +1,56 @@
package com.ccsens.beneficiation.util;
/**
* @author
*/
public class Constant {
/**注册来源*/
public static final class Type {
/**
* 实时值
*/
public final static byte REAL_VALUE = 0;
/**
* 设置值
*/
public final static byte SET_VALUE = 1;
/**
* 累计值
*/
public final static byte AGGREGATE_VALUE = 2;
/**
* 最低值
*/
public final static byte MINIMUM_VALUE_MIN = 3;
/**
* 最低值
*/
public final static byte MINIMUM_VALUE_MAX = 8;
/**
* 理想值
*/
public final static byte IDEAL_VALUE_MIN = 4;
/**
* 理想值
*/
public final static byte IDEAL_VALUE_MAX = 9;
/**
* 最高值
*/
public final static byte MAXIMUM_VALUE_MIN = 5;
/**
* 最高值
*/
public final static byte MAXIMUM_VALUE_MAX = 10;
/**
* 迟滞
*/
public final static byte HYSTERESIS = 6;
/**
* 迟滞
*/
public final static byte OTHER = 7;
}
}

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

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

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>-->

17
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,22 @@ import java.text.SimpleDateFormat;
import java.util.*;
public class DateUtil extends cn.hutool.core.date.DateUtil {
/**年月日时分秒*/
public static final String yyyyMMddHHmmss="yyyyMMddHHmmss";
/**年月日*/
public static final String yyyyMMdd="yyyyMMdd";
/**
* 时间格式转换
* @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() - 24 * 3600 * 1000);
String fileName = "智慧平车记录"+ DateUtil.format(start, DateUtil.yyyyMMdd) + "-" + DateUtil.format(end, DateUtil.yyyyMMdd) +".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