Commit d364f6b8 by 徐高华

活码批量更新

parent cd37346a
package com.gic.haoban.manage.api.dto.hm;
import java.io.Serializable;
import java.util.List;
public class HmBatchCountDTO implements Serializable{
/**
* @Fields serialVersionUID : TODO(用一句话描述这个变量表示什么)
*/
private static final long serialVersionUID = 4873701412965622239L;
private int taskStatus ;
private String taskId ;
private int totalCount ;
private int successCount ;
private int failount ;
private List<HmBatchModifyResultDTO> failList ;
public int getTaskStatus() {
return taskStatus;
}
public void setTaskStatus(int taskStatus) {
this.taskStatus = taskStatus;
}
public String getTaskId() {
return taskId;
}
public int getTotalCount() {
return totalCount;
}
public int getSuccessCount() {
return successCount;
}
public int getFailount() {
return failount;
}
public List<HmBatchModifyResultDTO> getFailList() {
return failList;
}
public void setTaskId(String taskId) {
this.taskId = taskId;
}
public void setTotalCount(int totalCount) {
this.totalCount = totalCount;
}
public void setSuccessCount(int successCount) {
this.successCount = successCount;
}
public void setFailount(int failount) {
this.failount = failount;
}
public void setFailList(List<HmBatchModifyResultDTO> failList) {
this.failList = failList;
}
}
\ No newline at end of file
package com.gic.haoban.manage.api.dto.hm;
import java.io.Serializable;
public class HmBatchModifyResultDTO implements Serializable{
/**
* @Fields serialVersionUID : TODO(用一句话描述这个变量表示什么)
*/
private static final long serialVersionUID = 5984478063344522210L;
private Long hmid;
private String hmCode ;
private String hmName;
private int errcode;
private String message;
public HmBatchModifyResultDTO(Long hmid, int errcode, String message) {
super();
this.hmid = hmid;
this.errcode = errcode;
this.message = message;
}
public String getHmCode() {
return hmCode;
}
public void setHmCode(String hmCode) {
this.hmCode = hmCode;
}
public Long getHmid() {
return hmid;
}
public String getHmName() {
return hmName;
}
public int getErrcode() {
return errcode;
}
public String getMessage() {
return message;
}
public void setHmid(Long hmid) {
this.hmid = hmid;
}
public void setHmName(String hmName) {
this.hmName = hmName;
}
public void setErrcode(int errcode) {
this.errcode = errcode;
}
public void setMessage(String message) {
this.message = message;
}
}
package com.gic.haoban.manage.api.dto.qdto.hm;
import java.io.Serializable;
import java.util.List;
/**
*
* @ClassName: HmBatchModifyQO
* @Description: 活码批量修改成员
* @author xugh
* @date 2023年5月15日 上午10:25:42
*
*/
public class HmBatchModifyQDTO implements Serializable {
/**
* @Fields serialVersionUID : TODO(用一句话描述这个变量表示什么)
*/
private static final long serialVersionUID = 551906331625487555L;
private String wxEnterpriseId;
private String enterpriseId ;
private String optClerkId;
private String optName;
private List<Long> hmIdList;
// 1新增 2删除
private int optType;
private List<String> clerkIdList;
// 1 继续执行更新 2不废弃活码
private int updateType;
public String getEnterpriseId() {
return enterpriseId;
}
public void setEnterpriseId(String enterpriseId) {
this.enterpriseId = enterpriseId;
}
public int getUpdateType() {
return updateType;
}
public void setUpdateType(int updateType) {
this.updateType = updateType;
}
public String getWxEnterpriseId() {
return wxEnterpriseId;
}
public String getOptName() {
return optName;
}
public List<Long> getHmIdList() {
return hmIdList;
}
public int getOptType() {
return optType;
}
public void setWxEnterpriseId(String wxEnterpriseId) {
this.wxEnterpriseId = wxEnterpriseId;
}
public void setOptName(String optName) {
this.optName = optName;
}
public void setHmIdList(List<Long> hmIdList) {
this.hmIdList = hmIdList;
}
public void setOptType(int optType) {
this.optType = optType;
}
public List<String> getClerkIdList() {
return clerkIdList;
}
public void setClerkIdList(List<String> clerkIdList) {
this.clerkIdList = clerkIdList;
}
public String getOptClerkId() {
return optClerkId;
}
public void setOptClerkId(String optClerkId) {
this.optClerkId = optClerkId;
}
}
......@@ -13,7 +13,8 @@ public enum PreDealTypeEnum {
friend(8, "第三方好友"),
friend_merge(9, "好友数据合并"),
tag(10, "标签"),
tag_member(11, "会员标签");
tag_member(11, "会员标签"),
modify_hm(20,"批量修改活码") ;
private int val;
private String name;
......
......@@ -16,7 +16,9 @@ public enum SyncTaskStatusEnum {
friend_sync(9),
merge_friend_sync(10),
tag(10),
member_tag(10);
member_tag(10) ,
modify_hm(21) ;
private int val;
......
......@@ -8,7 +8,8 @@ public enum SyncTaskTypeEnum {
FRIEND_SINGLE(4, "单个成员刷新好友"),
FRIEND_STORE(5, "刷新门店好友"),
MEMBER_TAG(6, "企业微信标签刷新"),
FRIEND_WX_ENTEPRISE(10, "企业好友初始化");
FRIEND_WX_ENTEPRISE(10, "企业好友初始化"),
BATCH_MODIFY_HM(20, "企微多人活码增加/剔除关联账号");
private int type;
private String taskName;
......
package com.gic.haoban.manage.api.service.hm;
import java.util.List;
import com.gic.api.base.commons.ServiceResponse;
import com.gic.haoban.base.api.common.pojo.dto.WebLoginDTO;
import com.gic.haoban.manage.api.dto.hm.HmBatchCountDTO;
import com.gic.haoban.manage.api.dto.hm.HmBatchModifyResultDTO;
import com.gic.haoban.manage.api.dto.hm.HmQrcodeDTO;
import com.gic.haoban.manage.api.dto.hm.HmQrcodeStoreDTO;
import com.gic.haoban.manage.api.dto.qdto.hm.HmBatchModifyQDTO;
import com.gic.haoban.manage.api.dto.qdto.hm.HmQrcodeListQDTO;
import com.gic.haoban.manage.api.dto.qdto.hm.HmQrcodeQDTO;
import java.util.List;
/**
* @author mozhu
* @date 2022/7/5 09:33
......@@ -55,6 +58,17 @@ public interface HmQrcodeApiService {
* @date 2022-07-05 10:59:06
*/
ServiceResponse update(HmQrcodeQDTO hmQrcodeQDTO);
/**
*
* @Title: batchModifyHm
* @Description: 批量更新多人活码
* @author xugh
* @param qdto
* @return
* @throws
*/
public ServiceResponse batchUpdateHm(HmQrcodeQDTO qdto) ;
/**
* 查询详情
......@@ -178,5 +192,9 @@ public interface HmQrcodeApiService {
ServiceResponse<List<String>> listHasQrcodeClerk(String enterpriseId, List<String> clerkIdList);
ServiceResponse<String> getClerkQrcode(String enterpriseId , String clerkId) ;
ServiceResponse<List<HmBatchModifyResultDTO>> batchModify(HmBatchModifyQDTO qdto) ;
ServiceResponse<HmBatchCountDTO> getModifyResult(String wxEnterpriseId , String taskId) ;
}
package com.gic.haoban.manage.service.dao.mapper;
import com.gic.haoban.manage.api.dto.SyncCheckDTO;
import com.gic.haoban.manage.service.entity.TabHaobanPreDealLog;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
......@@ -115,6 +114,10 @@ public interface PreDealLogMapper {
* @return
*/
public List<TabHaobanPreDealLog> listRebuildDepartByTaskId(@Param("taskId") String taskId);
public List<TabHaobanPreDealLog> listAllByTaskId(@Param("taskId") String taskId);
/**
* 统计重试任务数量
......
......@@ -37,4 +37,6 @@ public interface SyncTaskMapper {
List<TabHaobanSyncTask> listPageByWxEid(String wxEnterpriseId);
List<TabHaobanSyncTask> listTaskByType(@Param("taskType")int taskType);
TabHaobanSyncTask getSyncNewestTask(@Param("wxEnterpriseId")String wxEnterpriseId, @Param("taskType")int taskType);
}
\ No newline at end of file
......@@ -86,6 +86,8 @@ public interface TabHaobanHmClerkRelationMapper {
* @date 2022-07-13 17:04:38
*/
List<TabHaobanHmClerkRelation> getHmClerkByHmId(@Param("hmId") Long hmId);
List<TabHaobanHmClerkRelation> listHmClerkByHmIdList(@Param("hmIdList") List<Long> hmIdList) ;
/**
* 根据hmid 获取导购信息
......
......@@ -23,6 +23,10 @@ public interface TabHaobanHmQrcodeMapper {
* @return 实例对象
*/
TabHaobanHmQrcode queryById(@Param("hmId") Long hmId);
List<TabHaobanHmQrcode> queryByIdList(@Param("hmIds") List<Long> hmIds);
/**
* 新增数据
......
......@@ -36,6 +36,9 @@ public interface SyncTaskService {
* @return
*/
public TabHaobanSyncTask getSyncTask(String taskId);
public TabHaobanSyncTask getSyncNewestTask(String wxEnterpriseId , int taskType);
/**
* 获取任务列表
......
......@@ -2,6 +2,9 @@ package com.gic.haoban.manage.service.service.hm;
import com.gic.api.base.commons.BasePageInfo;
import com.gic.api.base.commons.Page;
import com.gic.api.base.commons.ServiceResponse;
import com.gic.haoban.manage.api.dto.hm.HmBatchModifyResultDTO;
import com.gic.haoban.manage.api.dto.qdto.hm.HmBatchModifyQDTO;
import com.gic.haoban.manage.api.dto.qdto.hm.HmClerkRelationQDTO;
import com.gic.haoban.manage.service.pojo.bo.hm.HmClerkRelationBO;
......@@ -142,5 +145,7 @@ public interface HmClerkRelationService {
* @throws
*/
void updateByClerkChangeStore(String enterpriseId,String oldClerkId,String newClerkId) ;
ServiceResponse<List<HmBatchModifyResultDTO>> batchModify(HmBatchModifyQDTO qdto);
}
package com.gic.haoban.manage.service.service.hm;
import com.gic.api.base.commons.Page;
import com.gic.haoban.manage.api.dto.qdto.hm.HmQrcodeListQDTO;
import com.gic.haoban.manage.api.dto.qdto.hm.HmQrcodeQDTO;
import com.gic.haoban.manage.service.pojo.bo.hm.HmQrcodeBO;
......@@ -9,7 +8,6 @@ import com.gic.haoban.manage.service.pojo.bo.hm.HmQrcodeGroupNumBO;
import java.util.List;
import org.apache.ibatis.annotations.Param;
/**
......
package com.gic.haoban.manage.service.service.hm.impl;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.stream.Collectors;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.gic.api.base.commons.BasePageInfo;
import com.gic.api.base.commons.Page;
import com.gic.api.base.commons.ServiceResponse;
import com.gic.clerk.api.dto.ClerkDTO;
import com.gic.clerk.api.service.ClerkService;
import com.gic.commons.util.GICMQClientUtil;
import com.gic.commons.util.ToolUtil;
import com.gic.enterprise.api.dto.StoreDTO;
import com.gic.enterprise.api.service.StoreService;
import com.gic.haoban.common.utils.EntityUtil;
import com.gic.haoban.common.utils.PageUtil;
import com.gic.haoban.manage.api.dto.DealParamMqDTO;
import com.gic.haoban.manage.api.dto.hm.HmBatchModifyResultDTO;
import com.gic.haoban.manage.api.dto.qdto.hm.HmBatchModifyQDTO;
import com.gic.haoban.manage.api.dto.qdto.hm.HmClerkRelationQDTO;
import com.gic.haoban.manage.api.enums.PreDealTypeEnum;
import com.gic.haoban.manage.api.enums.SyncTaskStatusEnum;
import com.gic.haoban.manage.api.enums.SyncTaskTypeEnum;
import com.gic.haoban.manage.service.dao.mapper.hm.TabHaobanHmClerkRelationMapper;
import com.gic.haoban.manage.service.dao.mapper.hm.TabHaobanHmQrcodeMapper;
import com.gic.haoban.manage.service.entity.TabHaobanPreDealLog;
import com.gic.haoban.manage.service.entity.TabHaobanSyncTask;
import com.gic.haoban.manage.service.entity.hm.TabHaobanHmClerkRelation;
import com.gic.haoban.manage.service.entity.hm.TabHaobanHmQrcode;
import com.gic.haoban.manage.service.pojo.bo.hm.HmClerkRelationBO;
import com.gic.haoban.manage.service.service.PreDealService;
import com.gic.haoban.manage.service.service.SyncTaskService;
import com.gic.haoban.manage.service.service.hm.HmClerkRelationService;
import com.gic.mq.sdk.GicMQClient;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
......@@ -31,12 +59,19 @@ import com.github.pagehelper.PageInfo;
@Service
public class HmClerkRelationServiceImpl implements HmClerkRelationService {
private static final Logger log = LoggerFactory.getLogger(HmClerkRelationService.class);
@Autowired
private TabHaobanHmClerkRelationMapper tabHaobanHmClerkRelationMapper;
@Autowired
private TabHaobanHmQrcodeMapper hmQrcodeMapper;
@Autowired
private ClerkService clerkService ;
@Autowired
private StoreService storeService ;
@Autowired
private SyncTaskService syncTaskService;
@Autowired
private PreDealService preDealService;
@Override
......@@ -112,4 +147,127 @@ public class HmClerkRelationServiceImpl implements HmClerkRelationService {
String storeName = newStore.getStoreName() ;
this.tabHaobanHmClerkRelationMapper.updateByClerkChangeStore(enterpriseId,newClerkId,clerkCode,clerkName,storeId, storeCode,storeName, oldClerkId) ;
}
@Override
public ServiceResponse<List<HmBatchModifyResultDTO>> batchModify(HmBatchModifyQDTO qdto) {
List<Long> hmIdList = qdto.getHmIdList() ;
String enterpriseId = qdto.getEnterpriseId() ;
List<TabHaobanHmClerkRelation> list = this.tabHaobanHmClerkRelationMapper.listHmClerkByHmIdList(hmIdList) ;
log.info("查询活码数量={},{}",list.size(),hmIdList.size());
Map<Long,List<TabHaobanHmClerkRelation>> map = list.stream().collect(Collectors.groupingBy(TabHaobanHmClerkRelation::getHmId));
Map<Long , Set<String>> modifyMap = new HashMap<>();
List<HmBatchModifyResultDTO> errList = new ArrayList<>() ;
for(Long hmId : hmIdList) {
List<TabHaobanHmClerkRelation> staffRelationList = map.get(hmId) ;
if (CollectionUtils.isEmpty(staffRelationList)) {
log.info("活码不存在={}",hmId);
continue;
}
Set<String> staffIdSet = staffRelationList.stream().map(o->o.getStaffId()).collect(Collectors.toSet()) ;
if(CollectionUtils.isNotEmpty(staffRelationList)) {
Set<String> staffIdSetBak = new HashSet<>();
staffIdSetBak.addAll(staffIdSet) ;
List<String> modifyIdList = qdto.getClerkIdList();
// add
if(qdto.getOptType()==1) {
staffIdSetBak.addAll(modifyIdList) ;
if(staffIdSetBak.size()>100) {
HmBatchModifyResultDTO err = new HmBatchModifyResultDTO(hmId,1,"超出多人活码成员数上限,最多支持添加100个成员") ;
errList.add(err) ;
}
}
// 减
if(qdto.getOptType()==2) {
staffIdSetBak.removeAll(modifyIdList);
if(staffIdSetBak.size()<=0) {
HmBatchModifyResultDTO err = new HmBatchModifyResultDTO(hmId,2,"成员数为0") ;
errList.add(err) ;
}
}
// 1 继续执行更新 2不废弃活码
if(qdto.getUpdateType()==2 && staffIdSetBak.size()==0) {
log.info("无人活码={}",hmId);
continue ;
}
if(staffIdSet.size()>100) {
log.info("超人数活码={}",hmId);
continue ;
}
if(staffIdSetBak.size() != staffIdSet.size()) {
modifyMap.put(hmId, staffIdSetBak) ;
}
}
}
log.info("异常的活码={}",JSONObject.toJSONString(errList));
if(CollectionUtils.isNotEmpty(errList) && qdto.getUpdateType()==0) {
List<Long> hmidList = errList.stream().map(o->o.getHmid()).collect(Collectors.toList()) ;
List<TabHaobanHmQrcode> qrcodeList = this.hmQrcodeMapper.queryByIdList(hmidList) ;
Map<Long,TabHaobanHmQrcode> qrcodeMap = qrcodeList.stream().collect(Collectors.toMap(TabHaobanHmQrcode::getHmId, o->o)) ;
errList.forEach(o->{
if(null != qrcodeMap.get(o.getHmid())) {
o.setHmCode(qrcodeMap.get(o.getHmid()).getHmCode());
o.setHmName(qrcodeMap.get(o.getHmid()).getName());
}
});
return ServiceResponse.success(errList) ;
}
String wxEnterpriseId = qdto.getWxEnterpriseId() ;
String clerkId = qdto.getOptClerkId() ;
String name = qdto.getOptName() ;
String taskName = "批量修改多人活码";
String taskId = this.createModifyHmTask(wxEnterpriseId, taskName, clerkId,
name, SyncTaskTypeEnum.BATCH_MODIFY_HM.getType());
if (StringUtils.isBlank(taskId)) {
return ServiceResponse.failure("9999", "创建任务失败") ;
}
List<TabHaobanPreDealLog> dealLogList = modifyMap.keySet().stream().map(hmid -> {
TabHaobanPreDealLog dealLog = new TabHaobanPreDealLog();
dealLog.setEnterpriseId(enterpriseId);
dealLog.setWxEnterpriseId(wxEnterpriseId);
dealLog.setTaskId(taskId);
dealLog.setDataId(hmid+"") ;
dealLog.setpDataId(hmid+"");
dealLog.setDataContent(JSON.toJSONString(modifyMap.get(hmid)));
dealLog.setDataType(PreDealTypeEnum.modify_hm.getVal());
dealLog.setStatusFlag(0);
return dealLog;
}).collect(Collectors.toList());
this.preDealService.insert(dealLogList);
this.sendToMq(taskId, dealLogList.stream().map(o->o.getDataId()).collect(Collectors.toSet()), SyncTaskStatusEnum.modify_hm);
return ServiceResponse.success() ;
}
private void sendToMq(String taskId, Set<String> dealList, SyncTaskStatusEnum syncTaskStatusEnum) {
//预处理分组任务
syncTaskService.updateTaskStatus(taskId, syncTaskStatusEnum.getVal());
List<String> listRet = dealList.stream().map(relationId -> {
DealParamMqDTO dealParamMqDTO = new DealParamMqDTO();
dealParamMqDTO.setTaskId(taskId);
dealParamMqDTO.setData(relationId);
dealParamMqDTO.setType(syncTaskStatusEnum.getVal());
return JSONObject.toJSONString(dealParamMqDTO);
}).collect(Collectors.toList());
GicMQClient clientInstance = GICMQClientUtil.getClientInstance();
try {
clientInstance.sendBatchMessages("departmentSyncDealMq", listRet, 10);
} catch (Exception e) {
e.printStackTrace();
}
}
public String createModifyHmTask(String wxEnterpriseId, String taskName, String staffId, String staffName, int syncTaskType) {
TabHaobanSyncTask tabHaobanSyncTask = new TabHaobanSyncTask();
tabHaobanSyncTask.setAddUser(staffId);
tabHaobanSyncTask.setTaskName(SyncTaskTypeEnum.getTaskName(syncTaskType));
tabHaobanSyncTask.setTaskDesc(staffName);
tabHaobanSyncTask.setWxEnterpriseId(wxEnterpriseId);
tabHaobanSyncTask.setStatusFlag(SyncTaskStatusEnum.init.getVal());
tabHaobanSyncTask.setTaskId(ToolUtil.randomUUID());
tabHaobanSyncTask.setTaskType(syncTaskType);
syncTaskService.createTask(tabHaobanSyncTask);
return tabHaobanSyncTask.getTaskId();
}
}
......@@ -50,6 +50,11 @@ public class SyncTaskServiceImpl implements SyncTaskService {
public TabHaobanSyncTask getSyncTask(String taskId) {
return syncTaskMapper.selectByPrimaryKey(taskId);
}
@Override
public TabHaobanSyncTask getSyncNewestTask(String wxEnterpriseId, int taskType) {
return syncTaskMapper.getSyncNewestTask(wxEnterpriseId,taskType);
}
@Override
public Page<SyncTaskDTO> listTaskPage(String wxEnterpriseId, BasePageInfo pageInfo) {
......
......@@ -125,7 +125,10 @@ public class DealSyncOperationApiServiceImpl implements DealSyncOperationApiServ
} else if (dataType.equals(PreDealTypeEnum.tag_member.getVal())) {
logger.info("11 会员标签处理标签项:{}", params);
operationMap.get("friendMemberTagSyncOperation").dealSingleByMq(dealParamMqDTO, dataPre);
} else {
} else if(dataType.equals(PreDealTypeEnum.modify_hm.getVal())) {
logger.info("20 活码批量修改");
operationMap.get("qwHmOperation").dealSingleByMq(dealParamMqDTO, dataPre);
}else {
logger.info("不是正常数据类型:{}", params);
}
}
......
......@@ -4,6 +4,7 @@ import java.util.ArrayList;
import java.util.Collections;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors;
......@@ -31,9 +32,12 @@ import com.gic.haoban.base.api.common.pojo.dto.WebLoginDTO;
import com.gic.haoban.manage.api.dto.StaffClerkRelationDTO;
import com.gic.haoban.manage.api.dto.WxEnterpriseDTO;
import com.gic.haoban.manage.api.dto.WxEnterpriseQwDTO;
import com.gic.haoban.manage.api.dto.hm.HmBatchCountDTO;
import com.gic.haoban.manage.api.dto.hm.HmBatchModifyResultDTO;
import com.gic.haoban.manage.api.dto.hm.HmClerkDTO;
import com.gic.haoban.manage.api.dto.hm.HmQrcodeDTO;
import com.gic.haoban.manage.api.dto.hm.HmQrcodeStoreDTO;
import com.gic.haoban.manage.api.dto.qdto.hm.HmBatchModifyQDTO;
import com.gic.haoban.manage.api.dto.qdto.hm.HmClerkRelationQDTO;
import com.gic.haoban.manage.api.dto.qdto.hm.HmQrcodeListQDTO;
import com.gic.haoban.manage.api.dto.qdto.hm.HmQrcodeQDTO;
......@@ -42,7 +46,12 @@ import com.gic.haoban.manage.api.enums.WelcomeRelationStatusEnum;
import com.gic.haoban.manage.api.enums.hm.HmWelcomeReferType;
import com.gic.haoban.manage.api.service.hm.HmQrcodeApiService;
import com.gic.haoban.manage.service.config.Config;
import com.gic.haoban.manage.service.dao.mapper.PreDealLogMapper;
import com.gic.haoban.manage.service.dao.mapper.hm.TabHaobanHmQrcodeMapper;
import com.gic.haoban.manage.service.entity.TabHaobanPreDealLog;
import com.gic.haoban.manage.service.entity.TabHaobanStaff;
import com.gic.haoban.manage.service.entity.TabHaobanSyncTask;
import com.gic.haoban.manage.service.entity.hm.TabHaobanHmQrcode;
import com.gic.haoban.manage.service.pojo.bo.hm.HmClerkRelationBO;
import com.gic.haoban.manage.service.pojo.bo.hm.HmGroupSettingBO;
import com.gic.haoban.manage.service.pojo.bo.hm.HmQrcodeBO;
......@@ -51,6 +60,7 @@ import com.gic.haoban.manage.service.pojo.bo.hm.HmWelcomeRelationBO;
import com.gic.haoban.manage.service.pojo.bo.welcome.WelcomeDetailBO;
import com.gic.haoban.manage.service.service.StaffClerkRelationService;
import com.gic.haoban.manage.service.service.StaffService;
import com.gic.haoban.manage.service.service.SyncTaskService;
import com.gic.haoban.manage.service.service.WelcomeService;
import com.gic.haoban.manage.service.service.WxEnterpriseService;
import com.gic.haoban.manage.service.service.hm.HmClerkRelationService;
......@@ -112,6 +122,12 @@ public class HmQrcodeApiServiceImpl implements HmQrcodeApiService {
private WelcomeService welcomeService;
@Autowired
private RightService rightService;
@Autowired
private SyncTaskService syncTaskService;
@Autowired
private PreDealLogMapper preDealLogMapper ;
@Autowired
private TabHaobanHmQrcodeMapper hmQrcodeMapper;
@GicLogRecord(value = "新增员工活码-${#logContent}",
category = GicLogRecordCategoryEnum.HUOMA,
......@@ -367,6 +383,39 @@ public class HmQrcodeApiServiceImpl implements HmQrcodeApiService {
}
return ServiceResponse.success();
}
public ServiceResponse batchUpdateHm(HmQrcodeQDTO qdto) {
String wxEnterpriseId = qdto.getWxEnterpriseId();
Long hmId = qdto.getHmId();
WxEnterpriseQwDTO qwDTO = this.wxEnterpriseService.getQwInfo(wxEnterpriseId);
HmQrcodeBO hm = hmQrcodeService.queryById(hmId);
List<String> clerkIdList = this.setStoreClerk(qdto, wxEnterpriseId, hmId, hm.getHmType(), false);
if (CollectionUtils.isEmpty(clerkIdList)) {
return ServiceResponse.failure(Convert.toStr(HaoBanErrCodeCommon.ERR_8.getCode()), "该导购已经生成过活码或未关联过好办");
}
//更新活码
QywxExternalcontactDTO qywxExternalcontactDTO = new QywxExternalcontactDTO();
qywxExternalcontactDTO.setType(hm.getHmType());
qywxExternalcontactDTO.setRemark(hm.getName());
qywxExternalcontactDTO.setSkipVerify(hm.getPassFlag() == 1);
qywxExternalcontactDTO.setState("HM" + hmId);
qywxExternalcontactDTO.setConfigId(hm.getWxConfigId());
List<String> userIds = staffClerkRelationService.listWxUserIdByClerkIds(clerkIdList, wxEnterpriseId);
if (CollectionUtils.isEmpty(userIds)) {
return ServiceResponse.failure(Convert.toStr(HaoBanErrCodeCommon.ERR_8.getCode()), "导购未关联好办");
}
qywxExternalcontactDTO.setUser(userIds);
QywxResponseDTO qywxResponseDTO = qywxUserApiService.updateContactWay(qwDTO.getThirdCorpid(), qwDTO.getSelf3thSecret(), qywxExternalcontactDTO,qwDTO.isSelf(),qwDTO.getUrlHost());
if (qywxResponseDTO.getErrcode() != 0) {
logger.error("更新企微活码失败");
GicLogRecordEvaluationContext.noWriteLog();
return ServiceResponse.failure(Convert.toStr(HaoBanErrCodeCommon.ERR_0.getCode()), qywxResponseDTO.getErrmsg());
}
return ServiceResponse.success();
}
/**
* 修改活码操作日志
......@@ -913,4 +962,58 @@ public class HmQrcodeApiServiceImpl implements HmQrcodeApiService {
public com.gic.api.base.commons.ServiceResponse<String> getClerkQrcode(String enterpriseId, String clerkId) {
return ServiceResponse.success(hmQrcodeService.getClerkQrcode(enterpriseId, clerkId));
}
@Override
public ServiceResponse<List<HmBatchModifyResultDTO>> batchModify(HmBatchModifyQDTO qdto) {
logger.info("批量修改活码={}",JSON.toJSONString(qdto));
ServiceResponse<List<HmBatchModifyResultDTO>> resp = this.hmClerkRelationService.batchModify(qdto) ;
return resp;
}
@Override
public ServiceResponse<HmBatchCountDTO> getModifyResult(String wxEnterpriseId, String taskId) {
TabHaobanSyncTask task = null ;
if(StringUtils.isNotEmpty(taskId)) {
task = syncTaskService.getSyncTask(taskId);
}else {
task = this.syncTaskService.getSyncNewestTask(wxEnterpriseId, 20) ;
}
if(null == task) {
return ServiceResponse.failure("9999", "无批量活码处理数据") ;
}
HmBatchCountDTO dto = new HmBatchCountDTO() ;
dto.setTaskStatus(task.getStatusFlag());
dto.setTaskId(task.getTaskId());
if(task.getStatusFlag() != 4) {
return ServiceResponse.success(dto) ;
}
List<TabHaobanPreDealLog> list = this.preDealLogMapper.listAllByTaskId(taskId) ;
dto.setTotalCount(list.size());
int successCount = 0 , failCount = 0 ;
List<HmBatchModifyResultDTO> failList = new ArrayList<>();
for(TabHaobanPreDealLog o : list) {
if(o.getStatusFlag()==2) {
successCount = successCount + 1 ;
}else {
failCount = failCount +1 ;
HmBatchModifyResultDTO err = new HmBatchModifyResultDTO(Long.valueOf(o.getDataId()), 3, o.getReason()) ;
failList.add(err) ;
}
}
dto.setSuccessCount(successCount);
dto.setFailount(failCount);
if(CollectionUtils.isNotEmpty(failList)) {
List<Long> hmidList = failList.stream().map(o->o.getHmid()).collect(Collectors.toList()) ;
List<TabHaobanHmQrcode> qrcodeList = this.hmQrcodeMapper.queryByIdList(hmidList) ;
Map<Long,TabHaobanHmQrcode> qrcodeMap = qrcodeList.stream().collect(Collectors.toMap(TabHaobanHmQrcode::getHmId, o->o)) ;
failList.forEach(o->{
if(null != qrcodeMap.get(o.getHmid())) {
o.setHmCode(qrcodeMap.get(o.getHmid()).getHmCode());
o.setHmName(qrcodeMap.get(o.getHmid()).getName());
}
});
}
dto.setFailList(failList);
return ServiceResponse.success(dto);
}
}
......@@ -278,7 +278,13 @@
AND b.status_flag = 2
)
</select>
<select id="listAllByTaskId" resultMap="BaseResultMap">
select
<include refid="Base_Column_List"/>
from tab_haoban_pre_deal_log
where task_id = #{taskId}
</select>
<select id="listRebuildByTaskId" resultMap="BaseResultMap">
select
......
......@@ -21,6 +21,14 @@
from tab_haoban_sync_task
where task_id = #{taskId,jdbcType=VARCHAR}
</select>
<select id="getSyncNewestTask" resultMap="BaseResultMap">
select
<include refid="Base_Column_List"/>
from tab_haoban_sync_task
where wx_enterprise_id = #{wxEnterpriseId} and task_type = #{taskType} order by create_time desc limit 1
</select>
<delete id="deleteByPrimaryKey" parameterType="java.lang.String">
delete from tab_haoban_sync_task
where task_id = #{taskId,jdbcType=VARCHAR}
......
......@@ -87,6 +87,16 @@
from tab_haoban_hm_clerk_relation
where hm_id = #{hmId} and status = 1
</select>
<select id="listHmClerkByHmIdList" resultMap="TabHaobanHmClerkRelationMap">
select <include refid="Base_Column_List" />
from tab_haoban_hm_clerk_relation
where hm_id in
<foreach item="id" index="index" collection="hmIdList" open="(" separator="," close=")">
#{id}
</foreach>
and status = 1
</select>
<select id="getHmClerkByHmIdAndStaffId" resultMap="TabHaobanHmClerkRelationMap">
select <include refid="Base_Column_List"></include>
......
......@@ -50,7 +50,16 @@
from tab_haoban_hm_qrcode
where hm_id = #{hmId}
</select>
<select id="queryByIdList" resultMap="TabHaobanHmQrcodeMap">
select
<include refid="Base_Column_List"></include>
from tab_haoban_hm_qrcode
where hm_id in
<foreach collection="hmIds" open="(" close=")" separator="," item="hmId">
#{hmId}
</foreach>
</select>
<!--新增所有列-->
<insert id="insert" keyProperty="hmId" useGeneratedKeys="true">
......
package com.gic.haoban.manage.web.controller.hm;
import cn.hutool.core.convert.Convert;
import java.text.ParseException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.TreeSet;
import java.util.stream.Collectors;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.logging.log4j.LogManager;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import com.alibaba.fastjson.JSON;
import com.gic.api.base.commons.BasePageInfo;
import com.gic.api.base.commons.Page;
......@@ -9,8 +27,19 @@ import com.gic.commons.util.EntityUtil;
import com.gic.commons.webapi.reponse.RestResponse;
import com.gic.haoban.base.api.common.pojo.dto.WebLoginDTO;
import com.gic.haoban.common.utils.AuthWebRequestUtil;
import com.gic.haoban.common.utils.HaobanResponse;
import com.gic.haoban.manage.api.constants.StatisticsApolloKeyConstant;
import com.gic.haoban.manage.api.dto.hm.*;
import com.gic.haoban.manage.api.dto.SyncCheckDTO;
import com.gic.haoban.manage.api.dto.hm.HmBatchCountDTO;
import com.gic.haoban.manage.api.dto.hm.HmBatchModifyResultDTO;
import com.gic.haoban.manage.api.dto.hm.HmClerkDTO;
import com.gic.haoban.manage.api.dto.hm.HmClerkRelationDTO;
import com.gic.haoban.manage.api.dto.hm.HmGroupDTO;
import com.gic.haoban.manage.api.dto.hm.HmQrcodeDTO;
import com.gic.haoban.manage.api.dto.hm.HmQrcodeListDTO;
import com.gic.haoban.manage.api.dto.hm.HmStoreDTO;
import com.gic.haoban.manage.api.dto.hm.WxUserAddLogDTO;
import com.gic.haoban.manage.api.dto.qdto.hm.HmBatchModifyQDTO;
import com.gic.haoban.manage.api.dto.qdto.hm.HmQrcodeListQDTO;
import com.gic.haoban.manage.api.dto.qdto.hm.HmQrcodeQDTO;
import com.gic.haoban.manage.api.dto.qdto.hm.WxUserAddLogSearchQDTO;
......@@ -24,6 +53,7 @@ import com.gic.haoban.manage.api.service.hm.WxUserAddLogApiService;
import com.gic.haoban.manage.api.util.DataHttpUtil;
import com.gic.haoban.manage.web.dto.HmOverviewDTO;
import com.gic.haoban.manage.web.errCode.HaoBanErrCode;
import com.gic.haoban.manage.web.qo.hm.HmBatchModifyQO;
import com.gic.haoban.manage.web.qo.hm.HmQrcodeDetailQO;
import com.gic.haoban.manage.web.qo.hm.HmQrcodeUpdateQO;
import com.gic.haoban.manage.web.qo.hm.data.HmDetailClerkListQO;
......@@ -33,18 +63,8 @@ import com.gic.haoban.manage.web.utils.statistics.DataStatisticsParamUtils;
import com.gic.haoban.manage.web.utils.statistics.DateUtils;
import com.gic.haoban.manage.web.vo.hm.HmDetailClerkListVO;
import com.gic.haoban.manage.web.vo.hm.HmTrendVO;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.logging.log4j.LogManager;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import java.text.ParseException;
import java.util.*;
import java.util.stream.Collectors;
import cn.hutool.core.convert.Convert;
/**
* 活码(TabHaobanHmQrcode)表控制层
......@@ -238,6 +258,70 @@ public class HmQrcodeController {
}
return RestResponse.successResult(statisticsDTO);
}
@RequestMapping(value = "get-hm-for-batch", method = RequestMethod.POST)
public RestResponse<Object> getHmFormBatch(@RequestBody HmQrcodeListQO qo) {
List<String> list = this.getHmCount(qo) ;
if(list.size() > 1000) {
return RestResponse.failure("9999", "最多支持1000条数据") ;
}
return RestResponse.successResult(list);
}
@RequestMapping(value = "batch-modify-hm", method = RequestMethod.POST)
public RestResponse<Object> batchModify(@RequestBody HmBatchModifyQO qo) {
HmBatchModifyQDTO qdto = EntityUtil.changeEntityByJSON(HmBatchModifyQDTO.class, qo) ;
WebLoginDTO loginUser = AuthWebRequestUtil.getLoginUser();
qdto.setWxEnterpriseId(loginUser.getWxEnterpriseId());
qdto.setOptClerkId(loginUser.getClerkId());
qdto.setOptName(loginUser.getClerkName());
qdto.setEnterpriseId(loginUser.getEnterpriseId());
ServiceResponse<List<HmBatchModifyResultDTO>> resp = this.hmQrcodeApiService.batchModify(qdto) ;
if(resp.isSuccess()) {
return RestResponse.successResult(resp.getResult()) ;
}
return RestResponse.failure("9999", resp.getMessage()) ;
}
@RequestMapping("hm-sync-check")
public RestResponse<Object> synchmSuccess(String taskId) {
WebLoginDTO login = AuthWebRequestUtil.getLoginUser();
String wxEnterpriseId = login.getWxEnterpriseId();
ServiceResponse<HmBatchCountDTO> resp = this.hmQrcodeApiService.getModifyResult(wxEnterpriseId,taskId);
return RestResponse.successResult(resp.getResult()) ;
}
private List<String> getHmCount(HmQrcodeListQO hmQrcodeListQO) {
WebLoginDTO loginUser = AuthWebRequestUtil.getLoginUser();
hmQrcodeListQO.getInFields().setEnterpriseId(loginUser.getEnterpriseId());
hmQrcodeListQO.getInFields().setWxEnterpriseId(loginUser.getWxEnterpriseId());
List<String> storeList = staffApiService.getHaoBanStoreIdsRolesByClerkId(loginUser.getClerkId(), loginUser.getWxEnterpriseId());
if (CollectionUtils.isEmpty(storeList)) {
return Collections.EMPTY_LIST ;
}
if (!storeList.contains("-1")) {
StringBuffer stringBuffer = new StringBuffer();
storeList.forEach(c -> stringBuffer.append(c).append(","));
hmQrcodeListQO.getInFields().setStoreId(stringBuffer.toString());
}
Long hmGroupId = hmQrcodeListQO.getInFields().getHmGroupId();
//-1 代表全部分组
if (hmGroupId == -1) {
hmQrcodeListQO.getInFields().setHmGroupId(null);
}
HmQrcodeListQDTO qdto = EntityUtil.changeEntityByJSON(HmQrcodeListQDTO.class, hmQrcodeListQO.getInFields());
if (!storeList.contains("-1")) {
qdto.setStoreId(storeList);
}
ServiceResponse<List<String>> listResp = this.hmQrcodeApiService.listHmIdForIndex(qdto);
logger.info("HMid列表={}", JSON.toJSONString(listResp));
List<String> hmIds = listResp.getResult();
if(CollectionUtils.isEmpty(hmIds)) {
return Collections.EMPTY_LIST ;
}
return hmIds ;
}
/**
* 详情
......
package com.gic.haoban.manage.web.qo.hm;
import java.io.Serializable;
import java.util.List;
/**
*
* @ClassName: HmBatchModifyQO
* @Description: 活码批量修改成员
* @author xugh
* @date 2023年5月15日 上午10:25:42
*
*/
public class HmBatchModifyQO implements Serializable {
/**
* @Fields serialVersionUID : TODO(用一句话描述这个变量表示什么)
*/
private static final long serialVersionUID = 551906331625487555L;
private List<String> hmIdList;
// 1新增 2删除
private int optType;
private List<String> clerkIdList;
// 1 继续执行更新 2不废弃活码
private int updateType;
public List<String> getHmIdList() {
return hmIdList;
}
public int getOptType() {
return optType;
}
public void setHmIdList(List<String> hmIdList) {
this.hmIdList = hmIdList;
}
public void setOptType(int optType) {
this.optType = optType;
}
public List<String> getClerkIdList() {
return clerkIdList;
}
public int getUpdateType() {
return updateType;
}
public void setClerkIdList(List<String> clerkIdList) {
this.clerkIdList = clerkIdList;
}
public void setUpdateType(int updateType) {
this.updateType = updateType;
}
}
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