Browse Source

模板分类初始化提交

feature/syp_points
songyunpeng 5 years ago
parent
commit
f84b21cffd
  1. 15
      esua-epdc/epdc-module/epdc-custom/epdc-custom-client/src/main/java/com/elink/esua/epdc/dto/CategoryOption.java
  2. 115
      esua-epdc/epdc-module/epdc-custom/epdc-custom-client/src/main/java/com/elink/esua/epdc/dto/ModuleCategoryDTO.java
  3. 37
      esua-epdc/epdc-module/epdc-custom/epdc-custom-client/src/main/java/com/elink/esua/epdc/dto/ModuleCategoryTreeDTO.java
  4. 120
      esua-epdc/epdc-module/epdc-custom/epdc-custom-server/src/main/java/com/elink/esua/epdc/modules/moduleCategory/controller/ModuleCategoryController.java
  5. 40
      esua-epdc/epdc-module/epdc-custom/epdc-custom-server/src/main/java/com/elink/esua/epdc/modules/moduleCategory/dao/ModuleCategoryDao.java
  6. 96
      esua-epdc/epdc-module/epdc-custom/epdc-custom-server/src/main/java/com/elink/esua/epdc/modules/moduleCategory/entity/ModuleCategoryEntity.java
  7. 89
      esua-epdc/epdc-module/epdc-custom/epdc-custom-server/src/main/java/com/elink/esua/epdc/modules/moduleCategory/excel/ModuleCategoryExcel.java
  8. 47
      esua-epdc/epdc-module/epdc-custom/epdc-custom-server/src/main/java/com/elink/esua/epdc/modules/moduleCategory/redis/ModuleCategoryRedis.java
  9. 110
      esua-epdc/epdc-module/epdc-custom/epdc-custom-server/src/main/java/com/elink/esua/epdc/modules/moduleCategory/service/ModuleCategoryService.java
  10. 296
      esua-epdc/epdc-module/epdc-custom/epdc-custom-server/src/main/java/com/elink/esua/epdc/modules/moduleCategory/service/impl/ModuleCategoryServiceImpl.java
  11. 47
      esua-epdc/epdc-module/epdc-custom/epdc-custom-server/src/main/resources/mapper/moduleCategory/ModuleCategoryDao.xml

15
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<T> {
private List<T> options;
}

115
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
* <p>
* 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.
* <p>
* 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.
* <p>
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
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;
}

37
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<ModuleCategoryTreeDTO> children;
}

120
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
* <p>
* 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.
* <p>
* 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.
* <p>
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
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<PageData<ModuleCategoryDTO>> page(@RequestParam Map<String, Object> params){
PageData<ModuleCategoryDTO> page = moduleCategoryService.page(params);
return new Result<PageData<ModuleCategoryDTO>>().ok(page);
}
/**
* @Description 前端查询
* @Author songyunpeng
* @Date 2020/10/28
* @Param []
* @return com.elink.esua.epdc.commons.tools.utils.Result<java.util.List<com.elink.esua.epdc.dto.ModuleCategoryDTO>>
**/
@GetMapping("list")
public Result<List<ModuleCategoryDTO>> list(){
List<ModuleCategoryDTO> list = moduleCategoryService.list(new HashMap<>(1));
return new Result<List<ModuleCategoryDTO>>().ok(list);
}
@GetMapping("{id}")
public Result<ModuleCategoryDTO> get(@PathVariable("id") String id){
ModuleCategoryDTO data = moduleCategoryService.get(id);
return new Result<ModuleCategoryDTO>().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<String, Object> params, HttpServletResponse response) throws Exception {
List<ModuleCategoryDTO> list = moduleCategoryService.list(params);
ExcelUtils.exportExcelToTarget(response, null, list, ModuleCategoryExcel.class);
}
/**
* @param
* @return com.elink.esua.epdc.commons.tools.utils.Result<com.elink.esua.epdc.dto.category.CategoryOption>
* @Author songyunpeng
* @Description 查询事件类别树, 供下拉框调用
* @Date 2019/12/3 18:07
**/
@GetMapping("getCategoryTree")
public Result<CategoryOption> getCategoryTree() {
return moduleCategoryService.getCategoryTree();
}
}

40
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
* <p>
* 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.
* <p>
* 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.
* <p>
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
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<ModuleCategoryEntity> {
List<ModuleCategoryEntity> getList(Map<String, Object> params);
List<ModuleCategoryTreeDTO> selectListCategoryTreeDTO();
}

96
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
* <p>
* 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.
* <p>
* 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.
* <p>
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
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;
}

89
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
* <p>
* 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.
* <p>
* 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.
* <p>
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
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;
}

47
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
* <p>
* 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.
* <p>
* 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.
* <p>
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
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;
}
}

