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

import cn.hutool.core.lang.Assert;
import com.boco.nbd.wios.flow.util.ProcessUtil;
import com.boco.nbd.wios.manage.contants.WiosConstant;
import com.boco.nbd.wios.manage.entity.bo.AccountBo;
import com.boco.nbd.wios.manage.entity.bo.AccountVo;
import com.boco.nbd.wios.manage.entity.bo.Oem;
import com.boco.nbd.wios.manage.entity.bo.Role;
import com.boco.nbd.wios.manage.mapper.def.OemDao;
import com.boco.nbd.wios.manage.service.impl.AccountService;
import com.boco.nbd.wios.manage.service.impl.RoleService;
import com.ihidea.component.api.v2.BaseResponse;
import com.ihidea.core.support.exception.ServiceException;
import com.ihidea.core.support.session.SessionInfo;
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.annotation.Resource;
import java.util.List;

/**
 * 账户相关api
 *
 * @author lilin
 * @version [版本号, 2020年5月9日]
 */
@RestController
@RequestMapping("api")
@Api(tags = "账户管理接口")
@ApiIgnore
public class AccountController {
    /**
     * 账户service
     */
    @Resource
    private AccountService accountService;

    /**
     * 角色service
     */
    @Resource
    private RoleService roleService;

    @Autowired
    private OemDao oemDao;


    /**
     * 查询账户列表
     *
     * @param name
     * @param status
     * @param type
     * @param account
     * @return
     */
    @GetMapping(value = "account/oem/list")
    @ApiOperation(value = "查询主机厂/经销商账户列表")
    @ApiImplicitParams({@ApiImplicitParam(name = "name", value = "姓名", dataType = "String", paramType = "query", required = false),
            @ApiImplicitParam(name = "status", value = "状态", dataType = "int", paramType = "query", required = false),
            @ApiImplicitParam(name = "oemId", value = "主机厂/经销商id", dataType = "int", paramType = "query", required = false),
            @ApiImplicitParam(name = "type", value = "类型 1:主机厂 2:经销商", dataType = "int", paramType = "query", required = false),
            @ApiImplicitParam(name = "account", value = "登陆账号", dataType = "String", paramType = "query", required = false),
    })
    public BaseResponse<List<AccountVo>> getOemAccountList(String name, Integer status, Integer type, String account) {
        AccountBo query = new AccountBo();
        query.setName(name);
        query.setStatus(status);
        query.setType(type);
        query.setAccount(account);
        return new BaseResponse<>(accountService.getOemAccountList(query));
    }

    /**
     * 添加主机厂/经销商账户
     *
     * @param accountInfo 账户信息
     * @return 新增成功的条数
     */
    @PostMapping(value = "account/oem/add")
    @ApiOperation(value = "添加主机厂/经销商账户")
    public BaseResponse<Integer> add(AccountBo accountInfo) {
        if (StringUtils.isEmpty(accountInfo.getRoleIds())) {
            throw new ServiceException("缺少角色");
        }
        SessionInfo currentUser = ProcessUtil.getUserInfo();
        if (currentUser == null) {
            return new BaseResponse<>(0);
        }
        if (WiosConstant.SUPER_USER_ID.equals(currentUser.getUserId())) {
            if (accountInfo.getOemId() == null) {
                throw new ServiceException("缺少主机厂/经销商id");
            }
            Oem oem = oemDao.selectById(accountInfo.getOemId());
            Integer parentId = oem.getWbAccountId();
            accountInfo.setParentId(parentId);
        } else {
            accountInfo.setParentId(Integer.valueOf(currentUser.getUserId()));
        }
        accountInfo.setPassword(WiosConstant.ACCOUNT_INIT_PASSWORD);
        return new BaseResponse<>(accountService.addAccount(accountInfo));
    }


