diff --git a/esua-epdc/epdc-module/epdc-custom/epdc-custom-client/src/main/java/com/elink/esua/epdc/dto/CategoryOption.java b/esua-epdc/epdc-module/epdc-custom/epdc-custom-client/src/main/java/com/elink/esua/epdc/dto/CategoryOption.java new file mode 100644 index 00000000..05760b40 --- /dev/null +++ b/esua-epdc/epdc-module/epdc-custom/epdc-custom-client/src/main/java/com/elink/esua/epdc/dto/CategoryOption.java @@ -0,0 +1,15 @@ +package com.elink.esua.epdc.dto; + +import lombok.Data; + +import java.util.List; + +/** + * @Description 事件类别树 + * @Author yinzuomei + * @Date 2019/12/3 18:03 + */ +@Data +public class CategoryOption { + private List options; +} diff --git a/esua-epdc/epdc-module/epdc-custom/epdc-custom-client/src/main/java/com/elink/esua/epdc/dto/ModuleCategoryDTO.java b/esua-epdc/epdc-module/epdc-custom/epdc-custom-client/src/main/java/com/elink/esua/epdc/dto/ModuleCategoryDTO.java new file mode 100644 index 00000000..3d03bf7c --- /dev/null +++ b/esua-epdc/epdc-module/epdc-custom/epdc-custom-client/src/main/java/com/elink/esua/epdc/dto/ModuleCategoryDTO.java @@ -0,0 +1,115 @@ +/** + * Copyright 2018 人人开源 https://www.renren.io + *

+ * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + *

+ * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + *

+ * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package com.elink.esua.epdc.dto; + +import com.elink.esua.epdc.commons.tools.utils.TreeNode; +import com.elink.esua.epdc.commons.tools.validator.group.AddGroup; +import com.elink.esua.epdc.commons.tools.validator.group.DefaultGroup; +import com.elink.esua.epdc.commons.tools.validator.group.UpdateGroup; +import lombok.Data; + +import javax.validation.constraints.Min; +import javax.validation.constraints.NotBlank; +import javax.validation.constraints.NotNull; +import javax.validation.constraints.Null; +import java.io.Serializable; + + +/** + * 模块类别表 模块类别表 + * + * @author qu qu@elink-cn.com + * @since v1.0.0 2020-10-28 + */ +@Data +public class ModuleCategoryDTO extends TreeNode implements Serializable { + + private static final long serialVersionUID = 1L; + + /** + * 主键 + */ + @Null(message = "{id.null}", groups = AddGroup.class) + @NotNull(message = "{id.require}", groups = UpdateGroup.class) + private String id; + + /** + * 上级ID + */ + @NotNull(message = "{sysdept.pid.require}", groups = DefaultGroup.class) + private String pid; + + /** + * 所有上级ID,逗号分隔 + */ + private String pids; + + /** + * 模块类别编码 + */ + private String categoryCode; + + /** + * 模块类别名称 + */ + @NotBlank(message = "{sysdept.name.require}", groups = DefaultGroup.class) + private String categoryName; + + /** + * 模块类别 + */ + private String categoryType; + + /** + * 模块类别图片 + */ + private String imgUrl; + + /** + * 模块样式 + */ + private String moduleStyle; + + /** + * 是否有BANNER 0-否,1-是 + */ + private String bannerFlag; + + /** + * 备注 + */ + private String remark; + + /** + * 排序 + */ + @Min(value = 0, message = "{sort.number}", groups = DefaultGroup.class) + private Integer sort; + + /** + * 启用标识 0-否,1-是 + */ + private String enableFlag; + + private String parentName; + + private String value; + + private String label; + +} \ No newline at end of file diff --git a/esua-epdc/epdc-module/epdc-custom/epdc-custom-client/src/main/java/com/elink/esua/epdc/dto/ModuleCategoryTreeDTO.java b/esua-epdc/epdc-module/epdc-custom/epdc-custom-client/src/main/java/com/elink/esua/epdc/dto/ModuleCategoryTreeDTO.java new file mode 100644 index 00000000..bbf665e2 --- /dev/null +++ b/esua-epdc/epdc-module/epdc-custom/epdc-custom-client/src/main/java/com/elink/esua/epdc/dto/ModuleCategoryTreeDTO.java @@ -0,0 +1,37 @@ +package com.elink.esua.epdc.dto; + + +import lombok.Data; + +import java.io.Serializable; +import java.util.List; + +/** + * @Description + * @Author songyunpeng + * @Date 2019/12/3 14:34 + */ +@Data +public class ModuleCategoryTreeDTO implements Serializable { + + private static final long serialVersionUID = 8751086975269527708L; + /** + * id + */ + private String id; + /** + * 上级分类ID + */ + private String pid; + + /** + * 分类名称 + */ + private String categoryName; + + private String value; + + private String label; + + private List children; +} diff --git a/esua-epdc/epdc-module/epdc-custom/epdc-custom-server/src/main/java/com/elink/esua/epdc/modules/moduleCategory/controller/ModuleCategoryController.java b/esua-epdc/epdc-module/epdc-custom/epdc-custom-server/src/main/java/com/elink/esua/epdc/modules/moduleCategory/controller/ModuleCategoryController.java new file mode 100644 index 00000000..1cd8f36f --- /dev/null +++ b/esua-epdc/epdc-module/epdc-custom/epdc-custom-server/src/main/java/com/elink/esua/epdc/modules/moduleCategory/controller/ModuleCategoryController.java @@ -0,0 +1,120 @@ +/** + * Copyright 2018 人人开源 https://www.renren.io + *

+ * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + *

+ * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + *

+ * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package com.elink.esua.epdc.modules.moduleCategory.controller; + +import com.elink.esua.epdc.commons.tools.page.PageData; +import com.elink.esua.epdc.commons.tools.utils.ExcelUtils; +import com.elink.esua.epdc.commons.tools.utils.Result; +import com.elink.esua.epdc.commons.tools.validator.AssertUtils; +import com.elink.esua.epdc.commons.tools.validator.ValidatorUtils; +import com.elink.esua.epdc.commons.tools.validator.group.AddGroup; +import com.elink.esua.epdc.commons.tools.validator.group.DefaultGroup; +import com.elink.esua.epdc.commons.tools.validator.group.UpdateGroup; +import com.elink.esua.epdc.dto.CategoryOption; +import com.elink.esua.epdc.dto.ModuleCategoryDTO; +import com.elink.esua.epdc.modules.moduleCategory.excel.ModuleCategoryExcel; +import com.elink.esua.epdc.modules.moduleCategory.service.ModuleCategoryService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.*; + +import javax.servlet.http.HttpServletResponse; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + + +/** + * 模块类别表 模块类别表 + * + * @author qu qu@elink-cn.com + * @since v1.0.0 2020-10-28 + */ +@RestController +@RequestMapping("modulecategory") +public class ModuleCategoryController { + + @Autowired + private ModuleCategoryService moduleCategoryService; + + @GetMapping("page") + public Result> page(@RequestParam Map params){ + PageData page = moduleCategoryService.page(params); + return new Result>().ok(page); + } + /** + * @Description 前端查询 + * @Author songyunpeng + * @Date 2020/10/28 + * @Param [] + * @return com.elink.esua.epdc.commons.tools.utils.Result> + **/ + @GetMapping("list") + public Result> list(){ + List list = moduleCategoryService.list(new HashMap<>(1)); + return new Result>().ok(list); + } + + @GetMapping("{id}") + public Result get(@PathVariable("id") String id){ + ModuleCategoryDTO data = moduleCategoryService.get(id); + return new Result().ok(data); + } + + @PostMapping + public Result save(@RequestBody ModuleCategoryDTO dto){ + //效验数据 + ValidatorUtils.validateEntity(dto, AddGroup.class, DefaultGroup.class); + moduleCategoryService.save(dto); + return new Result(); + } + + @PutMapping + public Result update(@RequestBody ModuleCategoryDTO dto){ + //效验数据 + ValidatorUtils.validateEntity(dto, UpdateGroup.class, DefaultGroup.class); + moduleCategoryService.update(dto); + return new Result(); + } + + @DeleteMapping + public Result delete(@RequestBody String[] ids){ + //效验数据 + AssertUtils.isArrayEmpty(ids, "id"); + moduleCategoryService.delete(ids); + return new Result(); + } + + @GetMapping("export") + public void export(@RequestParam Map params, HttpServletResponse response) throws Exception { + List list = moduleCategoryService.list(params); + ExcelUtils.exportExcelToTarget(response, null, list, ModuleCategoryExcel.class); + } + + + /** + * @param + * @return com.elink.esua.epdc.commons.tools.utils.Result + * @Author songyunpeng + * @Description 查询事件类别树, 供下拉框调用 + * @Date 2019/12/3 18:07 + **/ + @GetMapping("getCategoryTree") + public Result getCategoryTree() { + return moduleCategoryService.getCategoryTree(); + } +} \ No newline at end of file diff --git a/esua-epdc/epdc-module/epdc-custom/epdc-custom-server/src/main/java/com/elink/esua/epdc/modules/moduleCategory/dao/ModuleCategoryDao.java b/esua-epdc/epdc-module/epdc-custom/epdc-custom-server/src/main/java/com/elink/esua/epdc/modules/moduleCategory/dao/ModuleCategoryDao.java new file mode 100644 index 00000000..a3f7b66b --- /dev/null +++ b/esua-epdc/epdc-module/epdc-custom/epdc-custom-server/src/main/java/com/elink/esua/epdc/modules/moduleCategory/dao/ModuleCategoryDao.java @@ -0,0 +1,40 @@ +/** + * Copyright 2018 人人开源 https://www.renren.io + *

+ * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + *

+ * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + *

+ * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package com.elink.esua.epdc.modules.moduleCategory.dao; + +import com.elink.esua.epdc.commons.mybatis.dao.BaseDao; +import com.elink.esua.epdc.dto.ModuleCategoryTreeDTO; +import com.elink.esua.epdc.modules.moduleCategory.entity.ModuleCategoryEntity; +import org.apache.ibatis.annotations.Mapper; + +import java.util.List; +import java.util.Map; + +/** + * 模块类别表 模块类别表 + * + * @author qu qu@elink-cn.com + * @since v1.0.0 2020-10-28 + */ +@Mapper +public interface ModuleCategoryDao extends BaseDao { + + List getList(Map params); + + List selectListCategoryTreeDTO(); +} \ No newline at end of file diff --git a/esua-epdc/epdc-module/epdc-custom/epdc-custom-server/src/main/java/com/elink/esua/epdc/modules/moduleCategory/entity/ModuleCategoryEntity.java b/esua-epdc/epdc-module/epdc-custom/epdc-custom-server/src/main/java/com/elink/esua/epdc/modules/moduleCategory/entity/ModuleCategoryEntity.java new file mode 100644 index 00000000..cb1e80ef --- /dev/null +++ b/esua-epdc/epdc-module/epdc-custom/epdc-custom-server/src/main/java/com/elink/esua/epdc/modules/moduleCategory/entity/ModuleCategoryEntity.java @@ -0,0 +1,96 @@ +/** + * Copyright 2018 人人开源 https://www.renren.io + *

+ * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + *

+ * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + *

+ * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package com.elink.esua.epdc.modules.moduleCategory.entity; + +import com.baomidou.mybatisplus.annotation.TableName; + +import com.elink.esua.epdc.commons.mybatis.entity.BaseEpdcEntity; +import lombok.Data; +import lombok.EqualsAndHashCode; + +import java.util.Date; + +/** + * 模块类别表 模块类别表 + * + * @author qu qu@elink-cn.com + * @since v1.0.0 2020-10-28 + */ +@Data +@EqualsAndHashCode(callSuper=false) +@TableName("epdc_module_category") +public class ModuleCategoryEntity extends BaseEpdcEntity { + + private static final long serialVersionUID = 1L; + + /** + * 上级ID + */ + private String pid; + + /** + * 所有上级ID,逗号分隔 + */ + private String pids; + + /** + * 模块类别编码 + */ + private String categoryCode; + + /** + * 模块类别名称 + */ + private String categoryName; + + /** + * 模块类别 + */ + private String categoryType; + + /** + * 模块类别图片 + */ + private String imgUrl; + + /** + * 模块样式 + */ + private String moduleStyle; + + /** + * 是否有BANNER 0-否,1-是 + */ + private String bannerFlag; + + /** + * 备注 + */ + private String remark; + + /** + * 排序 + */ + private Integer sort; + + /** + * 启用标识 0-否,1-是 + */ + private String enableFlag; + +} \ No newline at end of file diff --git a/esua-epdc/epdc-module/epdc-custom/epdc-custom-server/src/main/java/com/elink/esua/epdc/modules/moduleCategory/excel/ModuleCategoryExcel.java b/esua-epdc/epdc-module/epdc-custom/epdc-custom-server/src/main/java/com/elink/esua/epdc/modules/moduleCategory/excel/ModuleCategoryExcel.java new file mode 100644 index 00000000..2f821d22 --- /dev/null +++ b/esua-epdc/epdc-module/epdc-custom/epdc-custom-server/src/main/java/com/elink/esua/epdc/modules/moduleCategory/excel/ModuleCategoryExcel.java @@ -0,0 +1,89 @@ +/** + * Copyright 2018 人人开源 https://www.renren.io + *

+ * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + *

+ * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + *

+ * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package com.elink.esua.epdc.modules.moduleCategory.excel; + +import cn.afterturn.easypoi.excel.annotation.Excel; +import lombok.Data; + +import java.util.Date; + +/** + * 模块类别表 模块类别表 + * + * @author qu qu@elink-cn.com + * @since v1.0.0 2020-10-28 + */ +@Data +public class ModuleCategoryExcel { + + @Excel(name = "主键") + private String id; + + @Excel(name = "上级ID") + private String pid; + + @Excel(name = "所有上级ID,逗号分隔") + private String pids; + + @Excel(name = "模块类别编码") + private String categoryCode; + + @Excel(name = "模块类别名称") + private String categoryName; + + @Excel(name = "模块类别") + private String categoryType; + + @Excel(name = "模块类别图片") + private String imgUrl; + + @Excel(name = "模块样式") + private String moduleStyle; + + @Excel(name = "是否有BANNER 0-否,1-是") + private String bannerFlag; + + @Excel(name = "备注") + private String remark; + + @Excel(name = "排序") + private Integer sort; + + @Excel(name = "启用标识 0-否,1-是") + private String enableFlag; + + @Excel(name = "删除标识 0-否,1-是") + private String delFlag; + + @Excel(name = "乐观锁") + private Integer revision; + + @Excel(name = "创建人") + private String createdBy; + + @Excel(name = "创建时间") + private Date createdTime; + + @Excel(name = "更新人") + private String updatedBy; + + @Excel(name = "更新时间") + private Date updatedTime; + + +} \ No newline at end of file diff --git a/esua-epdc/epdc-module/epdc-custom/epdc-custom-server/src/main/java/com/elink/esua/epdc/modules/moduleCategory/redis/ModuleCategoryRedis.java b/esua-epdc/epdc-module/epdc-custom/epdc-custom-server/src/main/java/com/elink/esua/epdc/modules/moduleCategory/redis/ModuleCategoryRedis.java new file mode 100644 index 00000000..5a1fd232 --- /dev/null +++ b/esua-epdc/epdc-module/epdc-custom/epdc-custom-server/src/main/java/com/elink/esua/epdc/modules/moduleCategory/redis/ModuleCategoryRedis.java @@ -0,0 +1,47 @@ +/** + * Copyright 2018 人人开源 https://www.renren.io + *

+ * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + *

+ * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + *

+ * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package com.elink.esua.epdc.modules.moduleCategory.redis; + +import com.elink.esua.epdc.commons.tools.redis.RedisUtils; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; + +/** + * 模块类别表 模块类别表 + * + * @author qu qu@elink-cn.com + * @since v1.0.0 2020-10-28 + */ +@Component +public class ModuleCategoryRedis { + @Autowired + private RedisUtils redisUtils; + + public void delete(Object[] ids) { + + } + + public void set(){ + + } + + public String get(String id){ + return null; + } + +} \ No newline at end of file diff --git a/esua-epdc/epdc-module/epdc-custom/epdc-custom-server/src/main/java/com/elink/esua/epdc/modules/moduleCategory/service/ModuleCategoryService.java b/esua-epdc/epdc-module/epdc-custom/epdc-custom-server/src/main/java/com/elink/esua/epdc/modules/moduleCategory/service/ModuleCategoryService.java new file mode 100644 index 00000000..89b75f73 --- /dev/null +++ b/esua-epdc/epdc-module/epdc-custom/epdc-custom-server/src/main/java/com/elink/esua/epdc/modules/moduleCategory/service/ModuleCategoryService.java @@ -0,0 +1,110 @@ +/** + * Copyright 2018 人人开源 https://www.renren.io + *

+ * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + *

+ * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + *

+ * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package com.elink.esua.epdc.modules.moduleCategory.service; + +import com.elink.esua.epdc.commons.mybatis.service.BaseService; +import com.elink.esua.epdc.commons.tools.page.PageData; +import com.elink.esua.epdc.commons.tools.utils.Result; +import com.elink.esua.epdc.dto.CategoryOption; +import com.elink.esua.epdc.dto.ModuleCategoryDTO; +import com.elink.esua.epdc.modules.moduleCategory.entity.ModuleCategoryEntity; + +import java.util.List; +import java.util.Map; + +/** + * 模块类别表 模块类别表 + * + * @author qu qu@elink-cn.com + * @since v1.0.0 2020-10-28 + */ +public interface ModuleCategoryService extends BaseService { + + /** + * 默认分页 + * + * @param params + * @return PageData + * @author generator + * @date 2020-10-28 + */ + PageData page(Map params); + + /** + * 默认查询 + * + * @param params + * @return java.util.List + * @author generator + * @date 2020-10-28 + */ + List list(Map params); + + /** + * 单条查询 + * + * @param id + * @return ModuleCategoryDTO + * @author generator + * @date 2020-10-28 + */ + ModuleCategoryDTO get(String id); + + /** + * 默认保存 + * + * @param dto + * @return void + * @author generator + * @date 2020-10-28 + */ + void save(ModuleCategoryDTO dto); + + /*** + * 校验编码是否重复 + */ + Integer getCodeCount(ModuleCategoryDTO dto); + + /** + * 默认更新 + * + * @param dto + * @return void + * @author generator + * @date 2020-10-28 + */ + void update(ModuleCategoryDTO dto); + + /** + * 批量删除 + * + * @param ids + * @return void + * @author generator + * @date 2020-10-28 + */ + void delete(String[] ids); + /** + * @Description 查询事件类别树, 供下拉框调用 + * @Author songyunpeng + * @Date 2020/10/28 + * @Param [] + * @return com.elink.esua.epdc.commons.tools.utils.Result + **/ + Result getCategoryTree(); +} \ No newline at end of file diff --git a/esua-epdc/epdc-module/epdc-custom/epdc-custom-server/src/main/java/com/elink/esua/epdc/modules/moduleCategory/service/impl/ModuleCategoryServiceImpl.java b/esua-epdc/epdc-module/epdc-custom/epdc-custom-server/src/main/java/com/elink/esua/epdc/modules/moduleCategory/service/impl/ModuleCategoryServiceImpl.java new file mode 100644 index 00000000..ea91c2ca --- /dev/null +++ b/esua-epdc/epdc-module/epdc-custom/epdc-custom-server/src/main/java/com/elink/esua/epdc/modules/moduleCategory/service/impl/ModuleCategoryServiceImpl.java @@ -0,0 +1,296 @@ +/** + * Copyright 2018 人人开源 https://www.renren.io + *

+ * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + *

+ * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + *

+ * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package com.elink.esua.epdc.modules.moduleCategory.service.impl; + +import com.alibaba.fastjson.JSONArray; +import com.alibaba.fastjson.JSONObject; +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; +import com.baomidou.mybatisplus.core.metadata.IPage; +import com.elink.esua.epdc.commons.mybatis.service.impl.BaseServiceImpl; +import com.elink.esua.epdc.commons.tools.constant.Constant; +import com.elink.esua.epdc.commons.tools.constant.FieldConstant; +import com.elink.esua.epdc.commons.tools.exception.ErrorCode; +import com.elink.esua.epdc.commons.tools.exception.RenException; +import com.elink.esua.epdc.commons.tools.page.PageData; +import com.elink.esua.epdc.commons.tools.utils.ConvertUtils; +import com.elink.esua.epdc.commons.tools.utils.Result; +import com.elink.esua.epdc.commons.tools.utils.TreeUtils; +import com.elink.esua.epdc.dto.CategoryOption; +import com.elink.esua.epdc.dto.ModuleCategoryDTO; +import com.elink.esua.epdc.dto.ModuleCategoryTreeDTO; +import com.elink.esua.epdc.modules.moduleCategory.dao.ModuleCategoryDao; +import com.elink.esua.epdc.modules.moduleCategory.entity.ModuleCategoryEntity; +import com.elink.esua.epdc.modules.moduleCategory.redis.ModuleCategoryRedis; +import com.elink.esua.epdc.modules.moduleCategory.service.ModuleCategoryService; +import com.google.common.collect.Lists; +import org.apache.commons.lang3.StringUtils; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +import java.util.*; + +/** + * 模块类别表 模块类别表 + * + * @author qu qu@elink-cn.com + * @since v1.0.0 2020-10-28 + */ +@Service +public class ModuleCategoryServiceImpl extends BaseServiceImpl implements ModuleCategoryService { + + @Autowired + private ModuleCategoryRedis moduleCategoryRedis; + + @Override + public PageData page(Map params) { + IPage page = baseDao.selectPage( + getPage(params, FieldConstant.CREATED_TIME, false), + getWrapper(params) + ); + return getPageData(page, ModuleCategoryDTO.class); + } + + @Override + public List list(Map params) { + List entityList = baseDao.getList(params); + + List dtoList = ConvertUtils.sourceToTarget(entityList, ModuleCategoryDTO.class); + + return TreeUtils.build(dtoList); + } + + private QueryWrapper getWrapper(Map params){ + String id = (String)params.get(FieldConstant.ID_HUMP); + + QueryWrapper wrapper = new QueryWrapper<>(); + wrapper.eq(StringUtils.isNotBlank(id), FieldConstant.ID, id); + + return wrapper; + } + + @Override + public ModuleCategoryDTO get(String id) { + ModuleCategoryEntity entity = baseDao.selectById(id); + return ConvertUtils.sourceToTarget(entity, ModuleCategoryDTO.class); + } + + @Override + @Transactional(rollbackFor = Exception.class) + public void save(ModuleCategoryDTO dto) { + String categoryCode = dto.getCategoryCode(); + if (StringUtils.isNotBlank(categoryCode)) { + if (getCodeCount(dto) > 0) { + throw new RenException("您输入的编码已存在"); + } + } + ModuleCategoryEntity entity = ConvertUtils.sourceToTarget(dto, ModuleCategoryEntity.class); + List list = getPidListByPid(entity.getPid()); + if (list.size() == 0) { + entity.setPids("0"); + } else { + String pids = ""; + for (int i = 0; i < list.size(); i++) { + if (i == list.size() - 1) { + pids = pids + list.get(i).getId(); + } else { + pids = pids + list.get(i).getId() + ","; + } + } + entity.setPids(pids); + } + insert(entity); + } + /** + * 获取所有上级分类 + * + * @param pid 上级ID + */ + private List getPidListByPid(String pid) { + //顶级部门,无上级部门 + if (Constant.CATEGORY_ROOT.equals(pid)) { + return new ArrayList<>(); + } + + //所有的分类列表 + QueryWrapper wrapper = new QueryWrapper<>(); + List categoryEntityList = baseDao.selectList(wrapper); + + //list转map + Map map = new HashMap<>(categoryEntityList.size()); + for (ModuleCategoryEntity entity : categoryEntityList) { + map.put(entity.getId(), entity); + } + + //递归查询所有上级分类列表 + List pCategoryEntityList = new ArrayList<>(); + + getPidTree(pid, map, pCategoryEntityList); + + return pCategoryEntityList; + } + private void getPidTree(String pid, Map map, List pCategoryEntityList) { + //顶级,无上级 + if (Constant.CATEGORY_ROOT.equals(pid)) { + return; + } + //上级存在 + ModuleCategoryEntity parent = map.get(pid); + if (parent != null) { + getPidTree(parent.getPid(), map, pCategoryEntityList); + } + + pCategoryEntityList.add(parent); + } + @Override + public Integer getCodeCount(ModuleCategoryDTO dto) { + QueryWrapper wrapper = new QueryWrapper<>(); + wrapper.eq("category_code", dto.getCategoryCode()); + String id = dto.getId(); + wrapper.ne(id != null, "id", dto.getId()); + wrapper.eq("del_flag", "0"); + return baseDao.selectCount(wrapper); + } + + @Override + @Transactional(rollbackFor = Exception.class) + public void update(ModuleCategoryDTO dto) { + String categoryCode = dto.getCategoryCode(); + if (StringUtils.isNotBlank(categoryCode)) { + if (getCodeCount(dto) > 0) { + throw new RenException("您输入的编码已存在"); + } + } + ModuleCategoryEntity entity = ConvertUtils.sourceToTarget(dto, ModuleCategoryEntity.class); + //上级部门不能为自身 + if (entity.getId().equals(entity.getPid())) { + throw new RenException(ErrorCode.SUPERIOR_DEPT_ERROR); + } + List list = getPidListByPid(entity.getPid()); + if (list.size() == 0) { + entity.setPids("0"); + } else { + String pids = ""; + for (int i = 0; i < list.size(); i++) { + if (i == list.size() - 1) { + pids = pids + list.get(i).getId(); + } else { + pids = pids + list.get(i).getId() + ","; + } + } + entity.setPids(pids); + } + updateById(entity); + } + + @Override + @Transactional(rollbackFor = Exception.class) + public void delete(String[] ids) { + // 逻辑删除(@TableLogic 注解) + baseDao.deleteBatchIds(Arrays.asList(ids)); + } + + @Override + public Result getCategoryTree() { + return new Result().ok(this.packageCategoryOption()); + } + /** + * @Description 组装信息 + * @Author songyunpeng + * @Date 2020/10/28 + * @Param [] + * @return void + **/ + private CategoryOption packageCategoryOption() { + List dtoList = baseDao.selectListCategoryTreeDTO(); + JSONObject node; + JSONArray headNodes = new JSONArray(); + for (ModuleCategoryTreeDTO categoryTreeDto : dtoList) { + + if ("0".equals(categoryTreeDto.getPid())) { + node = new JSONObject(); + node.put("value", categoryTreeDto.getId()); + node.put("label", categoryTreeDto.getCategoryName()); + headNodes.add(node); + } + } + + // 用于存放所有父级节点 + JSONArray parent; + // 用于存放所有子级节点 + JSONArray allChildren = new JSONArray(); + JSONArray children; + // 用于存放单个子级节点 + JSONObject childNode; + + parent = headNodes; + // 存放其余未处理的类别(节点) + List others = this.getOtherCategory(dtoList, parent); + + while (!others.isEmpty()) { + for (int i = 0; i < parent.size(); i++) { + node = parent.getJSONObject(i); + children = new JSONArray(); + for (ModuleCategoryTreeDTO categoryTreeDto : others) { + if (categoryTreeDto.getPid().equals(node.get("value"))) { + childNode = new JSONObject(); + childNode.put("value", categoryTreeDto.getId()); + childNode.put("label", categoryTreeDto.getCategoryName()); + + children.add(childNode); + allChildren.add(childNode); + } + } + if (!children.isEmpty()) { + node.put("children", children); + } + } + parent = allChildren; + + others = this.getOtherCategory(others, parent); + + } +// JSONObject treeNodes = new JSONObject(); +// treeNodes.put("options", headNodes); +// logger.info(treeNodes.toJSONString()); + //存放到redis中 + List cache = Lists.newArrayList(); + cache.add(headNodes); + CategoryOption option = new CategoryOption(); + option.setOptions(cache.get(0)); + return option; + } + + private List getOtherCategory(List dtoList, JSONArray parent) { + List already = Lists.newArrayList(); + for (int i = 0; i < parent.size(); i++) { + already.add((String) parent.getJSONObject(i).get("value")); + } + + List others = Lists.newArrayList(); + + for (ModuleCategoryTreeDTO categoryTreeDto : dtoList) { + String categoryTreeDtoId = categoryTreeDto.getId(); + if (!already.contains(categoryTreeDtoId)) { + others.add(categoryTreeDto); + } + } + return others; + } + +} \ No newline at end of file diff --git a/esua-epdc/epdc-module/epdc-custom/epdc-custom-server/src/main/resources/mapper/moduleCategory/ModuleCategoryDao.xml b/esua-epdc/epdc-module/epdc-custom/epdc-custom-server/src/main/resources/mapper/moduleCategory/ModuleCategoryDao.xml new file mode 100644 index 00000000..2f456d17 --- /dev/null +++ b/esua-epdc/epdc-module/epdc-custom/epdc-custom-server/src/main/resources/mapper/moduleCategory/ModuleCategoryDao.xml @@ -0,0 +1,47 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file