Browse Source

有效工时率编写,待威派格提供人员名单

yusm 1 year ago
parent
commit
cbc97bc062

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

@@ -1412,6 +1412,10 @@ public class ProjectController {
         return projectService.syncProjectWithSap(startDate,endDate);
     }
 
+    @RequestMapping("/getEffectiveLaborHourRate")
+    public HttpRespMsg getEffectiveLaborHourRate(String startDate,String endDate){
+        return projectService.getEffectiveLaborHourRate(startDate,endDate);
+    }
 
 
 }

+ 22 - 0
fhKeeper/formulahousekeeper/management-platform/src/main/java/com/management/platform/entity/vo/LaborHourRateVo.java

@@ -0,0 +1,22 @@
+package com.management.platform.entity.vo;
+
+import lombok.Data;
+import lombok.EqualsAndHashCode;
+import lombok.experimental.Accessors;
+
+import java.util.List;
+
+@Data
+@EqualsAndHashCode(callSuper = false)
+@Accessors(chain = true)
+public class LaborHourRateVo {
+    private Integer root_id;//大区的id
+    private String department_name;//部门名称
+    private List<Integer> child_ids;//子孙的id列表
+    private Double working_time;//实报工时
+    private Integer count;//在职人数
+    private Integer date_count;//应报工时天数
+    private Integer day_time;//日标准工时
+    private Long total_time;//应报工时
+    private Double rate;//比率
+}

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

@@ -7,6 +7,7 @@ import org.apache.ibatis.annotations.Select;
 import org.apache.ibatis.annotations.Update;
 
 import java.time.LocalDate;
+import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
@@ -180,4 +181,6 @@ public interface ReportMapper extends BaseMapper<Report> {
     List<Map<String, Object>> getCcReportByDate(@Param("date") String date, @Param("id") String id, @Param("state") Integer state);
 
     List<Map<String, Object>> getPushProjectReportToSap(Integer companyId, String startDate, String endDate,String userId);
+
+    List<Report> getSumWorkingTime(ArrayList<Integer> deptIds, String startDate, String endDate);
 }

+ 5 - 0
fhKeeper/formulahousekeeper/management-platform/src/main/java/com/management/platform/mapper/UserMapper.java

@@ -9,6 +9,7 @@ import org.apache.ibatis.annotations.Param;
 import org.apache.ibatis.annotations.Update;
 
 import java.time.LocalDate;
+import java.util.ArrayList;
 import java.util.List;
 import java.util.Map;
 
@@ -43,4 +44,8 @@ public interface UserMapper extends BaseMapper<User> {
     void setSuperiorNull(String userId);
 
     List<Map<String, Object>> getWeekPushUserList(Integer companyId, LocalDate startDate, LocalDate lastDay);
+
+    int getIsActiveCount(ArrayList<Integer> deptIds, String startDate, String endDate);
+
+    List<User> getInActiveList(ArrayList<Integer> deptIds, String startDate, String endDate);
 }

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

@@ -262,4 +262,6 @@ public interface ProjectService extends IService<Project> {
     HttpRespMsg getFunWorkContextList(Integer id);
 
     HttpRespMsg syncProjectWithSap(String startDate,String endDate);
+
+    HttpRespMsg getEffectiveLaborHourRate(String startDate, String endDate);
 }

+ 77 - 4
fhKeeper/formulahousekeeper/management-platform/src/main/java/com/management/platform/service/impl/ProjectServiceImpl.java

@@ -3,6 +3,7 @@ package com.management.platform.service.impl;
 import com.alibaba.fastjson.JSON;
 import com.alibaba.fastjson.JSONArray;
 import com.alibaba.fastjson.JSONObject;
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
@@ -53,10 +54,7 @@ import java.math.RoundingMode;
 import java.sql.Array;
 import java.sql.Timestamp;
 import java.text.*;
-import java.time.Duration;
-import java.time.LocalDate;
-import java.time.LocalDateTime;
-import java.time.LocalTime;
+import java.time.*;
 import java.time.chrono.ChronoLocalDate;
 import java.time.format.DateTimeFormatter;
 import java.time.temporal.TemporalAdjusters;
@@ -11199,6 +11197,81 @@ public class ProjectServiceImpl extends ServiceImpl<ProjectMapper, Project> impl
         return msg;
     }
 
