提交 08024aba 编写于 作者: L linkwechat8856@163.com

修复员工离职bug

上级 43df0ac1
package com.linkwechat.web.controller.wecom;
import cn.hutool.core.collection.CollectionUtil;
import com.linkwechat.common.annotation.Log;
import com.linkwechat.common.constant.HttpStatus;
import com.linkwechat.common.core.controller.BaseController;
import com.linkwechat.common.core.domain.AjaxResult;
import com.linkwechat.common.core.page.TableDataInfo;
import com.linkwechat.common.enums.BusinessType;
import com.linkwechat.common.exception.wecom.WeComException;
import com.linkwechat.common.utils.StringUtils;
import com.linkwechat.common.utils.file.FileUtils;
import com.linkwechat.wecom.domain.WeCommunityNewGroup;
import com.linkwechat.wecom.domain.WeEmpleCode;
......
package com.linkwechat.web.controller.wecom;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.linkwechat.common.core.controller.BaseController;
import com.linkwechat.common.core.domain.AjaxResult;
import com.linkwechat.common.core.page.TableDataInfo;
import com.linkwechat.common.utils.StringUtils;
import com.linkwechat.wecom.domain.WeMessagePush;
import com.linkwechat.wecom.domain.WeMoments;
import com.linkwechat.wecom.service.IWeMomentsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.List;
/**
* 朋友圈相关
*/
@RestController
@RequestMapping("/wecom/moments")
public class WeMomentsController extends BaseController {
@Autowired
IWeMomentsService iWeMomentsService;
/**
* 获取朋友圈列表
* @param weMoments
* @return
*/
@GetMapping("/list")
public TableDataInfo list(WeMoments weMoments) {
startPage();
return getDataTable(
iWeMomentsService.list(
new LambdaQueryWrapper<WeMoments>()
.eq(StringUtils.isNotEmpty(weMoments.getCreateBy()), WeMoments::getCreateBy
, weMoments.getCreateBy())
.apply(weMoments.getBeginTime() != null, "to_date(create_time::text,'YYYY-MM-DD') >= to_date('" + weMoments.getBeginTime() + "','YYYY-MM-DD')")
.apply(weMoments.getEndTime() != null, "to_date(create_time::text,'YYYY-MM-DD') <= to_date('" + weMoments.getEndTime() + "','YYYY-MM-DD')")
)
);
}
/**
* 新增或者编辑朋友圈
* @return
*/
@PostMapping("/addOrUpdate")
public AjaxResult addOrUpdate(@RequestBody WeMoments weMoments){
iWeMomentsService.addOrUpdateMoments(weMoments);
return AjaxResult.success();
}
}
......@@ -46,6 +46,7 @@ public class WeMsgTlpController extends BaseController
}
/**
* 新增欢迎语模板
*/
......
......@@ -46,6 +46,10 @@ public class RuoYiConfig
private boolean editPwd=true;
/**无需同步的用户*/
private String[] noSyncWeUser;
/**匿名访问的URL*/
private String[] anonUrl;
......@@ -185,4 +189,13 @@ public class RuoYiConfig
public void setEditPwd(boolean editPwd) {
this.editPwd = editPwd;
}
public String[] getNoSyncWeUser() {
return noSyncWeUser;
}
public void setNoSyncWeUser(String[] noSyncWeUser) {
this.noSyncWeUser = noSyncWeUser;
}
}
......@@ -35,17 +35,22 @@ public class GroupMessageTask {
if (CollectionUtils.isNotEmpty(weCustomerMessageTimeTasks)) {
weCustomerMessageTimeTasks.forEach(
s -> {
Integer solved=new Integer(1);
String exceMsg=null;
try {
if (s.getMessageInfo() != null && s.getMessageId() != null || (s.getMessageInfo().getPushType().equals(WeConstans.SEND_MESSAGE_CUSTOMER)
&& CollectionUtils.isNotEmpty(s.getCustomersInfo())) || (s.getMessageInfo().getPushType().equals(WeConstans.SEND_MESSAGE_GROUP)
&& CollectionUtils.isNotEmpty(s.getGroupsInfo()))) {
weCustomerMessageService.sendMessgae(s.getMessageInfo(), s.getMessageId(), s.getCustomersInfo(), s.getGroupsInfo());
//更新消息处理状态
customerMessageTimeTaskMapper.updateTaskSolvedById(s.getTaskId());
}
} catch (Exception e) {
log.error("定时群发消息处理异常:ex:{}", e);
e.printStackTrace();
solved=new Integer(2);
exceMsg=e.getMessage();
}finally {
//更新消息处理状态
customerMessageTimeTaskMapper.updateTaskSolvedById(s.getTaskId(),solved,exceMsg);
}
}
);
......
package com.linkwechat.wecom.client;
import com.dtflys.forest.annotation.BaseRequest;
import com.dtflys.forest.annotation.JSONBody;
import com.dtflys.forest.annotation.PostRequest;
import com.dtflys.forest.annotation.Retry;
import com.linkwechat.wecom.domain.dto.WeResultDto;
import com.linkwechat.wecom.domain.dto.moments.MomentsParamDto;
import com.linkwechat.wecom.retry.WeCommonRetryWhen;
/**
* 朋友圈
*/
@BaseRequest(baseURL = "${weComServerUrl}${weComePrefix}",retryer = WeCommonRetryWhen.class)
@Retry(maxRetryCount = "3", maxRetryInterval = "1000", condition = WeCommonRetryWhen.class)
public interface WeMomentsClient {
/**
* 创建朋友圈
* @param momentsParamDto
* @return
*/
@PostRequest("/externalcontact/add_moment_task")
WeResultDto addMomentTask(@JSONBody MomentsParamDto momentsParamDto);
}
package com.linkwechat.wecom.domain;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableLogic;
import com.baomidou.mybatisplus.annotation.TableName;
import com.linkwechat.common.core.domain.BaseEntity;
import com.linkwechat.wecom.handler.GenericTypeHandler;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
/**
* 朋友圈
*/
@Data
@TableName("we_moments")
public class WeMoments extends BaseEntity {
@TableId
private Long id;
/**可见类型:1:全部;2:部分;*/
private Integer scopeType;
/**朋友圈类型:1:企业动态;2:个人动态*/
private Integer type;
/**客户标签,多个使用逗号隔开*/
private String customerTag;
/**添加人,多个使用逗号隔开,(已发送员工)*/
private String addUser;
/**发送员工名称,使用逗号隔开*/
private String addUserName;
/**未发送员工,使用逗号隔开*/
private String noAddUser;
/**未发送员工名称,使用逗号隔开*/
private String noAddUserName;
/**文字内容*/
private String textContent;
/**附件*/
@TableField(typeHandler = GenericTypeHandler.class)
private OtherContent otherContent;
@TableLogic
private Integer delFlag;
/**异步任务id,最大长度为64字节,24小时有效;可使用获取发表朋友圈任务结果查询任务状态*/
private String jobId;
@Data
public static class OtherContent{
//附件类型:1:图片 2:视频 3:网页
private Integer annexType;
//多个资源url,使用逗号隔开
private String annexUrl;
//多个媒体id,使用逗号隔开
private String annexMediaid;
}
}
......@@ -19,7 +19,7 @@ import java.util.List;
* @date 2020-10-04
*/
@Data
@TableName("we_msg_tlp")
@TableName(value = "we_msg_tlp",autoResultMap = true)
public class WeMsgTlp extends BaseEntity
{
private static final long serialVersionUID = 1L;
......@@ -38,13 +38,13 @@ public class WeMsgTlp extends BaseEntity
/**图文*/
@TableField(typeHandler = GenericTypeHandler.class)
private ImageText imageText;
private List<ImageText> imageText;
/**小程序*/
@TableField(typeHandler = GenericTypeHandler.class)
private Applet applet;
private List<Applet> applet;
/** 0:正常;1:删除; */
......
package com.linkwechat.wecom.domain.dto.moments;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.util.ArrayList;
import java.util.List;
/**
* 朋友圈如参相关
*/
@Data
@Builder
@AllArgsConstructor
@NoArgsConstructor
public class MomentsParamDto {
//文本
private Text text;
//附件
private List<BaseAttachments> attachments;
//可见范围
private VisibleRange visible_range;
@Data
@Builder
public static class Text{
private String content;
}
/**
* 附件上级类
*/
@Data
public static class BaseAttachments{
//类型:image:图片;video:视频;link:图文;
private String msgtype;
}
/**
* 图片附件
*/
@Data
@Builder
public static class ImageAttachments extends BaseAttachments {
private Image image;
}
/**
* 视频附件
*/
@Data
@Builder
public static class VideoAttachments extends BaseAttachments{
private Video video;
}
/**
* 图文附件
*/
@Data
@Builder
public static class LinkAttachments extends BaseAttachments{
private Link link;
}
@Data
@Builder
public static class Image{
private String mediaId;
}
@Data
@Builder
public static class Video{
private String mediaId;
}
@Data
@Builder
public static class Link{
private String title;
private String url;
private String mediaId;
}
/****************************************
******************范围相关***************
***************************************/
@Data
@Builder
public static class VisibleRange{
private SenderList sender_list;
private ExternalContactList external_contact_list;
}
@Data
@Builder
public static class SenderList{
private String[] user_list;
private String[] department_list;
}
@Data
@Builder
public static class ExternalContactList{
private String[] tag_list;
}
}
package com.linkwechat.wecom.domain.dto.moments;
import com.linkwechat.wecom.domain.dto.WeResultDto;
import lombok.Data;
@Data
public class MomentsResultDto extends WeResultDto {
private String jobid;
}
......@@ -2,6 +2,7 @@ package com.linkwechat.wecom.handler;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.linkwechat.wecom.domain.WeMoments;
import com.linkwechat.wecom.domain.WeMsgTlp;
import com.linkwechat.wecom.domain.dto.message.CustomerMessagePushDto;
import org.apache.ibatis.type.BaseTypeHandler;
......@@ -19,7 +20,8 @@ import java.sql.SQLException;
* @param <T>
*/
@SuppressWarnings("all")
@MappedTypes(value = {JSONObject.class, CustomerMessagePushDto.class, WeMsgTlp.Applet.class,WeMsgTlp.ImageText.class})
@MappedTypes(value = {JSONObject.class, CustomerMessagePushDto.class, WeMsgTlp.Applet.class,WeMsgTlp.ImageText.class,
WeMoments.OtherContent.class})
@MappedJdbcTypes(value = {JdbcType.VARCHAR}, includeNullJdbcType = true)
public class GenericTypeHandler<T extends Object> extends BaseTypeHandler<T> {
......
......@@ -37,6 +37,6 @@ public interface WeCustomerMessageTimeTaskMapper extends BaseMapper<WeCustomerMe
* @param taskId 任务id
* @return int
*/
int updateTaskSolvedById(@Param("taskId") Long taskId);
int updateTaskSolvedById(@Param("taskId") Long taskId,@Param("solved") Integer solved,@Param("exceMsg") String exceMsg);
}
package com.linkwechat.wecom.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.linkwechat.wecom.domain.WeMoments;
public interface WeMomentsMapper extends BaseMapper<WeMoments> {
}
package com.linkwechat.wecom.service;
import com.baomidou.mybatisplus.extension.service.IService;
import com.linkwechat.wecom.domain.WeMoments;
import com.linkwechat.wecom.mapper.WeMomentsMapper;
public interface IWeMomentsService extends IService<WeMoments> {
void addOrUpdateMoments(WeMoments weMoments);
}
......@@ -251,6 +251,10 @@ public class WeCustomerServiceImpl extends ServiceImpl<WeCustomerMapper, WeCusto
if(CollectionUtil.isNotEmpty(weCustomerList)){
//移除不存在的客户
this.remove(new LambdaQueryWrapper<WeCustomer>()
.notIn(WeCustomer::getExternalUserid,weCustomerList.stream().map(WeCustomer::getExternalUserid).collect(Collectors.toList()))
);
//移除,同一个客户不同首位添加人id客户,保留最早时间客户
this.saveOrUpdateBatch(
weCustomerList.stream().collect(
......
package com.linkwechat.wecom.service.impl;
import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.collection.ListUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.google.common.base.Joiner;
import com.linkwechat.common.constant.WeConstans;
import com.linkwechat.common.utils.StringUtils;
import com.linkwechat.wecom.client.WeMomentsClient;
import com.linkwechat.wecom.domain.WeMoments;
import com.linkwechat.wecom.domain.WeUser;
import com.linkwechat.wecom.domain.dto.WeResultDto;
import com.linkwechat.wecom.domain.dto.moments.MomentsParamDto;
import com.linkwechat.wecom.mapper.WeMomentsMapper;
import com.linkwechat.wecom.service.IWeMomentsService;
import com.linkwechat.wecom.service.IWeUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;
@Service
public class WeMomentsServiceImpl extends ServiceImpl<WeMomentsMapper, WeMoments> implements IWeMomentsService {
@Autowired
WeMomentsClient weMomentsClient;
@Autowired
IWeUserService iWeUserService;
/**
* 发送更新朋友圈
* @param weMoments
*/
@Override
public void addOrUpdateMoments(WeMoments weMoments) {
String addUser = weMoments.getAddUser();
if(StringUtils.isNotEmpty(addUser)){
List<WeUser> weUsers = iWeUserService.listByIds(
ListUtil.toList(addUser.split(","))
);
if(CollectionUtil.isNotEmpty(weUsers)){
weMoments.setAddUserName(
Joiner.on(",").join( weUsers.stream().map(WeUser::getName).collect(Collectors.toList()))
);
}
List<WeUser> noWeUser = iWeUserService.list(new LambdaQueryWrapper<WeUser>()
.notIn(WeUser::getUserId, ListUtil.toList(addUser.split(",")))
);
if(CollectionUtil.isNotEmpty(noWeUser)){
weMoments.setNoAddUser(
Joiner.on(",").join( noWeUser.stream().map(WeUser::getUserId).collect(Collectors.toList()))
);
weMoments.setNoAddUserName(
Joiner.on(",").join( noWeUser.stream().map(WeUser::getName).collect(Collectors.toList()))
);
}
}
if(this.saveOrUpdate(weMoments)){
//企业动态,同步企业微信端
if(weMoments.getType()
.equals(new Integer(1))){
//附件封装
List<MomentsParamDto.BaseAttachments> attachments=new ArrayList<>();
WeMoments.OtherContent otherContent = weMoments.getOtherContent();
if(null != otherContent){
//图片
if(otherContent.getAnnexType().equals(new Integer(1))){
if(StringUtils.isNotEmpty(otherContent.getAnnexMediaid())){
Arrays.stream(otherContent.getAnnexMediaid().split(","))
.forEach(k->{
attachments.add(
MomentsParamDto.ImageAttachments.builder().image(
MomentsParamDto.Image.builder()
.mediaId(null)
.build()
).build()
);
});
}
}
//视频
if(otherContent.getAnnexType().equals(new Integer(2))){
if(StringUtils.isNotEmpty(otherContent.getAnnexMediaid())){
attachments.add(
MomentsParamDto.VideoAttachments.builder().video(
MomentsParamDto.Video.builder()
.mediaId(otherContent.getAnnexMediaid())
.build()
).build()
);
}
}
//链接
if(otherContent.getAnnexType().equals(new Integer(3))){
if(StringUtils.isNotEmpty(otherContent.getAnnexUrl())
&&StringUtils.isNotEmpty(otherContent.getAnnexMediaid())){
attachments.add(
MomentsParamDto.LinkAttachments.builder().link(
MomentsParamDto.Link.builder()
.url(otherContent.getAnnexUrl())
.mediaId(otherContent.getAnnexMediaid())
.build()
).build()
);
}
}
}
MomentsParamDto.VisibleRange visibleRange
= MomentsParamDto.VisibleRange.builder().build();
if(weMoments.getScopeType().equals(new Integer(2))){ //部分
if(StringUtils.isNotEmpty(weMoments.getCustomerTag())){ //客户标签
visibleRange.setExternal_contact_list(
MomentsParamDto.ExternalContactList.builder()
.tag_list(weMoments.getCustomerTag().split(","))
.build()
);
}
if(StringUtils.isNotEmpty(weMoments.getAddUser())){//指定发送人
visibleRange.setSender_list(
MomentsParamDto.SenderList.builder()
.user_list(weMoments.getAddUser().split(","))
.build()
);
}
}
WeResultDto weResultDto = weMomentsClient.addMomentTask(
MomentsParamDto.builder()
.text(MomentsParamDto.Text.builder()
.content(weMoments.getTextContent())
.build())
.visible_range(visibleRange)
.attachments(attachments)
.build()
);
//更新jobid
if(weResultDto.getErrcode().equals(WeConstans.WE_SUCCESS_CODE)){
weMoments.setJobId(weMoments.getJobId());
this.updateById(weMoments);
}
}
}
}
}
package com.linkwechat.wecom.service.impl;
import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.collection.ListUtil;
import cn.hutool.core.thread.ThreadUtil;
import cn.hutool.core.util.ArrayUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.baomidou.mybatisplus.extension.toolkit.SqlHelper;
import com.google.common.collect.Lists;
import com.linkwechat.common.config.RuoYiConfig;
import com.linkwechat.common.constant.WeConstans;
import com.linkwechat.common.core.redis.RedisCache;
import com.linkwechat.common.exception.wecom.WeComException;
......@@ -52,6 +55,10 @@ public class WeUserServiceImpl extends ServiceImpl<WeUserMapper, WeUser> impleme
@Autowired
private WeMsgAuditClient weMsgAuditClient;
@Autowired
private RuoYiConfig ruoYiConfig;
@Override
public List<WeUser> getListByIds(List<Long> idList) {
return this.list(new LambdaQueryWrapper<WeUser>().in(WeUser::getUserId,idList));
......@@ -207,9 +214,21 @@ public class WeUserServiceImpl extends ServiceImpl<WeUserMapper, WeUser> impleme
List<WeUser> weUsers = weUserClient.list(WeConstans.WE_ROOT_DEPARMENT_ID,
WeConstans.DEPARTMENT_SUB_WEUSER).getWeUsers();
if (CollectionUtil.isNotEmpty(weUsers)) {
List<WeUser> collect
= weUsers.stream().filter(o -> !o.getUserId().equals("45DuXiangShangQingXie")).collect(Collectors.toList());
List<List<WeUser>> lists = Lists.partition(collect, 500);
//不存在的客户设置为离职未分配状态
this.update(WeUser.builder()
.isActivate(WeConstans.WE_USER_IS_LEAVE)
.isAllocate(WeConstans.LEAVE_NO_ALLOCATE_STATE)
.dimissionTime(new Date())
.build(),new LambdaQueryWrapper<WeUser>()
.notIn(WeUser::getUserId,weUsers.stream().map(WeUser::getUserId).collect(Collectors.toList())));
String[] noSyncWeUser = ruoYiConfig.getNoSyncWeUser();
if(ArrayUtil.isNotEmpty(noSyncWeUser)){
weUsers=weUsers.stream().filter(o -> !ListUtil.toList(noSyncWeUser).contains(o.getUserId())).collect(Collectors.toList());
}
List<List<WeUser>> lists = Lists.partition(weUsers, 500);
for(List<WeUser> list : lists){
this.weUserMapper.insertBatch(list);
}
......
......@@ -38,10 +38,11 @@
)
</insert>
<update id="updateTaskSolvedById">
UPDATE we_customer_messageTimeTask
<set>
solved=1
</set>
UPDATE we_customer_messageTimeTask set
solved=#{solved},
<if test="exceMsg != null and exceMsg !=''">
exce_msg=#{exceMsg}
</if>
<where>
task_id=#{taskId}
</where>
......
<?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.WeMomentsMapper">
</mapper>
\ No newline at end of file
......@@ -65,6 +65,7 @@
<if test="birthday != null ">and birthday = #{birthday}</if>
<if test="isActivate != null ">and is_activate = #{isActivate}</if>
<if test="isOpenChat != null ">and is_open_chat = #{isOpenChat}</if>
and is_activate !=6
</where>
</select>
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册