CommonController.java 10.6 KB
Newer Older
苗卫卫 committed
1 2 3 4 5 6 7 8 9 10 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 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262
package com.boco.nbd.wios.manage.controller;

import cn.hutool.core.lang.Assert;
import com.boco.nbd.cams.core.constant.MessageConstant;
import com.boco.nbd.wios.manage.contants.WiosConstant;
import com.boco.nbd.wios.manage.entity.bo.Dictionary;
import com.boco.nbd.wios.manage.entity.bo.InfoConfig;
import com.boco.nbd.wios.manage.service.impl.CommonService;
import com.boco.nbd.wios.manage.service.impl.DictionaryService;
import com.boco.nbd.wios.manage.service.impl.InfoConfigService;
import com.boco.nbd.wios.manage.util.FileUtil;
import com.ihidea.component.api.v2.BaseResponse;
import com.ihidea.core.support.exception.ServiceException;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import springfox.documentation.annotations.ApiIgnore;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 通用接口
 *
 * @author xgl
 * @version [版本号, 2020年9月17日]
 */
@RestController
@RequestMapping("api")
@Api(tags = "通用接口")
@ApiIgnore
public class CommonController {

    @Autowired
    private CommonService commonService;

    @Autowired
    private DictionaryService dictionaryService;

    @Autowired
    private InfoConfigService infoConfigService;

    /**
     * 获取枚举内容
     *
     * @param enumNames
     * @return
     */
    @GetMapping(value = "enum/get")
    @ApiOperation(value = "获取枚举内容")
    @ApiImplicitParams({@ApiImplicitParam(name = "enumNames", value = "枚举类名", dataType = "String", paramType = "query", required = true),})
    public BaseResponse<Object> getEnums(String enumNames) {
        if (StringUtils.isEmpty(enumNames)) {
            throw new ServiceException(MessageConstant.MISSING_PARAM);
        }
        return new BaseResponse<>(commonService.getEnums(enumNames));
    }

    /**
     * 获取字典内容
     *
     * @param type
     * @return
     */
    @GetMapping(value = "dictionary/getByType")
    @ApiOperation(value = "获取字典内容")
    @ApiImplicitParams({@ApiImplicitParam(name = "type", value = "类型", dataType = "String", paramType = "query", required = true),
            @ApiImplicitParam(name = "name", value = "名称", dataType = "String", paramType = "query", required = false),})
    public BaseResponse<List<Dictionary>> getDictionaryByType(String type, String name) {
        if (StringUtils.isEmpty(type)) {
            throw new ServiceException(MessageConstant.MISSING_PARAM);
        }
        return new BaseResponse<>(dictionaryService.selectValidByType(type, name));
    }

    /**
     * 添加字典内容
     *
     * @param type
     * @param name
     * @param value
     * @return
     */
    @PostMapping(value = "dictionary/add")
    @ApiOperation(value = "添加字典内容")
    @ApiImplicitParams({@ApiImplicitParam(name = "type", value = "类型", dataType = "String", paramType = "query", required = true),
            @ApiImplicitParam(name = "name", value = "名称", dataType = "String", paramType = "query", required = true),
            @ApiImplicitParam(name = "value", value = "值", dataType = "String", paramType = "query", required = true),
            @ApiImplicitParam(name = "isSettle", value = "是否结算:0:否,1:是", dataType = "int", paramType = "query", required = false),
            @ApiImplicitParam(name = "deviceLen", value = "设备编号长度(0:不限)", dataType = "int", paramType = "query", required = false),
    })
    public BaseResponse<Object> dicAdd(String type, String name, String value, Integer isSettle, Integer deviceLen) {
        Assert.notNull(type, "缺少type");
        Assert.notNull(name, "缺少name");
        Assert.notNull(value, "缺少value");
        Dictionary dic = new Dictionary();
        dic.setType(type);
        dic.setName(name);
        dic.setValue(value);
        dic.setIsSettle(isSettle);
        dic.setDeviceLen(deviceLen);
        List<Dictionary> list = dictionaryService.selectValidByValue(type, value);
        if (!list.isEmpty()) {
            throw new ServiceException("该字典值已存在");
        }
        dictionaryService.add(dic);
        return new BaseResponse<Object>();
    }

    /**
     * 根据id更新字典内容
     *
     * @param id
     * @param value
     * @return
     */
    @PostMapping(value = "dictionary/update")
    @ApiOperation(value = "更新字典内容")
    @ApiImplicitParams({@ApiImplicitParam(name = "id", value = "主键id", dataType = "String", paramType = "query", required = true),
            @ApiImplicitParam(name = "value", value = "值", dataType = "String", paramType = "query", required = true),
            @ApiImplicitParam(name = "isSettle", value = "是否结算:0:否,1:是", dataType = "int", paramType = "query", required = false),
            @ApiImplicitParam(name = "deviceLen", value = "设备编号长度(0:不限)", dataType = "int", paramType = "query", required = false),
            @ApiImplicitParam(name = "name", value = "名称", dataType = "String", paramType = "query", required = false),})
    public BaseResponse<Object> dicUpdate(String id, String value, String name, Integer isSettle, Integer deviceLen) {
        Assert.notNull(id, "缺少id");
        Assert.notNull(value, "缺少value");
        Dictionary dic = new Dictionary();
        dic.setId(id);
        dic.setValue(value);
        dic.setIsSettle(isSettle);
        dic.setDeviceLen(deviceLen);
        dic.setName(name);
        dictionaryService.update(dic);
        return new BaseResponse<Object>();
    }

