|
|
@@ -4,9 +4,8 @@ import com.goafanti.admin.bo.*;
|
|
|
import com.goafanti.admin.service.AdminStatisticsService;
|
|
|
import com.goafanti.common.constant.AFTConstants;
|
|
|
import com.goafanti.common.dao.*;
|
|
|
-import com.goafanti.common.model.Admin;
|
|
|
-import com.goafanti.common.model.AdminUserCount;
|
|
|
-import com.goafanti.common.model.SalesTeam;
|
|
|
+import com.goafanti.common.error.BusinessException;
|
|
|
+import com.goafanti.common.model.*;
|
|
|
import com.goafanti.common.utils.DateUtils;
|
|
|
import com.goafanti.common.utils.LoggerUtils;
|
|
|
import com.goafanti.core.shiro.token.TokenManager;
|
|
|
@@ -16,6 +15,10 @@ import org.springframework.stereotype.Service;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
import java.math.BigDecimal;
|
|
|
+import java.math.RoundingMode;
|
|
|
+import java.time.LocalDate;
|
|
|
+import java.time.ZoneId;
|
|
|
+import java.time.format.DateTimeFormatter;
|
|
|
import java.util.*;
|
|
|
|
|
|
@Service
|
|
|
@@ -38,7 +41,7 @@ public class AdminStatisticsServiceImpl implements AdminStatisticsService {
|
|
|
@Resource
|
|
|
private UserFollowMapper userFollowMapper;
|
|
|
@Resource
|
|
|
- private NewOrderDunMapper newOrderDunMapper;
|
|
|
+ private DepartmentMapper departmentMapper;
|
|
|
|
|
|
|
|
|
@Override
|
|
|
@@ -428,6 +431,8 @@ public class AdminStatisticsServiceImpl implements AdminStatisticsService {
|
|
|
return 1;
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+
|
|
|
private void addSonTeam(List<SalesTeamBo>list, SalesTeamBo salesTeamBo, String startTime, String endTime) {
|
|
|
List<SalesTeam> salesTeams = salesTeamMapper.queryBySuperId(salesTeamBo.getId());
|
|
|
|
|
|
@@ -522,4 +527,157 @@ public class AdminStatisticsServiceImpl implements AdminStatisticsService {
|
|
|
this.endDay = endDay;
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 月份数据
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public Map<String,Object> monthData(String dateStr) {
|
|
|
+ DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
|
|
|
+ LocalDate localDate =LocalDate.parse(dateStr,formatter);
|
|
|
+ LocalDate endDate = localDate.plusMonths(1);
|
|
|
+ List<PublicRelease> publicReleases = publicReleaseMapper.selectByMonth(localDate, endDate,null);
|
|
|
+ List<PublicRelease> publicReleases2 = publicReleaseMapper.selectByMonth(localDate, endDate,1);
|
|
|
+ List<AdminPublicDuration> list=new ArrayList<>();
|
|
|
+ List<String> errors=new ArrayList<>();
|
|
|
+ for (PublicRelease e : publicReleases) {
|
|
|
+ AdminPublicDuration a = new AdminPublicDuration();
|
|
|
+ pushAdminNameAndProvince(e.getAid(),a);
|
|
|
+ //计算时间差,再加一天就是一共多少天
|
|
|
+ long daysBetween = DateUtils.getDaysBetween(e.getReleaseStart(), e.getReleaseEnd());
|
|
|
+ daysBetween+=1;
|
|
|
+ if (daysBetween==1){
|
|
|
+ a.setId(e.getAid());
|
|
|
+ a.setDate(e.getReleaseStart());
|
|
|
+ a.setDuration(e.getDuration());
|
|
|
+ list.add(a);
|
|
|
+ }else if(daysBetween>0){
|
|
|
+ double v = e.getDuration() / daysBetween;
|
|
|
+ for (int i = 0; i < daysBetween; i++) {
|
|
|
+ LocalDate localDate1 = e.getReleaseStart().toInstant().atZone(ZoneId.systemDefault()).toLocalDate().plusDays(i);
|
|
|
+ if (localDate1.isBefore(endDate)){
|
|
|
+ a.setId(e.getAid());
|
|
|
+ a.setDate(Date.from(localDate1.atStartOfDay(ZoneId.systemDefault()).toInstant()));
|
|
|
+ a.setDuration(v);
|
|
|
+ list.add(a);
|
|
|
+ }else{
|
|
|
+ errors.add(String.format("用户[%s]公出时间[%s]超出[%s],不计入本月公出",a.getName(),localDate1.format(formatter),endDate.format(formatter)));
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ for (PublicRelease e : publicReleases2) {
|
|
|
+ AdminPublicDuration a = new AdminPublicDuration();
|
|
|
+ pushAdminNameAndProvince(e.getAid(),a);
|
|
|
+ long daysBetween = DateUtils.getDaysBetween(e.getReleaseStart(), e.getReleaseEnd());
|
|
|
+ if(daysBetween>0){
|
|
|
+ double v = e.getDuration() / daysBetween;
|
|
|
+ for (int i = 0; i < daysBetween; i++) {
|
|
|
+ LocalDate localDate1 = e.getReleaseStart().toInstant().atZone(ZoneId.systemDefault()).toLocalDate().plusDays(i);
|
|
|
+ if (localDate1.isAfter(localDate)){
|
|
|
+ a.setId(e.getAid());
|
|
|
+ a.setDate(Date.from(localDate1.atStartOfDay(ZoneId.systemDefault()).toInstant()));
|
|
|
+ a.setDuration(v);
|
|
|
+ list.add(a);
|
|
|
+ }else{
|
|
|
+ errors.add(String.format("用户[%s]公出时间[%s]小于[%s],不计入本月公出",a.getName(),localDate1.format(formatter),endDate.format(formatter)));
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ //将数据统计到人
|
|
|
+ Map<String, BigDecimal> durationMap = new HashMap<>();
|
|
|
+ for (AdminPublicDuration e : list) {
|
|
|
+ String id = e.getId(); // 假设 AdminStatisticsBo 有一个 getId() 方法
|
|
|
+ BigDecimal duration = BigDecimal.valueOf(e.getDuration()); // 假设 AdminStatisticsBo 有一个 getCallDurationSum() 方法
|
|
|
+ if (durationMap.containsKey(id)) {
|
|
|
+ BigDecimal currentDuration = durationMap.get(id);
|
|
|
+ durationMap.put(id, currentDuration.add(duration));
|
|
|
+ } else {
|
|
|
+ durationMap.put(id, duration);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ List<AdminPublicDuration> list2=sumDurationsById(list);
|
|
|
+ Map<String,Object> map=new HashMap<>();
|
|
|
+ map.put("date",list);
|
|
|
+ map.put("count",list2);
|
|
|
+ map.put("errors",errors);
|
|
|
+ return map;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ private void pushAdminNameAndProvince(String aid, AdminPublicDuration a) {
|
|
|
+ Admin admin = adminMapper.queryById(aid);
|
|
|
+ Department department = departmentMapper.selectByPrimaryKey(admin.getDepartmentId());
|
|
|
+ String name = admin.getName();
|
|
|
+ // 去掉括号及其内部的内容
|
|
|
+ if (name.contains("(")){
|
|
|
+ int index = name.indexOf('(');
|
|
|
+ name = name.substring(0, index);
|
|
|
+ }else if (name.contains("(")){
|
|
|
+ int index = name.indexOf('(');
|
|
|
+ name = name.substring(0, index);
|
|
|
+ }
|
|
|
+ a.setName(name);
|
|
|
+ a.setWorkingHours(department.getWorkingHoursType());
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ public List<AdminPublicDuration> sumDurationsById(List<AdminPublicDuration> adminPublicDurations) {
|
|
|
+ Map<String, AdminPublicDuration> durationMap = new HashMap<>();
|
|
|
+ for (AdminPublicDuration adminPublicDuration : adminPublicDurations) {
|
|
|
+ String id = adminPublicDuration.getId();
|
|
|
+ String name = adminPublicDuration.getName();
|
|
|
+ double duration = adminPublicDuration.getDuration();
|
|
|
+ if (durationMap.containsKey(id)) {
|
|
|
+ AdminPublicDuration summary = durationMap.get(id);
|
|
|
+ summary.setWorkingHours(adminPublicDuration.getWorkingHours());
|
|
|
+ BigDecimal countDuration = BigDecimal.valueOf(summary.getDuration()).add(BigDecimal.valueOf(duration));
|
|
|
+ summary.setDuration(countDuration.doubleValue());
|
|
|
+ summary.setName(name);
|
|
|
+ summary.setCountNumber(summary.getCountNumber()+1);
|
|
|
+ if (summary.getWorkingHours()==null){
|
|
|
+ throw new BusinessException(String.format("用户[%s]未设置工作类型",name));
|
|
|
+ }
|
|
|
+ if (summary.getWorkingHours()==2){
|
|
|
+ summary.setConversion(7.0);
|
|
|
+ } else{
|
|
|
+ summary.setConversion(7.5);
|
|
|
+ }
|
|
|
+ if (summary.getConversion()!=null){
|
|
|
+ BigDecimal divide = BigDecimal.valueOf(summary.getDuration()).divide(BigDecimal.valueOf(summary.getConversion()), 2, RoundingMode.HALF_UP);
|
|
|
+ summary.setDays(divide.doubleValue());
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ AdminPublicDuration e = new AdminPublicDuration(id, name, duration);
|
|
|
+ e.setWorkingHours(adminPublicDuration.getWorkingHours());
|
|
|
+ if (e.getWorkingHours()==null){
|
|
|
+ throw new BusinessException(String.format("用户[%s]未设置工作类型",name));
|
|
|
+ }
|
|
|
+ if (e.getWorkingHours()==2){
|
|
|
+ e.setConversion(7.0);
|
|
|
+ } else{
|
|
|
+ e.setConversion(7.5);
|
|
|
+ }
|
|
|
+ if (e.getConversion()!=null){
|
|
|
+ BigDecimal divide = BigDecimal.valueOf(e.getDuration()).divide(BigDecimal.valueOf(e.getConversion()), 2, RoundingMode.HALF_UP);
|
|
|
+ e.setDays(divide.doubleValue());
|
|
|
+ }
|
|
|
+ durationMap.put(id, e);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return new ArrayList<>(durationMap.values());
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
}
|