Search in sources :

Example 1 with SysCategory

use of org.jeecg.modules.system.entity.SysCategory in project jeecg-boot by jeecgboot.

the class SysCategoryServiceImpl method updateSysCategory.

@Override
public void updateSysCategory(SysCategory sysCategory) {
    if (oConvertUtils.isEmpty(sysCategory.getPid())) {
        sysCategory.setPid(ISysCategoryService.ROOT_PID_VALUE);
    } else {
        // 如果当前节点父ID不为空 则设置父节点的hasChild 为1
        SysCategory parent = baseMapper.selectById(sysCategory.getPid());
        if (parent != null && !"1".equals(parent.getHasChild())) {
            parent.setHasChild("1");
            baseMapper.updateById(parent);
        }
    }
    baseMapper.updateById(sysCategory);
}
Also used : SysCategory(org.jeecg.modules.system.entity.SysCategory)

Example 2 with SysCategory

use of org.jeecg.modules.system.entity.SysCategory in project jeecg-boot by jeecgboot.

the class SysCategoryController method loadAllData.

/**
 * [列表页面]加载分类字典数据 用于值的替换
 * @param code
 * @return
 */
@RequestMapping(value = "/loadAllData", method = RequestMethod.GET)
public Result<List<DictModel>> loadAllData(@RequestParam(name = "code", required = true) String code) {
    Result<List<DictModel>> result = new Result<List<DictModel>>();
    LambdaQueryWrapper<SysCategory> query = new LambdaQueryWrapper<SysCategory>();
    if (oConvertUtils.isNotEmpty(code) && !"0".equals(code)) {
        query.likeRight(SysCategory::getCode, code);
    }
    List<SysCategory> list = this.sysCategoryService.list(query);
    if (list == null || list.size() == 0) {
        result.setMessage("无数据,参数有误.[code]");
        result.setSuccess(false);
        return result;
    }
    List<DictModel> rdList = new ArrayList<DictModel>();
    for (SysCategory c : list) {
        rdList.add(new DictModel(c.getId(), c.getName()));
    }
    result.setSuccess(true);
    result.setResult(rdList);
    return result;
}
Also used : DictModel(org.jeecg.common.system.vo.DictModel) SysCategory(org.jeecg.modules.system.entity.SysCategory) Result(org.jeecg.common.api.vo.Result) LambdaQueryWrapper(com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper)

Example 3 with SysCategory

use of org.jeecg.modules.system.entity.SysCategory in project jeecg-boot by jeecgboot.

the class SysCategoryController method delete.

/**
 *   通过id删除
 * @param id
 * @return
 */
@DeleteMapping(value = "/delete")
public Result<SysCategory> delete(@RequestParam(name = "id", required = true) String id) {
    Result<SysCategory> result = new Result<SysCategory>();
    SysCategory sysCategory = sysCategoryService.getById(id);
    if (sysCategory == null) {
        result.error500("未找到对应实体");
    } else {
        this.sysCategoryService.deleteSysCategory(id);
        result.success("删除成功!");
    }
    return result;
}
Also used : SysCategory(org.jeecg.modules.system.entity.SysCategory) Result(org.jeecg.common.api.vo.Result)

Example 4 with SysCategory

use of org.jeecg.modules.system.entity.SysCategory in project jeecg-boot by jeecgboot.

the class CategoryCodeRule method execute.

