浏览代码

补充调休模块逻辑

zhouyy 5 月之前
父节点
当前提交
09305de7ef

+ 19 - 3
fhKeeper/formulahousekeeper/management-platform/src/main/java/com/management/platform/controller/LeaveSheetController.java

@@ -3,7 +3,9 @@ package com.management.platform.controller;
 
 import com.alibaba.fastjson.JSONObject;
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
-import com.management.platform.entity.*;
+import com.management.platform.entity.LeaveSheet;
+import com.management.platform.entity.TimeType;
+import com.management.platform.entity.User;
 import com.management.platform.entity.vo.ExportLeave;
 import com.management.platform.mapper.DepartmentMapper;
 import com.management.platform.mapper.SysFunctionMapper;
@@ -13,8 +15,10 @@ import com.management.platform.service.DepartmentService;
 import com.management.platform.service.LeaveSheetService;
 import com.management.platform.util.DockWithMLD;
 import com.management.platform.util.HttpRespMsg;
-import org.springframework.util.StringUtils;
-import org.springframework.web.bind.annotation.*;
+import org.springframework.web.bind.annotation.PostMapping;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RequestParam;
+import org.springframework.web.bind.annotation.RestController;
 
 import javax.annotation.Resource;
 import javax.servlet.http.HttpServletRequest;
