OemController.java 9.1 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
package com.boco.nbd.wios.manage.controller;


import cn.hutool.core.lang.Assert;
import com.boco.nbd.cams.core.constant.CamsConstant;
import com.boco.nbd.cams.core.constant.MessageConstant;
import com.boco.nbd.wios.manage.contants.WiosConstant;
import com.boco.nbd.wios.manage.entity.bo.Oem;
import com.boco.nbd.wios.manage.entity.bo.OemBo;
import com.boco.nbd.wios.manage.entity.common.bo.UploadFile;
import com.boco.nbd.wios.manage.service.impl.OemService;
import com.boco.nbd.wios.manage.util.CommonUtils;
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 java.util.ArrayList;
import java.util.List;

/**
 * 主机厂/4s店相关api
 *
 * @author
 */
@RestController
@RequestMapping("api")
@Api(tags = "主机厂和经销商管理接口")
@ApiIgnore
public class OemController {
    @Autowired
    private OemService oemService;

    private final static String LIKE_FLAG = "%";

    /**
     * 查询列表
     *
     * @param oemBo
     * @return
     */
    @GetMapping(value = "oem/list")
    @ApiOperation(value = "查询列表")
    @ApiImplicitParams({@ApiImplicitParam(name = "page", value = "一页显示数量", dataType = "int", paramType = "query", required = false),
            @ApiImplicitParam(name = "pagecount", value = "页码", dataType = "int", paramType = "query", required = false),
            @ApiImplicitParam(name = "code", value = "编码", dataType = "String", paramType = "query", required = false),
            @ApiImplicitParam(name = "contactName", value = "联系人姓名", dataType = "String", paramType = "query", required = false),
            @ApiImplicitParam(name = "manualDispatchOrder", value = "是否人工派单 0:否 1:是", dataType = "int", paramType = "query", required = false),
            @ApiImplicitParam(name = "name", value = "名称", dataType = "String", paramType = "query", required = false),
            @ApiImplicitParam(name = "type", value = "类型 1-主机厂 2-经销商", dataType = "int", paramType = "query", required = false),
            @ApiImplicitParam(name = "status", value = "状态 0禁用 1启用", dataType = "int", paramType = "query", required = false),
            @ApiImplicitParam(name = "regionId", value = "区域id", dataType = "int", paramType = "query", required = false),})
    public BaseResponse<Object> list(OemBo oemBo) {
        if (!StringUtils.isEmpty(oemBo.getCode()) && oemBo.getCode().contains(LIKE_FLAG)) {
            oemBo.setCode(oemBo.getCode().replaceAll(LIKE_FLAG, "\\\\%"));
        }
        if (!StringUtils.isEmpty(oemBo.getName()) && oemBo.getName().contains(LIKE_FLAG)) {
            oemBo.setName(oemBo.getName().replaceAll(LIKE_FLAG, "\\\\%"));
        }
        if (!StringUtils.isEmpty(oemBo.getOrganizationCode()) && oemBo.getOrganizationCode().contains(LIKE_FLAG)) {
            oemBo.setOrganizationCode(oemBo.getOrganizationCode().replaceAll(LIKE_FLAG, "\\\\%"));
        }
        return new BaseResponse<>(oemService.getList(oemBo));
    }

    /**
     * 查询自己及旗下经销商
     *
     * @param id
     * @return
     */
    @GetMapping(value = "oem/getSelfAndChildren")
    @ApiOperation(value = "查询自己及旗下经销商")
    @ApiImplicitParams({@ApiImplicitParam(name = "id", value = "主机厂id", dataType = "int", paramType = "query", required = true),})
    public BaseResponse<List<Oem>> getSelfAndChildren(Integer id) {
        return new BaseResponse<>(oemService.getSelfAndChildren(id));
    }

    /**
     * 新增
     *
     * @param oem
     */
    @PostMapping(value = "oem/add")
    @ApiOperation(value = "添加")
    @ApiImplicitParams({@ApiImplicitParam(name = "account", value = "账户", dataType = "String", paramType = "query", required = true),
            @ApiImplicitParam(name = "type", value = "类型 1-主机厂 2-经销商", dataType = "int", paramType = "query", required = true),
    })
    public BaseResponse<Object> add(OemBo oem) {
        if (oem.getType() == null) {
            throw new ServiceException(MessageConstant.MISSING_PARAM);
        }
        oemService.add(oem);
        return new BaseResponse<>();
    }

