Commit 5663866c authored by suhuiguang's avatar suhuiguang

1.报检结果接收接口开发

parent 53396c1f
package com.yeejoin.amos.boot.module.jyjc.api.common;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.JsonSerializer;
import com.fasterxml.jackson.databind.SerializerProvider;
import org.apache.commons.lang3.StringUtils;
import org.typroject.tyboot.core.foundation.utils.DateTimeUtil;
import java.io.IOException;
import java.lang.reflect.Field;
import java.text.SimpleDateFormat;
import java.util.*;
/**
* @JsonComponent 会覆盖JsonFormat, 这里解析字段提升JsonFormat优先级
* <p>
* ProjectName: amos-boot-biz
* PackageName: com.yeejoin.amos.boot.module.jg.biz.config
*
* @author yangyang
* @version v1.0
* @date 2023/12/18 17:35
*/
public class BizCustomDateSerializer extends JsonSerializer<Date> {
private List<String> customFields = Arrays.asList("acceptDate", "expiryDate","applicationDate","noticeDate","installStartDate","handleDate","auditPassDate","applyDate");
public BizCustomDateSerializer()
{
}
@Override
public void serialize(Date value, JsonGenerator jgen, SerializerProvider provider) throws IOException, JsonProcessingException {
try {
Class<?> clazz = jgen.getCurrentValue().getClass();
if (Objects.equals(clazz, HashMap.class)) {
// 分页参数
if (customFields.contains(jgen.getOutputContext().getCurrentName())) {
SimpleDateFormat formatter = new SimpleDateFormat(DateTimeUtil.ISO_DATE);
jgen.writeString(formatter.format(value));
return;
}
} else {
Field field = clazz.getDeclaredField(jgen.getOutputContext().getCurrentName());
if (Objects.equals(field.getType(), Date.class)) {
if (field.isAnnotationPresent(JsonFormat.class)) {
String pattern = field.getAnnotation(JsonFormat.class).pattern();
if (StringUtils.isNotBlank(pattern)) {
SimpleDateFormat formatter = new SimpleDateFormat(pattern);
jgen.writeString(formatter.format(value));
return;
}
}
}
}
jgen.writeString(defaultFormattedDate(value));
} catch (Exception e) {
jgen.writeString(defaultFormattedDate(value));
}
}
private String defaultFormattedDate(Date value) {
SimpleDateFormat formatter = new SimpleDateFormat(DateTimeUtil.ISO_DATE_HOUR24_MIN_SEC);
String formattedDate = formatter.format(value);
return formattedDate;
}
}
\ No newline at end of file
package com.yeejoin.amos.boot.module.jyjc.api.model;
import lombok.Data;
import java.util.List;
/**
* @author Administrator
*/
@Data
public class AttachmentData {
/**
* 附件类型
*/
public String attachmentType;
/**
* 附件列表
*/
public List<AttachmentModel> attachmentContent;
}
package com.yeejoin.amos.boot.module.jyjc.api.model;
import lombok.Data;
/**
* @author Administrator
* 附件结构
*/
@Data
public class AttachmentModel {
/**
* 附件名称
*/
String name;
/**
* 附件路径
*/
String url;
/**
* 前端标识
*/
String uid;
/**
* 前端附件状态
*/
String status;
}
package com.yeejoin.amos.boot.module.jyjc.api.model;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.yeejoin.amos.boot.module.jyjc.api.common.BizCustomDateSerializer;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.util.Date;
import java.util.List;
/**
* 业务开通申请表
*
* @author system_generator
* @date 2023-12-14
*/
@Data
@ApiModel(value = "JyjcInspectionResultDataModel", description = "检验检测结果数据接收")
public class JyjcInspectionResultDataModel {
private static final long serialVersionUID = 1L;
@ApiModelProperty(value = "报检单号")
private String applicationNo;
@ApiModelProperty(value = "监管码")
private String supervisoryCode;
@ApiModelProperty(value = "检验结果状态(已出2、未出1)")
private String resultStatus;
@ApiModelProperty(value = "核准证号/许可证号")
private String licenseNumber;
@ApiModelProperty(value = "检验报告编号")
private String resultNo;
@ApiModelProperty(value = "内部人员代码")
private String innerPersonCode;
@ApiModelProperty(value = "检验结论")
private String inspectionConclusion;
@ApiModelProperty(value = "检验日期")
@JsonFormat(pattern = "yyyy-MM-dd")
@JsonSerialize(using = BizCustomDateSerializer.class)
private Date inspectionDate;
@ApiModelProperty(value = "下次检验日期")
@JsonFormat(pattern = "yyyy-MM-dd")
@JsonSerialize(using = BizCustomDateSerializer.class)
private Date nextInspectionDate;
@ApiModelProperty(value = "检验开始日期")
@JsonFormat(pattern = "yyyy-MM-dd")
@JsonSerialize(using = BizCustomDateSerializer.class)
private Date inspectionStartDate;
@ApiModelProperty(value = "检验结束日期")
@JsonFormat(pattern = "yyyy-MM-dd")
@JsonSerialize(using = BizCustomDateSerializer.class)
private Date inspectionEndDate;
@ApiModelProperty(value = "检验结果汇总")
private String inspectionResultSummary;
@ApiModelProperty(value = "不符合项")
private JSONArray nonConformance;
@ApiModelProperty(value = "附件")
private List<AttachmentData> attachments;
@ApiModelProperty(value = "检验结果技术参数")
private JSONObject techParams;
/**
* 校验检验系统唯一流水号,排查问题,跟踪问题使用
*/
private String traceId;
}
......@@ -2,6 +2,7 @@ package com.yeejoin.amos.boot.module.jyjc.biz.controller;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.yeejoin.amos.boot.biz.common.controller.BaseController;
import com.yeejoin.amos.boot.module.jyjc.api.model.JyjcInspectionResultDataModel;
import com.yeejoin.amos.boot.module.jyjc.api.model.JyjcInspectionResultModel;
import com.yeejoin.amos.boot.module.jyjc.biz.service.impl.JyjcInspectionResultServiceImpl;
import io.swagger.annotations.Api;
......@@ -175,4 +176,15 @@ public class JyjcInspectionResultController extends BaseController {
return ResponseHelper.buildResponse(jyjcInspectionResultServiceImpl.equipList(type, notNode));
}
/**
* 报检结果接收
* @param resultDataModels 结果信息
* @return List<JyjcInspectionResultDataModel>
*/
@TycloudOperation(ApiLevel = UserType.AGENCY)
@ApiOperation(httpMethod = "POST", value = "报检结果接收", notes = "对外对接使用,支持单条及批量")
@PostMapping(value = "/receive/data")
public ResponseModel<List<JyjcInspectionResultDataModel>> receivePushResultData(@RequestBody List<JyjcInspectionResultDataModel> resultDataModels){
return ResponseHelper.buildResponse(jyjcInspectionResultServiceImpl.receivePushResultData(resultDataModels));
}
}
package com.yeejoin.amos.boot.module.jyjc.biz.event;
import com.yeejoin.amos.boot.module.jyjc.api.entity.JyjcInspectionResult;
import lombok.Getter;
import org.springframework.context.ApplicationEvent;
import java.util.List;
/**
* @author Administrator
*/
@Getter
public class InspectionDetectionSaveToDbEvent extends ApplicationEvent {
private List<JyjcInspectionResult> jyjcInspectionResultList;
/**
* Create a new {@code ApplicationEvent}.
*
* @param source the object on which the event initially occurred or with
* which the event is associated (never {@code null})
*/
public InspectionDetectionSaveToDbEvent(Object source, List<JyjcInspectionResult> jyjcInspectionResultList) {
super(source);
this.jyjcInspectionResultList = jyjcInspectionResultList;
}
}
package com.yeejoin.amos.boot.module.jyjc.biz.event;
import com.yeejoin.amos.boot.module.jyjc.api.entity.JyjcInspectionResult;
import lombok.Getter;
import org.springframework.context.ApplicationEvent;
import java.util.List;
/**
* @author Administrator
*/
@Getter
public class UseInfoSaveToDbEvent extends ApplicationEvent {
private List<JyjcInspectionResult> jyjcInspectionResultList;
/**
* Create a new {@code ApplicationEvent}.
*
* @param source the object on which the event initially occurred or with
* which the event is associated (never {@code null})
*/
public UseInfoSaveToDbEvent(Object source, List<JyjcInspectionResult> jyjcInspectionResultList) {
super(source);
this.jyjcInspectionResultList = jyjcInspectionResultList;
}
}
package com.yeejoin.amos.boot.module.jyjc.biz.event.listener;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Sequence;
import com.yeejoin.amos.boot.module.jyjc.api.entity.JyjcInspectionResult;
import com.yeejoin.amos.boot.module.jyjc.biz.event.InspectionDetectionSaveToDbEvent;
import com.yeejoin.amos.boot.module.jyjc.biz.service.impl.CommonserviceImpl;
import com.yeejoin.amos.boot.module.ymt.api.entity.InspectionDetectionInfo;
import com.yeejoin.amos.boot.module.ymt.api.entity.TzsUserInfo;
import com.yeejoin.amos.boot.module.ymt.api.mapper.InspectionDetectionInfoMapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.ApplicationListener;
import org.springframework.stereotype.Component;
import org.springframework.util.CollectionUtils;
import javax.annotation.PostConstruct;
import java.util.Date;
import java.util.List;
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.stream.Collectors;
/**
* @author Administrator
*/
@Component
@Slf4j
public class InspectionDetectionSaveToDbEventListener implements ApplicationListener<InspectionDetectionSaveToDbEvent> {
@Value("${inspect.info.save.thread.number:3}")
private int threadNumber;
@Autowired
CommonserviceImpl commonService;
@Autowired
private Sequence sequence;
@Autowired
InspectionDetectionInfoMapper inspectionDetectionInfoMapper;
private BlockingQueue<JyjcInspectionResult> blockingQueue = new LinkedBlockingQueue<>();
@Override
public void onApplicationEvent(InspectionDetectionSaveToDbEvent event) {
log.info("收到检验检测信息插入或者更新消息:{}", JSONObject.toJSONString(event.getJyjcInspectionResultList()));
blockingQueue.addAll(event.getJyjcInspectionResultList());
}
@PostConstruct
public void init() {
ExecutorService executorService = Executors.newFixedThreadPool(threadNumber);
for (int i = 0; i < threadNumber; i++) {
executorService.execute(() -> {
while (true) {
try {
JyjcInspectionResult jyjcInspectionResult = blockingQueue.take();
InspectionDetectionInfo info = new InspectionDetectionInfo();
QueryWrapper<InspectionDetectionInfo> wrapper = new QueryWrapper<>();
wrapper.lambda().eq(InspectionDetectionInfo::getInspectReportNo, jyjcInspectionResult.getResultNo());
List<InspectionDetectionInfo> list = inspectionDetectionInfoMapper.selectList(wrapper);
if (CollectionUtils.isEmpty(list)) {
extracted(jyjcInspectionResult, info);
info.setSequenceNbr(sequence.nextId() + "");
inspectionDetectionInfoMapper.insert(info);
} else {
info = list.get(0);
extracted(jyjcInspectionResult, info);
inspectionDetectionInfoMapper.updateById(info);
}
} catch (Exception e) {
log.error(e.getMessage(), e);
}
}
});
}
}
private void extracted(JyjcInspectionResult jyjcInspectionResult, InspectionDetectionInfo info) {
info.setInspectOrgName(jyjcInspectionResult.getInspectionTypeName());
info.setInspectType(jyjcInspectionResult.getInspectionType());
info.setRecord(jyjcInspectionResult.getEquipUnicode());
info.setInspectDate(jyjcInspectionResult.getInspectionDate());
info.setInspectStaff(getInspectUserName(jyjcInspectionResult));
info.setInspectStaffCode(jyjcInspectionResult.getInspector());
info.setInspectConclusion(jyjcInspectionResult.getInspectionConclusion());
info.setProblemRemark(jyjcInspectionResult.getNonConformance());
info.setNextInspectDate(jyjcInspectionResult.getNextInspectionDate());
info.setSequenceCode(jyjcInspectionResult.getEquipUnicode());
info.setInspectOrgCode(jyjcInspectionResult.getInspectionUnitCode());
info.setInspectReportNo(jyjcInspectionResult.getResultNo());
info.setRecDate(new Date());
}
private String getInspectUserName(JyjcInspectionResult model) {
List<TzsUserInfo> userInfos = commonService.getUserInfosByUnitCode(model.getInspectionUnitCode());
return userInfos.stream().filter(u -> model.getInspector().contains(u.getSequenceNbr() + "")).map(TzsUserInfo::getName).collect(Collectors.joining(","));
}
}
package com.yeejoin.amos.boot.module.jyjc.biz.event.listener;
import com.alibaba.fastjson.JSONObject;
import com.yeejoin.amos.boot.module.jyjc.api.entity.JyjcInspectionResult;
import com.yeejoin.amos.boot.module.jyjc.biz.event.UseInfoSaveToDbEvent;
import com.yeejoin.amos.boot.module.ymt.api.mapper.UseInfoMapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.ApplicationListener;
import org.springframework.stereotype.Component;
import javax.annotation.PostConstruct;
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.LinkedBlockingQueue;
/**
* @author Administrator
*/
@Component
@Slf4j
public class UseInfoSaveToDbEventListener implements ApplicationListener<UseInfoSaveToDbEvent> {
@Value("${user.info.save.thread.number:3}")
private int threadNumber;
@Autowired
UseInfoMapper useInfoMapper;
private BlockingQueue<JyjcInspectionResult> blockingQueue = new LinkedBlockingQueue<>();
@Override
public void onApplicationEvent(UseInfoSaveToDbEvent event) {
log.info("收到更新使用信息的检验检测字段消息:{}", JSONObject.toJSONString(event.getJyjcInspectionResultList()));
blockingQueue.addAll(event.getJyjcInspectionResultList());
}
@PostConstruct
public void init() {
ExecutorService executorService = Executors.newFixedThreadPool(threadNumber);
for (int i = 0; i < threadNumber; i++) {
executorService.execute(() -> {
while (true) {
try {
JyjcInspectionResult jyjcInspectionResult = blockingQueue.take();
//更新使用信息表
useInfoMapper.updateByRecord(jyjcInspectionResult.getEquipUnicode(), jyjcInspectionResult.getNextInspectionDate(), jyjcInspectionResult.getInspectionType(), jyjcInspectionResult.getApplicationNo());
} catch (Exception e) {
log.error(e.getMessage(), e);
}
}
});
}
}
}
package com.yeejoin.amos.boot.module.jyjc.biz.event.publisher;
import org.springframework.context.ApplicationEvent;
import org.springframework.context.ApplicationEventPublisher;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Component;
@Component
public class EventPublisher {
private ApplicationEventPublisher publisher;
public EventPublisher(ApplicationEventPublisher publisher) {
this.publisher = publisher;
}
@Async
public void publish(ApplicationEvent event) {
publisher.publishEvent(event);
}
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment