Search in sources :

Example 1 with DictModel

use of org.jeecg.common.system.vo.DictModel in project jeecg-boot by jeecgboot.

the class OnlCgformDemoController method virtualDictData.

/**
 * 模拟字典数据
 *
 * @return
 */
private List<DictModel> virtualDictData() {
    List<DictModel> dict = new ArrayList<>();
    dict.add(new DictModel("bj", "北京"));
    dict.add(new DictModel("sd", "山东"));
    dict.add(new DictModel("ah", "安徽"));
    return dict;
}
Also used : DictModel(org.jeecg.common.system.vo.DictModel) ArrayList(java.util.ArrayList)

Example 2 with DictModel

use of org.jeecg.common.system.vo.DictModel in project jeecg-boot by jeecgboot.

the class OnlCgformDemoController method enhanceJavaListHttp.

/**
 * Online表单 http 增强,list增强示例
 * @param params
 * @return
 */
@PostMapping("/enhanceJavaListHttp")
public Result<?> enhanceJavaListHttp(@RequestBody JSONObject params) {
    log.info(" --- params:" + params.toJSONString());
    JSONArray dataList = params.getJSONArray("dataList");
    List<DictModel> dict = virtualDictData();
    for (int i = 0; i < dataList.size(); i++) {
        JSONObject record = dataList.getJSONObject(i);
        String province = record.getString("province");
        if (province == null) {
            continue;
        }
        String text = dict.stream().filter(p -> province.equals(p.getValue())).map(DictModel::getText).findAny().orElse(province);
        record.put("province", text);
    }
    Result<?> res = Result.OK(dataList);
    res.setCode(1);
    return res;
}
Also used : RequestBody(org.springframework.web.bind.annotation.RequestBody) JSONArray(com.alibaba.fastjson.JSONArray) PostMapping(org.springframework.web.bind.annotation.PostMapping) Slf4j(lombok.extern.slf4j.Slf4j) List(java.util.List) Result(org.jeecg.common.api.vo.Result) org.jeecg.common.util.oConvertUtils(org.jeecg.common.util.oConvertUtils) DictModel(org.jeecg.common.system.vo.DictModel) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) JSONObject(com.alibaba.fastjson.JSONObject) RestController(org.springframework.web.bind.annotation.RestController) ArrayList(java.util.ArrayList) JSONObject(com.alibaba.fastjson.JSONObject) DictModel(org.jeecg.common.system.vo.DictModel) JSONArray(com.alibaba.fastjson.JSONArray) PostMapping(org.springframework.web.bind.annotation.PostMapping)

Example 3 with DictModel

use of org.jeecg.common.system.vo.DictModel in project jeecg-boot by jeecgboot.

the class AutoPoiDictConfig method queryDict.

/**
 * 通过字典查询easypoi,所需字典文本
 *
 * @Author:scott
 * @since:2019-04-09
 * @return
 */
@Override
public String[] queryDict(String dicTable, String dicCode, String dicText) {
    List<String> dictReplaces = new ArrayList<String>();
    List<DictModel> dictList = null;
    // step.1 如果没有字典表则使用系统字典表
    if (oConvertUtils.isEmpty(dicTable)) {
        dictList = commonAPI.queryDictItemsByCode(dicCode);
    } else {
        try {
            dicText = oConvertUtils.getString(dicText, dicCode);
            dictList = commonAPI.queryTableDictItemsByCode(dicTable, dicText, dicCode);
        } catch (Exception e) {
            log.error(e.getMessage(), e);
        }
    }
    for (DictModel t : dictList) {
        if (t != null) {
            // update-begin---author:scott   Date:20211220  for:[issues/I4MBB3]@Excel dicText字段的值有下划线时,导入功能不能正确解析---
            if (t.getValue().contains(EXCEL_SPLIT_TAG)) {
                String val = t.getValue().replace(EXCEL_SPLIT_TAG, TEMP_EXCEL_SPLIT_TAG);
                dictReplaces.add(t.getText() + EXCEL_SPLIT_TAG + val);
            } else {
                dictReplaces.add(t.getText() + EXCEL_SPLIT_TAG + t.getValue());
            }
        // update-end---author:20211220     Date:20211220  for:[issues/I4MBB3]@Excel dicText字段的值有下划线时,导入功能不能正确解析---
        }
    }
    if (dictReplaces != null && dictReplaces.size() != 0) {
        log.info("---AutoPoi--Get_DB_Dict------" + dictReplaces.toString());
        return dictReplaces.toArray(new String[dictReplaces.size()]);
    }
    return null;
}
Also used : DictModel(org.jeecg.common.system.vo.DictModel) ArrayList(java.util.ArrayList)