    /**
     * 更新
     *
     * @param oem
     */
    @PostMapping(value = "oem/update")
    @ApiOperation(value = "更新")
    @ApiImplicitParams({@ApiImplicitParam(name = "id", value = "主键id", dataType = "int", paramType = "query", required = true),
            @ApiImplicitParam(name = "code", value = "编码", dataType = "String", paramType = "query", required = false),
            @ApiImplicitParam(name = "contactName", value = "联系人姓名", dataType = "String", paramType = "query", required = false),
            @ApiImplicitParam(name = "manualDispatchOrder", value = "是否人工派单 0:否 1:是", dataType = "String", paramType = "query", required = false),
            @ApiImplicitParam(name = "name", value = "名称", dataType = "String", paramType = "query", required = false),
    })
    public BaseResponse<Object> update(OemBo oem) {
        oemService.update(oem);
        return new BaseResponse<>();
    }

    /**
     * 更新账号
     *
     * @param accountId
     * @param account
     * @return
     */
    @PostMapping(value = "oem/updateAccount")
    @ApiOperation(value = "更新账号")
    @ApiImplicitParams({@ApiImplicitParam(name = "accountId", value = "账号id", dataType = "int", paramType = "query", required = true),
            @ApiImplicitParam(name = "account", value = "登陆手机号", dataType = "String", paramType = "query", required = true),})
    public BaseResponse<Object> updateAccount(Integer accountId, String account) {
        if (StringUtils.isEmpty(account) || accountId == null) {
            throw new ServiceException(MessageConstant.MISSING_PARAM);
        }
        oemService.updateAccount(accountId, account);
        return new BaseResponse<>();
    }

    /**
     * 附件上传
     *
     * @param oemId
     * @param fileName
     * @param fileUrl
     */
    @PostMapping(value = "oem/fileUpload")
    @ApiOperation(value = "附件上传")
    @ApiImplicitParams({@ApiImplicitParam(name = "oemId", value = "主机厂id", dataType = "int", paramType = "query", required = true),
            @ApiImplicitParam(name = "fileName", value = "文件名", dataType = "String", paramType = "query", required = true),
            @ApiImplicitParam(name = "fileUrl", value = "文件地址", dataType = "String", paramType = "query", required = true),})
    public BaseResponse<Object> fileUpload(Integer oemId, String fileName, String fileUrl) {
        if (StringUtils.isEmpty(fileName) || oemId == null || StringUtils.isEmpty(fileUrl)) {
            throw new ServiceException(MessageConstant.MISSING_PARAM);
        }
        if (!StringUtils.isEmpty(fileUrl)) {
            String[] arr = fileUrl.split(CamsConstant.COMMA);
            List<String> list = new ArrayList<>();
            for (String s : arr) {
                list.add(CommonUtils.urlHandle(s));
            }
            fileUrl = StringUtils.collectionToCommaDelimitedString(list);
        }
        oemService.fileUpload(oemId, fileName, fileUrl);
        return new BaseResponse<>();
    }

    /**
     * 校验唯一性
     *
     * @param code
     * @param name
     * @return
     */
    @GetMapping(value = "oem/checkExist")
    @ApiOperation(value = "校验唯一性")
    @ApiImplicitParams({@ApiImplicitParam(name = "code", value = "编码", dataType = "String", paramType = "query", required = false),
            @ApiImplicitParam(name = "name", value = "名称", dataType = "String", paramType = "query", required = false),
            @ApiImplicitParam(name = "id", value = "主机厂id", dataType = "int", paramType = "query", required = false),})
    public BaseResponse<Boolean> checkExist(String code, String name, Integer id) {
        if (StringUtils.isEmpty(code) && StringUtils.isEmpty(name)) {
            return new BaseResponse<>(false);
        }
        if (!StringUtils.isEmpty(code)) {
            return new BaseResponse<>(false);
        }
        return new BaseResponse<>(oemService.checkExist(code, name, id));
    }

    /**
     * 查询订单附件列表
     *
     * @param id
     * @return
     */
    @GetMapping(value = "oem/getFiles")
    @ApiOperation(value = "查询附件列表")
    @ApiImplicitParams({@ApiImplicitParam(name = "id", value = "主机厂id", dataType = "String", paramType = "query", required = true)})
    public BaseResponse<List<UploadFile>> getFiles(Integer id) {
        Assert.notNull(id, WiosConstant.EMPTY_ID);
        return new BaseResponse<List<UploadFile>>(oemService.getFiles(id));
    }
}