修复客户相关bug;

1 parent 1258e089
......@@ -187,12 +187,16 @@ public class WeGroupCodeController extends BaseController {
}
/**
* 从群活码获取第一个可用的实际码
* 从群活码获取第一个可用的实际码(实际埋点记录扫码次数)
*/
@ApiOperation(value = "从群活码获取第一个可用的实际码", httpMethod = "GET")
@GetMapping("/getActualCode/{groupCodeId}")
public AjaxResult getActual(@PathVariable("groupCodeId") String id) {
WeGroupCode groupCode = groupCodeService.getById(id);
//统计扫码次数
groupCodeService.countScanTimes(groupCode);
List<WeGroupCodeActual> actualCodeList = groupCodeService.selectActualList(groupCode.getId());
WeGroupCodeActual groupCodeActual = null;
for (WeGroupCodeActual item : actualCodeList) {
......
......@@ -7,16 +7,16 @@ import com.linkwechat.common.core.domain.AjaxResult;
import com.linkwechat.common.core.page.TableDataInfo;
import com.linkwechat.wecom.domain.WeGroup;
import com.linkwechat.wecom.domain.WeGroupMember;
import com.linkwechat.wecom.domain.vo.WeMakeGroupTagVo;
import com.linkwechat.wecom.service.IWeGroupMemberService;
import com.linkwechat.wecom.service.IWeGroupService;
import com.linkwechat.wecom.service.IWeGroupTagRelService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.security.core.context.SecurityContext;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.*;
import java.util.List;
......@@ -36,6 +36,10 @@ public class WeGroupController extends BaseController {
@Autowired
private IWeGroupMemberService weGroupMemberService;
@Autowired
private IWeGroupTagRelService iWeGroupTagRelService;
// @PreAuthorize("@ss.hasPermi('customerManage:group:list')")
@GetMapping({"/list"})
public TableDataInfo list(WeGroup weGroup) {
......@@ -86,4 +90,19 @@ public class WeGroupController extends BaseController {
return AjaxResult.success(weGroupService
.list(new LambdaQueryWrapper<WeGroup>().eq(WeGroup::getOwner,userId)));
}
/**
* 编辑群标签
* @return
*/
@PostMapping("/makeGroupTag")
@ApiOperation("编辑群标签")
public AjaxResult makeGroupTag(@RequestBody WeMakeGroupTagVo weMakeGroupTagVo){
iWeGroupTagRelService.makeGroupTag(weMakeGroupTagVo);
return AjaxResult.success();
}
}
......@@ -9,9 +9,10 @@ import com.linkwechat.common.utils.SnowFlakeUtil;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.experimental.SuperBuilder;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.experimental.SuperBuilder;
import org.springframework.format.annotation.DateTimeFormat;
import java.util.Date;
......@@ -38,6 +39,9 @@ public class WeGroup extends BaseEntity{
@ApiModelProperty(value = "群名")
private String groupName;
@TableField(exist = false)
private Long memberNum;
@ApiModelProperty(value = "群公告")
private String notice;
......@@ -47,25 +51,67 @@ public class WeGroup extends BaseEntity{
@ApiModelProperty(value = "0 - 正常;1 - 跟进人离职;2 - 离职继承中;3 - 离职继承完成")
private Integer status;
@JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd HH:mm:ss")
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
private Date addTime;
@ApiModelProperty(value = "管理员id")
private String adminUserId;
@JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd")
@DateTimeFormat(pattern = "yyyy-MM-dd")
private Date createTime;
@TableField(exist = false)
private String groupLeaderName;
@TableField(exist = false)
private String groupLeader;
@TableField(exist = false)
private Long memberNum;
@JsonFormat( pattern = "yyyy-MM-dd")
private String beginTime;
@TableField(exist = false)
@JsonFormat(pattern = "yyyy-MM-dd")
private String endTime;
/**员工id*/
@TableField(exist = false)
@ApiModelProperty(value = "员工id")
private String userIds;
/**
* 群头像
*/
@TableField(exist = false)
@ApiModelProperty(value = "群头像")
private String avatar;
/**
* 标签名,使用逗号隔开
*/
@TableField(exist = false)
private String tags;
/**
* 标签id
*/
@TableField(exist = false)
private String tagId;
/**
* 标签IDS
*/
@TableField(exist = false)
private String tagIds;
/**
* 加入时间
*/
private Date addTime;
/**
* 群管理员id
*/
private String adminUserId;
}
......@@ -111,8 +111,7 @@ public class WeGroupCode extends BaseEntity {
/**
* 实际码扫码次数之和
*/
@TableField(exist = false)
private Long totalScanTimes;
private Long totalScanTimes=new Long(0);
/**
* 即将过期实际码数量
......
package com.linkwechat.wecom.domain;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.linkwechat.common.core.domain.BaseEntity;
import lombok.Data;
/**
* 群与标签关系
*/
@Data
@TableName("we_group_tag_rel")
public class WeGroupTagRel extends BaseEntity {
//主键
@TableId
private String id;
//群id
private String chatId;
//标签id
private String tagId;
}
\ No newline at end of file
package com.linkwechat.wecom.domain.vo;
import com.linkwechat.wecom.domain.WeGroupTagRel;
import lombok.Data;
import java.util.List;
@Data
public class WeMakeGroupTagVo {
private String chatId;
private List<WeGroupTagRel> weeGroupTagRel;
}
package com.linkwechat.wecom.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.linkwechat.wecom.domain.WeGroupTagRel;
public interface WeGroupTagRelMapper extends BaseMapper<WeGroupTagRel> {
}
......@@ -78,4 +78,7 @@ public interface IWeGroupCodeService extends IService<WeGroupCode> {
*/
String selectGroupCodeUrlByEmplCodeState(String state);
void countScanTimes(WeGroupCode groupCode);
}
package com.linkwechat.wecom.service;
import com.baomidou.mybatisplus.extension.service.IService;
import com.linkwechat.wecom.domain.WeGroupTagRel;
import com.linkwechat.wecom.domain.vo.WeMakeGroupTagVo;
public interface IWeGroupTagRelService extends IService<WeGroupTagRel> {
void makeGroupTag(WeMakeGroupTagVo weMakeGroupTagVo);
}
......@@ -2,6 +2,7 @@ package com.linkwechat.wecom.service.impl;
import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.collection.ListUtil;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.ArrayUtil;
import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
......@@ -230,130 +231,76 @@ public class WeCustomerServiceImpl extends ServiceImpl<WeCustomerMapper, WeCusto
}
iWeFlowerCustomerRelService.saveBatch(weFlowerCustomerRel);
iWeFlowerCustomerTagRelService.saveOrUpdateBatch(weFlowerCustomerTagRels);
if(CollectionUtil.isNotEmpty(weFlowerCustomerRel)){
iWeFlowerCustomerRelService.saveBatch(
weFlowerCustomerRel.stream().collect(
Collectors.collectingAndThen(
Collectors.toCollection(() -> new TreeSet<>(Comparator.comparing(WeFlowerCustomerRel::getExternalUserid)
.thenComparing(WeFlowerCustomerRel::getUserId)
)), ArrayList::new)
)
);
}
if(CollectionUtil.isNotEmpty(weFlowerCustomerTagRels)){
iWeFlowerCustomerTagRelService.saveOrUpdateBatch(weFlowerCustomerTagRels);
}
if(CollectionUtil.isNotEmpty(weCustomerList)){
this.saveOrUpdateBatch(weCustomerList);
//移除,同一个客户不同首位添加人id客户,保留最早时间客户
this.saveOrUpdateBatch(
weCustomerList.stream().collect(
Collectors.collectingAndThen(
Collectors.toCollection(() -> new TreeSet<>(Comparator.comparing(WeCustomer::getExternalUserid))), ArrayList::new)
)
);
}
// List<ExternalUserDetail> list = new ArrayList<>();
// getByUser(userId, null, list);
//
// List<WeCustomer> weCustomerList=new ArrayList<>();
//
// list.forEach(userDetail -> {
// //客户入库
// WeCustomer weCustomer = new WeCustomer();
// BeanUtils.copyPropertiesignoreOther(userDetail.getExternal_contact(), weCustomer);
//
//
// //客户与通讯录客户关系
// List<WeTag> weTags = new ArrayList<>();
// List<WeTagGroup> weGroups = new ArrayList<>();
// List<WeFlowerCustomerTagRel> weFlowerCustomerTagRels = new ArrayList<>();
// List<WeFlowerCustomerRel> weFlowerCustomerRel = new ArrayList<>();
// Optional.ofNullable(userDetail.getFollow_info()).ifPresent(followInfo -> {
//
// weCustomer.setFirstUserId(userId);
// weCustomer.setFirstAddTime(new Date(followInfo.getCreatetime() * 1000L));
//
// weCustomerList.add(weCustomer);
//
// Long weFlowerCustomerRelId = SnowFlakeUtil.nextId();
// weFlowerCustomerRel.add(WeFlowerCustomerRel.builder()
// .id(weFlowerCustomerRelId)
// .userId(userId)
// .operUserid(followInfo.getOper_userid())
// .addWay(followInfo.getAdd_way())
// .externalUserid(weCustomer.getExternalUserid())
// .createTime(new Date(followInfo.getCreatetime() * 1000L))
// .build());
//
// List<String> tags = Stream.of(followInfo.getTag_id()).collect(Collectors.toList());
// if (CollectionUtil.isNotEmpty(tags)) {
// //获取相关标签组
// WeCropGroupTagListDto weCropGroupTagListDto = weCropTagClient.getCorpTagListByTagIds(WeFindCropTagParam.builder()
// .tag_id(followInfo.getTag_id())
// .build());
//
// if (weCropGroupTagListDto.getErrcode().equals(WeConstans.WE_SUCCESS_CODE)) {
// List<WeCropGroupTagDto> tagGroups = weCropGroupTagListDto.getTag_group();
// if (CollectionUtil.isNotEmpty(tagGroups)) {
// tagGroups.stream().forEach(tagGroup -> {
// weGroups.add(
// WeTagGroup.builder()
// .groupId(tagGroup.getGroup_id())
// .gourpName(tagGroup.getGroup_name())
// .build()
// );
//
// List<WeCropTagDto> weCropTagDtos = tagGroup.getTag();
// if (CollectionUtil.isNotEmpty(weCropTagDtos)) {
// Map<String, String> map = weCropTagDtos.stream().collect(Collectors.toMap(WeCropTagDto::getId, WeCropTagDto::getName));
// tags.forEach(tag -> {
// if (map.containsKey(tag)) {
// weTags.add(
// WeTag.builder()
// .groupId(tagGroup.getGroup_id())
// .tagId(tag)
// .name(map.get(tag))
// .build()
// );
//
// weFlowerCustomerTagRels.add(
// WeFlowerCustomerTagRel.builder()
// .userId(userId)
// .externalUserid(weCustomer.getExternalUserid())
// .flowerCustomerRelId(weFlowerCustomerRelId)
// .tagId(tag)
// .build()
// );
// }
}
// public static void main(String[] args) {
//
// });
// }
//
// });
// List<WeCustomer> weCustomerList=new ArrayList<>();
//
//
// }
// }
// }
// });
// weCustomerList.add(
// WeCustomer.builder()
// .externalUserid("abcdef")
// .firstUserId("1234")
// .firstAddTime(DateUtil.lastWeek())
// .build()
// );
//
// List<WeFlowerCustomerRel> weFlowerCustomerRels = iWeFlowerCustomerRelService.list(new LambdaQueryWrapper<WeFlowerCustomerRel>()
// .eq(WeFlowerCustomerRel::getExternalUserid, weCustomer.getExternalUserid())
// .eq(WeFlowerCustomerRel::getUserId,userId));
// weCustomerList.add(
// WeCustomer.builder()
// .externalUserid("abcdef")
// .firstUserId("4321")
// .firstAddTime(DateUtil.nextWeek())
// .build()
// );
//
// if (CollectionUtil.isNotEmpty(weFlowerCustomerRels)) {
// List<Long> weFlowerCustomerRelIds = weFlowerCustomerRels.stream().map(WeFlowerCustomerRel::getId).collect(Collectors.toList());
// iWeFlowerCustomerTagRelService.remove(new LambdaQueryWrapper<WeFlowerCustomerTagRel>()
// .in(WeFlowerCustomerTagRel::getFlowerCustomerRelId, weFlowerCustomerRelIds)
// .ne(WeFlowerCustomerTagRel::getRelTagType,new Integer(1))
// );
// iWeFlowerCustomerRelService.removeByIds(weFlowerCustomerRelIds);
// }
// weCustomerList.stream().filter((o1,o2)->)
//
// ArrayList<WeCustomer> collect = weCustomerList.stream().collect(
// Collectors.collectingAndThen(
// Collectors.toCollection(() -> new TreeSet<>(Comparator.comparing(WeCustomer::getExternalUserid)
// .thenComparing(WeCustomer::getFirstAddTime)
// )), ArrayList::new)
// );
//
// iWeFlowerCustomerRelService.saveBatch(weFlowerCustomerRel);
// System.out.println("=============");
//
// //设置标签跟客户关系,标签和标签组,saveOrUpdate,建立标签与添加人关系
// if (CollectionUtil.isNotEmpty(weTags) && CollectionUtil.isNotEmpty(weGroups)) {
// iWeTagService.saveOrUpdateBatch(weTags);
// iWeTagGroupService.saveOrUpdateBatch(weGroups);
// iWeFlowerCustomerTagRelService.saveOrUpdateBatch(weFlowerCustomerTagRels);
// }
//
// });
//
// if(CollectionUtil.isNotEmpty(weCustomerList)){
// this.saveOrUpdateBatch(weCustomerList);
// }
}
// }
/**
* 批量获取客户详情
......
......@@ -18,6 +18,7 @@ import com.linkwechat.wecom.mapper.WeCommunityNewGroupMapper;
import com.linkwechat.wecom.mapper.WeGroupCodeActualMapper;
import com.linkwechat.wecom.service.IWeGroupCodeActualService;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;
import com.linkwechat.wecom.mapper.WeGroupCodeMapper;
import com.linkwechat.wecom.domain.WeGroupCode;
......@@ -163,4 +164,24 @@ public class WeGroupCodeServiceImpl extends ServiceImpl<WeGroupCodeMapper, WeGro
public String selectGroupCodeUrlByEmplCodeState(String state) {
return baseMapper.selectGroupCodeUrlByEmplCodeState(state);
}
/**
* 统计扫码次数
* @param groupCode
*/
@Override
@Async
public void countScanTimes(WeGroupCode groupCode) {
if(groupCode !=null){
groupCode.setTotalScanTimes(
groupCode.getTotalScanTimes()+1
);
this.updateById(groupCode);
}
}
}
package com.linkwechat.wecom.service.impl;
import cn.hutool.core.collection.CollectionUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.linkwechat.wecom.domain.WeGroupTagRel;
import com.linkwechat.wecom.domain.vo.WeMakeGroupTagVo;
import com.linkwechat.wecom.mapper.WeGroupTagRelMapper;
import com.linkwechat.wecom.service.IWeGroupTagRelService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.List;
@Service
public class WeGroupTagRelServiceImpl extends ServiceImpl<WeGroupTagRelMapper,WeGroupTagRel> implements IWeGroupTagRelService {
@Override
@Transactional
public void makeGroupTag(WeMakeGroupTagVo weMakeGroupTagVo) {
List<WeGroupTagRel> addWeGroupTagRel = weMakeGroupTagVo.getWeeGroupTagRel();
if(CollectionUtil.isNotEmpty(addWeGroupTagRel)){
addWeGroupTagRel.stream().forEach(k->k.setChatId(weMakeGroupTagVo.getChatId()));
this.remove(new LambdaQueryWrapper<WeGroupTagRel>()
.eq(WeGroupTagRel::getChatId,weMakeGroupTagVo.getChatId()));
this.saveBatch(addWeGroupTagRel);
}
}
}
......@@ -45,7 +45,7 @@
w.`update_time`,
w.`remark`,
IFNULL((SELECT count(1) FROM we_group_code_actual WHERE (SELECT IFNULL(scan_code_times, 0)) &lt; scan_code_times_limit AND group_code_id = w.`id` ), 0) AS available_codes,
IFNULL((SELECT SUM( scan_code_times ) AS scan_times FROM we_group_code_actual WHERE group_code_id = w.`id` GROUP BY group_code_id), 0) AS total_scan_times,
w.total_scan_times,
IFNULL((SELECT count(1) FROM we_group_code_actual WHERE group_code_id = w.`id` AND TIMESTAMPDIFF(DAY, sysdate(), effect_time ) &lt; 3), 0) AS about_to_expire_codes
FROM
we_group_code w
......
......@@ -7,16 +7,16 @@
<select id="selectWeGroupList" parameterType="WeGroup" resultType="com.linkwechat.wecom.domain.WeGroup">
SELECT
wg.chat_id,
if(wg.group_name = '' or wg.group_name is null,
(SELECT group_concat(name separator '、') FROM we_group_member wgm WHERE wgm.chat_id = wg.chat_id limit 10),
wg.group_name) as group_name,
wg.add_time,
wg.notice,
wu.user_name as groupLeaderName,
(SELECT COUNT(*) FROM we_group_member wgm WHERE wgm.chat_id=wg.chat_id) as memberNum,
wg.status,
wg.`owner`
wg.chat_id,
wg.group_name,
wg.create_time,
wg.notice,
wu.user_name as groupLeaderName,
(SELECT COUNT(*) FROM we_group_member wgm WHERE wgm.chat_id=wg.chat_id) as memberNum,
wg.status,
wg.`owner`,
(SELECT GROUP_CONCAT(wt.`name`) FROM we_group_tag_rel wgtr LEFT JOIN we_tag wt ON wt.tag_id=wgtr.tag_id WHERE wg.chat_id=wgtr.chat_id) as tags,
(SELECT GROUP_CONCAT(wt.`tag_id`) FROM we_group_tag_rel wgtr LEFT JOIN we_tag wt ON wt.tag_id=wgtr.tag_id WHERE wg.chat_id=wgtr.chat_id) as tagIds
FROM
we_group wg
LEFT JOIN we_user wu ON wg.`owner`=wu.user_id
......@@ -24,11 +24,11 @@
<if test="groupName != null and groupName != ''"> and wg.group_name like concat('%', #{groupName}, '%')</if>
<if test="groupLeader != null and groupLeader != ''"> and wu.user_name like concat('%', #{groupLeader}, '%')</if>
<if test="beginTime != null and beginTime != ''"><!-- 开始时间检索 -->
AND date_format(wg.add_time,'%y%m%d') &gt;= date_format(#{beginTime},'%y%m%d')
AND date_format(wg.create_time,'%y%m%d') &gt;= date_format(#{beginTime},'%y%m%d')
</if>
<if test="endTime != null and endTime != ''"><!-- 结束时间检索 -->
AND date_format(wg.add_time,'%y%m%d') &lt;= date_format(#{endTime},'%y%m%d')
AND date_format(wg.create_time,'%y%m%d') &lt;= date_format(#{endTime},'%y%m%d')
</if>
<if test="userIds != null and userIds !=''">
<if test="userIds.indexOf(',') != -1">
......
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.linkwechat.wecom.mapper.WeGroupTagRelMapper">
</mapper>
\ No newline at end of file
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!