Commit 01efc6d8 by danmo

员工活码新增二维码添加客户数据统计

1 parent 538422fc
...@@ -10,11 +10,11 @@ import com.linkwechat.common.exception.wecom.WeComException; ...@@ -10,11 +10,11 @@ import com.linkwechat.common.exception.wecom.WeComException;
import com.linkwechat.common.utils.StringUtils; import com.linkwechat.common.utils.StringUtils;
import com.linkwechat.common.utils.file.FileUtils; import com.linkwechat.common.utils.file.FileUtils;
import com.linkwechat.wecom.domain.WeEmpleCode; import com.linkwechat.wecom.domain.WeEmpleCode;
import com.linkwechat.wecom.domain.WeEmpleCodeUseScop; import com.linkwechat.wecom.domain.WeFlowerCustomerRel;
import com.linkwechat.wecom.service.IWeEmpleCodeService; import com.linkwechat.wecom.service.IWeEmpleCodeService;
import com.linkwechat.wecom.service.IWeFlowerCustomerRelService;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.util.CollectionUtils;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
...@@ -40,6 +40,8 @@ import java.util.zip.ZipOutputStream; ...@@ -40,6 +40,8 @@ import java.util.zip.ZipOutputStream;
public class WeEmpleCodeController extends BaseController { public class WeEmpleCodeController extends BaseController {
@Autowired @Autowired
private IWeEmpleCodeService weEmpleCodeService; private IWeEmpleCodeService weEmpleCodeService;
@Autowired
private IWeFlowerCustomerRelService weFlowerCustomerRelService;
/** /**
* 查询员工活码列表 * 查询员工活码列表
...@@ -192,4 +194,16 @@ public class WeEmpleCodeController extends BaseController { ...@@ -192,4 +194,16 @@ public class WeEmpleCodeController extends BaseController {
e.printStackTrace(); e.printStackTrace();
} }
} }
/**
* 成员添加客户统计
* @return
*/
@PreAuthorize("@ss.hasPermi('wecom:code:getUserAddCustomerStat')")
@Log(title = "成员添加客户统计", businessType = BusinessType.OTHER)
@GetMapping("/getUserAddCustomerStat")
public AjaxResult getUserAddCustomerStat(WeFlowerCustomerRel weFlowerCustomerRel){
return AjaxResult.success(weFlowerCustomerRelService.getUserAddCustomerStat(weFlowerCustomerRel));
}
} }
...@@ -3,7 +3,11 @@ package com.linkwechat.common.utils; ...@@ -3,7 +3,11 @@ package com.linkwechat.common.utils;
import java.lang.management.ManagementFactory; import java.lang.management.ManagementFactory;
import java.text.ParseException; import java.text.ParseException;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date; import java.util.Date;
import java.util.List;
import org.apache.commons.lang3.time.DateFormatUtils; import org.apache.commons.lang3.time.DateFormatUtils;
/** /**
...@@ -160,5 +164,29 @@ public class DateUtils extends org.apache.commons.lang3.time.DateUtils ...@@ -160,5 +164,29 @@ public class DateUtils extends org.apache.commons.lang3.time.DateUtils
return endDate.getTime() - nowDate.getTime(); return endDate.getTime() - nowDate.getTime();
} }
/**
* 获取时间段内所有日期
* @param dBegin
* @param dEnd
* @return
*/
public static List<Date> findDates(Date dBegin, Date dEnd)
{
List lDate = new ArrayList();
lDate.add(dBegin);
Calendar calBegin = Calendar.getInstance();
// 使用给定的 Date 设置此 Calendar 的时间
calBegin.setTime(dBegin);
Calendar calEnd = Calendar.getInstance();
// 使用给定的 Date 设置此 Calendar 的时间
calEnd.setTime(dEnd);
// 测试此日期是否在指定日期之后
while (dEnd.after(calBegin.getTime()))
{
// 根据日历的规则,为给定的日历字段添加或减去指定的时间量
calBegin.add(Calendar.DAY_OF_MONTH, 1);
lDate.add(calBegin.getTime());
}
return lDate;
}
} }
package com.linkwechat.wecom.domain; package com.linkwechat.wecom.domain;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField; import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId; import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName; import com.baomidou.mybatisplus.annotation.TableName;
import com.fasterxml.jackson.annotation.JsonFormat; import com.fasterxml.jackson.annotation.JsonFormat;
import com.linkwechat.common.core.domain.BaseEntity;
import com.linkwechat.common.utils.SnowFlakeUtil; import com.linkwechat.common.utils.SnowFlakeUtil;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import lombok.Builder; import lombok.Builder;
import lombok.Data; import lombok.Data;
import lombok.NoArgsConstructor; import lombok.NoArgsConstructor;
import org.springframework.format.annotation.DateTimeFormat;
import java.util.Date; import java.util.Date;
import java.util.List; import java.util.List;
...@@ -82,4 +81,12 @@ public class WeFlowerCustomerRel ...@@ -82,4 +81,12 @@ public class WeFlowerCustomerRel
private String department; private String department;
@TableField(exist = false)
private String beginTime;
@TableField(exist = false)
private String endTime;
} }
package com.linkwechat.wecom.mapper; package com.linkwechat.wecom.mapper;
import java.util.List; import java.util.List;
import java.util.Map;
import com.alibaba.fastjson.JSONArray;
import com.baomidou.mybatisplus.core.mapper.BaseMapper; import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.linkwechat.wecom.domain.WeFlowerCustomerRel; import com.linkwechat.wecom.domain.WeFlowerCustomerRel;
import org.apache.ibatis.annotations.Param; import org.apache.ibatis.annotations.Param;
...@@ -77,4 +79,11 @@ public interface WeFlowerCustomerRelMapper extends BaseMapper<WeFlowerCustomerRe ...@@ -77,4 +79,11 @@ public interface WeFlowerCustomerRelMapper extends BaseMapper<WeFlowerCustomerRe
* @return * @return
*/ */
public int batchLogicDeleteByIds(@Param("ids") List<Long> ids); public int batchLogicDeleteByIds(@Param("ids") List<Long> ids);
/**
* 成员添加客户统计
* @param weFlowerCustomerRel
* @return
*/
public List<Map<String,Object>> getUserAddCustomerStat(WeFlowerCustomerRel weFlowerCustomerRel);
} }
package com.linkwechat.wecom.service; package com.linkwechat.wecom.service;
import java.util.List; import java.util.List;
import java.util.Map;
import com.baomidou.mybatisplus.extension.service.IService; import com.baomidou.mybatisplus.extension.service.IService;
import com.linkwechat.wecom.domain.WeFlowerCustomerRel; import com.linkwechat.wecom.domain.WeFlowerCustomerRel;
...@@ -19,4 +20,12 @@ public interface IWeFlowerCustomerRelService extends IService<WeFlowerCustomerRe ...@@ -19,4 +20,12 @@ public interface IWeFlowerCustomerRelService extends IService<WeFlowerCustomerRe
* @param externalUserid 用户id * @param externalUserid 用户id
*/ */
public Boolean deleteFollowUser(String userId, String externalUserid); public Boolean deleteFollowUser(String userId, String externalUserid);
/**
* 成员添加客户统计
* @param weFlowerCustomerRel
* @return Map
*/
public Map<String,Object> getUserAddCustomerStat(WeFlowerCustomerRel weFlowerCustomerRel);
} }
...@@ -2,29 +2,80 @@ package com.linkwechat.wecom.service.impl; ...@@ -2,29 +2,80 @@ package com.linkwechat.wecom.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.linkwechat.common.utils.DateUtils;
import com.linkwechat.wecom.domain.WeFlowerCustomerRel; import com.linkwechat.wecom.domain.WeFlowerCustomerRel;
import com.linkwechat.wecom.mapper.WeFlowerCustomerRelMapper; import com.linkwechat.wecom.mapper.WeFlowerCustomerRelMapper;
import com.linkwechat.wecom.service.IWeFlowerCustomerRelService; import com.linkwechat.wecom.service.IWeFlowerCustomerRelService;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import java.util.*;
import java.util.concurrent.atomic.AtomicLong;
import java.util.stream.Collectors;
/** /**
* 具有外部联系人功能企业员工也客户的关系Service业务层处理 * 具有外部联系人功能企业员工也客户的关系Service业务层处理
* *
* @author ruoyi * @author ruoyi
* @date 2020-09-19 * @date 2020-09-19
*/ */
@Service @Service
public class WeFlowerCustomerRelServiceImpl extends ServiceImpl<WeFlowerCustomerRelMapper,WeFlowerCustomerRel> implements IWeFlowerCustomerRelService public class WeFlowerCustomerRelServiceImpl extends ServiceImpl<WeFlowerCustomerRelMapper, WeFlowerCustomerRel> implements IWeFlowerCustomerRelService {
{
@Override @Override
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = Exception.class)
public Boolean deleteFollowUser(String userId, String externalUserid) { public Boolean deleteFollowUser(String userId, String externalUserid) {
return this.update(WeFlowerCustomerRel.builder().status("1").build() return this.update(WeFlowerCustomerRel.builder().status("1").build()
,new LambdaQueryWrapper<WeFlowerCustomerRel>() , new LambdaQueryWrapper<WeFlowerCustomerRel>()
.eq(WeFlowerCustomerRel::getUserId,userId) .eq(WeFlowerCustomerRel::getUserId, userId)
.eq(WeFlowerCustomerRel::getExternalUserid,externalUserid)); .eq(WeFlowerCustomerRel::getExternalUserid, externalUserid));
}
@Override
public Map<String, Object> getUserAddCustomerStat(WeFlowerCustomerRel weFlowerCustomerRel) {
Map<String, Object> resultMap = new HashMap<>(16);
List<String> dateList = new ArrayList<>();
List<Long> statList = new ArrayList<>();
Long resultTotal = 0L;
List<Map<String, Object>> userAddCustomerStatList = this.baseMapper.getUserAddCustomerStat(weFlowerCustomerRel);
String beginTime = weFlowerCustomerRel.getBeginTime();
String endTime = weFlowerCustomerRel.getEndTime();
if (beginTime != null && endTime != null) {
Date beginDate = DateUtils.dateTime(DateUtils.YYYY_MM_DD, beginTime);
Date endDate = DateUtils.dateTime(DateUtils.YYYY_MM_DD, endTime);
List<Date> dates = DateUtils.findDates(beginDate, endDate);
dateList = dates.stream().map(date -> DateUtils.dateTime(date)).collect(Collectors.toList());
Optional.ofNullable(dateList).orElseGet(ArrayList::new).forEach(date -> {
AtomicLong total = new AtomicLong(0);
Optional.ofNullable(userAddCustomerStatList).orElseGet(ArrayList::new).forEach(statInfo -> {
if (date.equals(statInfo.get("createTime"))) {
total.set((Long) statInfo.get("total"));
return;
}
});
statList.add(total.get());
});
resultTotal = statList.stream().mapToLong(Long::longValue).sum();
} else {
dateList.addAll(Optional.ofNullable(userAddCustomerStatList).orElseGet(ArrayList::new)
.stream()
.filter(statInfo -> null != statInfo.get("createTime"))
.map(statInfo -> (String) statInfo.get("createTime")).collect(Collectors.toList()));
statList.addAll(Optional.ofNullable(userAddCustomerStatList).orElseGet(ArrayList::new)
.stream()
.filter(statInfo -> null != statInfo.get("total"))
.map(statInfo -> (Long) statInfo.get("total")).collect(Collectors.toList()));
resultTotal = Optional.ofNullable(userAddCustomerStatList).orElseGet(ArrayList::new)
.stream()
.filter(statInfo -> null != statInfo.get("total"))
.mapToLong(statInfo -> (Long) statInfo.get("total")).sum();
}
resultMap.put("dateList", dateList);
resultMap.put("statList", statList);
resultMap.put("total", resultTotal);
return resultMap;
} }
} }
...@@ -118,4 +118,22 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" ...@@ -118,4 +118,22 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
</foreach> </foreach>
</update> </update>
<select id="getUserAddCustomerStat" parameterType="WeFlowerCustomerRel" resultType="java.util.HashMap">
select
left(wfcr.create_time,10) as createTime , count(1) as total
from
we_flower_customer_rel wfcr
<where>
<if test="userId != null and userId != ''">and wfcr.user_id = #{userId}</if>
<if test="addWay != null and addWay != ''">and wfcr.add_way = #{addWay}</if>
<if test="beginTime != null and beginTime != ''"><!-- 开始时间检索 -->
AND date_format(wfcr.create_time,'%y%m%d') &gt;= date_format(#{beginTime},'%y%m%d')
</if>
<if test="endTime != null and endTime != ''"><!-- 结束时间检索 -->
AND date_format(wfcr.create_time,'%y%m%d') &lt;= date_format(#{endTime},'%y%m%d')
</if>
</where>
group by
left(wfcr.create_time,10)
</select>
</mapper> </mapper>
\ No newline at end of file \ 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!