Commit 77bbc729 by fudahua

门店分组绑定校验

parent 9cbe1780
......@@ -47,7 +47,7 @@ public interface WxEnterpriseRelatedApiService {
* @param channalCode
* @return
*/
public boolean flushBindStoreByEnterpriseId(String enterpriseId, String wxEnterpriseId, String optStaffId, int channalCode);
public ServiceResponse flushBindStoreByEnterpriseId(String enterpriseId, String wxEnterpriseId, String optStaffId, int channalCode);
/**
* 获取企业绑定详情
......
......@@ -38,4 +38,12 @@ public interface WxEnterpriseRelatedMapper {
* @return
*/
TabHaobanWxEnterpriseRelated findOneByEIdAndWxEid(@Param("enterpriseId") String enterpriseId, @Param("wxEnterpriseId") String wxEnterpriseId);
/**
* 查询企业下唯一商户 总部企业
*
* @param enterpriseId
* @return
*/
TabHaobanWxEnterpriseRelated findRootWxEnterpriseByEnterpriseId(@Param("enterpriseId") String enterpriseId);
}
\ No newline at end of file
package com.gic.haoban.manage.service.service.out.impl;
import java.util.*;
import java.util.concurrent.TimeUnit;
import java.util.stream.Collector;
import java.util.stream.Collectors;
......@@ -15,6 +16,7 @@ import com.gic.haoban.common.utils.PageUtil;
import com.gic.haoban.manage.api.dto.*;
import com.gic.haoban.manage.service.entity.*;
import com.gic.haoban.manage.service.service.StoreRangeService;
import com.gic.redis.data.util.RedisUtil;
import com.google.common.collect.Sets;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
......@@ -60,6 +62,8 @@ public class WxEnterpriseRelatedApiServiceImpl implements WxEnterpriseRelatedApi
@Autowired
private StoreService storeService;
private static final String FLUSH_HAOBAN_BIND_STORE = "flush_haoban_bind_store:";
//获取门店详情
public boolean isEnterpriseOver(String eid) {
......@@ -185,6 +189,14 @@ public class WxEnterpriseRelatedApiServiceImpl implements WxEnterpriseRelatedApi
resp.setMessage("部分分组被其它企业绑定了!");
return resp;
}
if (!checkRootEnterprise(detailDTO)) {
logger.info("总部已经被设置不能存在多个总部:{}", JSONObject.toJSONString(detailDTO));
resp.setCode(3);
resp.setMessage("总部已经被设置不能存在多个总部!");
return resp;
}
//校验关联已经企业绑定
TabHaobanWxEnterpriseRelated tab = wxEnterpriseRelatedMapper.findOneByEIdAndWxEid(detailDTO.getEnterpriseId(), detailDTO.getWxEnterpriseId());
if (tab != null && (!tab.getWxEnterpriseRelatedId().equals(detailDTO.getWxEnterpriseRelatedId()))) {
......@@ -227,6 +239,29 @@ public class WxEnterpriseRelatedApiServiceImpl implements WxEnterpriseRelatedApi
}
/**
* 如果是总部的话 校验是否是自己本身 并且可以执行下去
* 如果是代理 标识可以执行下 如果存在总部且不是保存的不能执行的
*
* @param detailDTO
* @return
*/
private boolean checkRootEnterprise(WxEnterpriseRelationDetailDTO detailDTO) {
if (detailDTO.getWxEnterpriseType() == 1) {
return true;
}
//校验总部
TabHaobanWxEnterpriseRelated tab = wxEnterpriseRelatedMapper.findRootWxEnterpriseByEnterpriseId(detailDTO.getEnterpriseId());
if (tab == null) {
return true;
}
if (detailDTO.getWxEnterpriseRelatedId() != null && tab.getWxEnterpriseRelatedId().equals(detailDTO.getWxEnterpriseRelatedId())) {
return true;
}
return false;
}
/**
* 校验是否包含被其它企业绑定
*
* @param detailDTO
......@@ -249,13 +284,28 @@ public class WxEnterpriseRelatedApiServiceImpl implements WxEnterpriseRelatedApi
}
@Override
public boolean flushBindStoreByEnterpriseId(String enterpriseId, String wxEnterpriseId, String optStaffId, int channalCode) {
public ServiceResponse flushBindStoreByEnterpriseId(String enterpriseId, String wxEnterpriseId, String optStaffId, int channalCode) {
ServiceResponse resp = new ServiceResponse();
String key = FLUSH_HAOBAN_BIND_STORE + enterpriseId;
Object cache = RedisUtil.getCache(key);
if (null != cache) {
logger.info("已经有人在操作刷新,不能同步操作:{},{}", enterpriseId, optStaffId);
resp.setCode(2);
resp.setMessage("有正在执行,不能同时操作");
return resp;
}
RedisUtil.setCache(key, wxEnterpriseId, 120L, TimeUnit.SECONDS);
logger.info("刷新绑定门店:eid:{},staffid:{}", enterpriseId, optStaffId);
List<TabStoreRange> groupInfoDTOS = storeRangeService.queryAllBindRangeByEnterpriseId(enterpriseId);
if (CollectionUtils.isEmpty(groupInfoDTOS)) {
RedisUtil.delCache(key);
logger.info("无需刷新:{}", enterpriseId);
return true;
resp.setCode(3);
resp.setMessage("没有要刷新的数据");
return resp;
}
//根据微信企业分组 wxEnterpriseId->(List)groupId
Map<String, Set<String>> relationMapByWxEid = groupInfoDTOS.stream().filter(tab -> tab.getRelationType() == 1)
.collect(Collectors.groupingBy(tab -> tab.getWxEnterpriseId(), Collectors.mapping(tab -> tab.getRelationId(), Collectors.toSet())));
......@@ -317,7 +367,8 @@ public class WxEnterpriseRelatedApiServiceImpl implements WxEnterpriseRelatedApi
});
storeRangeService.saveStoreRelations(ret, optStaffId, channalCode);
return false;
RedisUtil.delCache(key);
return resp;
}
@Override
......
......@@ -210,4 +210,13 @@
where enterprise_id = #{enterpriseId,jdbcType=VARCHAR}
and status_flag = 1 and wx_enterprise_id=#{wxEnterpriseId}
</select>
<select id="findRootWxEnterpriseByEnterpriseId" resultMap="BaseResultMap">
select
<include refid="Base_Column_List"/>
from tab_haoban_wx_enterprise_related
where enterprise_id = #{enterpriseId,jdbcType=VARCHAR}
and status_flag = 1
and wx_enterprise_type = 0
</select>
</mapper>
\ No newline at end of file
import com.alibaba.fastjson.JSONObject;
import com.gic.api.base.commons.JSONResponse;
import com.gic.commons.util.GICMQClientUtil;
import com.gic.haoban.base.api.common.ServiceResponse;
import com.gic.haoban.manage.api.dto.WxEnterpriseDTO;
import com.gic.haoban.manage.api.enums.ChannelCodeEnum;
import com.gic.haoban.manage.api.service.DepartmentApiService;
import com.gic.haoban.manage.api.service.StaffApiService;
import com.gic.haoban.manage.api.service.TestApiService;
import com.gic.haoban.manage.api.service.WxEnterpriseRelatedApiService;
import com.gic.haoban.manage.service.service.MemberUnionRelatedService;
import com.gic.haoban.manage.service.util.EmojiFilterUtil;
import com.gic.mq.sdk.GicMQClient;
import com.gic.redis.data.util.RedisUtil;
import com.gic.wechat.api.dto.qywx.DepartmentDTO;
import com.gic.wechat.api.dto.qywx.QywxImageExternalMessageDTO;
import com.gic.wechat.api.dto.qywx.QywxXcxSendMessageDTO;
import com.gic.wechat.api.dto.qywx.UserDTO;
import com.gic.wechat.api.enums.QywxMediaTypeEnum;
import com.gic.wechat.api.service.qywx.QywxDepartmentApiService;
import com.gic.wechat.api.service.qywx.QywxSuiteApiService;
import com.gic.wechat.api.service.qywx.QywxUserApiService;
//import com.github.binarywang.java.emoji.EmojiConverter;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import javax.imageio.ImageIO;
import java.awt.image.BufferedImage;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.net.URL;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
//import com.github.binarywang.java.emoji.EmojiConverter;
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = {"classpath:applicationContext-conf.xml"})
public class ServiceTest {
......@@ -73,9 +57,9 @@ public class ServiceTest {
@Test
public void test11() {
boolean b = wxEnterpriseRelatedApiService.flushBindStoreByEnterpriseId("ff8080815dacd3a2015dacd3ef5c0000"
ServiceResponse response = wxEnterpriseRelatedApiService.flushBindStoreByEnterpriseId("ff8080815dacd3a2015dacd3ef5c0000"
, "ca66a01b79474c40b3e7c7f93daf1a3b", "-1", ChannelCodeEnum.SYNC_UNBIND.getCode());
System.out.println(b);
System.out.println(JSONObject.toJSONString(response));
}
......
......@@ -166,7 +166,7 @@ public class WxEnterpriseController extends WebBaseController{
@IgnoreLogin
@RequestMapping("wx-enterprise-bind")
public HaobanResponse wxEnterpriseBind(WxEnterpriseBindQo bindQo) {
if (org.apache.commons.lang3.StringUtils.isAnyBlank(bindQo.getEnterpriseId(), bindQo.getVersion())) {
if (StringUtils.isAnyBlank(bindQo.getEnterpriseId(), bindQo.getVersion())) {
return resultResponse(HaoBanErrCode.ERR_2);
}
LoginVO login = (LoginVO) AuthRequestUtil.getLoginUser();
......@@ -623,7 +623,12 @@ public class WxEnterpriseController extends WebBaseController{
public HaobanResponse flushBindStoreList(String enterpriseId) {
LoginVO login = (LoginVO) AuthRequestUtil.getLoginUser();
String wxEnterpriseId = login.getWxEnterpriseId();
wxEnterpriseRelatedApiService.flushBindStoreByEnterpriseId(enterpriseId, wxEnterpriseId, login.getStaffDTO().getStaffId(), ChannelCodeEnum.SYNC_UNBIND.getCode());
ServiceResponse response = wxEnterpriseRelatedApiService.flushBindStoreByEnterpriseId(enterpriseId, wxEnterpriseId, login.getStaffDTO().getStaffId(), ChannelCodeEnum.SYNC_UNBIND.getCode());
logger.info("返回信息:{}", JSONObject.toJSONString(response));
if (response.getCode() != 1) {
HaoBanErrCode.ERR_DEFINE.setMsg(response.getMessage());
return resultResponse(HaoBanErrCode.ERR_DEFINE);
}
return resultResponse(HaoBanErrCode.ERR_1);
}
......
......@@ -182,11 +182,13 @@ public class InfoController extends WebBaseController{
@RequestMapping("get-user-by-member-code")
public HaobanResponse getInfoByMemberCode(GetUserByMemberCodeQo qo) {
//todo 销售线索 获取当前wxEnterpriseId
EnterpriseDetailDTO enterpriseDetailDTO = wxEnterpriseRelatedApiService.getByEnterpriseId(qo.getGicEnterpriseId());
if (enterpriseDetailDTO == null) {
List<WxEnterpriseDTO> wxEnterpriseDTOS = wxEnterpriseRelatedApiService.listWxEnterpriseByEid(qo.getGicEnterpriseId());
if (CollectionUtils.isEmpty(wxEnterpriseDTOS)) {
logger.info("改企业没有关系好办:{}", qo.getGicEnterpriseId());
return resultResponse(HaoBanErrCode.ERR_500001);
}
WxEnterpriseDTO enterpriseDetailDTO = wxEnterpriseDTOS.get(0);
WxEnterpriseDTO enterpriseDTO = wxEnterpriseApiService.getOne(enterpriseDetailDTO.getWxEnterpriseId());
if (enterpriseDTO == null) {
......@@ -206,6 +208,7 @@ public class InfoController extends WebBaseController{
if (user == null) {
return resultResponse(HaoBanErrCode.ERR_6);
}
} else {
user.setUserId(qo.getUserId());
}
......@@ -220,14 +223,12 @@ public class InfoController extends WebBaseController{
relatedDTO.setOpenId(qo.getOpenid());
relatedDTO.setStaffId(staffDTO.getStaffId());
relatedDTO.setWxEnterpriseId(enterpriseDTO.getWxEnterpriseId());
relatedDTO.setGicEnterpriseId(enterpriseDetailDTO.getEnterpriseId());
relatedDTO.setGicEnterpriseId(qo.getGicEnterpriseId());
staffMemberRelationApiService.bindMemberAndStaff(relatedDTO);
List<StaffClerkInfoDTO> result = staffClerkRelationApiService.listBindDetailByStaffId(staffDTO.getStaffId());
// ServiceResponse<List<DepartmentDTO>> response = departmentApiService.listStoreListByStaffId(staffDTO.getStaffId());
// List<DepartmentDTO> result = response.getResult();
List<StoreMemberVO> retList = new ArrayList<>();
if (CollectionUtils.isNotEmpty(result)) {
result.stream().filter(staffClerkInfoDTO -> {
......@@ -255,65 +256,7 @@ public class InfoController extends WebBaseController{
retList.add(VO);
}
// VO.setDepartmentId(dto.getDepartmentId());
});
// //塞clerkCOde等基本信息
// List<StaffDepartmentRelatedDTO> relateList = staffDepartmentRelatedApiService.listByStaffId(staffDTO.getStaffId());
// Map<String,StaffDepartmentRelatedDTO> map = com.gic.commons.util.CollectionUtil.toMap(relateList, "departmentId");
// for(StoreVO VO : retList){
// StaffDepartmentRelatedDTO staffDepartmentRelatedDTO = map.get(VO.getDepartmentId());
// if(staffDepartmentRelatedDTO != null){
// String clerkCode = staffDepartmentRelatedDTO.getClerkCode();
// VO.setBindFlag(StringUtils.isEmpty(clerkCode)?0:1);
// VO.setClerkCode(clerkCode);
// VO.setStaffDepartmentRelatedId(staffDepartmentRelatedDTO.getStaffDepartmentRelatedId());
// VO.setStaffId(staffDTO.getStaffId());
// ClerkDTO clerkDTO = clerkService.getClerkByClerkCode(VO.getEnterpriseId(), clerkCode);
// VO.setClerkId(clerkDTO == null?"":clerkDTO.getClerkId());
// }else{
// VO.setBindFlag(0);
// }
// }
//
//
// //塞门店店长标志
// ClerkMainStoreRelatedDTO mainStore = clerkMainStoreRelatedApiService.getWxEnterpriseIdAndStaffId(enterpriseDTO.getWxEnterpriseId(),staffDTO.getStaffId());
// for(StoreVO VO : retList){
// //查gic门店
// StoreDTO storeDTO = storeService.getStore(VO.getStoreId());
// List<StorePhotoDTO> imgList = storeService.getStoreImages(VO.getStoreId());
// EnterpriseDetailDTO detail = wxEnterpriseRelatedApiService.getByEnterpriseId(storeDTO.getEnterpriseId());
// VO.setWxEnterpriseRelatedId(detail.getWxEnterpriseRelatedId());
// //已经绑定的门店
// if(VO.getBindFlag()==1){
// String clerkCode = VO.getClerkCode();
// if(StringUtils.isEmpty(clerkCode)){
// VO.setClerkType(0);
// }else{
// if(storeDTO != null){
// //查gic门店店长
// ClerkDTO clerkDTO = clerkService.getClerkByClerkId(storeDTO.getClerkId());
// if(clerkDTO != null){
// //code相同,则置为1
// if(clerkCode.equals(clerkDTO.getClerkCode())){
// VO.setClerkType(1);
// }
// }
// }
// }
// }
// if(CollectionUtil.isNotEmpty(imgList)){
// VO.setStoreImg(imgList.get(0).getQcloudImageUrl());;
// }
//
// if(mainStore != null && mainStore.getStoreId().equals(VO.getStoreId())){
// VO.setMainStoreFlag(1);
// }else{
// VO.setMainStoreFlag(0);
// }
// }
user.setStoreList(retList);
}
return resultResponse(HaoBanErrCode.ERR_1, user);
......
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