mirror of
https://codeup.aliyun.com/64f7d6b8ce01efaafef1e678/coal/coal.git
synced 2026-01-25 07:46:40 +08:00
完善门禁接口
This commit is contained in:
@@ -0,0 +1,66 @@
|
||||
package cn.lihongjie.coal.acDevice.controller;
|
||||
|
||||
import cn.lihongjie.coal.acDevice.dto.AcDeviceDto;
|
||||
import cn.lihongjie.coal.acDevice.dto.CreateAcDeviceDto;
|
||||
import cn.lihongjie.coal.acDevice.dto.UpdateAcDeviceDto;
|
||||
import cn.lihongjie.coal.acDevice.service.AcDeviceService;
|
||||
import cn.lihongjie.coal.annotation.OrgScope;
|
||||
import cn.lihongjie.coal.annotation.SysLog;
|
||||
import cn.lihongjie.coal.base.dto.CommonQuery;
|
||||
import cn.lihongjie.coal.base.dto.IdRequest;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/acDevice")
|
||||
@SysLog(module = "门禁设备")
|
||||
@Slf4j
|
||||
@OrgScope
|
||||
public class AcDeviceController {
|
||||
@Autowired private AcDeviceService service;
|
||||
|
||||
@PostMapping("/create")
|
||||
public AcDeviceDto create(@RequestBody CreateAcDeviceDto request) {
|
||||
return this.service.create(request);
|
||||
}
|
||||
|
||||
@PostMapping("/update")
|
||||
public AcDeviceDto update(@RequestBody UpdateAcDeviceDto request) {
|
||||
return this.service.update(request);
|
||||
}
|
||||
|
||||
@PostMapping("/delete")
|
||||
public Object delete(@RequestBody IdRequest request) {
|
||||
this.service.delete(request);
|
||||
return true;
|
||||
}
|
||||
|
||||
@PostMapping("/getById")
|
||||
public AcDeviceDto getById(@RequestBody IdRequest request) {
|
||||
return this.service.getById(request.getId());
|
||||
}
|
||||
|
||||
@PostMapping("/list")
|
||||
public Page<AcDeviceDto> list(@RequestBody CommonQuery request) {
|
||||
return this.service.list(request);
|
||||
}
|
||||
|
||||
@PostMapping("/archive")
|
||||
public Object archive(@RequestBody IdRequest request) {
|
||||
this.service.archive(request);
|
||||
return true;
|
||||
}
|
||||
|
||||
@PostMapping("/unarchive")
|
||||
public Object unarchive(@RequestBody IdRequest request) {
|
||||
this.service.unarchive(request);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
package cn.lihongjie.coal.acDevice.dto;
|
||||
|
||||
import cn.lihongjie.coal.acDeviceSupplier.dto.AcDeviceSupplierDto;
|
||||
import cn.lihongjie.coal.base.dto.OrgCommonDto;
|
||||
import cn.lihongjie.coal.dataCollector.dto.DataCollectorDto;
|
||||
|
||||
import jakarta.persistence.ManyToOne;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import org.hibernate.annotations.Comment;
|
||||
import org.hibernate.annotations.Formula;
|
||||
|
||||
@Data
|
||||
public class AcDeviceDto extends OrgCommonDto {
|
||||
|
||||
@ManyToOne
|
||||
AcDeviceSupplierDto supplier;
|
||||
|
||||
@ManyToOne
|
||||
DataCollectorDto dataCollector;
|
||||
|
||||
@Comment("设备类型")
|
||||
private String deviceType;
|
||||
|
||||
@Formula(
|
||||
"(select i.name\n"
|
||||
+ "from t_dictionary d,\n"
|
||||
+ " t_dictionary_item i\n"
|
||||
+ "where d.id = i.dictionary_id\n"
|
||||
+ " and d.code = 'ac.device.type'\n"
|
||||
+ " and i.code = device_type)")
|
||||
private String deviceTypeName;
|
||||
|
||||
private String location;
|
||||
|
||||
|
||||
private String archiveStatus;
|
||||
|
||||
private String archiveStatusName;
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
package cn.lihongjie.coal.acDevice.dto;
|
||||
|
||||
import cn.lihongjie.coal.acDevice.entity.AcDeviceEntity;
|
||||
import cn.lihongjie.coal.base.dto.OrgCommonDto;
|
||||
import cn.lihongjie.coal.errorMsg.ErrorMsgCode;
|
||||
import cn.lihongjie.coal.validator.OrgUniq;
|
||||
import cn.lihongjie.coal.validator.RequireCode;
|
||||
import cn.lihongjie.coal.validator.RequireName;
|
||||
|
||||
import jakarta.persistence.ManyToOne;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import org.hibernate.annotations.Comment;
|
||||
|
||||
@Data
|
||||
@RequireName
|
||||
@RequireCode
|
||||
@OrgUniq(fields = {"code"}, message = ErrorMsgCode.UNIQ_CODE, entityClass = AcDeviceEntity.class)
|
||||
@OrgUniq(fields = {"name"}, message = ErrorMsgCode.UNIQ_NAME, entityClass = AcDeviceEntity.class)
|
||||
public class CreateAcDeviceDto extends OrgCommonDto {
|
||||
|
||||
@ManyToOne
|
||||
String supplier;
|
||||
|
||||
@ManyToOne
|
||||
String dataCollector;
|
||||
|
||||
@Comment("设备类型")
|
||||
private String deviceType;
|
||||
|
||||
|
||||
|
||||
private String location;
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
package cn.lihongjie.coal.acDevice.dto;
|
||||
|
||||
import cn.lihongjie.coal.acDevice.entity.AcDeviceEntity;
|
||||
import cn.lihongjie.coal.base.dto.OrgCommonDto;
|
||||
import cn.lihongjie.coal.errorMsg.ErrorMsgCode;
|
||||
import cn.lihongjie.coal.validator.OrgUniq;
|
||||
import cn.lihongjie.coal.validator.RequireCode;
|
||||
import cn.lihongjie.coal.validator.RequireName;
|
||||
|
||||
import jakarta.persistence.ManyToOne;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import org.hibernate.annotations.Comment;
|
||||
|
||||
@Data
|
||||
@RequireName
|
||||
@RequireCode
|
||||
@OrgUniq(fields = {"code"}, message = ErrorMsgCode.UNIQ_CODE, entityClass = AcDeviceEntity.class)
|
||||
@OrgUniq(fields = {"name"}, message = ErrorMsgCode.UNIQ_NAME, entityClass = AcDeviceEntity.class)
|
||||
public class UpdateAcDeviceDto extends OrgCommonDto {
|
||||
|
||||
@ManyToOne
|
||||
String supplier;
|
||||
|
||||
@ManyToOne
|
||||
String dataCollector;
|
||||
|
||||
@Comment("设备类型")
|
||||
private String deviceType;
|
||||
|
||||
|
||||
|
||||
private String location;
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
package cn.lihongjie.coal.acDevice.entity;
|
||||
|
||||
import cn.lihongjie.coal.acDeviceSupplier.entity.AcDeviceSupplierEntity;
|
||||
import cn.lihongjie.coal.base.entity.OrgCommonEntity;
|
||||
import cn.lihongjie.coal.dataCollector.entity.DataCollectorEntity;
|
||||
|
||||
import jakarta.persistence.Entity;
|
||||
import jakarta.persistence.ManyToOne;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import org.hibernate.annotations.ColumnDefault;
|
||||
import org.hibernate.annotations.Comment;
|
||||
import org.hibernate.annotations.Formula;
|
||||
|
||||
@Data
|
||||
@Entity
|
||||
public class AcDeviceEntity extends OrgCommonEntity {
|
||||
@ManyToOne
|
||||
AcDeviceSupplierEntity supplier;
|
||||
|
||||
@ManyToOne
|
||||
DataCollectorEntity dataCollector;
|
||||
|
||||
@Comment("设备类型")
|
||||
private String deviceType;
|
||||
|
||||
@Formula(
|
||||
"(select i.name\n"
|
||||
+ "from t_dictionary d,\n"
|
||||
+ " t_dictionary_item i\n"
|
||||
+ "where d.id = i.dictionary_id\n"
|
||||
+ " and d.code = 'ac.device.type'\n"
|
||||
+ " and i.code = device_type)")
|
||||
private String deviceTypeName;
|
||||
|
||||
private String location;
|
||||
@Comment("归档状态")
|
||||
@ColumnDefault("'0'")
|
||||
private String archiveStatus = "0";
|
||||
|
||||
@Formula(
|
||||
"(select i.name\n"
|
||||
+ "from t_dictionary d,\n"
|
||||
+ " t_dictionary_item i\n"
|
||||
+ "where d.id = i.dictionary_id\n"
|
||||
+ " and d.code = 'archiveStatus'\n"
|
||||
+ " and i.code = archive_status)")
|
||||
private String archiveStatusName;
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
package cn.lihongjie.coal.acDevice.mapper;
|
||||
|
||||
import cn.lihongjie.coal.acDevice.dto.AcDeviceDto;
|
||||
import cn.lihongjie.coal.acDevice.dto.CreateAcDeviceDto;
|
||||
import cn.lihongjie.coal.acDevice.dto.UpdateAcDeviceDto;
|
||||
import cn.lihongjie.coal.acDevice.entity.AcDeviceEntity;
|
||||
import cn.lihongjie.coal.base.mapper.BaseMapper;
|
||||
import cn.lihongjie.coal.base.mapper.CommonEntityMapper;
|
||||
import cn.lihongjie.coal.base.mapper.CommonMapper;
|
||||
|
||||
import org.mapstruct.Mapper;
|
||||
import org.mapstruct.control.DeepClone;
|
||||
|
||||
@Mapper(
|
||||
componentModel = org.mapstruct.MappingConstants.ComponentModel.SPRING,
|
||||
uses = {CommonMapper.class, CommonEntityMapper.class},
|
||||
mappingControl = DeepClone.class)
|
||||
public interface AcDeviceMapper
|
||||
extends BaseMapper<AcDeviceEntity, AcDeviceDto, CreateAcDeviceDto, UpdateAcDeviceDto> {}
|
||||
@@ -0,0 +1,9 @@
|
||||
package cn.lihongjie.coal.acDevice.repository;
|
||||
|
||||
import cn.lihongjie.coal.acDevice.entity.AcDeviceEntity;
|
||||
import cn.lihongjie.coal.base.dao.BaseRepository;
|
||||
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
@Repository
|
||||
public interface AcDeviceRepository extends BaseRepository<AcDeviceEntity> {}
|
||||
@@ -0,0 +1,120 @@
|
||||
package cn.lihongjie.coal.acDevice.service;
|
||||
|
||||
import cn.lihongjie.coal.acDevice.dto.AcDeviceDto;
|
||||
import cn.lihongjie.coal.acDevice.dto.CreateAcDeviceDto;
|
||||
import cn.lihongjie.coal.acDevice.dto.UpdateAcDeviceDto;
|
||||
import cn.lihongjie.coal.acDevice.entity.AcDeviceEntity;
|
||||
import cn.lihongjie.coal.acDevice.mapper.AcDeviceMapper;
|
||||
import cn.lihongjie.coal.acDevice.repository.AcDeviceRepository;
|
||||
import cn.lihongjie.coal.base.dto.CommonQuery;
|
||||
import cn.lihongjie.coal.base.dto.IdRequest;
|
||||
import cn.lihongjie.coal.base.service.BaseService;
|
||||
import cn.lihongjie.coal.common.ArchiveUtils;
|
||||
import cn.lihongjie.coal.dbFunctions.DbFunctionService;
|
||||
import cn.lihongjie.coal.exception.BizException;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.core.convert.ConversionService;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.PageRequest;
|
||||
import org.springframework.data.domain.Sort;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
@Service
|
||||
@Slf4j
|
||||
@Transactional
|
||||
public class AcDeviceService extends BaseService<AcDeviceEntity, AcDeviceRepository> {
|
||||
@Autowired private AcDeviceRepository repository;
|
||||
|
||||
@Autowired private AcDeviceMapper mapper;
|
||||
|
||||
@Autowired private ConversionService conversionService;
|
||||
|
||||
@Autowired private DbFunctionService dbFunctionService;
|
||||
|
||||
public AcDeviceDto create(CreateAcDeviceDto request) {
|
||||
AcDeviceEntity entity = mapper.toEntity(request);
|
||||
|
||||
this.repository.save(entity);
|
||||
return getById(entity.getId());
|
||||
}
|
||||
|
||||
public AcDeviceDto update(UpdateAcDeviceDto request) {
|
||||
AcDeviceEntity entity = this.repository.get(request.getId());
|
||||
ArchiveUtils.checkArchiveStatus(
|
||||
entity,
|
||||
AcDeviceEntity::getArchiveStatus,
|
||||
x -> "0",
|
||||
(e, actual, expected) -> {
|
||||
throw new BizException("数据 " + "已归档,无法编辑");
|
||||
});
|
||||
this.mapper.updateEntity(entity, request);
|
||||
|
||||
this.repository.save(entity);
|
||||
|
||||
return getById(entity.getId());
|
||||
}
|
||||
|
||||
public void delete(IdRequest request) {
|
||||
ArchiveUtils.checkArchiveStatus(
|
||||
this.repository::findAllById,
|
||||
request.getIds(),
|
||||
AcDeviceEntity::getArchiveStatus,
|
||||
x -> "0",
|
||||
(e, actual, expected) -> {
|
||||
throw new BizException("数据 " + "已归档,无法删除");
|
||||
});
|
||||
this.repository.deleteAllById(request.getIds());
|
||||
}
|
||||
|
||||
public AcDeviceDto getById(String id) {
|
||||
AcDeviceEntity entity = repository.get(id);
|
||||
|
||||
return mapper.toDto(entity);
|
||||
}
|
||||
|
||||
public Page<AcDeviceDto> list(CommonQuery query) {
|
||||
Page<AcDeviceEntity> page =
|
||||
repository.findAll(
|
||||
query.specification(conversionService),
|
||||
PageRequest.of(
|
||||
query.getPageNo(),
|
||||
query.getPageSize(),
|
||||
Sort.by(query.getOrders())));
|
||||
|
||||
return page.map(this.mapper::toDto);
|
||||
}
|
||||
|
||||
public void archive(IdRequest dto) {
|
||||
this.repository.findAllById(dto.getIds()).stream()
|
||||
.peek(
|
||||
x ->
|
||||
ArchiveUtils.checkArchiveStatus(
|
||||
x,
|
||||
AcDeviceEntity::getArchiveStatus,
|
||||
y -> "0",
|
||||
(e, actual, expected) -> {
|
||||
throw new BizException("数据 " + "已归档,无法再次归档");
|
||||
}))
|
||||
.peek(x -> x.setArchiveStatus("1"))
|
||||
.forEach(this.repository::save);
|
||||
}
|
||||
|
||||
public void unarchive(IdRequest dto) {
|
||||
this.repository.findAllById(dto.getIds()).stream()
|
||||
.peek(
|
||||
x ->
|
||||
ArchiveUtils.checkArchiveStatus(
|
||||
x,
|
||||
AcDeviceEntity::getArchiveStatus,
|
||||
y -> "1",
|
||||
(e, actual, expected) -> {
|
||||
throw new BizException("数据" + "未归档,无法取消归档");
|
||||
}))
|
||||
.peek(x -> x.setArchiveStatus("0"))
|
||||
.forEach(this.repository::save);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
package cn.lihongjie.coal.acDeviceData.controller;
|
||||
|
||||
import cn.lihongjie.coal.acDeviceData.dto.AcDeviceDataDto;
|
||||
import cn.lihongjie.coal.acDeviceData.dto.CreateAcDeviceDataDto;
|
||||
import cn.lihongjie.coal.acDeviceData.dto.UpdateAcDeviceDataDto;
|
||||
import cn.lihongjie.coal.acDeviceData.service.AcDeviceDataService;
|
||||
import cn.lihongjie.coal.annotation.OrgScope;
|
||||
import cn.lihongjie.coal.annotation.SysLog;
|
||||
import cn.lihongjie.coal.base.dto.CommonQuery;
|
||||
import cn.lihongjie.coal.base.dto.IdRequest;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/acDeviceData")
|
||||
@SysLog(module = "门禁设备数据")
|
||||
@Slf4j
|
||||
@OrgScope
|
||||
public class AcDeviceDataController {
|
||||
@Autowired private AcDeviceDataService service;
|
||||
|
||||
@PostMapping("/create")
|
||||
public AcDeviceDataDto create(@RequestBody CreateAcDeviceDataDto request) {
|
||||
return this.service.create(request);
|
||||
}
|
||||
|
||||
@PostMapping("/update")
|
||||
public AcDeviceDataDto update(@RequestBody UpdateAcDeviceDataDto request) {
|
||||
return this.service.update(request);
|
||||
}
|
||||
|
||||
@PostMapping("/delete")
|
||||
public Object delete(@RequestBody IdRequest request) {
|
||||
this.service.delete(request);
|
||||
return true;
|
||||
}
|
||||
|
||||
@PostMapping("/getById")
|
||||
public AcDeviceDataDto getById(@RequestBody IdRequest request) {
|
||||
return this.service.getById(request.getId());
|
||||
}
|
||||
|
||||
@PostMapping("/list")
|
||||
public Page<AcDeviceDataDto> list(@RequestBody CommonQuery request) {
|
||||
return this.service.list(request);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,65 @@
|
||||
package cn.lihongjie.coal.acDeviceData.dto;
|
||||
|
||||
import cn.lihongjie.coal.base.dto.OrgCommonDto;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import org.hibernate.annotations.Comment;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
@Data
|
||||
public class AcDeviceDataDto extends OrgCommonDto {
|
||||
@Comment("原始数据id")
|
||||
private String srcId;
|
||||
|
||||
@Comment("停车场id")
|
||||
private String parkNo;
|
||||
|
||||
@Comment("停车场名称")
|
||||
private String parkName;
|
||||
|
||||
@Comment("大门id")
|
||||
private String gateNo;
|
||||
|
||||
@Comment("大门名称")
|
||||
private String gateName;
|
||||
|
||||
@Comment("车道id")
|
||||
private String laneNo;
|
||||
|
||||
@Comment("车道名称")
|
||||
private String laneName;
|
||||
|
||||
@Comment("车牌号")
|
||||
private String plateNo;
|
||||
|
||||
@Comment("方向编码")
|
||||
private String direction;
|
||||
|
||||
@Comment("操作类型")
|
||||
private String operationType;
|
||||
|
||||
@Comment("车牌类型")
|
||||
private String plateType;
|
||||
|
||||
@Comment("车牌颜色")
|
||||
private String plateColor;
|
||||
|
||||
@Comment("通行时间")
|
||||
private LocalDateTime passTime;
|
||||
|
||||
@Comment("车辆颜色")
|
||||
private String vehicleColor;
|
||||
|
||||
private String vehicleShade;
|
||||
|
||||
private String parkingType;
|
||||
|
||||
@Comment("车辆类型")
|
||||
private String vehicleType;
|
||||
|
||||
@Comment("信任度")
|
||||
private String belief;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
package cn.lihongjie.coal.acDeviceData.dto;
|
||||
|
||||
import cn.lihongjie.coal.base.dto.OrgCommonDto;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class CreateAcDeviceDataDto extends OrgCommonDto {}
|
||||
@@ -0,0 +1,8 @@
|
||||
package cn.lihongjie.coal.acDeviceData.dto;
|
||||
|
||||
import cn.lihongjie.coal.base.dto.OrgCommonDto;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class UpdateAcDeviceDataDto extends OrgCommonDto {}
|
||||
@@ -0,0 +1,86 @@
|
||||
package cn.lihongjie.coal.acDeviceData.entity;
|
||||
|
||||
import cn.lihongjie.coal.acDevice.entity.AcDeviceEntity;
|
||||
import cn.lihongjie.coal.base.entity.OrgCommonEntity;
|
||||
|
||||
import jakarta.persistence.Entity;
|
||||
import jakarta.persistence.ManyToOne;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import org.hibernate.annotations.Comment;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
@Data
|
||||
@Entity
|
||||
public class AcDeviceDataEntity extends OrgCommonEntity {
|
||||
|
||||
@ManyToOne
|
||||
private AcDeviceEntity device;
|
||||
|
||||
@Comment("原始数据id")
|
||||
private String srcId;
|
||||
|
||||
@Comment("停车场id")
|
||||
private String parkNo;
|
||||
|
||||
@Comment("停车场名称")
|
||||
private String parkName;
|
||||
|
||||
@Comment("大门id")
|
||||
private String gateNo;
|
||||
|
||||
@Comment("大门名称")
|
||||
private String gateName;
|
||||
|
||||
@Comment("车道id")
|
||||
private String laneNo;
|
||||
|
||||
@Comment("车道名称")
|
||||
private String laneName;
|
||||
|
||||
@Comment("车牌号")
|
||||
private String plateNo;
|
||||
|
||||
@Comment("方向编码")
|
||||
private String direction;
|
||||
@Comment("方向名称")
|
||||
private String directionName;
|
||||
|
||||
@Comment("操作类型")
|
||||
private String operationType;
|
||||
|
||||
@Comment("车牌类型")
|
||||
private String plateType;
|
||||
@Comment("车牌类型名称")
|
||||
private String plateTypeName;
|
||||
|
||||
@Comment("车牌颜色")
|
||||
private String plateColor;
|
||||
@Comment("车牌颜色名称")
|
||||
private String plateColorName;
|
||||
|
||||
@Comment("通行时间")
|
||||
private LocalDateTime passTime;
|
||||
|
||||
@Comment("车辆颜色")
|
||||
private String vehicleColor;
|
||||
@Comment("车辆颜色名称")
|
||||
private String vehicleColorName;
|
||||
|
||||
private String vehicleShade;
|
||||
|
||||
private String parkingType;
|
||||
@Comment("停车类型名称")
|
||||
private String parkingTypeName;
|
||||
|
||||
@Comment("车辆类型")
|
||||
private String vehicleType;
|
||||
@Comment("车辆类型名称")
|
||||
private String vehicleTypeName;
|
||||
|
||||
|
||||
@Comment("信任度")
|
||||
private String belief;
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
package cn.lihongjie.coal.acDeviceData.mapper;
|
||||
|
||||
import cn.lihongjie.coal.acDeviceData.dto.AcDeviceDataDto;
|
||||
import cn.lihongjie.coal.acDeviceData.dto.CreateAcDeviceDataDto;
|
||||
import cn.lihongjie.coal.acDeviceData.dto.UpdateAcDeviceDataDto;
|
||||
import cn.lihongjie.coal.acDeviceData.entity.AcDeviceDataEntity;
|
||||
import cn.lihongjie.coal.base.mapper.BaseMapper;
|
||||
import cn.lihongjie.coal.base.mapper.CommonEntityMapper;
|
||||
import cn.lihongjie.coal.base.mapper.CommonMapper;
|
||||
|
||||
import org.mapstruct.Mapper;
|
||||
import org.mapstruct.control.DeepClone;
|
||||
|
||||
@Mapper(
|
||||
componentModel = org.mapstruct.MappingConstants.ComponentModel.SPRING,
|
||||
uses = {CommonMapper.class, CommonEntityMapper.class},
|
||||
mappingControl = DeepClone.class)
|
||||
public interface AcDeviceDataMapper
|
||||
extends BaseMapper<
|
||||
AcDeviceDataEntity,
|
||||
AcDeviceDataDto,
|
||||
CreateAcDeviceDataDto,
|
||||
UpdateAcDeviceDataDto> {}
|
||||
@@ -0,0 +1,9 @@
|
||||
package cn.lihongjie.coal.acDeviceData.repository;
|
||||
|
||||
import cn.lihongjie.coal.acDeviceData.entity.AcDeviceDataEntity;
|
||||
import cn.lihongjie.coal.base.dao.BaseRepository;
|
||||
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
@Repository
|
||||
public interface AcDeviceDataRepository extends BaseRepository<AcDeviceDataEntity> {}
|
||||
@@ -0,0 +1,73 @@
|
||||
package cn.lihongjie.coal.acDeviceData.service;
|
||||
|
||||
import cn.lihongjie.coal.acDeviceData.dto.AcDeviceDataDto;
|
||||
import cn.lihongjie.coal.acDeviceData.dto.CreateAcDeviceDataDto;
|
||||
import cn.lihongjie.coal.acDeviceData.dto.UpdateAcDeviceDataDto;
|
||||
import cn.lihongjie.coal.acDeviceData.entity.AcDeviceDataEntity;
|
||||
import cn.lihongjie.coal.acDeviceData.mapper.AcDeviceDataMapper;
|
||||
import cn.lihongjie.coal.acDeviceData.repository.AcDeviceDataRepository;
|
||||
import cn.lihongjie.coal.base.dto.CommonQuery;
|
||||
import cn.lihongjie.coal.base.dto.IdRequest;
|
||||
import cn.lihongjie.coal.base.service.BaseService;
|
||||
import cn.lihongjie.coal.dbFunctions.DbFunctionService;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.core.convert.ConversionService;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.PageRequest;
|
||||
import org.springframework.data.domain.Sort;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
@Service
|
||||
@Slf4j
|
||||
@Transactional
|
||||
public class AcDeviceDataService extends BaseService<AcDeviceDataEntity, AcDeviceDataRepository> {
|
||||
@Autowired private AcDeviceDataRepository repository;
|
||||
|
||||
@Autowired private AcDeviceDataMapper mapper;
|
||||
|
||||
@Autowired private ConversionService conversionService;
|
||||
|
||||
@Autowired private DbFunctionService dbFunctionService;
|
||||
|
||||
public AcDeviceDataDto create(CreateAcDeviceDataDto request) {
|
||||
AcDeviceDataEntity entity = mapper.toEntity(request);
|
||||
|
||||
this.repository.save(entity);
|
||||
return getById(entity.getId());
|
||||
}
|
||||
|
||||
public AcDeviceDataDto update(UpdateAcDeviceDataDto request) {
|
||||
AcDeviceDataEntity entity = this.repository.get(request.getId());
|
||||
this.mapper.updateEntity(entity, request);
|
||||
|
||||
this.repository.save(entity);
|
||||
|
||||
return getById(entity.getId());
|
||||
}
|
||||
|
||||
public void delete(IdRequest request) {
|
||||
this.repository.deleteAllById(request.getIds());
|
||||
}
|
||||
|
||||
public AcDeviceDataDto getById(String id) {
|
||||
AcDeviceDataEntity entity = repository.get(id);
|
||||
|
||||
return mapper.toDto(entity);
|
||||
}
|
||||
|
||||
public Page<AcDeviceDataDto> list(CommonQuery query) {
|
||||
Page<AcDeviceDataEntity> page =
|
||||
repository.findAll(
|
||||
query.specification(conversionService),
|
||||
PageRequest.of(
|
||||
query.getPageNo(),
|
||||
query.getPageSize(),
|
||||
Sort.by(query.getOrders())));
|
||||
|
||||
return page.map(this.mapper::toDto);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,66 @@
|
||||
package cn.lihongjie.coal.acDeviceSupplier.controller;
|
||||
|
||||
import cn.lihongjie.coal.acDeviceSupplier.dto.AcDeviceSupplierDto;
|
||||
import cn.lihongjie.coal.acDeviceSupplier.dto.CreateAcDeviceSupplierDto;
|
||||
import cn.lihongjie.coal.acDeviceSupplier.dto.UpdateAcDeviceSupplierDto;
|
||||
import cn.lihongjie.coal.acDeviceSupplier.service.AcDeviceSupplierService;
|
||||
import cn.lihongjie.coal.annotation.OrgScope;
|
||||
import cn.lihongjie.coal.annotation.SysLog;
|
||||
import cn.lihongjie.coal.base.dto.CommonQuery;
|
||||
import cn.lihongjie.coal.base.dto.IdRequest;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/acDeviceSupplier")
|
||||
@SysLog(module = "门禁设备厂商")
|
||||
@Slf4j
|
||||
@OrgScope
|
||||
public class AcDeviceSupplierController {
|
||||
@Autowired private AcDeviceSupplierService service;
|
||||
|
||||
@PostMapping("/create")
|
||||
public AcDeviceSupplierDto create(@RequestBody CreateAcDeviceSupplierDto request) {
|
||||
return this.service.create(request);
|
||||
}
|
||||
|
||||
@PostMapping("/update")
|
||||
public AcDeviceSupplierDto update(@RequestBody UpdateAcDeviceSupplierDto request) {
|
||||
return this.service.update(request);
|
||||
}
|
||||
|
||||
@PostMapping("/delete")
|
||||
public Object delete(@RequestBody IdRequest request) {
|
||||
this.service.delete(request);
|
||||
return true;
|
||||
}
|
||||
|
||||
@PostMapping("/getById")
|
||||
public AcDeviceSupplierDto getById(@RequestBody IdRequest request) {
|
||||
return this.service.getById(request.getId());
|
||||
}
|
||||
|
||||
@PostMapping("/list")
|
||||
public Page<AcDeviceSupplierDto> list(@RequestBody CommonQuery request) {
|
||||
return this.service.list(request);
|
||||
}
|
||||
|
||||
@PostMapping("/archive")
|
||||
public Object archive(@RequestBody IdRequest request) {
|
||||
this.service.archive(request);
|
||||
return true;
|
||||
}
|
||||
|
||||
@PostMapping("/unarchive")
|
||||
public Object unarchive(@RequestBody IdRequest request) {
|
||||
this.service.unarchive(request);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
package cn.lihongjie.coal.acDeviceSupplier.dto;
|
||||
|
||||
import cn.lihongjie.coal.base.dto.OrgCommonDto;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class AcDeviceSupplierDto extends OrgCommonDto {
|
||||
|
||||
private String contact;
|
||||
|
||||
private String contactPhone;
|
||||
|
||||
private String address;
|
||||
private String archiveStatus;
|
||||
|
||||
private String archiveStatusName;
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
package cn.lihongjie.coal.acDeviceSupplier.dto;
|
||||
|
||||
import cn.lihongjie.coal.base.dto.OrgCommonDto;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class CreateAcDeviceSupplierDto extends OrgCommonDto {
|
||||
|
||||
private String contact;
|
||||
|
||||
private String contactPhone;
|
||||
|
||||
private String address;
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
package cn.lihongjie.coal.acDeviceSupplier.dto;
|
||||
|
||||
import cn.lihongjie.coal.base.dto.OrgCommonDto;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class UpdateAcDeviceSupplierDto extends OrgCommonDto {
|
||||
|
||||
private String contact;
|
||||
|
||||
private String contactPhone;
|
||||
|
||||
private String address;
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
package cn.lihongjie.coal.acDeviceSupplier.entity;
|
||||
|
||||
import cn.lihongjie.coal.base.entity.OrgCommonEntity;
|
||||
|
||||
import jakarta.persistence.Entity;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import org.hibernate.annotations.ColumnDefault;
|
||||
import org.hibernate.annotations.Comment;
|
||||
import org.hibernate.annotations.Formula;
|
||||
|
||||
@Data
|
||||
@Entity
|
||||
public class AcDeviceSupplierEntity extends OrgCommonEntity {
|
||||
private String contact;
|
||||
|
||||
private String contactPhone;
|
||||
|
||||
private String address;
|
||||
|
||||
@Comment("归档状态")
|
||||
@ColumnDefault("'0'")
|
||||
private String archiveStatus;
|
||||
|
||||
@Formula(
|
||||
"(select i.name\n"
|
||||
+ "from t_dictionary d,\n"
|
||||
+ " t_dictionary_item i\n"
|
||||
+ "where d.id = i.dictionary_id\n"
|
||||
+ " and d.code = 'archiveStatus'\n"
|
||||
+ " and i.code = archive_status)")
|
||||
private String archiveStatusName;
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
package cn.lihongjie.coal.acDeviceSupplier.mapper;
|
||||
|
||||
import cn.lihongjie.coal.acDeviceSupplier.dto.AcDeviceSupplierDto;
|
||||
import cn.lihongjie.coal.acDeviceSupplier.dto.CreateAcDeviceSupplierDto;
|
||||
import cn.lihongjie.coal.acDeviceSupplier.dto.UpdateAcDeviceSupplierDto;
|
||||
import cn.lihongjie.coal.acDeviceSupplier.entity.AcDeviceSupplierEntity;
|
||||
import cn.lihongjie.coal.base.mapper.BaseMapper;
|
||||
import cn.lihongjie.coal.base.mapper.CommonEntityMapper;
|
||||
import cn.lihongjie.coal.base.mapper.CommonMapper;
|
||||
|
||||
import org.mapstruct.Mapper;
|
||||
import org.mapstruct.control.DeepClone;
|
||||
|
||||
@Mapper(
|
||||
componentModel = org.mapstruct.MappingConstants.ComponentModel.SPRING,
|
||||
uses = {CommonMapper.class, CommonEntityMapper.class},
|
||||
mappingControl = DeepClone.class)
|
||||
public interface AcDeviceSupplierMapper
|
||||
extends BaseMapper<
|
||||
AcDeviceSupplierEntity,
|
||||
AcDeviceSupplierDto,
|
||||
CreateAcDeviceSupplierDto,
|
||||
UpdateAcDeviceSupplierDto> {}
|
||||
@@ -0,0 +1,9 @@
|
||||
package cn.lihongjie.coal.acDeviceSupplier.repository;
|
||||
|
||||
import cn.lihongjie.coal.acDeviceSupplier.entity.AcDeviceSupplierEntity;
|
||||
import cn.lihongjie.coal.base.dao.BaseRepository;
|
||||
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
@Repository
|
||||
public interface AcDeviceSupplierRepository extends BaseRepository<AcDeviceSupplierEntity> {}
|
||||
@@ -0,0 +1,121 @@
|
||||
package cn.lihongjie.coal.acDeviceSupplier.service;
|
||||
|
||||
import cn.lihongjie.coal.acDeviceSupplier.dto.AcDeviceSupplierDto;
|
||||
import cn.lihongjie.coal.acDeviceSupplier.dto.CreateAcDeviceSupplierDto;
|
||||
import cn.lihongjie.coal.acDeviceSupplier.dto.UpdateAcDeviceSupplierDto;
|
||||
import cn.lihongjie.coal.acDeviceSupplier.entity.AcDeviceSupplierEntity;
|
||||
import cn.lihongjie.coal.acDeviceSupplier.mapper.AcDeviceSupplierMapper;
|
||||
import cn.lihongjie.coal.acDeviceSupplier.repository.AcDeviceSupplierRepository;
|
||||
import cn.lihongjie.coal.base.dto.CommonQuery;
|
||||
import cn.lihongjie.coal.base.dto.IdRequest;
|
||||
import cn.lihongjie.coal.base.service.BaseService;
|
||||
import cn.lihongjie.coal.common.ArchiveUtils;
|
||||
import cn.lihongjie.coal.dbFunctions.DbFunctionService;
|
||||
import cn.lihongjie.coal.exception.BizException;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.core.convert.ConversionService;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.PageRequest;
|
||||
import org.springframework.data.domain.Sort;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
@Service
|
||||
@Slf4j
|
||||
@Transactional
|
||||
public class AcDeviceSupplierService
|
||||
extends BaseService<AcDeviceSupplierEntity, AcDeviceSupplierRepository> {
|
||||
@Autowired private AcDeviceSupplierRepository repository;
|
||||
|
||||
@Autowired private AcDeviceSupplierMapper mapper;
|
||||
|
||||
@Autowired private ConversionService conversionService;
|
||||
|
||||
@Autowired private DbFunctionService dbFunctionService;
|
||||
|
||||
public AcDeviceSupplierDto create(CreateAcDeviceSupplierDto request) {
|
||||
AcDeviceSupplierEntity entity = mapper.toEntity(request);
|
||||
|
||||
this.repository.save(entity);
|
||||
return getById(entity.getId());
|
||||
}
|
||||
|
||||
public AcDeviceSupplierDto update(UpdateAcDeviceSupplierDto request) {
|
||||
AcDeviceSupplierEntity entity = this.repository.get(request.getId());
|
||||
ArchiveUtils.checkArchiveStatus(
|
||||
entity,
|
||||
AcDeviceSupplierEntity::getArchiveStatus,
|
||||
x -> "0",
|
||||
(e, actual, expected) -> {
|
||||
throw new BizException("数据 " + "已归档,无法编辑");
|
||||
});
|
||||
this.mapper.updateEntity(entity, request);
|
||||
|
||||
this.repository.save(entity);
|
||||
|
||||
return getById(entity.getId());
|
||||
}
|
||||
|
||||
public void delete(IdRequest request) {
|
||||
ArchiveUtils.checkArchiveStatus(
|
||||
this.repository::findAllById,
|
||||
request.getIds(),
|
||||
AcDeviceSupplierEntity::getArchiveStatus,
|
||||
x -> "0",
|
||||
(e, actual, expected) -> {
|
||||
throw new BizException("数据 " + "已归档,无法删除");
|
||||
});
|
||||
this.repository.deleteAllById(request.getIds());
|
||||
}
|
||||
|
||||
public AcDeviceSupplierDto getById(String id) {
|
||||
AcDeviceSupplierEntity entity = repository.get(id);
|
||||
|
||||
return mapper.toDto(entity);
|
||||
}
|
||||
|
||||
public Page<AcDeviceSupplierDto> list(CommonQuery query) {
|
||||
Page<AcDeviceSupplierEntity> page =
|
||||
repository.findAll(
|
||||
query.specification(conversionService),
|
||||
PageRequest.of(
|
||||
query.getPageNo(),
|
||||
query.getPageSize(),
|
||||
Sort.by(query.getOrders())));
|
||||
|
||||
return page.map(this.mapper::toDto);
|
||||
}
|
||||
|
||||
public void archive(IdRequest dto) {
|
||||
this.repository.findAllById(dto.getIds()).stream()
|
||||
.peek(
|
||||
x ->
|
||||
ArchiveUtils.checkArchiveStatus(
|
||||
x,
|
||||
AcDeviceSupplierEntity::getArchiveStatus,
|
||||
y -> "0",
|
||||
(e, actual, expected) -> {
|
||||
throw new BizException("数据 " + "已归档,无法再次归档");
|
||||
}))
|
||||
.peek(x -> x.setArchiveStatus("1"))
|
||||
.forEach(this.repository::save);
|
||||
}
|
||||
|
||||
public void unarchive(IdRequest dto) {
|
||||
this.repository.findAllById(dto.getIds()).stream()
|
||||
.peek(
|
||||
x ->
|
||||
ArchiveUtils.checkArchiveStatus(
|
||||
x,
|
||||
AcDeviceSupplierEntity::getArchiveStatus,
|
||||
y -> "1",
|
||||
(e, actual, expected) -> {
|
||||
throw new BizException("数据" + "未归档,无法取消归档");
|
||||
}))
|
||||
.peek(x -> x.setArchiveStatus("0"))
|
||||
.forEach(this.repository::save);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,99 @@
|
||||
package cn.lihongjie.coal.dataCollector.listener;
|
||||
|
||||
import cn.lihongjie.coal.dataCollector.entity.DataCollectorEntity;
|
||||
import cn.lihongjie.coal.dataCollector.service.DataCollectorService;
|
||||
import cn.lihongjie.coal.dataCollectorLog.entity.DataCollectorLogEntity;
|
||||
import cn.lihongjie.coal.dataCollectorLog.service.DataCollectorLogService;
|
||||
import cn.lihongjie.coal.rabbitmq.RabbitMQConfiguration;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
import org.apache.commons.codec.digest.HmacAlgorithms;
|
||||
import org.apache.commons.codec.digest.HmacUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.amqp.rabbit.annotation.Exchange;
|
||||
import org.springframework.amqp.rabbit.annotation.QueueBinding;
|
||||
import org.springframework.amqp.rabbit.annotation.RabbitListener;
|
||||
import org.springframework.amqp.support.AmqpHeaders;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.messaging.handler.annotation.Headers;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.*;
|
||||
|
||||
@Component
|
||||
@Slf4j
|
||||
public class DataCollectorListener {
|
||||
|
||||
@Autowired DataCollectorService dataCollectorService;
|
||||
|
||||
@Autowired
|
||||
DataCollectorLogService dataCollectorLogService;
|
||||
|
||||
@RabbitListener(
|
||||
bindings = {
|
||||
@QueueBinding(
|
||||
value =
|
||||
@org.springframework.amqp.rabbit.annotation.Queue(
|
||||
value = "dataCollector.status",
|
||||
durable = "true"),
|
||||
exchange =
|
||||
@org.springframework.amqp.rabbit.annotation.Exchange(
|
||||
value = RabbitMQConfiguration.SYS_EXCHANGE,
|
||||
declare = Exchange.FALSE),
|
||||
key = "dataCollector.*")
|
||||
})
|
||||
@Transactional
|
||||
public void handleDataCollectorMessage(String body, @Headers Map<String, Object> headers) {
|
||||
|
||||
Object key = headers.get("appKey");
|
||||
|
||||
if (key == null) {
|
||||
log.error("appKey is null");
|
||||
return;
|
||||
}
|
||||
|
||||
DataCollectorEntity dataCollector = dataCollectorService.findByAppKey(key.toString());
|
||||
|
||||
var sign =
|
||||
new HmacUtils(HmacAlgorithms.HMAC_SHA_256, dataCollector.getAppSecret())
|
||||
.hmacHex(body);
|
||||
|
||||
if (!StringUtils.equals(sign, headers.get("sign").toString())) {
|
||||
log.error("sign not match {} {}", sign, headers.get("sign"));
|
||||
return;
|
||||
}
|
||||
|
||||
DataCollectorLogEntity log = new DataCollectorLogEntity();
|
||||
log.setDataCollector(dataCollector);
|
||||
log.setOrganizationId(dataCollector.getOrganizationId() );
|
||||
log.setLogTime(LocalDateTime.now());
|
||||
Object rk = headers.get(AmqpHeaders.RECEIVED_ROUTING_KEY);
|
||||
|
||||
switch (rk.toString()) {
|
||||
case "dataCollector.online":
|
||||
dataCollector.setLastLoginTime(LocalDateTime.now());
|
||||
log.setContent("online");
|
||||
break;
|
||||
|
||||
case "dataCollector.offline":
|
||||
dataCollector.setLastLogoutTime(LocalDateTime.now());
|
||||
log.setContent("offline");
|
||||
break;
|
||||
|
||||
case "dataCollector.heartbeat":
|
||||
dataCollector.setHeartbeatTime(LocalDateTime.now());
|
||||
log.setContent("heartbeat");
|
||||
break;
|
||||
|
||||
default:
|
||||
DataCollectorListener.log.error("unknown routing key {}", rk);
|
||||
break;
|
||||
}
|
||||
|
||||
dataCollectorService.save(dataCollector);
|
||||
dataCollectorLogService.save(log);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,292 @@
|
||||
package cn.lihongjie.coal.dataCollector.listener;
|
||||
|
||||
import cn.lihongjie.coal.acDevice.entity.AcDeviceEntity;
|
||||
import cn.lihongjie.coal.acDevice.service.AcDeviceService;
|
||||
import cn.lihongjie.coal.acDeviceData.entity.AcDeviceDataEntity;
|
||||
import cn.lihongjie.coal.acDeviceData.service.AcDeviceDataService;
|
||||
import cn.lihongjie.coal.dataCollector.entity.DataCollectorEntity;
|
||||
import cn.lihongjie.coal.dataCollector.service.DataCollectorService;
|
||||
import cn.lihongjie.coal.dataCollectorLog.entity.DataCollectorLogEntity;
|
||||
import cn.lihongjie.coal.dataCollectorLog.service.DataCollectorLogService;
|
||||
import cn.lihongjie.coal.rabbitmq.RabbitMQConfiguration;
|
||||
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.databind.node.ArrayNode;
|
||||
|
||||
import jakarta.persistence.criteria.CriteriaBuilder;
|
||||
import jakarta.persistence.criteria.CriteriaQuery;
|
||||
import jakarta.persistence.criteria.Predicate;
|
||||
import jakarta.persistence.criteria.Root;
|
||||
|
||||
import lombok.SneakyThrows;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
import org.apache.commons.codec.digest.HmacAlgorithms;
|
||||
import org.apache.commons.codec.digest.HmacUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.amqp.rabbit.annotation.Exchange;
|
||||
import org.springframework.amqp.rabbit.annotation.QueueBinding;
|
||||
import org.springframework.amqp.rabbit.annotation.RabbitListener;
|
||||
import org.springframework.amqp.support.AmqpHeaders;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.data.jpa.domain.Specification;
|
||||
import org.springframework.messaging.handler.annotation.Headers;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.time.Instant;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.ZoneOffset;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.StreamSupport;
|
||||
|
||||
@Component
|
||||
@Slf4j
|
||||
public class PmsListener {
|
||||
|
||||
@Autowired DataCollectorService dataCollectorService;
|
||||
|
||||
@Autowired DataCollectorLogService dataCollectorLogService;
|
||||
|
||||
@Autowired ObjectMapper objectMapper;
|
||||
|
||||
@Autowired AcDeviceDataService acDeviceDataService;
|
||||
|
||||
@Autowired
|
||||
AcDeviceService acDeviceService;
|
||||
|
||||
@SneakyThrows
|
||||
@RabbitListener(
|
||||
bindings = {
|
||||
@QueueBinding(
|
||||
value =
|
||||
@org.springframework.amqp.rabbit.annotation.Queue(
|
||||
value = "pms.data",
|
||||
durable = "true"),
|
||||
exchange =
|
||||
@Exchange(
|
||||
value = RabbitMQConfiguration.SYS_EXCHANGE,
|
||||
declare = Exchange.FALSE),
|
||||
key = "pms.*")
|
||||
})
|
||||
@Transactional
|
||||
public void handlePmsMessage(String body, @Headers Map<String, Object> headers) {
|
||||
|
||||
Object key = headers.get("appKey");
|
||||
|
||||
if (key == null) {
|
||||
log.error("appKey is null");
|
||||
return;
|
||||
}
|
||||
|
||||
DataCollectorEntity dataCollector = dataCollectorService.findByAppKey(key.toString());
|
||||
|
||||
var sign =
|
||||
new HmacUtils(HmacAlgorithms.HMAC_SHA_256, dataCollector.getAppSecret())
|
||||
.hmacHex(body.getBytes(StandardCharsets.UTF_8));
|
||||
|
||||
if (!StringUtils.equals(sign, headers.get("sign").toString())) {
|
||||
log.error("sign not match {} {}", sign, headers.get("sign"));
|
||||
return;
|
||||
}
|
||||
|
||||
List<AcDeviceEntity> devices = acDeviceService.findAll(
|
||||
new Specification<AcDeviceEntity>() {
|
||||
@Override
|
||||
public Predicate toPredicate(
|
||||
Root<AcDeviceEntity> root,
|
||||
CriteriaQuery<?> query,
|
||||
CriteriaBuilder criteriaBuilder) {
|
||||
return criteriaBuilder.and(
|
||||
criteriaBuilder.equal(
|
||||
root.get("dataCollector").get("id"),
|
||||
dataCollector.getId()));
|
||||
}
|
||||
});
|
||||
|
||||
if (devices.isEmpty()){
|
||||
log.error("no device found for data collector: {}", dataCollector.getId());
|
||||
return;
|
||||
}
|
||||
|
||||
var device = devices.get(0);
|
||||
|
||||
JsonNode jsonNode = objectMapper.readTree(body);
|
||||
|
||||
DataCollectorLogEntity logEntity = new DataCollectorLogEntity();
|
||||
logEntity.setOrganizationId(dataCollector.getOrganizationId());
|
||||
logEntity.setDataCollector(dataCollector);
|
||||
|
||||
Object rk = headers.get(AmqpHeaders.RECEIVED_ROUTING_KEY);
|
||||
|
||||
logEntity.setLogTime(LocalDateTime.now());
|
||||
logEntity.setType(rk.toString());
|
||||
|
||||
switch (rk.toString()) {
|
||||
case "pms.passvehicleinfo" -> {
|
||||
ArrayNode nodes = (ArrayNode) jsonNode;
|
||||
var ids =
|
||||
StreamSupport.stream(nodes.spliterator(), false)
|
||||
.map(x -> x.get("id").asText())
|
||||
.toList();
|
||||
logEntity.setContent(StringUtils.join(ids, ","));
|
||||
|
||||
Map<String, AcDeviceDataEntity> srcIdMap = acDeviceDataService
|
||||
.findAll(
|
||||
new Specification<AcDeviceDataEntity>() {
|
||||
@Override
|
||||
public Predicate toPredicate(
|
||||
Root<AcDeviceDataEntity> root,
|
||||
CriteriaQuery<?> query,
|
||||
CriteriaBuilder criteriaBuilder) {
|
||||
return criteriaBuilder.and(
|
||||
criteriaBuilder.equal(
|
||||
root.get("device").get("id"),
|
||||
device.getId()),
|
||||
root.get("srcId").in(ids));
|
||||
}
|
||||
})
|
||||
.stream()
|
||||
.collect(Collectors.toMap(AcDeviceDataEntity::getSrcId, e -> e));
|
||||
|
||||
nodes.forEach(
|
||||
x -> {
|
||||
var id = x.get("id").asText();
|
||||
if (srcIdMap.containsKey(id)) {
|
||||
log.info("data already exists: {} {}", id, device.getId());
|
||||
return;
|
||||
}
|
||||
var parkbelonged = x.get("parkbelonged").asText();
|
||||
var parkname = x.get("parkname").asText();
|
||||
var gateno = x.get("gateno").asText();
|
||||
var gatename = x.get("gatename").asText();
|
||||
var laneno = x.get("laneno").asText();
|
||||
var lanename = x.get("lanename").asText();
|
||||
var plateno = x.get("plateno").asText();
|
||||
var cardno = x.get("cardno").asText();
|
||||
var direction = x.get("direction").asText();
|
||||
var operationtype = x.get("operationtype").asText();
|
||||
var platetype = x.get("platetype").asText();
|
||||
var platecolor = x.get("platecolor").asText();
|
||||
var passtime = x.get("passtime").asText();
|
||||
var vehiclecolor = x.get("vehiclecolor").asText();
|
||||
var vehicleshade = x.get("vehicleshade").asText();
|
||||
var parkingtype = x.get("parkingtype").asText();
|
||||
var vehicletype = x.get("vehicletype").asText();
|
||||
var belief = x.get("belief").asText();
|
||||
|
||||
AcDeviceDataEntity deviceData = new AcDeviceDataEntity();
|
||||
deviceData.setDevice(device);
|
||||
deviceData.setSrcId(id);
|
||||
deviceData.setParkNo(parkbelonged);
|
||||
deviceData.setParkName(parkname);
|
||||
deviceData.setGateNo(gateno);
|
||||
deviceData.setGateName(gatename);
|
||||
deviceData.setLaneNo(laneno);
|
||||
deviceData.setLaneName(lanename);
|
||||
deviceData.setPlateNo(plateno);
|
||||
deviceData.setDirection(direction);
|
||||
deviceData.setDirectionName(
|
||||
switch (direction) {
|
||||
case "0" -> "入场";
|
||||
case "1" -> "出场";
|
||||
default -> "未知";
|
||||
});
|
||||
|
||||
deviceData.setOperationType(operationtype);
|
||||
deviceData.setPlateType(platetype);
|
||||
deviceData.setPlateTypeName(
|
||||
switch (platetype) {
|
||||
case "0" -> "无类型";
|
||||
case "1" -> "92 式民用车";
|
||||
case "2" -> "警用车";
|
||||
case "3" -> "上下军车";
|
||||
case "4" -> "92 式武警车";
|
||||
case "5" -> "左右军车车牌类型(一行结构)";
|
||||
case "7" -> "02 式个性化车";
|
||||
case "8" -> "黄色双行尾牌";
|
||||
case "9" -> "04 式新军车";
|
||||
case "10" -> "使馆车";
|
||||
case "11" -> "一行结构的新 WJ 车";
|
||||
case "12" -> "两行结构的新 WJ 车";
|
||||
case "13" -> "黄色 1225 农用车";
|
||||
case "14" -> "绿色 1325 农用车";
|
||||
case "15" -> "黄色 1325 农用车";
|
||||
case "16" -> "摩托车";
|
||||
case "17" -> "13 式新武警总部一行车牌";
|
||||
case "18" -> "13 式新武警总部两行车牌";
|
||||
case "19" -> "民航车牌类型";
|
||||
case "100" -> "教练车";
|
||||
case "101" -> "临时行驶车";
|
||||
case "102" -> "挂车";
|
||||
case "103" -> "领馆汽车";
|
||||
case "104" -> "港澳入出车";
|
||||
case "105" -> "临时入境车";
|
||||
default -> "未知";
|
||||
});
|
||||
deviceData.setPlateColor(platecolor);
|
||||
deviceData.setPlateColorName(
|
||||
switch (platecolor) {
|
||||
case "0" -> "其他";
|
||||
case "1" -> "蓝色";
|
||||
case "2" -> "黄色";
|
||||
case "3" -> "黑色";
|
||||
case "4" -> "白色";
|
||||
case "5" -> "绿色";
|
||||
default -> "未知";
|
||||
});
|
||||
deviceData.setPassTime(
|
||||
LocalDateTime.ofInstant(
|
||||
Instant.ofEpochMilli(Long.parseLong(passtime)),
|
||||
ZoneOffset.ofHours(8)));
|
||||
deviceData.setVehicleColor(vehiclecolor);
|
||||
deviceData.setVehicleColorName(
|
||||
switch (vehiclecolor) {
|
||||
case "0" -> "其它";
|
||||
case "1" -> "白色";
|
||||
case "2" -> "银色";
|
||||
case "3" -> "灰色";
|
||||
case "4" -> "黑色";
|
||||
case "5" -> "红色";
|
||||
case "6" -> "深蓝";
|
||||
case "7" -> "蓝色";
|
||||
case "8" -> "黄色";
|
||||
case "9" -> "绿色";
|
||||
case "10" -> "棕色";
|
||||
default -> "未知";
|
||||
});
|
||||
deviceData.setVehicleShade(vehicleshade);
|
||||
deviceData.setParkingType(parkingtype);
|
||||
deviceData.setParkingTypeName(
|
||||
switch (parkingtype) {
|
||||
case "0" -> "固定车";
|
||||
case "1" -> "临时车";
|
||||
|
||||
default -> "未知";
|
||||
});
|
||||
deviceData.setVehicleType(vehicletype);
|
||||
deviceData.setVehicleTypeName(
|
||||
switch (vehicletype) {
|
||||
case "0" -> "其他";
|
||||
case "1" -> "小型汽车";
|
||||
case "2" -> "大型汽车";
|
||||
|
||||
default -> "未知";
|
||||
});
|
||||
deviceData.setBelief(belief);
|
||||
acDeviceDataService.save(deviceData);
|
||||
});
|
||||
}
|
||||
default -> {
|
||||
log.warn("unknown message type: {}", rk);
|
||||
}
|
||||
}
|
||||
|
||||
dataCollectorLogService.save(logEntity);
|
||||
|
||||
// log.info("new message from pms: {}", body);
|
||||
}
|
||||
}
|
||||
@@ -6,4 +6,6 @@ import cn.lihongjie.coal.dataCollector.entity.DataCollectorEntity;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
@Repository
|
||||
public interface DataCollectorRepository extends BaseRepository<DataCollectorEntity> {}
|
||||
public interface DataCollectorRepository extends BaseRepository<DataCollectorEntity> {
|
||||
DataCollectorEntity findByAppKey(String appKey);
|
||||
}
|
||||
|
||||
@@ -75,4 +75,11 @@ public class DataCollectorService
|
||||
|
||||
return page.map(this.mapper::toDto);
|
||||
}
|
||||
|
||||
public DataCollectorEntity findByAppKey(String appKey) {
|
||||
|
||||
|
||||
return repository.findByAppKey(appKey);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -34,8 +34,10 @@ public class RabbitMQConfiguration {
|
||||
|
||||
@Autowired private ObjectMapper objectMapper;
|
||||
|
||||
|
||||
@Bean
|
||||
RabbitTemplateCustomizer rabbitTemplateCustomizer() {
|
||||
|
||||
return template -> {
|
||||
template.setMessageConverter(new Jackson2JsonMessageConverter(objectMapper));
|
||||
};
|
||||
|
||||
@@ -76,7 +76,7 @@ spring:
|
||||
username: ${PG_USER:postgres}
|
||||
password: ${PG_PASSWORD:abc@123}
|
||||
initial-size: 10
|
||||
max-active: 30
|
||||
max-active: 20
|
||||
min-idle: 10
|
||||
validation-query: "select 1"
|
||||
validation-query-timeout: 1000
|
||||
|
||||
@@ -2541,6 +2541,17 @@
|
||||
|
||||
]
|
||||
},
|
||||
{
|
||||
"code": "ac.device.type",
|
||||
"name": "门禁设备类型",
|
||||
"item": [
|
||||
{
|
||||
"code": "1",
|
||||
"name": "海康道闸PMS4.0"
|
||||
}
|
||||
|
||||
]
|
||||
},
|
||||
{
|
||||
"code": "thirdAccount.type",
|
||||
"name": "第三方账号类型",
|
||||
|
||||
17
src/main/resources/scripts/dict/enum/acDeviceDataDict.groovy
Normal file
17
src/main/resources/scripts/dict/enum/acDeviceDataDict.groovy
Normal file
@@ -0,0 +1,17 @@
|
||||
|
||||
package scripts.dict
|
||||
|
||||
import cn.lihongjie.coal.acDeviceData.controller.AcDeviceDataController
|
||||
import cn.lihongjie.coal.base.dto.CommonQuery
|
||||
import org.springframework.context.ApplicationContext
|
||||
|
||||
ApplicationContext ioc = ioc
|
||||
|
||||
def controller = ioc.getBean(AcDeviceDataController.class)
|
||||
|
||||
|
||||
|
||||
|
||||
return controller.list(new CommonQuery())
|
||||
|
||||
|
||||
17
src/main/resources/scripts/dict/enum/acDeviceDict.groovy
Normal file
17
src/main/resources/scripts/dict/enum/acDeviceDict.groovy
Normal file
@@ -0,0 +1,17 @@
|
||||
|
||||
package scripts.dict
|
||||
|
||||
import cn.lihongjie.coal.acDevice.controller.AcDeviceController
|
||||
import cn.lihongjie.coal.base.dto.CommonQuery
|
||||
import org.springframework.context.ApplicationContext
|
||||
|
||||
ApplicationContext ioc = ioc
|
||||
|
||||
def controller = ioc.getBean(AcDeviceController.class)
|
||||
|
||||
|
||||
|
||||
|
||||
return controller.list(new CommonQuery())
|
||||
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
|
||||
package scripts.dict
|
||||
|
||||
import cn.lihongjie.coal.acDeviceSupplier.controller.AcDeviceSupplierController
|
||||
import cn.lihongjie.coal.base.dto.CommonQuery
|
||||
import org.springframework.context.ApplicationContext
|
||||
|
||||
ApplicationContext ioc = ioc
|
||||
|
||||
def controller = ioc.getBean(AcDeviceSupplierController.class)
|
||||
|
||||
|
||||
|
||||
|
||||
return controller.list(new CommonQuery())
|
||||
|
||||
|
||||
Reference in New Issue
Block a user