361 lines
17 KiB
Java
361 lines
17 KiB
Java
package com.adc.da.mq;
|
|
|
|
import com.adc.da.slrs.otSvpps.service.IOtSvppsService;
|
|
import com.adc.da.slrs.sarBussionessStand.entity.SarBussionessStand;
|
|
import com.adc.da.slrs.sarLawsStandInfo.entity.SarLawsStandInfo;
|
|
import com.adc.da.slrs.sarStandardsInfo.service.ISarStandardsInfoService;
|
|
import com.adc.da.slrs.sysInfo.service.SysInfoEOService;
|
|
import com.adc.da.sys.dao.DicTypeEODao;
|
|
import com.adc.da.sys.entity.DicTypeEO;
|
|
import com.adc.da.utils.util.InitStandAttrUtil;
|
|
import com.alibaba.fastjson.JSON;
|
|
import com.rabbitmq.client.Channel;
|
|
import net.sf.json.JSONObject;
|
|
import org.apache.commons.lang.StringUtils;
|
|
import org.json.JSONTokener;
|
|
import org.slf4j.Logger;
|
|
import org.slf4j.LoggerFactory;
|
|
import org.springframework.amqp.rabbit.annotation.Exchange;
|
|
import org.springframework.amqp.rabbit.annotation.Queue;
|
|
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.Message;
|
|
import org.springframework.stereotype.Component;
|
|
|
|
import java.text.ParseException;
|
|
import java.text.SimpleDateFormat;
|
|
import java.util.*;
|
|
import java.util.stream.Collectors;
|
|
|
|
@Component
|
|
public class SendLawsMQService {
|
|
|
|
@Autowired
|
|
private ISarStandardsInfoService sarStandardsInfoService;
|
|
|
|
@Autowired
|
|
private SysInfoEOService sysInfoEOService;
|
|
|
|
@Autowired
|
|
private DicTypeEODao dicTypeEODao;
|
|
|
|
private static final Logger logger = LoggerFactory.getLogger(SendLawsMQService.class);
|
|
|
|
|
|
@RabbitListener(bindings = @QueueBinding(
|
|
value = @Queue(value = "createLawsMQ_SQ_GSAR_RELEASE", durable = "true"),
|
|
exchange = @Exchange(value = "laws-exchange_SQ_GSAR_RELEASE", ignoreDeclarationExceptions = "true"),
|
|
key = "laws-key_SQ_GSAR_RELEASE"))
|
|
public void createMQ(Map<String,Object> bussMap, Message message, Channel channel) throws Exception{
|
|
try{
|
|
try{
|
|
Thread.sleep(5000);
|
|
insertOrUpdateBussInfo(bussMap);
|
|
}catch(InterruptedException e){
|
|
logger.error(e.toString());
|
|
Thread.currentThread().interrupt();
|
|
}
|
|
} catch (Exception e) {
|
|
logger.error("搜索中心国内外政策消息队列进入转换前失败!");
|
|
logger.error(e.getMessage(),e);
|
|
} finally {
|
|
Long tag = (Long) message.getHeaders().get(AmqpHeaders.DELIVERY_TAG);
|
|
channel.basicAck(tag,false);
|
|
logger.debug("消息确认成功!!!!!!!!!");
|
|
}
|
|
}
|
|
|
|
public void insertOrUpdateBussInfo(Map<String,Object> bussMap) throws Exception {
|
|
String addOrUpdate = bussMap.get("addOrUpdate").toString();
|
|
String sarBuss = bussMap.get("sarLaws").toString();
|
|
JSONObject jsonobject = JSONObject.fromObject(sarBuss);
|
|
SarLawsStandInfo infoEO = com.alibaba.fastjson.JSONObject.parseObject(sarBuss,SarLawsStandInfo.class);
|
|
|
|
if(infoEO.getMapItems() == null || infoEO.getMapItems().isEmpty()){
|
|
if(jsonobject.get("mapItems") != null){
|
|
infoEO.setMapItems(net.sf.json.JSONObject.fromObject(jsonobject.get("mapItems")));
|
|
}
|
|
}
|
|
// SarLawsStandInfo infoEO = (SarLawsStandInfo) JSONObject.toBean(jsonobject,SarLawsStandInfo.class);
|
|
|
|
String FZRQFSRQ = null;
|
|
if ("updateFromAct".equals(addOrUpdate)){
|
|
addOrUpdate = "update";
|
|
FZRQFSRQ = "1";
|
|
}
|
|
|
|
//查询字典表,形成Hash映射提升速度
|
|
List<DicTypeEO> dicInfo = dicTypeEODao.getDicInfo("dic_id","dic_type_code", "dic_type_name","show_index");
|
|
dicInfo = dicInfo.stream().filter(dicTypeEO -> {
|
|
if(org.apache.commons.lang3.StringUtils.isNotBlank(dicTypeEO.getDicTypeCode())){
|
|
dicTypeEO.setDicTypeCode(dicTypeEO.getDicTypeCode().replace(" ",""));
|
|
return true;
|
|
}
|
|
return false;
|
|
}).collect(Collectors.toList());
|
|
Map<String, Integer> dicMap = dicInfo.stream()
|
|
.filter(item-> ("2klxdk7fo3tvpvin70dk".equals(item.getDicId()) || "18mg1g4x0rwubcto7fdd".equals(item.getDicId()) || "08rerbsn8ucjfk13z2ci".equals(item.getDicId()) || "pnv0ik979yqogocqujwo".equals(item.getDicId())) && !item.getDicTypeCode().isEmpty())
|
|
.collect(Collectors.toMap(DicTypeEO::getDicTypeCode,DicTypeEO::getShowIndex,(value1, value2 )->value2));
|
|
|
|
|
|
String sarStandAttrEOStr = infoEO.getSarStandAttrEOStr();
|
|
Map<String,Object> attrInfoMap = JSONObject.fromObject(sarStandAttrEOStr);
|
|
Map<String,Object> infoMap = infoEO.getAttrInfoCaseMap();
|
|
Map<String,String> infoEOMapItems = infoEO.getMapItems();
|
|
|
|
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
|
|
//修改索引信息表
|
|
// 往索引表中插入数据
|
|
String baseSearchContent = "";
|
|
String getCodeName = "";
|
|
Map<String,Object> saveMap = new HashMap<>();
|
|
saveMap.put("standType","laws");
|
|
//发布日期 高级查询
|
|
saveMap.put("issueTime",dateFormatToStr(infoEO.getIssueTime()));
|
|
Date issue_time_data = null;
|
|
if (StringUtils.isNotBlank(infoEO.getIssueTime())) {
|
|
try {
|
|
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
|
issue_time_data = format.parse(dateFormatToStr(infoEO.getIssueTime())+" 00:00:00");
|
|
} catch (ParseException ignored) {
|
|
}
|
|
}
|
|
if (issue_time_data != null) {
|
|
saveMap.put("issue_time_data",issue_time_data.getTime());
|
|
}else{
|
|
saveMap.put("issue_time_data",-1000000000000000000L);
|
|
}
|
|
|
|
//征集意见周期-起始时间
|
|
saveMap.put("commentCycleStart",dateFormatToStr(infoEO.getCommentCycleStart()));
|
|
Date commentCycleStart_data = null;
|
|
if (StringUtils.isNotBlank(infoEO.getCommentCycleStart())) {
|
|
try {
|
|
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
|
commentCycleStart_data = format.parse(dateFormatToStr(infoEO.getCommentCycleStart())+" 00:00:00");
|
|
} catch (ParseException ignored) {
|
|
}
|
|
}
|
|
if (commentCycleStart_data != null) {
|
|
saveMap.put("commentCycleStart_data",commentCycleStart_data.getTime());
|
|
}else{
|
|
saveMap.put("commentCycleStart_data",-1000000000000000000L);
|
|
}
|
|
|
|
//征集意见周期-结束时间
|
|
saveMap.put("commentCycleEnd",dateFormatToStr(infoEO.getCommentCycleEnd()));
|
|
Date commentCycleEnd_data = null;
|
|
if (StringUtils.isNotBlank(infoEO.getCommentCycleStart())) {
|
|
try {
|
|
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
|
commentCycleEnd_data = format.parse(dateFormatToStr(infoEO.getCommentCycleStart())+" 00:00:00");
|
|
} catch (ParseException ignored) {
|
|
}
|
|
}
|
|
if (commentCycleEnd_data != null) {
|
|
saveMap.put("commentCycleEnd_data",commentCycleEnd_data.getTime());
|
|
}else{
|
|
saveMap.put("commentCycleEnd_data",-1000000000000000000L);
|
|
}
|
|
|
|
saveMap.put("id",infoEO.getId());
|
|
String lawsTypeName = "";
|
|
if(infoEO.getLawsTextState() != null && StringUtils.isNotBlank(infoEO.getLawsType())){
|
|
List<String> valArr = Arrays.asList(infoEO.getLawsType().split(","));
|
|
lawsTypeName = dicTypeEODao.getDicNamesByCodes(valArr,"");
|
|
}
|
|
saveMap.put("standSortOrder",esStateOrder(infoEO.getLawsType(),dicMap));
|
|
saveMap.put("lawsType",infoEO.getLawsType());
|
|
saveMap.put("lawsTypeName",lawsTypeName);
|
|
saveMap.put("lawsNumber",infoEO.getLawsNumber());
|
|
saveMap.put("lawsName",infoEO.getLawsName());
|
|
saveMap.put("lawsEnName",infoEO.getLawsEnName());
|
|
saveMap.put("lawsNo",infoEO.getLawsNo());
|
|
saveMap.put("issueCompany",infoEO.getIssueCompany());
|
|
String lawsSyqyName = "";
|
|
if(infoEO.getLawsTextState() != null && StringUtils.isNotBlank(infoEO.getLawsSyqy())){
|
|
List<String> valArr = Arrays.asList(infoEO.getLawsSyqy().split(","));
|
|
lawsSyqyName = dicTypeEODao.getDicNamesByCodes(valArr,"");
|
|
}
|
|
saveMap.put("lawsSyqy",infoEO.getLawsSyqy());
|
|
saveMap.put("lawsSyqyName",lawsSyqyName);
|
|
String lawsSycxName = "";
|
|
if(infoEO.getLawsTextState() != null && StringUtils.isNotBlank(infoEO.getLawsSycx())){
|
|
List<String> valArr = Arrays.asList(infoEO.getLawsSycx().split(","));
|
|
lawsSycxName = dicTypeEODao.getDicNamesByCodes(valArr,"");
|
|
}
|
|
saveMap.put("lawsSycx",infoEO.getLawsSycx());
|
|
saveMap.put("lawsSycxName",lawsSycxName);
|
|
String isRelateAccessName = "";
|
|
if(infoEO.getIsRelateAccess() != null && StringUtils.isNotBlank(infoEO.getIsRelateAccess())){
|
|
if(infoEO.getIsRelateAccess().equals("1")){
|
|
isRelateAccessName = "是";
|
|
}else {
|
|
isRelateAccessName = "否";
|
|
}
|
|
}
|
|
saveMap.put("isRelateAccess",infoEO.getIsRelateAccess());
|
|
saveMap.put("isRelateAccessName",isRelateAccessName);
|
|
String lawsYearName = "";
|
|
if(infoEO.getLawsTextState() != null && StringUtils.isNotBlank(infoEO.getLawsYear())){
|
|
List<String> valArr = Arrays.asList(infoEO.getLawsYear().split(","));
|
|
lawsYearName = dicTypeEODao.getDicNamesByCodes(valArr,"");
|
|
}
|
|
saveMap.put("lawsYear",infoEO.getLawsYear());
|
|
saveMap.put("lawsYearName",lawsYearName);
|
|
saveMap.put("lawsNotisyncNum",infoEO.getLawsNotisyncNum());
|
|
saveMap.put("lawsBulletin",infoEO.getLawsBulletin());
|
|
String lawsLabelName = "";
|
|
if(infoEO.getLawsTextState() != null && StringUtils.isNotBlank(infoEO.getLawsLabel())){
|
|
List<String> valArr = Arrays.asList(infoEO.getLawsLabel().split(","));
|
|
lawsLabelName = dicTypeEODao.getDicNamesByCodes(valArr,"");
|
|
}
|
|
saveMap.put("lawsLabel",infoEO.getLawsLabel());
|
|
saveMap.put("lawsLabelName",lawsLabelName);
|
|
saveMap.put("lawsRemark",infoEO.getLawsRemark());
|
|
String lawsTextStateName = "";
|
|
if(infoEO.getLawsTextState() != null && StringUtils.isNotBlank(infoEO.getLawsTextState())){
|
|
List<String> valArr = Arrays.asList(infoEO.getLawsTextState().split(","));
|
|
lawsTextStateName = dicTypeEODao.getDicNamesByCodes(valArr,"");
|
|
}
|
|
saveMap.put("lawsTextState",infoEO.getLawsTextState());
|
|
saveMap.put("lawsTextStateName",lawsTextStateName);
|
|
//新加字段
|
|
saveMap.put("country",infoEO.getCountry());
|
|
if(StringUtils.isNotEmpty(infoEO.getCountry())){
|
|
String codeName = sysInfoEOService.getDicNamesByCodes(infoEO.getCountry(),"RFRFRFSCXVB");
|
|
saveMap.put("countryShow",codeName);
|
|
}
|
|
// 自定义属性字段
|
|
if (attrInfoMap != null && !attrInfoMap.isEmpty()) {
|
|
attrInfoMap = sysInfoEOService.changeSelectInfo(attrInfoMap, "laws",baseSearchContent);
|
|
saveMap.putAll(attrInfoMap);
|
|
}
|
|
|
|
saveMap.put("type","laws");
|
|
saveMap.put("validFlag","0");
|
|
saveMap.put("content",infoEO.getFileIds());
|
|
|
|
String fieldInfo = InitStandAttrUtil.queryFieldLaws;
|
|
List<String> fieldInfoList = Arrays.asList(fieldInfo .split(",")).stream().map(s -> (s.trim())).collect(Collectors.toList());
|
|
|
|
// 动态存储属性字段
|
|
for (String field : fieldInfoList) {
|
|
saveMap.put(field,attrInfoMap.getOrDefault(field,""));
|
|
String fieldValue = "";
|
|
String fieldFilter = field.toLowerCase();
|
|
if(infoMap.get(fieldFilter) != null && StringUtils.isNotBlank(infoMap.get(fieldFilter).toString())){
|
|
Object json= new JSONTokener(infoMap.get(fieldFilter).toString()).nextValue();
|
|
if(json instanceof org.json.JSONArray){
|
|
fieldValue = String.join(",", com.alibaba.fastjson.JSONObject.parseArray(infoMap.get(fieldFilter).toString(),String.class));
|
|
}else {
|
|
if(!("null").equals(json)){
|
|
fieldValue = infoMap.get(fieldFilter).toString();
|
|
}
|
|
}
|
|
if(fieldValue.contains("null")){
|
|
fieldValue = fieldValue.replace("null","");
|
|
}
|
|
}
|
|
saveMap.put(field+"Name",fieldValue);
|
|
}
|
|
|
|
if(infoEOMapItems != null && !infoEOMapItems.isEmpty()){
|
|
saveMap.put("mapItems",infoEOMapItems);
|
|
}
|
|
|
|
//当建立代替时,产生的没有文件的问题
|
|
if (StringUtils.isBlank(String.valueOf(saveMap.get("content")))) {
|
|
String context = filterStringIsNotBlank(String.valueOf(saveMap.get("ZCWBLAWS")),true)
|
|
+ filterStringIsNotBlank(String.valueOf(saveMap.get("GCWBLAWS")),true)
|
|
+ filterStringIsNotBlank(String.valueOf(saveMap.get("JDWJLAWS")),true)
|
|
+ filterStringIsNotBlank(String.valueOf(saveMap.get("GLWJLAWS")),true);
|
|
context = context.replace(",,", ",");
|
|
saveMap.put("content", context);
|
|
}
|
|
if("add".equals(addOrUpdate)){
|
|
sarStandardsInfoService.insertIntoIndexForMap(saveMap);
|
|
} else {
|
|
sarStandardsInfoService.updateIntoIndexForMap(saveMap);
|
|
}
|
|
}
|
|
|
|
private String esStateOrder(String data, Map<String, Integer> dicMap){
|
|
if(StringUtils.isNotBlank(data)){
|
|
data = data.replace(" ","");
|
|
if(dicMap.get(data.trim().toUpperCase()) != null){
|
|
return String.valueOf(dicMap.get(data.trim().toUpperCase()));
|
|
}else {
|
|
return "99999";
|
|
}
|
|
}else {
|
|
return "99999";
|
|
}
|
|
}
|
|
|
|
private String filterStringIsNotBlank(String str,boolean boo){
|
|
String f = ",";
|
|
return (str == null || str.equals("") || str.equals("null")) ? "" : (boo ? str+f : str);
|
|
}
|
|
|
|
private String dateFormatToStr(String dateStr){
|
|
if(dateStr == null || dateStr.equals("")){
|
|
return "";
|
|
}
|
|
String dateToStr = "";
|
|
try {
|
|
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
|
|
dateToStr = dateFormat.format(dateFormat.parse(dateStr.trim().substring(0,10)));
|
|
}catch (Exception e){
|
|
e.getMessage();
|
|
}
|
|
return dateToStr;
|
|
}
|
|
|
|
public Map<String,Object> dealNumberMsg (Map<String,Object> saveMap,SarBussionessStand infoEO,String getCodeName) {
|
|
/*if(StringUtils.isNotEmpty(infoEO.getStandYear())){
|
|
String num = getCodeName + " " + infoEO.getStandCode() + "-" + infoEO.getStandYear();
|
|
saveMap.put("numbershow",num);
|
|
int index = infoEO.getStandCode().indexOf(".");
|
|
int index1 = infoEO.getStandCode().indexOf(":");
|
|
String numberExpNull = "";
|
|
if(index > -1){
|
|
numberExpNull = getCodeName + infoEO.getStandCode() + "-" + num.replaceAll(" ","")
|
|
+ "-" + getCodeName + infoEO.getStandCode().substring(0,index) + "-" + infoEO.getStandCode().substring(0,index);
|
|
}else if(index1 > -1){
|
|
numberExpNull = getCodeName + infoEO.getStandCode() + "-" + num.replaceAll(" ","")
|
|
+ "-" + getCodeName + infoEO.getStandCode().substring(0,index1) + "-" + infoEO.getStandCode().substring(0,index1);
|
|
}else{
|
|
numberExpNull = getCodeName + infoEO.getStandCode() + "-" + num.replaceAll(" ","");
|
|
}
|
|
} else {
|
|
String number = getCodeName + " " + infoEO.getStandCode();
|
|
saveMap.put("numbershow",number);
|
|
String numberExpNull = "";
|
|
int index = infoEO.getStandCode().indexOf(".");
|
|
if(index > -1){
|
|
numberExpNull = getCodeName + infoEO.getStandCode() + "-" + number.replaceAll(" ","")
|
|
+ "-" + getCodeName + infoEO.getStandCode().substring(0,index) + "-" + infoEO.getStandCode().substring(0,index);
|
|
}else{
|
|
numberExpNull = getCodeName + infoEO.getStandCode() + "-" + number.replaceAll(" ","");
|
|
}
|
|
saveMap.put("numberExpNull",numberExpNull);
|
|
}*/
|
|
String number = infoEO.getStandCode();
|
|
saveMap.put("numbershow",number);
|
|
String numberExpNull = "";
|
|
int index = infoEO.getStandCode().indexOf(".");
|
|
if(index > -1){
|
|
numberExpNull = infoEO.getStandCode() + "-" + number.replaceAll(" ","")
|
|
+ "-" + infoEO.getStandCode().substring(0,index) + "-" + infoEO.getStandCode().substring(0,index);
|
|
}else{
|
|
numberExpNull = infoEO.getStandCode() + "-" + number.replaceAll(" ","");
|
|
}
|
|
saveMap.put("numberExpNull",numberExpNull);
|
|
return saveMap;
|
|
}
|
|
|
|
}
|