Commit d61114e6 by danmo

重构活码并新增使用范围修改任务

1 parent 11e2a1b1
package com.linkwechat.quartz.task;
import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.date.Week;
import cn.hutool.core.util.ObjectUtil;
import com.linkwechat.common.utils.StringUtils;
import com.linkwechat.wecom.client.WeExternalContactClient;
import com.linkwechat.wecom.domain.WeQrCode;
import com.linkwechat.wecom.domain.dto.WeContactWayDto;
import com.linkwechat.wecom.domain.dto.WeExternalContactDto;
import com.linkwechat.wecom.domain.vo.qr.WeQrScopePartyVo;
import com.linkwechat.wecom.domain.vo.qr.WeQrScopeUserVo;
import com.linkwechat.wecom.domain.vo.qr.WeQrScopeVo;
import com.linkwechat.wecom.service.IWeQrCodeService;
import com.linkwechat.wecom.service.IWeQrScopeService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.util.Arrays;
import java.util.Date;
import java.util.List;
import java.util.stream.Collectors;
/**
* @author danmo
* @description 活码使用范围修改任务
* @date 2021/11/13 23:02
**/
@Slf4j
@Component()
public class WeQrCodeUpdateTask {
@Autowired
private IWeQrScopeService weQrScopeService;
@Autowired
private IWeQrCodeService weQrCodeService;
@Autowired
private WeExternalContactClient externalContactClient;
private void qrCodeUpdateTask() {
Date date = new Date();
Week week = DateUtil.dayOfWeekEnum(date);
String formatTime = DateUtil.formatTime(date);
List<WeQrScopeVo> weQrScopeList = weQrScopeService.getWeQrScopeByTime(week.getValue(), formatTime);
if (CollectionUtil.isNotEmpty(weQrScopeList)) {
for (WeQrScopeVo weQrScope : weQrScopeList) {
WeQrCode weQrCode = weQrCodeService.getById(weQrScope.getQrId());
String configId = weQrCode.getConfigId();
WeContactWayDto contactWay = externalContactClient.getContactWay(configId);
if (contactWay != null && ObjectUtil.equal(0, contactWay.getErrcode())) {
String userIds = "";
String partys = "";
String qrUserIds = "";
String qrPartys = "";
if (CollectionUtil.isNotEmpty(contactWay.getContactWay().getUser())) {
userIds = String.join(",", contactWay.getContactWay().getUser());
}
if (CollectionUtil.isNotEmpty(contactWay.getContactWay().getParty())) {
partys = contactWay.getContactWay().getParty().stream().map(String::valueOf).collect(Collectors.joining(","));
}
if (CollectionUtil.isNotEmpty(weQrScope.getWeQrUserList())) {
qrUserIds = weQrScope.getWeQrUserList().stream().map(WeQrScopeUserVo::getUserId).collect(Collectors.joining(","));
}
if (CollectionUtil.isNotEmpty(weQrScope.getWeQrPartyList())) {
qrPartys = weQrScope.getWeQrPartyList().stream().map(WeQrScopePartyVo::getParty).collect(Collectors.joining(","));
}
if (!ObjectUtil.equal(qrUserIds, userIds) || !ObjectUtil.equal(qrPartys, partys)) {
WeExternalContactDto.WeContactWay weContactWay = new WeExternalContactDto.WeContactWay();
weContactWay.setConfig_id(configId);
if (StringUtils.isNotEmpty(qrUserIds)) {
weContactWay.setUser(qrUserIds.split(","));
}
if (StringUtils.isNotEmpty(qrPartys)) {
Long[] qrPartyList = Arrays.stream(qrPartys.split(","))
.map(s -> Long.parseLong(s.trim())).toArray(Long[]::new);
weContactWay.setParty(qrPartyList);
}
externalContactClient.updateContactWay(weContactWay);
}
}
}
}
}
}
package com.linkwechat.wecom.client; package com.linkwechat.wecom.client;
import com.dtflys.forest.annotation.*; import com.dtflys.forest.annotation.*;
import com.linkwechat.wecom.domain.dto.WeContactWayDto;
import com.linkwechat.wecom.domain.dto.WeExternalContactDto; import com.linkwechat.wecom.domain.dto.WeExternalContactDto;
import com.linkwechat.wecom.interceptor.WeAccessTokenInterceptor; import com.linkwechat.wecom.interceptor.WeAccessTokenInterceptor;
import com.linkwechat.wecom.retry.WeCommonRetryWhen; import com.linkwechat.wecom.retry.WeCommonRetryWhen;
...@@ -26,5 +27,5 @@ public interface WeExternalContactClient { ...@@ -26,5 +27,5 @@ public interface WeExternalContactClient {
WeExternalContactDto delContactWay(@Query("configId") String configId); WeExternalContactDto delContactWay(@Query("configId") String configId);
@Request(url = "/externalcontact/get_contact_way", type = "POST") @Request(url = "/externalcontact/get_contact_way", type = "POST")
WeExternalContactDto getContactWay(@Query("configId") String configId); WeContactWayDto getContactWay(@Query("configId") String configId);
} }
package com.linkwechat.wecom.domain.dto;
import lombok.Data;
import java.util.List;
/**
* @author danmo
* @description 联系我详情
* @date 2021/11/13 23:50
**/
@Data
public class WeContactWayDto extends WeResultDto {
private WeContactWay contactWay;
@Data
public static class WeContactWay {
//系我二维码链接,仅在scene为2时返回
private String configId;
// 联系方式类型,1-单人, 2-多人
private Integer type;
//场景,1-在小程序中联系,2-通过二维码联系
private Integer scene;
//外部客户添加时是否无需验证,默认为true
private Boolean skipVerify;
//使用该联系方式的用户userID列表,在type为1时为必填,且只能有一个
private List<String> user;
//使用该联系方式的部门id列表,只在type为2时有效
private List<Long> party;
//企业自定义的state参数,用于区分不同的添加渠道,在调用“获取外部联系人详情”时会返回该参数值,不超过30个字符
private String state;
//样式
private Integer style = 1;
}
}
...@@ -23,5 +23,7 @@ public interface WeQrScopeMapper extends BaseMapper<WeQrScope> { ...@@ -23,5 +23,7 @@ public interface WeQrScopeMapper extends BaseMapper<WeQrScope> {
List<WeQrScopeVo> getWeQrScopeByQrIds(@Param("qrIds") List<Long> qrIds); List<WeQrScopeVo> getWeQrScopeByQrIds(@Param("qrIds") List<Long> qrIds);
List<WeQrScopeVo> getWeQrScopeByTime(@Param("value") Integer value, @Param("formatTime") String formatTime);
} }
...@@ -42,4 +42,12 @@ public interface IWeQrScopeService extends IService<WeQrScope> { ...@@ -42,4 +42,12 @@ public interface IWeQrScopeService extends IService<WeQrScope> {
* @return * @return
*/ */
List<WeQrScopeVo> getWeQrScopeByQrIds(List<Long> qrIds); List<WeQrScopeVo> getWeQrScopeByQrIds(List<Long> qrIds);
/**
* 查询当前时间使用范围活码数据
* @param value
* @param formatTime
* @return
*/
List<WeQrScopeVo> getWeQrScopeByTime(Integer value, String formatTime);
} }
...@@ -91,4 +91,9 @@ public class IWeQrScopeServiceImpl extends ServiceImpl<WeQrScopeMapper, WeQrScop ...@@ -91,4 +91,9 @@ public class IWeQrScopeServiceImpl extends ServiceImpl<WeQrScopeMapper, WeQrScop
public List<WeQrScopeVo> getWeQrScopeByQrIds(List<Long> qrIds) { public List<WeQrScopeVo> getWeQrScopeByQrIds(List<Long> qrIds) {
return this.baseMapper.getWeQrScopeByQrIds(qrIds); return this.baseMapper.getWeQrScopeByQrIds(qrIds);
} }
@Override
public List<WeQrScopeVo> getWeQrScopeByTime(Integer value, String formatTime) {
return this.baseMapper.getWeQrScopeByTime(value,formatTime);
}
} }
...@@ -66,4 +66,23 @@ ...@@ -66,4 +66,23 @@
</where> </where>
</select> </select>
<select id="getWeQrScopeByTime" resultMap="QrScopeResult">
select
wqs.qr_id,
wqs.scope_id,
wqs.scope_type,
wqs.`type`,
wqs.begin_time,
wqs.end_time,
wqs.work_cycle,
wqs.user_id,
wqs.party
from we_qr_scope wqs
where find_in_set(#{value},wqs.work_cycle)
and str_to_date(wqs.begin_time,'%H:%i:%S') &lt;= str_to_date(#{formatTime},'%H:%i:%S')
and str_to_date(wqs.end_time ,'%H:%i:%S') &gt;= str_to_date(#{formatTime},'%H:%i:%S')
and wqs.`type` = 1
and wqs.del_flag = 0
</select>
</mapper> </mapper>
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!