|
@ -20,10 +20,14 @@ package com.elink.esua.epdc.service.impl; |
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
|
|
import com.baomidou.mybatisplus.core.metadata.IPage; |
|
|
import com.baomidou.mybatisplus.core.metadata.IPage; |
|
|
import com.elink.esua.epdc.commons.mybatis.service.impl.BaseServiceImpl; |
|
|
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.RenException; |
|
|
import com.elink.esua.epdc.commons.tools.page.PageData; |
|
|
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.ConvertUtils; |
|
|
import com.elink.esua.epdc.commons.tools.constant.FieldConstant; |
|
|
import com.elink.esua.epdc.commons.tools.utils.TreeUtils; |
|
|
import com.elink.esua.epdc.dao.ModuleTypeDao; |
|
|
import com.elink.esua.epdc.dao.ModuleTypeDao; |
|
|
|
|
|
import com.elink.esua.epdc.dto.ModuleTypeCategoryDTO; |
|
|
import com.elink.esua.epdc.dto.ModuleTypeDTO; |
|
|
import com.elink.esua.epdc.dto.ModuleTypeDTO; |
|
|
import com.elink.esua.epdc.entity.ModuleTypeEntity; |
|
|
import com.elink.esua.epdc.entity.ModuleTypeEntity; |
|
|
import com.elink.esua.epdc.redis.ModuleTypeRedis; |
|
|
import com.elink.esua.epdc.redis.ModuleTypeRedis; |
|
@ -33,9 +37,7 @@ import org.springframework.beans.factory.annotation.Autowired; |
|
|
import org.springframework.stereotype.Service; |
|
|
import org.springframework.stereotype.Service; |
|
|
import org.springframework.transaction.annotation.Transactional; |
|
|
import org.springframework.transaction.annotation.Transactional; |
|
|
|
|
|
|
|
|
import java.util.Arrays; |
|
|
import java.util.*; |
|
|
import java.util.List; |
|
|
|
|
|
import java.util.Map; |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
|
* 模块类别管理 |
|
|
* 模块类别管理 |
|
@ -76,17 +78,89 @@ public class ModuleTypeServiceImpl extends BaseServiceImpl<ModuleTypeDao, Module |
|
|
|
|
|
|
|
|
@Override |
|
|
@Override |
|
|
public ModuleTypeDTO get(String id) { |
|
|
public ModuleTypeDTO get(String id) { |
|
|
ModuleTypeEntity entity = baseDao.selectById(id); |
|
|
ModuleTypeEntity entity = baseDao.selectInfoById(id); |
|
|
return ConvertUtils.sourceToTarget(entity, ModuleTypeDTO.class); |
|
|
return ConvertUtils.sourceToTarget(entity, ModuleTypeDTO.class); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
@Override |
|
|
@Override |
|
|
@Transactional(rollbackFor = Exception.class) |
|
|
@Transactional(rollbackFor = Exception.class) |
|
|
public void save(ModuleTypeDTO dto) { |
|
|
public void save(ModuleTypeDTO dto) { |
|
|
|
|
|
String categoryCode = dto.getTypeCode(); |
|
|
|
|
|
if (StringUtils.isNotBlank(categoryCode)) { |
|
|
|
|
|
if (getCodeCount(dto) > 0) { |
|
|
|
|
|
throw new RenException("您输入的编码已存在"); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
ModuleTypeEntity entity = ConvertUtils.sourceToTarget(dto, ModuleTypeEntity.class); |
|
|
ModuleTypeEntity entity = ConvertUtils.sourceToTarget(dto, ModuleTypeEntity.class); |
|
|
|
|
|
entity.setBannerFlag("0"); |
|
|
|
|
|
List<ModuleTypeEntity> list = getPidListByPid(entity.getPid()); |
|
|
|
|
|
if(0==entity.getPid()){ |
|
|
|
|
|
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); |
|
|
insert(entity); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
* 获取所有上级分类 |
|
|
|
|
|
* |
|
|
|
|
|
* @param pid 上级ID |
|
|
|
|
|
*/ |
|
|
|
|
|
private List<ModuleTypeEntity> getPidListByPid(Long pid) { |
|
|
|
|
|
//顶级部门,无上级部门
|
|
|
|
|
|
if (Constant.CATEGORY_ROOT.equals(pid)) { |
|
|
|
|
|
return new ArrayList<>(); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
//所有的分类列表
|
|
|
|
|
|
QueryWrapper<ModuleTypeEntity> wrapper = new QueryWrapper<>(); |
|
|
|
|
|
List<ModuleTypeEntity> categoryEntityList = baseDao.selectList(wrapper); |
|
|
|
|
|
|
|
|
|
|
|
//list转map
|
|
|
|
|
|
Map<Long, ModuleTypeEntity> map = new HashMap<>(categoryEntityList.size()); |
|
|
|
|
|
for (ModuleTypeEntity entity : categoryEntityList) { |
|
|
|
|
|
map.put(entity.getId(), entity); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
//递归查询所有上级分类列表
|
|
|
|
|
|
List<ModuleTypeEntity> pCategoryEntityList = new ArrayList<>(); |
|
|
|
|
|
|
|
|
|
|
|
getPidTree(pid, map, pCategoryEntityList); |
|
|
|
|
|
|
|
|
|
|
|
return pCategoryEntityList; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private void getPidTree(Long pid, Map<Long, ModuleTypeEntity> map, List<ModuleTypeEntity> pCategoryEntityList) { |
|
|
|
|
|
//顶级,无上级
|
|
|
|
|
|
if (Constant.CATEGORY_ROOT.equals(pid)) { |
|
|
|
|
|
return; |
|
|
|
|
|
} |
|
|
|
|
|
//上级存在
|
|
|
|
|
|
ModuleTypeEntity parent = map.get(pid); |
|
|
|
|
|
if (parent != null) { |
|
|
|
|
|
getPidTree(parent.getPid(), map, pCategoryEntityList); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
pCategoryEntityList.add(parent); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public Integer getCodeCount(ModuleTypeDTO dto) { |
|
|
|
|
|
QueryWrapper<ModuleTypeEntity> wrapper = new QueryWrapper<>(); |
|
|
|
|
|
wrapper.eq("type_code", dto.getTypeCode()); |
|
|
|
|
|
wrapper.eq("del_flag", "0"); |
|
|
|
|
|
return baseDao.selectCount(wrapper); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
@Override |
|
|
@Override |
|
|
@Transactional(rollbackFor = Exception.class) |
|
|
@Transactional(rollbackFor = Exception.class) |
|
|
public void update(ModuleTypeDTO dto) { |
|
|
public void update(ModuleTypeDTO dto) { |
|
@ -101,4 +175,13 @@ public class ModuleTypeServiceImpl extends BaseServiceImpl<ModuleTypeDao, Module |
|
|
baseDao.deleteBatchIds(Arrays.asList(ids)); |
|
|
baseDao.deleteBatchIds(Arrays.asList(ids)); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
|
public List<ModuleTypeCategoryDTO> getList(HashMap<Object, Object> params) { |
|
|
|
|
|
List<ModuleTypeEntity> entityList = baseDao.getList(params); |
|
|
|
|
|
|
|
|
|
|
|
List<ModuleTypeCategoryDTO> dtoList = ConvertUtils.sourceToTarget(entityList, ModuleTypeCategoryDTO.class); |
|
|
|
|
|
|
|
|
|
|
|
return TreeUtils.build(dtoList); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
} |
|
|
} |