Selaa lähdekoodia

任务分组工时统计

yurk 2 vuotta sitten
vanhempi
commit
aa6dbd0c9c

+ 8 - 0
fhKeeper/formulahousekeeper/management-platform/src/main/java/com/management/platform/controller/ProjectController.java

@@ -897,5 +897,13 @@ public class ProjectController {
     public HttpRespMsg getTimeCostByGroup(String startDate,String endDate,Integer pageIndex,Integer pageSize,Integer groupId,Integer projectId){
         return projectService.getTimeCostByGroup(startDate,endDate,pageIndex,pageSize,groupId,projectId,request);
     }
+    @RequestMapping("/getTimeCostByGroupProject")
+    public HttpRespMsg getTimeCostByGroupProject(String startDate,String endDate,Integer pageIndex,Integer pageSize,Integer groupId,Integer projectId){
+        return projectService.getTimeCostByGroupProject(startDate,endDate,pageIndex,pageSize,groupId,projectId,request);
+    }
+    @RequestMapping("exportGroupWithProjectTimeCost")
+    public HttpRespMsg exportGroupWithProjectTimeCost(String startDate,String endDate,Integer pageIndex,Integer pageSize,Integer groupId,Integer projectId){
+        return projectService.exportGroupWithProjectTimeCost(startDate,endDate,pageIndex,pageSize,groupId,projectId,request);
+    }
 }
 

+ 4 - 0
fhKeeper/formulahousekeeper/management-platform/src/main/java/com/management/platform/mapper/ProjectMapper.java

@@ -115,4 +115,8 @@ public interface ProjectMapper extends BaseMapper<Project> {
     List<Map<String, Object>> selectWithGroup(Integer companyId, String startDate, String endDate, Integer startIndex, Integer endIndex, Integer projectId, List<Integer> inchagerIds, Integer groupId);
 
     long selectCountWithGroup(Integer companyId, String startDate, String endDate, Integer startIndex, Integer endIndex, Integer projectId, List<Integer> inchagerIds, Integer groupId);
+
+    List<Map<String, Object>> selectWithGroupProject(Integer companyId, String startDate, String endDate,  Integer startIndex, Integer endIndex, Integer projectId, List<Integer> inchagerIds, Integer groupId);
+
+    long selectCountWithGroupProject(Integer companyId, String startDate, String endDate, Integer startIndex, Integer endIndex, Integer projectId, List<Integer> inchagerIds, Integer groupId);
 }

+ 4 - 0
fhKeeper/formulahousekeeper/management-platform/src/main/java/com/management/platform/service/ProjectService.java

@@ -166,4 +166,8 @@ public interface ProjectService extends IService<Project> {
     HttpRespMsg getCostByGroup(String startDate, String endDate, Integer id, HttpServletRequest request);
 
     HttpRespMsg getTimeCostByGroup(String startDate, String endDate, Integer pageIndex, Integer pageSize, Integer groupId, Integer projectId,HttpServletRequest request);
+
+    HttpRespMsg getTimeCostByGroupProject(String startDate, String endDate, Integer pageIndex, Integer pageSize, Integer groupId, Integer projectId, HttpServletRequest request);
+
+    HttpRespMsg exportGroupWithProjectTimeCost(String startDate, String endDate, Integer pageIndex, Integer pageSize, Integer groupId, Integer projectId, HttpServletRequest request);
 }

+ 78 - 2
fhKeeper/formulahousekeeper/management-platform/src/main/java/com/management/platform/service/impl/ProjectServiceImpl.java

@@ -4795,8 +4795,6 @@ public class ProjectServiceImpl extends ServiceImpl<ProjectMapper, Project> impl
         String token = request.getHeader("TOKEN");
         User user = userMapper.selectById(token);
         Integer companyId = user.getCompanyId();
-        Integer startIndex = (pageIndex-1)*pageSize;
-        Integer endIndex = pageSize*pageIndex;
         HttpRespMsg msg = new HttpRespMsg();
         List<Project> projectList = projectMapper.selectList(new QueryWrapper<Project>().eq("company_id", companyId));
         List<SysRichFunction> functionAllList = sysFunctionMapper.getRoleFunctions(user.getRoleId(), "全部任务分组工时");
