Sfoglia il codice sorgente

1.按维度导出公式成本
2.休息时间段时长

cs 2 anni fa
parent
commit
e17f9b0500

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

@@ -584,6 +584,12 @@ public class ProjectController {
         return projectService.getDegreeCost(startDate, endDate, projectId, request);
     }
 
+    //导出自定义维度的工时成本
+    @RequestMapping("/exportDegreeCost")
+    public HttpRespMsg exportDegreeCost(String startDate, String endDate, Integer projectId,Integer deptId) {
+        return projectService.exportDegreeCost(startDate, endDate, projectId,deptId, request);
+    }
+
     @RequestMapping("/exportData")
     public HttpRespMsg exportData(String keyword,
                                   @RequestParam(required = false, defaultValue = "1") Integer searchField,

+ 6 - 0
fhKeeper/formulahousekeeper/management-platform/src/main/java/com/management/platform/controller/TimeTypeController.java

@@ -2,8 +2,10 @@ package com.management.platform.controller;
 
 
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
+import com.management.platform.entity.TimeAutoExclude;
 import com.management.platform.entity.TimeType;
 import com.management.platform.entity.User;
+import com.management.platform.mapper.TimeAutoExcludeMapper;
 import com.management.platform.mapper.UserMapper;
 import com.management.platform.service.TimeTypeService;
 import com.management.platform.service.UserService;
@@ -34,12 +36,16 @@ public class TimeTypeController {
     UserMapper userMapper;
     @Resource
     UserService userService;
+    @Resource
+    TimeAutoExcludeMapper timeAutoExcludeMapper;
     @RequestMapping("/getCompanyTimeSetting")
     public HttpRespMsg get(Integer companyId) {
         HttpRespMsg httpRespMsg = new HttpRespMsg();
         List<User> userList = userMapper.selectList(new QueryWrapper<User>().eq("company_id", companyId).eq("report_status", 1));
         TimeType timeType = timeTypeService.getById(companyId);
+        List<TimeAutoExclude> excludeTimeList = timeAutoExcludeMapper.selectList(new QueryWrapper<TimeAutoExclude>().eq("company_id", companyId));
         timeType.setUserList(userList);
+        timeType.setExcludeTimeList(excludeTimeList);
         httpRespMsg.data=timeType;
         return httpRespMsg;
     }

+ 7 - 0
fhKeeper/formulahousekeeper/management-platform/src/main/java/com/management/platform/entity/TimeType.java

@@ -6,6 +6,7 @@ import com.baomidou.mybatisplus.annotation.TableId;
 import com.baomidou.mybatisplus.annotation.TableField;
 import java.io.Serializable;
 import java.util.List;
+import java.util.Map;
 
 import lombok.Data;
 import lombok.EqualsAndHashCode;
@@ -50,6 +51,12 @@ public class TimeType extends Model<TimeType> {
     @TableField("pm")
     private Float pm;
 
+    /**
+     * 休息时间
+     */
+    @TableField(exist = false)
+    private List<TimeAutoExclude> excludeTimeList;
+
     /**
      * 每月工作天数
      */

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

@@ -148,4 +148,7 @@ public interface ProjectMapper extends BaseMapper<Project> {
 
     List<StageCost> selectStageSum(List<Integer> projectIds,Integer projectId, String  inchargerId, String startDate, String endDate);
 
+    List<Map<String, Object>> getExportDegreeCost(Integer companyId, String startDate, String endDate,Integer projectId, List<Integer> deptIds, List<Integer> filterDeptIds, List<Integer> deptRelatedProjectIds);
+
+    List<Map<String, Object>> getDegreeDetailCost(Integer companyId, String startDate, String endDate,String degreeId,List<Integer> filterDeptIds);
 }

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

@@ -221,4 +221,6 @@ public interface ProjectService extends IService<Project> {
     HttpRespMsg getSubProjectTimeCost(HttpServletRequest request, String startDate, String endDate, Integer projectId,Integer pageIndex,Integer pageSize);
 
     HttpRespMsg exportSubProjectTimeCost(HttpServletRequest request,String startDate,String endDate, Integer projectId);
+
+    HttpRespMsg exportDegreeCost(String startDate, String endDate, Integer projectId,Integer deptId, HttpServletRequest request);
 }

+ 189 - 0
fhKeeper/formulahousekeeper/management-platform/src/main/java/com/management/platform/service/impl/ProjectServiceImpl.java

@@ -9036,6 +9036,195 @@ public class ProjectServiceImpl extends ServiceImpl<ProjectMapper, Project> impl
         return msg;
     }
 
+    /**
+     * 按维度导出工时和成本
+     * @param startDate
+     * @param endDate
+     * @param projectId
+     * @param request
+     * @return
+     */
+    @Override
+    public HttpRespMsg exportDegreeCost(String startDate, String endDate, Integer projectId, Integer deptId, HttpServletRequest request) {
+        HttpRespMsg httpRespMsg = new HttpRespMsg();
+        try {
+            User targetUser = userMapper.selectById(request.getHeader("Token"));
+            Integer companyId =targetUser.getCompanyId();
+            WxCorpInfo wxCorpInfo = wxCorpInfoMapper.selectOne(new QueryWrapper<WxCorpInfo>().eq("company_id", companyId));
+            Map<String, Object> resultMap = new HashMap<>();
+            //当前用户管理部门
+            List<Integer> deptIds=null;
+            List<Department> departmentList = departmentMapper.selectList(new QueryWrapper<Department>().eq("manager_id", targetUser.getId()).eq("company_id", companyId));
+            List<Department> allDepartmentList = departmentMapper.selectList(new QueryWrapper<Department>().eq("company_id", targetUser.getCompanyId()));
+            List<DepartmentOtherManager> departmentOtherManagerList = departmentOtherManagerMapper.selectList(new QueryWrapper<DepartmentOtherManager>().eq("other_manager_id", targetUser.getId()));
+            List<SysRichFunction> functionAllList = sysFunctionMapper.getRoleFunctions(targetUser.getRoleId(), "查看全公司");
+            List<SysRichFunction> functionDpartList = sysFunctionMapper.getRoleFunctions(targetUser.getRoleId(), "查看负责部门");
+            List<SysRichFunction> functionTimeList = sysFunctionMapper.getRoleFunctions(targetUser.getRoleId(), "查看工时统计");
+            List<SysRichFunction> functionCostList = sysFunctionMapper.getRoleFunctions(targetUser.getRoleId(), "查看成本统计");
+            List<Integer> deptRelatedProjectIds = new ArrayList<>();
+
+            //判断查看权限
+            List<Integer> filterDeptIds=null;
+            //获取筛选的部门及其子部门
+            if(deptId!=null){
+                filterDeptIds= getBranchDepartment(deptId, allDepartmentList);
+            }
+            //若没有查看全部部门的权限
+            if(functionAllList.size()==0){
+                deptIds=new ArrayList<>();
+                deptIds.add(-1);
+                //获取负责的部门的相关的项目,对于这些项目是有查看全部参与人的权限的
+                List<Integer> allMyManagedDeptIds = new ArrayList<>();
+                List<Integer> collect = departmentList.stream().map(dm -> dm.getDepartmentId()).distinct().collect(Collectors.toList());
+                List<Integer> otherCollect = departmentOtherManagerList.stream().map(dom -> dom.getDepartmentId()).distinct().collect(Collectors.toList());
+                collect.addAll(otherCollect);
+                //获取全部的负责部门及其子部门
+                for (Integer integer : collect) {
+                    List<Integer> branchDepartment = getBranchDepartment(integer, allDepartmentList);
+                    allMyManagedDeptIds.addAll(branchDepartment);
+                }
+                //若有负责的部门的话,获取与这些部门所关联的项目
+                if (allMyManagedDeptIds.size() > 0) {
+                    List<Project> projectList = projectMapper.selectList(new QueryWrapper<Project>().select("id").in("dept_id", allMyManagedDeptIds));
+                    deptRelatedProjectIds = projectList.stream().map(Project::getId).collect(Collectors.toList());
+                }
+                if(functionDpartList.size()>0){
+                    if(functionTimeList.size()>0||functionCostList.size()>0){
+                        deptIds.addAll(allMyManagedDeptIds);
+                    }
+                }
+                //没有查看全公司的权限 只能先判断当前部门/父级别是否在负责部门才能获取数据
+                if(deptId!=null){
+                    Optional<Department> first = allDepartmentList.stream().filter(ad -> ad.getDepartmentId().equals(deptId)).findFirst();
+                    if(first.isPresent()){
+                        if(deptIds.contains(first.get().getSuperiorId())||deptIds.contains(deptId)){
+                            filterDeptIds= getBranchDepartment(deptId,allDepartmentList);
+                        }else {
+                            filterDeptIds=new ArrayList<>();
+                            filterDeptIds.add(-1);
+                        }
+                    }
+                }
+            }
+            //deptIds:管理的部门;filterDeptIds:筛选的部门;deptRelatedProjectIds:负责部门相关联的项目
+            List<Map<String, Object>> list = projectMapper.getExportDegreeCost(companyId, startDate, endDate,projectId,deptIds,filterDeptIds,deptRelatedProjectIds);
+            TimeType timeType = timeTypeMapper.selectById(companyId);
+            BigDecimal totalMoneyCost = BigDecimal.valueOf(0);
+            List<List<String>> allList=null ;
+            List<String> sumRow = null;
+            List<String> headList = new ArrayList<String>();
+            //headList.add("项目编号");
+            headList.add(MessageUtils.message("entry.projectId"));
+            //headList.add("项目名称");
+            headList.add(MessageUtils.message("entry.projectName"));
+            //headList.add("项目分类");
+            headList.add(MessageUtils.message("entry.projectType"));
+            //headList.add("人员");
+            headList.add(MessageUtils.message("entry.personnel"));
+            //headList.add("部门");
+            headList.add(MessageUtils.message("excel.department"));
+            headList.add(timeType.getCustomDegreeName());
+            if(functionTimeList.size()>0){
+                //headList.add("工时(h)");
+                headList.add(MessageUtils.message("entry.workHours")+"(h)");
+            }
+            if(functionCostList.size()>0){
+                //headList.add("成本(元)");
+                headList.add(MessageUtils.message("entry.cost")+"(元)");
+            }
+
+            allList=new ArrayList<>();
+            allList.add(headList);
+            double totalCostTime = 0;
+            for (Map<String, Object> map : list) {
+                if (!map.containsKey("cost")) {
+                    map.put("cost", 0);
+                }
+                if (!map.containsKey("costMoney")) {
+                    map.put("costMoney", 0);
+                } else {
+                    totalMoneyCost = totalMoneyCost.add((BigDecimal)map.get("costMoney"));
+                }
+                totalCostTime += (Double)map.get("cost");
+                List<String> rowData = new ArrayList<String>();
+                rowData.add("");
+                rowData.add("");
+                rowData.add("");
+                rowData.add("");
+                rowData.add("");
+                rowData.add(map.get("name")==null?"未分配":(String)map.get("name"));
+
+                if(functionTimeList.size()>0){
+                    rowData.add(((Double)map.get("cost")).toString());
+                }
+                if (functionCostList.size()>0){
+                    rowData.add(((BigDecimal)map.get("costMoney")).toString());
+                }
+                allList.add(rowData);
+                String degreeId = "-1";
+                if (map.containsKey("id")){
+                    degreeId = map.get("id").toString();
+                }
+                List<Map<String, Object>> membList = projectMapper.getDegreeDetailCost(companyId,startDate, endDate,degreeId,filterDeptIds);
+                map.put("membList", membList);
+                for (Map<String, Object> membMap : membList) {
+                    List<String> membRowData = new ArrayList<String>();
+                    membRowData.add(membMap.get("projectCode")==null?"":membMap.get("projectCode").toString());
+                    membRowData.add(membMap.get("projectName")==null?"":membMap.get("projectName").toString());
+                    membRowData.add(membMap.get("categoryName")==null?"":membMap.get("categoryName").toString());
+                    if(wxCorpInfo!=null&&wxCorpInfo.getSaasSyncContact()==1){
+                        membRowData.add(("$userName="+membMap.get("corpwxUserId")+"$"));
+                        if(membMap.get("departmentName").equals("未分配")){
+                            membRowData.add("未分配");
+                        }else {
+                            membRowData.add((String)("$departmentName="+membMap.get("corpwxDeptId")+"$"));
+                        }
+                    }else {
+                        membRowData.add((String)membMap.get("name"));
+                        membRowData.add((String)membMap.get("departmentName"));
+                    }
+                    membRowData.add("");
+                    if(functionTimeList.size()>0){
+                        membRowData.add(((Double)membMap.get("cost")).toString());
+                    }
+                    if (functionCostList.size()>0){
+                        membRowData.add(((BigDecimal)membMap.get("costMoney")).toString());
+                    }
+                    allList.add(membRowData);
+                }
+            }
+            //合计
+            sumRow=new ArrayList<>();
+            //sumRow.add("合计");
+            sumRow.add(MessageUtils.message("entry.total"));
+            sumRow.add("");
+            sumRow.add("");
+            sumRow.add("");
+            sumRow.add("");
+            sumRow.add("");
+            if(functionTimeList.size()>0){
+                sumRow.add(""+new BigDecimal(totalCostTime).setScale(1, BigDecimal.ROUND_HALF_UP));
+            }
+            if (functionCostList.size()>0){
+                sumRow.add(totalMoneyCost.toString());
+            }
+            allList.add(sumRow);
+            //生成excel文件导出
+            //String fileName = "项目成本工时统计_"+System.currentTimeMillis();
+            String fileName = MessageUtils.message("fileName.projectCost")+System.currentTimeMillis();
+            return excelExportService.exportGeneralExcelByTitleAndList(wxCorpInfo,fileName , allList, path);
+        } catch (NullPointerException e) {
+            e.printStackTrace();
+            //httpRespMsg.setError("验证失败");
+            httpRespMsg.setError(MessageUtils.message("access.verificationError"));
+            return httpRespMsg;
+        } catch (Exception exception) {
+            exception.printStackTrace();
+            httpRespMsg.setError(exception.getMessage());
+        }
+        return httpRespMsg;
+    }
+
     private List<GanttDataItem> getUserGanttDataItemList(GanttDataItem userGantt, List<GanttDataItem> itemList) {
         if(itemList==null){
             itemList=new ArrayList<>();

+ 71 - 1
fhKeeper/formulahousekeeper/management-platform/src/main/resources/mapper/ProjectMapper.xml

@@ -836,7 +836,7 @@
     </select>
     <!--按照项目内的阶段名称分组统计工时-->
     <select id="getDegreeCost" resultType="java.util.Map">
-        SELECT IFNULL(b.name, "未分配") as name, SUM(a.working_time) AS cost, SUM(a.cost) AS costMoney
+        SELECT IFNULL(b.name, "未分配") as name, SUM(a.working_time) AS cost, SUM(a.cost) AS costMoney, a.project_id AS projectId
         FROM report AS a
         left join report_extra_degree b on b.id = a.degree_id
         WHERE
@@ -1485,4 +1485,74 @@
             limit #{start},#{size}
         </if>
     </select>
+
+    <!--获取按维度分组的工时成本-->
+    <select id="getExportDegreeCost" resultType="java.util.Map">
+        SELECT r.name as name,r.id as id,SUM(b.working_time) AS cost, SUM(b.cost) AS costMoney
+        FROM project AS a
+        LEFT JOIN report AS b ON b.project_id = a.id
+        LEFT JOIN report_extra_degree AS r ON b.degree_id = r.id
+        JOIN user AS c ON b.creator_id = c.id
+        WHERE a.company_id = #{companyId}
+        <if test="projectId != null">
+            AND a.id = #{projectId}
+        </if>
+        <if test="startDate != null and endDate != null">
+            AND b.create_date between #{startDate} and #{endDate}
+        </if>
+        <choose>
+            <when test="filterDeptIds!=null and filterDeptIds.size()>0">
+                and b.dept_id in
+                <foreach collection="filterDeptIds" open="(" item="item" separator="," close=")">
+                    #{item}
+                </foreach>
+            </when>
+            <otherwise>
+                <if test="deptIds!=null and deptIds.size()>0">
+                    and (b.dept_id in
+                    <foreach collection="deptIds" open="(" item="item" separator="," close=")">
+                        #{item}
+                    </foreach>
+                    <if test="deptRelatedProjectIds.size() > 0">
+                        or a.id in
+                        <foreach collection="deptRelatedProjectIds" open="(" item="pid" separator="," close=")">
+                            #{pid}
+                        </foreach>
+                    </if>
+                    )
+                </if>
+            </otherwise>
+        </choose>
+        AND b.state = 1
+        GROUP BY b.degree_id
+        ORDER BY b.degree_id
+    </select>
+
+    <!--获取某个维度每个人分别需要的工时-->
+    <select id="getDegreeDetailCost" resultType="java.util.Map">
+        SELECT b.id as creatorId,a.project_id as projectId, b.name,b.corpwx_userid as corpwxUserId,a.dept_id as deptId,department.corpwx_deptid as corpwxDeptId, IFNULL(department.department_name, '未分配') as departmentName, SUM(a.working_time) AS cost, SUM(a.cost) AS costMoney,
+        p.project_name as projectName,p.project_code as projectCode,p.category_name as categoryName
+        FROM report AS a
+        JOIN user AS b ON a.creator_id = b.id
+        left JOIN project AS P on a.project_id = p.id
+        left join department on department.department_id = a.dept_id
+        WHERE a.company_id=#{companyId}
+        and a.state = 1
+        <if test="degreeId != null">
+            and a.degree_id = #{degreeId}
+        </if>
+        <if test="startDate != null and endDate != null">
+            AND a.create_date between #{startDate} and #{endDate}
+        </if>
+        <choose>
+            <when test="filterDeptIds!=null and filterDeptIds.size()>0">
+                and a.dept_id in
+                <foreach collection="filterDeptIds" open="(" item="item" separator="," close=")">
+                    #{item}
+                </foreach>
+            </when>
+        </choose>
+        GROUP BY b.id, a.dept_id, a.degree_id
+        ORDER BY b.id ASC, a.dept_id ASC
+    </select>
 </mapper>