Commit a397a521 by danmo

活码相关bug修改

1 parent 380e827e
package com.linkwechat.common.utils.file;
import cn.hutool.core.io.FileUtil;
import cn.hutool.core.util.ObjectUtil;
import com.linkwechat.common.utils.StringUtils;
import org.springframework.web.multipart.MultipartFile;
......@@ -8,8 +10,10 @@ import java.net.HttpURLConnection;
import java.net.URL;
import java.net.URLConnection;
import java.net.URLEncoder;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
import java.util.zip.ZipEntry;
import java.util.zip.ZipOutputStream;
import javax.servlet.http.HttpServletRequest;
......@@ -86,10 +90,20 @@ public class FileUtils extends org.apache.commons.io.FileUtils
*/
public static void batchDownloadFile(List<Map<String, String>> fileList, OutputStream os) {
try {
Map<String, Integer> fileNameCountMap = fileList.stream().collect(Collectors
.toMap(item -> item.get("fileName"), item -> 0, (key, value) -> key));
ZipOutputStream zos = new ZipOutputStream(os);
for (Map<String, String> fileInfo: fileList) {
String fileName = fileInfo.get("fileName");
String url = fileInfo.get("url");
if(fileNameCountMap.containsKey(fileName)){
Integer count = fileNameCountMap.get(fileName);
if(count > 0){
String tempName = FileUtil.getName(fileName) + "(" + count + ")";
fileName = fileName.replaceAll(FileUtil.getName(fileName),tempName);
}
fileNameCountMap.put(fileName,count+1);
}
// 跳过不包含指定键位的对象
if (StringUtils.isEmpty(url) || StringUtils.isEmpty(fileName)){
continue;
......
......@@ -2,7 +2,6 @@ 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.alibaba.fastjson.JSONObject;
import com.linkwechat.common.utils.StringUtils;
......@@ -10,6 +9,7 @@ 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.query.qr.WeQrCodeEventQuery;
import com.linkwechat.wecom.domain.vo.qr.WeQrScopePartyVo;
import com.linkwechat.wecom.domain.vo.qr.WeQrScopeUserVo;
import com.linkwechat.wecom.domain.vo.qr.WeQrScopeVo;
......@@ -17,7 +17,10 @@ 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.context.ApplicationListener;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Service;
import java.util.Arrays;
import java.util.Date;
......@@ -43,8 +46,8 @@ public class WeQrCodeUpdateTask {
@Autowired
private WeExternalContactClient externalContactClient;
public void qrCodeUpdateTask() {
List<WeQrScopeVo> weQrScopeList = weQrScopeService.getWeQrScopeByTime(DateUtil.formatDateTime(new Date()));
public void qrCodeUpdateTask(String qrCodeId) {
List<WeQrScopeVo> weQrScopeList = weQrScopeService.getWeQrScopeByTime(DateUtil.formatDateTime(new Date()),qrCodeId);
log.info("活码使用范围修改任务 weQrScopeList {}", JSONObject.toJSONString(weQrScopeList));
if (CollectionUtil.isNotEmpty(weQrScopeList)) {
Map<Long, List<WeQrScopeVo>> qrCodeMap = weQrScopeList.stream().collect(Collectors.groupingBy(WeQrScopeVo::getQrId));
......@@ -101,4 +104,17 @@ public class WeQrCodeUpdateTask {
}
}
}
@Service
public static class RefreshQrCodeHandle implements ApplicationListener<WeQrCodeEventQuery>{
@Autowired
private WeQrCodeUpdateTask weQrCodeUpdateTask;
@Async
@Override
public void onApplicationEvent(WeQrCodeEventQuery weQrCodeEventQuery) {
weQrCodeUpdateTask.qrCodeUpdateTask(weQrCodeEventQuery.getQrId());
}
}
}
package com.linkwechat.wecom.domain.query.qr;
import org.springframework.context.ApplicationEvent;
/**
* @author danmo
* @description
* @date 2021/11/21 19:52
**/
public class WeQrCodeEventQuery extends ApplicationEvent {
private String qrId;
public WeQrCodeEventQuery(Object source, String qrId) {
super(source);
this.qrId = qrId;
}
public String getQrId() {
return qrId;
}
public void setQrId(String qrId) {
this.qrId = qrId;
}
}
......@@ -24,6 +24,6 @@ public interface WeQrScopeMapper extends BaseMapper<WeQrScope> {
List<WeQrScopeVo> getWeQrScopeByQrIds(@Param("qrIds") List<Long> qrIds);
List<WeQrScopeVo> getWeQrScopeByTime(@Param("formatTime") String formatTime);
List<WeQrScopeVo> getWeQrScopeByTime(@Param("formatTime") String formatTime,@Param("qrId") String qrId);
}
......@@ -47,5 +47,5 @@ public interface IWeQrScopeService extends IService<WeQrScope> {
* 查询当前时间使用范围活码数据
* @return
*/
List<WeQrScopeVo> getWeQrScopeByTime(String formatTime);
List<WeQrScopeVo> getWeQrScopeByTime(String formatTime,String qrId);
}
......@@ -2,6 +2,7 @@ package com.linkwechat.wecom.service.event;
import com.linkwechat.wecom.domain.callback.WeCallBackEvent;
import com.linkwechat.wecom.domain.query.WeCustomerWelcomeQuery;
import com.linkwechat.wecom.domain.query.qr.WeQrCodeEventQuery;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.ApplicationEventPublisher;
import org.springframework.context.ApplicationEventPublisherAware;
......@@ -28,15 +29,23 @@ public class WeEventPublisherService implements ApplicationEventPublisherAware {
* 回调事件推送
*/
public void register(String message) {
log.info("回调事件推送:message:{}",message);
applicationEventPublisher.publishEvent(new WeCallBackEvent(this,message));
log.info("回调事件推送:message:{}", message);
applicationEventPublisher.publishEvent(new WeCallBackEvent(this, message));
}
/**
* 发布欢迎语事件
*/
public void register(String externalUserId, String userId, String welcomeCode, String state) {
log.info("发布发送欢迎语事件:externalUserId:{},userId:{},welcomeCode:{},state:{}",externalUserId,userId,welcomeCode,state);
applicationEventPublisher.publishEvent(new WeCustomerWelcomeQuery(this, externalUserId,userId,welcomeCode,state));
log.info("发布发送欢迎语事件:externalUserId:{},userId:{},welcomeCode:{},state:{}", externalUserId, userId, welcomeCode, state);
applicationEventPublisher.publishEvent(new WeCustomerWelcomeQuery(this, externalUserId, userId, welcomeCode, state));
}
/**
* 刷新活码
*/
public void refreshQrCode(String qrId) {
log.info("刷新活码任务:qrId:{}", qrId);
applicationEventPublisher.publishEvent(new WeQrCodeEventQuery(this, qrId));
}
}
......@@ -99,7 +99,7 @@ public class IWeQrScopeServiceImpl extends ServiceImpl<WeQrScopeMapper, WeQrScop
}
@Override
public List<WeQrScopeVo> getWeQrScopeByTime(String formatTime) {
return this.baseMapper.getWeQrScopeByTime(formatTime);
public List<WeQrScopeVo> getWeQrScopeByTime(String formatTime, String qrId) {
return this.baseMapper.getWeQrScopeByTime(formatTime,qrId);
}
}
......@@ -12,6 +12,7 @@ import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.linkwechat.common.core.page.PageDomain;
import com.linkwechat.common.core.page.TableSupport;
import com.linkwechat.common.enums.WeErrorCodeEnum;
import com.linkwechat.common.exception.wecom.WeComException;
import com.linkwechat.common.utils.DateUtils;
import com.linkwechat.common.utils.StringUtils;
......@@ -28,6 +29,7 @@ import com.linkwechat.wecom.domain.vo.qr.WeQrCodeScanCountVo;
import com.linkwechat.wecom.domain.vo.qr.WeQrScopeVo;
import com.linkwechat.wecom.mapper.WeQrCodeMapper;
import com.linkwechat.wecom.service.*;
import com.linkwechat.wecom.service.event.WeEventPublisherService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
......@@ -58,7 +60,8 @@ public class WeQrCodeServiceImpl extends ServiceImpl<WeQrCodeMapper, WeQrCode> i
@Autowired
private IWeCustomerService weCustomerService;
@Autowired
private WeEventPublisherService weEventPublisherService;
/**
* 新增员工活码
*
......@@ -80,6 +83,9 @@ public class WeQrCodeServiceImpl extends ServiceImpl<WeQrCodeMapper, WeQrCode> i
//保存活码素材
attachmentsService.saveBatchByQrId(weQrCode.getId(), weQrAddQuery.getAttachments());
}
weEventPublisherService.refreshQrCode(String.valueOf(weQrCode.getId()));
}else {
throw new WeComException(resultDto.getErrcode(), WeErrorCodeEnum.parseEnum(resultDto.getErrcode()).getErrorMsg());
}
}
......@@ -99,6 +105,9 @@ public class WeQrCodeServiceImpl extends ServiceImpl<WeQrCodeMapper, WeQrCode> i
//修改活码素材
attachmentsService.updateBatchByQrId(weQrCode.getId(), weQrAddQuery.getAttachments());
}
weEventPublisherService.refreshQrCode(String.valueOf(weQrCode.getId()));
}else {
throw new WeComException(resultDto.getErrcode(), WeErrorCodeEnum.parseEnum(resultDto.getErrcode()).getErrorMsg());
}
}
......
......@@ -79,6 +79,9 @@
where find_in_set(dayofweek(curdate())-1,wqs.work_cycle)
and date_format(concat(date_format(curdate(),'%Y-%m-%d '),wqs.begin_time), '%H:%i:%s') &lt;= date_format(#{formatTime},'%H:%i:%s')
and date_format(concat(date_format(curdate(),'%Y-%m-%d '),wqs.end_time), '%H:%i:%s') &gt;= date_format(#{formatTime},'%H:%i:%s')
<if test="qrId != null and qrId != ''">
and wqs.qr_id = #{qrId}
</if>
and wqs.del_flag = 0
</select>
</mapper>
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!