package com.nuvole.four.service.impl;
|
|
import cn.hutool.core.util.StrUtil;
|
import com.github.pagehelper.PageHelper;
|
import com.nuvole.base.domain.SysUser;
|
import com.nuvole.four.contants.Contants;
|
import com.nuvole.four.domain.StoreIndustryManage;
|
import com.nuvole.four.domain.query.StoreIndustryManageQuery;
|
import com.nuvole.four.mapper.StoreIndustryManageMapper;
|
import com.nuvole.four.service.StoreIndustryManageService;
|
import com.nuvole.four.util.SystemUtil;
|
import com.nuvole.util.IdGenerator;
|
import com.nuvole.util.TreeUtil;
|
import lombok.AllArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
import org.springframework.stereotype.Service;
|
|
import java.util.Date;
|
import java.util.List;
|
import java.util.Map;
|
|
/**
|
* @Description 行业管理Service实现类
|
* @Author dqh
|
* @Date 2024-04-12 17:41:29
|
*/
|
@Service
|
@RequiredArgsConstructor
|
public class StoreIndustryManageServiceImpl implements StoreIndustryManageService {
|
|
private final StoreIndustryManageMapper storeIndustryManageMapper;
|
|
|
|
/**
|
* 方法描述: 添加行业管理
|
*
|
* @date 2024-04-12 18:29
|
**/
|
@Override
|
public int addSelective(StoreIndustryManage entity){
|
entity.setId(IdGenerator.getId());
|
if(entity.getPId() == null){
|
entity.setPId(0L);
|
}
|
entity.setLevel(getLevel(entity.getPId()));
|
//生成code
|
String code = generateCode(entity);
|
entity.setIndustryCode(code);
|
entity.setIndustryCode(Contants.CODE + entity.getLevel() + Contants.CODE + entity.getLevel());
|
SysUser user = SystemUtil.getLoginUser(Contants.LOGIN_TYPE_PC);
|
entity.setCreateBy(user.getId());
|
entity.setCreateTime(new Date());
|
return storeIndustryManageMapper.insertSelective(entity);
|
}
|
|
/**
|
* 方法描述: 生成本级code
|
*
|
* @date 2024-04-13 21:57
|
**/
|
private String generateCode(StoreIndustryManage entity){
|
StoreIndustryManage pManage = storeIndustryManageMapper.selectByPrimaryKey(entity.getPId());
|
String parentCode = "";//父级code
|
if (pManage != null) {
|
parentCode = pManage.getIndustryCode();
|
parentCode = parentCode.substring(pManage.getIndustryCode().length());
|
}
|
String maxCode = storeIndustryManageMapper.getMaxCode(entity.getPId(),parentCode); //本级最大code
|
if (StrUtil.isNotBlank(maxCode)){
|
maxCode = maxCode.substring(entity.getIndustryCode().length());
|
}
|
return maxCode;
|
}
|
|
/**
|
* 方法描述:获取当前pId对应的level层级
|
*
|
**/
|
private Integer getLevel(Long pId){
|
Integer level = null;
|
if(pId == null || pId == 0){
|
level = 0;
|
} else {
|
//查询当前行业的level;根据pId的level + 1得出
|
level = storeIndustryManageMapper.getLevel(pId);
|
}
|
return level;
|
}
|
|
/**
|
* 方法描述:修改行业管理
|
*
|
* @date 2024-04-12 18:33
|
**/
|
@Override
|
public int editSelective(StoreIndustryManage entity){
|
if(entity.getPId() == null){
|
entity.setPId(0L);
|
}
|
entity.setLevel(getLevel(entity.getPId()));
|
SysUser user = SystemUtil.getLoginUser(Contants.LOGIN_TYPE_PC);
|
entity.setUpdateBy(user.getId());
|
entity.setUpdateTime(new Date());
|
return storeIndustryManageMapper.updateByPrimaryKeySelective(entity);
|
}
|
@Override
|
public StoreIndustryManage get(Long id){
|
return storeIndustryManageMapper.selectByPrimaryKey(id);
|
}
|
@Override
|
public int del(Long id){
|
//校验是否存在子节点;存在则不允许删除
|
int exists = storeIndustryManageMapper.selectByPid(id);
|
if(exists > 0){
|
throw new IllegalArgumentException("存在下级,不允许删除");
|
}
|
return storeIndustryManageMapper.deleteByPrimaryKey(id);
|
}
|
|
|
/**
|
* 方法描述:查询行业管理列表
|
*
|
* @date 2024-04-12 18:52
|
**/
|
@Override
|
public List<StoreIndustryManage> getList(StoreIndustryManageQuery query) {
|
return storeIndustryManageMapper.selectList(query);
|
}
|
|
/**
|
* 方法描述:查询列表默认方法
|
*
|
* @date 2024-04-12 18:52
|
**/
|
@Override
|
public List<StoreIndustryManage> getList(Map map) {
|
return storeIndustryManageMapper.selectAll(map);
|
}
|
|
/**
|
* 方法描述: 查询max(sortNo)的序号信息
|
* 返回 = max(sortNo) + 10
|
*
|
* @date 2024-04-12 18:17
|
**/
|
@Override
|
public Integer getSort() {
|
return storeIndustryManageMapper.getSort();
|
}
|
|
/**
|
* 方法描述: 查询所有行业树
|
*
|
* @date 2024-04-12 18:47
|
**/
|
@Override
|
public List<Map> getIndustryTree(Map map) {
|
PageHelper.orderBy("p_id,sort_no");
|
List<StoreIndustryManage> list = this.getList(map);
|
return TreeUtil.convert2Tree(list);
|
}
|
}
|