|
@@ -22,6 +22,7 @@ import org.apache.commons.io.FileUtils;
|
|
|
import org.apache.poi.EncryptedDocumentException;
|
|
|
import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
|
|
|
import org.apache.poi.ss.usermodel.*;
|
|
|
+import org.springframework.beans.BeanUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
|
import org.springframework.http.*;
|
|
@@ -36,6 +37,7 @@ import org.springframework.web.client.RestTemplate;
|
|
|
import org.springframework.web.multipart.MultipartFile;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
+import javax.print.DocFlavor;
|
|
|
import javax.servlet.http.HttpServletRequest;
|
|
|
import java.io.*;
|
|
|
import java.math.BigDecimal;
|
|
@@ -8013,4 +8015,235 @@ public class ReportServiceImpl extends ServiceImpl<ReportMapper, Report> impleme
|
|
|
httpRespMsg.setData(responseData);
|
|
|
return httpRespMsg;
|
|
|
}
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public HttpRespMsg getUserWorkTimeByCategory(Integer categoryId, Integer deptId, String userId, String startDate, String endDate, Integer pageIndex, Integer pageSize) {
|
|
|
+ HttpRespMsg httpRespMsg=new HttpRespMsg();
|
|
|
+ User user = userMapper.selectById(request.getHeader("token"));
|
|
|
+ List<UserCustom> userCustomList = userCustomMapper.selectList(new LambdaQueryWrapper<UserCustom>().eq(UserCustom::getCompanyId, user.getCompanyId()));
|
|
|
+ DateTimeFormatter dtf=DateTimeFormatter.ofPattern("yyyy-MM-dd");
|
|
|
+ List<LocalDate> dates = getDays(LocalDate.parse(startDate, dtf), LocalDate.parse(endDate, dtf));
|
|
|
+ List<Map<String,Object>> headerStringList=new ArrayList<>();
|
|
|
+ List<Map<String,Object>> customStringList=new ArrayList<>();
|
|
|
+// Map<String,Object> map1=new HashMap();
|
|
|
+// Map<String,Object> map2=new HashMap();
|
|
|
+// Map<String,Object> map3=new HashMap();
|
|
|
+// Map<String,Object> map4=new HashMap();
|
|
|
+// Map<String,Object> map5=new HashMap();
|
|
|
+// map1.put("titleIndex","");
|
|
|
+// map1.put("titleName","生产项目号");
|
|
|
+// map2.put("titleIndex","");
|
|
|
+// map2.put("titleName","姓名");
|
|
|
+// map3.put("titleIndex","");
|
|
|
+// map3.put("titleName","部门");
|
|
|
+// headerStringList.add(map1);
|
|
|
+// headerStringList.add(map2);
|
|
|
+// headerStringList.add(map3);
|
|
|
+ for (int i = 0; i < userCustomList.size(); i++) {
|
|
|
+ Map<String,Object> map=new HashMap();
|
|
|
+ switch (i){
|
|
|
+ case 0: map.put("titleIndex","plate1");
|
|
|
+ break;
|
|
|
+ case 1: map.put("titleIndex","plate2");
|
|
|
+ break;
|
|
|
+ case 2: map.put("titleIndex","plate3");
|
|
|
+ break;
|
|
|
+ case 3: map.put("titleIndex","plate4");
|
|
|
+ break;
|
|
|
+ case 4: map.put("titleIndex","plate5");
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ map.put("titleName", userCustomList.get(i).getName());
|
|
|
+ customStringList.add(map);
|
|
|
+ }
|
|
|
+// map4.put("titleIndex","allWorkingTime");
|
|
|
+// map4.put("titleName","总工时");
|
|
|
+// map5.put("titleIndex","targetWorkingTime");
|
|
|
+// map5.put("titleName","生产工时");
|
|
|
+// headerStringList.add(map4);
|
|
|
+// headerStringList.add(map5);
|
|
|
+ for (LocalDate localDate : dates) {
|
|
|
+ Map<String,Object> map=new HashMap();
|
|
|
+ map.put("titleIndex",localDate.format(dtf));
|
|
|
+ map.put("titleName",localDate.format(dtf));
|
|
|
+ headerStringList.add(map);
|
|
|
+ }
|
|
|
+ List<Department> allDeptList = departmentMapper.selectList(new LambdaQueryWrapper<Department>().eq(Department::getCompanyId, user.getCompanyId()));
|
|
|
+ Integer size=null;
|
|
|
+ Integer start=null;
|
|
|
+ if(pageIndex!=null&&pageSize!=null){
|
|
|
+ size=pageSize;
|
|
|
+ start=(pageIndex-1)*size;
|
|
|
+ }
|
|
|
+ boolean viewAll = sysFunctionService.hasPriviledge(user.getRoleId(), "分类全部工时明细表");
|
|
|
+ boolean viewIncharge = sysFunctionService.hasPriviledge(user.getRoleId(), "分类负责部门工时明细表");
|
|
|
+ //判断是否有查看全部的权限
|
|
|
+ List<Map<String,Object>> resultList;
|
|
|
+ if(!viewAll){
|
|
|
+ //判断是否有查看负责部门的权限
|
|
|
+ if(!viewIncharge){
|
|
|
+ //只能查看与本人有关的数据
|
|
|
+ resultList=reportMapper.getUserWorkTimeByCategory(categoryId,user.getId(),user.getCompanyId(),null,deptId,startDate,endDate);
|
|
|
+ }else {
|
|
|
+ List<Department> departmentList = departmentMapper.selectList(new LambdaQueryWrapper<Department>().select(Department::getDepartmentId).eq(Department::getManagerId, user.getId()));
|
|
|
+ List<DepartmentOtherManager> departmentOtherManagerList = departmentOtherManagerMapper.selectList(new QueryWrapper<DepartmentOtherManager>().eq("other_manager_id", user.getId()));
|
|
|
+ List<Integer> deptIds=new ArrayList<>();
|
|
|
+ List<Integer> theCollect = departmentList.stream().map(dm -> dm.getDepartmentId()).distinct().collect(Collectors.toList());
|
|
|
+ theCollect.add(-1);
|
|
|
+ List<Integer> otherCollect = departmentOtherManagerList.stream().map(dom -> dom.getDepartmentId()).distinct().collect(Collectors.toList());
|
|
|
+ otherCollect.add(-1);
|
|
|
+ theCollect.addAll(otherCollect);
|
|
|
+ for (Integer integer : theCollect) {
|
|
|
+ List<Integer> branchDepartment = getBranchDepartment(integer, allDeptList);
|
|
|
+ deptIds.addAll(branchDepartment);
|
|
|
+ }
|
|
|
+ resultList=reportMapper.getUserWorkTimeByCategory(categoryId,userId,user.getCompanyId(),deptIds,deptId,startDate,endDate);
|
|
|
+ }
|
|
|
+ }else {
|
|
|
+ //查看全部
|
|
|
+ resultList=reportMapper.getUserWorkTimeByCategory(categoryId,userId,user.getCompanyId(),null,deptId,startDate,endDate);
|
|
|
+ }
|
|
|
+ List<String> userIdList = resultList.stream().map(m -> String.valueOf(m.get("userId"))).distinct().collect(Collectors.toList());
|
|
|
+ Map<String, List<Map<String, Object>>> listMap = resultList.stream().collect(Collectors.groupingBy(r -> String.valueOf(r.get("userId"))));
|
|
|
+ List<Map<String,Object>> lastList=new ArrayList<>();
|
|
|
+ for (String targetUserId : userIdList) {
|
|
|
+ Optional<Map<String, Object>> first = resultList.stream().filter(r -> String.valueOf(r.get("userId")).equals(targetUserId)).findFirst();
|
|
|
+ if(first.isPresent()){
|
|
|
+ Map<String, Object> map = first.get();
|
|
|
+ Map<String,Object> item=new HashMap<>();
|
|
|
+ item.put("userId",String.valueOf(map.get("userId")));
|
|
|
+ item.put("categoryName",String.valueOf(map.get("categoryName")));
|
|
|
+ item.put("deptName",String.valueOf(map.get("deptName")));
|
|
|
+ item.put("userName",String.valueOf(map.get("userName")));
|
|
|
+ item.put("deptId",String.valueOf(map.get("deptId")));
|
|
|
+ item.put("targetWorkingTime",String.valueOf(map.get("targetWorkingTime")));
|
|
|
+ item.put("allWorkingTime",String.valueOf(map.get("allWorkingTime")));
|
|
|
+ item.put("plate1",map.get("plate1")==null?"":String.valueOf(map.get("plate1")));
|
|
|
+ item.put("plate2",map.get("plate2")==null?"":String.valueOf(map.get("plate2")));
|
|
|
+ item.put("plate3",map.get("plate3")==null?"":String.valueOf(map.get("plate3")));
|
|
|
+ item.put("plate4",map.get("plate4")==null?"":String.valueOf(map.get("plate4")));
|
|
|
+ item.put("plate5",map.get("plate5")==null?"":String.valueOf(map.get("plate5")));
|
|
|
+ if(map.get("corpWxUserId")!=null){
|
|
|
+ item.put("corpWxUserId",String.valueOf(map.get("corpWxUserId")));
|
|
|
+ }
|
|
|
+ if(map.get("corpWxDeptId")!=null){
|
|
|
+ item.put("corpWxDeptId",String.valueOf(map.get("corpWxDeptId")));
|
|
|
+ }
|
|
|
+ List<Map<String, Object>> mapList = listMap.get(targetUserId);
|
|
|
+ item.put("dataList",mapList);
|
|
|
+ lastList.add(item);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if(start!=null&&size!=null){
|
|
|
+ if(lastList.size()<size){
|
|
|
+ size=lastList.size();
|
|
|
+ }
|
|
|
+ if(lastList.size()<start){
|
|
|
+ start=0;
|
|
|
+ }
|
|
|
+ lastList=lastList.subList(start,size);
|
|
|
+ }
|
|
|
+ Map<String,Object> resultMap=new HashMap<>();
|
|
|
+ resultMap.put("record",lastList);
|
|
|
+ resultMap.put("total",lastList.size());
|
|
|
+ resultMap.put("header",headerStringList);
|
|
|
+ resultMap.put("custom",customStringList);
|
|
|
+ httpRespMsg.setData(resultMap);
|
|
|
+ return httpRespMsg;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public HttpRespMsg exportUserWorkTimeByCategory(Integer categoryId, Integer deptId, String userId, String startDate, String endDate) {
|
|
|
+ HttpRespMsg msg = getUserWorkTimeByCategory(categoryId, deptId, userId, startDate, endDate, null, null);
|
|
|
+ Integer companyId = userMapper.selectById(request.getHeader("token")).getCompanyId();
|
|
|
+ WxCorpInfo wxCorpInfo = wxCorpInfoMapper.selectOne(new QueryWrapper<WxCorpInfo>().eq("company_id", companyId));
|
|
|
+ DateTimeFormatter dtf=DateTimeFormatter.ofPattern("yyyy-MM-dd");
|
|
|
+ List<LocalDate> dates = getDays(LocalDate.parse(startDate, dtf), LocalDate.parse(endDate, dtf));
|
|
|
+ List<UserCustom> userCustomList = userCustomMapper.selectList(new LambdaQueryWrapper<UserCustom>().eq(UserCustom::getCompanyId, companyId));
|
|
|
+ Map<String,Object> data = (Map<String, Object>) msg.getData();
|
|
|
+ List<List<String>> dataList=new ArrayList<>();
|
|
|
+ List<String> titleList=new ArrayList<>();
|
|
|
+ titleList.add("生产项目号");
|
|
|
+ titleList.add("姓名");
|
|
|
+ titleList.add("部门");
|
|
|
+ List<Map<String,Object>> headerList= (List<Map<String, Object>>) data.get("header");
|
|
|
+ List<Map<String,Object>> customList= (List<Map<String, Object>>) data.get("custom");
|
|
|
+ for (Map<String, Object> custom : customList) {
|
|
|
+ titleList.add(String.valueOf(custom.get("titleName")));
|
|
|
+ }
|
|
|
+ titleList.add("总工时");
|
|
|
+ titleList.add("生产工时");
|
|
|
+ for (Map<String, Object> header : headerList) {
|
|
|
+ titleList.add(String.valueOf(header.get("titleName")));
|
|
|
+ }
|
|
|
+ dataList.add(titleList);
|
|
|
+ List<Map<String,Object>> records = (List<Map<String, Object>>) data.get("record");
|
|
|
+ for (Map<String, Object> record : records) {
|
|
|
+ List<String> item=new ArrayList<>();
|
|
|
+ item.add(String.valueOf(record.get("categoryName")));
|
|
|
+ if(wxCorpInfo!=null&&wxCorpInfo.getSaasSyncContact()==1){
|
|
|
+ item.add("$userName="+String.valueOf(record.get("corpWxUserId"))+"$");
|
|
|
+ item.add("$departmentName="+String.valueOf(record.get("corpWxDeptId"))+"$");
|
|
|
+ }else {
|
|
|
+ item.add(String.valueOf(record.get("userName")));
|
|
|
+ item.add(String.valueOf(record.get("deptName")));
|
|
|
+ }
|
|
|
+ for (int i = 0; i < userCustomList.size(); i++) {
|
|
|
+ switch (i){
|
|
|
+ case 0:item.add(record.get("plate1")==null?"":String.valueOf(record.get("plate1")));
|
|
|
+ break;
|
|
|
+ case 1:item.add(record.get("plate2")==null?"":String.valueOf(record.get("plate2")));
|
|
|
+ break;
|
|
|
+ case 2:item.add(record.get("plate3")==null?"":String.valueOf(record.get("plate3")));
|
|
|
+ break;
|
|
|
+ case 3:item.add(record.get("plate4")==null?"":String.valueOf(record.get("plate4")));
|
|
|
+ break;
|
|
|
+ case 4:item.add(record.get("plate5")==null?"":String.valueOf(record.get("plate5")));
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ item.add(String.valueOf(record.get("allWorkingTime")));
|
|
|
+ item.add(String.valueOf(record.get("targetWorkingTime")));
|
|
|
+ List<Map<String,Object>> details = (List<Map<String, Object>>) record.get("dataList");
|
|
|
+ for (LocalDate localDate : dates) {
|
|
|
+ String date = dtf.format(localDate);
|
|
|
+ Optional<Map<String, Object>> first = details.stream().filter(d -> String.valueOf(d.get("createDate")).equals(date)).findFirst();
|
|
|
+ if(first.isPresent()){
|
|
|
+ item.add(String.valueOf(first.get().get("workingTime")));
|
|
|
+ }else {
|
|
|
+ item.add("");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ dataList.add(item);
|
|
|
+ }
|
|
|
+ String fileName = "分类工时明细表"+"_"+System.currentTimeMillis();
|
|
|
+ try {
|
|
|
+ return excelExportService.exportGeneralExcelByTitleAndList(wxCorpInfo, fileName, dataList, path);
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ return msg;
|
|
|
+ }
|
|
|
+
|
|
|
+ private List<Integer> getBranchDepartment(Integer departmentId, List<Department> departmentList) {
|
|
|
+ List<Integer> list = new ArrayList<>();
|
|
|
+ list.add(departmentId);
|
|
|
+ //搜到子部门进行添加
|
|
|
+ for (Department department : departmentList) {
|
|
|
+ if (departmentId.equals(department.getSuperiorId())) {
|
|
|
+ list.addAll(getBranchDepartment(department.getDepartmentId(), departmentList));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return list;
|
|
|
+ }
|
|
|
+
|
|
|
+ private List<LocalDate> getDays(LocalDate start, LocalDate end) {
|
|
|
+ List<LocalDate> result = new ArrayList();
|
|
|
+ while (start.isBefore(end)) {
|
|
|
+ result.add(start);
|
|
|
+ start=start.plusDays(1);
|
|
|
+ }
|
|
|
+ result.add(start);
|
|
|
+ return result;
|
|
|
+ }
|
|
|
}
|