Parcourir la source

工时统计和导出接口调整

fuyuchuan il y a 5 mois
Parent
commit
dd33803ae7

+ 14 - 42
service-iot/service-iot-biz/src/main/java/com/usky/iot/controller/web/PmWorkContentController.java

@@ -9,6 +9,7 @@ import com.usky.common.log.enums.BusinessType;
 import com.usky.iot.domain.PmWorkContent;
 import com.usky.iot.domain.PmWorkReport;
 import com.usky.iot.service.PmWorkContentService;
+import com.usky.iot.service.vo.PmWorkHourStatisticRequestVO;
 import com.usky.iot.service.vo.WorkTimeExportTwoVO;
 import com.usky.iot.service.vo.WorkTimeExportVO;
 import org.apache.commons.lang3.StringUtils;
@@ -19,6 +20,7 @@ import javax.servlet.http.HttpServletResponse;
 import java.io.IOException;
 import java.time.LocalDate;
 import java.time.temporal.TemporalAdjusters;
+import java.util.ArrayList;
 import java.util.List;
 
 /**
@@ -48,7 +50,7 @@ public class PmWorkContentController {
                                                    @RequestParam(value = "endDate", required = false) String endDate,
                                                    @RequestParam(value = "projectName", required = false) String projectName,
                                                    @RequestParam(value = "projectAscription", required = false, defaultValue = "1") Integer projectAscription,
-                                                   @RequestParam(value = "submitterId" , required = false) Long submitterId) {
+                                                   @RequestParam(value = "submitterId", required = false) Long submitterId) {
         return ApiResult.success(pmWorkContentService.projectQuery(startDate, endDate, projectName, projectAscription, submitterId));
     }
 
@@ -97,47 +99,22 @@ public class PmWorkContentController {
 
     /**
      * 工时统计
-     *
-     * @param userId
-     * @param projectId
-     * @param filter
-     * @param startDate
-     * @param endDate
-     * @param workerOrProject
      * @return
      */
