Commit d7826e08 by fudahua

点击刷新企业微信数据

parent f3fa7b07
...@@ -30,6 +30,14 @@ public interface StaffApiService { ...@@ -30,6 +30,14 @@ public interface StaffApiService {
public void del(String staffDepartmentStaffRelatedId); public void del(String staffDepartmentStaffRelatedId);
/**
* 获取微信成员
* @param userId
* @param wxEnterpriseId
* @return
*/
public ServiceResponse getWxSaveNew(String userId,String wxEnterpriseId);
public void wxGetAdd(String userId,String wxEnterpriseId); public void wxGetAdd(String userId,String wxEnterpriseId);
public void staffEdit(StaffDTO staffDTO, String departmentIds); public void staffEdit(StaffDTO staffDTO, String departmentIds);
......
...@@ -69,4 +69,6 @@ public interface DepartmentMapper { ...@@ -69,4 +69,6 @@ public interface DepartmentMapper {
Integer totalStoreCountByEnterpriseId(@Param("wxEnterpriseId")String wxEnterpriseId); Integer totalStoreCountByEnterpriseId(@Param("wxEnterpriseId")String wxEnterpriseId);
public int cleanDepartment(@Param("wxEnterpriseId")String wxEnterpriseId, @Param("dIds") List<String> wxDeIds); public int cleanDepartment(@Param("wxEnterpriseId")String wxEnterpriseId, @Param("dIds") List<String> wxDeIds);
public List<TabHaobanDepartment> listDepartmentByWxDepartIds(@Param("wxEnterpriseId")String wxEnterpriseId, @Param("dIds") List<String> wxDeIds);
} }
\ No newline at end of file
...@@ -57,6 +57,11 @@ public interface TabHaobanStaffClerkRelationMapper { ...@@ -57,6 +57,11 @@ public interface TabHaobanStaffClerkRelationMapper {
List<TabHaobanStaffClerkRelation> listByClerkIds(@Param("clerkIds") List<String> clerkIds); List<TabHaobanStaffClerkRelation> listByClerkIds(@Param("clerkIds") List<String> clerkIds);
List<TabHaobanStaffClerkRelation> listByStoreId(@Param("storeId")String storeId); List<TabHaobanStaffClerkRelation> listByStoreId(@Param("storeId")String storeId);
/**
* 解绑
*/
int cleanStaffDepart( @Param("wxEnterpriseId")String wxEnterpriseId,@Param("staffIds")List<String> staffIds);
} }
\ No newline at end of file
...@@ -64,4 +64,12 @@ public interface DepartmentService { ...@@ -64,4 +64,12 @@ public interface DepartmentService {
*/ */
Integer cleanDepartment(String wxEnterpriseId,List<String> wxDepartmentList); Integer cleanDepartment(String wxEnterpriseId,List<String> wxDepartmentList);
/**
* 清空数据
* @param wxEnterpriseId
* @param wxDepartmentList
* @return
*/
List<DepartmentDTO> listDepartmentByWxDepartIds(String wxEnterpriseId,List<String> wxDepartmentList);
} }
...@@ -45,6 +45,6 @@ public interface StaffClerkRelationService { ...@@ -45,6 +45,6 @@ public interface StaffClerkRelationService {
String insert(StaffClerkRelationDTO staffClerkRelation); String insert(StaffClerkRelationDTO staffClerkRelation);
public int cleanStaffClerk(@Param("wxEnterpriseId") String wxEnterpriseId,@Param("staffIds") List<String> staffIds); public int cleanStaffClerk( String wxEnterpriseId, List<String> staffIds);
} }
...@@ -201,4 +201,9 @@ public class DepartmentServiceImpl implements DepartmentService { ...@@ -201,4 +201,9 @@ public class DepartmentServiceImpl implements DepartmentService {
return mapper.cleanDepartment(wxEnterpriseId,wxDepartmentList); return mapper.cleanDepartment(wxEnterpriseId,wxDepartmentList);
} }
@Override
public List<DepartmentDTO> listDepartmentByWxDepartIds(String wxEnterpriseId, List<String> wxDepartmentList) {
return EntityUtil.changeEntityListByJSON(DepartmentDTO.class, mapper.listDepartmentByWxDepartIds(wxEnterpriseId,wxDepartmentList));
}
} }
...@@ -88,7 +88,6 @@ public class StaffClerkRelationServiceImpl implements StaffClerkRelationService ...@@ -88,7 +88,6 @@ public class StaffClerkRelationServiceImpl implements StaffClerkRelationService
} }
@Override @Override
public int cleanStaffClerk(String wxEnterpriseId, List<String> staffIds) { public int cleanStaffClerk(String wxEnterpriseId, List<String> staffIds) {
// TODO 防报错,先提交下 return mapper.cleanStaffDepart(wxEnterpriseId,staffIds);
return 0;
} }
} }
...@@ -91,6 +91,6 @@ public class StaffDepartmentRelatedServiceImpl implements StaffDepartmentRelated ...@@ -91,6 +91,6 @@ public class StaffDepartmentRelatedServiceImpl implements StaffDepartmentRelated
@Override @Override
public int cleanStaffDepartment(String wxEnterpriseId, List<String> staffIds) { public int cleanStaffDepartment(String wxEnterpriseId, List<String> staffIds) {
return 0; return mapper.cleanStaffDepartment(wxEnterpriseId,staffIds);
} }
} }
...@@ -2,13 +2,7 @@ package com.gic.haoban.manage.service.service.out.impl; ...@@ -2,13 +2,7 @@ package com.gic.haoban.manage.service.service.out.impl;
import java.io.InputStream; import java.io.InputStream;
import java.net.URL; import java.net.URL;
import java.util.ArrayList; import java.util.*;
import java.util.Collections;
import java.util.Date;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors; import java.util.stream.Collectors;
...@@ -17,9 +11,11 @@ import com.gic.commons.util.GlobalInfo; ...@@ -17,9 +11,11 @@ import com.gic.commons.util.GlobalInfo;
import com.gic.commons.util.GlobalVar; import com.gic.commons.util.GlobalVar;
import com.gic.haoban.manage.api.dto.*; import com.gic.haoban.manage.api.dto.*;
import com.gic.haoban.manage.api.service.DepartmentApiService; import com.gic.haoban.manage.api.service.DepartmentApiService;
import com.gic.haoban.manage.service.service.*;
import com.gic.redis.data.anno.RedisCache; import com.gic.redis.data.anno.RedisCache;
import com.gic.thirdparty.api.dto.PicUploadResDTO; import com.gic.thirdparty.api.dto.PicUploadResDTO;
import com.gic.thirdparty.api.service.QQCloudPicService; import com.gic.thirdparty.api.service.QQCloudPicService;
import com.google.common.collect.Sets;
import com.vdurmont.emoji.EmojiParser; import com.vdurmont.emoji.EmojiParser;
import org.apache.commons.collections.CollectionUtils; import org.apache.commons.collections.CollectionUtils;
...@@ -56,12 +52,6 @@ import com.gic.haoban.manage.service.entity.TabHaobanDepartment; ...@@ -56,12 +52,6 @@ import com.gic.haoban.manage.service.entity.TabHaobanDepartment;
import com.gic.haoban.manage.service.entity.TabHaobanStaff; import com.gic.haoban.manage.service.entity.TabHaobanStaff;
import com.gic.haoban.manage.service.entity.TabHaobanStaffDepartmentRelated; import com.gic.haoban.manage.service.entity.TabHaobanStaffDepartmentRelated;
import com.gic.haoban.manage.service.entity.TabHaobanSyncErrorLog; import com.gic.haoban.manage.service.entity.TabHaobanSyncErrorLog;
import com.gic.haoban.manage.service.service.DepartmentService;
import com.gic.haoban.manage.service.service.StaffDepartmentRelatedService;
import com.gic.haoban.manage.service.service.StaffService;
import com.gic.haoban.manage.service.service.SyncErrorLogService;
import com.gic.haoban.manage.service.service.UserLoginLogService;
import com.gic.haoban.manage.service.service.WxEnterpriseService;
import com.gic.redis.data.util.RedisUtil; import com.gic.redis.data.util.RedisUtil;
import com.gic.wechat.api.dto.qywx.UserDTO; import com.gic.wechat.api.dto.qywx.UserDTO;
import com.gic.wechat.api.service.qywx.QywxUserApiService; import com.gic.wechat.api.service.qywx.QywxUserApiService;
...@@ -107,6 +97,9 @@ public class StaffApiServiceImpl implements StaffApiService { ...@@ -107,6 +97,9 @@ public class StaffApiServiceImpl implements StaffApiService {
@Autowired @Autowired
private QQCloudPicService qqCloudPicService; private QQCloudPicService qqCloudPicService;
@Autowired
private StaffClerkRelationService staffClerkRelationService;
@Override @Override
public StaffDTO selectById(String staffId) { public StaffDTO selectById(String staffId) {
...@@ -310,7 +303,121 @@ public class StaffApiServiceImpl implements StaffApiService { ...@@ -310,7 +303,121 @@ public class StaffApiServiceImpl implements StaffApiService {
} }
@Override @Override
public void wxGetAdd(String userId,String wxEnterpriseId) { public ServiceResponse getWxSaveNew(String userId, String wxEnterpriseId) {
ServiceResponse res=new ServiceResponse();
WxEnterpriseDTO enterpriseDTO = wxEnterpriseService.selectById(wxEnterpriseId);
if (null == enterpriseDTO) {
logger.info("企业不存在:{}:{}",wxEnterpriseId,userId);
res.setMessage("企业不存在");
res.setCode(2);
return res;
}
UserDTO user = qywxUserApiService.getSelfWorkWxUser(enterpriseDTO.getCorpid(), enterpriseDTO.getContactSecret(), userId);
if (null == user) {
logger.info("企业微信用户不存在:{}:{}",wxEnterpriseId,userId);
res.setMessage("企业微信用户不存在");
res.setCode(3);
return res;
}
TabHaobanStaff staff = staffService.selectByUserIdAndEnterpriseId(userId,wxEnterpriseId);
if(staff == null) {
logger.info("新增成员");
staff = new TabHaobanStaff();
staff.setWxUserId(userId);
staff.setCreateTime(new Date());
staff.setUpdateTime(new Date());
staff.setStatusFlag(1);
staff.setWxEnterpriseId(wxEnterpriseId);
if(StringUtils.isNotBlank(user.getAvatar())){
staff.setHeadImg(changeHeaderImageUrl(user.getAvatar()));
}
staff.setPhoneNumber(user.getMobile());
if (StringUtils.isNotBlank(user.getName())) {
user.setName(EmojiParser.removeAllEmojis(user.getName()));
staff.setStaffName((user.getName()));
}
if (StringUtils.isNotBlank(user.getAlias())) {
user.setAlias(EmojiParser.removeAllEmojis(user.getAlias()));
staff.setNickName((user.getAlias()));
}
staff.setNationCode("86");
staff.setSex(user.getGender() == null ? 1:Integer.parseInt(user.getGender()));
staff.setActiveFlag(1);
staff.setPostion(user.getPosition());
staff.setExtendPostion(user.getExternal_position());
staff.setActiveFlag(0);
String staffId = staffService.add(staff);
}
logger.info("门店变更保存:{}",JSONObject.toJSONString(user));
staffDepartChange(staff,wxEnterpriseId,user);
return res;
}
private void staffDepartChange(TabHaobanStaff staff,String wxEnterpriseId,UserDTO user){
//更新部门
Integer[] departmentIds = user.getDepartment();
List<String> wxDepartIds=new ArrayList<>();
for (Integer wDId:departmentIds) {
wxDepartIds.add(wDId.toString());
}
//关联部门
List<DepartmentDTO> departmentDTOList = departmentService.listDepartmentByWxDepartIds(wxEnterpriseId, wxDepartIds);
if (CollectionUtils.isEmpty(departmentDTOList)) {
logger.info("部门没有更新或同步:{}",wxEnterpriseId);
return ;
}
//已存在部门
List<TabHaobanStaffDepartmentRelated> hasRelation = staffDepartmentRelatedService.listStaffDepartmentByStaffId(staff.getStaffId());
Map<String,TabHaobanStaffDepartmentRelated> hasRelationMap=new HashMap<>();
if (CollectionUtils.isNotEmpty(hasRelation)) {
hasRelationMap = hasRelation.stream().collect(Collectors.toMap(TabHaobanStaffDepartmentRelated::getDepartmentId, tab -> tab));
}
Map<String, TabHaobanStaffDepartmentRelated> finalHasRelationMap = hasRelationMap;
TabHaobanStaff finalStaff = staff;
//新增操作
departmentDTOList.forEach(departmentDTO -> {
if (!finalHasRelationMap.containsKey(departmentDTO.getDepartmentId())) {
StaffDepartmentRelatedDTO dto = new StaffDepartmentRelatedDTO();
dto.setPhoneNumber(user.getMobile());
dto.setWxUserId(user.getUserid());
dto.setStaffId(finalStaff.getStaffId());
dto.setStaffName(user.getName());
dto.setWxEnterpriseId(wxEnterpriseId);
dto.setStatusFlag(1);
dto.setDepartmentId(departmentDTO.getDepartmentId());
dto.setNationCode("86");
dto.setStaffName(user.getName());
staffDepartmentRelatedService.add(dto);
}
});
//删除操作
Set<String> newDepartIds = departmentDTOList.stream().map(DepartmentDTO::getDepartmentId).collect(Collectors.toSet());
Set<String> hasDepartIds = hasRelationMap.keySet();
Sets.SetView<String> delDepartIds = Sets.difference(hasDepartIds, newDepartIds);
logger.info("删除部门:{}",JSONObject.toJSONString(delDepartIds));
if (!delDepartIds.isEmpty()) {
delDepartIds.forEach(delDepartId->{
TabHaobanStaffDepartmentRelated departmentRelated = finalHasRelationMap.get(delDepartId);
if (null != departmentRelated) {
StaffDepartmentRelatedDTO relatedDTO = new StaffDepartmentRelatedDTO();
relatedDTO.setStaffDepartmentRelatedId(departmentRelated.getStaffDepartmentRelatedId());
staffDepartmentRelatedService.del(relatedDTO);
}
});
}
}
@Override
public void wxGetAdd(String userId,String wxEnterpriseId){
ServiceResponse wxSaveNew = getWxSaveNew(userId, wxEnterpriseId);
logger.info("信息:{}",JSONObject.toJSONString(wxSaveNew));
}
@Deprecated
public void wxGetAddOld(String userId,String wxEnterpriseId) {
//获取微信用户信息 //获取微信用户信息
TabHaobanStaff staff = staffService.selectByUserIdAndEnterpriseId(userId,wxEnterpriseId); TabHaobanStaff staff = staffService.selectByUserIdAndEnterpriseId(userId,wxEnterpriseId);
...@@ -561,9 +668,9 @@ public class StaffApiServiceImpl implements StaffApiService { ...@@ -561,9 +668,9 @@ public class StaffApiServiceImpl implements StaffApiService {
logger.info("【员工修改删除】tab1.getDepartmentId()={}",tab1.getDepartmentId()); logger.info("【员工修改删除】tab1.getDepartmentId()={}",tab1.getDepartmentId());
StaffDepartmentRelatedDTO related = EntityUtil.changeEntityByJSON(StaffDepartmentRelatedDTO.class, tab1); StaffDepartmentRelatedDTO related = EntityUtil.changeEntityByJSON(StaffDepartmentRelatedDTO.class, tab1);
staffDepartmentRelatedService.del(related); staffDepartmentRelatedService.del(related);
if(org.apache.commons.lang3.StringUtils.isNotBlank(tab1.getClerkCode())){ // if(org.apache.commons.lang3.StringUtils.isNotBlank(tab1.getClerkCode())){
cleanGicClerk(tab1.getClerkCode(), tab1.getDepartmentId()); // cleanGicClerk(tab1.getClerkCode(), tab1.getDepartmentId());
} // }
} }
} }
......
...@@ -512,4 +512,15 @@ ...@@ -512,4 +512,15 @@
#{item} #{item}
</foreach> </foreach>
</update> </update>
<select id="listDepartmentByWxDepartIds" resultMap="BaseResultMap" >
select
<include refid="Base_Column_List" />
from tab_haoban_department
where wx_enterprise_id = #{wxEnterpriseId} and status_flag = 1 and
wx_department_id in
<foreach collection="dIds" item="item" open="(" separator="," close=")">
#{item}
</foreach>
</select>
</mapper> </mapper>
\ No newline at end of file
...@@ -343,14 +343,13 @@ ...@@ -343,14 +343,13 @@
<update id="cleanStaff" parameterType="com.gic.haoban.manage.service.entity.TabHaobanStaff" > <update id="cleanStaff" parameterType="com.gic.haoban.manage.service.entity.TabHaobanStaff" >
update tab_haoban_staff update tab_haoban_staff
set wx_user_id = #{wxUserId,jdbcType=VARCHAR}, set
status_flag = 0, status_flag = 0,
update_time = now() update_time = now()
where wx_enterprise_id = #{wxEnterpriseId,jdbcType=VARCHAR} and status_flag = 1 where wx_enterprise_id = #{wxEnterpriseId,jdbcType=VARCHAR} and status_flag = 1
and staff_id not in and staff_id not in
<foreach collection="wxUserIds" item="item" open="(" separator="," close=")"> <foreach collection="staffIds" item="item" open="(" separator="," close=")">
#{item} #{item}
</foreach> </foreach>
</update> </update>
......
...@@ -251,15 +251,27 @@ ...@@ -251,15 +251,27 @@
#{id,jdbcType=VARCHAR} #{id,jdbcType=VARCHAR}
</foreach> </foreach>
</select> </select>
<select id="listByStoreId" resultMap="BaseResultMap" parameterType="java.lang.String" > <select id="listByStoreId" resultMap="BaseResultMap" parameterType="java.lang.String" >
select select
<include refid="Base_Column_List" /> <include refid="Base_Column_List" />
from tab_haoban_staff_clerk_relation from tab_haoban_staff_clerk_relation
where status_flag=1 where status_flag=1
and store_id = #{storeId,jdbcType=VARCHAR} and store_id = #{storeId,jdbcType=VARCHAR}
</select> </select>
<update id="cleanStaffDepart" >
update tab_haoban_staff_clerk_relation
set
status_flag = 0,
update_time = now()
where wx_enterprise_id = #{wxEnterpriseId} and status_flag = 1 and
staff_id not in
<foreach collection="staffIds" item="item" open="(" separator="," close=")">
#{item}
</foreach>
</update>
</mapper> </mapper>
\ No newline at end of file
...@@ -4,7 +4,9 @@ import com.gic.api.base.commons.JSONResponse; ...@@ -4,7 +4,9 @@ import com.gic.api.base.commons.JSONResponse;
import com.gic.haoban.manage.api.dto.SyncSingleDealDTO; import com.gic.haoban.manage.api.dto.SyncSingleDealDTO;
import com.gic.haoban.manage.api.service.DealSyncOperationApiService; import com.gic.haoban.manage.api.service.DealSyncOperationApiService;
import com.gic.haoban.manage.api.service.DepartmentApiService; import com.gic.haoban.manage.api.service.DepartmentApiService;
import com.gic.haoban.manage.api.service.StaffApiService;
import com.gic.haoban.manage.api.service.WxEnterpriseRelatedApiService; import com.gic.haoban.manage.api.service.WxEnterpriseRelatedApiService;
import com.gic.haoban.manage.service.service.StaffService;
import com.gic.wechat.api.dto.qywx.DepartmentDTO; import com.gic.wechat.api.dto.qywx.DepartmentDTO;
import com.gic.wechat.api.dto.qywx.QywxXcxSendMessageDTO; import com.gic.wechat.api.dto.qywx.QywxXcxSendMessageDTO;
import com.gic.wechat.api.dto.qywx.UserDTO; import com.gic.wechat.api.dto.qywx.UserDTO;
...@@ -28,6 +30,9 @@ public class DealSyncTest { ...@@ -28,6 +30,9 @@ public class DealSyncTest {
@Autowired @Autowired
private DealSyncOperationApiService dealSyncOperationApiService; private DealSyncOperationApiService dealSyncOperationApiService;
@Autowired
private StaffApiService staffApiService;
@Test @Test
public void test() { public void test() {
List<SyncSingleDealDTO> add = new ArrayList<>(); List<SyncSingleDealDTO> add = new ArrayList<>();
...@@ -59,8 +64,11 @@ public class DealSyncTest { ...@@ -59,8 +64,11 @@ public class DealSyncTest {
@Test @Test
public void test2() { public void test2() {
dealSyncOperationApiService.cleanDiffrence("ca66a01b79474c40b3e7c7f93daf1a3b", "c582c28a5a1d439b9b7f7e8be18b3ea0"); dealSyncOperationApiService.cleanDiffrence("ca66a01b79474c40b3e7c7f93daf1a3b", "73387b7d355c416f93242f3d71a487a8");
} }
@Test
public void test3() {
staffApiService.getWxSaveNew("3e7a7c09097a40b18aef1478b04688fe", "ca66a01b79474c40b3e7c7f93daf1a3b");
}
} }
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