@@ -4818,6 +4816,8 @@ public class ProjectServiceImpl extends ServiceImpl<ProjectMapper, Project> impl
         List<Map<String,Object>> record;
         long total;
         if(pageIndex!=null&&pageSize!=null){
+            Integer startIndex = (pageIndex-1)*pageSize;
+            Integer endIndex = pageSize*pageIndex;
             record = projectMapper.selectWithGroup(companyId,startDate,endDate, startIndex, endIndex, projectId,inchagerIds,groupId);
         }else {
             record=projectMapper.selectWithGroup(companyId,startDate,endDate, null, null, projectId,inchagerIds,groupId);
@@ -4830,6 +4830,82 @@ public class ProjectServiceImpl extends ServiceImpl<ProjectMapper, Project> impl
         return msg;
     }
 
+    @Override
+    public HttpRespMsg getTimeCostByGroupProject(String startDate, String endDate, Integer pageIndex, Integer pageSize, Integer groupId, Integer projectId, HttpServletRequest request) {
+        String token = request.getHeader("TOKEN");
+        User user = userMapper.selectById(token);
+        Integer companyId = user.getCompanyId();
+        HttpRespMsg msg = new HttpRespMsg();
+        List<Project> projectList = projectMapper.selectList(new QueryWrapper<Project>().eq("company_id", companyId));
+        List<SysRichFunction> functionAllList = sysFunctionMapper.getRoleFunctions(user.getRoleId(), "全部任务分组工时");
+        List<SysRichFunction> functionInchargeList = sysFunctionMapper.getRoleFunctions(user.getRoleId(), "负责项目任务分组工时");
+        //判断查看权限
+        List<Integer> inchagerIds=null;
+        if(functionAllList.size()==0){
+            inchagerIds=new ArrayList<>();
+            if(functionInchargeList.size()>0){
+                List<Project> list = projectList.stream().filter(pl -> (pl.getInchargerId()==null?0:pl.getInchargerId()).equals(user.getId())).collect(Collectors.toList());
+                if(list!=null){
+                    List<Integer> collect = list.stream().map(li -> li.getId()).collect(Collectors.toList());
+                    inchagerIds.addAll(collect);
+                }
+            }else {
+                inchagerIds.add(-1);
+            }
+        }
+        List<Map<String,Object>> record;
+        long total;
+        if(pageIndex!=null&&pageSize!=null){
+            Integer startIndex = (pageIndex-1)*pageSize;
+            Integer endIndex = pageSize*pageIndex;
+            record = projectMapper.selectWithGroupProject(companyId,startDate,endDate, startIndex, endIndex, projectId,inchagerIds,groupId);
+        }else {
+            record=projectMapper.selectWithGroupProject(companyId,startDate,endDate, null, null, projectId,inchagerIds,groupId);
+        }
+        total =projectMapper.selectCountWithGroupProject(companyId,startDate,endDate, null, null, projectId,inchagerIds,groupId);
+        HashMap<String, Object> map = new HashMap<>();
+        map.put("records", record);
+        map.put("total", total);
+        msg.data = map;
+        return msg;
+    }
+
+    @Override
+    public HttpRespMsg exportGroupWithProjectTimeCost(String startDate, String endDate, Integer pageIndex, Integer pageSize, Integer groupId, Integer projectId, HttpServletRequest request) {
+        HttpRespMsg httpRespMsg=new HttpRespMsg();
+        HttpRespMsg timeCostByGroup = getTimeCostByGroup(startDate, endDate, null, null, groupId, projectId, request);
+        HttpRespMsg timeCostByGroupProject = getTimeCostByGroupProject(startDate, endDate, null, null, groupId, projectId, request);
+        HashMap<String,Object> timeCostByGroupData = (HashMap<String, Object>) timeCostByGroup.data;
+        HashMap<String,Object>  timeCostByGroupProjectData =  (HashMap<String, Object>) timeCostByGroupProject.data;
+        List<Map<String,Object>> timeCostByGroupList= (List<Map<String, Object>>) timeCostByGroupData.get("records");
+        List<Map<String,Object>> timeCostByGroupProjectList= (List<Map<String, Object>>) timeCostByGroupProjectData.get("records");
+        List<List<String>> sheetOneList = new ArrayList<>();
+        List<List<String>> sheetTwoList=new ArrayList<>();
+        String[] sheetOneTitles = {"分组名称", "工时"};
+        String[] sheetTwoTitles={"项目编号","项目名称","分组名称","工时"};
+        sheetOneList.add(Lists.list(sheetOneTitles));
+        sheetTwoList.add(Lists.list(sheetTwoTitles));
+        for (Map<String, Object> map : timeCostByGroupList) {
+            List<String> item=new ArrayList<>();
+            item.add(String.valueOf(map.get("groupName")));
+            item.add(String.valueOf(map.get("workingTime")));
+            sheetOneList.add(item);
+        }
+        for (Map<String, Object> map : timeCostByGroupProjectList) {
+            List<String> item=new ArrayList<>();
+            item.add(String.valueOf(map.get("projectCode")));
+            item.add(String.valueOf(map.get("projectName")));
+            item.add(String.valueOf(map.get("groupName")));
+            item.add(String.valueOf(map.get("workingTime")));
+            sheetTwoList.add(item);
+        }
+        String fileName = "任务分组工时统计_"+System.currentTimeMillis();
+        /*ExcelUtil.exportGeneralExcelByTitleAndList(fileName, sheetOneList, path);*/
+        ExcelUtil.exportTwoSheetGeneralExcelByTitleAndList(fileName,sheetOneList,sheetTwoList,path);
+        httpRespMsg.data =  pathPrefix + fileName+".xls";
+        return httpRespMsg;
+    }
+
 
     private List<Department> getSubDepts(Department dp, List<Department> list) {
         List<Department> collect = list.stream().filter(l -> dp.getDepartmentId().equals(l.getSuperiorId())).collect(Collectors.toList());

+ 152 - 5
fhKeeper/formulahousekeeper/management-platform/src/main/java/com/management/platform/util/ExcelUtil.java

@@ -2,14 +2,9 @@ package com.management.platform.util;
 
 import org.apache.poi.hssf.usermodel.*;
 import org.apache.poi.ss.usermodel.*;
-import org.springframework.util.StringUtils;
 
-import javax.servlet.http.HttpServletResponse;
 import java.io.File;
 import java.io.FileOutputStream;
-import java.io.OutputStream;
-import java.net.URLEncoder;
-import java.nio.charset.StandardCharsets;
 import java.util.List;
 
 public class ExcelUtil {
@@ -155,6 +150,158 @@ public class ExcelUtil {
 //        return "";
     }
 
+    public static String exportTwoSheetGeneralExcelByTitleAndList(String title, List<List<String>> sheetOneList,List<List<String>> sheetTwoList, String downloadPath) {
+        String result="系统提示:Excel文件导出成功!";
+        String fileName= title+".xls";
+        try {
+//            response.reset();
+//            response.setHeader("Content-disposition",
+//                "attachment;filename="+ URLEncoder.encode(fileName, "UTF-8"));
+//            //设置文件头编码格式
+//            response.setContentType("APPLICATION/OCTET-STREAM;charset=UTF-8");//设置类型
+//            response.setHeader("Cache-Control","no-cache");//设置头
+//            response.setDateHeader("Expires", 0);//设置日期头
+            // 创建工作簿
+            HSSFWorkbook workBook = new HSSFWorkbook();
+            // 创建工作类
+            HSSFSheet sheetOne = workBook.createSheet();
+            HSSFSheet sheetTwo = workBook.createSheet();
+            sheetOne.setDefaultColumnWidth(16);
+            sheetTwo.setDefaultColumnWidth(16);
+            //设置字体样式
+            HSSFFont headFont = workBook.createFont();
+            headFont.setBold(true);
+            headFont.setFontHeightInPoints((short) 10);
+            headFont.setFontName("黑体");
+
+            HSSFFont titleFont = workBook.createFont();
+            titleFont.setBold(true);
+            titleFont.setFontHeightInPoints((short) 10);
+            titleFont.setFontName("黑体");
+
+            HSSFFont font = workBook.createFont();
+            font.setFontHeightInPoints((short) 10);
+            font.setFontName("宋体");
+
+            //设置单元格样式
+            CellStyle headStyle = workBook.createCellStyle();
+            headStyle.setFont(headFont);
+            headStyle.setAlignment(HorizontalAlignment.CENTER);
+            headStyle.setVerticalAlignment(org.apache.poi.ss.usermodel.VerticalAlignment.CENTER);
+            headStyle.setWrapText(true);
+            headStyle.setBorderBottom(BorderStyle.THIN); //下边框
+            headStyle.setBorderLeft(BorderStyle.THIN);//左边框
+            headStyle.setBorderTop(BorderStyle.THIN);//上边框
+            headStyle.setBorderRight(BorderStyle.THIN);//右边框
+
+            String color = "c0c0c0";    //此处得到的color为16进制的字符串
+            //转为RGB码
+            int r = Integer.parseInt((color.substring(0,2)),16);   //转为16进制
+            int g = Integer.parseInt((color.substring(2,4)),16);
+            int b = Integer.parseInt((color.substring(4,6)),16);
+
+            //自定义cell颜色
+            HSSFPalette palette = workBook.getCustomPalette();
+            //这里的9是索引
+            palette.setColorAtIndex((short)9, (byte) r, (byte) g, (byte) b);
+
+            CellStyle titleStyle = workBook.createCellStyle();
+            titleStyle.setFont(titleFont);
+            titleStyle.setAlignment(HorizontalAlignment.CENTER);
+            titleStyle.setVerticalAlignment(org.apache.poi.ss.usermodel.VerticalAlignment.CENTER);
+            titleStyle.setFillPattern(FillPatternType.SOLID_FOREGROUND);  //填充单元格
+            titleStyle.setFillForegroundColor((short)9);    //填色
+            titleStyle.setWrapText(true);
+            titleStyle.setBorderBottom(BorderStyle.THIN); //下边框
+            titleStyle.setBorderLeft(BorderStyle.THIN);//左边框
+            titleStyle.setBorderTop(BorderStyle.THIN);//上边框
+            titleStyle.setBorderRight(BorderStyle.THIN);//右边框
+
+            CellStyle cellStyle = workBook.createCellStyle();
+            cellStyle.setFont(font);
+            cellStyle.setAlignment(HorizontalAlignment.CENTER);
+            cellStyle.setVerticalAlignment(org.apache.poi.ss.usermodel.VerticalAlignment.CENTER);
+            cellStyle.setWrapText(true);
+            cellStyle.setBorderBottom(BorderStyle.THIN); //下边框
+            cellStyle.setBorderLeft(BorderStyle.THIN);//左边框
+            cellStyle.setBorderTop(BorderStyle.THIN);//上边框
+            cellStyle.setBorderRight(BorderStyle.THIN);//右边框
+
+            if(sheetOneList.size() > 0) {
+                //标题(如果需要在EXCEL内容最上面加标题,请打开下面的注释,修改start)
+                /*
+                HSSFRow titleRow = sheet.createRow(0);
+                titleRow.setHeightInPoints(30);
+                HSSFCell titleCell = titleRow.createCell(0);
+                titleCell.setCellStyle(headStyle);
+                titleCell.setCellValue(title);
+                //合并单元格
+                CellRangeAddress cellRangeAddress = new CellRangeAddress(0,0,0, list.get(0).size() - 1);
+                //加入合并单元格对象
+                sheet.addMergedRegion(cellRangeAddress);
+                //使用RegionUtil类为合并后的单元格添加边框
+			    RegionUtil.setBorderBottom(BorderStyle.THIN, cellRangeAddress, sheet); // 下边框
+                RegionUtil.setBorderLeft(BorderStyle.THIN, cellRangeAddress, sheet); // 左边框
+                RegionUtil.setBorderRight(BorderStyle.THIN, cellRangeAddress, sheet); // 有边框
+                RegionUtil.setBorderTop(BorderStyle.THIN, cellRangeAddress, sheet); // 上边框
+                */
+                int start = 0;
+                for(List<String> rowList : sheetOneList) {
+                    HSSFRow row = sheetOne.createRow(start);
+                    row.setHeightInPoints(24);
+                    for(int i = 0; i < rowList.size(); i++) {
+                        HSSFCell cell = row.createCell(i);
+                        if(start == 0) {
+                            cell.setCellStyle(titleStyle);
+                        }else {
+                            cell.setCellStyle(cellStyle);
+                        }
+                        cell.setCellValue(rowList.get(i));
+                    }
+                    start++;
+                }
+            }
+            if(sheetTwoList.size()>0){
+                int start = 0;
+                for(List<String> rowList : sheetTwoList) {
+                    HSSFRow row = sheetTwo.createRow(start);
+                    row.setHeightInPoints(24);
+                    for(int i = 0; i < rowList.size(); i++) {
+                        HSSFCell cell = row.createCell(i);
+                        if(start == 0) {
+                            cell.setCellStyle(titleStyle);
+                        }else {
+                            cell.setCellStyle(cellStyle);
+                        }
+                        cell.setCellValue(rowList.get(i));
+                    }
+                    start++;
+                }
+            }
+            //用于非传统ajax;
+//            String headStr = "attachment; filename=\"" + fileName + "\"";
+//            response.setContentType("APPLICATION/OCTET-STREAM");//返回格式为流
+//            response.setHeader("Content-Disposition", headStr);
+//            //普通下载不需要以上三行,注掉即可
+//            OutputStream os = response.getOutputStream();//在线下载
+            File dir = null;
+            dir = new File(downloadPath);
+            // D://cloud/upload 文件上传后所存储的位置,部署到服务器上时配置服务器地址即可
+            if (!dir.exists()) {
+                dir.mkdirs();
+            }
+            FileOutputStream os = new FileOutputStream(downloadPath+fileName);//保存到本地
+            workBook.write(os);
+            os.flush();
+            os.close();
+        }catch(Exception e) {
+            System.out.println(result);
+            e.printStackTrace();
+        }
+        return "/upload/"+fileName;
+//        return "";
+    }
+
     public static boolean isRowEmpty(Row row){
         for (int i = row.getFirstCellNum(); i < row.getLastCellNum(); i++) {
             Cell cell = row.getCell(i);

+ 60 - 3
fhKeeper/formulahousekeeper/management-platform/src/main/resources/mapper/ProjectMapper.xml

@@ -879,7 +879,7 @@
         order  by us.department_id)as total
     </select>
     <select id="selectWithGroup" resultType="java.util.Map">
-        select SUM(a.working_time) as workingTime,IFNULL(b.name,'未分组') as groupName ,c.project_name as projectName,c.project_code as projectCode
+        select SUM(a.working_time) as workingTime,IFNULL(b.name,'未分组') as groupName
         from report a
         left join task_group b on a.group_id=b.id
         left join project c on a.project_id=c.id
@@ -899,7 +899,7 @@
         <if test="groupId!=null">
             and a.group_id=#{groupId}
         </if>
-        group by b.id
+        group by b.name
         order by c.id
         <if test="startIndex!=null and endIndex!=null">
             limit #{startIndex},#{endIndex}
@@ -907,6 +907,34 @@
     </select>
     <select id="selectCountWithGroup" resultType="java.lang.Long">
         select count(1) from(
+        select SUM(a.working_time) as workingTime,IFNULL(b.name,'未分组') as groupName
+        from report a
+        left join task_group b on a.group_id=b.id
+        left join project c on a.project_id=c.id
+        where c.company_id=#{companyId} and a.state=1
+        <if test="startDate!=null and endDate!=null">
+            and a.create_date &gt;=#{startDate} and a.create_date &lt;=#{endDate}
+        </if>
+        <if test="projectId!=null">
+            and c.id=#{projectId}
+        </if>
+        <if test="inchagerIds!=null and inchagerIds.size()>0">
+            and c.id in
+            <foreach collection="inchagerIds" open="(" separator="," close=")" item="item">
+                #{item}
+            </foreach>
+        </if>
+        <if test="groupId!=null">
+            and a.group_id=#{groupId}
+        </if>
+        group by b.name
+        order by c.id
+        <if test="startIndex!=null and endIndex!=null">
+            limit #{startIndex},#{endIndex}
+        </if>) as total
+    </select>
+
+    <select id="selectWithGroupProject" resultType="java.util.Map">
         select SUM(a.working_time) as workingTime,IFNULL(b.name,'未分组') as groupName ,c.project_name as projectName,c.project_code as projectCode
         from report a
         left join task_group b on a.group_id=b.id
@@ -927,7 +955,36 @@
         <if test="groupId!=null">
             and a.group_id=#{groupId}
         </if>
-        group by b.id
+        group by c.id,b.id
+        order by c.id
+        <if test="startIndex!=null and endIndex!=null">
+            limit #{startIndex},#{endIndex}
+        </if>
+    </select>
+
+    <select id="selectCountWithGroupProject" resultType="java.lang.Long">
+        select count(1) from(
+        select SUM(a.working_time) as workingTime,IFNULL(b.name,'未分组') as groupName ,c.project_name as projectName,c.project_code as projectCode
+        from report a
+        left join task_group b on a.group_id=b.id
+        left join project c on a.project_id=c.id
+        where c.company_id=#{companyId} and a.state=1
+        <if test="startDate!=null and endDate!=null">
+            and a.create_date &gt;=#{startDate} and a.create_date &lt;=#{endDate}
+        </if>
+        <if test="projectId!=null">
+            and c.id=#{projectId}
+        </if>
+        <if test="inchagerIds!=null and inchagerIds.size()>0">
+            and c.id in
+            <foreach collection="inchagerIds" open="(" separator="," close=")" item="item">
+                #{item}
+            </foreach>
+        </if>
+        <if test="groupId!=null">
+            and a.group_id=#{groupId}
+        </if>
+        group by c.id,b.id
         order by c.id
         <if test="startIndex!=null and endIndex!=null">
             limit #{startIndex},#{endIndex}