|
@@ -0,0 +1,162 @@
|
|
|
+package com.management.platform.service.impl;
|
|
|
+
|
|
|
+import com.alibaba.fastjson.JSONArray;
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
+import com.management.platform.entity.*;
|
|
|
+import com.management.platform.entity.vo.SysRichFunction;
|
|
|
+import com.management.platform.mapper.*;
|
|
|
+import com.management.platform.service.ReportBatchService;
|
|
|
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
+import com.management.platform.util.HttpRespMsg;
|
|
|
+import com.management.platform.util.ListUtil;
|
|
|
+import com.management.platform.util.MessageUtils;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+import org.springframework.util.StringUtils;
|
|
|
+
|
|
|
+import javax.annotation.Resource;
|
|
|
+import javax.servlet.http.HttpServletRequest;
|
|
|
+import java.math.BigDecimal;
|
|
|
+import java.text.DecimalFormat;
|
|
|
+import java.time.format.DateTimeFormatter;
|
|
|
+import java.util.*;
|
|
|
+import java.util.stream.Collectors;
|
|
|
+
|
|
|
+/**
|
|
|
+ * <p>
|
|
|
+ * 服务实现类
|
|
|
+ * </p>
|
|
|
+ *
|
|
|
+ * @author Seyason
|
|
|
+ * @since 2023-08-10
|
|
|
+ */
|
|
|
+@Service
|
|
|
+public class ReportBatchServiceImpl extends ServiceImpl<ReportBatchMapper, ReportBatch> implements ReportBatchService {
|
|
|
+
|
|
|
+ @Resource
|
|
|
+ private UserFvTimeMapper userFvTimeMapper;
|
|
|
+ @Resource
|
|
|
+ private ReportBatchMapper reportBatchMapper;
|
|
|
+ @Resource
|
|
|
+ private UserMapper userMapper;
|
|
|
+ @Resource
|
|
|
+ private SysFunctionMapper sysFunctionMapper;
|
|
|
+ @Resource
|
|
|
+ private ReportMapper reportMapper;
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public HttpRespMsg getAuditList(Integer state, Integer departmentId, Integer projectId, String date, String startDate, String endDate, String userId, HttpServletRequest request) {
|
|
|
+ HttpRespMsg httpRespMsg = new HttpRespMsg();
|
|
|
+ try {
|
|
|
+ User curUser = userMapper.selectById(request.getHeader("Token"));
|
|
|
+ Integer companyId = curUser.getCompanyId();
|
|
|
+ String leaderId = null;
|
|
|
+ List<SysRichFunction> functionList = sysFunctionMapper.getRoleFunctions(curUser.getRoleId(), "审核全员日报");
|
|
|
+ if (functionList.size() == 0) {//没有全员审核的权限
|
|
|
+ leaderId = curUser.getId();
|
|
|
+ }
|
|
|
+ List<String> targetUids = null;
|
|
|
+ if (!StringUtils.isEmpty(userId)) {
|
|
|
+ targetUids = ListUtil.convertLongIdsArrayToList(userId);
|
|
|
+ }
|
|
|
+ List<Map<String, Object>> auditReportList = reportMapper.getAuditReportList(date, companyId, departmentId, projectId, leaderId, 0, startDate, endDate, targetUids);
|
|
|
+ List<Integer> batchIds = new ArrayList<>();
|
|
|
+ for (Map<String, Object> map : auditReportList) {
|
|
|
+ Integer batchId = (Integer)map.get("batchId");
|
|
|
+ if (!batchIds.contains(batchId)) {
|
|
|
+ batchIds.add(batchId);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ DateTimeFormatter dtf = DateTimeFormatter.ofPattern("yyyy-MM-dd");
|
|
|
+ List<ReportBatch> reportBatches = new ArrayList<>();
|
|
|
+ if (batchIds.size() > 0) {
|
|
|
+ reportBatches = reportBatchMapper.selectList(new QueryWrapper<ReportBatch>().in("id", batchIds).orderByDesc("id"));
|
|
|
+ reportBatches.forEach(batch -> {
|
|
|
+ batch.setReportTime(batch.getTotalWorkTime());
|
|
|
+ List<Map> filterMapList = new ArrayList<>();
|
|
|
+ //取第一天的所有项目日报
|
|
|
+ String firstDate = null;
|
|
|
+ StringBuilder reportIds = new StringBuilder();
|
|
|
+ for (Map<String, Object> map : auditReportList) {
|
|
|
+ Integer batchId = (Integer)map.get("batchId");
|
|
|
+ String curDate = (String)map.get("date");
|
|
|
+ if (batch.getId().equals(batchId)) {
|
|
|
+ if (firstDate == null) {
|
|
|
+ firstDate = curDate;
|
|
|
+ filterMapList.add(map);
|
|
|
+ } else if (curDate.equals(firstDate)){
|
|
|
+ filterMapList.add(map);
|
|
|
+ }
|
|
|
+ reportIds.append((Integer)map.get("id")).append(",");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ batch.setData(filterMapList);
|
|
|
+ reportIds.deleteCharAt(reportIds.length()-1);
|
|
|
+ batch.setReportIds(reportIds.toString());
|
|
|
+ batch.setDateStr(batch.getStartDate().format(dtf)+" 至 "+batch.getEndDate().format(dtf));
|
|
|
+ if (filterMapList.size() > 0) {
|
|
|
+ //取第一个的姓名和部门名称
|
|
|
+ batch.setName((String)filterMapList.get(0).get("name"));
|
|
|
+ batch.setDepartmentName((String)filterMapList.get(0).get("departmentName"));
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+//
|
|
|
+// //抽取姓名,进行分组
|
|
|
+// List<Map<String, Object>> nameList = new ArrayList<Map<String, Object>>();
|
|
|
+// Map<String, Object> lastName = null;
|
|
|
+// //某个用户某天下的各个项目日报列表
|
|
|
+// List<Map<String, Object>> userDailyReportList = null;
|
|
|
+// for (Map a : auditReportList) {
|
|
|
+// String createDate = (String)a.get("date");
|
|
|
+// String name = (String)a.get("name");
|
|
|
+// String uid = (String)a.get("userId");
|
|
|
+// String corpwxUserid = (String)a.get("corpwxUserid");
|
|
|
+//
|
|
|
+// if (lastName == null || !(lastName.get("name").equals(name) && lastName.get("dateStr").equals(createDate))) {
|
|
|
+// lastName = new HashMap<String, Object>();
|
|
|
+// lastName.put("dateStr", createDate);
|
|
|
+// lastName.put("name", name);
|
|
|
+// lastName.put("userId", uid);
|
|
|
+// lastName.put("corpwxUserid", corpwxUserid);
|
|
|
+// nameList.add(lastName);
|
|
|
+// userDailyReportList = new ArrayList<>();
|
|
|
+// lastName.put("data", userDailyReportList);
|
|
|
+// }
|
|
|
+// //每组日报数据都加上去
|
|
|
+// userDailyReportList.add(a);
|
|
|
+// }
|
|
|
+//
|
|
|
+
|
|
|
+// //设置每人每日考勤打卡时长
|
|
|
+// QueryWrapper<UserFvTime> userFvTimeQueryWrapper = new QueryWrapper<>();
|
|
|
+// if (nameList.size() > 0) {
|
|
|
+// for (Map map : nameList) {
|
|
|
+// String itemUid = (String)map.get("userId");
|
|
|
+// String dateStr = (String)map.get("dateStr");
|
|
|
+// userFvTimeQueryWrapper.or(wrapper->wrapper.eq("user_id", itemUid).eq("work_date", dateStr));
|
|
|
+// }
|
|
|
+// List<UserFvTime> timeList = userFvTimeMapper.selectList(userFvTimeQueryWrapper);
|
|
|
+// //过滤匹配当前的数据
|
|
|
+// for (Map map : nameList) {
|
|
|
+// String itemUid = (String)map.get("userId");
|
|
|
+// String dateStr = (String)map.get("dateStr");
|
|
|
+// Optional<UserFvTime> first = timeList.stream().filter(time -> time.getUserId().equals(itemUid) && dtf.format(time.getWorkDate()).equals(dateStr)).findFirst();
|
|
|
+// if (first.isPresent()) {
|
|
|
+// double wh = first.get().getWorkHours();
|
|
|
+// //赋值打卡时长
|
|
|
+// map.put("cardHours", wh);
|
|
|
+// }
|
|
|
+// }
|
|
|
+// }
|
|
|
+ httpRespMsg.data = reportBatches;
|
|
|
+ } catch (NullPointerException e) {
|
|
|
+ //httpRespMsg.setError("验证失败");
|
|
|
+ e.printStackTrace();
|
|
|
+ httpRespMsg.setError(MessageUtils.message("access.verificationError"));
|
|
|
+ return httpRespMsg;
|
|
|
+ }
|
|
|
+ return httpRespMsg;
|
|
|
+ }
|
|
|
+}
|