SysCodeController.java 1.9 KB
package cn.com.glsx.smart.modules.controller;

import cn.com.glsx.smart.common.exception.ResultEnum;
import cn.com.glsx.smart.modules.entity.SmartSysCode;
import cn.com.glsx.smart.modules.service.SmartSysCodeService;
import com.alibaba.fastjson.JSON;
import com.glsx.plat.common.utils.StringUtils;
import com.glsx.plat.core.web.R;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * <p>Description:
 * <p>Project: chejia-smart
 *
 * @author wbh
 * @date 2021-03-15
 */
@Slf4j
@RestController
@RequestMapping("/sysCode")
public class SysCodeController {
    @Autowired
    private SmartSysCodeService sysCodeService;

    @RequestMapping(value = "/getList", method = {RequestMethod.GET, RequestMethod.POST})
    public R getList(SmartSysCode code) {
        log.info("/sysCode/getList param: {}", JSON.toJSONString(code));
        if(StringUtils.isEmpty(code.getDictType())
                || StringUtils.isEmpty(code.getParentKey())){
            return R.error(ResultEnum.PARAM_ERROR.getCode(), ResultEnum.PARAM_ERROR.getMessage());
        }
        try {
            List<SmartSysCode> sysCodeList = sysCodeService.getList(code);
            return R.ok().data(sysCodeList);
        } catch (Exception e) {
            log.error("!!!! /sysCode/getList ERROR", e);
            return R.error();
        }
    }

    @RequestMapping(value = "/getListByCondition", method = {RequestMethod.POST})
    public List<SmartSysCode> getListByCondition(@RequestBody SmartSysCode code) {
        log.info("/sysCode/getListByCondition param: {}", JSON.toJSONString(code));
        return sysCodeService.getList(code);
    }
}