Commit 2cfe5c6a authored by 赵啸非's avatar 赵啸非

添加业务修改通知php

parent 58dba73a
package com.mortals.xhx.base.system.message;
public interface MessageService {
/**
* 发送第三方平台四二班透传消息
*
* @param sendUrl
* @param content
* @return
*/
void sendThirdParty(String sendUrl, String content);
}
\ No newline at end of file
package com.mortals.xhx.base.system.message.impl;
import cn.hutool.core.exceptions.ExceptionUtil;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.mortals.framework.service.ICacheService;
import com.mortals.xhx.base.system.message.MessageService;
import com.mortals.xhx.common.utils.SendTask;
import com.mortals.xhx.common.utils.SendTaskThreadPool;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
/**
* DeviceService
* 设备 service实现
*
* @author zxfei
* @date 2022-03-09
*/
@Service("messageService")
@Slf4j
public class MessageServiceImpl implements MessageService {
@Autowired
private SendTaskThreadPool sendTaskThreadPool;
@Override
public void sendThirdParty(String sendUrl, String content) {
SendTask sendTask = new SendTask(sendUrl, content);
sendTaskThreadPool.execute(sendTask);
}
public static void main(String[] args) {
}
}
\ No newline at end of file
package com.mortals.xhx.busiz.req;
import lombok.Data;
@Data
public class ApiThirdPartyReq<T> {
/**
* 结果编码
*/
private int code;
/**
* 结果描述
*/
private String msg;
private Integer type;
private Integer status;
private T data;
}
package com.mortals.xhx.busiz.req;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.annotation.JSONField;
import lombok.Data;
/**
* 业务类
*
* @author:
* @date: 2022/9/7 14:35
*/
@Data
public class BussinessThirdPartyReq {
private Long id;
/**
* 业务名称
*/
private String name;
/**
* 备注
*/
private String remark;
/**
* 是否允许预约(1.允许,0.不允许)
*/
private Integer canorder;
/**
* 是否允许取号(1.允许,0.不允许)
*/
private Integer cantake;
/**
* 大厅情况展示 (1.展示,0.不展示)
*/
private Integer datashow;
/**
* 英语业务名
*/
private String englishname;
/**
* 业务状态 (0.停用,1.正常)
*/
private Integer status;
}
package com.mortals.xhx.common.code;
import java.util.LinkedHashMap;
import java.util.Map;
public enum MessageTypeEnum {
CRUD(0, "设备增删改查"),
TRANSACTION(1, "设备消息类,数据域透传设备上行消息体");
private Integer value;
private String desc;
MessageTypeEnum(Integer value, String desc) {
this.value = value;
this.desc = desc;
}
public Integer getValue() {
return this.value;
}
public String getDesc() {
return this.desc;
}
public static MessageTypeEnum getByValue(Integer value) {
for (MessageTypeEnum sendMsgTypeEnum : MessageTypeEnum.values()) {
if (sendMsgTypeEnum.getValue() == value) {
return sendMsgTypeEnum;
}
}
return null;
}
/**
* 获取Map集合
*
* @param eItem 不包含项
* @return
*/
public static Map<String, String> getEnumMap(Integer... eItem) {
Map<String, String> resultMap = new LinkedHashMap<>();
for (MessageTypeEnum item : MessageTypeEnum.values()) {
try {
boolean hasE = false;
for (Integer e : eItem) {
if (item.getValue() == e) {
hasE = true;
break;
}
}
if (!hasE) {
resultMap.put(item.getValue() + "", item.getDesc());
}
} catch (Exception ex) {
}
}
return resultMap;
}
}
\ No newline at end of file
package com.mortals.xhx.common.code;
import java.util.LinkedHashMap;
import java.util.Map;
/**
* 启用状态 (0.停止,1.启用)枚举类
*
* @author zxfei
*/
public enum ThirdPartyStatusEnum {
新增(1, "新增"),
修改(2, "修改"),
删除(3, "删除");
private Integer value;
private String desc;
ThirdPartyStatusEnum(Integer value, String desc) {
this.value = value;
this.desc = desc;
}
public Integer getValue() {
return this.value;
}
public String getDesc() {
return this.desc;
}
public static ThirdPartyStatusEnum getByValue(Integer value) {
for (ThirdPartyStatusEnum statusEnum : ThirdPartyStatusEnum.values()) {
if (statusEnum.getValue() == value) {
return statusEnum;
}
}
return null;
}
/**
* 获取Map集合
*
* @param eItem 不包含项
* @return
*/
public static Map<String, String> getEnumMap(Integer... eItem) {
Map<String, String> resultMap = new LinkedHashMap<>();
for (ThirdPartyStatusEnum item : ThirdPartyStatusEnum.values()) {
try {
boolean hasE = false;
for (Integer e : eItem) {
if (item.getValue() == e) {
hasE = true;
break;
}
}
if (!hasE) {
resultMap.put(item.getValue() + "", item.getDesc());
}
} catch (Exception ex) {
}
}
return resultMap;
}
}
\ No newline at end of file
package com.mortals.xhx.common.code;
import java.util.LinkedHashMap;
import java.util.Map;
/**
* 启用状态 (0.停止,1.启用)枚举类
*
* @author zxfei
*/
public enum ThirdPartyTypeEnum {
业务(1, "业务信息变更"),
启用(2, "启用");
private Integer value;
private String desc;
ThirdPartyTypeEnum(Integer value, String desc) {
this.value = value;
this.desc = desc;
}
public Integer getValue() {
return this.value;
}
public String getDesc() {
return this.desc;
}
public static ThirdPartyTypeEnum getByValue(Integer value) {
for (ThirdPartyTypeEnum statusEnum : ThirdPartyTypeEnum.values()) {
if (statusEnum.getValue() == value) {
return statusEnum;
}
}
return null;
}
/**
* 获取Map集合
*
* @param eItem 不包含项
* @return
*/
public static Map<String, String> getEnumMap(Integer... eItem) {
Map<String, String> resultMap = new LinkedHashMap<>();
for (ThirdPartyTypeEnum item : ThirdPartyTypeEnum.values()) {
try {
boolean hasE = false;
for (Integer e : eItem) {
if (item.getValue() == e) {
hasE = true;
break;
}
}
if (!hasE) {
resultMap.put(item.getValue() + "", item.getDesc());
}
} catch (Exception ex) {
}
}
return resultMap;
}
}
\ No newline at end of file
package com.mortals.xhx.common.utils;
import com.alibaba.fastjson.JSON;
import com.mortals.framework.util.HttpUtil;
import com.mortals.xhx.busiz.req.ApiThirdPartyReq;
import com.mortals.xhx.common.code.MessageTypeEnum;
import com.mortals.xhx.common.code.YesNoEnum;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import java.util.HashMap;
import java.util.Map;
import static com.mortals.framework.util.HttpUtil.HEADER_CONTENT_TYPE;
/**
* 发通知第三方
*
* @author: zxfei
* @date: 2022/4/28 10:56
* @description:
**/
@Slf4j
@AllArgsConstructor
public class SendTask implements Runnable {
private String sendUrl;
private String content;
@Override
public void run() {
ApiThirdPartyReq<String> apiThirdPartyReq = new ApiThirdPartyReq<>();
apiThirdPartyReq.setCode(YesNoEnum.YES.getValue());
apiThirdPartyReq.setType(MessageTypeEnum.TRANSACTION.getValue());
apiThirdPartyReq.setData(content);
String resp = null;
try {
Map<String, String> header = new HashMap<>();
header.put(HEADER_CONTENT_TYPE, "application/json");
String reqStr = JSON.toJSONString(apiThirdPartyReq);
log.info("sendUrl:{} \n sendMessageReq:{}",sendUrl, reqStr);
resp = HttpUtil.doPost(sendUrl, header, reqStr);
log.debug("sendMessageResp:{}", resp);
} catch (Exception e) {
log.error("异常:", e);
}
}
}
package com.mortals.xhx.common.utils;
import org.springframework.stereotype.Component;
import java.util.concurrent.Executors;
import java.util.concurrent.ThreadPoolExecutor;
/**
* 发送任务线程池
*
* @author: zxfei
* @date: 2022/4/28 10:52
*/
@Component
public class SendTaskThreadPool {
/**
* 线程池
*/
private ThreadPoolExecutor threadPool;
private int poolSize;
private volatile boolean isInit = false;
private Object lock = new Object();
public void init(Integer threadNum) {
if (poolSize < 0) {
throw new IllegalArgumentException();
}
if (poolSize < Runtime.getRuntime().availableProcessors()) {
poolSize = Runtime.getRuntime().availableProcessors() + 1;
}
if (!isInit) {
synchronized (lock) {
if (!isInit) {
threadPool = (ThreadPoolExecutor) Executors.newFixedThreadPool(threadNum);
isInit = true;
}
}
}
}
public void execute(Runnable command) {
threadPool.execute(command);
}
public void setPoolSize(int poolSize) {
threadPool.setCorePoolSize(poolSize);
threadPool.setMaximumPoolSize(poolSize);
}
public void incrementPoolSize(int delta) {
setPoolSize(threadPool.getCorePoolSize() + delta);
}
public synchronized void close() {
if (threadPool != null) {
threadPool.shutdown();
threadPool = null;
isInit = false;
}
}
}
package com.mortals.xhx.module.business.service.impl;
import cn.hutool.core.util.StrUtil;
import com.alibaba.fastjson.JSON;
import com.mortals.framework.ap.GlobalSysInfo;
import com.mortals.framework.exception.AppException;
import com.mortals.framework.model.Context;
import com.mortals.framework.model.PageInfo;
import com.mortals.framework.model.Result;
import com.mortals.framework.service.impl.AbstractCRUDCacheServiceImpl;
import com.mortals.xhx.base.system.message.MessageService;
import com.mortals.xhx.busiz.req.ApiThirdPartyReq;
import com.mortals.xhx.busiz.req.BussinessThirdPartyReq;
import com.mortals.xhx.common.code.IsBusinessEnum;
import com.mortals.xhx.common.code.ThirdPartyStatusEnum;
import com.mortals.xhx.common.code.ThirdPartyTypeEnum;
import com.mortals.xhx.common.code.YesNoEnum;
import com.mortals.xhx.common.utils.BeanUtil;
import com.mortals.xhx.module.business.model.*;
import com.mortals.xhx.module.business.service.BusinessMatterService;
import com.mortals.xhx.module.business.dao.BusinessDao;
import com.mortals.xhx.module.business.model.BusinessEntity;
import com.mortals.xhx.module.business.model.BusinessQuery;
import com.mortals.xhx.module.business.service.BusinessService;
import com.mortals.xhx.module.site.model.SiteBusinessEntity;
import com.mortals.xhx.module.site.model.SiteBusinessQuery;
import com.mortals.xhx.module.site.model.SiteEntity;
import com.mortals.xhx.module.site.service.SiteBusinessService;
import com.mortals.xhx.module.site.service.SiteService;
import com.mortals.xhx.module.window.model.WindowBusinessEntity;
import com.mortals.xhx.module.window.model.WindowBusinessQuery;
import com.mortals.xhx.module.window.service.WindowBusinessService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.mortals.framework.exception.AppException;
import com.mortals.framework.model.Context;
import com.mortals.xhx.common.code.SatusEnum;
import com.mortals.framework.service.impl.AbstractCRUDServiceImpl;
import com.mortals.xhx.module.business.dao.BusinessDao;
import com.mortals.xhx.module.business.service.BusinessService;
import org.springframework.util.ObjectUtils;
import java.util.*;
import java.util.stream.Collectors;
import static com.mortals.framework.ap.SysConstains.RESULT_KEY;
import static com.mortals.xhx.common.key.Constant.PARAM_SERVER_PHP_HTTP_URL;
/**
* BusinessService
......@@ -38,11 +46,17 @@ import static com.mortals.framework.ap.SysConstains.RESULT_KEY;
* @date 2022-01-13
*/
@Service("businessService")
@Slf4j
public class BusinessServiceImpl extends AbstractCRUDCacheServiceImpl<BusinessDao, BusinessEntity, Long> implements BusinessService {
@Autowired
private SiteBusinessService siteBusinessService;
@Autowired
private WindowBusinessService windowBusinessService;
@Autowired
private SiteService siteService;
@Autowired
private MessageService messageService;
@Override
protected void findAfter(BusinessEntity params, PageInfo pageInfo, Context context, List<BusinessEntity> list) throws AppException {
......@@ -87,21 +101,97 @@ public class BusinessServiceImpl extends AbstractCRUDCacheServiceImpl<BusinessDa
.filter(item -> !item.getBusinessName().equals(entity.getName()))
.peek(item -> item.setBusinessName(entity.getName()))
.collect(Collectors.toList());
if(!ObjectUtils.isEmpty(siteBusinessEntities)){
siteBusinessService.update(siteBusinessEntities,context);
if (!ObjectUtils.isEmpty(siteBusinessEntities)) {
siteBusinessService.update(siteBusinessEntities, context);
}
//通知第三方平台
String phpUrl = GlobalSysInfo.getParamValue(PARAM_SERVER_PHP_HTTP_URL, "http://172.15.28.116:8090");
phpUrl += "/inter/device/baseDataSave";
BussinessThirdPartyReq bussinessThirdPartyReq = new BussinessThirdPartyReq();
BeanUtils.copyProperties(entity, bussinessThirdPartyReq, BeanUtil.getNullPropertyNames(entity));
ApiThirdPartyReq<BussinessThirdPartyReq> apiThirdPartyReq = new ApiThirdPartyReq<>();
apiThirdPartyReq.setCode(YesNoEnum.YES.getValue());
apiThirdPartyReq.setType(ThirdPartyTypeEnum.业务.getValue());
apiThirdPartyReq.setStatus(ThirdPartyStatusEnum.修改.getValue());
apiThirdPartyReq.setData(bussinessThirdPartyReq);
messageService.sendThirdParty(phpUrl, JSON.toJSONString(apiThirdPartyReq));
super.updateAfter(entity, context);
}
@Override
protected void removeBefore(Long[] ids, Context context) throws AppException {
Set<Long> idSet = Arrays.asList(ids).stream().collect(Collectors.toSet());
List<BusinessEntity> businessEntities = this.get(ids, context);
//有子节点 禁止删除
List<BusinessEntity> collect = businessEntities.stream().filter(f -> IsBusinessEnum.一级业务.getValue() == f.getIsBusiness()).collect(Collectors.toList());
if (!ObjectUtils.isEmpty(collect)) {
//删除节点包含一级节点,查询删除的子节点 是否包含在所有
for (BusinessEntity businessEntity : collect) {
List<BusinessEntity> childList = this.find(new BusinessQuery().parentId(businessEntity.getId()));
boolean bool = false;
for (BusinessEntity child : childList) {
if (!idSet.contains(child.getId())) {
bool = true;
break;
}
if (bool) {
throw new AppException("删除的父业务存在子业务,不能删除");
}
}
}
}
String phpUrl = GlobalSysInfo.getParamValue(PARAM_SERVER_PHP_HTTP_URL, "http://172.15.28.116:8090");
phpUrl += "/inter/device/baseDataSave";
for (BusinessEntity entity : businessEntities) {
BussinessThirdPartyReq bussinessThirdPartyReq = new BussinessThirdPartyReq();
BeanUtils.copyProperties(entity, bussinessThirdPartyReq, BeanUtil.getNullPropertyNames(entity));
ApiThirdPartyReq<BussinessThirdPartyReq> apiThirdPartyReq = new ApiThirdPartyReq<>();
apiThirdPartyReq.setCode(YesNoEnum.YES.getValue());
apiThirdPartyReq.setType(ThirdPartyTypeEnum.业务.getValue());
apiThirdPartyReq.setStatus(ThirdPartyStatusEnum.删除.getValue());
apiThirdPartyReq.setData(bussinessThirdPartyReq);
messageService.sendThirdParty(phpUrl, JSON.toJSONString(apiThirdPartyReq));
}
super.removeBefore(ids, context);
}
/**
* @param ids
* @param context
* @param result
* @throws AppException
*/
@Override
protected void removeAfter(Long[] ids, Context context, int result) throws AppException {
super.removeAfter(ids, context, result);
if (!ObjectUtils.isEmpty(ids)) {
//级联删除窗口业务
WindowBusinessQuery windowBusinessQuery = new WindowBusinessQuery();
windowBusinessQuery.setSiteBusinessIdList(Arrays.asList(ids));
List<WindowBusinessEntity> windowBusinessEntities = windowBusinessService.find(windowBusinessQuery);
log.info("remove windowBusinessEntities size:{}", windowBusinessEntities.size());
if (!ObjectUtils.isEmpty(windowBusinessEntities)) {
Long[] idList = windowBusinessEntities.stream().map(item -> item.getId()).toArray(Long[]::new);
windowBusinessService.remove(idList, context);
}
SiteBusinessQuery siteBusinessQuery = new SiteBusinessQuery();
siteBusinessQuery.setBusinessIdList(Arrays.asList(ids));
List<SiteBusinessEntity> siteBusinessEntities = siteBusinessService.find(siteBusinessQuery);
log.info("remove siteBusinessEntities size:{}", siteBusinessEntities.size());
if (!ObjectUtils.isEmpty(siteBusinessEntities)) {
Long[] idList = siteBusinessEntities.stream().map(item -> item.getId()).toArray(Long[]::new);
siteBusinessService.remove(idList, context);
}
}
}
@Override
public void addBusinessToSite(String businessIds, Long siteId, Context context) {
......@@ -129,7 +219,7 @@ public class BusinessServiceImpl extends AbstractCRUDCacheServiceImpl<BusinessDa
}
@Override
public Result<BusinessEntity> flatList(BusinessEntity query,PageInfo pageInfo, Context context) {
public Result<BusinessEntity> flatList(BusinessEntity query, PageInfo pageInfo, Context context) {
Result<BusinessEntity> result = this.dao.getList(query, pageInfo);
return result;
}
......@@ -138,7 +228,7 @@ public class BusinessServiceImpl extends AbstractCRUDCacheServiceImpl<BusinessDa
SiteBusinessEntity siteBusinessEntity = new SiteBusinessEntity();
BeanUtils.copyProperties(item, siteBusinessEntity, BeanUtil.getNullPropertyNames(item));
SiteEntity siteEntity = siteService.get(siteId);
if(ObjectUtils.isEmpty(siteEntity)){
if (ObjectUtils.isEmpty(siteEntity)) {
throw new AppException("未找到相应站点!");
}
siteBusinessEntity.setSiteId(siteEntity.getId());
......@@ -182,6 +272,5 @@ public class BusinessServiceImpl extends AbstractCRUDCacheServiceImpl<BusinessDa
System.out.println(JSON.toJSONString(siteBusinessQuery));
}
}
\ 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