Example 4 with DictModel

use of org.jeecg.common.system.vo.DictModel 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 5 with DictModel

use of org.jeecg.common.system.vo.DictModel in project jeecg-boot by jeecgboot.

the class SysDictController method loadDictOrderByValue.

/**
 * 【接口签名验证】
 * 【给表单设计器的表字典使用】下拉搜索模式,有值时动态拼接数据
 * @param dictCode
 * @param keyword 当前控件的值,可以逗号分割
 * @param sign
 * @param pageSize
 * @return
 */
@RequestMapping(value = "/loadDictOrderByValue/{dictCode}", method = RequestMethod.GET)
public Result<List<DictModel>> loadDictOrderByValue(@PathVariable String dictCode, @RequestParam(name = "keyword") String keyword, @RequestParam(value = "sign", required = false) String sign, @RequestParam(value = "pageSize", required = false) Integer pageSize) {
    // 首次查询查出来用户选中的值,并且不分页
    Result<List<DictModel>> firstRes = this.loadDict(dictCode, keyword, sign, null);
    if (!firstRes.isSuccess()) {
        return firstRes;
    }
    // 然后再查询出第一页的数据
    Result<List<DictModel>> result = this.loadDict(dictCode, "", sign, pageSize);
    if (!result.isSuccess()) {
        return result;
    }
    // 合并两次查询的数据
    List<DictModel> firstList = firstRes.getResult();
    List<DictModel> list = result.getResult();
    for (DictModel firstItem : firstList) {
        // anyMatch 表示:判断的条件里,任意一个元素匹配成功,返回true
        // allMatch 表示:判断条件里的元素,所有的都匹配成功,返回true
        // noneMatch 跟 allMatch 相反,表示:判断条件里的元素,所有的都匹配失败,返回true
        boolean none = list.stream().noneMatch(item -> item.getValue().equals(firstItem.getValue()));
        // 当元素不存在时,再添加到集合里
        if (none) {
            list.add(0, firstItem);
        }
    }
    return result;
}
Also used : DictModel(org.jeecg.common.system.vo.DictModel)

Aggregations

DictModel (org.jeecg.common.system.vo.DictModel)24 ArrayList (java.util.ArrayList)12 IPage (com.baomidou.mybatisplus.core.metadata.IPage)8 List (java.util.List)8 Result (org.jeecg.common.api.vo.Result)8 LambdaQueryWrapper (com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper)6 Page (com.baomidou.mybatisplus.extension.plugins.pagination.Page)6 Slf4j (lombok.extern.slf4j.Slf4j)6 org.jeecg.common.util.oConvertUtils (org.jeecg.common.util.oConvertUtils)6 JSONObject (com.alibaba.fastjson.JSONObject)5 HashMap (java.util.HashMap)5 Collectors (java.util.stream.Collectors)5 CommonConstant (org.jeecg.common.constant.CommonConstant)5 Autowired (org.springframework.beans.factory.annotation.Autowired)5 ServiceImpl (com.baomidou.mybatisplus.extension.service.impl.ServiceImpl)3 Map (java.util.Map)3 CacheConstant (org.jeecg.common.constant.CacheConstant)3 DictModelMany (org.jeecg.common.system.vo.DictModelMany)3 DictQuery (org.jeecg.common.system.vo.DictQuery)3 SqlInjectionUtil (org.jeecg.common.util.SqlInjectionUtil)3