10 changed files with 795 additions and 0 deletions
@ -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.dto.category; |
||||
|
|
||||
|
import java.io.Serializable; |
||||
|
import java.util.Date; |
||||
|
|
||||
|
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 io.swagger.annotations.ApiModelProperty; |
||||
|
import lombok.Data; |
||||
|
|
||||
|
import javax.validation.constraints.Min; |
||||
|
import javax.validation.constraints.NotBlank; |
||||
|
import javax.validation.constraints.NotNull; |
||||
|
import javax.validation.constraints.Null; |
||||
|
|
||||
|
|
||||
|
/** |
||||
|
* 分类管理 |
||||
|
* |
||||
|
* @author wjp wjp@elink-cn.com |
||||
|
* @since v1.0.0 2019-11-26 |
||||
|
*/ |
||||
|
@Data |
||||
|
public class CategoryDTO implements Serializable { |
||||
|
|
||||
|
private static final long serialVersionUID = 1L; |
||||
|
|
||||
|
/** |
||||
|
* id |
||||
|
*/ |
||||
|
@ApiModelProperty(value = "id") |
||||
|
@Null(message = "{id.null}", groups = AddGroup.class) |
||||
|
@NotNull(message = "{id.require}", groups = UpdateGroup.class) |
||||
|
private String id; |
||||
|
|
||||
|
/** |
||||
|
* 上级分类ID |
||||
|
*/ |
||||
|
@ApiModelProperty(value = "上级ID") |
||||
|
@NotNull(message = "{sysdept.pid.require}", groups = DefaultGroup.class) |
||||
|
private String pid; |
||||
|
|
||||
|
/** |
||||
|
* 分类名称 |
||||
|
*/ |
||||
|
@ApiModelProperty(value = "分类名称") |
||||
|
@NotBlank(message = "{sysdept.name.require}", groups = DefaultGroup.class) |
||||
|
private String categoryName; |
||||
|
|
||||
|
/** |
||||
|
* 分类类别 |
||||
|
*/ |
||||
|
private String categoryType; |
||||
|
|
||||
|
/** |
||||
|
* 分类编码 |
||||
|
*/ |
||||
|
private String categoryCode; |
||||
|
|
||||
|
/** |
||||
|
* 排序 |
||||
|
*/ |
||||
|
@ApiModelProperty(value = "排序") |
||||
|
@Min(value = 0, message = "{sort.number}", groups = DefaultGroup.class) |
||||
|
private Integer sort; |
||||
|
|
||||
|
private String parentName; |
||||
|
|
||||
|
|
||||
|
} |
||||
@ -0,0 +1,91 @@ |
|||||
|
/** |
||||
|
* 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.category.controller; |
||||
|
|
||||
|
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.UpdateGroup; |
||||
|
import com.elink.esua.epdc.commons.tools.validator.group.DefaultGroup; |
||||
|
import com.elink.esua.epdc.dto.category.CategoryDTO; |
||||
|
import com.elink.esua.epdc.modules.category.excel.CategoryExcel; |
||||
|
import com.elink.esua.epdc.modules.category.service.CategoryService; |
||||
|
import org.springframework.beans.factory.annotation.Autowired; |
||||
|
import org.springframework.web.bind.annotation.*; |
||||
|
|
||||
|
import javax.servlet.http.HttpServletResponse; |
||||
|
import java.util.List; |
||||
|
import java.util.Map; |
||||
|
|
||||
|
|
||||
|
/** |
||||
|
* 分类管理 |
||||
|
* |
||||
|
* @author wjp wjp@elink-cn.com |
||||
|
* @since v1.0.0 2019-11-26 |
||||
|
*/ |
||||
|
@RestController |
||||
|
@RequestMapping("category") |
||||
|
public class CategoryController { |
||||
|
|
||||
|
@Autowired |
||||
|
private CategoryService categoryService; |
||||
|
|
||||
|
@GetMapping("list") |
||||
|
public Result<List<CategoryDTO>> list(@RequestParam Map<String, Object> params){ |
||||
|
List<CategoryDTO> list = categoryService.list(params); |
||||
|
return new Result<List<CategoryDTO>>().ok(list); |
||||
|
} |
||||
|
|
||||
|
@GetMapping("{id}") |
||||
|
public Result<CategoryDTO> get(@PathVariable("id") Long id){ |
||||
|
CategoryDTO data = categoryService.get(id); |
||||
|
return new Result<CategoryDTO>().ok(data); |
||||
|
} |
||||
|
|
||||
|
@PostMapping |
||||
|
public Result save(@RequestBody CategoryDTO dto){ |
||||
|
//效验数据
|
||||
|
ValidatorUtils.validateEntity(dto, AddGroup.class, DefaultGroup.class); |
||||
|
categoryService.save(dto); |
||||
|
return new Result(); |
||||
|
} |
||||
|
|
||||
|
@PutMapping |
||||
|
public Result update(@RequestBody CategoryDTO dto){ |
||||
|
//效验数据
|
||||
|
ValidatorUtils.validateEntity(dto, UpdateGroup.class, DefaultGroup.class); |
||||
|
categoryService.update(dto); |
||||
|
return new Result(); |
||||
|
} |
||||
|
|
||||
|
@DeleteMapping |
||||
|
public Result delete(@RequestBody Long id){ |
||||
|
categoryService.delete(id); |
||||
|
return new Result(); |
||||
|
} |
||||
|
|
||||
|
@GetMapping("export") |
||||
|
public void export(@RequestParam Map<String, Object> params, HttpServletResponse response) throws Exception { |
||||
|
List<CategoryDTO> list = categoryService.list(params); |
||||
|
ExcelUtils.exportExcelToTarget(response, null, list, CategoryExcel.class); |
||||
|
} |
||||
|
|
||||
|
} |
||||
@ -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.category.dao; |
||||
|
|
||||
|
import com.elink.esua.epdc.commons.mybatis.dao.BaseDao; |
||||
|
import com.elink.esua.epdc.modules.category.entity.CategoryEntity; |
||||
|
import org.apache.ibatis.annotations.Mapper; |
||||
|
|
||||
|
import java.util.List; |
||||
|
import java.util.Map; |
||||
|
|
||||
|
/** |
||||
|
* 分类管理 |
||||
|
* |
||||
|
* @author wjp wjp@elink-cn.com |
||||
|
* @since v1.0.0 2019-11-26 |
||||
|
*/ |
||||
|
@Mapper |
||||
|
public interface CategoryDao extends BaseDao<CategoryEntity> { |
||||
|
|
||||
|
List<CategoryEntity> getList(Map<String, Object> params); |
||||
|
|
||||
|
CategoryEntity getById(Long id); |
||||
|
|
||||
|
/** |
||||
|
* 根据分类ID,获取所有子分类ID列表 |
||||
|
* |
||||
|
* @param id 分类ID |
||||
|
*/ |
||||
|
List<Long> getSubCategoryIdList(String id); |
||||
|
|
||||
|
} |
||||
@ -0,0 +1,108 @@ |
|||||
|
/** |
||||
|
* 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.category.entity; |
||||
|
|
||||
|
import com.baomidou.mybatisplus.annotation.*; |
||||
|
|
||||
|
import lombok.Data; |
||||
|
import lombok.EqualsAndHashCode; |
||||
|
|
||||
|
import java.io.Serializable; |
||||
|
import java.util.Date; |
||||
|
|
||||
|
/** |
||||
|
* 分类管理 |
||||
|
* |
||||
|
* @author wjp wjp@elink-cn.com |
||||
|
* @since v1.0.0 2019-11-26 |
||||
|
*/ |
||||
|
@Data |
||||
|
@EqualsAndHashCode(callSuper=false) |
||||
|
@TableName("epdc_category") |
||||
|
public class CategoryEntity implements Serializable { |
||||
|
|
||||
|
private static final long serialVersionUID = 1L; |
||||
|
|
||||
|
@TableId(type = IdType.UUID) |
||||
|
private String id; |
||||
|
|
||||
|
/** |
||||
|
* 上级分类ID |
||||
|
*/ |
||||
|
private String pid; |
||||
|
|
||||
|
/** |
||||
|
* 所有上级分类ID,用逗号分开 |
||||
|
*/ |
||||
|
private String pids; |
||||
|
|
||||
|
/** |
||||
|
* 分类名称 |
||||
|
*/ |
||||
|
private String categoryName; |
||||
|
|
||||
|
/** |
||||
|
* 分类编码 |
||||
|
*/ |
||||
|
private String categoryCode; |
||||
|
|
||||
|
/** |
||||
|
* 分类类别 |
||||
|
*/ |
||||
|
private String categoryType; |
||||
|
|
||||
|
/** |
||||
|
* 排序 |
||||
|
*/ |
||||
|
private Integer sort; |
||||
|
|
||||
|
/** |
||||
|
* 删除标识 0:未删除 1:删除 |
||||
|
*/ |
||||
|
@TableLogic |
||||
|
@TableField(fill = FieldFill.INSERT) |
||||
|
private Integer delFlag; |
||||
|
/** |
||||
|
* 更新者 |
||||
|
*/ |
||||
|
@TableField(fill = FieldFill.INSERT_UPDATE) |
||||
|
private Long updater; |
||||
|
/** |
||||
|
* 更新时间 |
||||
|
*/ |
||||
|
@TableField(fill = FieldFill.INSERT_UPDATE) |
||||
|
private Date updateDate; |
||||
|
|
||||
|
/** |
||||
|
* 上级部门名称 |
||||
|
*/ |
||||
|
@TableField(exist = false) |
||||
|
private String parentName; |
||||
|
|
||||
|
/** |
||||
|
* 创建者 |
||||
|
*/ |
||||
|
@TableField(fill = FieldFill.INSERT) |
||||
|
private Long creator; |
||||
|
/** |
||||
|
* 创建时间 |
||||
|
*/ |
||||
|
@TableField(fill = FieldFill.INSERT) |
||||
|
private Date createDate; |
||||
|
|
||||
|
} |
||||
@ -0,0 +1,68 @@ |
|||||
|
/** |
||||
|
* 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.category.excel; |
||||
|
|
||||
|
import cn.afterturn.easypoi.excel.annotation.Excel; |
||||
|
import lombok.Data; |
||||
|
|
||||
|
import java.util.Date; |
||||
|
|
||||
|
/** |
||||
|
* 分类管理 |
||||
|
* |
||||
|
* @author wjp wjp@elink-cn.com |
||||
|
* @since v1.0.0 2019-11-26 |
||||
|
*/ |
||||
|
@Data |
||||
|
public class CategoryExcel { |
||||
|
|
||||
|
@Excel(name = "id") |
||||
|
private Long id; |
||||
|
|
||||
|
@Excel(name = "上级分类ID") |
||||
|
private Long pid; |
||||
|
|
||||
|
@Excel(name = "所有上级分类ID,用逗号分开") |
||||
|
private String pids; |
||||
|
|
||||
|
@Excel(name = "分类名称") |
||||
|
private String categoryName; |
||||
|
|
||||
|
@Excel(name = "分类类别") |
||||
|
private String categoryType; |
||||
|
|
||||
|
@Excel(name = "排序") |
||||
|
private Integer sort; |
||||
|
|
||||
|
@Excel(name = "删除标识 0:未删除 1:删除") |
||||
|
private Integer delFlag; |
||||
|
|
||||
|
@Excel(name = "创建者") |
||||
|
private Long creator; |
||||
|
|
||||
|
@Excel(name = "创建时间") |
||||
|
private Date createDate; |
||||
|
|
||||
|
@Excel(name = "更新者") |
||||
|
private Long updater; |
||||
|
|
||||
|
@Excel(name = "更新时间") |
||||
|
private Date updateDate; |
||||
|
|
||||
|
|
||||
|
} |
||||
@ -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.category.redis; |
||||
|
|
||||
|
import com.elink.esua.epdc.commons.tools.redis.RedisUtils; |
||||
|
import org.springframework.beans.factory.annotation.Autowired; |
||||
|
import org.springframework.stereotype.Component; |
||||
|
|
||||
|
/** |
||||
|
* 分类管理 |
||||
|
* |
||||
|
* @author wjp wjp@elink-cn.com |
||||
|
* @since v1.0.0 2019-11-26 |
||||
|
*/ |
||||
|
@Component |
||||
|
public class CategoryRedis { |
||||
|
@Autowired |
||||
|
private RedisUtils redisUtils; |
||||
|
|
||||
|
public void delete(Object[] ids) { |
||||
|
|
||||
|
} |
||||
|
|
||||
|
public void set(){ |
||||
|
|
||||
|
} |
||||
|
|
||||
|
public String get(String id){ |
||||
|
return null; |
||||
|
} |
||||
|
|
||||
|
} |
||||
@ -0,0 +1,97 @@ |
|||||
|
/** |
||||
|
* 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.category.service; |
||||
|
|
||||
|
import com.elink.esua.epdc.commons.mybatis.service.BaseService; |
||||
|
import com.elink.esua.epdc.dto.category.CategoryDTO; |
||||
|
import com.elink.esua.epdc.modules.category.entity.CategoryEntity; |
||||
|
|
||||
|
import java.util.List; |
||||
|
import java.util.Map; |
||||
|
|
||||
|
/** |
||||
|
* 分类管理 |
||||
|
* |
||||
|
* @author wjp wjp@elink-cn.com |
||||
|
* @since v1.0.0 2019-11-26 |
||||
|
*/ |
||||
|
public interface CategoryService extends BaseService<CategoryEntity> { |
||||
|
|
||||
|
|
||||
|
/** |
||||
|
* 默认查询 |
||||
|
* |
||||
|
* @param params |
||||
|
* @return java.util.List<CategoryDTO> |
||||
|
* @author generator |
||||
|
* @date 2019-11-26 |
||||
|
*/ |
||||
|
List<CategoryDTO> list(Map<String, Object> params); |
||||
|
|
||||
|
/** |
||||
|
* 单条查询 |
||||
|
* |
||||
|
* @param id |
||||
|
* @return CategoryDTO |
||||
|
* @author generator |
||||
|
* @date 2019-11-26 |
||||
|
*/ |
||||
|
CategoryDTO get(Long id); |
||||
|
|
||||
|
/** |
||||
|
* 默认保存 |
||||
|
* |
||||
|
* @param dto |
||||
|
* @return void |
||||
|
* @author generator |
||||
|
* @date 2019-11-26 |
||||
|
*/ |
||||
|
void save(CategoryDTO dto); |
||||
|
|
||||
|
/** |
||||
|
* 默认更新 |
||||
|
* |
||||
|
* @param dto |
||||
|
* @return void |
||||
|
* @author generator |
||||
|
* @date 2019-11-26 |
||||
|
*/ |
||||
|
void update(CategoryDTO dto); |
||||
|
|
||||
|
|
||||
|
void delete(Long id); |
||||
|
|
||||
|
/** |
||||
|
* 根据分类ID,获取所有子分类ID列表 |
||||
|
* |
||||
|
* @param id 分类ID |
||||
|
*/ |
||||
|
List<Long> getSubCategoryIdList(Long id); |
||||
|
|
||||
|
/*** |
||||
|
* 校验编码是否重复 |
||||
|
*/ |
||||
|
Integer getCodeCount(CategoryDTO dto); |
||||
|
|
||||
|
/** |
||||
|
* 获取所有上级分类 |
||||
|
* |
||||
|
* @param id |
||||
|
*/ |
||||
|
List<CategoryEntity> getPidListById(Long id); |
||||
|
} |
||||
@ -0,0 +1,207 @@ |
|||||
|
/** |
||||
|
* 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.category.service.impl; |
||||
|
|
||||
|
import com.baomidou.mybatisplus.core.conditions.Wrapper; |
||||
|
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.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.constant.FieldConstant; |
||||
|
import com.elink.esua.epdc.dto.category.CategoryDTO; |
||||
|
import com.elink.esua.epdc.modules.category.dao.CategoryDao; |
||||
|
import com.elink.esua.epdc.modules.category.entity.CategoryEntity; |
||||
|
import com.elink.esua.epdc.modules.category.redis.CategoryRedis; |
||||
|
import com.elink.esua.epdc.modules.category.service.CategoryService; |
||||
|
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 wjp wjp@elink-cn.com |
||||
|
* @since v1.0.0 2019-11-26 |
||||
|
*/ |
||||
|
@Service |
||||
|
public class CategoryServiceImpl extends BaseServiceImpl<CategoryDao, CategoryEntity> implements CategoryService { |
||||
|
|
||||
|
@Autowired |
||||
|
private CategoryRedis categoryRedis; |
||||
|
|
||||
|
@Override |
||||
|
public List<CategoryDTO> list(Map<String, Object> params) { |
||||
|
List<CategoryEntity> entityList = baseDao.getList(params); |
||||
|
return ConvertUtils.sourceToTarget(entityList, CategoryDTO.class); |
||||
|
} |
||||
|
|
||||
|
@Override |
||||
|
public CategoryDTO get(Long id) { |
||||
|
if (id == null) { |
||||
|
return null; |
||||
|
} |
||||
|
CategoryEntity entity = baseDao.getById(id); |
||||
|
|
||||
|
return ConvertUtils.sourceToTarget(entity, CategoryDTO.class); |
||||
|
} |
||||
|
|
||||
|
@Override |
||||
|
@Transactional(rollbackFor = Exception.class) |
||||
|
public void save(CategoryDTO dto) { |
||||
|
String categoryCode = dto.getCategoryCode(); |
||||
|
if (StringUtils.isNotBlank(categoryCode)) { |
||||
|
if (getCodeCount(dto) > 0) { |
||||
|
throw new RenException("您输入的编码已存在"); |
||||
|
} |
||||
|
} |
||||
|
CategoryEntity entity = ConvertUtils.sourceToTarget(dto, CategoryEntity.class); |
||||
|
List<CategoryEntity> 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().toString(); |
||||
|
}else { |
||||
|
pids = pids + list.get(i).getId().toString() + ","; |
||||
|
} |
||||
|
} |
||||
|
entity.setPids(pids); |
||||
|
} |
||||
|
insert(entity); |
||||
|
} |
||||
|
|
||||
|
@Override |
||||
|
public List<CategoryEntity> getPidListById(Long id) { |
||||
|
//所有的分类列表
|
||||
|
CategoryEntity categoryEntity = baseDao.selectById(id); |
||||
|
return getPidListByPid(categoryEntity.getPid()); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 获取所有上级分类 |
||||
|
* |
||||
|
* @param pid 上级ID |
||||
|
*/ |
||||
|
private List<CategoryEntity> getPidListByPid(String pid) { |
||||
|
//顶级部门,无上级部门
|
||||
|
if (Constant.CATEGORY_ROOT.equals(pid)) { |
||||
|
return new ArrayList<>(); |
||||
|
} |
||||
|
|
||||
|
//所有的分类列表
|
||||
|
QueryWrapper<CategoryEntity> wrapper = new QueryWrapper<>(); |
||||
|
List<CategoryEntity> categoryEntityList = baseDao.selectList(wrapper); |
||||
|
|
||||
|
//list转map
|
||||
|
Map<String, CategoryEntity> map = new HashMap<>(categoryEntityList.size()); |
||||
|
for (CategoryEntity entity : categoryEntityList) { |
||||
|
map.put(entity.getId(), entity); |
||||
|
} |
||||
|
|
||||
|
//递归查询所有上级分类列表
|
||||
|
List<CategoryEntity> pCategoryEntityList = new ArrayList<>(); |
||||
|
|
||||
|
getPidTree(pid, map, pCategoryEntityList); |
||||
|
|
||||
|
return pCategoryEntityList; |
||||
|
} |
||||
|
|
||||
|
private void getPidTree(String pid, Map<String, CategoryEntity> map, List<CategoryEntity> pCategoryEntityList) { |
||||
|
//顶级,无上级
|
||||
|
if (Constant.CATEGORY_ROOT.equals(pid)) { |
||||
|
return; |
||||
|
} |
||||
|
//上级存在
|
||||
|
CategoryEntity parent = map.get(pid); |
||||
|
if (parent != null) { |
||||
|
getPidTree(parent.getPid(), map, pCategoryEntityList); |
||||
|
} |
||||
|
|
||||
|
pCategoryEntityList.add(parent); |
||||
|
} |
||||
|
|
||||
|
@Override |
||||
|
public Integer getCodeCount(CategoryDTO dto) { |
||||
|
QueryWrapper<CategoryEntity> wrapper = new QueryWrapper<>(); |
||||
|
wrapper.eq("category_code", dto.getCategoryCode()); |
||||
|
String id = dto.getId(); |
||||
|
wrapper.ne(id!=null, "id", dto.getId()); |
||||
|
return baseDao.selectCount(wrapper); |
||||
|
} |
||||
|
|
||||
|
|
||||
|
|
||||
|
@Override |
||||
|
@Transactional(rollbackFor = Exception.class) |
||||
|
public void update(CategoryDTO dto) { |
||||
|
String categoryCode = dto.getCategoryCode(); |
||||
|
if (StringUtils.isNotBlank(categoryCode)) { |
||||
|
if (getCodeCount(dto) > 0) { |
||||
|
throw new RenException("您输入的编码已存在"); |
||||
|
} |
||||
|
} |
||||
|
CategoryEntity entity = ConvertUtils.sourceToTarget(dto, CategoryEntity.class); |
||||
|
//上级部门不能为自身
|
||||
|
if (entity.getId().equals(entity.getPid())) { |
||||
|
throw new RenException(ErrorCode.SUPERIOR_DEPT_ERROR); |
||||
|
} |
||||
|
List<CategoryEntity> 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().toString(); |
||||
|
}else { |
||||
|
pids = pids + list.get(i).getId().toString() + ","; |
||||
|
} |
||||
|
} |
||||
|
entity.setPids(pids); |
||||
|
} |
||||
|
updateById(entity); |
||||
|
} |
||||
|
|
||||
|
@Override |
||||
|
@Transactional(rollbackFor = Exception.class) |
||||
|
public void delete(Long id) { |
||||
|
//判断是否有子部门
|
||||
|
List<Long> subList = getSubCategoryIdList(id); |
||||
|
if (subList.size() > 1) { |
||||
|
throw new RenException(ErrorCode.DEPT_SUB_DELETE_ERROR); |
||||
|
} |
||||
|
// 逻辑删除(@TableLogic 注解)
|
||||
|
logicDelete(new Long[]{id}, CategoryEntity.class); |
||||
|
|
||||
|
} |
||||
|
|
||||
|
@Override |
||||
|
public List<Long> getSubCategoryIdList(Long id) { |
||||
|
List<Long> subCategoryIdList = baseDao.getSubCategoryIdList("%" + id + "%"); |
||||
|
return subCategoryIdList; |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,37 @@ |
|||||
|
<?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.category.dao.CategoryDao"> |
||||
|
|
||||
|
<resultMap type="com.elink.esua.epdc.modules.category.entity.CategoryEntity" id="categoryMap"> |
||||
|
<result property="id" column="id"/> |
||||
|
<result property="pid" column="pid"/> |
||||
|
<result property="pids" column="pids"/> |
||||
|
<result property="categoryName" column="category_name"/> |
||||
|
<result property="categoryCode" column="category_code"/> |
||||
|
<result property="categoryType" column="category_type"/> |
||||
|
<result property="sort" column="sort"/> |
||||
|
<result property="delFlag" column="del_flag"/> |
||||
|
<result property="creator" column="creator"/> |
||||
|
<result property="createDate" column="create_date"/> |
||||
|
<result property="updater" column="updater"/> |
||||
|
<result property="updateDate" column="update_date"/> |
||||
|
</resultMap> |
||||
|
|
||||
|
|
||||
|
<select id="getList" resultType="com.elink.esua.epdc.modules.category.entity.CategoryEntity"> |
||||
|
select t1.*,(select t2.category_name from epdc_category t2 where t2.id=t1.pid)parentName from epdc_category t1 |
||||
|
where t1.del_flag = 0 |
||||
|
order by t1.sort asc |
||||
|
</select> |
||||
|
|
||||
|
<select id="getById" resultType="com.elink.esua.epdc.modules.category.entity.CategoryEntity"> |
||||
|
select t1.*,(select t2.category_name from epdc_category t2 where t2.id=t1.pid)parentName from epdc_category t1 |
||||
|
where t1.id = #{value} and t1.del_flag = 0 |
||||
|
</select> |
||||
|
|
||||
|
<select id="getSubCategoryIdList" resultType="long"> |
||||
|
select id from epdc_category where pids like #{id} and del_flag = 0 |
||||
|
</select> |
||||
|
|
||||
|
</mapper> |
||||
Loading…
Reference in new issue