389 lines
18 KiB
Java
389 lines
18 KiB
Java
package com.adc.da.mq;
|
||
|
||
import com.adc.da.slrs.otSvpps.service.IOtSvppsService;
|
||
import com.adc.da.slrs.sarBussStandMenu.entity.SarBussStandMenu;
|
||
import com.adc.da.slrs.sarBussStandMenu.service.ISarBussStandMenuService;
|
||
import com.adc.da.slrs.sarBussionessStand.entity.SarBussionessStand;
|
||
import com.adc.da.slrs.sarResource.entity.TsResource;
|
||
import com.adc.da.slrs.sarResource.service.ITsResourceService;
|
||
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.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||
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 javax.annotation.Resource;
|
||
import java.text.ParseException;
|
||
import java.text.SimpleDateFormat;
|
||
import java.util.*;
|
||
import java.util.stream.Collectors;
|
||
|
||
@Component
|
||
public class SendBussMQService {
|
||
|
||
@Autowired
|
||
private ISarStandardsInfoService sarStandardsInfoService;
|
||
|
||
@Resource
|
||
private ISarBussStandMenuService sarBussMenusService;
|
||
|
||
@Resource
|
||
private ITsResourceService tsResourceService;
|
||
|
||
@Autowired
|
||
private SysInfoEOService sysInfoEOService;
|
||
|
||
@Autowired
|
||
private DicTypeEODao dicTypeEODao;
|
||
|
||
@Autowired
|
||
private IOtSvppsService otSvppsEOService;
|
||
|
||
private static final Logger logger = LoggerFactory.getLogger(SendBussMQService.class);
|
||
|
||
|
||
@RabbitListener(bindings = @QueueBinding(
|
||
value = @Queue(value = "createBussMQ_SQ_GSAR_RELEASE", durable = "true"),
|
||
exchange = @Exchange(value = "buss-exchange_SQ_GSAR_RELEASE", ignoreDeclarationExceptions = "true"),
|
||
key = "buss-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("sarBuss").toString();
|
||
JSONObject jsonobject = JSONObject.fromObject(sarBuss);
|
||
SarBussionessStand infoEO = (SarBussionessStand) JSONObject.toBean(jsonobject,SarBussionessStand.class);
|
||
String FZRQFSRQ = null;
|
||
if ("updateFromAct".equals(addOrUpdate)){
|
||
addOrUpdate = "update";
|
||
FZRQFSRQ = "1";
|
||
}
|
||
|
||
String sarStandAttrEOStr = infoEO.getSarStandAttrEOStr();
|
||
Map<String,Object> attrInfoMap = JSONObject.fromObject(sarStandAttrEOStr);
|
||
Map<String,Object> infoMap = infoEO.getAttrInfoCaseMap();
|
||
|
||
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
|
||
//修改索引信息表
|
||
// 往索引表中插入数据
|
||
String baseSearchContent = "";
|
||
String getCodeName = "";
|
||
Map<String,Object> saveMap = new HashMap<>();
|
||
|
||
//发布日期 高级查询
|
||
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",-100000000L);
|
||
}
|
||
|
||
//实施日期 高级查询
|
||
saveMap.put("putTime",dateFormatToStr(infoEO.getPutTime()));
|
||
Date put_time_data = null;
|
||
if (StringUtils.isNotBlank(infoEO.getPutTime())) {
|
||
try {
|
||
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
||
put_time_data = format.parse(dateFormatToStr(infoEO.getPutTime())+" 00:00:00");
|
||
} catch (ParseException ignored) {
|
||
}
|
||
}
|
||
if (put_time_data != null) {
|
||
// ES对比按照字符串比较,因此9位时间戳前加0
|
||
Date putTime = null;
|
||
try {
|
||
putTime = sdf.parse(infoEO.getPutTime());
|
||
String putTimeStr = String.valueOf(putTime.getTime());
|
||
saveMap.put("putDate",sdf.format(putTime));
|
||
if (putTimeStr.length() > 12) {
|
||
saveMap.put("put_time_data",putTimeStr);
|
||
} else {
|
||
saveMap.put("put_time_data","0" + putTimeStr);
|
||
logger.info("前面加零的put_time_data:"+saveMap.get("put_time_data"));
|
||
}
|
||
} catch (ParseException e) {
|
||
saveMap.put("put_time_data",-100000000L);
|
||
saveMap.put("putDate",null);
|
||
}
|
||
}else{
|
||
saveMap.put("put_time_data",-100000000L);
|
||
saveMap.put("putDate",null);
|
||
}
|
||
logger.info("saveMap实施日期:"+saveMap.get("put_time_data"));
|
||
saveMap.put("warehousingTime",sdf.format(infoEO.getCreationTime())); // 入库时间
|
||
if (infoEO.getCreationTime().getTime() > 12) {
|
||
saveMap.put("warehousingTimeStamp",infoEO.getCreationTime().getTime()); // 入库时间戳
|
||
}else {
|
||
saveMap.put("warehousingTimeStamp", "0" + infoEO.getCreationTime().getTime()); // 入库时间戳
|
||
}
|
||
|
||
|
||
//查询字典表,形成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));
|
||
|
||
|
||
saveMap.put("id",infoEO.getId());
|
||
saveMap.put("standSortOrder",esStateOrder(String.valueOf(infoEO.getStandSort()),dicMap));
|
||
|
||
// saveMap.put("standSort",infoEO.getStandSort());
|
||
// saveMap.put("stand_sort",infoEO.getStandSort());
|
||
saveMap.put("standSort",convertStandSort(infoEO.getId()));
|
||
saveMap.put("stand_sort",convertStandSort(infoEO.getId()));
|
||
if(StringUtils.isNotEmpty(infoEO.getStandSort())){
|
||
String codeName = sysInfoEOService.getDicNamesByCodes(infoEO.getStandSort(),"JKSADFH564S");
|
||
saveMap.put("standSortShow",codeName);
|
||
getCodeName = codeName;
|
||
}
|
||
saveMap.put("standYear",infoEO.getStandYear());
|
||
saveMap.put("stand_year",infoEO.getStandYear());
|
||
if(jsonobject.get("standNumber") != null){
|
||
saveMap.put("standNumber",jsonobject.get("standNumber"));
|
||
}else {
|
||
saveMap.put("standNumber","");
|
||
}
|
||
|
||
saveMap.put("stand_code",infoEO.getStandCode());
|
||
saveMap = dealNumberMsg(saveMap,infoEO,infoEO.getStandSort());
|
||
saveMap.put("nameshow",infoEO.getStandName());
|
||
saveMap.put("stand_name",infoEO.getStandName());
|
||
saveMap.put("standEnName",infoEO.getStandEnName());
|
||
saveMap.put("stand_en_name",infoEO.getStandEnName());
|
||
saveMap.put("replaceStandNum",infoEO.getReplaceStandNum());
|
||
saveMap.put("replace_stand_num",infoEO.getReplaceStandNum());
|
||
saveMap.put("replacedStandNum",infoEO.getReplacedStandNum());
|
||
saveMap.put("replaced_stand_num",infoEO.getReplacedStandNum());
|
||
saveMap.put("statecode",infoEO.getStandStatus());
|
||
saveMap.put("stand_status",infoEO.getStandStatus());
|
||
if (StringUtils.isNotEmpty(infoEO.getStandStatus())) {
|
||
String codeName = sysInfoEOService.getDicNamesByCodes(infoEO.getStandStatus(),"");
|
||
saveMap.put("standstateshow",codeName);
|
||
}
|
||
String textStatusBussName = "";
|
||
if(infoEO.getTextStatusBuss() != null && StringUtils.isNotBlank(infoEO.getTextStatusBuss())){
|
||
List<String> valArr = Arrays.asList(infoEO.getTextStatusBuss().split(","));
|
||
textStatusBussName = dicTypeEODao.getDicNamesByCodes(valArr,"");
|
||
}
|
||
saveMap.put("textStatusBuss",infoEO.getTextStatusBuss());
|
||
saveMap.put("textStatusBussName",textStatusBussName);
|
||
//新加字段
|
||
saveMap.put("country",infoEO.getApplyCountry());
|
||
if(StringUtils.isNotEmpty(infoEO.getApplyCountry())){
|
||
String codeName = sysInfoEOService.getDicNamesByCodes(infoEO.getApplyCountry(),"RFRFRFSCXVB");
|
||
saveMap.put("countryShow",codeName);
|
||
}
|
||
// 自定义属性字段
|
||
if (attrInfoMap != null && !attrInfoMap.isEmpty()) {
|
||
attrInfoMap = sysInfoEOService.changeSelectInfo(attrInfoMap, "stand",baseSearchContent);
|
||
saveMap.putAll(attrInfoMap);
|
||
}
|
||
|
||
saveMap.put("type","bussstand");
|
||
saveMap.put("validFlag","0");
|
||
saveMap.put("content",infoEO.getFileIds());
|
||
|
||
String fieldInfo = InitStandAttrUtil.queryFieldBuss;
|
||
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 (StringUtils.isBlank(String.valueOf(saveMap.get("content")))) {
|
||
String context = filterStringIsNotBlank(String.valueOf(saveMap.get("FBGBUSS")),true)
|
||
+ filterStringIsNotBlank(String.valueOf(saveMap.get("BZSMBUSS")),true)
|
||
+ filterStringIsNotBlank(String.valueOf(saveMap.get("LSBBBUSS")),true)
|
||
+ filterStringIsNotBlank(String.valueOf(saveMap.get("QTWJBUSS")),true)
|
||
+ filterStringIsNotBlank(String.valueOf(saveMap.get("GLWJBUSS")),true);
|
||
context = context.replace(",,", ",");
|
||
saveMap.put("content", context);
|
||
}
|
||
String numberShow = String.valueOf(saveMap.get("numbershow"));
|
||
if (!"null".equals(numberShow) && StringUtils.isNotBlank(numberShow)) {
|
||
saveMap.put("titleBig", numberShow.toUpperCase());
|
||
}
|
||
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;
|
||
}
|
||
|
||
public String convertStandSort(String standId) {
|
||
QueryWrapper<SarBussStandMenu> wrapper = new QueryWrapper<>();
|
||
wrapper.eq("BUSS_STAND_ID", standId);
|
||
wrapper.gt("length(MENU_ID)", 0);
|
||
wrapper.select("MENU_ID");
|
||
List<SarBussStandMenu> sarStandMenuList = sarBussMenusService.list(wrapper);
|
||
if (sarStandMenuList.isEmpty()) {
|
||
return null;
|
||
}
|
||
List<String> standMenuIdSet = sarStandMenuList.stream().map(SarBussStandMenu::getMenuId).collect(Collectors.toList());
|
||
List<String> standMenuList = new ArrayList<>();
|
||
for (String menuId : standMenuIdSet) {
|
||
List<String> result = new ArrayList<>();
|
||
recursivelyFetchParentNodes(menuId, result);
|
||
standMenuList.add(String.join("/", result));
|
||
}
|
||
return String.join(",", standMenuList);
|
||
}
|
||
|
||
private void recursivelyFetchParentNodes(String currentId, List<String> result) {
|
||
TsResource menu = null;
|
||
try {
|
||
menu = tsResourceService.getById(currentId);
|
||
if (menu != null) {
|
||
result.add(0,menu.getMenuName());
|
||
if (StringUtils.isNotEmpty(menu.getParentId())) {
|
||
recursivelyFetchParentNodes(menu.getParentId(), result);
|
||
}
|
||
}
|
||
} catch (Exception e) {
|
||
e.printStackTrace();
|
||
}
|
||
}
|
||
|
||
}
|