From f0d0f473efdaa169b1a7d694f08a57653279ff51 Mon Sep 17 00:00:00 2001 From: "DESKTOP-G8BCEP0\\HP" <2037158277@qq.com> Date: Wed, 1 Sep 2021 18:02:27 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E4=BA=86=E6=8C=89=E7=85=A7?= =?UTF-8?q?=E6=97=B6=E9=97=B4=E6=AE=B5=E6=9F=A5=E8=AF=A2=E5=B7=A5=E6=97=B6?= =?UTF-8?q?=E8=AE=B0=E5=BD=95=E7=9A=84=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/WorkHourRecordController.java | 11 ++++-- .../java/com/xkrs/dao/WorkHourRecordDao.java | 3 +- .../xkrs/service/WorkHourRecordService.java | 4 +- .../impl/WorkHourRecordServiceImpl.java | 10 ++++- src/main/java/com/xkrs/utils/Query.java | 38 +++++++++++++++++++ src/main/resources/application.properties | 2 +- 6 files changed, 59 insertions(+), 9 deletions(-) diff --git a/src/main/java/com/xkrs/controller/WorkHourRecordController.java b/src/main/java/com/xkrs/controller/WorkHourRecordController.java index 30722e4..72eae2f 100644 --- a/src/main/java/com/xkrs/controller/WorkHourRecordController.java +++ b/src/main/java/com/xkrs/controller/WorkHourRecordController.java @@ -99,19 +99,22 @@ public class WorkHourRecordController { /** * 查询我参与的当前项目的提交的工时记录 - * @param projectNumber + * @param map * @param token * @return */ - @GetMapping("/findRecord") + @PostMapping("/findRecord") @PreAuthorize("hasAnyAuthority('auth_administor','auth_general_user')") - public String findRecord(@RequestParam("projectNumber") String projectNumber,@RequestHeader(value="Authorization") String token){ + public String findRecord(@RequestBody Map map,@RequestHeader(value="Authorization") String token){ // 获取区域信息 Locale locale = LocaleContextHolder.getLocale(); + String projectNumber = (String) map.get("projectNumber"); + String startTime = (String) map.get("startTime"); + String endTime = (String) map.get("endTime"); // 验证token String tokenUserName = TokenUtil.getTokenUserName(token); SysUserEntity sysUserEntity = sysUserDao.selectByUserName(tokenUserName); - List workHourRecords = workHourRecordService.findRecord(projectNumber, sysUserEntity.getId()); + List workHourRecords = workHourRecordService.findRecord(projectNumber, sysUserEntity.getId(),startTime,endTime); if(workHourRecords == null || workHourRecords.size() == 0){ return outputEncapsulationObject(PromptMessageEnum.DATA_NONE,"暂时还没有该项目的工时记录",locale); } diff --git a/src/main/java/com/xkrs/dao/WorkHourRecordDao.java b/src/main/java/com/xkrs/dao/WorkHourRecordDao.java index c7e591e..b902a15 100644 --- a/src/main/java/com/xkrs/dao/WorkHourRecordDao.java +++ b/src/main/java/com/xkrs/dao/WorkHourRecordDao.java @@ -5,6 +5,7 @@ import com.xkrs.model.vo.MemberWorkRecordVo; import com.xkrs.model.vo.OutExcelVo; import com.xkrs.model.vo.OutMemberVo; import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.jpa.repository.JpaSpecificationExecutor; import org.springframework.data.jpa.repository.Modifying; import org.springframework.data.jpa.repository.Query; import org.springframework.data.repository.query.Param; @@ -17,7 +18,7 @@ import java.util.Map; * @author XinYi Song */ @Component -public interface WorkHourRecordDao extends JpaRepository { +public interface WorkHourRecordDao extends JpaRepository, JpaSpecificationExecutor { /** * 查询我参与的 diff --git a/src/main/java/com/xkrs/service/WorkHourRecordService.java b/src/main/java/com/xkrs/service/WorkHourRecordService.java index 628e412..81f0daa 100644 --- a/src/main/java/com/xkrs/service/WorkHourRecordService.java +++ b/src/main/java/com/xkrs/service/WorkHourRecordService.java @@ -47,9 +47,11 @@ public interface WorkHourRecordService { * 查询我参与的当前项目的提交的工时记录 * @param projectNumber * @param userId + * @param startTime + * @param endTime * @return */ - List findRecord(String projectNumber,Integer userId); + List findRecord(String projectNumber,Integer userId,String startTime, String endTime); /** * 修改工时记录 diff --git a/src/main/java/com/xkrs/service/impl/WorkHourRecordServiceImpl.java b/src/main/java/com/xkrs/service/impl/WorkHourRecordServiceImpl.java index ad019c4..b446671 100644 --- a/src/main/java/com/xkrs/service/impl/WorkHourRecordServiceImpl.java +++ b/src/main/java/com/xkrs/service/impl/WorkHourRecordServiceImpl.java @@ -12,6 +12,7 @@ import com.xkrs.model.vo.OutExcelVo; import com.xkrs.model.vo.OutMemberVo; import com.xkrs.service.WorkHourRecordService; import com.xkrs.utils.DateTimeUtil; +import com.xkrs.utils.Query; import org.apache.poi.hssf.usermodel.*; import org.apache.poi.ss.usermodel.*; import org.springframework.context.i18n.LocaleContextHolder; @@ -40,6 +41,9 @@ public class WorkHourRecordServiceImpl implements WorkHourRecordService { @Resource private SysUserDao sysUserDao; + @Resource + private Query query; + /** * 提交工时记录 * @param workRecordQo @@ -101,11 +105,13 @@ public class WorkHourRecordServiceImpl implements WorkHourRecordService { * 查询我参与的当前项目的提交的工时记录 * @param projectNumber * @param userId + * @param startTime + * @param endTime * @return */ @Override - public List findRecord(String projectNumber, Integer userId) { - return workHourRecordDao.findRecord(projectNumber,userId); + public List findRecord(String projectNumber, Integer userId, String startTime, String endTime) { + return query.selectWorkRecord(projectNumber,userId,startTime,endTime); } /** diff --git a/src/main/java/com/xkrs/utils/Query.java b/src/main/java/com/xkrs/utils/Query.java index 8d648ae..1068767 100644 --- a/src/main/java/com/xkrs/utils/Query.java +++ b/src/main/java/com/xkrs/utils/Query.java @@ -1,7 +1,9 @@ package com.xkrs.utils; import com.xkrs.dao.ProjectOverviewDao; +import com.xkrs.dao.WorkHourRecordDao; import com.xkrs.model.entity.ProjectOverview; +import com.xkrs.model.entity.WorkHourRecord; import org.springframework.data.jpa.domain.Specification; import org.springframework.stereotype.Component; @@ -23,6 +25,9 @@ public class Query { @Resource private ProjectOverviewDao projectOverviewDao; + @Resource + private WorkHourRecordDao workHourRecordDao; + /** * 动态多条件查询项目信息 * @param @@ -47,4 +52,37 @@ public class Query { } + /** + * 查询工时记录 + * @param projectNumber + * @param userId + * @param startTime + * @param endTime + * @return + */ + public List selectWorkRecord(String projectNumber, Integer userId, String startTime, String endTime) { + Specification specification = new Specification() { + @Override + public Predicate toPredicate(Root root, CriteriaQuery criteriaQuery, CriteriaBuilder criteriaBuilder) { + List list = new ArrayList<>(); + if (projectNumber != null && !"".equals(projectNumber)) { + list.add(criteriaBuilder.equal(root.get("projectNumber").as(String.class), projectNumber)); + } + if (userId != null && !"".equals(userId)) { + list.add(criteriaBuilder.equal(root.get("userId").as(Integer.class), userId)); + } + if(startTime != null && !"".equals(startTime)){ + list.add(criteriaBuilder.greaterThanOrEqualTo(root.get("submitTime").as(String.class), startTime)); + } + if(endTime != null && !"".equals(endTime)){ + list.add(criteriaBuilder.lessThanOrEqualTo(root.get("submitTime").as(String.class), endTime)); + } + Predicate[] predicates = new Predicate[list.size()]; + return criteriaBuilder.and(list.toArray(predicates)); + } + }; + return workHourRecordDao.findAll(specification); + } + + } \ No newline at end of file diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index e19252a..d23403d 100644 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -29,7 +29,7 @@ spring.datasource.hikari.validation-timeout = 3000 ## Spring Data JPA 配置 spring.jpa.database = POSTGRESQL spring.jpa.database-platform = org.hibernate.dialect.PostgreSQLDialect -spring.jpa.show-sql = true +spring.jpa.show-sql = false # 指定 ddl mode (none, validate, create, create-drop, update) spring.jpa.hibernate.ddl-auto = update # 命名策略