    /**
     * 获取上传地址
     *
     * @return
     */
    @GetMapping(value = "getUploadUrl")
    @ApiOperation(value = "获取上传地址")
    public BaseResponse<String> getUploadUrl() {
        return new BaseResponse<String>(WiosConstant.FILE_UPLOAD_DEFAULT_URL);
    }

    /**
     * 下载模板文件
     *
     * @param response
     * @param fileName
     * @return
     * @throws Exception
     */
    @GetMapping(value = "getTemplateFile")
    @ApiOperation(value = "获取模板文件")
    @ApiImplicitParams({@ApiImplicitParam(name = "fileName", value = "文件名", dataType = "String", paramType = "query", required = true),})
    public void getTemplateFile(HttpServletResponse response, String fileName) throws Exception {
        FileUtil.downloadTemplate(response, fileName);
    }

    /**
     * 批量更新时效配置
     *
     * @param dicJson
     * @return
     */
    @PostMapping(value = "dictionary/timingConfigUpdate")
    @ApiOperation(value = "批量更新时效配置")
    @ApiImplicitParams({@ApiImplicitParam(name = "dicJson", value = "json数据", dataType = "String", paramType = "query", required = true),})
    public BaseResponse<Object> timingConfigUpdate(String dicJson) {
        Assert.notNull(dicJson, MessageConstant.MISSING_PARAM);
        List<Dictionary> list = Dictionary.jsonHandle(dicJson);
        dictionaryService.timingConfigUpdate(list);
        return new BaseResponse<>();
    }

    /**
     * 删除文件
     *
     * @param id
     * @return
     */
    @PostMapping(value = "uploadFile/delete")
    @ApiOperation(value = "删除文件")
    @ApiImplicitParams({@ApiImplicitParam(name = "id", value = "文件id", dataType = "int", paramType = "query", required = true),})
    public BaseResponse<Object> deleteFile(Integer id) {
        Assert.notNull(id, "缺少id");
        commonService.deleteUploadFile(id);
        return new BaseResponse<>();
    }

    /**
     * @return com.ihidea.component.api.v2.BaseResponse<java.lang.Object>
     * @Description 添加基本信息配置
     * @Param [type, name]
     * @author liwenxiang
     * @date 2021/7/24 13:41
     */
    @PostMapping(value = "infoConfig/add")
    @ApiOperation(value = "添加信息配置")
    @ApiImplicitParams({@ApiImplicitParam(name = "type", value = "类型(0-安装紧急程度,1-首联人,2-邮箱)", dataType = "Integer", paramType = "query", required = true),
            @ApiImplicitParam(name = "name", value = "值", dataType = "String", paramType = "query", required = true)})
    public BaseResponse<Object> infoConfigAdd(Integer type, String name) {
        infoConfigService.add(type, name);
        return new BaseResponse<Object>();
    }

    /**
     * @return com.ihidea.component.api.v2.BaseResponse<java.lang.Object>
     * @Description 编辑基本信息配置
     * @Param [type, name]
     * @author liwenxiang
     * @date 2021/7/24 14:05
     */
    @PostMapping(value = "infoConfig/update")
    @ApiOperation(value = "更新信息配置")
    @ApiImplicitParams({@ApiImplicitParam(name = "id", value = "配置信息id", dataType = "String", paramType = "query", required = true),
            @ApiImplicitParam(name = "name", value = "值", dataType = "String", paramType = "query", required = true)})
    public BaseResponse<Object> infoConfigUpdate(String id, String name) {
        infoConfigService.update(id, name);
        return new BaseResponse<Object>();
    }

    /**
     * @return com.ihidea.component.api.v2.BaseResponse<java.lang.Object>
     * @Description 删除基本信息配置
     * @Param [id]
     * @author liwenxiang
     * @date 2021/7/26 10:04
     */
    @PostMapping(value = "infoConfig/del")
    @ApiOperation(value = "删除基本信息配置")
    @ApiImplicitParams({@ApiImplicitParam(name = "id", value = "配置信息id", dataType = "String", paramType = "query", required = true)})
    public BaseResponse<Object> infoConfigUpdate(String id) {
        infoConfigService.delete(id);
        return new BaseResponse<Object>();
    }

    /**
     * @return
     * @Description 条件查询信息配置列表
     * @Param [type, name]
     * @author liwenxiang
     * @date 2021/7/26 9:50
     */
    @GetMapping(value = "infoConfig/getListByCondition")
    @ApiOperation(value = "获取配置信息列表")
    @ApiImplicitParams({@ApiImplicitParam(name = "type", value = "类型(0-安装紧急程度,1-首联人,2-邮箱)", dataType = "Integer", paramType = "query", required = true),
            @ApiImplicitParam(name = "name", value = "值", dataType = "String", paramType = "query", required = false)})
    public BaseResponse<List<InfoConfig>> getInfoConfigListByCondition(Integer type, String name) {
        return new BaseResponse<>(infoConfigService.getInfoConfigListByCondition(type, name));
    }
}