@Override
public Object execute(JSONObject params, JSONObject formData) {
    log.info("系统自定义编码规则[category_code_rule],params:{} ,formData: {}", params, formData);
    String categoryPid = ROOT_PID_VALUE;
    String categoryCode = null;
    if (formData != null && formData.size() > 0) {
        Object obj = formData.get("pid");
        if (oConvertUtils.isNotEmpty(obj))
            categoryPid = obj.toString();
    } else {
        if (params != null) {
            Object obj = params.get("pid");
            if (oConvertUtils.isNotEmpty(obj))
                categoryPid = obj.toString();
        }
    }
    /*
         * 分成三种情况
         * 1.数据库无数据 调用YouBianCodeUtil.getNextYouBianCode(null);
         * 2.添加子节点,无兄弟元素 YouBianCodeUtil.getSubYouBianCode(parentCode,null);
         * 3.添加子节点有兄弟元素 YouBianCodeUtil.getNextYouBianCode(lastCode);
         * */
    // 找同类 确定上一个最大的code值
    LambdaQueryWrapper<SysCategory> query = new LambdaQueryWrapper<SysCategory>().eq(SysCategory::getPid, categoryPid).isNotNull(SysCategory::getCode).orderByDesc(SysCategory::getCode);
    SysCategoryMapper baseMapper = (SysCategoryMapper) SpringContextUtils.getBean("sysCategoryMapper");
    List<SysCategory> list = baseMapper.selectList(query);
    if (list == null || list.size() == 0) {
        if (ROOT_PID_VALUE.equals(categoryPid)) {
            // 情况1
            categoryCode = YouBianCodeUtil.getNextYouBianCode(null);
        } else {
            // 情况2
            SysCategory parent = (SysCategory) baseMapper.selectById(categoryPid);
            categoryCode = YouBianCodeUtil.getSubYouBianCode(parent.getCode(), null);
        }
    } else {
        // 情况3
        categoryCode = YouBianCodeUtil.getNextYouBianCode(list.get(0).getCode());
    }
    return categoryCode;
}
Also used : JSONObject(com.alibaba.fastjson.JSONObject) SysCategory(org.jeecg.modules.system.entity.SysCategory) SysCategoryMapper(org.jeecg.modules.system.mapper.SysCategoryMapper)

Example 5 with SysCategory

use of org.jeecg.modules.system.entity.SysCategory in project kms by mahonelau.

the class SysCategoryServiceImpl method getTreeChildIds.

/**
 * 递归 根据父id获取子节点id
 * @param pidVal
 * @param sb
 * @return
 */
private StringBuffer getTreeChildIds(String pidVal, StringBuffer sb) {
    LambdaQueryWrapper<SysCategory> queryWrapper = new LambdaQueryWrapper<>();
    queryWrapper.eq(SysCategory::getPid, pidVal);
    List<SysCategory> dataList = baseMapper.selectList(queryWrapper);
    if (dataList != null && dataList.size() > 0) {
        for (SysCategory category : dataList) {
            if (!sb.toString().contains(category.getId())) {
                sb.append(",").append(category.getId());
            }
            this.getTreeChildIds(category.getId(), sb);
        }
    }
    return sb;
}
Also used : SysCategory(org.jeecg.modules.system.entity.SysCategory) LambdaQueryWrapper(com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper)

Aggregations

SysCategory (org.jeecg.modules.system.entity.SysCategory)33 Result (org.jeecg.common.api.vo.Result)15 LambdaQueryWrapper (com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper)12 JSONObject (com.alibaba.fastjson.JSONObject)6 IOException (java.io.IOException)6 DictModel (org.jeecg.common.system.vo.DictModel)6 ImportParams (org.jeecgframework.poi.excel.entity.ImportParams)6 MultipartFile (org.springframework.web.multipart.MultipartFile)6 MultipartHttpServletRequest (org.springframework.web.multipart.MultipartHttpServletRequest)6 CacheEvict (org.springframework.cache.annotation.CacheEvict)4 JSON (com.alibaba.fastjson.JSON)3 QueryWrapper (com.baomidou.mybatisplus.core.conditions.query.QueryWrapper)3 IPage (com.baomidou.mybatisplus.core.metadata.IPage)3 Page (com.baomidou.mybatisplus.extension.plugins.pagination.Page)3 java.util (java.util)3 Collectors (java.util.stream.Collectors)3 HttpServletRequest (javax.servlet.http.HttpServletRequest)3 HttpServletResponse (javax.servlet.http.HttpServletResponse)3 Slf4j (lombok.extern.slf4j.Slf4j)3 StringUtils (org.apache.commons.lang.StringUtils)3