Commit ea3ded1d by danmo

重构员工活码

1 parent b7982c24
......@@ -5,6 +5,7 @@ import cn.hutool.core.lang.Snowflake;
import cn.hutool.core.util.IdUtil;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.RandomUtil;
import com.baomidou.mybatisplus.annotation.TableField;
import com.linkwechat.common.constant.WeConstans;
import com.linkwechat.wecom.domain.WeMessageTemplate;
import com.linkwechat.wecom.domain.WeQrCode;
......@@ -13,6 +14,7 @@ import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import org.apache.commons.lang3.BooleanUtils;
import org.apache.commons.lang3.StringUtils;
import java.util.List;
......@@ -25,6 +27,9 @@ import java.util.List;
@Data
public class WeQrAddQuery {
@ApiModelProperty("活码Id")
private Long qrId;
@ApiModelProperty("名称")
private String qrName;
......@@ -50,12 +55,8 @@ public class WeQrAddQuery {
private List<WeMessageTemplate> attachments;
@ApiModelProperty(value = "渠道",hidden = true)
private static String state;
private String state;
static {
Snowflake snowflake = IdUtil.getSnowflake(RandomUtil.randomLong(6), RandomUtil.randomInt(6));
state = snowflake.nextIdStr();
}
/**
......@@ -64,13 +65,16 @@ public class WeQrAddQuery {
* @return 企微接口参数实体类
*/
public WeExternalContactDto.WeContactWay getWeContactWay() {
Snowflake snowflake = IdUtil.getSnowflake(RandomUtil.randomLong(6), RandomUtil.randomInt(6));
this.state = snowflake.nextIdStr();
WeExternalContactDto.WeContactWay weContactWay = new WeExternalContactDto.WeContactWay();
//根据类型生成相应的活码
if(this.qrId == null){
weContactWay.setState(WeConstans.WE_QR_CODE_PREFIX + "_" + state);
}
weContactWay.setType(this.qrType);
weContactWay.setScene(WeConstans.QR_CODE_EMPLE_CODE_SCENE);
weContactWay.setSkip_verify(BooleanUtils.toBoolean(this.qrAutoAdd));
weContactWay.setState(WeConstans.WE_QR_CODE_PREFIX + "_" + state);
if (CollectionUtil.isNotEmpty(qrUserInfos)) {
//员工列表
String[] userIdArr = qrUserInfos.stream().filter(item ->
......@@ -97,12 +101,15 @@ public class WeQrAddQuery {
*/
public WeQrCode getWeQrCodeEntity(String configId, String qrCode){
WeQrCode weQrCode = new WeQrCode();
weQrCode.setId(this.qrId);
weQrCode.setName(this.qrName);
weQrCode.setAutoAdd(this.qrAutoAdd);
weQrCode.setGroupId(this.getQrGroupId());
weQrCode.setType(this.qrType);
weQrCode.setRuleType(this.qrRuleType);
weQrCode.setState(state);
if(this.qrId == null){
weQrCode.setState(state);
}
weQrCode.setConfigId(configId);
weQrCode.setQrCode(qrCode);
return weQrCode;
......
package com.linkwechat.wecom.domain.query.qr;
import com.linkwechat.common.core.domain.BaseEntity;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
/**
* @author danmo
* @description 活码列表入参
* @date 2021/11/9 13:58
**/
@ApiModel
@Data
public class WeQrCodeListQuery extends BaseEntity {
@ApiModelProperty("活码Id")
private Long qrId;
@ApiModelProperty("活码名称")
private String qrName;
@ApiModelProperty("员工名称")
private String qrUserName;
}
package com.linkwechat.wecom.domain.query.qr;
import com.baomidou.mybatisplus.annotation.TableField;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
......@@ -15,6 +16,9 @@ import java.util.List;
@Data
public class WeQrUserInfoQuery {
@ApiModelProperty(value = "排期分组id(修改接口时传)")
private String scopeId;
@ApiModelProperty("排班员工类型 1-默认 2-自定义")
private Integer type;
......
package com.linkwechat.wecom.domain.vo.qr;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.util.List;
/**
* @author danmo
* @description 活码统计出参
* @date 2021/11/11 0:36
**/
@ApiModel
@Data
public class WeQrCodeScanCountVo {
@ApiModelProperty("今日扫码次数")
private Integer today;
@ApiModelProperty("累计扫码次数")
private Integer total;
@ApiModelProperty("时间横坐标")
private List<String> xAxis;
@ApiModelProperty("扫码次数纵坐标")
private List<Integer> yAxis;
}
......@@ -3,6 +3,7 @@ package com.linkwechat.wecom.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.linkwechat.wecom.domain.WeQrCode;
import com.linkwechat.wecom.domain.query.qr.WeQrCodeListQuery;
import com.linkwechat.wecom.domain.vo.qr.WeQrCodeDetailVo;
import org.apache.ibatis.annotations.Mapper;
import org.springframework.stereotype.Repository;
......@@ -32,5 +33,12 @@ public interface WeQrCodeMapper extends BaseMapper<WeQrCode> {
* @return
*/
List<WeQrCodeDetailVo> getQrDetailByQrIds(List<Long> qrIds);
/**
* 查询活码列表id
* @param qrCodeListQuery
* @return
*/
List<Long> getQrCodeList(WeQrCodeListQuery qrCodeListQuery);
}
......@@ -30,4 +30,11 @@ public interface IWeQrAttachmentsService extends IService<WeQrAttachments> {
* @return
*/
Boolean delBatchByQrIds(List<Long> qrIds);
/**
* 通过活码id批量修改活码欢迎语素材
* @param qrId 活码id
* @param attachments 素材列表
*/
void updateBatchByQrId(Long qrId, List<WeMessageTemplate> attachments);
}
package com.linkwechat.wecom.service;
import com.baomidou.mybatisplus.extension.service.IService;
import com.github.pagehelper.PageInfo;
import com.linkwechat.wecom.domain.WeQrCode;
import com.linkwechat.wecom.domain.query.qr.WeQrAddQuery;
import com.linkwechat.wecom.domain.query.qr.WeQrCodeListQuery;
import com.linkwechat.wecom.domain.vo.qr.WeQrCodeDetailVo;
import com.linkwechat.wecom.domain.vo.qr.WeQrCodeScanCountVo;
import java.util.List;
......@@ -22,6 +25,12 @@ public interface IWeQrCodeService extends IService<WeQrCode> {
void addQrCode(WeQrAddQuery weQrAddQuery);
/**
* 修改员工活码
* @param weQrAddQuery 入参
*/
void updateQrCode(WeQrAddQuery weQrAddQuery);
/**
* 获取活码详情
* @param qrId
* @return
......@@ -29,7 +38,22 @@ public interface IWeQrCodeService extends IService<WeQrCode> {
WeQrCodeDetailVo getQrDetail(Long qrId);
/**
* 获取活码列表
* @return list
*/
PageInfo<WeQrCodeDetailVo> getQrCodeList(WeQrCodeListQuery qrCodeListQuery);
/**
* 删除活码
*/
void delQrCode(List<Long> qrIds);
/**
* 获取活码统计
* @param qrCodeListQuery 入参
* @return WeQrCodeScanCountVo
*/
WeQrCodeScanCountVo getWeQrCodeScanCount(WeQrCodeListQuery qrCodeListQuery);
}
......@@ -30,4 +30,11 @@ public interface IWeQrScopeService extends IService<WeQrScope> {
* @return
*/
Boolean delBatchByQrIds(List<Long> qrIds);
/**
* 通过活码id批量修改适用范围
* @param qrId 活码id
* @param qrUserInfos 适用范围列表
*/
void updateBatchByQrId(Long qrId, List<WeQrUserInfoQuery> qrUserInfos);
}
......@@ -18,8 +18,8 @@ public interface IWeQrTagRelService extends IService<WeQrTagRel> {
/**
* 通过活码id批量保存活码标签
* @param qrId
* @param qrTags
* @param qrId 活码id
* @param qrTags 标签id
*/
void saveBatchByQrId(Long qrId, List<String> qrTags);
......@@ -28,4 +28,11 @@ public interface IWeQrTagRelService extends IService<WeQrTagRel> {
* @param qrIds
*/
Boolean delBatchByQrIds(List<Long> qrIds);
/**
* 通过活码id批量修改活码标签
* @param qrId 活码id
* @param qrTags 标签id
*/
void updateBatchByQrId(Long qrId, List<String> qrTags);
}
package com.linkwechat.wecom.service.impl;
import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.collection.ListUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.linkwechat.wecom.domain.WeMessageTemplate;
......@@ -42,4 +43,10 @@ public class IWeQrAttachmentsServiceImpl extends ServiceImpl<WeQrAttachmentsMapp
weQrAttachments.setDelFlag(1);
return this.update(weQrAttachments,new LambdaQueryWrapper<WeQrAttachments>().in(WeQrAttachments::getQrId,qrIds));
}
@Override
public void updateBatchByQrId(Long qrId, List<WeMessageTemplate> attachments) {
delBatchByQrIds(ListUtil.toList(qrId));
saveBatchByQrId(qrId,attachments);
}
}
package com.linkwechat.wecom.service.impl;
import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.collection.ListUtil;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.RandomUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.linkwechat.common.utils.StringUtils;
import com.linkwechat.wecom.domain.query.qr.WeQrUserInfoQuery;
import org.springframework.stereotype.Service;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
......@@ -74,4 +77,12 @@ public class IWeQrScopeServiceImpl extends ServiceImpl<WeQrScopeMapper, WeQrScop
weQrScope.setDelFlag(1);
return this.update(weQrScope,new LambdaQueryWrapper<WeQrScope>().in(WeQrScope::getQrId,qrIds));
}
@Override
public void updateBatchByQrId(Long qrId, List<WeQrUserInfoQuery> qrUserInfos) {
if(CollectionUtil.isNotEmpty(qrUserInfos)){
delBatchByQrIds(ListUtil.toList(qrId));
this.saveBatchByQrId(qrId,qrUserInfos);
}
}
}
package com.linkwechat.wecom.service.impl;
import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.collection.ListUtil;
import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
......@@ -40,4 +43,10 @@ public class IWeQrTagRelServiceImpl extends ServiceImpl<WeQrTagRelMapper, WeQrTa
weQrTagRel.setDelFlag(1);
return this.update(weQrTagRel, new LambdaQueryWrapper<WeQrTagRel>().in(WeQrTagRel::getQrId,qrIds));
}
@Override
public void updateBatchByQrId(Long qrId, List<String> qrTags) {
this.delBatchByQrIds(ListUtil.toList(qrId));
this.saveBatchByQrId(qrId,qrTags);
}
}
......@@ -5,25 +5,27 @@ import cn.hutool.core.date.DateTime;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.thread.ThreadUtil;
import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.pagehelper.PageInfo;
import com.linkwechat.common.exception.wecom.WeComException;
import com.linkwechat.common.utils.StringUtils;
import com.linkwechat.wecom.client.WeExternalContactClient;
import com.linkwechat.wecom.domain.WeCustomer;
import com.linkwechat.wecom.domain.WeQrCode;
import com.linkwechat.wecom.domain.WeQrScope;
import com.linkwechat.wecom.domain.dto.WeExternalContactDto;
import com.linkwechat.wecom.domain.query.qr.WeQrAddQuery;
import com.linkwechat.wecom.domain.query.qr.WeQrCodeListQuery;
import com.linkwechat.wecom.domain.query.qr.WeQrUserInfoQuery;
import com.linkwechat.wecom.domain.vo.qr.WeQrCodeDetailVo;
import com.linkwechat.wecom.domain.vo.qr.WeQrScopeVo;
import com.linkwechat.wecom.domain.vo.tag.WeTagVo;
import com.linkwechat.wecom.domain.vo.qr.WeQrCodeScanCountVo;
import com.linkwechat.wecom.mapper.WeQrCodeMapper;
import com.linkwechat.wecom.service.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
/**
......@@ -48,7 +50,8 @@ public class WeQrCodeServiceImpl extends ServiceImpl<WeQrCodeMapper, WeQrCode> i
private IWeQrAttachmentsService attachmentsService;
@Autowired
private IWeTagService weTagService;
private IWeCustomerService weCustomerService;
/**
* 新增员工活码
......@@ -75,10 +78,45 @@ public class WeQrCodeServiceImpl extends ServiceImpl<WeQrCodeMapper, WeQrCode> i
}
@Override
public void updateQrCode(WeQrAddQuery weQrAddQuery) {
//校验排期是否存在冲突
checkScope(weQrAddQuery.getQrUserInfos());
WeExternalContactDto.WeContactWay weContactWay = weQrAddQuery.getWeContactWay();
WeExternalContactDto resultDto = externalContactClient.updateContactWay(weContactWay);
if (resultDto != null && ObjectUtil.equal(0, resultDto.getErrcode())) {
WeQrCode weQrCode = weQrAddQuery.getWeQrCodeEntity(null, null);
if (updateById(weQrCode)) {
//修改标签数据
tagRelService.updateBatchByQrId(weQrCode.getId(), weQrAddQuery.getQrTags());
//修改活码范围数据
scopeService.updateBatchByQrId(weQrCode.getId(), weQrAddQuery.getQrUserInfos());
//修改活码素材
attachmentsService.updateBatchByQrId(weQrCode.getId(), weQrAddQuery.getAttachments());
}
}
}
@Override
public WeQrCodeDetailVo getQrDetail(Long qrId) {
return this.baseMapper.getQrDetailByQrId(qrId);
}
@Override
public PageInfo<WeQrCodeDetailVo> getQrCodeList(WeQrCodeListQuery qrCodeListQuery) {
List<WeQrCodeDetailVo> weQrCodeList = new ArrayList<>();
List<Long> qrCodeIdList = this.baseMapper.getQrCodeList(qrCodeListQuery);
if(CollectionUtil.isNotEmpty(qrCodeIdList)){
List<WeQrCodeDetailVo> qrDetailByQrIds = this.baseMapper.getQrDetailByQrIds(qrCodeIdList);
weQrCodeList.addAll(qrDetailByQrIds);
}
PageInfo<Long> pageIdInfo = new PageInfo<>(qrCodeIdList);
PageInfo<WeQrCodeDetailVo> pageInfo = new PageInfo<>(weQrCodeList);
pageInfo.setTotal(pageIdInfo.getTotal());
pageInfo.setPageNum(pageIdInfo.getPageNum());
pageInfo.setPageSize(pageIdInfo.getPageSize());
return pageInfo;
}
@Override
public void delQrCode(List<Long> qrIds) {
......@@ -102,6 +140,18 @@ public class WeQrCodeServiceImpl extends ServiceImpl<WeQrCodeMapper, WeQrCode> i
}
}
@Override
public WeQrCodeScanCountVo getWeQrCodeScanCount(WeQrCodeListQuery qrCodeListQuery) {
Long qrId = qrCodeListQuery.getQrId();
String beginTime = qrCodeListQuery.getBeginTime();
String endTime = qrCodeListQuery.getEndTime();
WeQrCode weQrCode = getById(qrId);
String state = weQrCode.getState();
//todo 计算
//weCustomerService.list(new LambdaQueryWrapper<WeCustomer>().eq(WeCustomer::getStatus))
return null;
}
/**
* 校验排期是否重复
*
......
......@@ -123,4 +123,26 @@
</if>
</select>
<select id="getQrCodeList" resultType="java.lang.Long">
select
wqc.id
from we_qr_code wqc
left join we_qr_tag_rel wqtr on wqtr.qr_id = wqc.id and wqtr.del_flag = 0
left join we_qr_scope wqs on wqs.qr_id = wqc.id and wqs.del_flag = 0
left join we_qr_attachments wqa on wqa.qr_id = wqc.id and wqs.del_flag = 0
where 1=1
<if test="qrName != null and qrName != ''">
and wqc.name like concat('%', #{qrName}, '%')
</if>
<if test="qrUserName != null and qrUserName != ''">
and exists (select 1 from we_user wu where wu.user_id = wqs.user_id and wu.user_name like concat('%', #{qrUserName}, '%'))
</if>
<if test="beginTime != null and beginTime != ''"><!-- 开始时间检索 -->
AND date_format(wqc.create_time,'%y%m%d') &gt;= date_format(#{beginTime},'%y%m%d')
</if>
<if test="endTime != null and endTime != ''"><!-- 结束时间检索 -->
AND date_format(wqc.create_time,'%y%m%d') &lt;= date_format(#{endTime},'%y%m%d')
</if>
</select>
</mapper>
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!