eladmin-master/eladmin-common/src/main/java/me/zhengjie/annotation/Query.java
@@ -1,94 +1,96 @@ /* * Copyright 2019-2020 Zheng Jie * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package me.zhengjie.annotation; import java.lang.annotation.ElementType; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; import java.lang.annotation.Target; /** * @author Zheng Jie * @date 2019-6-4 13:52:30 */ @Target(ElementType.FIELD) @Retention(RetentionPolicy.RUNTIME) public @interface Query { // Dong ZhaoYang 2017/8/7 基本对象的属性名 String propName() default ""; // Dong ZhaoYang 2017/8/7 查询方式 Type type() default Type.EQUAL; /** * 连接查询的属性名,如User类中的dept */ String joinName() default ""; /** * 默认左连接 */ Join join() default Join.LEFT; /** * 多字段模糊搜索,仅支持String类型字段,多个用逗号隔开, 如@Query(blurry = "email,username") */ String blurry() default ""; //wcd加 String isOr() default ""; // enum Type { // jie 2019/6/4 相等 EQUAL // Dong ZhaoYang 2017/8/7 大于等于 , GREATER_THAN // Dong ZhaoYang 2017/8/7 小于等于 , LESS_THAN // Dong ZhaoYang 2017/8/7 中模糊查询 , INNER_LIKE // Dong ZhaoYang 2017/8/7 左模糊查询 , LEFT_LIKE // Dong ZhaoYang 2017/8/7 右模糊查询 , RIGHT_LIKE // Dong ZhaoYang 2017/8/7 小于 , LESS_THAN_NQ // jie 2019/6/4 包含 , IN // 不包含 , NOT_IN // 不等于 ,NOT_EQUAL // between ,BETWEEN // 不为空 ,NOT_NULL // 为空 ,IS_NULL } /** * @author Zheng Jie * 适用于简单连接查询,复杂的请自定义该注解,或者使用sql查询 */ enum Join { /** jie 2019-6-4 13:18:30 */ LEFT, RIGHT, INNER } } /* * Copyright 2019-2020 Zheng Jie * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package me.zhengjie.annotation; import java.lang.annotation.ElementType; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; import java.lang.annotation.Target; /** * @author Zheng Jie * @date 2019-6-4 13:52:30 */ @Target(ElementType.FIELD) @Retention(RetentionPolicy.RUNTIME) public @interface Query { // Dong ZhaoYang 2017/8/7 基本对象的属性名 String propName() default ""; // Dong ZhaoYang 2017/8/7 查询方式 Type type() default Type.EQUAL; /** * 连接查询的属性名,如User类中的dept */ String joinName() default ""; /** * 默认左连接 */ Join join() default Join.LEFT; /** * 多字段模糊搜索,仅支持String类型字段,多个用逗号隔开, 如@Query(blurry = "email,username") */ String blurry() default ""; //wcd加 String isOr() default ""; // String orGroup() default ""; enum Type { // jie 2019/6/4 相等 EQUAL // Dong ZhaoYang 2017/8/7 大于等于 , GREATER_THAN // Dong ZhaoYang 2017/8/7 小于等于 , LESS_THAN // Dong ZhaoYang 2017/8/7 中模糊查询 , INNER_LIKE // Dong ZhaoYang 2017/8/7 左模糊查询 , LEFT_LIKE // Dong ZhaoYang 2017/8/7 右模糊查询 , RIGHT_LIKE // Dong ZhaoYang 2017/8/7 小于 , LESS_THAN_NQ // jie 2019/6/4 包含 , IN // 不包含 , NOT_IN // 不等于 ,NOT_EQUAL // between ,BETWEEN // 不为空 ,NOT_NULL // 为空 ,IS_NULL } /** * @author Zheng Jie * 适用于简单连接查询,复杂的请自定义该注解,或者使用sql查询 */ enum Join { /** jie 2019-6-4 13:18:30 */ LEFT, RIGHT, INNER } } eladmin-master/eladmin-common/src/main/java/me/zhengjie/utils/QueryHelp.java
@@ -1,232 +1,299 @@ /* * Copyright 2019-2020 Zheng Jie * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package me.zhengjie.utils; import cn.hutool.core.collection.CollUtil; import cn.hutool.core.collection.CollectionUtil; import cn.hutool.core.util.ObjectUtil; import lombok.extern.slf4j.Slf4j; import me.zhengjie.annotation.DataPermission; import me.zhengjie.annotation.Query; import javax.persistence.criteria.*; import java.lang.reflect.Field; import java.util.*; /** * @author Zheng Jie * @date 2019-6-4 14:59:48 */ @Slf4j @SuppressWarnings({"unchecked","all"}) public class QueryHelp { public static <R, Q> Predicate getPredicate(Root<R> root, Q query, CriteriaBuilder cb) { List<Predicate> list = new ArrayList<>(); if(query == null){ return cb.and(list.toArray(new Predicate[0])); } // 数据权限验证 DataPermission permission = query.getClass().getAnnotation(DataPermission.class); if(permission != null){ // 获取数据权限 List<Long> dataScopes = SecurityUtils.getCurrentUserDataScope(); if(CollectionUtil.isNotEmpty(dataScopes)){ if(StringUtils.isNotBlank(permission.joinName()) && StringUtils.isNotBlank(permission.fieldName())) { Join join = root.join(permission.joinName(), JoinType.LEFT); list.add(getExpression(permission.fieldName(),join, root).in(dataScopes)); } else if (StringUtils.isBlank(permission.joinName()) && StringUtils.isNotBlank(permission.fieldName())) { list.add(getExpression(permission.fieldName(),null, root).in(dataScopes)); } } } try { List<Field> fields = getAllFields(query.getClass(), new ArrayList<>()); for (Field field : fields) { boolean accessible = field.isAccessible(); // 设置对象的访问权限,保证对private的属性的访 field.setAccessible(true); Query q = field.getAnnotation(Query.class); if (q != null) { String propName = q.propName(); String joinName = q.joinName(); String blurry = q.blurry(); // wcd加 String isOr = q.isOr(); // String attributeName = isBlank(propName) ? field.getName() : propName; Class<?> fieldType = field.getType(); Object val = field.get(query); if (ObjectUtil.isNull(val) || "".equals(val)) { continue; } Join join = null; // 模糊多字段 if (ObjectUtil.isNotEmpty(blurry)) { String[] blurrys = blurry.split(","); List<Predicate> orPredicate = new ArrayList<>(); for (String s : blurrys) { String[] joinNames = s.split(">"); if (joinNames.length == 2) { orPredicate.add(cb.like(root.join(joinNames[0], JoinType.LEFT).get(joinNames[1]) .as(String.class), "%" + val.toString() + "%")); } else { orPredicate.add(cb.like(root.get(joinNames[0]) .as(String.class), "%" + val.toString() + "%")); } } Predicate[] p = new Predicate[orPredicate.size()]; list.add(cb.or(orPredicate.toArray(p))); continue; } if (ObjectUtil.isNotEmpty(joinName)) { String[] joinNames = joinName.split(">"); for (String name : joinNames) { switch (q.join()) { case LEFT: if(ObjectUtil.isNotNull(join) && ObjectUtil.isNotNull(val)){ join = join.join(name, JoinType.LEFT); } else { join = root.join(name, JoinType.LEFT); } break; case RIGHT: if(ObjectUtil.isNotNull(join) && ObjectUtil.isNotNull(val)){ join = join.join(name, JoinType.RIGHT); } else { join = root.join(name, JoinType.RIGHT); } break; case INNER: if(ObjectUtil.isNotNull(join) && ObjectUtil.isNotNull(val)){ join = join.join(name, JoinType.INNER); } else { join = root.join(name, JoinType.INNER); } break; default: break; } } } // wcd加 if (ObjectUtil.isNotEmpty(isOr)) { String[] isOrs = isOr.split(","); List<Predicate> orP = new ArrayList<>(); for (String s : isOrs) { orP.add(cb.equal(root.get(s) .as(String.class), val)); } Predicate[] orpr = new Predicate[orP.size()]; list.add(cb.or(orP.toArray(orpr))); continue; } // switch (q.type()) { case EQUAL: list.add(cb.equal(getExpression(attributeName,join,root) .as((Class<? extends Comparable>) fieldType),val)); break; case GREATER_THAN: list.add(cb.greaterThanOrEqualTo(getExpression(attributeName,join,root) .as((Class<? extends Comparable>) fieldType), (Comparable) val)); break; case LESS_THAN: list.add(cb.lessThanOrEqualTo(getExpression(attributeName,join,root) .as((Class<? extends Comparable>) fieldType), (Comparable) val)); break; case LESS_THAN_NQ: list.add(cb.lessThan(getExpression(attributeName,join,root) .as((Class<? extends Comparable>) fieldType), (Comparable) val)); break; case INNER_LIKE: list.add(cb.like(getExpression(attributeName,join,root) .as(String.class), "%" + val.toString() + "%")); break; case LEFT_LIKE: list.add(cb.like(getExpression(attributeName,join,root) .as(String.class), "%" + val.toString())); break; case RIGHT_LIKE: list.add(cb.like(getExpression(attributeName,join,root) .as(String.class), val.toString() + "%")); break; case IN: if (CollUtil.isNotEmpty((Collection<Object>)val)) { list.add(getExpression(attributeName,join,root).in((Collection<Object>) val)); } break; case NOT_IN: if (CollUtil.isNotEmpty((Collection<Object>)val)) { list.add(getExpression(attributeName,join,root).in((Collection<Object>) val).not()); } break; case NOT_EQUAL: list.add(cb.notEqual(getExpression(attributeName,join,root), val)); break; case NOT_NULL: list.add(cb.isNotNull(getExpression(attributeName,join,root))); break; case IS_NULL: list.add(cb.isNull(getExpression(attributeName,join,root))); break; case BETWEEN: List<Object> between = new ArrayList<>((List<Object>)val); list.add(cb.between(getExpression(attributeName, join, root).as((Class<? extends Comparable>) between.get(0).getClass()), (Comparable) between.get(0), (Comparable) between.get(1))); break; default: break; } } field.setAccessible(accessible); } } catch (Exception e) { log.error(e.getMessage(), e); } int size = list.size(); return cb.and(list.toArray(new Predicate[size])); } @SuppressWarnings("unchecked") private static <T, R> Expression<T> getExpression(String attributeName, Join join, Root<R> root) { if (ObjectUtil.isNotEmpty(join)) { return join.get(attributeName); } else { return root.get(attributeName); } } private static boolean isBlank(final CharSequence cs) { int strLen; if (cs == null || (strLen = cs.length()) == 0) { return true; } for (int i = 0; i < strLen; i++) { if (!Character.isWhitespace(cs.charAt(i))) { return false; } } return true; } public static List<Field> getAllFields(Class clazz, List<Field> fields) { if (clazz != null) { fields.addAll(Arrays.asList(clazz.getDeclaredFields())); getAllFields(clazz.getSuperclass(), fields); } return fields; } } /* * Copyright 2019-2020 Zheng Jie * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package me.zhengjie.utils; import cn.hutool.core.collection.CollUtil; import cn.hutool.core.collection.CollectionUtil; import cn.hutool.core.util.ObjectUtil; import lombok.extern.slf4j.Slf4j; import me.zhengjie.annotation.DataPermission; import me.zhengjie.annotation.Query; import javax.persistence.criteria.*; import java.lang.reflect.Field; import java.util.*; /** * @author Zheng Jie * @date 2019-6-4 14:59:48 */ @Slf4j @SuppressWarnings({"unchecked","all"}) public class QueryHelp { public static <R, Q> Predicate getPredicate(Root<R> root, Q query, CriteriaBuilder cb) { List<Predicate> list = new ArrayList<>(); if(query == null){ return cb.and(list.toArray(new Predicate[0])); } // 数据权限验证 DataPermission permission = query.getClass().getAnnotation(DataPermission.class); if(permission != null){ // 获取数据权限 List<Long> dataScopes = SecurityUtils.getCurrentUserDataScope(); if(CollectionUtil.isNotEmpty(dataScopes)){ if(StringUtils.isNotBlank(permission.joinName()) && StringUtils.isNotBlank(permission.fieldName())) { Join join = root.join(permission.joinName(), JoinType.LEFT); list.add(getExpression(permission.fieldName(),join, root).in(dataScopes)); } else if (StringUtils.isBlank(permission.joinName()) && StringUtils.isNotBlank(permission.fieldName())) { list.add(getExpression(permission.fieldName(),null, root).in(dataScopes)); } } } try { List<Field> fields = getAllFields(query.getClass(), new ArrayList<>()); Map<String, List<Predicate>> orGroupMap = new HashMap<String, List<Predicate>>(); for (Field field : fields) { boolean accessible = field.isAccessible(); // 设置对象的访问权限,保证对private的属性的访 field.setAccessible(true); Query q = field.getAnnotation(Query.class); if (q != null) { String propName = q.propName(); String joinName = q.joinName(); String blurry = q.blurry(); // wcd加 String isOr = q.isOr(); // String attributeName = isBlank(propName) ? field.getName() : propName; Class<?> fieldType = field.getType(); Object val = field.get(query); if (ObjectUtil.isNull(val) || "".equals(val)) { continue; } Join join = null; // 模糊多字段 if (ObjectUtil.isNotEmpty(blurry)) { String[] blurrys = blurry.split(","); List<Predicate> orPredicate = new ArrayList<>(); for (String s : blurrys) { String[] joinNames = s.split(">"); if (joinNames.length == 2) { orPredicate.add(cb.like(root.join(joinNames[0], JoinType.LEFT).get(joinNames[1]) .as(String.class), "%" + val.toString() + "%")); } else { orPredicate.add(cb.like(root.get(joinNames[0]) .as(String.class), "%" + val.toString() + "%")); } } Predicate[] p = new Predicate[orPredicate.size()]; list.add(cb.or(orPredicate.toArray(p))); continue; } if (ObjectUtil.isNotEmpty(joinName)) { String[] joinNames = joinName.split(">"); for (String name : joinNames) { switch (q.join()) { case LEFT: if(ObjectUtil.isNotNull(join) && ObjectUtil.isNotNull(val)){ join = join.join(name, JoinType.LEFT); } else { join = root.join(name, JoinType.LEFT); } break; case RIGHT: if(ObjectUtil.isNotNull(join) && ObjectUtil.isNotNull(val)){ join = join.join(name, JoinType.RIGHT); } else { join = root.join(name, JoinType.RIGHT); } break; case INNER: if(ObjectUtil.isNotNull(join) && ObjectUtil.isNotNull(val)){ join = join.join(name, JoinType.INNER); } else { join = root.join(name, JoinType.INNER); } break; default: break; } } } // wcd加 if (ObjectUtil.isNotEmpty(isOr)) { String[] isOrs = isOr.split(","); List<Predicate> orP = new ArrayList<>(); for (String s : isOrs) { orP.add(cb.equal(root.get(s) .as(String.class), val)); } Predicate[] orpr = new Predicate[orP.size()]; list.add(cb.or(orP.toArray(orpr))); continue; } // String orGroup = q.orGroup(); if (ObjectUtil.isNotEmpty(orGroup)) { if (orGroupMap.get(orGroup) == null) { orGroupMap.put(orGroup, new ArrayList<Predicate>()); } List<Predicate> predicates = orGroupMap.get(orGroup); switch (q.type()) { case EQUAL: predicates.add(cb.equal(getExpression(attributeName,join,root) .as((Class<? extends Comparable>) fieldType),val)); break; case GREATER_THAN: predicates.add(cb.greaterThanOrEqualTo(getExpression(attributeName,join,root) .as((Class<? extends Comparable>) fieldType), (Comparable) val)); break; case LESS_THAN: predicates.add(cb.lessThanOrEqualTo(getExpression(attributeName,join,root) .as((Class<? extends Comparable>) fieldType), (Comparable) val)); break; case LESS_THAN_NQ: predicates.add(cb.lessThan(getExpression(attributeName,join,root) .as((Class<? extends Comparable>) fieldType), (Comparable) val)); break; case INNER_LIKE: predicates.add(cb.like(getExpression(attributeName,join,root) .as(String.class), "%" + val.toString() + "%")); break; case LEFT_LIKE: predicates.add(cb.like(getExpression(attributeName,join,root) .as(String.class), "%" + val.toString())); break; case RIGHT_LIKE: predicates.add(cb.like(getExpression(attributeName,join,root) .as(String.class), val.toString() + "%")); break; case IN: if (CollUtil.isNotEmpty((Collection<Object>)val)) { predicates.add(getExpression(attributeName,join,root).in((Collection<Object>) val)); } break; case NOT_IN: if (CollUtil.isNotEmpty((Collection<Object>)val)) { predicates.add(getExpression(attributeName,join,root).in((Collection<Object>) val).not()); } break; case NOT_EQUAL: predicates.add(cb.notEqual(getExpression(attributeName,join,root), val)); break; case NOT_NULL: predicates.add(cb.isNotNull(getExpression(attributeName,join,root))); break; case IS_NULL: predicates.add(cb.isNull(getExpression(attributeName,join,root))); break; case BETWEEN: List<Object> between = new ArrayList<>((List<Object>)val); predicates.add(cb.between(getExpression(attributeName, join, root).as((Class<? extends Comparable>) between.get(0).getClass()), (Comparable) between.get(0), (Comparable) between.get(1))); break; default: break; } } else { switch (q.type()) { case EQUAL: list.add(cb.equal(getExpression(attributeName,join,root) .as((Class<? extends Comparable>) fieldType),val)); break; case GREATER_THAN: list.add(cb.greaterThanOrEqualTo(getExpression(attributeName,join,root) .as((Class<? extends Comparable>) fieldType), (Comparable) val)); break; case LESS_THAN: list.add(cb.lessThanOrEqualTo(getExpression(attributeName,join,root) .as((Class<? extends Comparable>) fieldType), (Comparable) val)); break; case LESS_THAN_NQ: list.add(cb.lessThan(getExpression(attributeName,join,root) .as((Class<? extends Comparable>) fieldType), (Comparable) val)); break; case INNER_LIKE: list.add(cb.like(getExpression(attributeName,join,root) .as(String.class), "%" + val.toString() + "%")); break; case LEFT_LIKE: list.add(cb.like(getExpression(attributeName,join,root) .as(String.class), "%" + val.toString())); break; case RIGHT_LIKE: list.add(cb.like(getExpression(attributeName,join,root) .as(String.class), val.toString() + "%")); break; case IN: if (CollUtil.isNotEmpty((Collection<Object>)val)) { list.add(getExpression(attributeName,join,root).in((Collection<Object>) val)); } break; case NOT_IN: if (CollUtil.isNotEmpty((Collection<Object>)val)) { list.add(getExpression(attributeName,join,root).in((Collection<Object>) val).not()); } break; case NOT_EQUAL: list.add(cb.notEqual(getExpression(attributeName,join,root), val)); break; case NOT_NULL: list.add(cb.isNotNull(getExpression(attributeName,join,root))); break; case IS_NULL: list.add(cb.isNull(getExpression(attributeName,join,root))); break; case BETWEEN: List<Object> between = new ArrayList<>((List<Object>)val); list.add(cb.between(getExpression(attributeName, join, root).as((Class<? extends Comparable>) between.get(0).getClass()), (Comparable) between.get(0), (Comparable) between.get(1))); break; default: break; } } } field.setAccessible(accessible); } orGroupMap.values().forEach(predicates -> list.add(cb.or(predicates.toArray(new Predicate[0])))); } catch (Exception e) { log.error(e.getMessage(), e); } int size = list.size(); return cb.and(list.toArray(new Predicate[size])); } @SuppressWarnings("unchecked") private static <T, R> Expression<T> getExpression(String attributeName, Join join, Root<R> root) { if (ObjectUtil.isNotEmpty(join)) { return join.get(attributeName); } else { return root.get(attributeName); } } private static boolean isBlank(final CharSequence cs) { int strLen; if (cs == null || (strLen = cs.length()) == 0) { return true; } for (int i = 0; i < strLen; i++) { if (!Character.isWhitespace(cs.charAt(i))) { return false; } } return true; } public static List<Field> getAllFields(Class clazz, List<Field> fields) { if (clazz != null) { fields.addAll(Arrays.asList(clazz.getDeclaredFields())); getAllFields(clazz.getSuperclass(), fields); } return fields; } } eladmin-master/eladmin-system/src/main/java/me/zhengjie/modules/attendance/rest/AttendanceController.java
@@ -1,132 +1,140 @@ /* * Copyright 2019-2020 Zheng Jie * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package me.zhengjie.modules.attendance.rest; import me.zhengjie.annotation.Log; import me.zhengjie.modules.attendance.domain.Attendance; import me.zhengjie.modules.attendance.repository.AttendanceRepository; import me.zhengjie.modules.attendance.service.AttendanceService; import me.zhengjie.modules.attendance.service.dto.AttendanceDto; import me.zhengjie.modules.attendance.service.dto.AttendanceQueryCriteria; import org.apache.commons.lang3.ObjectUtils; import org.springframework.data.domain.Pageable; import lombok.RequiredArgsConstructor; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.*; import io.swagger.annotations.*; import java.io.IOException; import java.util.List; import javax.servlet.http.HttpServletResponse; /** * @website https://eladmin.vip * @author wcd * @date 2022-12-14 **/ @RestController @RequiredArgsConstructor @Api(tags = "考勤记录管理") @RequestMapping("/api/attendance") public class AttendanceController { private final AttendanceService attendanceService; private final AttendanceRepository attendanceRepository; @Log("导出数据") @ApiOperation("导出数据") @GetMapping(value = "/download") @PreAuthorize("@el.check('attendance:download')") public void exportAttendance(HttpServletResponse response, AttendanceQueryCriteria criteria) throws IOException { attendanceService.download(attendanceService.queryAll(criteria), response); } @GetMapping @Log("查询考勤记录") @ApiOperation("查询考勤记录") @PreAuthorize("@el.check('attendance:list')") public ResponseEntity<Object> queryAttendance(AttendanceQueryCriteria criteria, Pageable pageable){ return new ResponseEntity<>(attendanceService.queryAll(criteria,pageable),HttpStatus.OK); } @GetMapping(value = "/all") @Log("查询考勤记录") @ApiOperation("查询考勤记录") @PreAuthorize("@el.check('attendance:list')") public ResponseEntity<Object> queryAttendance(AttendanceQueryCriteria criteria){ return new ResponseEntity<>(attendanceService.queryAll(criteria),HttpStatus.OK); } @PostMapping @Log("新增考勤记录") @ApiOperation("新增考勤记录") @PreAuthorize("@el.check('attendance:add')") public ResponseEntity<Object> createAttendance(@Validated @RequestBody Attendance resources){ return new ResponseEntity<>(attendanceService.create(resources),HttpStatus.CREATED); } @PutMapping @Log("修改考勤记录") @ApiOperation("修改考勤记录") @PreAuthorize("@el.check('attendance:edit')") public ResponseEntity<Object> updateAttendance(@Validated @RequestBody Attendance resources){ attendanceService.update(resources); return new ResponseEntity<>(HttpStatus.NO_CONTENT); } @DeleteMapping @Log("删除考勤记录") @ApiOperation("删除考勤记录") @PreAuthorize("@el.check('attendance:del')") public ResponseEntity<Object> deleteAttendance(@RequestBody Long[] ids) { attendanceService.deleteAll(ids); return new ResponseEntity<>(HttpStatus.OK); } @GetMapping(value = "/attendanceHours") @Log("查询某月出勤小时数") @ApiOperation("查询某月出勤小时数") @PreAuthorize("@el.check('attendance:list')") public ResponseEntity<Object> queryAttendanceHours(AttendanceQueryCriteria criteria) { return new ResponseEntity<>(attendanceService.queryAttendanceHours(criteria),HttpStatus.OK); } @GetMapping(value = "/queryAttendanceHours") @Log("查询某天出勤小时数") @ApiOperation("查询某天出勤小时数") @PreAuthorize("@el.check('attendance:list')") public ResponseEntity<Object> queryAttendanceHours(Long userId, String date) { return new ResponseEntity<>(attendanceService.queryAttendanceHours(userId, date),HttpStatus.OK); } @PostMapping(value = "/getUserMakeUpCard") @Log("补卡判断登录人") @ApiOperation("补卡判断登录人") public ResponseEntity<Object> getUserMakeUpCard(@Validated @RequestBody String userId){ attendanceService.getUserMakeUpCard(userId); return new ResponseEntity<>(HttpStatus.CREATED); } @PostMapping(value = "/addAttendanceInfo") @Log("考勤信息补充") @ApiOperation("考勤信息补充") public ResponseEntity<Object> addAttendanceInfo(@Validated @RequestBody Attendance attendance) throws Exception { attendanceService.addAttendanceInfo(attendance); return new ResponseEntity<>(HttpStatus.CREATED); } /* * Copyright 2019-2020 Zheng Jie * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package me.zhengjie.modules.attendance.rest; import me.zhengjie.annotation.Log; import me.zhengjie.modules.attendance.domain.Attendance; import me.zhengjie.modules.attendance.repository.AttendanceRepository; import me.zhengjie.modules.attendance.service.AttendanceService; import me.zhengjie.modules.attendance.service.dto.AttendanceDto; import me.zhengjie.modules.attendance.service.dto.AttendanceQueryCriteria; import org.apache.commons.lang3.ObjectUtils; import org.springframework.data.domain.Pageable; import lombok.RequiredArgsConstructor; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.*; import io.swagger.annotations.*; import java.io.IOException; import java.util.List; import javax.servlet.http.HttpServletResponse; /** * @website https://eladmin.vip * @author wcd * @date 2022-12-14 **/ @RestController @RequiredArgsConstructor @Api(tags = "考勤记录管理") @RequestMapping("/api/attendance") public class AttendanceController { private final AttendanceService attendanceService; private final AttendanceRepository attendanceRepository; @Log("导出数据") @ApiOperation("导出数据") @GetMapping(value = "/download") @PreAuthorize("@el.check('attendance:download')") public void exportAttendance(HttpServletResponse response, AttendanceQueryCriteria criteria) throws IOException { attendanceService.download(attendanceService.queryAll(criteria), response); } @GetMapping @Log("查询考勤记录") @ApiOperation("查询考勤记录") @PreAuthorize("@el.check('attendance:list')") public ResponseEntity<Object> queryAttendance(AttendanceQueryCriteria criteria, Pageable pageable){ return new ResponseEntity<>(attendanceService.queryAll(criteria,pageable),HttpStatus.OK); } @GetMapping("/notNormal") @Log("查询考勤记录") @ApiOperation("查询考勤记录") @PreAuthorize("@el.check('attendance:list')") public ResponseEntity<Object> queryAttendanceNotNormal(AttendanceQueryCriteria criteria, Pageable pageable){ return new ResponseEntity<>(attendanceService.queryAllNotNormal(criteria,pageable),HttpStatus.OK); } @GetMapping(value = "/all") @Log("查询考勤记录") @ApiOperation("查询考勤记录") @PreAuthorize("@el.check('attendance:list')") public ResponseEntity<Object> queryAttendance(AttendanceQueryCriteria criteria){ return new ResponseEntity<>(attendanceService.queryAll(criteria),HttpStatus.OK); } @PostMapping @Log("新增考勤记录") @ApiOperation("新增考勤记录") @PreAuthorize("@el.check('attendance:add')") public ResponseEntity<Object> createAttendance(@Validated @RequestBody Attendance resources){ return new ResponseEntity<>(attendanceService.create(resources),HttpStatus.CREATED); } @PutMapping @Log("修改考勤记录") @ApiOperation("修改考勤记录") @PreAuthorize("@el.check('attendance:edit')") public ResponseEntity<Object> updateAttendance(@Validated @RequestBody Attendance resources){ attendanceService.update(resources); return new ResponseEntity<>(HttpStatus.NO_CONTENT); } @DeleteMapping @Log("删除考勤记录") @ApiOperation("删除考勤记录") @PreAuthorize("@el.check('attendance:del')") public ResponseEntity<Object> deleteAttendance(@RequestBody Long[] ids) { attendanceService.deleteAll(ids); return new ResponseEntity<>(HttpStatus.OK); } @GetMapping(value = "/attendanceHours") @Log("查询某月出勤小时数") @ApiOperation("查询某月出勤小时数") @PreAuthorize("@el.check('attendance:list')") public ResponseEntity<Object> queryAttendanceHours(AttendanceQueryCriteria criteria) { return new ResponseEntity<>(attendanceService.queryAttendanceHours(criteria),HttpStatus.OK); } @GetMapping(value = "/queryAttendanceHours") @Log("查询某天出勤小时数") @ApiOperation("查询某天出勤小时数") @PreAuthorize("@el.check('attendance:list')") public ResponseEntity<Object> queryAttendanceHours(Long userId, String date) { return new ResponseEntity<>(attendanceService.queryAttendanceHours(userId, date),HttpStatus.OK); } @PostMapping(value = "/getUserMakeUpCard") @Log("补卡判断登录人") @ApiOperation("补卡判断登录人") public ResponseEntity<Object> getUserMakeUpCard(@Validated @RequestBody String userId){ attendanceService.getUserMakeUpCard(userId); return new ResponseEntity<>(HttpStatus.CREATED); } @PostMapping(value = "/addAttendanceInfo") @Log("考勤信息补充") @ApiOperation("考勤信息补充") public ResponseEntity<Object> addAttendanceInfo(@Validated @RequestBody Attendance attendance) throws Exception { attendanceService.addAttendanceInfo(attendance); return new ResponseEntity<>(HttpStatus.CREATED); } } eladmin-master/eladmin-system/src/main/java/me/zhengjie/modules/attendance/service/AttendanceService.java
@@ -44,6 +44,14 @@ Map<String,Object> queryAll(AttendanceQueryCriteria criteria, Pageable pageable); /** * 查询数据分页 * @param criteria 条件 * @param pageable 分页参数 * @return Map<String,Object> */ Map<String,Object> queryAllNotNormal(AttendanceQueryCriteria criteria, Pageable pageable); /** * 查询所有数据不分页 * @param criteria 条件参数 * @return List<AttendanceDto> eladmin-master/eladmin-system/src/main/java/me/zhengjie/modules/attendance/service/dto/AttendanceQueryCriteria.java
@@ -1,60 +1,71 @@ /* * Copyright 2019-2020 Zheng Jie * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package me.zhengjie.modules.attendance.service.dto; import lombok.Data; import java.util.List; import me.zhengjie.annotation.Query; /** * @website https://eladmin.vip * @author wcd * @date 2022-12-14 **/ @Data public class AttendanceQueryCriteria { /** 精确查询姓名 */ @Query private Long userId; /** 时间区间查询 */ @Query(type = Query.Type.BETWEEN, propName = "attendanceDate") private List<String> attendanceDate; /* 开始位置精确查询 */ @Query(type = Query.Type.EQUAL, propName = "startLocationResults") private String startLocationResults; /* 结束位置精确查询 */ @Query(type = Query.Type.EQUAL, propName = "endLocationResults") private String endLocationResults; /* 开始打卡精确查询 */ @Query(type = Query.Type.EQUAL, propName = "startClockResults") private String startClockResults; /* 结束打卡精确查询 */ @Query(type = Query.Type.EQUAL, propName = "endClockResults") private String endClockResults; /* 模糊 */ @Query(propName = "attendanceDate", type = Query.Type.INNER_LIKE) private String attendanceDateLike; private String targetYearMonth; /* * Copyright 2019-2020 Zheng Jie * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package me.zhengjie.modules.attendance.service.dto; import lombok.Data; import java.util.List; import me.zhengjie.annotation.Query; /** * @website https://eladmin.vip * @author wcd * @date 2022-12-14 **/ @Data public class AttendanceQueryCriteria { /** 精确查询姓名 */ @Query private Long userId; /** 时间区间查询 */ @Query(type = Query.Type.BETWEEN, propName = "attendanceDate") private List<String> attendanceDate; /* 开始位置精确查询 */ @Query(type = Query.Type.EQUAL, propName = "startLocationResults") private String startLocationResults; /* 结束位置精确查询 */ @Query(type = Query.Type.EQUAL, propName = "endLocationResults") private String endLocationResults; /* 开始打卡精确查询 */ @Query(type = Query.Type.EQUAL, propName = "startClockResults") private String startClockResults; /* 结束打卡精确查询 */ @Query(type = Query.Type.EQUAL, propName = "endClockResults") private String endClockResults; /* 开始打卡模糊查询 */ @Query(orGroup = "NotNormal", type = Query.Type.IN, propName = "startClockResults") private List<String> startClockResultsList; /* 结束打卡模糊查询 */ @Query(orGroup = "NotNormal", type = Query.Type.IN, propName = "endClockResults") private List<String> endClockResultsList; /* 模糊 */ @Query(propName = "attendanceDate", type = Query.Type.INNER_LIKE) private String attendanceDateLike; @Query(propName = "userId", type = Query.Type.IN) private List<Long> userIds; private String targetYearMonth; } eladmin-master/eladmin-system/src/main/java/me/zhengjie/modules/attendance/service/impl/AttendanceServiceImpl.java
@@ -24,14 +24,8 @@ import me.zhengjie.modules.attendance.service.mapstruct.AttendanceMapper; import me.zhengjie.modules.constant.Constant; import me.zhengjie.modules.quartz.service.impl.WeComServiceImpl; import me.zhengjie.modules.system.domain.Role; import me.zhengjie.modules.system.domain.SysConfigHoliday; import me.zhengjie.modules.system.domain.SysRostering; import me.zhengjie.modules.system.domain.User; import me.zhengjie.modules.system.repository.DictDetailRepository; import me.zhengjie.modules.system.repository.SysConfigHolidayRepository; import me.zhengjie.modules.system.repository.SysRosteringRepository; import me.zhengjie.modules.system.repository.UserRepository; import me.zhengjie.modules.system.domain.*; import me.zhengjie.modules.system.repository.*; import me.zhengjie.modules.system.service.dto.SysConfigHolidayQueryCriteria; import me.zhengjie.utils.*; import org.apache.commons.lang3.ObjectUtils; @@ -96,6 +90,29 @@ } @Override public Map<String,Object> queryAllNotNormal(AttendanceQueryCriteria criteria, Pageable pageable) { if (criteria.getUserId() == null) { List<String> wecomExcludeList = dictDetailRepository.findByDictName("wecom_exclude_list").stream().map(DictDetail::getValue).collect(Collectors.toList()); criteria.setUserIds(userRepository.findAllByEnabled(true).stream().filter(user ->!wecomExcludeList.contains(user.getWeComId())).map(User::getId).collect(Collectors.toList())); } criteria.setStartClockResultsList(Arrays.asList(Constant.ATTENDANCE_START_EARLY, Constant.ATTENDANCE_START_LATE, Constant.ATTENDANCE_STATE_WAITFOR, Constant.ATTENDANCE_STATE_NOTSIGNED, Constant.ATTENDANCE_STATE_LACK_OF_TIME)); criteria.setEndClockResultsList(Arrays.asList(Constant.ATTENDANCE_START_EARLY, Constant.ATTENDANCE_START_LATE, Constant.ATTENDANCE_STATE_WAITFOR, Constant.ATTENDANCE_STATE_NOTSIGNED, Constant.ATTENDANCE_STATE_LACK_OF_TIME)); Page<Attendance> page = attendanceRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root,criteria,criteriaBuilder),pageable); //将实体转换为Dto(重写) Function<Attendance, AttendanceDto> func = attendance -> { // 将实体类转换成DTO AttendanceDto attendanceDto = attendanceMapper.toDto(attendance); //查询用户信息 User user = userRepository.findById(attendanceDto.getUserId()).orElseGet(User::new); attendanceDto.setUserName(user.getNickName()); return attendanceDto; }; return PageUtil.toPage(page.map(func)); } @Override public List<AttendanceDto> queryAll(AttendanceQueryCriteria criteria){ return attendanceMapper.toDto(attendanceRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root,criteria,criteriaBuilder))); } eladmin-master/eladmin-system/src/main/java/me/zhengjie/modules/task/service/impl/TaskServiceImpl.java
@@ -16,6 +16,7 @@ package me.zhengjie.modules.task.service.impl; import lombok.RequiredArgsConstructor; import me.zhengjie.exception.BadRequestException; import me.zhengjie.modules.constant.Constant; import me.zhengjie.modules.project.domain.Project; import me.zhengjie.modules.project.repository.ProjectRepository; @@ -946,6 +947,10 @@ @CacheEvict(cacheNames = "ChildrenTask", allEntries = true) public TaskMongo create(Long userId, TaskMongo resources) { resources.setTaskStatus(Constant.TASK_STATUS_NOT_STARTED); boolean existed = mongoTemplate.exists(Query.query(Criteria.where("name").is(resources.getName()).and("projectId").is(resources.getProjectId())), TaskMongo.class); if (existed) { throw new BadRequestException("任务名称重复"); } synchronized (lock) { // 查询最大的old_id值 Query query = new Query(); @@ -972,7 +977,10 @@ // // containUserList.addAll(userIdList.stream().filter(o -> !containUserList.contains(o)).collect(Collectors.toList())); boolean existed = mongoTemplate.exists(Query.query(Criteria.where("name").is(resources.getName()).and("projectId").is(resources.getProjectId()).and("id").ne(resources.getId())), TaskMongo.class); if (existed) { throw new BadRequestException("任务名称重复"); } return mongoTemplate.save(resources); } eladmin-web-master/src/api/attendance/attendanceLeave.js
@@ -40,17 +40,17 @@ }) } export function getYearTimeLength(data) { export function getYearTimeLength(userId, data) { return request({ url: 'api/attendanceLeave/getYearTimeLength', url: 'api/attendanceLeave/getYearTimeLength/' + userId, method: 'post', data }) } export function getOverTimeLength(data) { export function getOverTimeLength(userId, data) { return request({ url: 'api/attendanceLeave/getOverTimeLength', url: 'api/attendanceLeave/getOverTimeLength/' + userId, method: 'post', data }) eladmin-web-master/src/views/assetManagement/assetUseManagement/index.vue
@@ -210,7 +210,7 @@ crudUser.getAll().then(res => { this.users = res }) // 资产 // 资产 response.data crudAssetManagement.getAll().then(res => { this.assetManagements = res }) eladmin-web-master/src/views/attendance/attendanceLeave/index.vue
@@ -449,11 +449,11 @@ return } // 获取年假剩余时长 crudAttendanceLeave.getYearTimeLength((this.form.userId == null ? 1 : this.form.userId)).then(res => { crudAttendanceLeave.getYearTimeLength((this.form.userId == null ? 1 : this.form.userId), this.form.leaveStartTime.substring(0, 4)).then(res => { this.yearTimeLenght = res }) // 获取调休假剩余时长 crudAttendanceLeave.getOverTimeLength((this.form.userId == null ? 1 : this.form.userId)).then(res => { crudAttendanceLeave.getOverTimeLength((this.form.userId == null ? 1 : this.form.userId), this.form.leaveStartTime.substring(0, 7)).then(res => { this.OverTimeLenght = res }) // 通过后台计算时长 eladmin-web-master/src/views/task/taskUser/index.vue
@@ -326,7 +326,7 @@ 当前任务:<i> {{ selectedTaskName }} </i> <span v-if="taskTotal.performanceType" style="magin: right 10px;" style="margin: right 10px;" ><i> (绩效类型: {{