110
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
* <p>
* 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.
* <p>
* 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.
* <p>
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
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<ModuleCategoryEntity> {
/**
* 默认分页
*
* @param params
* @return PageData<ModuleCategoryDTO>
* @author generator
* @date 2020-10-28
*/
PageData<ModuleCategoryDTO> page(Map<String, Object> params);
/**
* 默认查询
*
* @param params
* @return java.util.List<ModuleCategoryDTO>
* @author generator
* @date 2020-10-28
*/
List<ModuleCategoryDTO> list(Map<String, Object> 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<com.elink.esua.epdc.dto.CategoryOption>
**/
Result<CategoryOption> getCategoryTree();
}

296
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
* <p>
* 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.
* <p>
* 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.
* <p>
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
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<ModuleCategoryDao, ModuleCategoryEntity> implements ModuleCategoryService {
@Autowired
private ModuleCategoryRedis moduleCategoryRedis;
@Override
public PageData<ModuleCategoryDTO> page(Map<String, Object> params) {
IPage<ModuleCategoryEntity> page = baseDao.selectPage(
getPage(params, FieldConstant.CREATED_TIME, false),
getWrapper(params)
);
return getPageData(page, ModuleCategoryDTO.class);
}
@Override
public List<ModuleCategoryDTO> list(Map<String, Object> params) {
List<ModuleCategoryEntity> entityList = baseDao.getList(params);
List<ModuleCategoryDTO> dtoList = ConvertUtils.sourceToTarget(entityList, ModuleCategoryDTO.class);
return TreeUtils.build(dtoList);
}
private QueryWrapper<ModuleCategoryEntity> getWrapper(Map<String, Object> params){
String id = (String)params.get(FieldConstant.ID_HUMP);
QueryWrapper<ModuleCategoryEntity> 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<ModuleCategoryEntity> 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<ModuleCategoryEntity> getPidListByPid(String pid) {
//顶级部门,无上级部门
if (Constant.CATEGORY_ROOT.equals(pid)) {
return new ArrayList<>();
}
//所有的分类列表
QueryWrapper<ModuleCategoryEntity> wrapper = new QueryWrapper<>();
List<ModuleCategoryEntity> categoryEntityList = baseDao.selectList(wrapper);
//list转map
Map<String, ModuleCategoryEntity> map = new HashMap<>(categoryEntityList.size());
for (ModuleCategoryEntity entity : categoryEntityList) {
map.put(entity.getId(), entity);
}
//递归查询所有上级分类列表
List<ModuleCategoryEntity> pCategoryEntityList = new ArrayList<>();
getPidTree(pid, map, pCategoryEntityList);
return pCategoryEntityList;
}
private void getPidTree(String pid, Map<String, ModuleCategoryEntity> map, List<ModuleCategoryEntity> 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<ModuleCategoryEntity> 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<ModuleCategoryEntity> 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<CategoryOption> getCategoryTree() {
return new Result<CategoryOption>().ok(this.packageCategoryOption());
}
/**
* @Description 组装信息
* @Author songyunpeng
* @Date 2020/10/28
* @Param []
* @return void
**/
private CategoryOption packageCategoryOption() {
List<ModuleCategoryTreeDTO> 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<ModuleCategoryTreeDTO> 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<JSONArray> cache = Lists.newArrayList();
cache.add(headNodes);
CategoryOption option = new CategoryOption();
option.setOptions(cache.get(0));
return option;
}
private List<ModuleCategoryTreeDTO> getOtherCategory(List<ModuleCategoryTreeDTO> dtoList, JSONArray parent) {
List<String> already = Lists.newArrayList();
for (int i = 0; i < parent.size(); i++) {
already.add((String) parent.getJSONObject(i).get("value"));
}
List<ModuleCategoryTreeDTO> others = Lists.newArrayList();
for (ModuleCategoryTreeDTO categoryTreeDto : dtoList) {
String categoryTreeDtoId = categoryTreeDto.getId();
if (!already.contains(categoryTreeDtoId)) {
others.add(categoryTreeDto);
}
}
return others;
}
}

47
esua-epdc/epdc-module/epdc-custom/epdc-custom-server/src/main/resources/mapper/moduleCategory/ModuleCategoryDao.xml

@ -0,0 +1,47 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.elink.esua.epdc.modules.moduleCategory.dao.ModuleCategoryDao">
<resultMap type="com.elink.esua.epdc.modules.moduleCategory.entity.ModuleCategoryEntity" id="moduleCategoryMap">
<result property="id" column="ID"/>
<result property="pid" column="PID"/>
<result property="pids" column="PIDS"/>
<result property="categoryCode" column="CATEGORY_CODE"/>
<result property="categoryName" column="CATEGORY_NAME"/>
<result property="categoryType" column="CATEGORY_TYPE"/>
<result property="imgUrl" column="IMG_URL"/>
<result property="moduleStyle" column="MODULE_STYLE"/>
<result property="bannerFlag" column="BANNER_FLAG"/>
<result property="remark" column="REMARK"/>
<result property="sort" column="SORT"/>
<result property="enableFlag" column="ENABLE_FLAG"/>
<result property="delFlag" column="DEL_FLAG"/>
<result property="revision" column="REVISION"/>
<result property="createdBy" column="CREATED_BY"/>
<result property="createdTime" column="CREATED_TIME"/>
<result property="updatedBy" column="UPDATED_BY"/>
<result property="updatedTime" column="UPDATED_TIME"/>
</resultMap>
<select id="getList" resultType="com.elink.esua.epdc.modules.moduleCategory.entity.ModuleCategoryEntity">
select t1.*,t1.id as value,t1.category_name as label,(select t2.category_name from epdc_module_category t2 where t2.id=t1.pid)parentName from epdc_module_category t1
where t1.del_flag = '0' AND t1.enable_flag = '1'
order by t1.sort asc
</select>
<select id="selectListCategoryTreeDTO" resultType="com.elink.esua.epdc.dto.ModuleCategoryTreeDTO">
SELECT
t1.id,
t1.pid,
t1.category_name as categoryName,
t1.id AS VALUE,
t1.category_name AS label
FROM
epdc_module_category t1
WHERE
t1.del_flag = 0
ORDER BY
t1.sort ASC
</select>
</mapper>
Loading…
Cancel
Save