-    @GetMapping("/workHourStatistic")
-    public ApiResult<List<Object>> workHourStatistic(@RequestParam(value = "userId", required = false) List<Long> userId,
-                                                     @RequestParam(value = "projectId", required = false) Integer projectId,
-                                                     @RequestParam(value = "filter", required = false, defaultValue = "1") Integer filter,
-                                                     @RequestParam(value = "startDate", required = false) String startDate,
-                                                     @RequestParam(value = "endDate", required = false) String endDate,
-                                                     @RequestParam(value = "workerOrProject", required = false, defaultValue = "1") Integer workerOrProject) {
-        if (StringUtils.isBlank(startDate) || StringUtils.isBlank(endDate)) {
-            startDate = LocalDate.now().with(TemporalAdjusters.firstDayOfYear()).toString();
-            endDate = LocalDate.now().with(TemporalAdjusters.lastDayOfYear()).toString();
-        }
-        return ApiResult.success(pmWorkContentService.workHourStatistic(userId, projectId, filter, startDate, endDate, workerOrProject));
+    @PostMapping("/workHourStatistic")
+    public ApiResult<List<Object>> workHourStatistic(@RequestBody PmWorkHourStatisticRequestVO requestVO) {
+        return ApiResult.success(pmWorkContentService.workHourStatistic(requestVO));
     }
 
-    /**
-     * 工时明细导出
-     *
-     * @param response
-     * @param userId
-     * @param projectId
-     * @param startDate
-     * @param endDate
-     * @throws IOException
-     */
+/**
+ * 工时明细导出
+ *
+ * @param response
+ */
     @Log(title = "导出工时明细", businessType = BusinessType.EXPORT)
     @PostMapping("/workHourStatisticExport")
-    public void export(HttpServletResponse response,
-                       @RequestParam(value = "userId", required = false) Long userId,
-                       @RequestParam(value = "projectId", required = false) Integer projectId,
-                       @RequestParam(value = "startDate", required = false) String startDate,
-                       @RequestParam(value = "endDate", required = false) String endDate) throws IOException {
-        List<WorkTimeExportVO> list = pmWorkContentService.workHourStatisticExport(userId, projectId, startDate, endDate);
+    public void export(HttpServletResponse response, @RequestBody PmWorkHourStatisticRequestVO requestVO){
+        List<WorkTimeExportVO> list = pmWorkContentService.workHourStatisticExport(requestVO);
         ExcelUtil<WorkTimeExportVO> util = new ExcelUtil<WorkTimeExportVO>(WorkTimeExportVO.class);
         util.exportExcel(response, list, "工时明细", "工时明细");
     }
@@ -146,11 +123,6 @@ public class PmWorkContentController {
      * 工时导出
      *
      * @param response
-     * @param userId
-     * @param projectId
-     * @param startDate
-     * @param endDate
-     * @throws IOException
      */
     @Log(title = "导出工时统计", businessType = BusinessType.EXPORT)
     @PostMapping("/workHourExport")
@@ -163,7 +135,7 @@ public class PmWorkContentController {
                        @RequestParam(value = "workerOrProject", required = false, defaultValue = "1") Integer workerOrProject) throws IOException {
         List<WorkTimeExportTwoVO> list = pmWorkContentService.workHourExport(userId, projectId, filter, startDate, endDate, workerOrProject);
         ExcelUtil<WorkTimeExportTwoVO> util = new ExcelUtil<WorkTimeExportTwoVO>(WorkTimeExportTwoVO.class);
-        util.exportExcel(response, list, "工时明细", "工时明细");
+        util.exportExcel(response, list, "工时统计", "工时统计");
     }
 
 }

+ 2 - 10
service-iot/service-iot-biz/src/main/java/com/usky/iot/mapper/PmWorkContentMapper.java

@@ -36,18 +36,10 @@ public interface PmWorkContentMapper extends CrudMapper<PmWorkContent> {
     /**
      * 人员查询时增加部门隔离,项目维度不需要
      *
-     * @param userId
+     * @param userIds
      * @return
      */
-/*
-    List<WorkHoursStatisticsVO> statisticsDept(@Param("startTime") LocalDate startTime,
-                                               @Param("endTime") LocalDate endTime,
-                                               @Param("userId") Long userId,
-                                               @Param("tenantId") Integer tenantId,
-                                               @Param("deptId") Long deptId);
-*/
-
-    List<WorkTimeExportVO> workHourStatisticExport(@Param("userId") Long userId,
+    List<WorkTimeExportVO> workHourStatisticExport(@Param("userIds") List<Long> userIds,
                                                    @Param("projectId") Integer projectId,
                                                    @Param("startTime") LocalDate startTime,
                                                    @Param("endTime") LocalDate endTime,

+ 4 - 11
service-iot/service-iot-biz/src/main/java/com/usky/iot/service/PmWorkContentService.java

@@ -5,6 +5,7 @@ import com.usky.common.core.bean.CommonPage;
 import com.usky.iot.domain.PmWorkContent;
 import com.usky.common.mybatis.core.CrudService;
 import com.usky.iot.domain.PmWorkReport;
+import com.usky.iot.service.vo.PmWorkHourStatisticRequestVO;
 import com.usky.iot.service.vo.WorkTimeExportTwoVO;
 import com.usky.iot.service.vo.WorkTimeExportVO;
 
@@ -69,22 +70,14 @@ public interface PmWorkContentService extends CrudService<PmWorkContent> {
     CommonPage<PmWorkReport> reportPage(Integer projectAscription, Integer pageNum, Integer pageSize, Integer report, String startDate, String endDate, Integer projectId, Long userId);
 
     /** 工时统计页面
-     * @param userId          用户id
-     * @param filter          是否过滤0工时(默认1:不过滤;2:过滤)
-     * @param startDate       开始时间
-     * @param endDate         结束时间
-     * @param workerOrProject 打工仔还是项目(默认1:打工仔;2:项目)
      * @return 返回项目名(或牛马名)以及项目工时
      */
-    List<Object> workHourStatistic(List<Long> userId, Integer projectId, Integer filter, String startDate, String endDate, Integer workerOrProject);
+    List<Object> workHourStatistic(PmWorkHourStatisticRequestVO requestVO);
 
     /** 工时明细导出
-     * @param userId          用户id
-     * @param startDate       开始时间
-     * @param endDate         结束时间
-     * @return 返回项目名(或牛马名)以及项目工时
+     * @return
      */
-    List<WorkTimeExportVO> workHourStatisticExport(Long userId, Integer projectId, String startDate, String endDate);
+    List<WorkTimeExportVO> workHourStatisticExport(PmWorkHourStatisticRequestVO requestVO);
 
     /** 工时统计导出
      * @param userId          用户id

+ 45 - 19
service-iot/service-iot-biz/src/main/java/com/usky/iot/service/impl/PmWorkContentServiceImpl.java

@@ -28,6 +28,7 @@ import java.math.BigDecimal;
 import java.time.LocalDate;
 import java.time.LocalDateTime;
 import java.time.format.DateTimeFormatter;
+import java.time.temporal.TemporalAdjusters;
 import java.util.*;
 import java.util.stream.Collectors;
 
@@ -704,7 +705,7 @@ public class PmWorkContentServiceImpl extends AbstractCrudService<PmWorkContentM
         Long deptId = SecurityUtils.getLoginUser().getSysUser().getDeptId();
         LambdaQueryWrapper<PmProject> projectsQuery = Wrappers.lambdaQuery();
         projectsQuery.select(PmProject::getId, PmProject::getProjectName);
-        if (projectId != null && projectId != 0) {
+        if (projectId != null && projectId >= 0) {
             projectsQuery.eq(PmProject::getId, projectId);
             return pmProjectMapper.selectList(projectsQuery);
         }
@@ -722,14 +723,13 @@ public class PmWorkContentServiceImpl extends AbstractCrudService<PmWorkContentM
     private List<SysUser> userNameList(List<Long> userId) {
         LambdaQueryWrapper<SysUser> userNameQuery = Wrappers.lambdaQuery();
         userNameQuery.select(SysUser::getUserId, SysUser::getNickName, SysUser::getUserName, SysUser::getPhonenumber, SysUser::getAvatar,
-                        SysUser::getSex, SysUser::getDeptId, SysUser::getAddress)
-                .eq(SysUser::getDelFlag, 0)
-                .eq(SysUser::getStatus, 0);
+                        SysUser::getSex, SysUser::getDeptId, SysUser::getAddress);
         if (!userId.isEmpty()) {
-            userNameQuery.in(SysUser::getUserId, userId);
+            userNameQuery.eq(SysUser::getDelFlag, 0).eq(SysUser::getStatus, 0).in(SysUser::getUserId, userId);
             return sysUserMapper.selectList(userNameQuery);
+        } else {
+            userNameQuery.eq(SysUser::getUserId, SecurityUtils.getUserId());
         }
-        userNameQuery.apply(Objects.nonNull(DataScopeContextHolder.getDataScopeSql()), DataScopeContextHolder.getDataScopeSql());
         return sysUserMapper.selectList(userNameQuery);
     }
 
@@ -785,16 +785,40 @@ public class PmWorkContentServiceImpl extends AbstractCrudService<PmWorkContentM
      * @author: fu
      * @date: 2024/8/8 19:22
      * @param: [userId, projectId, startDate, endDate]
+     *      * @param userId          用户id
+     *      * @param filter          是否过滤0工时(默认1:不过滤;2:过滤)
+     *      * @param startDate       开始时间
+     *      * @param endDate         结束时间
+     *      * @param workerOrProject 打工仔还是项目(默认1:打工仔;2:项目)
      * @return: java.util.List<com.usky.iot.domain.WorkTimeExportVO>
      **/
     @DataScope
     @Override
-    public List<Object> workHourStatistic(List<Long> userId, Integer projectId, Integer filter, String startDate, String endDate, Integer workerOrProject) {
+    public List<Object> workHourStatistic(PmWorkHourStatisticRequestVO requestVO) {
+        List<Long> userId = new ArrayList<>();
+        if (requestVO.getUserId() != null) {
+            userId = requestVO.getUserId();
+        }
+        Integer projectId = requestVO.getProjectId();
+        Integer filter = 1;
+        if (requestVO.getFilter() != null) {
+            filter = requestVO.getFilter();
+        }
+        String startDate = requestVO.getStartDate();
+        String endDate = requestVO.getEndDate();
+        Integer workerOrProject = 1;
+        if (requestVO.getWorkerOrProject() != null){
+            workerOrProject = requestVO.getWorkerOrProject();
+        }
+        if (StringUtils.isBlank(startDate) || StringUtils.isBlank(endDate)) {
+            startDate = LocalDate.now().with(TemporalAdjusters.firstDayOfYear()).toString();
+            endDate = LocalDate.now().with(TemporalAdjusters.lastDayOfYear()).toString();
+        }
+
         List<ProjectWorkTimeVO> projectWorkTime = new ArrayList<>();
         List<UserWorkTimeVO> userWorkTimeVO = new ArrayList<>();
-        List<ProjectWorkTimeVO> projectWorkTime1 = new ArrayList<>();
-        List<UserWorkTimeVO> userWorkTimeVO1 = new ArrayList<>();
         List<Object> returnList = new ArrayList<>();
+
         if (StringUtils.isBlank(startDate) || StringUtils.isBlank(endDate)) {
             throw new BusinessException("请设置查询时间范围!");
         }
@@ -1015,24 +1039,26 @@ public class PmWorkContentServiceImpl extends AbstractCrudService<PmWorkContentM
 
     /**
      * 工时-明细-导出
-     * @param userId
-     * @param projectId
-     * @param startDate
-     * @param endDate
      * @return
      */
     @DataScope(deptAlias = "u")
     @Override
-    public List<WorkTimeExportVO> workHourStatisticExport(Long userId, Integer projectId, String startDate, String
-            endDate) {
+    public List<WorkTimeExportVO> workHourStatisticExport(PmWorkHourStatisticRequestVO requestVO) {
+        List<Long> userIds = new ArrayList<>();
+        if (!requestVO.getUserId().isEmpty()){
+            userIds = requestVO.getUserId();
+        }
+
+        Integer projectId = requestVO.getProjectId();
+
         Integer tenantId = SecurityUtils.getTenantId();
         LocalDate start = null;
         LocalDate end = null;
-        if (StringUtils.isNotBlank(startDate) && StringUtils.isNotBlank(endDate)) {
-            start = LocalDate.parse(startDate);
-            end = LocalDate.parse(endDate);
+        if (StringUtils.isNotBlank(requestVO.getStartDate()) && StringUtils.isNotBlank(requestVO.getEndDate())) {
+            start = LocalDate.parse(requestVO.getStartDate());
+            end = LocalDate.parse(requestVO.getEndDate());
         }
-        return pmWorkContentMapper.workHourStatisticExport(userId, projectId, start, end, tenantId);
+        return pmWorkContentMapper.workHourStatisticExport(userIds, projectId, start, end, tenantId);
     }
 
     /**

+ 43 - 0
service-iot/service-iot-biz/src/main/java/com/usky/iot/service/vo/PmWorkHourStatisticRequestVO.java

@@ -0,0 +1,43 @@
+package com.usky.iot.service.vo;
+
+import lombok.Data;
+
+import java.util.List;
+
+/**
+ *
+ * @author fu
+ * @date 2024/9/20
+ */
+@Data
+public class PmWorkHourStatisticRequestVO {
+    /**
+     * 用户id集合
+     */
+    private List<Long> userId;
+
+    /**
+     * 项目id
+     */
+    private Integer projectId;
+
+    /**
+     * 过滤标识 是否过滤0工时(默认1:不过滤;2:过滤)
+     **/
+    private Integer filter;
+
+    /**
+     * 开始时间
+     */
+    private String startDate;
+
+    /**
+     * 结束时间
+     */
+    private String endDate;
+
+    /**
+     * 人员 or 项目 打工仔还是项目(默认1:打工仔;2:项目)
+     */
+    private Integer workerOrProject;
+}

+ 1 - 1
service-iot/service-iot-biz/src/main/resources/mapper/iot/PmWorkContentMapper.xml

@@ -40,7 +40,7 @@
             AND pr.id = #{projectId}
         </if>
         <if test="userId != null and userId != '' and userId != 0">
-            AND pr.submitter_id = #{userId}
+            AND pr.submitter_id IN #{userIds}
         </if>
         <if test="startTime != null and startTime != '' and endTime != null and endTime != ''">
             AND pr.report_date BETWEEN #{startTime} AND #{endTime}