Commit fa2b3210 authored by zhangsen's avatar zhangsen

人员赋码规则bug修改、部分API开发

parent 274097d8
package com.yeejoin.amos.boot.module.jxiop.api.dto;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.ToString;
/**
* @author LiuLin
* @date 2023年08月02日 11:02
*/
@Data
@ToString
@AllArgsConstructor
@NoArgsConstructor
public class BizMessage {
private String indexKey;
private String indexValue;
private String traceId;
private RiskBizInfoVo bizInfo;
/**
* 数据来源:实时数据、周期数据
*/
String dataSource;
}
......@@ -90,4 +90,12 @@ public class PersonBasicDto extends BaseDto {
@ApiModelProperty(value = "岗位")
private String postName;
@ApiModelProperty(value = "赋码颜色")
private String qrcodeColor;
@ApiModelProperty(value = "赋码描述")
private String qrcodeDesc;
}
package com.yeejoin.amos.boot.module.jxiop.api.dto;
import lombok.Data;
import java.util.List;
/**
* @author LiuLin
* @date 2023年08月02日 11:02
*/
@Data
public class RiskBizInfoVo {
private String warningObjectName;
private String warningObjectCode;
private String warningTime;
private String sourceAttribution;
private String sourceAttributionDesc;
private String sourceSupplyField;
private String bussId;
private String bussName;
private String type;
private List<RiskDynamicDetailsVo> dynamicDetails;
private String warningObjectType;
}
package com.yeejoin.amos.boot.module.jxiop.api.dto;
import lombok.Data;
import java.util.List;
import java.util.Map;
/**
* @author LiuLin
* @date 2023年08月02日 11:02
*/
@Data
public class RiskDynamicDetailsVo {
private String tabName;
private List<TableContentVo> tabContent;
private Map<String, Object> specialMap;
}
package com.yeejoin.amos.boot.module.jxiop.api.dto;
import lombok.Data;
/**
* @author LiuLin
* @date 2023年08月02日 11:02
*/
@Data
public class TableContentVo {
private String key;
private String label;
private Object value;
private String type;
}
......@@ -151,8 +151,14 @@ public class PersonBasic extends BaseEntity {
private String postName;
/**
* 岗位
* 赋码颜色
*/
@TableField("qrcode_color")
private String qrcodeColor;
/**
* 赋码颜色描述
*/
@TableField("qrcode_desc")
private String qrcodeDesc;
}
package com.yeejoin.amos.boot.module.jxiop.api.feign;
import com.yeejoin.amos.component.robot.AmosRequestContext;
import feign.RequestInterceptor;
import feign.RequestTemplate;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;
import javax.servlet.http.HttpServletRequest;
/**
* @author fengwang
* @date 2022-07-28.
*/
public class FeignBasicAuthRequestInterceptor implements RequestInterceptor {
@Autowired
AmosRequestContext amosAuth;
public FeignBasicAuthRequestInterceptor() {
}
@Override
public void apply(RequestTemplate template) {
ServletRequestAttributes attributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
if (attributes != null) {
HttpServletRequest request = attributes.getRequest();
/* Get token from header */
String authToken = request.getHeader("token");
/* If token not found get it from request parameter */
if (StringUtils.isBlank(authToken)) {
authToken = request.getHeader("X-Access-Token");
}
template.header("X-Access-Token", authToken);
template.header("token", authToken);
template.header("appKey", request.getHeader("appKey"));
template.header("product", request.getHeader("product"));
template.header("clientType", "feignClient");
}else {
template.header("X-Access-Token", amosAuth.getToken());
template.header("token", amosAuth.getToken());
template.header("appKey", amosAuth.getAppKey());
template.header("product", amosAuth.getProduct());
template.header("clientType", "feignClient");
}
}
}
package com.yeejoin.amos.boot.module.jxiop.api.feign;
import feign.codec.Encoder;
import feign.form.spring.SpringFormEncoder;
import org.springframework.beans.factory.ObjectFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.http.HttpMessageConverters;
import org.springframework.cloud.openfeign.support.SpringEncoder;
import org.springframework.context.annotation.Bean;
/**
* @author fengwang
* @date 2022-07-28.
*/
public class FeignConfiguration {
@Autowired
private ObjectFactory<HttpMessageConverters> messageConverters;
@Bean
public Encoder feignFormEncoder() {
return new SpringFormEncoder(new SpringEncoder(messageConverters));
}
@Bean
public FeignBasicAuthRequestInterceptor basicAuthRequestInterceptor() {
return new FeignBasicAuthRequestInterceptor();
}
@Bean
public FeignErrorDecoder errorDecoder(){
return new FeignErrorDecoder();
}
}
package com.yeejoin.amos.boot.module.jxiop.api.feign;
import com.alibaba.fastjson.JSONObject;
import feign.Response;
import feign.Util;
import feign.codec.ErrorDecoder;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.IOException;
/**
* @author fengwang
* @date 2022-07-28.
*/
public class FeignErrorDecoder implements ErrorDecoder {
private static final Logger log = LoggerFactory.getLogger(FeignErrorDecoder.class);
@Override
public Exception decode(String methodKey, Response response) {
String msg = null;
try {
msg = Util.toString(response.body().asReader(Util.UTF_8));
JSONObject object = JSONObject.parseObject(msg);
throw new RuntimeException(object.get("devMessage").toString());
} catch (IOException e) {
log.error("feign 调用失败" + e.getMessage());
}
throw new RuntimeException(methodKey + "远程调用失败");
}
}
package com.yeejoin.amos.boot.module.jxiop.api.feign;
import com.yeejoin.amos.component.feign.config.InnerInvokException;
import com.yeejoin.amos.component.feign.model.FeignClientResult;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import java.util.List;
import java.util.Map;
@FeignClient(name = "${mcb.warning.name:MCB-SERVER}", path = "warning", configuration = {FeignConfiguration.class})
public interface McbWarningFeign {
/**
* 根据风险来源查询人员红黄绿吗信息
*/
@GetMapping("/task/getQrCodeCount")
FeignClientResult<Map<String, Object>> getQrCodeCount(@RequestParam(required = false, value = "parentCode") String parentCode,
@RequestParam(value = "warningObjectType") String warningObjectType);
}
......@@ -3,7 +3,10 @@ package com.yeejoin.amos.boot.module.jxiop.biz.controller;
import com.yeejoin.amos.boot.module.jxiop.api.dto.PersonDto;
import com.yeejoin.amos.boot.module.jxiop.api.dto.StationBasicDto;
import com.yeejoin.amos.boot.module.jxiop.api.dto.UserMapperDto;
import com.yeejoin.amos.boot.module.jxiop.api.feign.McbWarningFeign;
import com.yeejoin.amos.boot.module.jxiop.api.mapper.PersonBasicMapper;
import com.yeejoin.amos.component.feign.config.InnerInvokException;
import com.yeejoin.amos.component.feign.model.FeignClientResult;
import org.apache.poi.ss.formula.functions.T;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.RequestMapping;
......@@ -12,6 +15,7 @@ import io.swagger.annotations.Api;
import org.springframework.web.bind.annotation.RestController;
import com.yeejoin.amos.boot.biz.common.controller.BaseController;
import java.math.BigDecimal;
import java.text.ParseException;
import java.util.List;
import java.util.Map;
......@@ -44,6 +48,13 @@ public class PersonBasicController extends BaseController {
@Autowired
PersonBasicServiceImpl personBasicServiceImpl;
@Autowired
McbWarningFeign mcbWarningFeign;
@Autowired
PersonBasicMapper personBasicMapper;
/**
* 新增人员基本信息
*
......@@ -208,4 +219,48 @@ public class PersonBasicController extends BaseController {
return ResponseHelper.buildResponse(resultList);
}
/**
* 评估大屏 - 人员赋码数量等统计
*
* @param parentCode 父级code
*/
@TycloudOperation(ApiLevel = UserType.AGENCY)
@GetMapping(value = "/getQrCodeCount")
@ApiOperation(httpMethod = "GET", value = "评估大屏 - 人员赋码数量等统计", notes = "评估大屏 - 人员赋码数量等统计")
public ResponseModel<Map<String, Object>> getQrCodeCount(@RequestParam(required = false, value = "parentCode") String parentCode) {
FeignClientResult<Map<String, Object>> sevenEntity = null;
try {
sevenEntity = mcbWarningFeign.getQrCodeCount(parentCode, "RYFM");
} catch (Exception e) {
e.printStackTrace();
}
if (sevenEntity != null && 200 == sevenEntity.getStatus()) {
Map<String, Object> result = sevenEntity.getResult();
String red = result.get("red").toString();
String yellow = result.get("yellow").toString();
String redToGreen = result.get("redToGreen").toString();
String yellowToGreen = result.get("yellowToGreen").toString();
Integer countAll = personBasicMapper.getPersonYardByPageCount(parentCode);
result.put("redToGreenPercent", getPercent(new BigDecimal(red), new BigDecimal(countAll)));
result.put("redPercent", getPercent(new BigDecimal(redToGreen), new BigDecimal(countAll)));
result.put("yellowToGreenPercent", getPercent(new BigDecimal(yellow), new BigDecimal(countAll)));
result.put("yellowPercent", getPercent(new BigDecimal(yellowToGreen), new BigDecimal(countAll)));
return ResponseHelper.buildResponse(result);
}
return ResponseHelper.buildResponse(null);
}
/**
* 百分比
*
* @param numerator 分子
* @param denominator 分母
* @return 百分比
*/
private double getPercent(BigDecimal numerator, BigDecimal denominator) {
BigDecimal multiply = numerator.divide(denominator.compareTo(BigDecimal.ZERO) != 0 ? denominator : new BigDecimal(1), 4, BigDecimal.ROUND_DOWN).multiply(new BigDecimal(100));
return Math.abs(multiply.doubleValue());
}
}
package com.yeejoin.amos.boot.module.jxiop.biz.emqx;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
import com.yeejoin.amos.boot.biz.common.entity.BaseEntity;
import com.yeejoin.amos.boot.module.jxiop.api.entity.PersonBasic;
import com.yeejoin.amos.boot.module.jxiop.api.mapper.PersonBasicMapper;
import com.yeejoin.amos.boot.module.jxiop.api.mapper.StationBasicMapper;
import com.yeejoin.amos.boot.module.jxiop.biz.service.impl.PersonBasicServiceImpl;
import com.yeejoin.amos.component.robot.AmosRequestContext;
import lombok.extern.slf4j.Slf4j;
import org.eclipse.paho.client.mqttv3.MqttException;
import org.eclipse.paho.client.mqttv3.MqttMessage;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.stereotype.Component;
import org.typroject.tyboot.component.emq.EmqKeeper;
import org.typroject.tyboot.component.emq.EmqxListener;
import org.typroject.tyboot.core.foundation.context.RequestContext;
import javax.annotation.PostConstruct;
import java.util.List;
import java.util.Map;
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.LinkedBlockingQueue;
@Component
@EnableScheduling
@Slf4j
public class PersonYardMessage extends EmqxListener {
@Autowired
private AmosRequestContext amosAuth;
@Autowired
protected EmqKeeper emqKeeper;
@Autowired
private PersonBasicMapper personBasicMapper;
// 江西电建接收红黄绿码主题
private static final String RYFM_WARNING_CODING = "ryfm/warning/coding";
private static final BlockingQueue<JSONObject> blockingQueue = new LinkedBlockingQueue<JSONObject>();
@PostConstruct
void init() throws Exception {
new Thread(taskRunnable).start();
emqKeeper.subscript(RYFM_WARNING_CODING, 2, this);
}
@Override
public void processMessage(String topic, MqttMessage message) throws Exception {
log.info("人员赋码消息{}", new String(message.getPayload()));
JSONObject ja = JSON.parseObject(new String(message.getPayload()));
blockingQueue.add(ja);
}
Runnable taskRunnable = new Runnable() {
@Override
public void run() {
boolean isRun = true;
int k = 0;
while (isRun) {
k++;
isRun = k < Integer.MAX_VALUE;
try {
JSONObject analysisResult = blockingQueue.take();
// RequestContext.setAppKey(amosAuth.getAppKey());
// RequestContext.setProduct(amosAuth.getProduct());
// RequestContext.setToken(amosAuth.getToken());
jxIopUpdate(analysisResult);
} catch (Exception e) {
e.printStackTrace();
}
}
}
};
public void jxIopUpdate(JSONObject analysisResult) {
log.info("人员赋码数据:{}", analysisResult);
String warningObjectCode = String.valueOf(analysisResult.get("warningObjectCode"));
String codeColor = String.valueOf(analysisResult.get("codeColor"));
PersonBasic personBasic = personBasicMapper.selectById(warningObjectCode);
if (ObjectUtils.isEmpty(personBasic)) {
try {
emqKeeper.getMqttClient().publish("ryfm/warning/coding", analysisResult.toJSONString().getBytes(), 2, Boolean.FALSE);
} catch (MqttException e) {
e.printStackTrace();
}
} else {
personBasic.setQrcodeColor(codeColor);
personBasicMapper.updateById(personBasic);
}
}
}
......@@ -64,9 +64,9 @@ public class StationYardMessage extends EmqxListener {
isRun = k < Integer.MAX_VALUE;
try {
List<Map<String, String>> analysisResult = blockingQueue.take();
RequestContext.setAppKey(amosAuth.getAppKey());
RequestContext.setProduct(amosAuth.getProduct());
RequestContext.setToken(amosAuth.getToken());
// RequestContext.setAppKey(amosAuth.getAppKey());
// RequestContext.setProduct(amosAuth.getProduct());
// RequestContext.setToken(amosAuth.getToken());
jxIopUpdate(analysisResult);
} catch (Exception e) {
e.printStackTrace();
......
package com.yeejoin.amos.boot.module.jxiop.biz.service.impl;
import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
import com.yeejoin.amos.boot.biz.common.feign.AmosFeignService;
import com.yeejoin.amos.boot.biz.common.utils.DateUtils;
import com.yeejoin.amos.boot.biz.common.utils.RedisUtils;
import com.yeejoin.amos.boot.module.jxiop.api.Enum.QrcodeColorEnum;
import com.yeejoin.amos.boot.module.jxiop.api.dto.BizMessage;
import com.yeejoin.amos.boot.module.jxiop.api.dto.RiskBizInfoVo;
import com.yeejoin.amos.boot.module.jxiop.api.entity.PersonAccount;
import com.yeejoin.amos.boot.module.jxiop.api.entity.PersonBasic;
import com.yeejoin.amos.boot.module.jxiop.api.entity.PersonCertificate;
import com.yeejoin.amos.boot.module.jxiop.api.mapper.PersonAccountMapper;
import com.yeejoin.amos.boot.module.jxiop.api.mapper.PersonBasicMapper;
import com.yeejoin.amos.boot.module.jxiop.api.mapper.PersonCertificateMapper;
import com.yeejoin.amos.boot.module.jxiop.api.util.Constants;
import com.yeejoin.amos.feign.systemctl.model.DictionarieValueModel;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.eclipse.paho.client.mqttv3.MqttException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import org.typroject.tyboot.component.emq.EmqKeeper;
import java.nio.charset.StandardCharsets;
import java.text.ParseException;
import java.util.*;
import java.util.stream.Collectors;
......@@ -42,6 +50,14 @@ public class PersonYardTimeTask {
@Autowired
private RedisUtils redisUtils;
@Autowired
private PersonAccountMapper personAccountMapper;
@Autowired
protected EmqKeeper emqKeeper;
@Scheduled(cron = "0 0 0 1/1 * ? ")
public void timeYardTimeTask() {
if (!redisUtils.hasKey(Constants.JXIOP_DICT_POST) || !redisUtils.hasKey(Constants.JXIOP_DICT_CERTIFICATES)) {
......@@ -55,13 +71,15 @@ public class PersonYardTimeTask {
List<PersonCertificate> personCertificates = personCertificateMapper.selectList(null);
List<PersonAccount> personAccounts = personAccountMapper.selectList(null);
Map<Long, PersonAccount> personAccountMap = personAccounts.stream().collect(Collectors.toMap(PersonAccount::getPersonId, t -> t));
Map<Long, List<PersonCertificate>> perCertificateMap = personCertificates.stream().filter(item -> ObjectUtils.isNotEmpty(item.getPersonId())).collect(Collectors.groupingBy(PersonCertificate::getPersonId));
List<PersonBasic> personBasics = new ArrayList<>();
personBasicList.forEach(personBasic -> {
List<PersonCertificate> personCertificateList = perCertificateMap.get(personBasic.getSequenceNbr());
PersonAccount personAccount = personAccountMap.get(personBasic.getSequenceNbr());
String yuanShiQrcodeColor = personBasic.getQrcodeColor();
List<PersonCertificate> personCertificateList = perCertificateMap.get(personBasic.getSequenceNbr());
//默认红码
personBasic.setQrcodeColor(QrcodeColorEnum.RED.getCode());
// 该岗位应获得的证书
......@@ -97,18 +115,46 @@ public class PersonYardTimeTask {
list.remove(item.getCertificateName());
}
}
String qrcodeDescOld = personBasic.getQrcodeDesc();
String qrcodeColorOld = personBasic.getQrcodeColor();
if (CollectionUtils.isEmpty(list) && isInMonth == 0 && isOver == 0) {
personBasic.setQrcodeColor(QrcodeColorEnum.GREEN.getCode());
personBasic.setQrcodeDesc("证书齐全");
} else if (CollectionUtils.isEmpty(list) && isOver == 1) {
personBasic.setQrcodeColor(QrcodeColorEnum.RED.getCode());
personBasic.setQrcodeDesc("证书不全");
} else if (CollectionUtils.isEmpty(list) && isOver == 0 && isInMonth == 1) {
personBasic.setQrcodeColor(QrcodeColorEnum.YELLOW.getCode());
personBasic.setQrcodeDesc("证书临期");
}
if (!yuanShiQrcodeColor.equals(personBasic.getQrcodeColor())) {
if (!qrcodeDescOld.equals(personBasic.getQrcodeDesc())) {
personBasic.setRecDate(new Date());
personBasics.add(personBasic);
personBasicService.updateById(personBasic);
if (("证书不全".equals(personBasic.getQrcodeDesc()) ||
"证书临期".equals(personBasic.getQrcodeDesc()))) {
BizMessage bizMessage = new BizMessage();
bizMessage.setIndexKey("RYFM");
bizMessage.setIndexValue(personBasic.getPostName() + personBasic.getQrcodeDesc());
RiskBizInfoVo riskBizInfoVo = personBasicService.fetchData(personBasic, personAccount);
bizMessage.setBizInfo(riskBizInfoVo);
try {
emqKeeper.getMqttClient().publish(PersonBasicServiceImpl.RYFM_DATA_MQTT_TOPIC, JSON.toJSONString(bizMessage).getBytes(StandardCharsets.UTF_8), 2, false);
} catch (MqttException e) {
e.printStackTrace();
}
}
} else if ("证书齐全".equals(personBasic.getQrcodeDesc())) {
HashMap<String, String> personMap = new HashMap<>();
personMap.put("objectId", String.valueOf(personBasic.getSequenceNbr()));
personMap.put("qrCodeColor", qrcodeColorOld);
personMap.put("warningObjectType", "RYFM");
personMap.put("sourceAttribution", personBasic.getProjectOrgCode());
personMap.put("sourceAttributionDesc", personAccount.getProjectName());
try {
emqKeeper.getMqttClient().publish(PersonBasicServiceImpl.RYFM_GREEN, JSON.toJSONString(personMap).getBytes(StandardCharsets.UTF_8), 2, false);
} catch (MqttException e) {
e.printStackTrace();
}
}
});
personBasicService.updateBatchById(personBasics);
}
}
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