+    @Override
+    public HttpRespMsg getEffectiveLaborHourRate(String startDate, String endDate) {
+        LambdaQueryWrapper<Department> lqw = new LambdaQueryWrapper<>();
+        lqw.in(Department::getDepartmentId,3759,3899,3900,3901,3902,3903,3904,3906,5719);
+        List<Department> departments = departmentMapper.selectList(lqw);
+
+        ArrayList<LaborHourRateVo> laborHourRateVos = new ArrayList<>();
+
+        int dayCount = WorkDayCalculateUtils.getWorkDaysCountInRange(startDate, endDate, 0);//应报工时天数
+
+        for (Department department : departments) {
+            LaborHourRateVo laborHourRateVo = new LaborHourRateVo();
+            laborHourRateVo.setRoot_id(department.getDepartmentId());
+            laborHourRateVo.setDepartment_name(department.getDepartmentName());
+            ArrayList<Integer> deptIds = new ArrayList<>();
+            setDeptIdList(department.getDepartmentId(),deptIds);
+            deptIds.add(department.getDepartmentId());
+            laborHourRateVo.setChild_ids(deptIds);
+            //查询该公司下某头部部门及子部门在四种项目下的工时之和,某个时间段内
+            List<Report> reportList= reportMapper.getSumWorkingTime(deptIds,startDate,endDate);
+            ArrayList<Report> reports = new ArrayList<>();//按时填报的report
+            for (Report report : reportList) {
+                LocalDate createDate = report.getCreateDate();
+                LocalDateTime createTime = report.getCreateTime();
+                LocalDate createTimeLocalDate = createTime.toLocalDate();
+                boolean b1 = WorkDayCalculateUtils.sameMonth(createDate, createTimeLocalDate);
+                boolean b2 = WorkDayCalculateUtils.sameWeek(createDate, createTimeLocalDate);
+                if (b1&&b2){
+                    reports.add(report);
+                }
+            }
+            double timeSum = reports.stream().mapToDouble(Report::getWorkingTime).sum();
+
+
+            int inActiveDays=0;
+            //查询  入职时间早于起始时间 但是员工在这段时间离职 的员工列表
+            List<User> inActiveList=userMapper.getInActiveList(deptIds,startDate,endDate);
+            //获取离职员工在此期间工作多少天
+            for (User user : inActiveList) {
+                DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
+                String inactiveDate = user.getInactiveDate().format(formatter);
+                inActiveDays+=WorkDayCalculateUtils.getWorkDaysCountInRange(startDate,inactiveDate,0);
+            }
+            //-- 查询 有多少个  入职时间早于起始时间 并且是在职的员工
+            int isActiveCount=userMapper.getIsActiveCount(deptIds,startDate,endDate);
+
+            laborHourRateVo.setWorking_time(timeSum);
+            laborHourRateVo.setDate_count(dayCount);
+            laborHourRateVo.setCount(isActiveCount);
+            laborHourRateVo.setTotal_time((long) (inActiveList.size()*8*inActiveDays+isActiveCount*8*dayCount));//应报工时还少了在职的加上可能辞职的
+            System.out.println("============="+inActiveDays);
+            System.out.println("============="+isActiveCount);
+            laborHourRateVo.setDay_time(8);
+            laborHourRateVos.add(laborHourRateVo);
+        }
+        HttpRespMsg msg = new HttpRespMsg();
+        msg.setData(laborHourRateVos);
+        return msg;
+    }
+
+
+    public void setDeptIdList(Integer departmentId,List<Integer> deptIds){
+        LambdaQueryWrapper<Department> lqw = new LambdaQueryWrapper<>();
+        lqw.eq(Department::getSuperiorId,departmentId);
+        List<Department> departmentList = departmentMapper.selectList(lqw);
+
+        if (departmentList!=null&&departmentList.size()>0){
+            List<Integer> collect = departmentList.stream().map(Department::getDepartmentId).collect(Collectors.toList());
+            deptIds.addAll(collect);
+            for (Integer id : collect) {
+                setDeptIdList(id,deptIds);
+            }
+        }
+    }
+
     private void syncServiceData(String startDate, String endDate, Integer companyId) {
         List<ReportExtraDegree> extraDegrees = reportExtraDegreeService.list(new QueryWrapper<ReportExtraDegree>().eq("company_id", companyId));
         //配置请求xml

+ 1 - 0
fhKeeper/formulahousekeeper/management-platform/src/main/java/com/management/platform/task/TimingTask.java

@@ -38,6 +38,7 @@ import java.security.SecureRandom;
 import java.sql.Timestamp;
 import java.text.DecimalFormat;
 import java.time.*;
+import java.time.Period;
 import java.time.format.DateTimeFormatter;
 import java.time.temporal.TemporalAccessor;
 import java.time.temporal.TemporalAdjusters;

+ 23 - 1
fhKeeper/formulahousekeeper/management-platform/src/main/java/com/management/platform/util/WorkDayCalculateUtils.java

@@ -7,6 +7,7 @@ import java.text.SimpleDateFormat;
 import java.time.DayOfWeek;
 import java.time.LocalDate;
 import java.time.format.DateTimeFormatter;
+import java.time.temporal.WeekFields;
 import java.util.*;
 
 public class WorkDayCalculateUtils {
@@ -291,7 +292,28 @@ public class WorkDayCalculateUtils {
     }
 
 
+
+    //判断俩日期是否在同一周
+    public static boolean sameWeek(LocalDate date1, LocalDate date2) {
+        WeekFields weekFields = WeekFields.of(Locale.getDefault());
+        int week1 = date1.get(weekFields.weekOfWeekBasedYear());
+        System.out.println(week1);
+        int week2 = date2.get(weekFields.weekOfWeekBasedYear());
+        System.out.println(week2);
+        return week1 == week2;
+    }
+
+    //判断俩日期是否在月份
+    public static boolean sameMonth(LocalDate date1, LocalDate date2) {
+        return date1.getYear() == date2.getYear() && date1.getMonth() == date2.getMonth();
+    }
+
     public static void main(String[] args) {
-        System.out.println(getWorkDaysCountInRange("2022-08-06","2022-08-08", 1));
+        System.out.println(getWorkDaysCountInRange("2023-11-01","2023-11-04", 0));
+
+        LocalDate date1 = LocalDate.of(2023, 12, 1);
+        LocalDate date2 = LocalDate.of(2023, 11, 30);
+//        System.out.println(sameWeek(date1, date2));
+//        System.out.println(sameMonth(date1, date2));
     }
 }

+ 1 - 1
fhKeeper/formulahousekeeper/management-platform/src/main/resources/application.yml

@@ -15,7 +15,7 @@ spring:
       location: C:/upload/
   datasource:
     driver-class-name: com.mysql.cj.jdbc.Driver
-    url: jdbc:mysql://47.101.180.183:17089/man_mingyi?useUnicode=true&characterEncoding=utf8&serverTimezone=GMT%2B8&rewriteBatchedStatements=true&useSSL=false
+    url: jdbc:mysql://47.101.180.183:17089/man_dev?useUnicode=true&characterEncoding=utf8&serverTimezone=GMT%2B8&rewriteBatchedStatements=true&useSSL=false
     username: root
     password: P011430@Huoshi*
     

+ 12 - 0
fhKeeper/formulahousekeeper/management-platform/src/main/resources/mapper/ReportMapper.xml

@@ -966,4 +966,16 @@
             and r.creator_id=#{userId}
         </if>
     </select>
+
+    <select id="getSumWorkingTime" resultType="com.management.platform.entity.Report">
+        SELECT * FROM report r
+        LEFT JOIN project p
+        ON r.project_id=p.id
+        WHERE p.company_id=936 AND p.category IN(168,169,171,172)
+        AND r.dept_id IN
+        <foreach collection="deptIds" item="id" open="(" close=")" separator=",">
+            #{id}
+        </foreach>
+        AND r.create_date BETWEEN #{startDate} AND #{endDate}
+    </select>
 </mapper>

+ 29 - 0
fhKeeper/formulahousekeeper/management-platform/src/main/resources/mapper/UserMapper.xml

@@ -181,4 +181,33 @@
         select user.id, name, department.department_name from user left join department on department.department_id = user.department_id
             ${ew.customSqlSegment}
     </select>
+
+    <select id="getIsActiveCount" resultType="java.lang.Integer">
+        SELECT count(1) isActiveCount FROM user
+        WHERE id IN (SELECT DISTINCT r.creator_id  FROM report r
+        LEFT JOIN project p
+        ON r.project_id=p.id
+        WHERE p.company_id=936 AND p.category IN(168,169,171,172)
+        AND r.dept_id IN
+        <foreach collection="deptIds" item="id" open="(" close=")" separator=",">
+            #{id}
+        </foreach>
+        AND r.create_date BETWEEN #{startDate} AND #{endDate})
+        AND is_active=1 AND (inactive_date >= #{endDate} OR inactive_date is null) AND induction_date &lt;= #{startDate}
+    </select>
+
+    <select id="getInActiveList" resultType="com.management.platform.entity.User">
+        SELECT user.* FROM user
+        WHERE id in
+        (SELECT DISTINCT r.creator_id  FROM report r
+        LEFT JOIN project p
+        ON r.project_id=p.id
+        WHERE p.company_id=936 AND p.category IN(168,169,171,172)
+        AND r.dept_id IN
+        <foreach collection="deptIds" item="id" open="(" close=")" separator=",">
+            #{id}
+        </foreach>
+        AND r.create_date BETWEEN #{startDate} AND #{endDate})
+        AND inactive_date BETWEEN #{startDate} AND #{endDate} and induction_date &lt;= #{startDate}
+    </select>
 </mapper>

+ 1 - 0
fhKeeper/formulahousekeeper/ops-platform/src/main/java/com/management/platform/mapper/CompanyMapper.java

@@ -2,6 +2,7 @@ package com.management.platform.mapper;
 
 import com.management.platform.entity.Company;
 import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+import org.apache.ibatis.annotations.Delete;
 
 /**
  * <p>