@@ -54,6 +58,18 @@ public class LeaveSheetController {
     TimeTypeMapper timeTypeMapper;
 
 
+    /***
+     * 获取员工调休时长
+     * @param userName
+     * @param request
+     * @return
+     */
+    @PostMapping("/getCompanyUserTime")
+    public HttpRespMsg getCompanyUserTime(@RequestParam(value = "userName",required = false) String userName,HttpServletRequest request) {
+        HttpRespMsg httpRespMsg = new HttpRespMsg();
+        httpRespMsg = leaveSheetService.getCompanyUserTime(userName,request);
+        return httpRespMsg;
+    }
     /**
      * 提交请假申请单
      * @param sheet 请假单封装数据

+ 16 - 0
fhKeeper/formulahousekeeper/management-platform/src/main/java/com/management/platform/entity/vo/UserRestTimeVO.java

@@ -0,0 +1,16 @@
+package com.management.platform.entity.vo;
+
+import lombok.Data;
+
+import java.math.BigDecimal;
+
+@Data
+public class UserRestTimeVO {
+    private String userId;
+    private String userName;
+    private BigDecimal restTimeHour;
+    private BigDecimal overTimeHour;
+
+    private String restTimeHourStr;
+    private String restTimeDayStr;
+}

+ 5 - 4
fhKeeper/formulahousekeeper/management-platform/src/main/java/com/management/platform/mapper/LeaveSheetMapper.java

@@ -1,11 +1,10 @@
 package com.management.platform.mapper;
 
-import com.management.platform.entity.LeaveSheet;
 import com.baomidou.mybatisplus.core.mapper.BaseMapper;
-import com.management.platform.entity.User;
-import org.apache.tomcat.jni.Local;
+import com.management.platform.entity.LeaveSheet;
+import com.management.platform.entity.vo.UserRestTimeVO;
+import org.apache.ibatis.annotations.Param;
 
-import java.time.LocalDate;
 import java.util.List;
 import java.util.Map;
 
@@ -26,4 +25,6 @@ public interface LeaveSheetMapper extends BaseMapper<LeaveSheet> {
     List<LeaveSheet> selectLeave(Integer companyId, String startDate, String endDate);
 
     List<Map<String,Object>> selectLeaveAll(Integer companyId, String startDate, String endDate,List<Integer> branchDepartment,List<Integer> deptIds);
+
+    List<UserRestTimeVO> getCompanyUserRestTimeHours(@Param("companyId") Integer companyId,@Param("userName")String userName);
 }

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

@@ -4,6 +4,7 @@ import com.baomidou.mybatisplus.core.mapper.BaseMapper;
 import com.management.platform.entity.Report;
 import com.management.platform.entity.bo.BonusDataBO;
 import com.management.platform.entity.vo.UserProjectBonusTimeVO;
+import com.management.platform.entity.vo.UserRestTimeVO;
 import org.apache.ibatis.annotations.Param;
 import org.apache.ibatis.annotations.Select;
 import org.apache.ibatis.annotations.Update;
@@ -251,4 +252,6 @@ public interface ReportMapper extends BaseMapper<Report> {
     void batchUpdateReportStageToNull(List<Integer> list);
 
     List<UserProjectBonusTimeVO> getUserProjectsByBonusBO(BonusDataBO bonusDataBO);
+
+    List<UserRestTimeVO> getCompanyUserOverTimeHours(@Param("companyId") Integer companyId,@Param("userName") String userName);
 }

+ 3 - 4
fhKeeper/formulahousekeeper/management-platform/src/main/java/com/management/platform/service/LeaveSheetService.java

@@ -1,14 +1,11 @@
 package com.management.platform.service;
 
-import com.management.platform.entity.ExpenseSheet;
-import com.management.platform.entity.LeaveSheet;
 import com.baomidou.mybatisplus.extension.service.IService;
+import com.management.platform.entity.LeaveSheet;
 import com.management.platform.util.HttpRespMsg;
 
 import javax.servlet.http.HttpServletRequest;
-import java.time.LocalDate;
 import java.util.List;
-import java.util.Map;
 
 /**
  * <p>
@@ -43,4 +40,6 @@ public interface LeaveSheetService extends IService<LeaveSheet> {
     float leaveTimeSum(Integer companyId, String startDate, String endDate, float standardHours, float allDay, List<LeaveSheet> leaveSheets);
 
     HttpRespMsg leaveDays(String startDate, String endDate);
+
+    HttpRespMsg getCompanyUserTime(String userName, HttpServletRequest request);
 }

+ 65 - 5
fhKeeper/formulahousekeeper/management-platform/src/main/java/com/management/platform/service/impl/LeaveSheetServiceImpl.java

@@ -6,29 +6,27 @@ 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;
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import com.management.platform.controller.AuditWorkflowSettingController;
 import com.management.platform.entity.*;
 import com.management.platform.entity.vo.SysRichFunction;
+import com.management.platform.entity.vo.UserRestTimeVO;
 import com.management.platform.mapper.*;
 import com.management.platform.service.*;
-import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
-import com.management.platform.util.ExcelUtil;
 import com.management.platform.util.HttpRespMsg;
 import com.management.platform.util.MessageUtils;
 import com.management.platform.util.WorkDayCalculateUtils;
 import org.springframework.beans.factory.annotation.Value;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
+import org.springframework.util.CollectionUtils;
 import org.springframework.util.StringUtils;
-import org.springframework.web.bind.annotation.RequestParam;
 
 import javax.annotation.Resource;
 import javax.servlet.http.HttpServletRequest;
-import javax.xml.transform.Source;
 import java.math.BigDecimal;
 import java.time.LocalDate;
 import java.time.LocalDateTime;
-import java.time.ZoneOffset;
 import java.time.format.DateTimeFormatter;
 import java.util.*;
 import java.util.stream.Collectors;
@@ -831,4 +829,66 @@ public class LeaveSheetServiceImpl extends ServiceImpl<LeaveSheetMapper, LeaveSh
         httpRespMsg.data = leaveDays;
         return httpRespMsg;
     }
+
+    @Override
+    public HttpRespMsg getCompanyUserTime(String userName,HttpServletRequest request) {
+        HttpRespMsg httpRespMsg = new HttpRespMsg();
+        User user= userMapper.selectById(request.getHeader("token"));
+        if(null == user){
+            httpRespMsg.setError("用户不存在");
+            return httpRespMsg;
+        }
+
+        List<UserRestTimeVO> resList = new ArrayList<>();
+
+        //获取该公司全天工作时长
+        TimeType timeType = timeTypeMapper.selectById(user.getCompanyId());
+        if(null == timeType){
+            httpRespMsg.setError("公司时间信息未完善,请填写");
+            return httpRespMsg;
+        }
+        float allDayHours = timeType.getAllday();
+        if(allDayHours <=0){
+            httpRespMsg.setError("公司全天时长有误,请完善对应信息");
+            return httpRespMsg;
+        }
+
+        //获取加班时长 creatorId overTimeHours
+        List<UserRestTimeVO> overTimeHourList = reportMapper.getCompanyUserOverTimeHours(user.getCompanyId(),userName);
+
+        //获取已经休息的时长
+        List<UserRestTimeVO> restTimeHourList = leaveSheetMapper.getCompanyUserRestTimeHours(user.getCompanyId(),userName);
+
+        if(!CollectionUtils.isEmpty(overTimeHourList)){
+            Map<String, UserRestTimeVO> overTimeHourMap = overTimeHourList.stream().collect(Collectors.toMap(UserRestTimeVO::getUserId, t -> t));
+            Map<String, UserRestTimeVO> restTimeHourMap = new HashMap<>();
+            if(!CollectionUtils.isEmpty(restTimeHourMap)){
+                restTimeHourMap = restTimeHourList.stream().collect(Collectors.toMap(UserRestTimeVO::getUserId, t -> t));
+            }
+
+            for (Map.Entry<String, UserRestTimeVO> entry : overTimeHourMap.entrySet()) {
+                String userId = entry.getKey();
+                UserRestTimeVO tmpUserTimeVO = entry.getValue();
+                UserRestTimeVO restTimeUserVO = restTimeHourMap.get(userId);
+                if(null != restTimeUserVO){
+                    BigDecimal leftTimeHour = tmpUserTimeVO.getOverTimeHour().subtract(restTimeUserVO.getRestTimeHour());
+                    if(0 > leftTimeHour.compareTo(new BigDecimal(0))){
+                        tmpUserTimeVO.setRestTimeHourStr("0.0");
+                        tmpUserTimeVO.setRestTimeDayStr("0.0");
+                    }else{
+                        tmpUserTimeVO.setRestTimeHourStr(leftTimeHour.setScale(1,BigDecimal.ROUND_HALF_UP).toString());
+                        tmpUserTimeVO.setRestTimeDayStr(leftTimeHour.divide(new BigDecimal(allDayHours), 1, BigDecimal.ROUND_HALF_UP).toString());
+                    }
+                }else{
+                    //restTimeHour就是调休时长
+                    tmpUserTimeVO.setRestTimeHourStr(tmpUserTimeVO.getOverTimeHour().setScale(1,BigDecimal.ROUND_HALF_UP).toString());
+                    tmpUserTimeVO.setRestTimeDayStr(tmpUserTimeVO.getOverTimeHour().divide(new BigDecimal(allDayHours), 1, BigDecimal.ROUND_HALF_UP).toString());
+                }
+                resList.add(tmpUserTimeVO);
+            }
+            httpRespMsg.setData(resList);
+        }
+
+        return httpRespMsg;
+    }
 }

+ 23 - 0
fhKeeper/formulahousekeeper/management-platform/src/main/resources/mapper/LeaveSheetMapper.xml

@@ -76,4 +76,27 @@
             </foreach>
         </if>
     </select>
+    <select id="getCompanyUserRestTimeHours" resultType="com.management.platform.entity.vo.UserRestTimeVO">
+        select tmp1.id as userId,tmp1.name as userName,ifnull(tmp2.restTimeHour,0) restTimeHour
+        from
+            (
+                select id,name
+                from user
+                <where>
+                    company_id = #{companyId}
+                    <if test="userName != null and userName !='' ">
+                        and name like concat('%',#{userName},'%')
+                    </if>
+                </where>
+            )tmp1
+                left join (
+                select owner_id userId,ifnull(sum(time_hours),0) as restTimeHour
+                from leave_sheet
+                where
+                    company_id = #{companyId}
+                  and leave_type = 6
+                  and status not in (2,3)
+                group by owner_id
+            ) tmp2 on tmp1.id = tmp2.userId
+    </select>
 </mapper>

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

@@ -1569,6 +1569,26 @@
         ) tmp2 on tmp1.creator_id = tmp2.creator_id and tmp1.project_id = tmp2.project_id
 
     </select>
+    <select id="getCompanyUserOverTimeHours" resultType="com.management.platform.entity.vo.UserRestTimeVO">
+        select tmp1.id as userId,tmp1.name as userName,ifnull(tmp2.overTimeHour,0) as overTimeHour
+        from
+            (
+                select id,name
+                from user
+                <where>
+                    company_id = #{companyId}
+                <if test="userName != null and userName !='' ">
+                    and name like concat('%',#{userName},'%')
+                </if>
+                </where>
+            )tmp1
+                left join (
+                select creator_id userId,IFNULL(sum(overtime_hours),0) as overTimeHour
+                from report
+                where company_id = #{companyId}
+                group by creator_id
+            ) tmp2 on tmp1.id = tmp2.userId
+    </select>
 
     <update id="batchUpdateReportStageToNull">
         update report set stage=null where id in