Commit a7422712 authored by 韩桐桐's avatar 韩桐桐

Merge remote-tracking branch 'origin/develop_tzs_register' into develop_tzs_register

parents 1e5a8897 5229dc83
......@@ -13,7 +13,7 @@ import java.util.Set;
@Getter
@AllArgsConstructor
public enum CategoryEnum {
DETECTION("detection", JYJCTypeEnum.AQFJY, JYJCTypeEnum.DTJC),
DETECTION("detection", JYJCTypeEnum.DTJC),
FIRST_INSPECTION("firstinspect", JYJCTypeEnum.DQJY, JYJCTypeEnum.SCJY),
SUPERVISE("supervise", JYJCTypeEnum.WXJDJY, JYJCTypeEnum.GZJDJY, JYJCTypeEnum.AZJDJY);
......
......@@ -14,17 +14,18 @@ public enum JYJCTypeEnum {
/**
* 检验检测类型
*/
AQFJY("AQFJY", "安全阀校验"),
DTJC("DTJC", "电梯检测"),
DQJY("DQJY", "定期检验"),
SCJY("SCJY", "首次检验"),
WXJDJY("WXJDJY", "维修监督检验"),
GZJDJY("GZJDJY", "改造监督检验"),
AZJDJY("AZJDJY", "安装监督检验");
DTJC("DTJC", "电梯检测","jc"),
DQJY("DQJY", "定期检验", "jy"),
SCJY("SCJY", "首次检验", "jy"),
WXJDJY("WXJDJY", "维修监督检验", "jy"),
GZJDJY("GZJDJY", "改造监督检验", "jy"),
AZJDJY("AZJDJY", "安装监督检验", "jy");
private final String code;
private final String name;
private final String bizType;
public static JYJCTypeEnum of(String code) {
for (JYJCTypeEnum e : JYJCTypeEnum.values()) {
if (e.getCode().equals(code)) {
......
......@@ -22,4 +22,7 @@ public class InspectionEquipInfoModel implements Serializable {
@ApiModelProperty(value = "申请表主键")
private String appSeq;
@ApiModelProperty(value = "主题,无需上送,由topic解析出来")
private String componentKey;
}
package com.yeejoin.amos.boot.module.jyjc.biz.config;
import lombok.Data;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;
import java.lang.reflect.Field;
/**
* 各检验检测类型是否启用规则,默认不启用
* @author Administrator
*/
@Component
@ConfigurationProperties(prefix = "inspection.rule.enabled")
@Data
public class InspectionRuleEnableConfig {
/**
* 定期检验是否启用规则:true-启用,false-不启用
*/
private Boolean DQJY;
/**
* 首次检验是否启用规则:true-启用,false-不启用
*/
private Boolean SCJY;
/**
* 维修监督检验是否启用规则:true-启用,false-不启用
*/
private Boolean WXJDJY;
/**
* 改造监督检验是否启用规则:true-启用,false-不启用
*/
private Boolean GZJDJY;
/**
* 安装监督检验是否启用规则:true-启用,false-不启用
*/
private Boolean AZJDJY;
/**
* 电梯检测是否启用规则:true-启用,false-不启用
*/
private Boolean DTJC;
public Object getValueByFieldName(String fieldName){
Field field = null;
try {
field = this.getClass().getDeclaredField(fieldName);
field.setAccessible(true);
return field.get(this);
} catch (NoSuchFieldException | IllegalAccessException e) {
e.printStackTrace();
}
return false;
}
}
\ No newline at end of file
package com.yeejoin.amos.boot.module.jyjc.biz.event;
import com.yeejoin.amos.boot.module.jyjc.api.model.InspectionEquipInfoModel;
import lombok.Getter;
import org.springframework.context.ApplicationEvent;
/**
* @author Administrator
*/
@Getter
public class InspectionOrgRefreshEvent extends ApplicationEvent {
private InspectionEquipInfoModel inspectionEquipInfoModel;
/**
* 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 InspectionOrgRefreshEvent(Object source, InspectionEquipInfoModel inspectionEquipInfoModel) {
super(source);
this.inspectionEquipInfoModel = inspectionEquipInfoModel;
}
}
package com.yeejoin.amos.boot.module.jyjc.biz.event;
import com.yeejoin.amos.boot.module.jyjc.biz.rule.InspectionEquipInfo;
import lombok.Getter;
import org.springframework.context.ApplicationEvent;
/**
* @author Administrator
*/
@Getter
public class TouchRuleEvent extends ApplicationEvent {
private InspectionEquipInfo inspectionEquipInfo;
/**
* 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 TouchRuleEvent(Object source, InspectionEquipInfo inspectionEquipInfo) {
super(source);
this.inspectionEquipInfo = inspectionEquipInfo;
}
}
package com.yeejoin.amos.boot.module.jyjc.biz.event.listener;
import com.yeejoin.amos.boot.biz.common.utils.RedisUtils;
import com.yeejoin.amos.boot.module.jyjc.api.enums.JYJCTypeEnum;
import com.yeejoin.amos.boot.module.jyjc.api.enums.OpenBizTypeEnum;
import com.yeejoin.amos.boot.module.jyjc.api.model.InspectionEquipInfoModel;
import com.yeejoin.amos.boot.module.jyjc.biz.config.InspectionRuleEnableConfig;
import com.yeejoin.amos.boot.module.jyjc.biz.event.InspectionOrgRefreshEvent;
import com.yeejoin.amos.boot.module.jyjc.biz.service.impl.RuleCommonServiceImpl;
import com.yeejoin.amos.boot.module.ymt.api.dto.TzBaseEnterpriseInfoDto;
import lombok.extern.slf4j.Slf4j;
import org.eclipse.paho.client.mqttv3.MqttException;
import org.springframework.context.ApplicationListener;
import org.springframework.stereotype.Component;
import java.util.List;
/**
* 不启用规则时,业务处理
* @author Administrator
*/
@Component
@Slf4j
public class DisableRuleDataPreparationListener implements ApplicationListener<InspectionOrgRefreshEvent> {
private InspectionRuleEnableConfig inspectionRuleEnableConfig;
private RuleCommonServiceImpl ruleCommonService;
private RedisUtils redisUtils;
public DisableRuleDataPreparationListener(InspectionRuleEnableConfig inspectionRuleEnableConfig, RuleCommonServiceImpl ruleCommonService, RedisUtils redisUtils) {
this.inspectionRuleEnableConfig = inspectionRuleEnableConfig;
this.ruleCommonService = ruleCommonService;
this.redisUtils = redisUtils;
}
@Override
public void onApplicationEvent(InspectionOrgRefreshEvent event) {
InspectionEquipInfoModel equipInfoModel = event.getInspectionEquipInfoModel();
String componentKey = equipInfoModel.getComponentKey();
// 规则不启用时业务处理
if (!this.getEnableConfig(equipInfoModel.getInspectionType())) {
log.warn("检验类型:{},未启用规则,将返回全部数据", equipInfoModel.getInspectionType());
this.responseForPublisher(componentKey, this.getAllInspectionOrgList(equipInfoModel));
}
}
/**
* 按照检验类型判断是否启用, 不配置时默认不启用
*
* @param inspectionType 检验类型枚举 @see JYJCTypeEnum
* @return true-启用规则,false-不启用
*/
private boolean getEnableConfig(String inspectionType) {
return inspectionRuleEnableConfig.getValueByFieldName(inspectionType) == null ? false : (Boolean) inspectionRuleEnableConfig.getValueByFieldName(inspectionType);
}
private void responseForPublisher(String componentKey, List<TzBaseEnterpriseInfoDto> allInspectionOrgList) {
try {
ruleCommonService.publishMqttMessage(componentKey, allInspectionOrgList);
} catch (MqttException e) {
log.error("规则不启用时,推送订阅者全部检验检测或者检验机构时失败:{}", e.getMessage());
}
}
private List<TzBaseEnterpriseInfoDto> getAllInspectionOrgList(InspectionEquipInfoModel equipInfoModel) {
// 提升性能,数据缓存1分钟
String redisKey = this.getInspectionOrgListRedisKey(equipInfoModel.getInspectionType());
if (redisUtils.hasKey(redisKey)) {
return (List<TzBaseEnterpriseInfoDto>) redisUtils.get(redisKey);
} else {
List<TzBaseEnterpriseInfoDto> allInspectionOrgList = ruleCommonService.getInspectionUnitList(this.getBizTypeByInspectionType(equipInfoModel.getInspectionType()));
// 设置为必须处理,前端不再显示《不予处理》按钮
ruleCommonService.setIsCanNoAccept(allInspectionOrgList, true);
// 将对象直接存储到缓存,避免 JSON 序列化和反序列化
redisUtils.set(redisKey, allInspectionOrgList, 60);
return allInspectionOrgList;
}
}
private String getInspectionOrgListRedisKey(String inspectionType) {
return String.format("%s:%s", "inspection.rule.org.data", inspectionType);
}
private String getBizTypeByInspectionType(String inspectionType) {
JYJCTypeEnum jyjcTypeEnum = JYJCTypeEnum.of(inspectionType);
if (jyjcTypeEnum != null) {
return jyjcTypeEnum.getBizType();
}
return OpenBizTypeEnum.JY.getCode();
}
}
package com.yeejoin.amos.boot.module.jyjc.biz.event.listener;
import com.yeejoin.amos.boot.module.jyjc.biz.event.TouchRuleEvent;
import com.yeejoin.amos.boot.module.jyjc.biz.rule.InspectionEquipInfo;
import com.yeejoin.amos.component.robot.AmosRequestContext;
import com.yeejoin.amos.feign.rule.Rule;
import com.yeejoin.amos.feign.rule.model.FactBaseModel;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.ApplicationListener;
import org.springframework.stereotype.Component;
import org.typroject.tyboot.core.foundation.context.RequestContext;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import static com.alibaba.fastjson.JSON.toJSONString;
/**
* @author Administrator
*/
@Component
@Slf4j
public class TouchRuleEventListener implements ApplicationListener<TouchRuleEvent> {
private AmosRequestContext amosRequestContext;
@Value("${inspection.rule.project-name:报检规则}")
private String ruleName;
public TouchRuleEventListener(AmosRequestContext amosRequestContext) {
this.amosRequestContext = amosRequestContext;
}
@Override
public void onApplicationEvent(TouchRuleEvent event) {
this.touchRuleWithApi(event.getInspectionEquipInfo());
}
private void touchRuleWithApi(InspectionEquipInfo inspectionEquipInfo) {
if (log.isInfoEnabled()) {
log.info("发送规则的消息对象:{}", toJSONString(inspectionEquipInfo));
}
try {
RequestContext.setToken(amosRequestContext.getToken());
RequestContext.setAppKey(amosRequestContext.getAppKey());
RequestContext.setProduct(amosRequestContext.getProduct());
HashMap<String, byte[]> factMap = new HashMap<>();
List<Object> factList = new ArrayList<>();
factList.add(inspectionEquipInfo);
for (Object fact : factList) {
factMap.put(fact.getClass().getName(), toJSONString(fact).getBytes());
}
FactBaseModel factBaseModel = new FactBaseModel();
factBaseModel.setFactMap(factMap);
factBaseModel.setPackageId(ruleName + "/" + inspectionEquipInfo.getBizType());
factBaseModel.setProcessIds(null);
if (log.isInfoEnabled()) {
log.info("发送规则的消息对象:{},\n变量对象:{}", toJSONString(factBaseModel), toJSONString(factBaseModel));
}
Rule.ruleClient.fireRule(factBaseModel);
} catch (Exception e) {
log.error("调用规则触发获取报检规则失败", e);
}
}
}
package com.yeejoin.amos.boot.module.jyjc.biz.service.impl;
import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.sun.org.apache.regexp.internal.RE;
import com.yeejoin.amos.boot.module.jyjc.api.enums.TopicEnum;
import com.yeejoin.amos.boot.module.ymt.api.dto.TzBaseEnterpriseInfoDto;
import com.yeejoin.amos.boot.module.ymt.api.entity.UseInfo;
import com.yeejoin.amos.boot.module.ymt.api.mapper.TzBaseEnterpriseInfoMapper;
import com.yeejoin.amos.boot.module.ymt.api.mapper.UseInfoMapper;
import com.yeejoin.amos.component.rule.config.RuleConfig;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.eclipse.paho.client.mqttv3.MqttException;
import org.springframework.stereotype.Component;
import org.typroject.tyboot.component.emq.EmqKeeper;
import java.util.Arrays;
import java.util.List;
/**
* @author Administrator
*/
@Component
@Slf4j
public class RuleCommonServiceImpl {
private UseInfoMapper useInfoMapper;
private TzBaseEnterpriseInfoMapper enterpriseInfoMapper;
private final EmqKeeper emqKeeper;
/**
* 特殊独立的区县
*/
private static final String[] EXCLUSION_CITY_REGIONS = {"610403", "610581"};
public RuleCommonServiceImpl(UseInfoMapper useInfoMapper) {
public RuleCommonServiceImpl(UseInfoMapper useInfoMapper, TzBaseEnterpriseInfoMapper enterpriseInfoMapper, EmqKeeper emqKeeper) {
this.useInfoMapper = useInfoMapper;
this.enterpriseInfoMapper = enterpriseInfoMapper;
this.emqKeeper = emqKeeper;
}
public String getArea(String record) {
String getArea(String record) {
UseInfo equipUseInfo = useInfoMapper.selectOne(Wrappers.<UseInfo>lambdaQuery().select(UseInfo::getCity, UseInfo::getCounty).eq(UseInfo::getRecord, record));
if (equipUseInfo == null) {
return "";
......@@ -68,4 +84,25 @@ public class RuleCommonServiceImpl {
return equipUseInfo.getCounty();
}
public List<TzBaseEnterpriseInfoDto> getInspectionUnitList(String openBizType) {
return enterpriseInfoMapper.getInspectionUnitList(openBizType);
}
public void publishMqttMessage(String componentKey, Object message) throws MqttException {
log.info("报检规则推送到web主题:{}:,消息内容为:{}", String.format(TopicEnum.INSPECTION_LIST_PUSH.getTopic(), componentKey), JSON.toJSONString(message));
try {
emqKeeper.getMqttClient().publish(String.format(TopicEnum.INSPECTION_LIST_PUSH.getTopic(), componentKey),
JSON.toJSONString(message).getBytes(), RuleConfig.DEFAULT_QOS, false);
} catch (MqttException e) {
log.error("Error publishing MQTT message: {}", e.getMessage());
throw e;
}
}
public void setIsCanNoAccept(List<TzBaseEnterpriseInfoDto> matchEnterpriseInfos, Boolean isCanNoAccept) {
matchEnterpriseInfos.forEach(m -> {
m.setUseCodeAndName(m.getUseCode() + "_" + isCanNoAccept);
});
}
}
......@@ -59,3 +59,12 @@ rule.definition.local-ip=172.16.3.20
spring.kafka.bootstrap-servers=172.16.10.243:9092
spring.kafka.security.protocol=SASL_PLAINTEXT
spring.kafka.properties.sasl.mechanism=PLAIN
#定期检验是否启用规则:true-启用,false-不启用,默认不配置时不启动规则
inspection.rule.enabled.DQJY=true
#安装监督检验是否启用规则:true-启用,false-不启用
inspection.rule.enabled.AZJDJY=true
#改造监督检验是否启用规则:true-启用,false-不启用
inspection.rule.enabled.GZJDJY=true
#维修监督检验是否启用规则:true-启用,false-不启用
inspection.rule.enabled.WXJDJY=true
\ No newline at end of file
......@@ -177,9 +177,7 @@
info.sequence_nbr,
info.use_code,
info.use_unit,
concat(info.use_code,'_',info.use_unit) as useCodeAndName,
info.use_contact,
info.contact_phone
concat(info.use_code,'_',info.use_unit) as useCodeAndName
FROM
tz_base_enterprise_info info
INNER JOIN tz_jyjc_opening_application tjoa ON info.use_code = tjoa.unit_code
......@@ -194,7 +192,6 @@
<if test="city != null and city != ''">
and tjoa.detection_region like concat('%',#{city},'%')
</if>
group by info.use_code
</select>
<select id="selectBySeq" resultType="com.yeejoin.amos.boot.module.ymt.api.entity.TzBaseEnterpriseInfo">
select * from tz_base_enterprise_info where sequence_nbr = #{sequenceNbr}
......
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