    /**
     * 修改账户
     *
     * @param accountInfo 账户信息
     * @return 修改成功的数量
     */
    @PostMapping(value = "account/update")
    @ApiOperation(value = "修改账户")
    @ApiImplicitParams({@ApiImplicitParam(name = "id", value = "主键", dataType = "int", paramType = "query", required = true),
            @ApiImplicitParam(name = "phone", value = "手机号", dataType = "String", paramType = "query", required = false),
            @ApiImplicitParam(name = "name", value = "账户名称", dataType = "String", paramType = "query", required = false),
            @ApiImplicitParam(name = "account", value = "登陆账号", dataType = "String", paramType = "query", required = false),
            @ApiImplicitParam(name = "roleIds", value = "角色id", dataType = "String", paramType = "query", required = false),
    })
    public BaseResponse<Integer> update(AccountBo accountInfo) {
        return new BaseResponse<>(accountService.updateAccount(accountInfo));
    }

    /**
     * 修改密码
     *
     * @param id          账户id
     * @param oldPassword 旧密码
     * @param password    新密码
     * @return 是否修改成功:1成功,其他失败
     */
    @PostMapping(value = "account/updatePassword")
    @ApiOperation(value = "修改密码")
    @ApiImplicitParams({@ApiImplicitParam(name = "id", value = "主键", dataType = "int", paramType = "query", required = true),
            @ApiImplicitParam(name = "oldPassword", value = "老密码", dataType = "String", paramType = "query", required = true),
            @ApiImplicitParam(name = "password", value = "新密码", dataType = "String", paramType = "query", required = true),})
    public BaseResponse<Integer> updatePassword(Integer id, String oldPassword, String password) {
        return new BaseResponse<>(accountService.updatePassword(id, oldPassword, password));
    }

    /**
     * 重置密码
     *
     * @param id
     * @return
     */
    @PostMapping(value = "account/initPassword")
    @ApiOperation(value = "重置密码")
    @ApiImplicitParams({@ApiImplicitParam(name = "id", value = "主键", dataType = "int", paramType = "query", required = true)})
    public BaseResponse<Integer> updatePassword(Integer id) {
        return new BaseResponse<>(accountService.initPassword(id));
    }

    /**
     * 发送短信验证码
     *
     * @param phone
     * @return
     */
    @PostMapping(value = "account/sendCaptcha")
    @ApiOperation(value = "发送短信验证码")
    @ApiImplicitParams({@ApiImplicitParam(name = "phone", value = "手机号", dataType = "String", paramType = "query", required = true)})
    public BaseResponse<Object> updatePasswodByCaptcha(String phone) {
        Assert.notEmpty(phone, "phone不能为空");
        accountService.sendCaptcha(phone);
        return new BaseResponse<>();
    }

    /**
     * 通过短信验证码修改密码
     *
     * @param newPassword
     * @param captcha
     * @param phone
     * @return
     */
    @PostMapping(value = "account/updatePasswodByCaptcha")
    @ApiOperation(value = "通过短信验证码修改密码")
    @ApiImplicitParams({@ApiImplicitParam(name = "newPassword", value = "新密码", dataType = "String", paramType = "query", required = true),
            @ApiImplicitParam(name = "captcha", value = "验证码", dataType = "String", paramType = "query", required = true),
            @ApiImplicitParam(name = "phone", value = "手机号", dataType = "String", paramType = "query", required = true)})
    public BaseResponse<Object> updatePasswodByCaptcha(String newPassword, String captcha, String phone) {
        Assert.notEmpty(newPassword, "newPassword不能为空");
        Assert.notEmpty(captcha, "captcha不能为空");
        Assert.notEmpty(phone, "phone不能为空");
        accountService.resetPwd(newPassword, captcha, phone);
        return new BaseResponse<>();
    }

    /**
     * 根据账户id查询角色列表
     *
     * @param accountId 账户id
     * @return 角色列表
     */
    @GetMapping(value = "account/roleList")
    @ApiOperation(value = "根据账户id查询角色列表")
    @ApiImplicitParam(name = "accountId", value = "账户id", dataType = "int", paramType = "query", required = true)
    public BaseResponse<List<Role>> findAccountRoleList(String accountId) {
        return new BaseResponse<>(roleService.findAccountRoleList(accountId));
    }
}