JcbController.java 3.32 KB
Newer Older
谢恒's avatar
谢恒 committed
1 2 3 4 5 6 7 8 9
package com.hs.admin.controller;

import com.hs.admin.base.HsRuntimeException;
import com.hs.admin.base.PageResult;
import com.hs.admin.base.Result;
import com.hs.admin.bean.Jcb;
import com.hs.admin.dto.JcbDto;
import com.hs.admin.service.JcbService;
import com.hs.admin.util.JsonUtils;
谢恒's avatar
谢恒 committed
10
import com.hs.admin.util.LogUtil;
谢恒's avatar
谢恒 committed
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45
import com.hs.admin.util.LoginUserUtil;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * @author xieheng
 */
@RestController
public class JcbController {
    @Resource
    LoginUserUtil loginUserUtil;
    @Resource
    JcbService jcbService;

    /**
     * @description: 添加租户/修改
     * @param: jcbDto
     * @return: String
     * @author: XieHeng
     * @date: 2021/5/10 8:49 上午
     */
    @PutMapping(value = "/api/admin/saveJcb")
    public String saveJcb(@RequestBody @Validated JcbDto jcbDto) {
        Result result;
        try {
            loginUserUtil.getLoginUser();
            boolean b = jcbService.saveJcb(jcbDto);
            if (b) {
                result = Result.returnSuccess(null);
            } else {
                result = Result.returnError();
            }
        } catch (HsRuntimeException e) {
谢恒's avatar
谢恒 committed
46
            LogUtil.error("\n>>>>>saveJcb错误日志:"+e);
谢恒's avatar
谢恒 committed
47 48
            result = Result.returnHsException(e);
        } catch (Exception e) {
谢恒's avatar
谢恒 committed
49
            LogUtil.error("\n>>>>>saveJcb错误日志:"+e);
谢恒's avatar
谢恒 committed
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73
            result = Result.returnError();
        }
        return JsonUtils.beanToJson(result);
    }

    /**
     * @description: 删除租户
     * @param: jcbId
     * @return: String
     * @author: XieHeng
     * @date: 2021/5/10 9:02 上午
     */
    @GetMapping(value = "/api/admin/deleteJcb")
    public String delJcb(Integer id) {
        Result result;
        try {
            loginUserUtil.getLoginUser();
            boolean b = jcbService.delJcb(id);
            if (b) {
                result = Result.returnSuccess(null);
            } else {
                result = Result.returnError();
            }
        } catch (HsRuntimeException e) {
谢恒's avatar
谢恒 committed
74
            LogUtil.error("\n>>>>>deleteJcb错误日志:"+e);
谢恒's avatar
谢恒 committed
75 76
            result = Result.returnHsException(e);
        } catch (Exception e) {
谢恒's avatar
谢恒 committed
77
            LogUtil.error("\n>>>>>deleteJcb错误日志:"+e);
谢恒's avatar
谢恒 committed
78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98
            result = Result.returnError();
        }
        return JsonUtils.beanToJson(result);
    }

    /**
     * @description: 获取租户列表
     * @param: pageNum
     * @param: pageSize
     * @return: String
     * @author: XieHeng
     * @date: 2021/5/10 9:04 上午
     */
    @GetMapping(value = "/api/admin/getJcbList")
    public String getJcbList(@RequestParam(defaultValue = "1") Integer pageNum, @RequestParam(defaultValue = "20") Integer pageSize) {
        Result result;
        try {
            loginUserUtil.getLoginUser();
            PageResult<Jcb> pageResult = jcbService.getJcbList(pageNum, pageSize);
            result = Result.returnSuccess(pageResult);
        } catch (HsRuntimeException e) {
谢恒's avatar
谢恒 committed
99
            LogUtil.error("\n>>>>>getJcbList错误日志:"+e);
谢恒's avatar
谢恒 committed
100 101
            result = Result.returnHsException(e);
        } catch (Exception e) {
谢恒's avatar
谢恒 committed
102
            LogUtil.error("\n>>>>>getJcbList错误日志:"+e);
谢恒's avatar
谢恒 committed
103 104 105 106 107
            result = Result.returnError();
        }
        return JsonUtils.beanToJson(result);
    }
}