Commit 85df4b07 by xuwenqian

feat:新增发送企业微信消息通用方法

parent 035edf98
...@@ -7,22 +7,34 @@ import com.gic.haoban.manage.api.dto.QywxCallBackDTO; ...@@ -7,22 +7,34 @@ import com.gic.haoban.manage.api.dto.QywxCallBackDTO;
* Created by tgs on 2020/2/20. * Created by tgs on 2020/2/20.
*/ */
public interface MessageApiService { public interface MessageApiService {
/**接收企业微信的推送消息*/ /**
* 接收企业微信的推送消息
*
* @param gicMessageDTO
*/
@Deprecated
void gicMessageReceive(GicMessageDTO gicMessageDTO); void gicMessageReceive(GicMessageDTO gicMessageDTO);
/**接收企业微信的推送消息*/ /**
* 接收企业微信的推送消息
*
* @param qywxCallBackDTO
*/
void wxMessageReceive(QywxCallBackDTO qywxCallBackDTO); void wxMessageReceive(QywxCallBackDTO qywxCallBackDTO);
/** /**
* 队列消费gic推送数据 * 队列消费gic推送数据
*
* @param param * @param param
*/ */
@Deprecated
void dealGicMessage(String param); void dealGicMessage(String param);
/** /**
* 队列消费企业微信推送数据 * 队列消费企业微信推送数据
* @param param * @param param
*/ */
@Deprecated
void dealWxMessage(String param); void dealWxMessage(String param);
/** /**
* 发送消费消息 * 发送消费消息
...@@ -33,9 +45,11 @@ public interface MessageApiService { ...@@ -33,9 +45,11 @@ public interface MessageApiService {
* @param storeId * @param storeId
* @return * @return
*/ */
Boolean sendFaceMessage(String clerkId,String memberId, String memberName, String arrivalTime,String storeId); Boolean sendFaceMessage(String clerkId, String memberId, String memberName, String arrivalTime, String storeId);
/** /**
* 发送完善标签信息 * 发送完善标签信息
*
* @param clerkId * @param clerkId
* @param clerkId * @param clerkId
* @param memberName * @param memberName
...@@ -43,5 +57,16 @@ public interface MessageApiService { ...@@ -43,5 +57,16 @@ public interface MessageApiService {
* @param orderId * @param orderId
* @param storeId * @param storeId
*/ */
Boolean sendPerfectRemarkMessage(String clerkId, String memberId,String memberName, String customerTime, String orderId,String storeId); Boolean sendPerfectRemarkMessage(String clerkId, String memberId, String memberName, String customerTime, String orderId, String storeId);
/**
* 通用发送企业微信消息
*
* @param param 参数
* @author xuwenqian
* @date 2021-07-16 10:09:00
*/
void sendWxMessage(String param);
} }
...@@ -6,31 +6,19 @@ import com.gic.commons.util.EntityUtil; ...@@ -6,31 +6,19 @@ import com.gic.commons.util.EntityUtil;
import com.gic.commons.util.GICMQClientUtil; import com.gic.commons.util.GICMQClientUtil;
import com.gic.commons.util.GlobalInfo; import com.gic.commons.util.GlobalInfo;
import com.gic.commons.util.GlobalVar; import com.gic.commons.util.GlobalVar;
import com.gic.enterprise.api.dto.StoreDTO;
import com.gic.enterprise.api.service.StoreService; import com.gic.enterprise.api.service.StoreService;
import com.gic.haoban.app.customer.service.api.service.InnerApiService; import com.gic.haoban.app.customer.service.api.service.InnerApiService;
import com.gic.haoban.base.api.common.Constant; import com.gic.haoban.base.api.common.Constant;
import com.gic.haoban.base.api.common.ServiceResponse; import com.gic.haoban.manage.api.dto.*;
import com.gic.haoban.manage.api.dto.DepartmentDTO;
import com.gic.haoban.manage.api.dto.GicClerkDTO;
import com.gic.haoban.manage.api.dto.GicMessageDTO;
import com.gic.haoban.manage.api.dto.QywxCallBackDTO;
import com.gic.haoban.manage.api.dto.StaffClerkRelationDTO;
import com.gic.haoban.manage.api.dto.StaffDTO;
import com.gic.haoban.manage.api.dto.StaffDepartmentRelatedDTO;
import com.gic.haoban.manage.api.dto.WxApplicationDTO;
import com.gic.haoban.manage.api.dto.WxEnterpriseDTO;
import com.gic.haoban.manage.api.enums.AppPageType; import com.gic.haoban.manage.api.enums.AppPageType;
import com.gic.haoban.manage.api.enums.GicDataType; import com.gic.haoban.manage.api.enums.GicDataType;
import com.gic.haoban.manage.api.enums.GicEditType;
import com.gic.haoban.manage.api.enums.WxEditType; import com.gic.haoban.manage.api.enums.WxEditType;
import com.gic.haoban.manage.api.service.DepartmentApiService; import com.gic.haoban.manage.api.service.*;
import com.gic.haoban.manage.api.service.MessageApiService;
import com.gic.haoban.manage.api.service.StaffApiService;
import com.gic.haoban.manage.api.service.StaffClerkRelationApiService;
import com.gic.haoban.manage.api.service.StaffDepartmentRelatedApiService;
import com.gic.haoban.manage.service.config.Config; import com.gic.haoban.manage.service.config.Config;
import com.gic.haoban.manage.service.entity.*; import com.gic.haoban.manage.service.entity.TabHaobanDepartment;
import com.gic.haoban.manage.service.entity.TabHaobanStaff;
import com.gic.haoban.manage.service.entity.TabHaobanStaffDepartmentRelated;
import com.gic.haoban.manage.service.entity.TabHaobanWxEnterprise;
import com.gic.haoban.manage.service.service.*; import com.gic.haoban.manage.service.service.*;
import com.gic.mq.sdk.GicMQClient; import com.gic.mq.sdk.GicMQClient;
import com.gic.thirdparty.api.dto.PicUploadResDTO; import com.gic.thirdparty.api.dto.PicUploadResDTO;
...@@ -39,22 +27,20 @@ import com.gic.wechat.api.dto.qywx.ItemDTO; ...@@ -39,22 +27,20 @@ import com.gic.wechat.api.dto.qywx.ItemDTO;
import com.gic.wechat.api.dto.qywx.QywxXcxSendMessageDTO; import com.gic.wechat.api.dto.qywx.QywxXcxSendMessageDTO;
import com.gic.wechat.api.service.qywx.QywxDepartmentApiService; import com.gic.wechat.api.service.qywx.QywxDepartmentApiService;
import com.gic.wechat.api.service.qywx.QywxSuiteApiService; import com.gic.wechat.api.service.qywx.QywxSuiteApiService;
import org.apache.commons.io.IOUtils;
import org.apache.commons.lang.StringUtils;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.io.InputStream; import java.io.InputStream;
import java.net.URL; import java.net.URL;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.Iterator;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import org.apache.commons.io.IOUtils;
import org.apache.commons.lang.StringUtils;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
/** /**
* 接收企业微信或者gic推送消息进行处理 * 接收企业微信或者gic推送消息进行处理
* Created by tgs on 2020/2/20. * Created by tgs on 2020/2/20.
...@@ -126,7 +112,7 @@ public class MessageApiServiceImpl implements MessageApiService { ...@@ -126,7 +112,7 @@ public class MessageApiServiceImpl implements MessageApiService {
public void wxMessageReceive(QywxCallBackDTO qywxCallBackDTO) { public void wxMessageReceive(QywxCallBackDTO qywxCallBackDTO) {
GicMQClient clientInstance = GICMQClientUtil.getClientInstance(); GicMQClient clientInstance = GICMQClientUtil.getClientInstance();
try { try {
if(config.getSuiteId().equals(qywxCallBackDTO.getSuiteId()) || CONTACT_APP.equals(qywxCallBackDTO.getSuiteId())){ if (config.getSuiteId().equals(qywxCallBackDTO.getSuiteId()) || CONTACT_APP.equals(qywxCallBackDTO.getSuiteId())) {
log.info("发送消息到dealWxMessageMq,{}", JSON.toJSONString(qywxCallBackDTO)); log.info("发送消息到dealWxMessageMq,{}", JSON.toJSONString(qywxCallBackDTO));
clientInstance.sendMessage("dealWxMessageMq", JSON.toJSONString(qywxCallBackDTO)); clientInstance.sendMessage("dealWxMessageMq", JSON.toJSONString(qywxCallBackDTO));
} }
...@@ -137,7 +123,6 @@ public class MessageApiServiceImpl implements MessageApiService { ...@@ -137,7 +123,6 @@ public class MessageApiServiceImpl implements MessageApiService {
@Override @Override
public void dealGicMessage(String param) { public void dealGicMessage(String param) {
return;
} }
@Override @Override
...@@ -147,56 +132,56 @@ public class MessageApiServiceImpl implements MessageApiService { ...@@ -147,56 +132,56 @@ public class MessageApiServiceImpl implements MessageApiService {
return; return;
} }
QywxCallBackDTO dto = JSON.parseObject(param, QywxCallBackDTO.class); QywxCallBackDTO dto = JSON.parseObject(param, QywxCallBackDTO.class);
log.info("【处理微信回调】dto={}",JSON.toJSONString(param)); log.info("【处理微信回调】dto={}", JSON.toJSONString(param));
if(dto != null){ if (dto != null) {
String corpId = dto.getAuthCorpId(); String corpId = dto.getAuthCorpId();
TabHaobanWxEnterprise enterprise = this.enterpriseService.getEnterpriseBycorpId(corpId); TabHaobanWxEnterprise enterprise = this.enterpriseService.getEnterpriseBycorpId(corpId);
if(enterprise != null){ if (enterprise != null) {
if(dto.getChangeType().endsWith("party")){ if (dto.getChangeType().endsWith("party")) {
this.dealDepartment(dto); this.dealDepartment(dto);
}else { } else {
this.dealUser(dto); this.dealUser(dto);
} }
} }
} }
} }
private void dealDepartment(QywxCallBackDTO qywxCallBackDTO){ private void dealDepartment(QywxCallBackDTO qywxCallBackDTO) {
DepartmentDTO departmentDTO = new DepartmentDTO(); DepartmentDTO departmentDTO = new DepartmentDTO();
departmentDTO.setDepartmentName(qywxCallBackDTO.getDepartmentName()); departmentDTO.setDepartmentName(qywxCallBackDTO.getDepartmentName());
departmentDTO.setIsStore(0); departmentDTO.setIsStore(0);
//departmentDTO.setRelatedId(qywxCallBackDTO.getId()+""); //departmentDTO.setRelatedId(qywxCallBackDTO.getId()+"");
TabHaobanWxEnterprise enterprise = this.enterpriseService.getEnterpriseBycorpId(qywxCallBackDTO.getAuthCorpId()); TabHaobanWxEnterprise enterprise = this.enterpriseService.getEnterpriseBycorpId(qywxCallBackDTO.getAuthCorpId());
TabHaobanDepartment parentDepartment = new TabHaobanDepartment(); TabHaobanDepartment parentDepartment = new TabHaobanDepartment();
if(qywxCallBackDTO.getParentId() != null){ if (qywxCallBackDTO.getParentId() != null) {
parentDepartment = this.departmentService.getByWxId(qywxCallBackDTO.getParentId() + "", enterprise.getWxEnterpriseId()); parentDepartment = this.departmentService.getByWxId(qywxCallBackDTO.getParentId() + "", enterprise.getWxEnterpriseId());
}else{ } else {
TabHaobanDepartment oldDepartment = this.departmentService.getByWxId(qywxCallBackDTO.getId() + "", enterprise.getWxEnterpriseId()); TabHaobanDepartment oldDepartment = this.departmentService.getByWxId(qywxCallBackDTO.getId() + "", enterprise.getWxEnterpriseId());
if(oldDepartment != null){ if (oldDepartment != null) {
parentDepartment = departmentService.selectById(oldDepartment.getParentDepartmentId()); parentDepartment = departmentService.selectById(oldDepartment.getParentDepartmentId());
} }
} }
if(!qywxCallBackDTO.getChangeType().equals(WxEditType.DELETEDEPART.getCode())){ if (!qywxCallBackDTO.getChangeType().equals(WxEditType.DELETEDEPART.getCode())) {
if(parentDepartment == null){ if (parentDepartment == null) {
log.info("微信同步父部门不存在"); log.info("微信同步父部门不存在");
return; return;
} }
departmentDTO.setParentDepartmentId(parentDepartment.getDepartmentId()); departmentDTO.setParentDepartmentId(parentDepartment.getDepartmentId());
departmentDTO.setChainId(parentDepartment.getChainId()+ Constant.ID_SEPARATOR + parentDepartment.getDepartmentId()); departmentDTO.setChainId(parentDepartment.getChainId() + Constant.ID_SEPARATOR + parentDepartment.getDepartmentId());
departmentDTO.setChainName(parentDepartment.getChainName() + Constant.NAME_SEPARATOR + parentDepartment.getChainName()); departmentDTO.setChainName(parentDepartment.getChainName() + Constant.NAME_SEPARATOR + parentDepartment.getChainName());
departmentDTO.setLevel(parentDepartment.getLevel() + 1); departmentDTO.setLevel(parentDepartment.getLevel() + 1);
} }
departmentDTO.setWxEnterpriseId(enterprise.getWxEnterpriseId()); departmentDTO.setWxEnterpriseId(enterprise.getWxEnterpriseId());
departmentDTO.setWxDepartmentId(qywxCallBackDTO.getId()+""); departmentDTO.setWxDepartmentId(qywxCallBackDTO.getId() + "");
if(qywxCallBackDTO.getParentId() != null){ if (qywxCallBackDTO.getParentId() != null) {
List<com.gic.wechat.api.dto.qywx.DepartmentDTO> list = this.qywxDepartmentApiService.listDepartment(qywxCallBackDTO.getAuthCorpId(), qywxCallBackDTO.getSuiteId(), qywxCallBackDTO.getParentId()); List<com.gic.wechat.api.dto.qywx.DepartmentDTO> list = this.qywxDepartmentApiService.listDepartment(qywxCallBackDTO.getAuthCorpId(), qywxCallBackDTO.getSuiteId(), qywxCallBackDTO.getParentId());
if(list != null){ if (list != null) {
for (com.gic.wechat.api.dto.qywx.DepartmentDTO departmentDTO2 : list) { for (com.gic.wechat.api.dto.qywx.DepartmentDTO departmentDTO2 : list) {
if(departmentDTO2.getId().equals(departmentDTO.getDepartmentId())){ if (departmentDTO2.getId().equals(departmentDTO.getDepartmentId())) {
departmentDTO.setSort(qywxCallBackDTO.getOrder()); departmentDTO.setSort(qywxCallBackDTO.getOrder());
}else{ } else {
TabHaobanDepartment tab = this.departmentService.getByWxId(departmentDTO2.getId() + "", enterprise.getWxEnterpriseId()); TabHaobanDepartment tab = this.departmentService.getByWxId(departmentDTO2.getId() + "", enterprise.getWxEnterpriseId());
if(tab != null){ if (tab != null) {
tab.setSort(departmentDTO2.getOrder()); tab.setSort(departmentDTO2.getOrder());
this.departmentService.edit(EntityUtil.changeEntityByJSON(DepartmentDTO.class, tab)); this.departmentService.edit(EntityUtil.changeEntityByJSON(DepartmentDTO.class, tab));
} }
...@@ -204,28 +189,28 @@ public class MessageApiServiceImpl implements MessageApiService { ...@@ -204,28 +189,28 @@ public class MessageApiServiceImpl implements MessageApiService {
} }
} }
} }
if(qywxCallBackDTO.getChangeType().equals(WxEditType.ADDDEPART.getCode())){ if (qywxCallBackDTO.getChangeType().equals(WxEditType.ADDDEPART.getCode())) {
String response = this.departmentService.add(departmentDTO); String response = this.departmentService.add(departmentDTO);
log.info("微信同步新增部门:{}", JSON.toJSONString(response)); log.info("微信同步新增部门:{}", JSON.toJSONString(response));
}else if(qywxCallBackDTO.getChangeType().equals(WxEditType.UPDATEDEPART.getCode())){ } else if (qywxCallBackDTO.getChangeType().equals(WxEditType.UPDATEDEPART.getCode())) {
TabHaobanDepartment department = this.departmentService.getByWxId(qywxCallBackDTO.getId() + "", enterprise.getWxEnterpriseId()); TabHaobanDepartment department = this.departmentService.getByWxId(qywxCallBackDTO.getId() + "", enterprise.getWxEnterpriseId());
if(department == null){ if (department == null) {
String response = this.departmentService.add(departmentDTO); String response = this.departmentService.add(departmentDTO);
log.info("微信同步新增部门:{}", JSON.toJSONString(response)); log.info("微信同步新增部门:{}", JSON.toJSONString(response));
}else { } else {
departmentDTO.setIsStore(department.getIsStore()); departmentDTO.setIsStore(department.getIsStore());
departmentDTO.setDepartmentId(department.getDepartmentId()); departmentDTO.setDepartmentId(department.getDepartmentId());
this.departmentService.edit(departmentDTO); this.departmentService.edit(departmentDTO);
log.info("企业微信更新同步完成"); log.info("企业微信更新同步完成");
} }
}else { } else {
TabHaobanDepartment department = this.departmentService.getByWxId(qywxCallBackDTO.getId() + "", enterprise.getWxEnterpriseId()); TabHaobanDepartment department = this.departmentService.getByWxId(qywxCallBackDTO.getId() + "", enterprise.getWxEnterpriseId());
if(department == null){ if (department == null) {
log.info("微信同步删除部门不存在"); log.info("微信同步删除部门不存在");
}else { } else {
if(StringUtils.isBlank(department.getRelatedId())){ if (StringUtils.isBlank(department.getRelatedId())) {
this.departmentService.del(department.getDepartmentId()); this.departmentService.del(department.getDepartmentId());
}else{ } else {
this.departmentApiService.wxCallBackrecycle(department.getDepartmentId()); this.departmentApiService.wxCallBackrecycle(department.getDepartmentId());
} }
log.info("企业微信删除同步完成"); log.info("企业微信删除同步完成");
...@@ -233,10 +218,10 @@ public class MessageApiServiceImpl implements MessageApiService { ...@@ -233,10 +218,10 @@ public class MessageApiServiceImpl implements MessageApiService {
} }
} }
private void dealUser(QywxCallBackDTO qywxCallBackDTO){ private void dealUser(QywxCallBackDTO qywxCallBackDTO) {
TabHaobanStaff staff = new TabHaobanStaff(); TabHaobanStaff staff = new TabHaobanStaff();
TabHaobanWxEnterprise enterprise = this.enterpriseService.getEnterpriseBycorpId(qywxCallBackDTO.getAuthCorpId()); TabHaobanWxEnterprise enterprise = this.enterpriseService.getEnterpriseBycorpId(qywxCallBackDTO.getAuthCorpId());
if(enterprise != null){ if (enterprise != null) {
staff.setWxEnterpriseId(enterprise.getWxEnterpriseId()); staff.setWxEnterpriseId(enterprise.getWxEnterpriseId());
//staff.setActiveFlag(0); //staff.setActiveFlag(0);
staff.setPhoneNumber(qywxCallBackDTO.getMobile()); staff.setPhoneNumber(qywxCallBackDTO.getMobile());
...@@ -245,44 +230,44 @@ public class MessageApiServiceImpl implements MessageApiService { ...@@ -245,44 +230,44 @@ public class MessageApiServiceImpl implements MessageApiService {
staff.setStaffName(qywxCallBackDTO.getUserName()); staff.setStaffName(qywxCallBackDTO.getUserName());
staff.setWxUserId(qywxCallBackDTO.getUserid()); staff.setWxUserId(qywxCallBackDTO.getUserid());
staff.setPostion(qywxCallBackDTO.getPosition()); staff.setPostion(qywxCallBackDTO.getPosition());
if(StringUtils.isNotBlank(qywxCallBackDTO.getAvatar())){ if (StringUtils.isNotBlank(qywxCallBackDTO.getAvatar())) {
staff.setHeadImg(changeHeaderImageUrl(qywxCallBackDTO.getAvatar())); staff.setHeadImg(changeHeaderImageUrl(qywxCallBackDTO.getAvatar()));
} }
staff.setNationCode("86"); staff.setNationCode("86");
//激活状态 //激活状态
if(qywxCallBackDTO.getStatus() != null && qywxCallBackDTO.getStatus() == 1){ if (qywxCallBackDTO.getStatus() != null && qywxCallBackDTO.getStatus() == 1) {
staff.setActiveFlag(1); staff.setActiveFlag(1);
} }
if(qywxCallBackDTO.getChangeType().equals(WxEditType.ADDUSER.getCode())){ if (qywxCallBackDTO.getChangeType().equals(WxEditType.ADDUSER.getCode())) {
if(staff.getActiveFlag() == null){ if (staff.getActiveFlag() == null) {
staff.setActiveFlag(0); staff.setActiveFlag(0);
} }
this.addUser(qywxCallBackDTO, staff); this.addUser(qywxCallBackDTO, staff);
} else if(qywxCallBackDTO.getChangeType().equals(WxEditType.UPDATEUSER.getCode())){ } else if (qywxCallBackDTO.getChangeType().equals(WxEditType.UPDATEUSER.getCode())) {
TabHaobanStaff oldStaff = this.staffService.selectByUserIdAndEnterpriseId(qywxCallBackDTO.getUserid(),enterprise.getWxEnterpriseId()); TabHaobanStaff oldStaff = this.staffService.selectByUserIdAndEnterpriseId(qywxCallBackDTO.getUserid(), enterprise.getWxEnterpriseId());
if(oldStaff != null){ if (oldStaff != null) {
staff.setWxUserId(qywxCallBackDTO.getNewUserid()); staff.setWxUserId(qywxCallBackDTO.getNewUserid());
staff.setStaffId(oldStaff.getStaffId()); staff.setStaffId(oldStaff.getStaffId());
log.info("【微信回调更新】staff={}",JSON.toJSONString(staff)); log.info("【微信回调更新】staff={}", JSON.toJSONString(staff));
if(StringUtils.isBlank(staff.getPhoneNumber())){ if (StringUtils.isBlank(staff.getPhoneNumber())) {
staff.setPhoneNumber(oldStaff.getPhoneNumber()); staff.setPhoneNumber(oldStaff.getPhoneNumber());
} }
if(StringUtils.isBlank(staff.getNationCode())){ if (StringUtils.isBlank(staff.getNationCode())) {
staff.setNationCode(oldStaff.getNationCode()); staff.setNationCode(oldStaff.getNationCode());
} }
if(StringUtils.isBlank(staff.getStaffName())){ if (StringUtils.isBlank(staff.getStaffName())) {
staff.setStaffName(oldStaff.getStaffName()); staff.setStaffName(oldStaff.getStaffName());
} }
if(StringUtils.isBlank(staff.getPostion())){ if (StringUtils.isBlank(staff.getPostion())) {
staff.setPostion(oldStaff.getPostion()); staff.setPostion(oldStaff.getPostion());
} }
if(staff.getSex() == null){ if (staff.getSex() == null) {
staff.setSex(oldStaff.getSex()); staff.setSex(oldStaff.getSex());
} }
if(staff.getActiveFlag() == null){ if (staff.getActiveFlag() == null) {
staff.setActiveFlag(oldStaff.getActiveFlag()); staff.setActiveFlag(oldStaff.getActiveFlag());
} }
if(StringUtils.isBlank(staff.getHeadImg())){ if (StringUtils.isBlank(staff.getHeadImg())) {
staff.setHeadImg(oldStaff.getHeadImg()); staff.setHeadImg(oldStaff.getHeadImg());
} }
// this.staffService.updateByPrimaryKey(staff); // this.staffService.updateByPrimaryKey(staff);
...@@ -291,80 +276,80 @@ public class MessageApiServiceImpl implements MessageApiService { ...@@ -291,80 +276,80 @@ public class MessageApiServiceImpl implements MessageApiService {
String[] departArr = qywxCallBackDTO.getDepartment(); String[] departArr = qywxCallBackDTO.getDepartment();
String departmentIds = ""; String departmentIds = "";
//部门修改了 //部门修改了
if(departArr != null){ if (departArr != null) {
for(String s : departArr){ for (String s : departArr) {
TabHaobanDepartment department = this.departmentService.getByWxId(s, enterprise.getWxEnterpriseId()); TabHaobanDepartment department = this.departmentService.getByWxId(s, enterprise.getWxEnterpriseId());
if(department == null){ if (department == null) {
log.info("部门不存在"); log.info("部门不存在");
continue; continue;
} }
departmentIds += department.getDepartmentId() + ","; departmentIds += department.getDepartmentId() + ",";
} }
departmentIds = departmentIds.substring(0,departmentIds.length() - 1); departmentIds = departmentIds.substring(0, departmentIds.length() - 1);
}else{ } else {
//部门没有修改 //部门没有修改
List<TabHaobanStaffDepartmentRelated> list = staffDepartmentRelatedService.listStaffDepartmentByStaffId(staff.getStaffId()); List<TabHaobanStaffDepartmentRelated> list = staffDepartmentRelatedService.listStaffDepartmentByStaffId(staff.getStaffId());
for (TabHaobanStaffDepartmentRelated tabHaobanStaffDepartmentRelated : list) { for (TabHaobanStaffDepartmentRelated tabHaobanStaffDepartmentRelated : list) {
departmentIds += tabHaobanStaffDepartmentRelated.getDepartmentId() + ","; departmentIds += tabHaobanStaffDepartmentRelated.getDepartmentId() + ",";
} }
departmentIds = departmentIds.substring(0,departmentIds.length() - 1); departmentIds = departmentIds.substring(0, departmentIds.length() - 1);
} }
StaffDTO staffDTO = EntityUtil.changeEntityByJSON(StaffDTO.class, staff); StaffDTO staffDTO = EntityUtil.changeEntityByJSON(StaffDTO.class, staff);
staffDTO.setWeixinPush(true); staffDTO.setWeixinPush(true);
staffApiService.staffEdit(staffDTO, departmentIds); staffApiService.staffEdit(staffDTO, departmentIds);
}else { } else {
if(staff.getActiveFlag() == null){ if (staff.getActiveFlag() == null) {
staff.setActiveFlag(0); staff.setActiveFlag(0);
} }
this.addUser(qywxCallBackDTO, staff); this.addUser(qywxCallBackDTO, staff);
} }
} else { } else {
TabHaobanStaff oldStaff = this.staffService.selectByUserIdAndEnterpriseId(qywxCallBackDTO.getUserid(),enterprise.getWxEnterpriseId()); TabHaobanStaff oldStaff = this.staffService.selectByUserIdAndEnterpriseId(qywxCallBackDTO.getUserid(), enterprise.getWxEnterpriseId());
//List<TabHaobanStaffDepartmentRelated> list = staffDepartmentRelatedService.listStaffDepartmentByStaffId(staff.getStaffId()); //List<TabHaobanStaffDepartmentRelated> list = staffDepartmentRelatedService.listStaffDepartmentByStaffId(staff.getStaffId());
if(oldStaff != null){ if (oldStaff != null) {
List<TabHaobanStaffDepartmentRelated> relatedList = staffDepartmentRelatedService.listStaffDepartmentByStaffId(oldStaff.getStaffId()); List<TabHaobanStaffDepartmentRelated> relatedList = staffDepartmentRelatedService.listStaffDepartmentByStaffId(oldStaff.getStaffId());
TabHaobanStaffDepartmentRelated staffRelated = relatedList.get(0); TabHaobanStaffDepartmentRelated staffRelated = relatedList.get(0);
if(StringUtils.isNotBlank(staffRelated.getClerkCode())){ if (StringUtils.isNotBlank(staffRelated.getClerkCode())) {
staffApiService.cleanGicClerk(staffRelated.getClerkCode(), staffRelated.getDepartmentId()); staffApiService.cleanGicClerk(staffRelated.getClerkCode(), staffRelated.getDepartmentId());
} }
innerApiService.delCardByStaffId(oldStaff.getStaffId()); innerApiService.delCardByStaffId(oldStaff.getStaffId());
this.staffDepartmentRelatedService.del(EntityUtil.changeEntityByJSON(StaffDepartmentRelatedDTO.class, staffRelated)); this.staffDepartmentRelatedService.del(EntityUtil.changeEntityByJSON(StaffDepartmentRelatedDTO.class, staffRelated));
this.staffService.delByuserid(oldStaff.getStaffId()); this.staffService.delByuserid(oldStaff.getStaffId());
}else { } else {
log.info("微信同步删除的门店不存在,{}", qywxCallBackDTO.getUserid()); log.info("微信同步删除的门店不存在,{}", qywxCallBackDTO.getUserid());
} }
} }
}else { } else {
log.info("授权企业不存在,{}", qywxCallBackDTO.getAuthCorpId()); log.info("授权企业不存在,{}", qywxCallBackDTO.getAuthCorpId());
} }
} }
private void addUser(QywxCallBackDTO qywxCallBackDTO, TabHaobanStaff staff){ private void addUser(QywxCallBackDTO qywxCallBackDTO, TabHaobanStaff staff) {
TabHaobanWxEnterprise enterprise = this.enterpriseService.getEnterpriseBycorpId(qywxCallBackDTO.getAuthCorpId()); TabHaobanWxEnterprise enterprise = this.enterpriseService.getEnterpriseBycorpId(qywxCallBackDTO.getAuthCorpId());
StaffDTO staffDTO = staffApiService.selectByUserIdAndEnterpriseId(staff.getWxUserId(),enterprise.getWxEnterpriseId()); StaffDTO staffDTO = staffApiService.selectByUserIdAndEnterpriseId(staff.getWxUserId(), enterprise.getWxEnterpriseId());
String[] departArr = qywxCallBackDTO.getDepartment(); String[] departArr = qywxCallBackDTO.getDepartment();
String departmentIds = ""; String departmentIds = "";
for(String s : departArr){ for (String s : departArr) {
TabHaobanDepartment department = this.departmentService.getByWxId(s, enterprise.getWxEnterpriseId()); TabHaobanDepartment department = this.departmentService.getByWxId(s, enterprise.getWxEnterpriseId());
if(department == null){ if (department == null) {
log.info("部门不存在"); log.info("部门不存在");
continue; continue;
} }
departmentIds += department.getDepartmentId() + ","; departmentIds += department.getDepartmentId() + ",";
} }
departmentIds = departmentIds.substring(0,departmentIds.length() - 1); departmentIds = departmentIds.substring(0, departmentIds.length() - 1);
if(staffDTO == null){ if (staffDTO == null) {
staffApiService.wxGetAdd(staff.getWxUserId(), enterprise.getWxEnterpriseId()); staffApiService.wxGetAdd(staff.getWxUserId(), enterprise.getWxEnterpriseId());
}else{ } else {
List<TabHaobanStaffDepartmentRelated> list = staffDepartmentRelatedService.listStaffDepartmentByStaffId(staff.getStaffId()); List<TabHaobanStaffDepartmentRelated> list = staffDepartmentRelatedService.listStaffDepartmentByStaffId(staff.getStaffId());
for (TabHaobanStaffDepartmentRelated tabHaobanStaffDepartmentRelated : list) { for (TabHaobanStaffDepartmentRelated tabHaobanStaffDepartmentRelated : list) {
if(!departmentIds.contains(tabHaobanStaffDepartmentRelated.getDepartmentId())){ if (!departmentIds.contains(tabHaobanStaffDepartmentRelated.getDepartmentId())) {
departmentIds += tabHaobanStaffDepartmentRelated.getDepartmentId() + ","; departmentIds += tabHaobanStaffDepartmentRelated.getDepartmentId() + ",";
} }
if(departmentIds.endsWith(",")){ if (departmentIds.endsWith(",")) {
departmentIds = departmentIds.substring(0,departmentIds.length() - 1); departmentIds = departmentIds.substring(0, departmentIds.length() - 1);
} }
} }
StaffDTO staffUpdate = EntityUtil.changeEntityByJSON(StaffDTO.class, staff); StaffDTO staffUpdate = EntityUtil.changeEntityByJSON(StaffDTO.class, staff);
...@@ -376,12 +361,12 @@ public class MessageApiServiceImpl implements MessageApiService { ...@@ -376,12 +361,12 @@ public class MessageApiServiceImpl implements MessageApiService {
// this.addUserDepart(qywxCallBackDTO, add, staff.getWxEnterpriseId()); // this.addUserDepart(qywxCallBackDTO, add, staff.getWxEnterpriseId());
} }
private void addUserDepart(QywxCallBackDTO qywxCallBackDTO, String staffId, String wxEnterpriseId){ private void addUserDepart(QywxCallBackDTO qywxCallBackDTO, String staffId, String wxEnterpriseId) {
String[] departArr = qywxCallBackDTO.getDepartment(); String[] departArr = qywxCallBackDTO.getDepartment();
if(departArr != null){ if (departArr != null) {
for(String s : departArr){ for (String s : departArr) {
TabHaobanDepartment department = this.departmentService.getByWxId(s, wxEnterpriseId); TabHaobanDepartment department = this.departmentService.getByWxId(s, wxEnterpriseId);
if(department == null){ if (department == null) {
log.info("部门不存在"); log.info("部门不存在");
continue; continue;
} }
...@@ -401,35 +386,36 @@ public class MessageApiServiceImpl implements MessageApiService { ...@@ -401,35 +386,36 @@ public class MessageApiServiceImpl implements MessageApiService {
} }
private String changeHeaderImageUrl(String headImgUrl) { private String changeHeaderImageUrl(String headImgUrl) {
try { try {
InputStream in = new URL(headImgUrl).openStream(); InputStream in = new URL(headImgUrl).openStream();
byte[] data = IOUtils.toByteArray(in); byte[] data = IOUtils.toByteArray(in);
PicUploadResDTO uploadPic = qqCloudPicService.uploadPic(GlobalVar.ctxPropertiesMap.get(GlobalInfo.QQPIC_KEY_ENTERPRISE), data); PicUploadResDTO uploadPic = qqCloudPicService.uploadPic(GlobalVar.ctxPropertiesMap.get(GlobalInfo.QQPIC_KEY_ENTERPRISE), data);
log.info("腾讯云万象优图返回" + JSON.toJSONString(uploadPic)); log.info("腾讯云万象优图返回" + JSON.toJSONString(uploadPic));
return uploadPic.downloadUrl; return uploadPic.downloadUrl;
}catch (Exception e){ } catch (Exception e) {
log.info("上传腾讯云万象优图返回失败了:", e); log.info("上传腾讯云万象优图返回失败了:", e);
return headImgUrl; return headImgUrl;
} }
} }
/** /**
* 通过关联的父级ID链查询父级部门 * 通过关联的父级ID链查询父级部门
*
* @param parentChain * @param parentChain
* @return * @return
*/ */
private DepartmentDTO getParentDepartment(String parentChain, int dataType, String wxEnterpriseId){ private DepartmentDTO getParentDepartment(String parentChain, int dataType, String wxEnterpriseId) {
if(StringUtils.isNotBlank(parentChain)){ if (StringUtils.isNotBlank(parentChain)) {
String[] arr = parentChain.split("_"); String[] arr = parentChain.split("_");
int len = arr.length; int len = arr.length;
int startIndex = len - 2; int startIndex = len - 2;
if(dataType == GicDataType.STORE.getCode() || dataType == GicDataType.DEPARTMENT.getCode()){ if (dataType == GicDataType.STORE.getCode() || dataType == GicDataType.DEPARTMENT.getCode()) {
startIndex = len - 1; startIndex = len - 1;
} }
for(int i = startIndex ; i>=0 && i< len; i--){ for (int i = startIndex; i >= 0 && i < len; i--) {
DepartmentDTO department = this.departmentService.getByRelatedIdNotInRecycle(arr[i]); DepartmentDTO department = this.departmentService.getByRelatedIdNotInRecycle(arr[i]);
log.info("当前节点id:{}, {}", arr[i], JSON.toJSONString(department)); log.info("当前节点id:{}, {}", arr[i], JSON.toJSONString(department));
if(department != null){ if (department != null) {
return department; return department;
} }
} }
...@@ -439,26 +425,25 @@ public class MessageApiServiceImpl implements MessageApiService { ...@@ -439,26 +425,25 @@ public class MessageApiServiceImpl implements MessageApiService {
} }
@Override @Override
public Boolean sendFaceMessage(String clerkId,String memberId,String memberName,String arrivalTime,String storeId) { public Boolean sendFaceMessage(String clerkId, String memberId, String memberName, String arrivalTime, String storeId) {
JSONObject jsonObject = new JSONObject(); JSONObject jsonObject = new JSONObject();
jsonObject.put("memberId", memberId); jsonObject.put("memberId", memberId);
jsonObject.put("storeId", storeId); jsonObject.put("storeId", storeId);
String data = jsonObject.toJSONString(); String data = jsonObject.toJSONString();
String pageUrl = staffDepartmentRelatedApiService.getPageUrl(AppPageType.FACE_ARRIVAL.getCode(), data); String pageUrl = staffDepartmentRelatedApiService.getPageUrl(AppPageType.FACE_ARRIVAL.getCode(), data);
StaffClerkRelationDTO relation = staffClerkRelationApiService.getByClerkId(clerkId); StaffClerkRelationDTO relation = staffClerkRelationApiService.getByClerkId(clerkId);
if(relation == null){ if (relation == null) {
log.info("clerkId未绑定:clerkId={}",clerkId); log.info("clerkId未绑定:clerkId={}", clerkId);
return false; return false;
} }
WxEnterpriseDTO wxEnterprise = wxEnterpriseService.selectById(relation.getWxEnterpriseId()); WxEnterpriseDTO wxEnterprise = wxEnterpriseService.selectById(relation.getWxEnterpriseId());
if(wxEnterprise == null){ if (wxEnterprise == null) {
log.info("企业为空"); log.info("企业为空");
return false; return false;
} }
if(relation != null){
String userId = relation.getWxUserId(); String userId = relation.getWxUserId();
QywxXcxSendMessageDTO messageDTO = new QywxXcxSendMessageDTO(); QywxXcxSendMessageDTO messageDTO = new QywxXcxSendMessageDTO();
Map<String,String> map = new HashMap<>(); Map<String, String> map = new HashMap<>();
map.put("事件", "人脸匹配"); map.put("事件", "人脸匹配");
map.put("会员", memberName); map.put("会员", memberName);
map.put("到店时间", arrivalTime); map.put("到店时间", arrivalTime);
...@@ -470,41 +455,23 @@ public class MessageApiServiceImpl implements MessageApiService { ...@@ -470,41 +455,23 @@ public class MessageApiServiceImpl implements MessageApiService {
messageDTO.setPage(pageUrl); messageDTO.setPage(pageUrl);
messageDTO.setTitle("我的顾客通知"); messageDTO.setTitle("我的顾客通知");
messageDTO.setItems(items); messageDTO.setItems(items);
return qywxSuiteApiService.sendMessage(wxEnterprise.getCorpid(), config.getWxSuiteid(), messageDTO);
boolean b = qywxSuiteApiService.sendMessage(wxEnterprise.getCorpid(),config.getWxSuiteid(), messageDTO);
return b;
}
return false;
} }
private List<ItemDTO> getItemsList(Map<String, String> map) { private List<ItemDTO> getItemsList(Map<String, String> map) {
List<ItemDTO> items = new ArrayList(); List<ItemDTO> items = new ArrayList();
Iterator<String> it = map.keySet().iterator(); map.keySet().forEach(key -> {
while (it.hasNext()) {
String key = it.next();
String value = map.get(key); String value = map.get(key);
ItemDTO dto = new ItemDTO(); ItemDTO dto = new ItemDTO();
dto.setKey(key); dto.setKey(key);
dto.setValue(value); dto.setValue(value);
items.add(dto); items.add(dto);
} });
return items; return items;
} }
public static void main(String[] args){
String parentChain = "1_";
String[] arr = parentChain.split("_");
int len = arr.length;
int startIndex = len - 1;
System.out.println(len);
for(int i = startIndex ; i>=0 && i< len; i--){
System.out.println(i);
}
}
@Override @Override
public Boolean sendPerfectRemarkMessage(String clerkId,String memberId, String memberName, String customerTime, String orderId,String storeId) { public Boolean sendPerfectRemarkMessage(String clerkId, String memberId, String memberName, String customerTime, String orderId, String storeId) {
JSONObject jsonObject = new JSONObject(); JSONObject jsonObject = new JSONObject();
jsonObject.put("memberId", memberId); jsonObject.put("memberId", memberId);
jsonObject.put("storeId", storeId); jsonObject.put("storeId", storeId);
...@@ -512,19 +479,18 @@ public class MessageApiServiceImpl implements MessageApiService { ...@@ -512,19 +479,18 @@ public class MessageApiServiceImpl implements MessageApiService {
String data = jsonObject.toJSONString(); String data = jsonObject.toJSONString();
String pageUrl = staffDepartmentRelatedApiService.getPageUrl(AppPageType.PERFECT_TAG.getCode(), data); String pageUrl = staffDepartmentRelatedApiService.getPageUrl(AppPageType.PERFECT_TAG.getCode(), data);
StaffClerkRelationDTO relation = staffClerkRelationApiService.getByClerkId(clerkId); StaffClerkRelationDTO relation = staffClerkRelationApiService.getByClerkId(clerkId);
if(relation == null){ if (relation == null) {
log.info("clerkId未绑定:clerkId={}",clerkId); log.info("clerkId未绑定:clerkId={}", clerkId);
return false; return false;
} }
WxEnterpriseDTO wxEnterprise = wxEnterpriseService.selectById(relation.getWxEnterpriseId()); WxEnterpriseDTO wxEnterprise = wxEnterpriseService.selectById(relation.getWxEnterpriseId());
if(wxEnterprise == null){ if (wxEnterprise == null) {
log.info("企业为空"); log.info("企业为空");
return false; return false;
} }
if(relation != null){
String userId = relation.getWxUserId(); String userId = relation.getWxUserId();
QywxXcxSendMessageDTO messageDTO = new QywxXcxSendMessageDTO(); QywxXcxSendMessageDTO messageDTO = new QywxXcxSendMessageDTO();
Map<String,String> map = new HashMap<>(); Map<String, String> map = new HashMap<>();
map.put("事件", "会员完善标签"); map.put("事件", "会员完善标签");
map.put("会员", memberName); map.put("会员", memberName);
map.put("消费订单", orderId); map.put("消费订单", orderId);
...@@ -537,11 +503,42 @@ public class MessageApiServiceImpl implements MessageApiService { ...@@ -537,11 +503,42 @@ public class MessageApiServiceImpl implements MessageApiService {
messageDTO.setPage(pageUrl); messageDTO.setPage(pageUrl);
messageDTO.setTitle("我的顾客通知"); messageDTO.setTitle("我的顾客通知");
messageDTO.setItems(items); messageDTO.setItems(items);
return qywxSuiteApiService.sendMessage(wxEnterprise.getCorpid(), config.getWxSuiteid(), messageDTO);
boolean b = qywxSuiteApiService.sendMessage(wxEnterprise.getCorpid(),config.getWxSuiteid(), messageDTO);
return b;
} }
return false;
@Override
public void sendWxMessage(String param) {
log.info("发送企业微信消息:{}", param);
if (StringUtils.isBlank(param)) {
log.info("param参数为空");
return;
}
JSONObject jsonObject = JSON.parseObject(param);
String wxEnterpriseId = jsonObject.getString("wxEnterpriseId");
String wxUserId = jsonObject.getString("wxUserId");
String pageUrl = jsonObject.getString("pageUrl");
String title = jsonObject.getString("title");
String content = jsonObject.getString("content");
String memberName = jsonObject.getString("memberName");
WxEnterpriseDTO wxEnterprise = wxEnterpriseService.selectById(wxEnterpriseId);
if (wxEnterprise == null) {
log.info("企业为空");
return;
}
QywxXcxSendMessageDTO messageDTO = new QywxXcxSendMessageDTO();
//后续map加判断可加参数
Map<String, String> map = new HashMap<>();
map.put("事件", content);
map.put("会员", memberName);
List<ItemDTO> items = getItemsList(map);
List<String> userList = new ArrayList<>();
userList.add(wxUserId);
messageDTO.setAppid(config.getAppid());
messageDTO.setUserIds(userList);
messageDTO.setPage(pageUrl);
messageDTO.setTitle(title);
messageDTO.setItems(items);
qywxSuiteApiService.sendMessage(wxEnterprise.getCorpid(), config.getWxSuiteid(), messageDTO);
} }
} }
...@@ -435,6 +435,8 @@ ...@@ -435,6 +435,8 @@
<select id="listAll" resultType="com.gic.haoban.manage.api.dto.StaffClerkRelationDTO"> <select id="listAll" resultType="com.gic.haoban.manage.api.dto.StaffClerkRelationDTO">
SELECT a.store_id, SELECT a.store_id,
a.wx_enterprise_id,
a.wx_user_id,
a.staff_id, a.staff_id,
a.clerk_id, a.clerk_id,
b.staff_name, b.staff_name,
......
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