Commit 39bb6ca7 by 墨竹

fix:企微同步通讯录处理部门bug

parent 2c82e1e6
...@@ -45,27 +45,6 @@ public interface DepartmentApiService { ...@@ -45,27 +45,6 @@ public interface DepartmentApiService {
*/ */
DepartmentDTO selectById(String departmentId); DepartmentDTO selectById(String departmentId);
/** /**
* 新增部门
* @param department
* @return
*/
@Deprecated
ServiceResponse<DepartmentDTO> add(DepartmentDTO department);
/**
* 修改部门
* @param department
* @return
*/
@Deprecated
ServiceResponse edit(DepartmentDTO department);
/**
* 删除部门
* @param departmentId
* @return
*/
@Deprecated
ServiceResponse del(String departmentId);
/**
* 根据关联id 获取部门 * 根据关联id 获取部门
* @param departId * @param departId
* @return * @return
......
...@@ -13,7 +13,6 @@ import com.gic.haoban.manage.service.dao.mapper.TabHaobanWelcomeSuitRangMapper; ...@@ -13,7 +13,6 @@ import com.gic.haoban.manage.service.dao.mapper.TabHaobanWelcomeSuitRangMapper;
import com.gic.haoban.manage.service.entity.TabHaobanDepartment; import com.gic.haoban.manage.service.entity.TabHaobanDepartment;
import com.gic.haoban.manage.service.entity.TabHaobanWelcomeSuitRang; import com.gic.haoban.manage.service.entity.TabHaobanWelcomeSuitRang;
import com.gic.haoban.manage.service.service.DepartmentService; import com.gic.haoban.manage.service.service.DepartmentService;
import com.gic.haoban.manage.service.task.QywxDeptSyncOperation;
import com.github.pagehelper.Page; import com.github.pagehelper.Page;
import org.apache.commons.collections.CollectionUtils; import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang.StringUtils; import org.apache.commons.lang.StringUtils;
......
...@@ -2,14 +2,11 @@ package com.gic.haoban.manage.service.service.out.impl; ...@@ -2,14 +2,11 @@ package com.gic.haoban.manage.service.service.out.impl;
import cn.hutool.core.collection.CollectionUtil; import cn.hutool.core.collection.CollectionUtil;
import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import com.gic.api.base.commons.JSONResponse; import com.gic.api.base.commons.JSONResponse;
import com.gic.api.base.commons.Page; import com.gic.api.base.commons.Page;
import com.gic.commons.util.EntityUtil; import com.gic.commons.util.EntityUtil;
import com.gic.commons.util.GICMQClientUtil; import com.gic.commons.util.GICMQClientUtil;
import com.gic.enterprise.api.dto.StoreDTO;
import com.gic.enterprise.api.dto.StoreGroupDTO;
import com.gic.enterprise.api.service.StoreGroupService; import com.gic.enterprise.api.service.StoreGroupService;
import com.gic.enterprise.api.service.StoreService; import com.gic.enterprise.api.service.StoreService;
import com.gic.haoban.base.api.common.BasePageInfo; import com.gic.haoban.base.api.common.BasePageInfo;
...@@ -88,167 +85,6 @@ public class DepartmentApiServiceImpl implements DepartmentApiService { ...@@ -88,167 +85,6 @@ public class DepartmentApiServiceImpl implements DepartmentApiService {
} }
@Override @Override
public ServiceResponse<DepartmentDTO> add(DepartmentDTO department) {
ServiceResponse hr = new ServiceResponse();
hr.setCode(1);
//调微信的新增接口
String wxDepartmentId = "";
WxEnterpriseDTO enterpriseDTO = wxEnterpriseService.selectById(department.getWxEnterpriseId());
logger.info("【部门新增】enterpriseDTO = {}", JSON.toJSONString(enterpriseDTO));
if (enterpriseDTO != null) {
Long sort = department.getSort();
if (sort == null) {
long maxSort = departmentMapper.selectMaxSort(department.getParentDepartmentId());
department.setSort(maxSort + 1);
}
com.gic.wechat.api.dto.qywx.DepartmentDTO dto = new com.gic.wechat.api.dto.qywx.DepartmentDTO();
dto.setCorpid(enterpriseDTO.getCorpid());
dto.setName(department.getDepartmentName());
dto.setOrder(department.getSort());
TabHaobanDepartment parent = departmentService.selectById(department.getParentDepartmentId());
dto.setParentid(Integer.valueOf(parent.getWxDepartmentId()));
SecretSettingDTO secretSetting = secretSettingService.getSecretSetting(enterpriseDTO.getWxEnterpriseId(), SecretTypeEnum.CONTACT_SECRET.getVal());
if (null == secretSetting || secretSetting.getCheckFlag() == 0) {
hr.setCode(0);
hr.setMessage("没有设置通讯录secret");
return hr;
}
logger.info("【部门新增】corpid() = {},siteId={},dto={}", enterpriseDTO.getCorpid(), secretSetting.getSecretVal(), JSON.toJSONString(dto));
JSONResponse jp = qywxDepartmentApiService.createSelfDepartment(enterpriseDTO.getCorpid(), secretSetting.getSecretVal(), dto);
logger.info("【部门新增】jp = {}", JSON.toJSONString(jp));
if (jp.getErrorCode() != 0) {
hr.setCode(0);
hr.setMessage("微信新增部门失败:" + jp.getErrorCode());
return hr;
}
wxDepartmentId = jp.getResult().toString();
logger.info("【部门新增】wxDepartmentId = {}", wxDepartmentId);
department.setWxDepartmentId(wxDepartmentId);
department.setLevel(parent.getLevel() + 1);
setGicEnterpriseId(department);
String departmentId = departmentService.add(department);
department.setDepartmentId(departmentId);
hr.setResult(department);
}
return hr;
}
private void setGicEnterpriseId(DepartmentDTO department) {
String relatedId = department.getRelatedId();
if (StringUtils.isNotBlank(relatedId)) {
Integer storeFlag = department.getIsStore();
if (storeFlag == 1) {
StoreDTO store = storeService.getStore(relatedId);
if (store != null) {
department.setEnterpriseId(store.getEnterpriseId());
}
} else {
com.gic.enterprise.api.dto.DepartmentDTO departmentDTO = gicDepartmentService.getDeptment(relatedId);
if (departmentDTO != null) {
department.setEnterpriseId(departmentDTO.getEnterpriseId());
}
StoreGroupDTO storeGroup = storeGroupService.getStoreGroupById(relatedId);
if (storeGroup != null) {
department.setEnterpriseId(storeGroup.getEnterpriseId());
}
}
}
}
@Override
public ServiceResponse edit(DepartmentDTO department) {
ServiceResponse hr = new ServiceResponse();
hr.setCode(1);
hr.setResult(department);
//调微信的修改接口
TabHaobanDepartment tab = departmentService.selectById(department.getDepartmentId());
if (tab == null) {
hr.setCode(0);
hr.setMessage("部门不存在");
return hr;
}
logger.info("【部门修改】tab={}", JSON.toJSONString(tab));
WxEnterpriseDTO enterpriseDTO = wxEnterpriseService.selectById(tab.getWxEnterpriseId());
if (enterpriseDTO != null) {
com.gic.wechat.api.dto.qywx.DepartmentDTO dto = new com.gic.wechat.api.dto.qywx.DepartmentDTO();
dto.setCorpid(enterpriseDTO.getCorpid());
dto.setName(department.getDepartmentName());
dto.setOrder(department.getSort());
TabHaobanDepartment parent = departmentService.selectById(department.getParentDepartmentId());
dto.setParentid(Integer.valueOf(parent.getWxDepartmentId()));
dto.setId(Integer.valueOf(tab.getWxDepartmentId()));
SecretSettingDTO secretSetting = secretSettingService.getSecretSetting(enterpriseDTO.getWxEnterpriseId(), SecretTypeEnum.CONTACT_SECRET.getVal());
if (null == secretSetting || secretSetting.getCheckFlag() == 0) {
hr.setCode(0);
hr.setMessage("没有设置通讯录secret");
return hr;
}
JSONResponse jp = qywxDepartmentApiService.updateSelfDepartment(enterpriseDTO.getCorpid(), secretSetting.getSecretVal(), dto);
logger.info("【部门修改】jp={}", JSON.toJSONString(jp));
if (jp.getErrorCode() != 0) {
hr.setCode(0);
hr.setMessage("微信修改部门失败");
return hr;
}
}
departmentService.edit(department);
return hr;
}
@Override
public ServiceResponse del(String departmentId) {
ServiceResponse hr = new ServiceResponse();
hr.setCode(1);
List<TabHaobanDepartment> list = departmentService.listByParentId(departmentId);
logger.info("【部门删除】list.size={}", list.size());
if (!list.isEmpty()) {
hr.setCode(0);
hr.setMessage("存在子部门,删除部门失败");
return hr;
}
List<TabHaobanStaffDepartmentRelated> staffList = staffDepartmentService.listByDepartmentId(departmentId);
logger.info("【部门删除】staffList.size={}", staffList.size());
if (!staffList.isEmpty()) {
hr.setCode(0);
hr.setMessage("存在成员,删除部门失败");
return hr;
}
//调微信的删除接口
TabHaobanDepartment department = departmentService.selectById(departmentId);
if (department == null) {
hr.setCode(0);
hr.setMessage("不存在部门,删除部门失败");
return hr;
}
WxEnterpriseDTO enterpriseDTO = wxEnterpriseService.selectById(department.getWxEnterpriseId());
if (enterpriseDTO != null) {
SecretSettingDTO secretSetting = secretSettingService.getSecretSetting(enterpriseDTO.getWxEnterpriseId(), SecretTypeEnum.CONTACT_SECRET.getVal());
if (null == secretSetting || secretSetting.getCheckFlag() == 0) {
logger.info("没有设置通讯录secret:{}", JSONObject.toJSONString(secretSetting));
hr.setCode(0);
hr.setMessage("没有设置通讯录secret");
return hr;
}
JSONResponse jp = qywxDepartmentApiService.deleteSelfDepartment(enterpriseDTO.getCorpid(), secretSetting.getSecretVal(), Integer.parseInt(department.getWxDepartmentId()));
if (jp.getErrorCode() != 0) {
logger.info("微信删除部门失败:{}", JSONObject.toJSONString(jp));
hr.setCode(0);
hr.setMessage("微信删除部门失败");
return hr;
}
}
departmentService.del(departmentId);
return hr;
}
@Override
public ServiceResponse wxCallBackDel(String departmentId) { public ServiceResponse wxCallBackDel(String departmentId) {
ServiceResponse hr = new ServiceResponse(); ServiceResponse hr = new ServiceResponse();
hr.setCode(1); hr.setCode(1);
...@@ -436,46 +272,6 @@ public class DepartmentApiServiceImpl implements DepartmentApiService { ...@@ -436,46 +272,6 @@ public class DepartmentApiServiceImpl implements DepartmentApiService {
if (true) { if (true) {
return; return;
} }
logger.info("【同步门店】fieldList={}", fieldListString);
List<SyncJsonColumnDTO> fieldList = JSONArray.parseArray(fieldListString, SyncJsonColumnDTO.class);
if (fieldList.isEmpty()) {
return;
}
Integer status = 0;
String storeName = "";
String departmentId = "";
String storeId = "";
String storeParentId = "";
for (SyncJsonColumnDTO syncJsonColumnDTO : fieldList) {
String name = StringUtil.camelName(syncJsonColumnDTO.getName());
String value = syncJsonColumnDTO.getValue();
if ("status".equals(name)) {
status = Integer.parseInt(value);
}
if ("storeName".equals(name)) {
storeName = value;
}
if ("departmentId".equals(name)) {
departmentId = value;
}
if ("storeGroupId".equals(name)) {
storeParentId = value;
}
if ("storeId".equals(name)) {
storeId = (value);
}
}
DepartmentDTO department = departmentService.getByRelatedId(storeId);
DepartmentDTO parent = departmentService.getByRelatedId(storeParentId);
if (department != null && parent != null && (!department.getParentDepartmentId().equals(parent.getDepartmentId()))) {
logger.info("更新部门!");
department.setDepartmentName(storeName);
department.setParentDepartmentId(parent.getDepartmentId());
this.edit(department);
}
} }
/** /**
...@@ -595,6 +391,7 @@ public class DepartmentApiServiceImpl implements DepartmentApiService { ...@@ -595,6 +391,7 @@ public class DepartmentApiServiceImpl implements DepartmentApiService {
private void addAllDepartment(List<com.gic.wechat.api.dto.qywx.DepartmentDTO> list, Integer parentId, private void addAllDepartment(List<com.gic.wechat.api.dto.qywx.DepartmentDTO> list, Integer parentId,
String wxEnterpriseId, String corpid, String contactSecret, String taskId) { String wxEnterpriseId, String corpid, String contactSecret, String taskId) {
logger.info("新增所有企微部门");
int level = 1; int level = 1;
String chainId = "0"; String chainId = "0";
String chainName = "0"; String chainName = "0";
......
...@@ -115,7 +115,7 @@ public class MessageApiServiceImpl implements MessageApiService { ...@@ -115,7 +115,7 @@ public class MessageApiServiceImpl implements MessageApiService {
@Override @Override
public void dealWxMessage(String param) { public void dealWxMessage(String param) {
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));
//处理成员 //处理成员
dealQywxUser(dto); dealQywxUser(dto);
//处理部门 //处理部门
......
...@@ -33,6 +33,7 @@ import java.util.Set; ...@@ -33,6 +33,7 @@ import java.util.Set;
import java.util.stream.Collectors; import java.util.stream.Collectors;
/** /**
* 同步通讯录部门
* Created 2020/4/13. * Created 2020/4/13.
* *
* @author hua * @author hua
......
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