Search in sources :

Example 1 with Dict

use of com.ikoori.vip.common.persistence.model.Dict in project vip by guangdada.

the class DictServiceImpl method addDict.

@Override
public void addDict(String dictName, String dictValues) {
    // 判断有没有该字典
    List<Dict> dicts = dictMapper.selectList(new EntityWrapper<Dict>().eq("name", dictName).and().eq("pid", 0));
    if (dicts != null && dicts.size() > 0) {
        throw new BussinessException(BizExceptionEnum.DICT_EXISTED);
    }
    // 解析dictValues
    List<Map<String, String>> items = parseKeyValue(dictValues);
    // 添加字典
    Dict dict = new Dict();
    dict.setName(dictName);
    dict.setNum(0);
    dict.setPid(0);
    this.dictMapper.insert(dict);
    // 添加字典条目
    for (Map<String, String> item : items) {
        String num = item.get(MUTI_STR_KEY);
        String name = item.get(MUTI_STR_VALUE);
        Dict itemDict = new Dict();
        itemDict.setPid(dict.getId());
        itemDict.setName(name);
        try {
            itemDict.setNum(Integer.valueOf(num));
        } catch (NumberFormatException e) {
            throw new BussinessException(BizExceptionEnum.DICT_MUST_BE_NUMBER);
        }
        this.dictMapper.insert(itemDict);
    }
}
Also used : Dict(com.ikoori.vip.common.persistence.model.Dict) EntityWrapper(com.baomidou.mybatisplus.mapper.EntityWrapper) Map(java.util.Map) BussinessException(com.ikoori.vip.common.exception.BussinessException)

Example 2 with Dict

use of com.ikoori.vip.common.persistence.model.Dict in project vip by guangdada.

the class ConstantFactory method getDictsByName.

/**
 * 根据字典名称和字典中的值获取对应的名称
 */
@Override
public String getDictsByName(String name, Integer val) {
    Dict temp = new Dict();
    temp.setName(name);
    Dict dict = dictMapper.selectOne(temp);
    if (dict == null) {
        return "";
    } else {
        Wrapper<Dict> wrapper = new EntityWrapper<>();
        wrapper = wrapper.eq("pid", dict.getId());
        List<Dict> dicts = dictMapper.selectList(wrapper);
        for (Dict item : dicts) {
            if (item.getNum() != null && item.getNum().equals(val)) {
                return item.getName();
            }
        }
        return "";
    }
}
Also used : Dict(com.ikoori.vip.common.persistence.model.Dict) EntityWrapper(com.baomidou.mybatisplus.mapper.EntityWrapper)

Example 3 with Dict

use of com.ikoori.vip.common.persistence.model.Dict in project vip by guangdada.

the class DictWarpper method warpTheMap.

@Override
public void warpTheMap(Map<String, Object> map) {
    StringBuffer detail = new StringBuffer();
    Integer id = (Integer) map.get("id");
    List<Dict> dicts = ConstantFactory.me().findInDict(id);
    if (dicts != null) {
        for (Dict dict : dicts) {
            detail.append(dict.getNum() + ":" + dict.getName() + ",");
        }
        map.put("detail", ToolUtil.removeSuffix(detail.toString(), ","));
    }
}
Also used : Dict(com.ikoori.vip.common.persistence.model.Dict)

Example 4 with Dict

use of com.ikoori.vip.common.persistence.model.Dict in project vip by guangdada.

the class DictController method deptUpdate.

/**
 * 跳转到修改字典
 */
@Permission(Const.ADMIN_NAME)
@RequestMapping("/dict_edit/{dictId}")
public String deptUpdate(@PathVariable Integer dictId, Model model) {
    Dict dict = dictMapper.selectById(dictId);
    model.addAttribute("dict", dict);
    List<Dict> subDicts = dictMapper.selectList(new EntityWrapper<Dict>().eq("pid", dictId));
    model.addAttribute("subDicts", subDicts);
    LogObjectHolder.me().set(dict);
    return PREFIX + "dict_edit.html";
}
Also used : Dict(com.ikoori.vip.common.persistence.model.Dict) EntityWrapper(com.baomidou.mybatisplus.mapper.EntityWrapper) Permission(com.ikoori.vip.common.annotion.Permission) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

Dict (com.ikoori.vip.common.persistence.model.Dict)4 EntityWrapper (com.baomidou.mybatisplus.mapper.EntityWrapper)3 Permission (com.ikoori.vip.common.annotion.Permission)1 BussinessException (com.ikoori.vip.common.exception.BussinessException)1 Map (java.util.Map)1 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)1