Commit 24e87b5e by 陶光胜

微信和gic消息推送处理

parent 32080dba
package com.gic.haoban.manage.api.dto;
import java.io.Serializable;
/**
* Created by tgs on 2020/2/20.
*/
public class GicMessageDTO implements Serializable {
private String enterpriseId;
private String parentId;
private String parentChain;
private String id;
//1gic企业部门,2分组,3门店
private Integer type;
private String name;
//1新增,2修改,3删除
private Integer changeType;
public String getEnterpriseId() {
return enterpriseId;
}
public void setEnterpriseId(String enterpriseId) {
this.enterpriseId = enterpriseId;
}
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public Integer getType() {
return type;
}
public void setType(Integer type) {
this.type = type;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public Integer getChangeType() {
return changeType;
}
public void setChangeType(Integer changeType) {
this.changeType = changeType;
}
public String getParentId() {
return parentId;
}
public void setParentId(String parentId) {
this.parentId = parentId;
}
public String getParentChain() {
return parentChain;
}
public void setParentChain(String parentChain) {
this.parentChain = parentChain;
}
}
package com.gic.haoban.manage.api.dto;
import javax.persistence.criteria.CriteriaBuilder;
import java.io.Serializable;
/**
* Created by tgs on 2020/2/15.
*/
public class QywxCallBackDTO implements Serializable{
private String suiteId;
private String infoType;
private String timeStamp;
private String authCode;
private String suiteTicket;
private String authCorpId;
private String userid;
private String userName;
/**1男 2女***/
private Integer gender;
private String alias;
private String[] department;
private String newUserid;
private String mobile;
private Integer id;
private String departmentName;
private Integer parentId;
private Integer order;
/**部门创建:create_party;部门修改:update_party;部门删除:delete_party*
* 成员创建:create_user;成员修改:update_user;成员删除:delete_user*/
private String changeType;
public String getSuiteId() {
return suiteId;
}
public void setSuiteId(String suiteId) {
this.suiteId = suiteId;
}
public String getInfoType() {
return infoType;
}
public void setInfoType(String infoType) {
this.infoType = infoType;
}
public String getTimeStamp() {
return timeStamp;
}
public void setTimeStamp(String timeStamp) {
this.timeStamp = timeStamp;
}
public String getAuthCode() {
return authCode;
}
public void setAuthCode(String authCode) {
this.authCode = authCode;
}
public String getSuiteTicket() {
return suiteTicket;
}
public void setSuiteTicket(String suiteTicket) {
this.suiteTicket = suiteTicket;
}
public String getUserid() {
return userid;
}
public void setUserid(String userid) {
this.userid = userid;
}
public Integer getParentId() {
return parentId;
}
public void setParentId(Integer parentId) {
this.parentId = parentId;
}
public Integer getOrder() {
return order;
}
public void setOrder(Integer order) {
this.order = order;
}
public String getNewUserid() {
return newUserid;
}
public void setNewUserid(String newUserid) {
this.newUserid = newUserid;
}
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public String getUserName() {
return userName;
}
public void setUserName(String userName) {
this.userName = userName;
}
public String getDepartmentName() {
return departmentName;
}
public void setDepartmentName(String departmentName) {
this.departmentName = departmentName;
}
public String getAuthCorpId() {
return authCorpId;
}
public void setAuthCorpId(String authCorpId) {
this.authCorpId = authCorpId;
}
public String getChangeType() {
return changeType;
}
public void setChangeType(String changeType) {
this.changeType = changeType;
}
public String[] getDepartment() {
return department;
}
public void setDepartment(String[] department) {
this.department = department;
}
public String getMobile() {
return mobile;
}
public void setMobile(String mobile) {
this.mobile = mobile;
}
public Integer getGender() {
return gender;
}
public void setGender(Integer gender) {
this.gender = gender;
}
public String getAlias() {
return alias;
}
public void setAlias(String alias) {
this.alias = alias;
}
}
package com.gic.haoban.manage.api.enums;
/**
* Created by tgs on 2020/2/20.
*/
public enum GicDataType {
DEPARTMENT(1, "企业部门"),
GROUP(2,"门店分组"),
STORE(3,"门店");
GicDataType(Integer type, String desc){
this.code = type;
this.desc = desc;
}
private int code;
private String desc;
public String getDesc() {
return desc;
}
public void setDesc(String desc) {
this.desc = desc;
}
public int getCode() {
return code;
}
public void setCode(int code) {
this.code = code;
}
}
package com.gic.haoban.manage.api.enums;
/**
* Created by tgs on 2020/2/20.
*/
public enum GicEditType {
ADD(1, "新增"),
UPDATE(2,"修改"),
DELETE(3,"删除");
GicEditType(Integer type, String desc){
this.code = type;
this.desc = desc;
}
private int code;
private String desc;
public String getDesc() {
return desc;
}
public void setDesc(String desc) {
this.desc = desc;
}
public int getCode() {
return code;
}
public void setCode(int code) {
this.code = code;
}
}
package com.gic.haoban.manage.api.enums;
/**
* Created by tgs on 2020/2/20.
*/
public enum WxEditType {
ADDDEPART("create_party", "创建部门"),
UPDATEDEPART("update_party", "更新部门"),
DELETEDEPART("delete_party", "删除部门"),
ADDUSER("create_user", "新增用户"),
UPDATEUSER("update_user", "更新用户"),
DELETEUSER("delete_user", "删除用户");
WxEditType(String type, String desc){
this.code = type;
this.desc = desc;
}
private String code;
private String desc;
public String getDesc() {
return desc;
}
public void setDesc(String desc) {
this.desc = desc;
}
public String getCode() {
return code;
}
public void setCode(String code) {
this.code = code;
}
}
package com.gic.haoban.manage.api.service;
import com.gic.haoban.manage.api.dto.GicMessageDTO;
import com.gic.haoban.manage.api.dto.QywxCallBackDTO;
/**
* Created by tgs on 2020/2/20.
*/
public interface MessageApiService {
/**接收企业微信的推送消息*/
void gicMessageReceive(GicMessageDTO gicMessageDTO);
/**接收企业微信的推送消息*/
void wxMessageReceive(QywxCallBackDTO qywxCallBackDTO);
/**
* 队列消费gic推送数据
* @param param
*/
void dealGicMessage(String param);
/**
* 队列消费企业微信推送数据
* @param param
*/
void dealWxMessage(String param);
}
...@@ -26,6 +26,8 @@ public interface DepartmentMapper { ...@@ -26,6 +26,8 @@ public interface DepartmentMapper {
int selectMaxSort(@Param("parentDepartmentId")String parentDepartmentId); int selectMaxSort(@Param("parentDepartmentId")String parentDepartmentId);
TabHaobanDepartment selectByRelatedId(@Param("relatedId")String relatedId); TabHaobanDepartment selectByRelatedId(@Param("relatedId")String relatedId);
TabHaobanDepartment getByWxId(@Param("wxDepartmentId")String wxDepartmentId);
List<TabHaobanDepartment> listByDepartmentIds(@Param("departmentIds")List<String> departmentIds,@Param("storeFlag")int storeFlag); List<TabHaobanDepartment> listByDepartmentIds(@Param("departmentIds")List<String> departmentIds,@Param("storeFlag")int storeFlag);
......
...@@ -5,6 +5,7 @@ import java.util.List; ...@@ -5,6 +5,7 @@ import java.util.List;
import com.gic.api.base.commons.Page; import com.gic.api.base.commons.Page;
import com.gic.haoban.manage.api.dto.StaffDepartmentRelatedDTO; import com.gic.haoban.manage.api.dto.StaffDepartmentRelatedDTO;
import com.gic.haoban.manage.service.entity.TabHaobanStaffDepartmentRelated; import com.gic.haoban.manage.service.entity.TabHaobanStaffDepartmentRelated;
import org.apache.ibatis.annotations.Param;
public interface StaffDepartmentRelatedMapper { public interface StaffDepartmentRelatedMapper {
int deleteByPrimaryKey(String staffDepartmentRelatedId); int deleteByPrimaryKey(String staffDepartmentRelatedId);
...@@ -31,4 +32,6 @@ public interface StaffDepartmentRelatedMapper { ...@@ -31,4 +32,6 @@ public interface StaffDepartmentRelatedMapper {
TabHaobanStaffDepartmentRelated getById(String staffDepartmentRelatedId); TabHaobanStaffDepartmentRelated getById(String staffDepartmentRelatedId);
int delByUserid(@Param("userid") String userId);
} }
\ No newline at end of file
...@@ -3,6 +3,7 @@ package com.gic.haoban.manage.service.dao.mapper; ...@@ -3,6 +3,7 @@ package com.gic.haoban.manage.service.dao.mapper;
import java.util.List; import java.util.List;
import com.gic.haoban.manage.service.entity.TabHaobanWxEnterprise; import com.gic.haoban.manage.service.entity.TabHaobanWxEnterprise;
import org.apache.ibatis.annotations.Param;
public interface WxEnterpriseMapper { public interface WxEnterpriseMapper {
int deleteByPrimaryKey(String wxEnterpriseId); int deleteByPrimaryKey(String wxEnterpriseId);
...@@ -18,4 +19,6 @@ public interface WxEnterpriseMapper { ...@@ -18,4 +19,6 @@ public interface WxEnterpriseMapper {
int updateByPrimaryKey(TabHaobanWxEnterprise record); int updateByPrimaryKey(TabHaobanWxEnterprise record);
List<TabHaobanWxEnterprise> list(); List<TabHaobanWxEnterprise> list();
List<TabHaobanWxEnterprise> listBycorpId(@Param("corpId") String corpId);
} }
\ No newline at end of file
...@@ -19,5 +19,6 @@ public interface WxEnterpriseRelatedMapper { ...@@ -19,5 +19,6 @@ public interface WxEnterpriseRelatedMapper {
List<TabHaobanWxEnterpriseRelated> listByWxenterpriseId(String wxEnterpriseId); List<TabHaobanWxEnterpriseRelated> listByWxenterpriseId(String wxEnterpriseId);
TabHaobanWxEnterpriseRelated findOneByEnterpriseId(String enterpriseId); List<TabHaobanWxEnterpriseRelated> findOneByEnterpriseId(String enterpriseId);
} }
\ No newline at end of file
...@@ -20,6 +20,8 @@ public interface DepartmentService { ...@@ -20,6 +20,8 @@ public interface DepartmentService {
TabHaobanDepartment selectByRelatedId(String relatedId); TabHaobanDepartment selectByRelatedId(String relatedId);
TabHaobanDepartment getByWxId(String wxDepartmentId);
void recycle(String departmentId); void recycle(String departmentId);
Page<TabHaobanDepartment> pageDepartmentByParams(String wxEnterpriseId, String keyword, Integer storeFlag, Integer recycleFlag); Page<TabHaobanDepartment> pageDepartmentByParams(String wxEnterpriseId, String keyword, Integer storeFlag, Integer recycleFlag);
......
...@@ -18,5 +18,5 @@ public interface StaffDepartmentRelatedService { ...@@ -18,5 +18,5 @@ public interface StaffDepartmentRelatedService {
void del(StaffDepartmentRelatedDTO related); void del(StaffDepartmentRelatedDTO related);
void delByUserid(String userid);
} }
...@@ -18,4 +18,6 @@ public interface StaffService { ...@@ -18,4 +18,6 @@ public interface StaffService {
TabHaobanStaff selectByUserId(String userId); TabHaobanStaff selectByUserId(String userId);
void updateByPrimaryKey(TabHaobanStaff tab); void updateByPrimaryKey(TabHaobanStaff tab);
int delByuserid(String staffId);
} }
...@@ -2,8 +2,11 @@ package com.gic.haoban.manage.service.service; ...@@ -2,8 +2,11 @@ package com.gic.haoban.manage.service.service;
import com.gic.haoban.manage.service.entity.TabHaobanWxEnterpriseRelated; import com.gic.haoban.manage.service.entity.TabHaobanWxEnterpriseRelated;
import java.util.List;
public interface WxEnterpriseRelatedService { public interface WxEnterpriseRelatedService {
TabHaobanWxEnterpriseRelated getByGicEnterpriseIdByEnterpriseRelatedId(String wxEnterpriseRelatedId); TabHaobanWxEnterpriseRelated getByGicEnterpriseIdByEnterpriseRelatedId(String wxEnterpriseRelatedId);
TabHaobanWxEnterpriseRelated getEnterpriseByGicEnterpriseId(String gicEnterpriseId);
} }
package com.gic.haoban.manage.service.service; package com.gic.haoban.manage.service.service;
import com.gic.haoban.manage.api.dto.WxEnterpriseDTO; import com.gic.haoban.manage.api.dto.WxEnterpriseDTO;
import com.gic.haoban.manage.service.entity.TabHaobanWxEnterprise;
public interface WxEnterpriseService { public interface WxEnterpriseService {
...@@ -8,4 +9,11 @@ public interface WxEnterpriseService { ...@@ -8,4 +9,11 @@ public interface WxEnterpriseService {
WxEnterpriseDTO selectById(String wxEnterpriseId); WxEnterpriseDTO selectById(String wxEnterpriseId);
/**
* 通过微信企业ID查询好办企业ID
* @param corpId
* @return
*/
TabHaobanWxEnterprise getEnterpriseBycorpId(String corpId);
} }
...@@ -78,6 +78,11 @@ public class DepartmentServiceImpl implements DepartmentService { ...@@ -78,6 +78,11 @@ public class DepartmentServiceImpl implements DepartmentService {
} }
@Override @Override
public TabHaobanDepartment getByWxId(String wxDepartmentId) {
return null;
}
@Override
public void recycle(String departmentId) { public void recycle(String departmentId) {
TabHaobanDepartment tab = mapper.selectByPrimaryKey(departmentId); TabHaobanDepartment tab = mapper.selectByPrimaryKey(departmentId);
if(tab != null) { if(tab != null) {
......
...@@ -59,6 +59,10 @@ public class StaffDepartmentRelatedServiceImpl implements StaffDepartmentRelated ...@@ -59,6 +59,10 @@ public class StaffDepartmentRelatedServiceImpl implements StaffDepartmentRelated
} }
@Override
public void delByUserid(String userid) {
}
} }
...@@ -56,4 +56,12 @@ public class StaffServiceImpl implements StaffService { ...@@ -56,4 +56,12 @@ public class StaffServiceImpl implements StaffService {
mapper.updateByPrimaryKey(tab); mapper.updateByPrimaryKey(tab);
} }
@Override
public int delByuserid(String staffId) {
TabHaobanStaff staff = new TabHaobanStaff();
staff.setStaffId(staffId);
staff.setStatusFlag(0);
return this.mapper.updateByPrimaryKey(staff);
}
} }
package com.gic.haoban.manage.service.service.impl; package com.gic.haoban.manage.service.service.impl;
import org.apache.commons.collections.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
...@@ -7,6 +8,8 @@ import com.gic.haoban.manage.service.dao.mapper.WxEnterpriseRelatedMapper; ...@@ -7,6 +8,8 @@ import com.gic.haoban.manage.service.dao.mapper.WxEnterpriseRelatedMapper;
import com.gic.haoban.manage.service.entity.TabHaobanWxEnterpriseRelated; import com.gic.haoban.manage.service.entity.TabHaobanWxEnterpriseRelated;
import com.gic.haoban.manage.service.service.WxEnterpriseRelatedService; import com.gic.haoban.manage.service.service.WxEnterpriseRelatedService;
import java.util.List;
@Service @Service
public class WxEnterpriseRelatedServiceImpl implements WxEnterpriseRelatedService { public class WxEnterpriseRelatedServiceImpl implements WxEnterpriseRelatedService {
@Autowired @Autowired
...@@ -18,4 +21,13 @@ public class WxEnterpriseRelatedServiceImpl implements WxEnterpriseRelatedServic ...@@ -18,4 +21,13 @@ public class WxEnterpriseRelatedServiceImpl implements WxEnterpriseRelatedServic
return mapper.selectByPrimaryKey(wxEnterpriseRelatedId); return mapper.selectByPrimaryKey(wxEnterpriseRelatedId);
} }
@Override
public TabHaobanWxEnterpriseRelated getEnterpriseByGicEnterpriseId(String gicEnterpriseId) {
List<TabHaobanWxEnterpriseRelated> list = mapper.findOneByEnterpriseId(gicEnterpriseId);
if(CollectionUtils.isNotEmpty(list)){
return list.get(0);
}
return null;
}
} }
package com.gic.haoban.manage.service.service.impl; package com.gic.haoban.manage.service.service.impl;
import java.util.Date; import java.util.Date;
import java.util.List;
import org.apache.commons.collections.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
...@@ -34,4 +36,13 @@ public class WxEnterpriseServiceImpl implements WxEnterpriseService { ...@@ -34,4 +36,13 @@ public class WxEnterpriseServiceImpl implements WxEnterpriseService {
return null; return null;
} }
@Override
public TabHaobanWxEnterprise getEnterpriseBycorpId(String corpId) {
List<TabHaobanWxEnterprise> list = this.mapper.listBycorpId(corpId);
if(CollectionUtils.isNotEmpty(list)){
return list.get(0);
}
return null;
}
} }
package com.gic.haoban.manage.service.service.out.impl;
import com.alibaba.fastjson.JSON;
import com.gic.commons.util.GICMQClientUtil;
import com.gic.haoban.base.api.common.Constant;
import com.gic.haoban.common.utils.HaobanResponse;
import com.gic.haoban.manage.api.dto.DepartmentDTO;
import com.gic.haoban.manage.api.dto.GicMessageDTO;
import com.gic.haoban.manage.api.dto.QywxCallBackDTO;
import com.gic.haoban.manage.api.dto.StaffDepartmentRelatedDTO;
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.service.DepartmentApiService;
import com.gic.haoban.manage.api.service.MessageApiService;
import com.gic.haoban.manage.service.entity.*;
import com.gic.haoban.manage.service.service.*;
import com.gic.mq.sdk.GicMQClient;
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推送消息进行处理
* Created by tgs on 2020/2/20.
*/
@Service("messageApiService")
public class MessageApiServiceImpl implements MessageApiService {
private static final Logger log = LogManager.getLogger(MessageApiServiceImpl.class);
@Autowired
private DepartmentService departmentService;
@Autowired
private WxEnterpriseRelatedService wxEnterpriseRelatedService;
@Autowired
private DepartmentApiService departmentApiService;
@Autowired
private WxEnterpriseService enterpriseService;
@Autowired
private StaffService staffService;
@Autowired
private StaffDepartmentRelatedService staffDepartmentRelatedService;
@Override
public void gicMessageReceive(GicMessageDTO gicMessageDTO) {
GicMQClient clientInstance = GICMQClientUtil.getClientInstance();
try {
log.info("发送消息到dealGicMessageMq,{}", JSON.toJSONString(gicMessageDTO));
clientInstance.sendMessage("dealGicMessageMq", JSON.toJSONString(gicMessageDTO));
} catch (Exception e) {
e.printStackTrace();
}
}
@Override
public void wxMessageReceive(QywxCallBackDTO qywxCallBackDTO) {
GicMQClient clientInstance = GICMQClientUtil.getClientInstance();
try {
log.info("发送消息到dealWxMessageMq,{}", JSON.toJSONString(qywxCallBackDTO));
clientInstance.sendMessage("dealWxMessageMq", JSON.toJSONString(qywxCallBackDTO));
} catch (Exception e) {
e.printStackTrace();
}
}
@Override
public void dealGicMessage(String param) {
GicMessageDTO dto = JSON.parseObject(param, GicMessageDTO.class);
TabHaobanWxEnterpriseRelated enterprise =
this.wxEnterpriseRelatedService.getEnterpriseByGicEnterpriseId(dto.getEnterpriseId());
if(enterprise != null){
DepartmentDTO departmentDTO = new DepartmentDTO();
departmentDTO.setDepartmentName(dto.getName());
departmentDTO.setIsStore(dto.getType() != GicDataType.STORE.getCode() ? 0 : 1);
departmentDTO.setRelatedId(dto.getId());
DepartmentDTO parentDepartment = this.getParentDepartment(dto.getParentChain(), dto.getType(), enterprise.getWxEnterpriseId());
departmentDTO.setParentDepartmentId(parentDepartment.getDepartmentId());
departmentDTO.setChainId(parentDepartment.getChainId()+ Constant.ID_SEPARATOR + parentDepartment.getDepartmentId());
departmentDTO.setChainName(parentDepartment.getChainName() + Constant.NAME_SEPARATOR + parentDepartment.getChainName());
departmentDTO.setLevel(parentDepartment.getLevel() + 1);
departmentDTO.setWxEnterpriseId(enterprise.getWxEnterpriseId());
if(dto.getType() == GicEditType.ADD.getCode()){
HaobanResponse response = this.departmentApiService.add(departmentDTO);
log.info("添加结果:{}", JSON.toJSONString(response));
}else if(dto.getType() == GicEditType.UPDATE.getCode()){
TabHaobanDepartment department = this.departmentService.selectByRelatedId(dto.getId());
if(department == null){
HaobanResponse response = this.departmentApiService.add(departmentDTO);
log.info("添加结果:{}", JSON.toJSONString(response));
}else {
departmentDTO.setDepartmentId(department.getDepartmentId());
this.departmentApiService.edit(departmentDTO);
log.info("gic同步更新完成");
}
}else {
TabHaobanDepartment department = this.departmentService.selectByRelatedId(dto.getId());
if(department != null){
this.departmentApiService.del(department.getDepartmentId());
log.info("gic同步删除完成");
}else {
log.info("gic同步删除不存在");
}
}
}
}
@Override
public void dealWxMessage(String param) {
QywxCallBackDTO dto = JSON.parseObject(param, QywxCallBackDTO.class);
if(dto.getInfoType().endsWith("party")){
this.dealDepartment(dto);
}else {
this.dealUser(dto);
}
}
private void dealDepartment(QywxCallBackDTO qywxCallBackDTO){
DepartmentDTO departmentDTO = new DepartmentDTO();
departmentDTO.setDepartmentName(qywxCallBackDTO.getDepartmentName());
departmentDTO.setIsStore(0);
departmentDTO.setRelatedId(qywxCallBackDTO.getId()+"");
TabHaobanDepartment parentDepartment = this.departmentService.getByWxId(qywxCallBackDTO.getParentId() + "");
departmentDTO.setParentDepartmentId(parentDepartment.getDepartmentId());
departmentDTO.setChainId(parentDepartment.getChainId()+ Constant.ID_SEPARATOR + parentDepartment.getDepartmentId());
departmentDTO.setChainName(parentDepartment.getChainName() + Constant.NAME_SEPARATOR + parentDepartment.getChainName());
departmentDTO.setLevel(parentDepartment.getLevel() + 1);
TabHaobanWxEnterprise enterprise = this.enterpriseService.getEnterpriseBycorpId(qywxCallBackDTO.getAuthCorpId());
departmentDTO.setWxEnterpriseId(enterprise.getWxEnterpriseId());
departmentDTO.setWxDepartmentId(qywxCallBackDTO.getId()+"");
if(qywxCallBackDTO.getChangeType().equals(WxEditType.ADDDEPART.getCode())){
String response = this.departmentService.add(departmentDTO);
log.info("微信同步新增部门:{}", JSON.toJSONString(response));
}else if(qywxCallBackDTO.getChangeType().equals(WxEditType.UPDATEDEPART.getCode())){
TabHaobanDepartment department = this.departmentService.getByWxId(qywxCallBackDTO.getId() + "");
if(department == null){
String response = this.departmentService.add(departmentDTO);
log.info("微信同步新增部门:{}", JSON.toJSONString(response));
}else {
departmentDTO.setDepartmentId(department.getDepartmentId());
this.departmentService.edit(departmentDTO);
log.info("企业微信更新同步完成");
}
}else {
TabHaobanDepartment department = this.departmentService.getByWxId(qywxCallBackDTO.getId() + "");
if(department == null){
log.info("微信同步删除部门不存在");
}else {
this.departmentService.del(departmentDTO.getDepartmentId());
log.info("企业微信删除同步完成");
}
}
}
private void dealUser(QywxCallBackDTO qywxCallBackDTO){
TabHaobanStaff staff = new TabHaobanStaff();
TabHaobanWxEnterprise enterprise = this.enterpriseService.getEnterpriseBycorpId(qywxCallBackDTO.getAuthCorpId());
if(enterprise == null){
staff.setWxEnterpriseId(enterprise.getWxEnterpriseId());
staff.setActiveFlag(0);
staff.setPhoneNumber(qywxCallBackDTO.getMobile());
staff.setNickName(qywxCallBackDTO.getAlias());
staff.setSex(qywxCallBackDTO.getGender());
staff.setStaffName(qywxCallBackDTO.getUserName());
staff.setWxUserId(qywxCallBackDTO.getUserid());
if(qywxCallBackDTO.getChangeType().equals(WxEditType.ADDUSER.getCode())){
this.addUser(qywxCallBackDTO, staff);
} else if(qywxCallBackDTO.getChangeType().equals(WxEditType.UPDATEUSER.getCode())){
TabHaobanStaff oldStaff = this.staffService.selectByUserId(qywxCallBackDTO.getUserid());
if(oldStaff != null){
staff.setWxUserId(qywxCallBackDTO.getNewUserid());
staff.setStaffId(oldStaff.getStaffId());
this.staffService.updateByPrimaryKey(staff);
this.staffDepartmentRelatedService.delByUserid(qywxCallBackDTO.getUserid());
this.addUserDepart(qywxCallBackDTO, oldStaff.getStaffId());
}else {
this.addUser(qywxCallBackDTO, staff);
}
} else {
TabHaobanStaff oldStaff = this.staffService.selectByUserId(qywxCallBackDTO.getUserid());
if(oldStaff != null){
this.staffService.delByuserid(oldStaff.getStaffId());
}else {
log.info("微信同步删除的门店不存在,{}", qywxCallBackDTO.getUserid());
}
}
}else {
log.info("授权企业不存在,{}", qywxCallBackDTO.getAuthCorpId());
}
}
private void addUser(QywxCallBackDTO qywxCallBackDTO, TabHaobanStaff staff){
String add = this.staffService.add(staff);
log.info("新增用户返回结果:{}", add);
this.addUserDepart(qywxCallBackDTO, add);
}
private void addUserDepart(QywxCallBackDTO qywxCallBackDTO, String staffId){
String[] departArr = qywxCallBackDTO.getDepartment();
for(String s : departArr){
TabHaobanDepartment department = this.departmentService.getByWxId(s);
if(department == null){
log.info("部门不存在");
continue;
}
StaffDepartmentRelatedDTO related = new StaffDepartmentRelatedDTO();
related.setWxUserId(qywxCallBackDTO.getUserid());
related.setClerkCode(qywxCallBackDTO.getUserid());
related.setDepartmentId(department.getDepartmentId());
related.setPhoneNumber(qywxCallBackDTO.getMobile());
related.setStaffDepartmentRelatedId(staffId);
related.setStatusFlag(1);
String add1 = this.staffDepartmentRelatedService.add(related);
log.info("新增用户部门关联关系:{}", add1);
}
}
/**
* 通过关联的父级ID链查询父级部门
* @param parentChain
* @return
*/
private DepartmentDTO getParentDepartment(String parentChain, int dataType, String wxEnterpriseId){
if(StringUtils.isNotBlank(parentChain)){
String[] arr = parentChain.split("_");
int len = arr.length;
int startIndex = len - 2;
if(dataType == GicDataType.STORE.getCode()){
startIndex = len - 1;
}
for(int i = startIndex; i< len; i--){
DepartmentDTO department = this.departmentService.getByRelatedId(arr[i]);
if(department != null){
return department;
}
}
}
DepartmentDTO departmentDTO = this.departmentService.getRootByEnterpriseId(wxEnterpriseId);
return departmentDTO;
}
}
...@@ -28,6 +28,7 @@ ...@@ -28,6 +28,7 @@
<dubbo:service interface="com.gic.haoban.manage.api.service.WxEnterpriseRelatedApiService" ref="wxEnterpriseRelatedApiServiceImpl" timeout="10000" /> <dubbo:service interface="com.gic.haoban.manage.api.service.WxEnterpriseRelatedApiService" ref="wxEnterpriseRelatedApiServiceImpl" timeout="10000" />
<dubbo:service interface="com.gic.haoban.manage.api.service.StaffDepartmentRelatedApiService" ref="staffDepartmentRelatedApiServiceImpl" timeout="10000" /> <dubbo:service interface="com.gic.haoban.manage.api.service.StaffDepartmentRelatedApiService" ref="staffDepartmentRelatedApiServiceImpl" timeout="10000" />
<dubbo:service interface="com.gic.haoban.manage.api.service.WxEnterpriseApiService" ref="wxEnterpriseApiServiceImpl" timeout="10000" /> <dubbo:service interface="com.gic.haoban.manage.api.service.WxEnterpriseApiService" ref="wxEnterpriseApiServiceImpl" timeout="10000" />
<dubbo:service interface="com.gic.haoban.manage.api.service.MessageApiService" ref="messageApiService" timeout="10000" />
<dubbo:reference interface="com.gic.enterprise.api.service.DepartmentService" id="gicDepartmentService"/> <dubbo:reference interface="com.gic.enterprise.api.service.DepartmentService" id="gicDepartmentService"/>
<dubbo:reference interface="com.gic.wechat.api.service.qywx.QywxDepartmentApiService" id="qywxDepartmentApiService"/> <dubbo:reference interface="com.gic.wechat.api.service.qywx.QywxDepartmentApiService" id="qywxDepartmentApiService"/>
......
...@@ -224,7 +224,14 @@ ...@@ -224,7 +224,14 @@
where related_id = #{relatedId,jdbcType=VARCHAR} where related_id = #{relatedId,jdbcType=VARCHAR}
and status_flag = 1 and status_flag = 1
</select> </select>
<select id="getByWxId" resultMap="BaseResultMap" parameterType="java.lang.String" >
select
<include refid="Base_Column_List" />
from tab_haoban_department
where wx_department_id = #{wxDepartmentId,jdbcType=VARCHAR}
and status_flag = 1
</select>
<select id="pageDepartmentByParams" resultMap="BaseResultMap" parameterType="java.lang.String" > <select id="pageDepartmentByParams" resultMap="BaseResultMap" parameterType="java.lang.String" >
select select
......
...@@ -192,5 +192,10 @@ ...@@ -192,5 +192,10 @@
where staff_id = #{staffId,jdbcType=VARCHAR} where staff_id = #{staffId,jdbcType=VARCHAR}
and status_flag = 1 and status_flag = 1
</select> </select>
<update id="delByUserid" >
update tab_haoban_staff_department_related
set
status_flag = 0
where wx_user_id = #{userid,jdbcType=VARCHAR}
</update>
</mapper> </mapper>
\ No newline at end of file
...@@ -265,7 +265,7 @@ ...@@ -265,7 +265,7 @@
select select
<include refid="Base_Column_List" /> <include refid="Base_Column_List" />
from tab_haoban_staff from tab_haoban_staff
where user_id = #{userId,jdbcType=VARCHAR} where wx_user_id = #{userId,jdbcType=VARCHAR}
and staus_flag = 1 and staus_flag = 1
</select> </select>
</mapper> </mapper>
\ No newline at end of file
...@@ -352,13 +352,18 @@ ...@@ -352,13 +352,18 @@
where wx_enterprise_id = #{wxEnterpriseId,jdbcType=VARCHAR} where wx_enterprise_id = #{wxEnterpriseId,jdbcType=VARCHAR}
</update> </update>
<select id="list" resultMap="BaseResultMap" parameterType="java.lang.String" > <select id="list" resultMap="BaseResultMap" parameterType="java.lang.String" >
select select
<include refid="Base_Column_List" /> <include refid="Base_Column_List" />
from tab_haoban_wx_enterprise from tab_haoban_wx_enterprise
where status_flag = 1 where status_flag = 1
</select> </select>
<select id="listBycorpId" resultMap="BaseResultMap" parameterType="java.lang.String" >
select
<include refid="Base_Column_List" />
from tab_haoban_wx_enterprise
where status_flag = 1 and corpid= #{corpId}
</select>
</mapper> </mapper>
\ No newline at end of file
...@@ -129,5 +129,4 @@ ...@@ -129,5 +129,4 @@
where enterprise_id = #{enterpriseId,jdbcType=VARCHAR} where enterprise_id = #{enterpriseId,jdbcType=VARCHAR}
and status_flag = 1 and status_flag = 1
</select> </select>
</mapper> </mapper>
\ 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