diff --git a/src/main/java/cn/lihongjie/coal/acAppointment/controller/AcAppointmentController.java b/src/main/java/cn/lihongjie/coal/acAppointment/controller/AcAppointmentController.java new file mode 100644 index 00000000..88df43aa --- /dev/null +++ b/src/main/java/cn/lihongjie/coal/acAppointment/controller/AcAppointmentController.java @@ -0,0 +1,73 @@ +package cn.lihongjie.coal.acAppointment.controller; + +import cn.lihongjie.coal.acAppointment.dto.AcAppointmentDto; +import cn.lihongjie.coal.acAppointment.dto.BatchCreateAcAppointmentDto; +import cn.lihongjie.coal.acAppointment.dto.CreateAcAppointmentDto; +import cn.lihongjie.coal.acAppointment.dto.UpdateAcAppointmentDto; +import cn.lihongjie.coal.acAppointment.service.AcAppointmentService; +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("/acAppointment") +@SysLog(module = "门禁设备预约") +@Slf4j +@OrgScope +public class AcAppointmentController { + @Autowired private AcAppointmentService service; + + @PostMapping("/create") + public AcAppointmentDto create(@RequestBody CreateAcAppointmentDto request) { + return this.service.create(request); + } + + @PostMapping("/batchCreate") + public Object batchCreate(@RequestBody BatchCreateAcAppointmentDto request) { + this.service.batchCreate(request); + return true; + } + + @PostMapping("/update") + public AcAppointmentDto update(@RequestBody UpdateAcAppointmentDto request) { + return this.service.update(request); + } + + @PostMapping("/delete") + public Object delete(@RequestBody IdRequest request) { + this.service.delete(request); + return true; + } + + @PostMapping("/getById") + public AcAppointmentDto getById(@RequestBody IdRequest request) { + return this.service.getById(request.getId()); + } + + @PostMapping("/list") + public Page 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; + } +} diff --git a/src/main/java/cn/lihongjie/coal/acAppointment/dto/AcAppointmentDto.java b/src/main/java/cn/lihongjie/coal/acAppointment/dto/AcAppointmentDto.java new file mode 100644 index 00000000..bf1c40ed --- /dev/null +++ b/src/main/java/cn/lihongjie/coal/acAppointment/dto/AcAppointmentDto.java @@ -0,0 +1,82 @@ +package cn.lihongjie.coal.acAppointment.dto; + +import cn.lihongjie.coal.acDevice.dto.AcDeviceDto; +import cn.lihongjie.coal.base.dto.OrgCommonDto; + +import jakarta.persistence.ManyToOne; + +import lombok.Data; + +import org.hibernate.annotations.Comment; +import org.hibernate.annotations.Formula; + +@Data +public class AcAppointmentDto extends OrgCommonDto { + + + @ManyToOne + private AcDeviceDto device; + + @Comment("预约开始时间") + private java.time.LocalDateTime startTime; + + @Comment("预约结束时间") + private java.time.LocalDateTime endTime; + + @Comment("车牌号") + private String plateNo; + + @Comment("姓名") + private String driverName; + + @Comment("联系电话") + private String driverPhone; + + @Comment("事由") + private String reason; + + + + @Comment("下发时间") + private java.time.LocalDateTime sendTime; + + @Comment("下发状态") + private String sendStatus; + + @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 = 'common.step.status'\n" + + " and i.code = send_status)") + private String sendStatusName; + + @Comment("下发完成时间") + private java.time.LocalDateTime sendFinishTime; + + + + + @Comment("删除时间") + private java.time.LocalDateTime deleteTime; + + + @Comment("下发状态") + private String deleteStatus; + + @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 = 'common.step.status'\n" + + " and i.code = delete_status)") + private String deleteStatusName; + + @Comment("删除完成时间") + private java.time.LocalDateTime deleteFinishTime; + private String archiveStatus; + + private String archiveStatusName; +} diff --git a/src/main/java/cn/lihongjie/coal/acAppointment/dto/BatchCreateAcAppointmentDto.java b/src/main/java/cn/lihongjie/coal/acAppointment/dto/BatchCreateAcAppointmentDto.java new file mode 100644 index 00000000..478ec89b --- /dev/null +++ b/src/main/java/cn/lihongjie/coal/acAppointment/dto/BatchCreateAcAppointmentDto.java @@ -0,0 +1,32 @@ +package cn.lihongjie.coal.acAppointment.dto; + +import cn.lihongjie.coal.base.dto.OrgCommonDto; + +import lombok.Data; + +import org.hibernate.annotations.Comment; + +import java.util.List; + +@Data +public class BatchCreateAcAppointmentDto extends OrgCommonDto { + + @Comment("预约开始时间") + private java.time.LocalDateTime startTime; + + @Comment("预约结束时间") + private java.time.LocalDateTime endTime; + + @Comment("车牌号,司机姓名,联系电话") + private List lines; + + + + + + + @Comment("事由") + private String reason; + + +} diff --git a/src/main/java/cn/lihongjie/coal/acAppointment/dto/CreateAcAppointmentDto.java b/src/main/java/cn/lihongjie/coal/acAppointment/dto/CreateAcAppointmentDto.java new file mode 100644 index 00000000..e8da3095 --- /dev/null +++ b/src/main/java/cn/lihongjie/coal/acAppointment/dto/CreateAcAppointmentDto.java @@ -0,0 +1,37 @@ +package cn.lihongjie.coal.acAppointment.dto; + +import cn.lihongjie.coal.base.dto.OrgCommonDto; + +import lombok.Data; + +import org.hibernate.annotations.Comment; + +@Data +public class CreateAcAppointmentDto extends OrgCommonDto { + + private String device; + + @Comment("预约开始时间") + private java.time.LocalDateTime startTime; + + @Comment("预约结束时间") + private java.time.LocalDateTime endTime; + + @Comment("车牌号") + private String plateNo; + + + + + + @Comment("姓名") + private String driverName; + + @Comment("联系电话") + private String driverPhone; + + @Comment("事由") + private String reason; + + +} diff --git a/src/main/java/cn/lihongjie/coal/acAppointment/dto/UpdateAcAppointmentDto.java b/src/main/java/cn/lihongjie/coal/acAppointment/dto/UpdateAcAppointmentDto.java new file mode 100644 index 00000000..97072f03 --- /dev/null +++ b/src/main/java/cn/lihongjie/coal/acAppointment/dto/UpdateAcAppointmentDto.java @@ -0,0 +1,31 @@ +package cn.lihongjie.coal.acAppointment.dto; + +import cn.lihongjie.coal.base.dto.OrgCommonDto; + +import lombok.Data; + +import org.hibernate.annotations.Comment; + +@Data +public class UpdateAcAppointmentDto extends OrgCommonDto { + + private String device; + + @Comment("预约开始时间") + private java.time.LocalDateTime startTime; + + @Comment("预约结束时间") + private java.time.LocalDateTime endTime; + + @Comment("车牌号") + private String plateNo; + + @Comment("姓名") + private String driverName; + + @Comment("联系电话") + private String driverPhone; + + @Comment("事由") + private String reason; +} diff --git a/src/main/java/cn/lihongjie/coal/acAppointment/entity/AcAppointmentEntity.java b/src/main/java/cn/lihongjie/coal/acAppointment/entity/AcAppointmentEntity.java new file mode 100644 index 00000000..60bbc081 --- /dev/null +++ b/src/main/java/cn/lihongjie/coal/acAppointment/entity/AcAppointmentEntity.java @@ -0,0 +1,109 @@ +package cn.lihongjie.coal.acAppointment.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.ColumnDefault; +import org.hibernate.annotations.Comment; +import org.hibernate.annotations.Formula; + +@Data +@Entity +public class AcAppointmentEntity extends OrgCommonEntity { + + @ManyToOne + private AcDeviceEntity device; + + @Comment("预约开始时间") + private java.time.LocalDateTime startTime; + + @Comment("预约结束时间") + private java.time.LocalDateTime endTime; + + @Comment("车牌号") + private String plateNo; + + @Comment("姓名") + private String driverName; + + @Comment("联系电话") + private String driverPhone; + + @Comment("事由") + private String reason; + + + + @Comment("下发时间") + private java.time.LocalDateTime sendTime; + + @Comment("下发状态") + private String sendStatus; + + @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 = 'common.step.status'\n" + + " and i.code = send_status)") + private String sendStatusName; + + @Comment("下发完成时间") + private java.time.LocalDateTime sendFinishTime; + + + + + + + + @Comment("删除时间") + private java.time.LocalDateTime deleteTime; + + + @Comment("下发状态") + private String deleteStatus; + + @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 = 'common.step.status'\n" + + " and i.code = delete_status)") + private String deleteStatusName; + + @Comment("删除完成时间") + private java.time.LocalDateTime deleteFinishTime; + + @Comment("预约状态") + private String appointmentStatus; + + @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 = 'appointment.status'\n" + + " and i.code = appointment_status)") + private String appointmentStatusName; + + @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; +} diff --git a/src/main/java/cn/lihongjie/coal/acAppointment/listener/AcAppointmentListener.java b/src/main/java/cn/lihongjie/coal/acAppointment/listener/AcAppointmentListener.java new file mode 100644 index 00000000..818644f4 --- /dev/null +++ b/src/main/java/cn/lihongjie/coal/acAppointment/listener/AcAppointmentListener.java @@ -0,0 +1,373 @@ +package cn.lihongjie.coal.acAppointment.listener; + +import cn.lihongjie.coal.acAppointment.entity.AcAppointmentEntity; +import cn.lihongjie.coal.acAppointment.service.AcAppointmentService; +import cn.lihongjie.coal.acDevice.service.AcDeviceService; +import cn.lihongjie.coal.acDeviceData.service.AcDeviceDataService; +import cn.lihongjie.coal.dataCollector.service.DataCollectorService; +import cn.lihongjie.coal.dataCollectorLog.service.DataCollectorLogService; +import cn.lihongjie.coal.rabbitmq.RabbitMQConfiguration; +import cn.lihongjie.coal.rabbitmq.RabbitMQService; + +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.node.ObjectNode; + +import lombok.SneakyThrows; +import lombok.extern.slf4j.Slf4j; + +import org.apache.commons.lang3.StringUtils; +import org.jetbrains.annotations.NotNull; +import org.springframework.amqp.core.AmqpAdmin; +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 AcAppointmentListener { + + @Autowired DataCollectorService dataCollectorService; + + @Autowired DataCollectorLogService dataCollectorLogService; + + @Autowired ObjectMapper objectMapper; + + @Autowired AcDeviceDataService acDeviceDataService; + + @Autowired AcDeviceService acDeviceService; + @Autowired RabbitMQService rabbitMQService; + @Autowired AcAppointmentService acAppointmentService; + @Autowired AmqpAdmin amqpAdmin; + + @NotNull + private static HashMap buildMessage( + AcAppointmentEntity appointment, String value) { + HashMap map = new HashMap<>(); + + map.put("eventType", value); + map.put("appointId", appointment.getId()); + // 客户端生成 序列 vehicleinfo_id_seq + map.put("id", ""); + // 车牌号 + map.put("plateno", appointment.getPlateNo()); + map.put("platecolor", "1"); + map.put("platetype", "0"); + map.put("vehiclecolor", "1"); + map.put("vehicletype", "1"); + map.put("parkingtype", "0"); + map.put("cardno", ""); + map.put("brand", ""); + map.put( + "ownername", + StringUtils.defaultIfBlank(appointment.getDriverName(), appointment.getPlateNo())); + map.put("owneraddress", ""); + map.put("ownerphonenumber", appointment.getDriverPhone()); + map.put("identitynumber", ""); + map.put( + "registertime", + LocalDateTime.now().format(RabbitMQConfiguration.DATE_TIME_FORMATTER)); + + map.put( + "begintime", + appointment.getStartTime().format(RabbitMQConfiguration.DATE_TIME_FORMATTER)); + map.put( + "endtime", + appointment.getEndTime().format(RabbitMQConfiguration.DATE_TIME_FORMATTER)); + map.put("ownergender", ""); + map.put("ownerworkplace", ""); + map.put("ownerdepartment", ""); + map.put("ownerpost", ""); + // 序列 uniquenosequence + map.put("uniquenumber", ""); + + map.put("categorybelonged", "1"); + map.put("expiredhandling", "0"); + map.put("matchedhandling", "0"); + map.put("timestamp", LocalDateTime.now().format(RabbitMQConfiguration.DATE_TIME_FORMATTER)); + map.put("reserve1", ""); + map.put("reserve2", appointment.getId()); + map.put("parkpermission", "1,2,3,4,5"); + map.put("vehicleinfo_cardtype", "0"); + map.put("groupbelonged", "0"); + map.put("isalreaybag", "1"); + map.put("isfromthirdsystem", "0"); + map.put("uploadflag", "0"); + map.put("historytime", null); + map.put( + "extrainfo", + """ +{ +"发动机号": "", +"排放量号": "", +"识别代码": "", +"车架号": "", +"车辆排量": "", +"车队名称": "" +} +"""); + return map; + } + + @SneakyThrows + @RabbitListener( + bindings = { + @QueueBinding( + value = + @org.springframework.amqp.rabbit.annotation.Queue( + value = "acAppointment.data", + durable = "true"), + exchange = + @Exchange( + value = RabbitMQConfiguration.SYS_EXCHANGE, + declare = Exchange.FALSE), + key = "acAppointment.*") + }) + @Transactional + public void handlePmsMessage(String body, @Headers Map headers) { + + var rk = headers.get(AmqpHeaders.RECEIVED_ROUTING_KEY).toString(); + + switch (rk) { + case "acAppointment.create": + handleCreate(body); + break; + case "acAppointment.update": + handleUpdate(body); + break; + case "acAppointment.delete": + handleDelete(body); + break; + + case "acAppointment.cancel": + handleCancel(body); + break; + case "acAppointment.expire": + handleExpire(body); + break; + + case "acAppointment.response": + handleResponse(body); + break; + default: + log.error("unknown routing key: {}", rk); + } + } + + @SneakyThrows + private void handleResponse(String body) { + + ObjectNode node = (ObjectNode) objectMapper.readTree(body); + + String appointId = node.get("appointId").asText(); + String eventType = node.get("eventType").asText(); + String status = node.get("status").asText(); + LocalDateTime time = LocalDateTime.parse(node.get("time").asText(), RabbitMQConfiguration.DATE_TIME_FORMATTER); + + + AcAppointmentEntity appointment; + try { + + appointment = acAppointmentService.get(appointId); + } catch (Exception e) { + + log.error("appointment not exist: {}", appointId); + return; + } + + if (StringUtils.equals(status, "3")){ + log.info("{} fail: {}\n{}", eventType, appointId, node.get("message").asText()); + }else { + + log.info("{} success: {}", eventType, appointId); + } + + + switch (eventType){ + + + case "acAppointment.create" ->{ + + + appointment.setSendFinishTime(time); + appointment.setSendStatus(status); + + + + } + + + case "acAppointment.update" ->{ + + appointment.setSendFinishTime(time); + appointment.setSendStatus(status); + + } + + case "acAppointment.delete" ->{ + + + log.info("appointment delete: {}", appointId); + + } + + case "acAppointment.cancel" ->{ + + appointment.setDeleteFinishTime(time); + appointment.setDeleteStatus(status); + + } + case "acAppointment.expire" ->{ + + appointment.setDeleteFinishTime(time); + appointment.setDeleteStatus(status); + + } + + } + + + this.acAppointmentService.save(appointment); + + } + + @SneakyThrows + private void handleDelete(String body) { + + List values = objectMapper.readerForListOf(ObjectNode.class).readValue(body); + + for (ObjectNode value : values) { + + String id = value.get("id").asText(); + String appKey = value.get("appKey").asText(); + + HashMap map = new HashMap<>(); + map.put("eventType", "acAppointment.delete"); + map.put("appointId", id); + + String queueName = "pms.client." + appKey; + + rabbitMQService.send("", queueName, map, new HashMap<>()); + } + } + + @SneakyThrows + private void handleCancel(String body) { + + List values = objectMapper.readerForListOf(ObjectNode.class).readValue(body); + + for (ObjectNode value : values) { + + String id = value.get("id").asText(); + String appKey = value.get("appKey").asText(); + + HashMap map = new HashMap<>(); + map.put("eventType", "acAppointment.cancel"); + map.put("appointId", id); + + String queueName = "pms.client." + appKey; + + rabbitMQService.send("", queueName, map, new HashMap<>()); + } + } + + @SneakyThrows + private void handleExpire(String body) { + + List values = objectMapper.readerForListOf(ObjectNode.class).readValue(body); + + for (ObjectNode value : values) { + + String id = value.get("id").asText(); + String appKey = value.get("appKey").asText(); + + HashMap map = new HashMap<>(); + map.put("eventType", "acAppointment.expire"); + map.put("appointId", id); + + String queueName = "pms.client." + appKey; + + rabbitMQService.send("", queueName, map, new HashMap<>()); + } + } + + private void handleUpdate(String body) { + + AcAppointmentEntity appointment = acAppointmentService.get(body); + + if (StringUtils.isEmpty(appointment.getSendStatus()) + || "0".equals(appointment.getSendStatus())) { + handleCreate(body); + + } else if (StringUtils.equals("1", appointment.getSendStatus())) { + + log.info( + "appointment sending: {} status {}", + appointment.getId(), + appointment.getSendStatus()); + + } else if (StringUtils.equals("2", appointment.getSendStatus())) { + + doUpdate(appointment); + + } else if (StringUtils.equals("3", appointment.getSendStatus())) { + + appointment.setSendStatus("0"); + handleCreate(body); + + } else { + + log.error("unknown status: {}", appointment.getSendStatus()); + } + } + + private void doUpdate(AcAppointmentEntity appointment) { + + HashMap message = buildMessage(appointment, "acAppointment.update"); + + String appKey = appointment.getDevice().getDataCollector().getAppKey(); + + String queueName = "pms.client." + appKey; + + rabbitMQService.send("", queueName, message, new HashMap<>()); + + appointment.setSendStatus("1"); + appointment.setSendTime(LocalDateTime.now()); + appointment.setSendFinishTime(null); + acAppointmentService.save(appointment); + } + + private void handleCreate(String body) { + + AcAppointmentEntity appointment = acAppointmentService.get(body); + + if (StringUtils.isEmpty(appointment.getSendStatus()) + || "0".equals(appointment.getSendStatus())) { + + String appKey = appointment.getDevice().getDataCollector().getAppKey(); + appointment.setSendStatus("1"); + + HashMap map = buildMessage(appointment, "acAppointment.create"); + + String queueName = "pms.client." + appKey; + + rabbitMQService.send("", queueName, map, new HashMap<>()); + + appointment.setSendStatus("1"); + appointment.setSendTime(LocalDateTime.now()); + appointment.setSendFinishTime(null); + acAppointmentService.save(appointment); + + } else { + + log.info("appointment already send: {}", appointment.getId()); + } + } +} diff --git a/src/main/java/cn/lihongjie/coal/acAppointment/mapper/AcAppointmentMapper.java b/src/main/java/cn/lihongjie/coal/acAppointment/mapper/AcAppointmentMapper.java new file mode 100644 index 00000000..ad6a6d0b --- /dev/null +++ b/src/main/java/cn/lihongjie/coal/acAppointment/mapper/AcAppointmentMapper.java @@ -0,0 +1,23 @@ +package cn.lihongjie.coal.acAppointment.mapper; + +import cn.lihongjie.coal.acAppointment.dto.AcAppointmentDto; +import cn.lihongjie.coal.acAppointment.dto.CreateAcAppointmentDto; +import cn.lihongjie.coal.acAppointment.dto.UpdateAcAppointmentDto; +import cn.lihongjie.coal.acAppointment.entity.AcAppointmentEntity; +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 AcAppointmentMapper + extends BaseMapper< + AcAppointmentEntity, + AcAppointmentDto, + CreateAcAppointmentDto, + UpdateAcAppointmentDto> {} diff --git a/src/main/java/cn/lihongjie/coal/acAppointment/repository/AcAppointmentRepository.java b/src/main/java/cn/lihongjie/coal/acAppointment/repository/AcAppointmentRepository.java new file mode 100644 index 00000000..89468a6e --- /dev/null +++ b/src/main/java/cn/lihongjie/coal/acAppointment/repository/AcAppointmentRepository.java @@ -0,0 +1,9 @@ +package cn.lihongjie.coal.acAppointment.repository; + +import cn.lihongjie.coal.acAppointment.entity.AcAppointmentEntity; +import cn.lihongjie.coal.base.dao.BaseRepository; + +import org.springframework.stereotype.Repository; + +@Repository +public interface AcAppointmentRepository extends BaseRepository {} diff --git a/src/main/java/cn/lihongjie/coal/acAppointment/service/AcAppointmentService.java b/src/main/java/cn/lihongjie/coal/acAppointment/service/AcAppointmentService.java new file mode 100644 index 00000000..8157f0f3 --- /dev/null +++ b/src/main/java/cn/lihongjie/coal/acAppointment/service/AcAppointmentService.java @@ -0,0 +1,247 @@ +package cn.lihongjie.coal.acAppointment.service; + +import cn.lihongjie.coal.acAppointment.dto.AcAppointmentDto; +import cn.lihongjie.coal.acAppointment.dto.BatchCreateAcAppointmentDto; +import cn.lihongjie.coal.acAppointment.dto.CreateAcAppointmentDto; +import cn.lihongjie.coal.acAppointment.dto.UpdateAcAppointmentDto; +import cn.lihongjie.coal.acAppointment.entity.AcAppointmentEntity; +import cn.lihongjie.coal.acAppointment.mapper.AcAppointmentMapper; +import cn.lihongjie.coal.acAppointment.repository.AcAppointmentRepository; +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 cn.lihongjie.coal.rabbitmq.RabbitMQService; + +import com.google.common.base.Splitter; + +import jakarta.persistence.criteria.CriteriaBuilder; +import jakarta.persistence.criteria.CriteriaQuery; +import jakarta.persistence.criteria.Predicate; +import jakarta.persistence.criteria.Root; + +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.data.jpa.domain.Specification; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +import java.time.LocalDateTime; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.stream.Collectors; + +@Service +@Slf4j +@Transactional +public class AcAppointmentService + extends BaseService { + @Autowired RabbitMQService rabbitMQService; + @Autowired private AcAppointmentRepository repository; + @Autowired private AcAppointmentMapper mapper; + @Autowired private ConversionService conversionService; + @Autowired private DbFunctionService dbFunctionService; + + public AcAppointmentDto create(CreateAcAppointmentDto request) { + + AcAppointmentEntity entity = mapper.toEntity(request); + entity.setAppointmentStatus("0"); + + this.repository.save(entity); + + rabbitMQService.sendToSysExchange("acAppointment.create", entity.getId(), new HashMap()); + + return getById(entity.getId()); + } + + public void batchCreate(BatchCreateAcAppointmentDto request) { + + for (String no : request.getLines()) { + + List parts = Splitter.on(",").trimResults().omitEmptyStrings().splitToList(no); + + CreateAcAppointmentDto dto = new CreateAcAppointmentDto(); + dto.setStartTime(request.getStartTime()); + dto.setEndTime(request.getEndTime()); + dto.setPlateNo(parts.get(0)); + + dto.setReason(request.getReason()); + + if (parts.size() > 1) dto.setDriverName(parts.get(1)); + else dto.setDriverName(""); + + if (parts.size() > 2) dto.setDriverPhone(parts.get(2)); + else dto.setDriverPhone(""); + + create(dto); + } + } + + public AcAppointmentDto update(UpdateAcAppointmentDto request) { + AcAppointmentEntity entity = this.repository.get(request.getId()); + ArchiveUtils.checkArchiveStatus( + entity, + AcAppointmentEntity::getArchiveStatus, + x -> "0", + (e, actual, expected) -> { + throw new BizException("数据 " + "已归档,无法编辑"); + }); + this.mapper.updateEntity(entity, request); + + this.repository.save(entity); + rabbitMQService.sendToSysExchange("acAppointment.update", entity.getId(), new HashMap()); + + return getById(entity.getId()); + } + + public void delete(IdRequest request) { + ArchiveUtils.checkArchiveStatus( + this.repository::findAllById, + request.getIds(), + AcAppointmentEntity::getArchiveStatus, + x -> "0", + (e, actual, expected) -> { + throw new BizException("数据 " + "已归档,无法删除"); + }); + + List all = this.repository.findAllById(request.getIds()); + + List> payload = all.stream() + .map( + x -> { + return Map.of( + "id", + x.getId(), + "appKey", + x.getDevice().getDataCollector().getAppKey()); + }).collect(Collectors.toList()); + + + rabbitMQService.sendToSysExchange("acAppointment.delete", payload, new HashMap()); + + this.repository.deleteAllById(request.getIds()); + } + + + public void cancel(IdRequest request) { + ArchiveUtils.checkArchiveStatus( + this.repository::findAllById, + request.getIds(), + AcAppointmentEntity::getArchiveStatus, + x -> "0", + (e, actual, expected) -> { + throw new BizException("数据 " + "已归档,无法删除"); + }); + + List all = this.repository.findAllById(request.getIds()); + + List> payload = all.stream() + .map( + x -> { + return Map.of( + "id", + x.getId(), + "appKey", + x.getDevice().getDataCollector().getAppKey()); + }).collect(Collectors.toList()); + + all.forEach(x -> x.setAppointmentStatus("1")); + all.forEach(x -> x.setArchiveStatus("1")); + this.repository.saveAll(all); + rabbitMQService.sendToSysExchange("acAppointment.cancel", payload, new HashMap()); + + + + + } + + + public void expire(){ + + + List all = this.repository.findAll(new Specification() { + @Override + public Predicate toPredicate(Root root, CriteriaQuery query, CriteriaBuilder criteriaBuilder) { + return criteriaBuilder.and( + criteriaBuilder.lessThan(root.get("endTime"), LocalDateTime.now())) + ; + } + }); + + List> payload = all.stream() + .map( + x -> { + return Map.of( + "id", + x.getId(), + "appKey", + x.getDevice().getDataCollector().getAppKey()); + }).collect(Collectors.toList()); + + all.forEach(x -> x.setAppointmentStatus("2")); + + all.forEach(x -> x.setArchiveStatus("1")); + + this.repository.saveAll(all); + + rabbitMQService.sendToSysExchange("acAppointment.expire", payload, new HashMap()); + + + } + + public AcAppointmentDto getById(String id) { + AcAppointmentEntity entity = repository.get(id); + + return mapper.toDto(entity); + } + + public Page list(CommonQuery query) { + Page 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, + AcAppointmentEntity::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, + AcAppointmentEntity::getArchiveStatus, + y -> "1", + (e, actual, expected) -> { + throw new BizException("数据" + "未归档,无法取消归档"); + })) + .peek(x -> x.setArchiveStatus("0")) + .forEach(this.repository::save); + } +} diff --git a/src/main/java/cn/lihongjie/coal/coalWashingMonthReport/dto/CoalWashingMonthReportDto.java b/src/main/java/cn/lihongjie/coal/coalWashingMonthReport/dto/CoalWashingMonthReportDto.java index e17f5c6e..ed7d8fb0 100644 --- a/src/main/java/cn/lihongjie/coal/coalWashingMonthReport/dto/CoalWashingMonthReportDto.java +++ b/src/main/java/cn/lihongjie/coal/coalWashingMonthReport/dto/CoalWashingMonthReportDto.java @@ -17,6 +17,13 @@ public class CoalWashingMonthReportDto extends OrgCommonDto { private String remark2; private String remark3; private String remark4; + + private String remark6; + private String remark7; + private String remark8; + private String remark9; + private String remark10; + private String remark11; private Double days; } diff --git a/src/main/java/cn/lihongjie/coal/coalWashingMonthReport/entity/CoalWashingMonthReportEntity.java b/src/main/java/cn/lihongjie/coal/coalWashingMonthReport/entity/CoalWashingMonthReportEntity.java index 22069368..4e6f7e63 100644 --- a/src/main/java/cn/lihongjie/coal/coalWashingMonthReport/entity/CoalWashingMonthReportEntity.java +++ b/src/main/java/cn/lihongjie/coal/coalWashingMonthReport/entity/CoalWashingMonthReportEntity.java @@ -37,6 +37,33 @@ select gen_random_uuid()::text as id, date_trunc('month', d.date) as create_time, date_trunc('month', d.date) as update_time, '' as remark4, + sum(case + when d.remark6 is null or d.remark6 = '' then null + else d.remark6::numeric end) as remark6, + + round(sum(case when d.remark6 is null or d.remark6 = '' then null else d.remark6::numeric end) / + sum(case when d.remark1 is null or d.remark1 = '' then null else d.remark1::numeric end) * 100, + 2) as remark7, + + + + sum(case + when d.remark8 is null or d.remark8 = '' then null + else d.remark8::numeric end) as remark8, + + round(sum(case when d.remark8 is null or d.remark8 = '' then null else d.remark8::numeric end) / + sum(case when d.remark1 is null or d.remark1 = '' then null else d.remark1::numeric end) * 100, + 2) as remark9, + + sum(case + when d.remark10 is null or d.remark10 = '' then null + else d.remark10::numeric end) as remark10, + + round(sum(case when d.remark10 is null or d.remark10 = '' then null else d.remark10::numeric end) / + sum(case when d.remark1 is null or d.remark1 = '' then null else d.remark1::numeric end) * 100, + 2) as remark11, + + '' as create_user_id, '' as update_user_id, null as file_ids, @@ -55,6 +82,13 @@ public class CoalWashingMonthReportEntity extends OrgCommonEntity { private String remark3; private String remark4; + private String remark6; + private String remark7; + private String remark8; + private String remark9; + private String remark10; + private String remark11; + private Double days; } diff --git a/src/main/java/cn/lihongjie/coal/dataCollector/service/DataCollectorService.java b/src/main/java/cn/lihongjie/coal/dataCollector/service/DataCollectorService.java index adc65611..d7dc7eee 100644 --- a/src/main/java/cn/lihongjie/coal/dataCollector/service/DataCollectorService.java +++ b/src/main/java/cn/lihongjie/coal/dataCollector/service/DataCollectorService.java @@ -11,8 +11,14 @@ import cn.lihongjie.coal.dataCollector.mapper.DataCollectorMapper; import cn.lihongjie.coal.dataCollector.repository.DataCollectorRepository; import cn.lihongjie.coal.dbFunctions.DbFunctionService; +import jakarta.annotation.PostConstruct; + import lombok.extern.slf4j.Slf4j; +import org.apache.commons.lang3.StringUtils; +import org.jetbrains.annotations.Nullable; +import org.springframework.amqp.core.AmqpAdmin; +import org.springframework.amqp.core.Queue; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.core.convert.ConversionService; import org.springframework.data.domain.Page; @@ -21,6 +27,7 @@ import org.springframework.data.domain.Sort; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; +import java.util.HashMap; import java.util.UUID; @Service @@ -36,15 +43,34 @@ public class DataCollectorService @Autowired private DbFunctionService dbFunctionService; + @Autowired AmqpAdmin amqpAdmin; + + @PostConstruct + public void init() { + + findAll().stream() + .filter(x -> StringUtils.isNotEmpty(x.getAppKey())) + .forEach(this::createQueue); + } + public DataCollectorDto create(CreateDataCollectorDto request) { DataCollectorEntity entity = mapper.toEntity(request); entity.setAppKey(UUID.randomUUID().toString()); entity.setAppSecret(UUID.randomUUID().toString()); this.repository.save(entity); + + createQueue(entity); + return getById(entity.getId()); } + @Nullable + private String createQueue(DataCollectorEntity entity) { + return amqpAdmin.declareQueue( + new Queue("pms.client." + entity.getAppKey(), true, false, false, new HashMap<>())); + } + public DataCollectorDto update(UpdateDataCollectorDto request) { DataCollectorEntity entity = this.repository.get(request.getId()); this.mapper.updateEntity(entity, request); diff --git a/src/main/java/cn/lihongjie/coal/organization/service/OrganizationService.java b/src/main/java/cn/lihongjie/coal/organization/service/OrganizationService.java index db6e939c..72fdfef0 100644 --- a/src/main/java/cn/lihongjie/coal/organization/service/OrganizationService.java +++ b/src/main/java/cn/lihongjie/coal/organization/service/OrganizationService.java @@ -28,6 +28,7 @@ import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import java.time.LocalDateTime; +import java.util.HashMap; @Service @Slf4j @@ -62,7 +63,7 @@ class OrganizationService extends BaseService()); return getById(entity.getId()); } @@ -71,7 +72,7 @@ class OrganizationService extends BaseService()); return getById(entity.getId()); } diff --git a/src/main/java/cn/lihongjie/coal/rabbitmq/RabbitMQConfiguration.java b/src/main/java/cn/lihongjie/coal/rabbitmq/RabbitMQConfiguration.java index edd4e13b..8c255c7e 100644 --- a/src/main/java/cn/lihongjie/coal/rabbitmq/RabbitMQConfiguration.java +++ b/src/main/java/cn/lihongjie/coal/rabbitmq/RabbitMQConfiguration.java @@ -12,6 +12,7 @@ import org.springframework.boot.convert.DurationStyle; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; +import java.time.format.DateTimeFormatter; import java.util.*; @EnableRabbit @@ -31,6 +32,7 @@ public class RabbitMQConfiguration { }; public static final Long[] DELAY_QUEUES_TIME = Arrays.stream(DELAY_QUEUES).map(x -> DurationStyle.detectAndParse(x).toMillis()).toArray(Long[]::new); + public static final DateTimeFormatter DATE_TIME_FORMATTER = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"); @Autowired private ObjectMapper objectMapper; @@ -51,6 +53,7 @@ public class RabbitMQConfiguration { return sysExchange; } + @Bean public HeadersExchange delayExchange() { HashMap arguments = new HashMap<>(); @@ -78,7 +81,7 @@ public class RabbitMQConfiguration { "delayQueue." + delayQueue, Binding.DestinationType.QUEUE, SYS_DELAY_EXCHANGE, - null, + "", bindArgs)); } diff --git a/src/main/java/cn/lihongjie/coal/rabbitmq/RabbitMQService.java b/src/main/java/cn/lihongjie/coal/rabbitmq/RabbitMQService.java index 54d8f117..92ccfbe0 100644 --- a/src/main/java/cn/lihongjie/coal/rabbitmq/RabbitMQService.java +++ b/src/main/java/cn/lihongjie/coal/rabbitmq/RabbitMQService.java @@ -1,24 +1,37 @@ package cn.lihongjie.coal.rabbitmq; +import org.apache.commons.collections4.MapUtils; import org.springframework.amqp.rabbit.core.RabbitTemplate; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; +import java.util.HashMap; +import java.util.Map; + @Service public class RabbitMQService { @Autowired RabbitTemplate rabbitTemplate; - public void send(String exchange, String routingKey, String data) { + public void send(String exchange, String routingKey, Object data, Map headers) { + + rabbitTemplate.convertAndSend( + exchange, + routingKey, + data, + message -> { + if (MapUtils.isNotEmpty(headers)) + message.getMessageProperties().getHeaders().putAll(headers); + return message; + }); - rabbitTemplate.convertAndSend(exchange, routingKey, data); } - public void sendToSysDelayExchange(String routingKey, String data, long delay) { + public void sendToSysDelayExchange(String routingKey, Object data, long delay) { send(RabbitMQConfiguration.SYS_DELAY_EXCHANGE, routingKey, data, delay); } - public void send(String exchange, String routingKey, String data, long delay) { + public void send(String exchange, String routingKey, Object data, long delay) { rabbitTemplate.convertAndSend( exchange, @@ -45,7 +58,11 @@ public class RabbitMQService { throw new IllegalArgumentException("delay is too long: " + delay); } - public void sendToSysExchange(String routingKey, String data) { - send(RabbitMQConfiguration.SYS_EXCHANGE, routingKey, data); + public void sendToSysExchange(String routingKey, Object data) { + sendToSysExchange(routingKey, data, new HashMap<>()); + } + + public void sendToSysExchange(String routingKey, Object data, Map headers) { + send(RabbitMQConfiguration.SYS_EXCHANGE, routingKey, data, headers); } } diff --git a/src/main/resources/config/dictionary.json b/src/main/resources/config/dictionary.json index eb75b7e0..e1be55bb 100644 --- a/src/main/resources/config/dictionary.json +++ b/src/main/resources/config/dictionary.json @@ -1675,6 +1675,47 @@ } ] }, + { + "code": "common.step.status", + "name": "通用状态步骤", + "item": [ + { + "code": "0", + "name": "未开始" + }, + { + "code": "1", + "name": "进行中" + }, + { + "code": "2", + "name": "已完成" + }, + { + "code": "3", + "name": "失败" + } + ] + }, + { + "code": "appointment.status", + "name": "道闸车辆预约状态", + "item": [ + { + "code": "0", + "name": "正常" + }, + { + "code": "1", + "name": "已取消" + }, + { + "code": "2", + "name": "已过期" + } + + ] + }, { "code": "purchaseOrder.status", "name": "采购订单状态", @@ -2529,7 +2570,6 @@ } ] }, - { "code": "em.device.type", "name": "环保设备类型", @@ -2538,7 +2578,6 @@ "code": "1", "name": "扬尘检测设备" } - ] }, { @@ -2549,14 +2588,12 @@ "code": "1", "name": "海康道闸PMS4.0" } - ] }, { "code": "thirdAccount.type", "name": "第三方账号类型", "item": [ - { "code": "1", "name": "阿里云" diff --git a/src/main/resources/scripts/dict/enum/acAppointmentDict.groovy b/src/main/resources/scripts/dict/enum/acAppointmentDict.groovy new file mode 100644 index 00000000..20a5ca08 --- /dev/null +++ b/src/main/resources/scripts/dict/enum/acAppointmentDict.groovy @@ -0,0 +1,17 @@ + +package scripts.dict + +import cn.lihongjie.coal.acAppointment.controller.AcAppointmentController +import cn.lihongjie.coal.base.dto.CommonQuery +import org.springframework.context.ApplicationContext + +ApplicationContext ioc = ioc + +def controller = ioc.getBean(AcAppointmentController.class) + + + + +return controller.list(new CommonQuery()) + +