From 068093a6e0fb03ed664ad4c71b5b824b6998d7da Mon Sep 17 00:00:00 2001 From: ls <1793460677@qq.com> Date: Wed, 26 Feb 2025 09:56:43 +0800 Subject: [PATCH] =?UTF-8?q?add:=20=E7=94=A8=E6=88=B7=E3=80=81=E7=BB=84?= =?UTF-8?q?=E7=BB=87?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pom.xml | 6 +- .../java/com/boge/common/base/BaseDTO.java | 33 +++ .../java/com/boge/common/base/BaseMapper.java | 53 +++++ .../com/boge/common/base/TableDataInfo.java | 78 +++++++ .../java/com/boge/common/query/BaseQuery.java | 73 +++++++ .../java/com/boge/common/query/LConsumer.java | 21 ++ .../java/com/boge/common/query/MapOf.java | 21 ++ .../java/com/boge/common/query/PageQuery.java | 115 ++++++++++ .../java/com/boge/common/query/QParam.java | 18 ++ .../com/boge/common/query/QueryTEnum.java | 35 +++ .../java/com/boge/common/utils/CopyUtil.java | 33 +++ .../dept/controller/DeptController.java | 104 +++++++++ .../com/boge/modules/dept/dao/SysDept.java | 107 ++++++++++ .../boge/modules/dept/dao/SysUserDept.java | 35 +++ .../dept/dao/mapper/SysDeptMapper.java | 46 ++++ .../dept/dao/mapper/SysUserDeptMapper.java | 18 ++ .../com/boge/modules/dept/dto/DeptQuery.java | 31 +++ .../com/boge/modules/dept/dto/DeptTree.java | 44 ++++ .../modules/dept/service/ISysDeptService.java | 68 ++++++ .../dept/service/ISysUserDeptService.java | 16 ++ .../dept/service/impl/SysDeptServiceImpl.java | 179 ++++++++++++++++ .../service/impl/SysUserDeptServiceImpl.java | 21 ++ .../com/boge/modules/dept/util/PageUtil.java | 70 ++++++ .../java/com/boge/modules/dept/vo/DeptVo.java | 83 +++++++ .../dict/controller/SysDictController.java | 102 +++++++++ .../java/com/boge/modules/dict/dao/Dict.java | 107 ++++++++++ .../dict/dao/mapper/SysDictMapper.java | 18 ++ .../com/boge/modules/dict/dto/DictQuery.java | 19 ++ .../modules/dict/service/ISysDictService.java | 88 ++++++++ .../dict/service/impl/SysDictServiceImpl.java | 202 ++++++++++++++++++ .../flow/controller/FlwDeModelController.java | 2 +- .../flow/controller/FlwDeployController.java | 2 +- .../controller/FlwInstanceController.java | 2 +- .../resources/mapper/dept/SysDeptMapper.xml | 40 ++++ .../mapper/dept/SysUserDeptMapper.xml | 5 + .../resources/mapper/dict/SysDictMapper.xml | 5 + 36 files changed, 1896 insertions(+), 4 deletions(-) create mode 100644 src/main/java/com/boge/common/base/BaseDTO.java create mode 100644 src/main/java/com/boge/common/base/BaseMapper.java create mode 100644 src/main/java/com/boge/common/base/TableDataInfo.java create mode 100644 src/main/java/com/boge/common/query/BaseQuery.java create mode 100644 src/main/java/com/boge/common/query/LConsumer.java create mode 100644 src/main/java/com/boge/common/query/MapOf.java create mode 100644 src/main/java/com/boge/common/query/PageQuery.java create mode 100644 src/main/java/com/boge/common/query/QParam.java create mode 100644 src/main/java/com/boge/common/query/QueryTEnum.java create mode 100644 src/main/java/com/boge/common/utils/CopyUtil.java create mode 100644 src/main/java/com/boge/modules/dept/controller/DeptController.java create mode 100644 src/main/java/com/boge/modules/dept/dao/SysDept.java create mode 100644 src/main/java/com/boge/modules/dept/dao/SysUserDept.java create mode 100644 src/main/java/com/boge/modules/dept/dao/mapper/SysDeptMapper.java create mode 100644 src/main/java/com/boge/modules/dept/dao/mapper/SysUserDeptMapper.java create mode 100644 src/main/java/com/boge/modules/dept/dto/DeptQuery.java create mode 100644 src/main/java/com/boge/modules/dept/dto/DeptTree.java create mode 100644 src/main/java/com/boge/modules/dept/service/ISysDeptService.java create mode 100644 src/main/java/com/boge/modules/dept/service/ISysUserDeptService.java create mode 100644 src/main/java/com/boge/modules/dept/service/impl/SysDeptServiceImpl.java create mode 100644 src/main/java/com/boge/modules/dept/service/impl/SysUserDeptServiceImpl.java create mode 100644 src/main/java/com/boge/modules/dept/util/PageUtil.java create mode 100644 src/main/java/com/boge/modules/dept/vo/DeptVo.java create mode 100644 src/main/java/com/boge/modules/dict/controller/SysDictController.java create mode 100644 src/main/java/com/boge/modules/dict/dao/Dict.java create mode 100644 src/main/java/com/boge/modules/dict/dao/mapper/SysDictMapper.java create mode 100644 src/main/java/com/boge/modules/dict/dto/DictQuery.java create mode 100644 src/main/java/com/boge/modules/dict/service/ISysDictService.java create mode 100644 src/main/java/com/boge/modules/dict/service/impl/SysDictServiceImpl.java create mode 100644 src/main/resources/mapper/dept/SysDeptMapper.xml create mode 100644 src/main/resources/mapper/dept/SysUserDeptMapper.xml create mode 100644 src/main/resources/mapper/dict/SysDictMapper.xml diff --git a/pom.xml b/pom.xml index 0f4bffd..f6f6a2f 100644 --- a/pom.xml +++ b/pom.xml @@ -39,7 +39,7 @@ 2.9.9 2.8.5 1.2.72 - 4.1.1 + 5.8.22 1.18.4 @@ -54,6 +54,10 @@ org.springframework.boot spring-boot-starter-web + + org.springframework.boot + spring-boot-starter-security + org.springframework.boot spring-boot-starter-aop diff --git a/src/main/java/com/boge/common/base/BaseDTO.java b/src/main/java/com/boge/common/base/BaseDTO.java new file mode 100644 index 0000000..8e8d046 --- /dev/null +++ b/src/main/java/com/boge/common/base/BaseDTO.java @@ -0,0 +1,33 @@ +package com.boge.common.base; + +import com.alibaba.fastjson.annotation.JSONField; +import com.fasterxml.jackson.annotation.JsonFormat; +import lombok.Data; + +import java.io.Serializable; +import java.util.Date; + +/** + * @author Zheng Jie + * @date 2019年10月24日20:48:53 + */ +@Data +public class BaseDTO implements Serializable { + + private String create_name; + + private String create_id; + + private String update_name; + + private String update_id; + + @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss") + @JSONField(format = "yyyy-MM-dd HH:mm:ss") + private Date create_time; + + @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss") + @JSONField(format = "yyyy-MM-dd HH:mm:ss") + private Date update_time; + +} diff --git a/src/main/java/com/boge/common/base/BaseMapper.java b/src/main/java/com/boge/common/base/BaseMapper.java new file mode 100644 index 0000000..7000d21 --- /dev/null +++ b/src/main/java/com/boge/common/base/BaseMapper.java @@ -0,0 +1,53 @@ +/* + * 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 com.boge.common.base; + +import java.util.List; + +/** + * @author Zheng Jie + * @date 2018-11-23 + */ +public interface BaseMapper { + + /** + * DTO转Entity + * @param dto / + * @return / + */ + E toEntity(D dto); + + /** + * Entity转DTO + * @param entity / + * @return / + */ + D toDto(E entity); + + /** + * DTO集合转Entity集合 + * @param dtoList / + * @return / + */ + List toEntity(List dtoList); + + /** + * Entity集合转DTO集合 + * @param entityList / + * @return / + */ + List toDto(List entityList); +} diff --git a/src/main/java/com/boge/common/base/TableDataInfo.java b/src/main/java/com/boge/common/base/TableDataInfo.java new file mode 100644 index 0000000..be4155e --- /dev/null +++ b/src/main/java/com/boge/common/base/TableDataInfo.java @@ -0,0 +1,78 @@ +package com.boge.common.base; + +import cn.hutool.http.HttpStatus; +import com.baomidou.mybatisplus.core.metadata.IPage; +import lombok.Data; +import lombok.NoArgsConstructor; + +import java.io.Serializable; +import java.util.List; + +/** + * 表格分页数据对象 + * + * @author Lion Li + */ + +@Data +@NoArgsConstructor +public class TableDataInfo implements Serializable { + private static final long serialVersionUID = 1L; + + /** + * 总记录数 + */ + private long totalElements; + + /** + * 列表数据 + */ + private List content; + + /** + * 消息状态码 + */ + private int code; + + /** + * 消息内容 + */ + private String msg; + + /** + * 分页 + * + * @param list 列表数据 + * @param total 总记录数 + */ + public TableDataInfo(List list, long total) { + this.content = list; + this.totalElements = total; + } + + public static TableDataInfo build(IPage page) { + TableDataInfo rspData = new TableDataInfo<>(); + rspData.setCode(HttpStatus.HTTP_OK); + rspData.setMsg("查询成功"); + rspData.setContent(page.getRecords()); + rspData.setTotalElements(page.getTotal()); + return rspData; + } + + public static TableDataInfo build(List list) { + TableDataInfo rspData = new TableDataInfo<>(); + rspData.setCode(HttpStatus.HTTP_OK); + rspData.setMsg("查询成功"); + rspData.setContent(list); + rspData.setTotalElements(list.size()); + return rspData; + } + + public static TableDataInfo build() { + TableDataInfo rspData = new TableDataInfo<>(); + rspData.setCode(HttpStatus.HTTP_OK); + rspData.setMsg("查询成功"); + return rspData; + } + +} diff --git a/src/main/java/com/boge/common/query/BaseQuery.java b/src/main/java/com/boge/common/query/BaseQuery.java new file mode 100644 index 0000000..df8c26f --- /dev/null +++ b/src/main/java/com/boge/common/query/BaseQuery.java @@ -0,0 +1,73 @@ +package com.boge.common.query; + +import com.alibaba.fastjson.JSONObject; +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; +import com.baomidou.mybatisplus.core.toolkit.LambdaUtils; +import com.baomidou.mybatisplus.core.toolkit.support.ColumnCache; +import lombok.Data; + +import sun.reflect.generics.reflectiveObjects.ParameterizedTypeImpl; + +import java.lang.reflect.Type; +import java.util.Date; +import java.util.Map; + +/** + * 泛型必须为数据tb对应do:由mybatis管理 + * @author ZZQ + * @Date 2022/12/14 6:33 下午 + */ +@Data +public class BaseQuery { + /** + * 模糊查询 + */ + private String blurry; + /** + * 是否启用 + */ + private String is_used; + /** + * 创建时间范围查询 + */ + private String start_time; + private String end_time; + + + /** + * 字段映射Map:指定字段对应QueryWrapper的查询类型 + * 字段与数据库字段对应,不支持驼峰 + * 通过buid构建 + */ + public Map doP = MapOf.of("blurry", QParam.builder().k(new String[]{"name"}).type(QueryTEnum.LK).build() + ,"startTime", QParam.builder().k(new String[]{"create_time"}).type(QueryTEnum.LT).build() + ,"endTime", QParam.builder().k(new String[]{"create_time"}).type(QueryTEnum.LE).build() + ,"sort", QParam.builder().k(new String[]{"sort"}).type(QueryTEnum.BY).build() + ); + + public QueryWrapper build(){ + this.paramMapping(); + QueryWrapper wrapper = new QueryWrapper<>(); + JSONObject json = (JSONObject)JSONObject.toJSON(this); + Type[] types = ((ParameterizedTypeImpl) this.getClass().getGenericSuperclass()).getActualTypeArguments(); + Map columnMap = LambdaUtils.getColumnMap((Class) types[0]); + + String dopStr = "doP"; + json.forEach((key, vel) -> { + if (vel != null && !key.equals(dopStr)){ + QParam qParam = doP.get(key); + if (qParam != null){ + QueryTEnum.build(qParam.type,wrapper,qParam.k,vel); + }else { + ColumnCache columnCache = columnMap.get(LambdaUtils.formatKey(key)); + if (columnCache!=null){ + wrapper.eq(columnCache.getColumn(),vel); + } + } + } + }); + return wrapper; + } + + public void paramMapping(){}; +} diff --git a/src/main/java/com/boge/common/query/LConsumer.java b/src/main/java/com/boge/common/query/LConsumer.java new file mode 100644 index 0000000..0f3443d --- /dev/null +++ b/src/main/java/com/boge/common/query/LConsumer.java @@ -0,0 +1,21 @@ +package com.boge.common.query; + +import java.util.Objects; + +/** + * s + * @author ZZQ + * @Date 2022/12/14 8:40 下午 + */ +@FunctionalInterface +public interface LConsumer { + + /** + * 切面 + * @param x 、 + * @param y 、 + * @param z 、 + */ + void accept(X x,Y y,Z z); + +} diff --git a/src/main/java/com/boge/common/query/MapOf.java b/src/main/java/com/boge/common/query/MapOf.java new file mode 100644 index 0000000..227ae44 --- /dev/null +++ b/src/main/java/com/boge/common/query/MapOf.java @@ -0,0 +1,21 @@ +package com.boge.common.query; + + +import java.io.Serializable; +import java.util.HashMap; + +/** + * s + * @author ZZQ + * @Date 2022/11/29 2:55 下午 + */ +public class MapOf implements Serializable { + + public static HashMap of(K... key){ + HashMap map = new HashMap<>(); + for (int i = 0; i < (key.length & ~1); i=i+2) { + map.put(key[i],key[i+1]); + } + return map; + } +} diff --git a/src/main/java/com/boge/common/query/PageQuery.java b/src/main/java/com/boge/common/query/PageQuery.java new file mode 100644 index 0000000..f632e64 --- /dev/null +++ b/src/main/java/com/boge/common/query/PageQuery.java @@ -0,0 +1,115 @@ +package com.boge.common.query; + +import cn.hutool.core.util.ObjectUtil; +import com.baomidou.mybatisplus.annotation.TableId; +import com.baomidou.mybatisplus.core.metadata.OrderItem; +import com.baomidou.mybatisplus.extension.plugins.pagination.Page; +import lombok.Data; +import org.apache.commons.lang3.StringUtils; + +import java.io.Serializable; +import java.lang.reflect.Field; +import java.util.Locale; + +/** + *

+ * 分页参数 + *

+ * + * @author generator + * @since 2023-11-16 + */ +@Data +public class PageQuery implements Serializable { + + private static final long serialVersionUID = 1L; + + /** + * 分页大小 + */ + private Integer size; + + /** + * 当前页数 + */ + private Integer page; + + /** + * 排序列 + */ + private String sort; + + /** + * 排序的方向desc或者asc + */ + private Boolean isAsc; + + /** + * 当前记录起始索引 默认值 + */ + public static final int DEFAULT_PAGE_NUM = 1; + + /** + * 每页显示记录数 默认值 默认查全部 + */ + public static final int DEFAULT_PAGE_SIZE = Integer.MAX_VALUE; + + public Page build() { + Integer pageNum = ObjectUtil.defaultIfNull(getPage(), DEFAULT_PAGE_NUM); + Integer pageSize = ObjectUtil.defaultIfNull(getSize(), DEFAULT_PAGE_SIZE); + if (pageNum <= 0) { + pageNum = DEFAULT_PAGE_NUM; + } + Page page = new Page<>(pageNum, pageSize); + if (StringUtils.isNotEmpty(sort)){ + String[] split = sort.split(","); + for (int i = 0; i < (split.length & ~1); i=i+2) { + String col = split[i]; + OrderItem item = new OrderItem(); + item.setColumn(col); + item.setAsc(split[i+1].toLowerCase(Locale.ROOT).equals("asc")); + page.addOrder(item); + } + } + return page; + } + + public Page build(Class r) { + Integer pageNum = ObjectUtil.defaultIfNull(getPage(), DEFAULT_PAGE_NUM); + Integer pageSize = ObjectUtil.defaultIfNull(getSize(), DEFAULT_PAGE_SIZE); + if (pageNum <= 0) { + pageNum = DEFAULT_PAGE_NUM; + } + Page page = new Page<>(pageNum, pageSize); + if (StringUtils.isNotEmpty(sort)){ + String[] split = sort.split(","); + for (int i = 0; i < (split.length & ~1); i=i+2) { + String col = split[i]; + if ("id".equals(col)){ + String mId = mappingId(r); + col = StringUtils.isNotEmpty(mId)?mId:col; + } + OrderItem item = new OrderItem(); + item.setColumn(col); + item.setAsc(split[i+1].toLowerCase(Locale.ROOT).equals("asc")); + page.addOrder(item); + } + + } + return page; + } + + private String mappingId(R r){ + if (r instanceof Class){ + Field[] fields = ((Class) r).getDeclaredFields(); + for (Field field : fields) { + TableId[] byType = field.getAnnotationsByType(TableId.class); + if (byType !=null && byType.length>0){ + TableId tableId = byType[0]; + return tableId.value(); + } + } + } + return null; + } +} diff --git a/src/main/java/com/boge/common/query/QParam.java b/src/main/java/com/boge/common/query/QParam.java new file mode 100644 index 0000000..45a7307 --- /dev/null +++ b/src/main/java/com/boge/common/query/QParam.java @@ -0,0 +1,18 @@ +package com.boge.common.query; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + + +/** + * s + * @author ZZQ + * @Date 2022/12/15 1:41 下午 + */ +@Builder +public class QParam { + public String[] k; + public QueryTEnum type; +} diff --git a/src/main/java/com/boge/common/query/QueryTEnum.java b/src/main/java/com/boge/common/query/QueryTEnum.java new file mode 100644 index 0000000..e509afd --- /dev/null +++ b/src/main/java/com/boge/common/query/QueryTEnum.java @@ -0,0 +1,35 @@ +package com.boge.common.query; + +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; +import lombok.Getter; +import org.apache.commons.lang3.StringUtils; + +import java.util.Collection; + +/** + * s + * @author ZZQ + * @Date 2022/12/14 8:26 下午 + */ +@Getter +public enum QueryTEnum { + // + EQ((q, k, v) -> { q.eq(k[0],v); }), + IN((q, key, o) -> { if (o instanceof Collection){ q.in(key[0],(Collection) o); } }), + LK((q, keys, o) -> { for (String key : keys) { q.like(key,o); } }), + LE((q, k, v) -> { q.le(k[0],v); }), + BY((q, k, v) -> { q.orderByDesc(k[0],v); }), + NO((q, k, v) -> { q.isNull(k[0]); }), + LT((q, k, v) -> { q.lt(k[0],v); }), + OREQ((q, k, v) -> { if (StringUtils.isBlank((String)v)){ q.isNull(k[0]); }else { q.eq(k[0],v); } }); + + private LConsumer doP; + + QueryTEnum(LConsumer doP) { + this.doP = doP; + } + + public static void build(QueryTEnum type, QueryWrapper q, String[] k , Object v){ + type.getDoP().accept(q,k,v); + } +} diff --git a/src/main/java/com/boge/common/utils/CopyUtil.java b/src/main/java/com/boge/common/utils/CopyUtil.java new file mode 100644 index 0000000..8027889 --- /dev/null +++ b/src/main/java/com/boge/common/utils/CopyUtil.java @@ -0,0 +1,33 @@ +package com.boge.common.utils; + +import org.springframework.beans.BeanUtils; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.Iterator; +import java.util.List; + + +public class CopyUtil { + public static List copyList(final Collection sources, final Class clazz) { + if (sources == null) { + return new ArrayList(0); + } else { + List list = new ArrayList(sources.size()); + Iterator var3 = sources.iterator(); + + while(var3.hasNext()) { + Object source = var3.next(); + + try { + T dest = clazz.newInstance(); + BeanUtils.copyProperties(source, dest); + list.add(dest); + } catch (Throwable var6) { + } + } + return list; + } + } + +} diff --git a/src/main/java/com/boge/modules/dept/controller/DeptController.java b/src/main/java/com/boge/modules/dept/controller/DeptController.java new file mode 100644 index 0000000..ab4a7cc --- /dev/null +++ b/src/main/java/com/boge/modules/dept/controller/DeptController.java @@ -0,0 +1,104 @@ +/* + * 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 com.boge.modules.dept.controller; + +import com.baomidou.mybatisplus.extension.plugins.pagination.Page; +import com.boge.common.base.TableDataInfo; +import com.boge.common.exception.RRException; +import com.boge.common.query.PageQuery; +import com.boge.modules.dept.dao.SysDept; +import com.boge.modules.dept.dto.DeptQuery; +import com.boge.modules.dept.service.ISysDeptService; +import com.boge.modules.dept.util.PageUtil; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; +import org.springframework.util.CollectionUtils; +import org.springframework.validation.annotation.Validated; +import org.springframework.web.bind.annotation.*; + +import java.util.List; +import java.util.Set; + +/** +* @author Zheng Jie +* @date 2019-03-25 +*/ +@RestController + +@RequestMapping("/api/dept") +public class DeptController { + + @Autowired + private ISysDeptService deptService; + + + @GetMapping + public ResponseEntity query(DeptQuery query) throws Exception { + List list = deptService.list(query.build()); + return new ResponseEntity<>(PageUtil.toPage(list, list.size()),HttpStatus.OK); + } + + + @GetMapping("/vo") + public ResponseEntity queryvo(DeptQuery query, PageQuery pageQuery) throws Exception { + Page deptPage = deptService.queryVo(query, pageQuery); + return new ResponseEntity((TableDataInfo.build(deptPage)),HttpStatus.OK); + } + + + + @GetMapping("/allTree") + public ResponseEntity allTree(DeptQuery query) { + return new ResponseEntity<>(deptService.buildTree(query),HttpStatus.OK); + } + + + @PostMapping("/superior") + public ResponseEntity getSuperior(@RequestBody List ids) { + if (CollectionUtils.isEmpty(ids)){ + return ResponseEntity.noContent().build(); + } + return new ResponseEntity<>(deptService.getSuperior(ids),HttpStatus.OK); + } + + + @PostMapping + public ResponseEntity create(@Validated @RequestBody SysDept resources){ + deptService.createDept(resources); + return new ResponseEntity<>(HttpStatus.CREATED); + } + + + @PutMapping + public ResponseEntity update(@Validated @RequestBody SysDept dept){ + if (dept.getPid() != null && dept.getDept_id().equals(dept.getPid())) { + throw new RRException("ID不能为空"); + } + deptService.updateDept(dept); + return new ResponseEntity<>(HttpStatus.NO_CONTENT); + } + + + @DeleteMapping + public ResponseEntity delete(@RequestBody Set deptIds){ + if (CollectionUtils.isEmpty(deptIds)){ + return ResponseEntity.noContent().build(); + } + deptService.delateDept(deptIds); + return new ResponseEntity<>(HttpStatus.OK); + } +} diff --git a/src/main/java/com/boge/modules/dept/dao/SysDept.java b/src/main/java/com/boge/modules/dept/dao/SysDept.java new file mode 100644 index 0000000..2f798f6 --- /dev/null +++ b/src/main/java/com/boge/modules/dept/dao/SysDept.java @@ -0,0 +1,107 @@ +package com.boge.modules.dept.dao; + +import com.baomidou.mybatisplus.annotation.IdType; +import com.baomidou.mybatisplus.annotation.TableId; +import com.baomidou.mybatisplus.annotation.TableName; +import com.fasterxml.jackson.annotation.JsonFormat; +import lombok.Data; +import lombok.EqualsAndHashCode; + +import java.io.Serializable; +import java.util.Date; + +/** + *

+ * 部门 + *

+ * + * @author generator + * @since 2022-12-15 + */ +@Data +@EqualsAndHashCode(callSuper = false) +@TableName("sys_dept") +public class SysDept implements Serializable { + + private static final long serialVersionUID = 1L; + + /** + * ID + */ + @TableId(value = "dept_id", type = IdType.NONE) + private String dept_id; + + /** + * 上级部门 + */ + private String pid; + + /** + * 子部门数目 + */ + private Integer sub_count; + + /** + * 名称 + */ + private String name; + + /** + * 中文名称 + */ + private String zh_name; + /** + * 英文名称 + */ + private String en_name; + + /** + * 印尼名称 + */ + private String in_name; + + /** + * 排序 + */ + private Integer dept_sort; + + /** + * 状态 + */ + private Boolean is_used; + + private String create_id; + + /** + * 创建者 + */ + private String create_name; + + private String update_id; + + /** + * 更新者 + */ + private String update_name; + + /** + * 创建日期 + */ + @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss") + private Date create_time; + + /** + * 更新时间 + */ + @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss") + private Date update_time; + + /** + * 部门编号 + */ + private String code; + + private String ext_id; + + +} diff --git a/src/main/java/com/boge/modules/dept/dao/SysUserDept.java b/src/main/java/com/boge/modules/dept/dao/SysUserDept.java new file mode 100644 index 0000000..a7c9433 --- /dev/null +++ b/src/main/java/com/boge/modules/dept/dao/SysUserDept.java @@ -0,0 +1,35 @@ +package com.boge.modules.dept.dao; + +import com.baomidou.mybatisplus.annotation.TableName; +import lombok.Data; +import lombok.EqualsAndHashCode; + +import java.io.Serializable; + +/** + *

+ * 部门表 + *

+ * + * @author generator + * @since 2022-12-15 + */ +@Data +@EqualsAndHashCode(callSuper = false) +@TableName("sys_user_dept") +public class SysUserDept implements Serializable { + + private static final long serialVersionUID = 1L; + + /** + * 用户标识 + */ + private Long user_id; + + /** + * 部门标识 + */ + private Long dept_id; + + +} diff --git a/src/main/java/com/boge/modules/dept/dao/mapper/SysDeptMapper.java b/src/main/java/com/boge/modules/dept/dao/mapper/SysDeptMapper.java new file mode 100644 index 0000000..75d9d17 --- /dev/null +++ b/src/main/java/com/boge/modules/dept/dao/mapper/SysDeptMapper.java @@ -0,0 +1,46 @@ +package com.boge.modules.dept.dao.mapper; + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.boge.modules.dept.dao.SysDept; +import org.apache.ibatis.annotations.Mapper; +import org.apache.ibatis.annotations.Param; + +import java.util.Collection; +import java.util.List; +import java.util.Map; + +/** + *

+ * 部门 Mapper 接口 + *

+ * + * @author generator + * @since 2022-12-15 + */ +@Mapper +public interface SysDeptMapper extends BaseMapper { + + /** + * 保存依赖关系 + * @param UserId + * @param deptId + */ + void saveDeptRelation(@Param("user") String UserId,@Param("depts") Collection deptId); + void delDeptRelation(@Param("user") String UserId); + + List getDeptRelation(@Param("deptIds") Collection deptIds); + + /** + * 跟新sub_count字段 + * @param deptId + * @return + */ + int updateSubCount(String deptId); + + /** + * 返回字符串列表 split = , + * @param pid + * @return + */ + String findAllChild(String pid); +} diff --git a/src/main/java/com/boge/modules/dept/dao/mapper/SysUserDeptMapper.java b/src/main/java/com/boge/modules/dept/dao/mapper/SysUserDeptMapper.java new file mode 100644 index 0000000..1612192 --- /dev/null +++ b/src/main/java/com/boge/modules/dept/dao/mapper/SysUserDeptMapper.java @@ -0,0 +1,18 @@ +package com.boge.modules.dept.dao.mapper; + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.boge.modules.dept.dao.SysUserDept; +import org.apache.ibatis.annotations.Mapper; + +/** + *

+ * 部门表 Mapper 接口 + *

+ * + * @author generator + * @since 2022-12-15 + */ +@Mapper +public interface SysUserDeptMapper extends BaseMapper { + +} diff --git a/src/main/java/com/boge/modules/dept/dto/DeptQuery.java b/src/main/java/com/boge/modules/dept/dto/DeptQuery.java new file mode 100644 index 0000000..8e59173 --- /dev/null +++ b/src/main/java/com/boge/modules/dept/dto/DeptQuery.java @@ -0,0 +1,31 @@ +package com.boge.modules.dept.dto; + +import com.boge.common.query.BaseQuery; +import com.boge.common.query.QParam; +import com.boge.common.query.QueryTEnum; +import com.boge.modules.dept.dao.SysDept; +import lombok.Data; + + +import java.util.List; + + +@Data +public class DeptQuery extends BaseQuery { + + private List deptIds; + + private String name; + + private String code; + + private Long pid; + + private Boolean pid_is_null; + + @Override + public void paramMapping() { + super.doP.put("pid_is_null", QParam.builder().k(new String[]{"pid"}).type(QueryTEnum.NO).build()); + super.doP.put("deptIds", QParam.builder().k(new String[]{"dept_id"}).type(QueryTEnum.IN).build()); + } +} diff --git a/src/main/java/com/boge/modules/dept/dto/DeptTree.java b/src/main/java/com/boge/modules/dept/dto/DeptTree.java new file mode 100644 index 0000000..ce1d628 --- /dev/null +++ b/src/main/java/com/boge/modules/dept/dto/DeptTree.java @@ -0,0 +1,44 @@ +/* + * 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 com.boge.modules.dept.dto; + +import com.fasterxml.jackson.annotation.JsonInclude; +import lombok.Getter; +import lombok.Setter; + +import java.io.Serializable; +import java.util.List; + +/** +* @author Zheng Jie +* @date 2019-03-25 +*/ +@Getter +@Setter +public class DeptTree implements Serializable { + + private String dept_id; + + private String pid; + + private String name; + private String in_name; + private String en_name; + private String zh_name; + @JsonInclude(JsonInclude.Include.NON_EMPTY) + private List children; + +} diff --git a/src/main/java/com/boge/modules/dept/service/ISysDeptService.java b/src/main/java/com/boge/modules/dept/service/ISysDeptService.java new file mode 100644 index 0000000..a36a3d7 --- /dev/null +++ b/src/main/java/com/boge/modules/dept/service/ISysDeptService.java @@ -0,0 +1,68 @@ +package com.boge.modules.dept.service; + +import com.baomidou.mybatisplus.extension.plugins.pagination.Page; +import com.baomidou.mybatisplus.extension.service.IService; +import com.boge.common.query.PageQuery; +import com.boge.modules.dept.dao.SysDept; +import com.boge.modules.dept.dto.DeptQuery; + + +import java.util.Collection; +import java.util.List; +import java.util.Map; +import java.util.Set; + +/** + *

+ * 部门 服务类 + *

+ * + * @author generator + * @since 2022-12-15 + */ +public interface ISysDeptService extends IService { + /** + * 条件查询 + * @param query + * @param pageQuery + * @return + */ + Page queryVo(DeptQuery query, PageQuery pageQuery); + + /** + * 条件查询树结构 + * @param query + * @return + */ + Map buildTree(DeptQuery query); + + /** + * 查询当前部门id的上级id + * @param deptIds + * @return + */ + Map getSuperior(List deptIds); + + /** + * 保存用户部门关系 + * @param UserId + * @param deptIds + */ + void saveUserDeptRelation(String UserId, Collection deptIds); + void delUserDeptRelation(String user); + + /** + * 更新部门:同时更新节点 + * @param dept + */ + void updateDept(SysDept dept); + + /** + * 删除部门及子部门 + * @param deptIds + */ + void delateDept(Set deptIds); + + void createDept(SysDept dept); + +} diff --git a/src/main/java/com/boge/modules/dept/service/ISysUserDeptService.java b/src/main/java/com/boge/modules/dept/service/ISysUserDeptService.java new file mode 100644 index 0000000..8161107 --- /dev/null +++ b/src/main/java/com/boge/modules/dept/service/ISysUserDeptService.java @@ -0,0 +1,16 @@ +package com.boge.modules.dept.service; + +import com.baomidou.mybatisplus.extension.service.IService; +import com.boge.modules.dept.dao.SysUserDept; + +/** + *

+ * 部门表 服务类 + *

+ * + * @author generator + * @since 2022-12-15 + */ +public interface ISysUserDeptService extends IService { + +} diff --git a/src/main/java/com/boge/modules/dept/service/impl/SysDeptServiceImpl.java b/src/main/java/com/boge/modules/dept/service/impl/SysDeptServiceImpl.java new file mode 100644 index 0000000..20fba73 --- /dev/null +++ b/src/main/java/com/boge/modules/dept/service/impl/SysDeptServiceImpl.java @@ -0,0 +1,179 @@ +package com.boge.modules.dept.service.impl; + +import cn.hutool.core.collection.CollectionUtil; +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; +import com.baomidou.mybatisplus.extension.plugins.pagination.Page; +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import com.boge.common.exception.RRException; +import com.boge.common.query.PageQuery; +import com.boge.common.utils.CopyUtil; +import com.boge.common.utils.ShiroUtils; +import com.boge.modules.dept.dao.SysDept; +import com.boge.modules.dept.dao.mapper.SysDeptMapper; +import com.boge.modules.dept.dto.DeptQuery; +import com.boge.modules.dept.dto.DeptTree; +import com.boge.modules.dept.service.ISysDeptService; +import com.boge.modules.dept.vo.DeptVo; +import com.boge.modules.sys.entity.SysUserEntity; +import org.apache.commons.lang3.StringUtils; +import cn.hutool.core.util.IdUtil; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; +import org.springframework.util.CollectionUtils; + +import java.util.*; +import java.util.stream.Collectors; + +/** + *

+ * 部门 服务实现类 + *

+ * + * @author generator + * @since 2022-12-15 + */ +@Service +public class SysDeptServiceImpl extends ServiceImpl implements ISysDeptService { + + @Autowired + private SysDeptMapper sysDeptMapper; + + @Override + public Map buildTree(DeptQuery query) { + List list = this.list(query.build()); + List deptTrees = CopyUtil.copyList(list, DeptTree.class); + return this.buildTree(deptTrees); + } + + @Override + public Map getSuperior(List deptIds) { + return null; + } + + private Map buildTree(List deptDtos) { + List trees= new ArrayList<>(); + Set depts = new LinkedHashSet<>(); + List deptNames = deptDtos.stream().map(DeptTree::getName).collect(Collectors.toList()); + boolean isChild; + for (DeptTree deptDTO : deptDtos) { + isChild = false; + if (deptDTO.getPid() == null) { + trees.add(deptDTO); + } + for (DeptTree it : deptDtos) { + if (it.getPid() != null && deptDTO.getDept_id().equals(it.getPid())) { + isChild = true; + if (deptDTO.getChildren() == null) { + deptDTO.setChildren(new ArrayList<>()); + } + deptDTO.getChildren().add(it); + } + } + if (isChild) { + depts.add(deptDTO); + } else if (deptDTO.getPid() != null && !deptNames.contains(this.getById(deptDTO.getPid()).getName())) { + depts.add(deptDTO); + } + } + Map map = new HashMap<>(2); + map.put("totalElements", deptDtos.size()); + map.put("content", CollectionUtil.isEmpty(trees) ? deptDtos : trees); + return map; + } + + @Override + public Page queryVo(DeptQuery query, PageQuery pageQuery) { + if (query.getPid_is_null() == null){ + if (query.getPid() == null){ + query.setPid_is_null(true); + } + if (StringUtils.isNotEmpty(query.getName()) || query.getIs_used()!=null){ + query.setPid_is_null(null); + } + } + Page page = this.page(pageQuery.build(SysDept.class), query.build()); + page.setRecords(CopyUtil.copyList(page.getRecords(), DeptVo.class)); + if (StringUtils.isNotEmpty(query.getName()) || query.getIs_used()!=null){ + page.getRecords().forEach(a->((DeptVo)a).setHas_children(false) ); + } + return page; + } + + + @Override + public void saveUserDeptRelation(String userId, Collection deptIds) { + if (StringUtils.isEmpty(userId) || CollectionUtils.isEmpty(deptIds)){ + return; + } + sysDeptMapper.saveDeptRelation(userId,deptIds); + } + + @Override + public void delUserDeptRelation(String user) { + sysDeptMapper.delDeptRelation(user); + } + + @Override + @Transactional(rollbackFor = Exception.class) + public void updateDept(SysDept dept) { + if (dept == null ||StringUtils.isEmpty(dept.getDept_id())){ + return; + } + this.updateById(dept); + //删除节点信息 + sysDeptMapper.updateSubCount(dept.getDept_id()); + if (StringUtils.isNotEmpty(dept.getPid())){ + sysDeptMapper.updateSubCount(dept.getPid()); + } + } + + @Override + @Transactional(rollbackFor = Exception.class) + public void delateDept(Set deptIds) { + if (CollectionUtils.isEmpty(deptIds)){ + return; + } + verification(deptIds); + Set depts = new HashSet<>(); + Set pids = new HashSet<>(); + List deptList = sysDeptMapper.selectList(new QueryWrapper().in("dept_id", deptIds)); + for (String deptId : deptIds) { + depts.add(deptId); + String allChild = sysDeptMapper.findAllChild(deptId); + if (StringUtils.isNotEmpty(allChild)){ + String[] split = allChild.split(","); + depts.addAll(Arrays.asList(split)); + } + } + this.remove(new QueryWrapper().in("dept_id", depts)); + deptList.forEach(dept -> { + if (StringUtils.isNotEmpty(dept.getPid())){sysDeptMapper.updateSubCount(dept.getPid());} + }); + + } + + private void verification(Set depeIds) { + if (!CollectionUtils.isEmpty(depeIds)){ + List deptRelation = sysDeptMapper.getDeptRelation(depeIds); + if (!CollectionUtils.isEmpty(deptRelation)){ + throw new RRException("部门为空"); + } + } + } + + @Override + @Transactional(rollbackFor = Exception.class) + public void createDept(SysDept dept) { + SysUserEntity userEntity = ShiroUtils.getUserEntity(); + + dept.setCreate_id(String.valueOf(userEntity.getUserId())); + dept.setCreate_name(userEntity.getUsername()); + dept.setCreate_time(new Date()); + this.save(dept); + // 清理缓存 + if (StringUtils.isNotEmpty(dept.getPid())){ + sysDeptMapper.updateSubCount(dept.getPid()); + } + } +} diff --git a/src/main/java/com/boge/modules/dept/service/impl/SysUserDeptServiceImpl.java b/src/main/java/com/boge/modules/dept/service/impl/SysUserDeptServiceImpl.java new file mode 100644 index 0000000..10d9631 --- /dev/null +++ b/src/main/java/com/boge/modules/dept/service/impl/SysUserDeptServiceImpl.java @@ -0,0 +1,21 @@ +package com.boge.modules.dept.service.impl; + +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; + +import com.boge.modules.dept.dao.SysUserDept; +import com.boge.modules.dept.dao.mapper.SysUserDeptMapper; +import com.boge.modules.dept.service.ISysUserDeptService; +import org.springframework.stereotype.Service; + +/** + *

+ * 部门表 服务实现类 + *

+ * + * @author generator + * @since 2022-12-15 + */ +@Service +public class SysUserDeptServiceImpl extends ServiceImpl implements ISysUserDeptService { + +} diff --git a/src/main/java/com/boge/modules/dept/util/PageUtil.java b/src/main/java/com/boge/modules/dept/util/PageUtil.java new file mode 100644 index 0000000..d97ddd4 --- /dev/null +++ b/src/main/java/com/boge/modules/dept/util/PageUtil.java @@ -0,0 +1,70 @@ +/* + * 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 com.boge.modules.dept.util; + +import org.springframework.data.domain.Page; + +import java.util.ArrayList; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Map; + +/** + * 分页工具 + * @author Zheng Jie + * @date 2018-12-10 + */ +public class PageUtil extends cn.hutool.core.util.PageUtil { + + /** + * List 分页 + */ + public static List toPage(int page, int size , List list) { + int fromIndex = page * size; + int toIndex = page * size + size; + if(fromIndex > list.size()){ + return new ArrayList(); + } else if(toIndex >= list.size()) { + return list.subList(fromIndex,list.size()); + } else { + return list.subList(fromIndex,toIndex); + } + } + + /** + * Page 数据处理,预防redis反序列化报错 + */ + public static Map toPage(Page page) { + Map map = new LinkedHashMap<>(2); + map.put("content",page.getContent()); + map.put("totalElements",page.getTotalElements()); + return map; + } + + + /** + * 自定义分页 + */ + public static Map toPage(Object object, Object totalElements) { + Map map = new LinkedHashMap<>(2); + map.put("content",object); + map.put("totalElements",totalElements); + return map; + } + + + +} diff --git a/src/main/java/com/boge/modules/dept/vo/DeptVo.java b/src/main/java/com/boge/modules/dept/vo/DeptVo.java new file mode 100644 index 0000000..6504b3e --- /dev/null +++ b/src/main/java/com/boge/modules/dept/vo/DeptVo.java @@ -0,0 +1,83 @@ +/* + * 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 com.boge.modules.dept.vo; + + +import com.boge.common.base.BaseDTO; +import lombok.Getter; +import lombok.Setter; + +import javax.validation.constraints.NotBlank; +import javax.validation.constraints.NotNull; +import java.io.Serializable; +import java.util.List; + +/** +* @author Zheng Jie +* @date 2019-03-25 +*/ +@Getter +@Setter +public class DeptVo extends BaseDTO implements Serializable { + + + private String dept_id; + + private String code; + + private String ext_id; + + + + private Integer dept_sort; + + + @NotBlank + + private String name; + @NotBlank + + private String zh_name; + @NotBlank + + private String en_name; + @NotBlank + + private String in_name; + + @NotNull + + private Boolean is_used; + + + private Long pid; + + + private Integer sub_count = 0; + /** + * 前端显示 + */ + private Boolean has_children =Boolean.FALSE; + + private List children; + + public void setSub_count(Integer sub_count) { + this.sub_count = sub_count; + if (sub_count >0){ + this.has_children =Boolean.TRUE; + } + } +} diff --git a/src/main/java/com/boge/modules/dict/controller/SysDictController.java b/src/main/java/com/boge/modules/dict/controller/SysDictController.java new file mode 100644 index 0000000..59f55cd --- /dev/null +++ b/src/main/java/com/boge/modules/dict/controller/SysDictController.java @@ -0,0 +1,102 @@ +package com.boge.modules.dict.controller; + +import com.alibaba.fastjson.JSONObject; +import com.boge.common.base.TableDataInfo; +import com.boge.common.query.PageQuery; +import com.boge.modules.dict.dao.Dict; +import com.boge.modules.dict.dto.DictQuery; +import com.boge.modules.dict.service.ISysDictService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; +import org.springframework.validation.annotation.Validated; +import org.springframework.web.bind.annotation.*; + +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Set; + +/** + *

+ * 字典表 前端控制器 + *

+ * + * @author generator + * @since 2022-12-14 + */ +@RestController +@RequestMapping("/api/dict") +public class SysDictController { + + @Autowired + private ISysDictService dictService; + + + @GetMapping + + public ResponseEntity query(@RequestParam Map whereJson, PageQuery pageable){ + return new ResponseEntity<>(TableDataInfo.build(dictService.queryAll(whereJson,pageable)), HttpStatus.OK); + } + + + @GetMapping(value = "/all") + public ResponseEntity queryAll(){ + return new ResponseEntity<>(dictService.queryAll(),HttpStatus.OK); + } + + @PostMapping + public ResponseEntity create(@RequestBody Dict dict){ + dictService.create(dict); + return new ResponseEntity<>(HttpStatus.CREATED); + } + + @PutMapping + public ResponseEntity updateDict(@Validated @RequestBody Dict dto){ + dictService.updateDict(dto); + return new ResponseEntity<>(HttpStatus.NO_CONTENT); + } + + @DeleteMapping + public ResponseEntity delete(@RequestBody Set ids){ + dictService.deleteBatchByIds(ids); + return new ResponseEntity<>(HttpStatus.OK); + } + + @GetMapping("/dictDetail") + public ResponseEntity queryDetails(@RequestParam Map criteria, PageQuery pageable){ + DictQuery dictQuery = JSONObject.parseObject(JSONObject.toJSONString(criteria), DictQuery.class); + return new ResponseEntity<>(TableDataInfo.build(dictService.queryAllDetail(dictQuery,pageable)),HttpStatus.OK); + } + + + @GetMapping(value = "/dictDetail/map") + public ResponseEntity getDictDetailMaps(@RequestParam String dictName){ + String[] names = dictName.split("[,,]"); + Map> dictMap = new HashMap<>(16); + for (String name : names) { + dictMap.put(name, dictService.getDictByName(name)); + } + return new ResponseEntity<>(dictMap, HttpStatus.OK); + } + + @PostMapping("/dictDetail") + public ResponseEntity createDetail(@RequestBody Dict resources){ + dictService.createDetail(resources); + return new ResponseEntity<>(HttpStatus.CREATED); + } + + @PutMapping("/dictDetail") + public ResponseEntity updateDetail(@RequestBody Dict resources){ + dictService.updateDetail(resources); + return new ResponseEntity<>(HttpStatus.NO_CONTENT); + } + + @DeleteMapping(value = "/dictDetail/{id}") + public ResponseEntity deleteDetail(@PathVariable String id){ + dictService.deleteDetail(id); + return new ResponseEntity<>(HttpStatus.OK); + } + +} + diff --git a/src/main/java/com/boge/modules/dict/dao/Dict.java b/src/main/java/com/boge/modules/dict/dao/Dict.java new file mode 100644 index 0000000..d22d2e5 --- /dev/null +++ b/src/main/java/com/boge/modules/dict/dao/Dict.java @@ -0,0 +1,107 @@ +package com.boge.modules.dict.dao; + +import com.baomidou.mybatisplus.annotation.TableId; +import com.baomidou.mybatisplus.annotation.TableName; +import lombok.Data; +import lombok.EqualsAndHashCode; + +import java.io.Serializable; +import java.math.BigDecimal; + +/** + *

+ * 字典表 + *

+ * + * @author generator + * @since 2022-12-14 + */ +@Data +@EqualsAndHashCode(callSuper = false) +@TableName("sys_dict") +public class Dict implements Serializable { + + private static final long serialVersionUID = 1L; + + /** + * 字典标识 + */ + @TableId(value = "dict_id") + private String dict_id; + + /** + * 编码 + */ + private String code; + + /** + * 名称 + */ + private String name; + + /** + * 字典标签 + */ + private String label; + + /** + * 字典值 + */ + private String value; + + /** + * 排序号 + */ + private BigDecimal dict_sort; + + /** + * 字典类型 + */ + private String dict_type; + + /** + * 参数1 + */ + private String para1; + + /** + * 参数2 + */ + private String para2; + + /** + * 参数3 + */ + private String para3; + + /** + * 创建人 + */ + private String create_id; + + /** + * 创建人 + */ + private String create_name; + + /** + * 创建时间 + */ + private String create_time; + + /** + * 修改人 + */ + private String update_id; + + /** + * 修改人 + */ + private String update_name; + + /** + * 修改时间 + */ + private String update_time; + +} diff --git a/src/main/java/com/boge/modules/dict/dao/mapper/SysDictMapper.java b/src/main/java/com/boge/modules/dict/dao/mapper/SysDictMapper.java new file mode 100644 index 0000000..cf65a53 --- /dev/null +++ b/src/main/java/com/boge/modules/dict/dao/mapper/SysDictMapper.java @@ -0,0 +1,18 @@ +package com.boge.modules.dict.dao.mapper; + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.boge.modules.dict.dao.Dict; +import org.apache.ibatis.annotations.Mapper; + +/** + *

+ * 字典表 Mapper 接口 + *

+ * + * @author generator + * @since 2022-12-14 + */ +@Mapper +public interface SysDictMapper extends BaseMapper { + +} diff --git a/src/main/java/com/boge/modules/dict/dto/DictQuery.java b/src/main/java/com/boge/modules/dict/dto/DictQuery.java new file mode 100644 index 0000000..463ee0f --- /dev/null +++ b/src/main/java/com/boge/modules/dict/dto/DictQuery.java @@ -0,0 +1,19 @@ +package com.boge.modules.dict.dto; + +import com.boge.common.query.BaseQuery; +import com.boge.modules.dict.dao.Dict; +import lombok.Data; + + +/** + * @Author: lyd + * @Description: + * @Date: 2022/12/15 + */ +@Data +public class DictQuery extends BaseQuery { + private String code; + + private String dict_name; + private String dict_id; +} diff --git a/src/main/java/com/boge/modules/dict/service/ISysDictService.java b/src/main/java/com/boge/modules/dict/service/ISysDictService.java new file mode 100644 index 0000000..1992566 --- /dev/null +++ b/src/main/java/com/boge/modules/dict/service/ISysDictService.java @@ -0,0 +1,88 @@ +package com.boge.modules.dict.service; + +import com.baomidou.mybatisplus.core.metadata.IPage; +import com.baomidou.mybatisplus.extension.service.IService; +import com.boge.common.query.PageQuery; +import com.boge.modules.dict.dao.Dict; +import com.boge.modules.dict.dto.DictQuery; + + +import java.util.List; +import java.util.Map; +import java.util.Set; + +/** + *

+ * 字典表 服务类 + *

+ * + * @author generator + * @since 2022-12-14 + */ +public interface ISysDictService extends IService { + + /** + * 分页查找 + * @param whereJson + * @param pageable + * @return + */ + IPage queryAll(Map whereJson, PageQuery pageable); + + /** + * 新增 + * @param dict + */ + void create(Dict dict); + + /** + * 修改字典数据 + * @param dto + */ + void updateDict(Dict dto); + + /** + * 通过id批量删除字典 + * @param ids + */ + void deleteBatchByIds(Set ids); + + /** + * 分页查询获取字典明细 + * @param criteria + * @param pageable + * @return + */ + IPage queryAllDetail(DictQuery criteria, PageQuery pageable); + + /** + * 获取字典明细 + * @param name + * @return + */ + List getDictByName(String name); + + /** + * 添加字典明细 + * @param resources + */ + void createDetail(Dict resources); + + /** + * 更新字典明细 + * @param resources + */ + void updateDetail(Dict resources); + + /** + * 删除字典 + * @param id + */ + void deleteDetail(String id); + + /** + * 查询所有字典信息 + * @return + */ + List queryAll(); +} diff --git a/src/main/java/com/boge/modules/dict/service/impl/SysDictServiceImpl.java b/src/main/java/com/boge/modules/dict/service/impl/SysDictServiceImpl.java new file mode 100644 index 0000000..eccb2a5 --- /dev/null +++ b/src/main/java/com/boge/modules/dict/service/impl/SysDictServiceImpl.java @@ -0,0 +1,202 @@ +package com.boge.modules.dict.service.impl; + +import cn.hutool.core.date.DateUtil; +import cn.hutool.core.util.IdUtil; +import cn.hutool.core.util.ObjectUtil; + +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.boge.common.exception.RRException; +import com.boge.common.query.PageQuery; +import com.boge.common.utils.ShiroUtils; +import com.boge.modules.dict.dao.Dict; +import com.boge.modules.dict.dao.mapper.SysDictMapper; +import com.boge.modules.dict.dto.DictQuery; +import com.boge.modules.dict.service.ISysDictService; +import com.boge.modules.sys.entity.SysUserEntity; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +import java.util.List; +import java.util.Map; +import java.util.Set; + +/** + *

+ * 字典表 服务实现类 + *

+ * + * @author generator + * @since 2022-12-14 + */ +@Service("ISysDictService") +public class SysDictServiceImpl extends ServiceImpl implements ISysDictService { + @Autowired + private SysDictMapper sysDictMapper; + + @Override + public IPage queryAll(Map whereJson, PageQuery page) { + String blurry = null; + if (ObjectUtil.isNotNull(whereJson.get("blurry"))) blurry = whereJson.get("blurry").toString(); + IPage pages = this.page(new Page<>(page.getPage() + 1, page.getSize()), new QueryWrapper() + .select("MAX(dict_id) AS dict_id, code, name") + .lambda() + .like(ObjectUtil.isNotNull(blurry), Dict::getCode, blurry) + .or(ObjectUtil.isNotNull(blurry)) + .like(ObjectUtil.isNotNull(blurry), Dict::getName, blurry) + .orderBy(true, true, Dict::getCode) + .groupBy(Dict::getCode, Dict::getName)); + return pages; + } + + @Override + @Transactional(rollbackFor = Exception.class) + public void create(Dict dict) { + SysUserEntity userEntity = ShiroUtils.getUserEntity(); + String date = DateUtil.now(); + List oldDict = sysDictMapper.selectList(new LambdaQueryWrapper() + .eq(ObjectUtil.isNotNull(dict.getCode()), Dict::getCode, dict.getCode())); + if (ObjectUtil.isNotNull(oldDict)) + throw new RRException("无标签"); + dict.setDict_id(IdUtil.getSnowflake(1, 1).nextIdStr()); + dict.setCreate_id(String.valueOf(userEntity.getUserId())); + dict.setCreate_name(userEntity.getUsername()); + dict.setCreate_time(date); + dict.setUpdate_id(String.valueOf(userEntity.getUserId())); + dict.setUpdate_name(userEntity.getUsername()); + dict.setUpdate_time(date); + sysDictMapper.insert(dict); + } + + @Override + @Transactional(rollbackFor = Exception.class) + public void updateDict(Dict dto) { + SysUserEntity userEntity = ShiroUtils.getUserEntity(); + Dict dict = sysDictMapper.selectById(dto.getDict_id()); + if (ObjectUtil.isNull(dict)) { + throw new RRException("无标签"); + } + List dictList = sysDictMapper.selectList(new LambdaQueryWrapper().eq(Dict::getCode, dto.getCode())); + if (ObjectUtil.isNotNull(dictList) && !dto.getCode().equals(dict.getCode())) + throw new RRException("无标签"); + String currentUserId = String.valueOf(userEntity.getUserId()); + String currentNickName = userEntity.getNickname(); + // 根据code获取所有字典 + List dicts = sysDictMapper.selectList(new LambdaQueryWrapper().eq(Dict::getCode, dict.getCode())); + dicts.forEach(di -> { + di.setCode(dto.getCode()); + di.setName(dto.getName()); + di.setUpdate_id(currentUserId); + di.setUpdate_name(currentNickName); + di.setUpdate_time(DateUtil.now()); + sysDictMapper.updateById(di); + }); + } + + @Override + @Transactional(rollbackFor = Exception.class) + public void deleteBatchByIds(Set ids) { + // 查找code删除 + ids.forEach(id -> { + String code = sysDictMapper.selectById(id).getCode(); + sysDictMapper.delete(new LambdaQueryWrapper().eq(Dict::getCode, code)); + }); + } + + @Override + public IPage queryAllDetail(DictQuery criteria, PageQuery page) { + LambdaQueryWrapper lam = new LambdaQueryWrapper<>(); + lam.eq(Dict::getCode, criteria.getCode()) + .isNotNull(Dict::getLabel) + .ne(Dict::getLabel, "") + .orderBy(true, true, Dict::getDict_sort); + IPage pages = new Page<>(page.getPage() + 1, page.getSize()); + sysDictMapper.selectPage(pages, lam); + return pages; + } + + @Override + public List getDictByName(String name) { + List dictList = sysDictMapper.selectList(new LambdaQueryWrapper().eq(Dict::getCode, name) + .isNotNull(Dict::getLabel) + .ne(Dict::getLabel, "")); + return dictList; + } + + @Override + @Transactional(rollbackFor = Exception.class) + public void createDetail(Dict dict) { + SysUserEntity userEntity = ShiroUtils.getUserEntity(); + // 校验是否已经有标签 + Dict one = sysDictMapper.selectOne(new LambdaQueryWrapper().eq(Dict::getLabel, dict.getLabel()) + .eq(Dict::getCode, dict.getCode())); + if (ObjectUtil.isNotNull(one)) + throw new RRException("无标签"); + // 判断是否有空的值 + List selectOne = sysDictMapper.selectList(new LambdaQueryWrapper().eq(Dict::getCode, dict.getCode())); + Dict dic = selectOne.get(0); + if (ObjectUtil.isNull(dic.getLabel())) { + // 空就赋值 + dic.setCode(dict.getCode()); + dic.setLabel(dict.getLabel()); + dic.setValue(dict.getValue()); + dic.setDict_sort(dict.getDict_sort()); + dic.setDict_type(dict.getDict_type()); + dic.setPara1(dict.getPara1()); + dic.setPara2(dict.getPara2()); + dic.setPara3(dict.getPara3()); + sysDictMapper.updateById(dic); + return; + } + // 插入新的数据 + dict.setDict_id(IdUtil.getSnowflake(1, 1).nextIdStr()); + dict.setCode(dic.getCode()); + dict.setName(dic.getName()); + dict.setCreate_id(String.valueOf(userEntity.getUserId())); + dict.setCreate_name(userEntity.getUsername()); + dict.setCreate_time(DateUtil.now()); + dict.setUpdate_id(String.valueOf(userEntity.getUserId())); + dict.setUpdate_name(userEntity.getUsername()); + dict.setUpdate_time(DateUtil.now()); + sysDictMapper.insert(dict); + } + + @Override + @Transactional(rollbackFor = Exception.class) + public void updateDetail(Dict resources) { + SysUserEntity userEntity = ShiroUtils.getUserEntity(); + Dict dict = sysDictMapper.selectById(resources.getDict_id()); + if (ObjectUtil.isNull(dict)) { + throw new RRException("无标签"); + } + // 校验是否已经有标签 + List dictList = sysDictMapper.selectList(new LambdaQueryWrapper().eq(Dict::getLabel, resources.getLabel()) + .eq(Dict::getCode, resources.getCode())); + if (ObjectUtil.isNotNull(dictList) && !resources.getLabel().equals(dict.getLabel())) { + throw new RRException("无标签"); + } + resources.setUpdate_id(String.valueOf(userEntity.getUserId())); + resources.setUpdate_name(userEntity.getUsername()); + resources.setUpdate_time(DateUtil.now()); + sysDictMapper.updateById(resources); + } + + @Override + @Transactional(rollbackFor = Exception.class) + public void deleteDetail(String id) { + sysDictMapper.deleteById(id); + } + + @Override + public List queryAll() { + return sysDictMapper.selectList(new QueryWrapper() + .select("MAX(dict_id) AS dictId, code, name") + .lambda() + .groupBy(Dict::getCode, Dict::getName)); + } + +} diff --git a/src/main/java/com/boge/modules/flow/controller/FlwDeModelController.java b/src/main/java/com/boge/modules/flow/controller/FlwDeModelController.java index c43f29b..26eab4e 100644 --- a/src/main/java/com/boge/modules/flow/controller/FlwDeModelController.java +++ b/src/main/java/com/boge/modules/flow/controller/FlwDeModelController.java @@ -24,7 +24,7 @@ import com.boge.common.utils.R; /** - * + * * * @author boge * @email dengpbs@163.com diff --git a/src/main/java/com/boge/modules/flow/controller/FlwDeployController.java b/src/main/java/com/boge/modules/flow/controller/FlwDeployController.java index 370275a..b67f900 100644 --- a/src/main/java/com/boge/modules/flow/controller/FlwDeployController.java +++ b/src/main/java/com/boge/modules/flow/controller/FlwDeployController.java @@ -63,7 +63,7 @@ public class FlwDeployController { /** - * 根据Id查询流程定义信息 + * 发起流程 * @param id * @return */ diff --git a/src/main/java/com/boge/modules/flow/controller/FlwInstanceController.java b/src/main/java/com/boge/modules/flow/controller/FlwInstanceController.java index 8e9389c..45a0448 100644 --- a/src/main/java/com/boge/modules/flow/controller/FlwInstanceController.java +++ b/src/main/java/com/boge/modules/flow/controller/FlwInstanceController.java @@ -55,7 +55,7 @@ public class FlwInstanceController { } /** - * 我的发起 + * 我的完成 * @param params * @return */ diff --git a/src/main/resources/mapper/dept/SysDeptMapper.xml b/src/main/resources/mapper/dept/SysDeptMapper.xml new file mode 100644 index 0000000..c000a91 --- /dev/null +++ b/src/main/resources/mapper/dept/SysDeptMapper.xml @@ -0,0 +1,40 @@ + + + + + + replace into sys_user_dept values + + (#{user},#{dept}) + + + + delete from sys_user_dept where user_id = #{user} + + + + update sys_dept set sub_count = + (select m.count from (select count(*) count from sys_dept where pid = #{pid}) as m) + where dept_id = #{pid} + + + + diff --git a/src/main/resources/mapper/dept/SysUserDeptMapper.xml b/src/main/resources/mapper/dept/SysUserDeptMapper.xml new file mode 100644 index 0000000..ef53433 --- /dev/null +++ b/src/main/resources/mapper/dept/SysUserDeptMapper.xml @@ -0,0 +1,5 @@ + + + + + diff --git a/src/main/resources/mapper/dict/SysDictMapper.xml b/src/main/resources/mapper/dict/SysDictMapper.xml new file mode 100644 index 0000000..b7c97b1 --- /dev/null +++ b/src/main/resources/mapper/dict/SysDictMapper.xml @@ -0,0 +1,5 @@ + + + + +