拆分think模块包
This commit is contained in:
@@ -0,0 +1,178 @@
|
||||
package com.gxwebsoft.common.system.controller;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.gxwebsoft.common.core.security.JwtUtil;
|
||||
import com.gxwebsoft.common.core.utils.CommonUtil;
|
||||
import com.gxwebsoft.common.core.utils.RequestUtil;
|
||||
import com.gxwebsoft.common.core.web.ApiResult;
|
||||
import com.gxwebsoft.common.core.web.BaseController;
|
||||
import com.gxwebsoft.common.core.web.BatchParam;
|
||||
import com.gxwebsoft.common.core.web.PageResult;
|
||||
import com.gxwebsoft.common.system.entity.User;
|
||||
import com.gxwebsoft.common.system.entity.MerchantAccount;
|
||||
import com.gxwebsoft.common.system.entity.UserRole;
|
||||
import com.gxwebsoft.common.system.mapper.MerchantAccountMapper;
|
||||
import com.gxwebsoft.common.system.param.MerchantAccountParam;
|
||||
import com.gxwebsoft.common.system.service.MerchantAccountService;
|
||||
import com.gxwebsoft.common.system.service.UserRoleService;
|
||||
import com.gxwebsoft.common.system.service.UserService;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 商户账号控制器
|
||||
*
|
||||
* @author 科技小王子
|
||||
* @since 2024-04-19 12:02:24
|
||||
*/
|
||||
@Api(tags = "商户账号管理")
|
||||
@RestController
|
||||
@RequestMapping("/api/system/merchant-account")
|
||||
public class MerchantAccountController extends BaseController {
|
||||
@Resource
|
||||
private MerchantAccountService merchantAccountService;
|
||||
@Resource
|
||||
private MerchantAccountMapper merchantAccountMapper;
|
||||
@Resource
|
||||
private UserService userService;
|
||||
@Resource
|
||||
private UserRoleService userRoleService;
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:merchantAccount:list')")
|
||||
@ApiOperation("分页查询商户账号")
|
||||
@GetMapping("/page")
|
||||
public ApiResult<PageResult<MerchantAccount>> page(MerchantAccountParam param) {
|
||||
// 使用关联查询
|
||||
return success(merchantAccountService.pageRel(param));
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:merchantAccount:list')")
|
||||
@ApiOperation("查询全部商户账号")
|
||||
@GetMapping()
|
||||
public ApiResult<List<MerchantAccount>> list(MerchantAccountParam param) {
|
||||
// 使用关联查询
|
||||
return success(merchantAccountService.listRel(param));
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:merchantAccount:list')")
|
||||
@ApiOperation("根据id查询商户账号")
|
||||
@GetMapping("/{id}")
|
||||
public ApiResult<MerchantAccount> get(@PathVariable("id") Integer id) {
|
||||
// 使用关联查询
|
||||
return success(merchantAccountService.getByIdRel(id));
|
||||
}
|
||||
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:merchantAccount:save')")
|
||||
@ApiOperation("添加商户账号")
|
||||
@PostMapping()
|
||||
public ApiResult<?> save(@RequestBody MerchantAccount merchantAccount, HttpServletRequest request) {
|
||||
if (merchantAccountService.count(new LambdaQueryWrapper<MerchantAccount>().eq(MerchantAccount::getPhone,merchantAccount.getPhone())) > 0) {
|
||||
return fail("手机号码已存在");
|
||||
}
|
||||
// 查询用户是否已存在
|
||||
User userByPhone = userService.getByPhone(merchantAccount.getPhone());
|
||||
if (userByPhone != null){
|
||||
merchantAccount.setUserId(userByPhone.getUserId());
|
||||
if (userRoleService.count(new LambdaQueryWrapper<UserRole>().eq(UserRole::getRoleId,merchantAccount.getRoleId())) == 0) {
|
||||
// 添加角色
|
||||
final UserRole userRole = new UserRole();
|
||||
userRole.setUserId(userByPhone.getUserId());
|
||||
userRole.setRoleId(merchantAccount.getRoleId());
|
||||
userRoleService.save(userRole);
|
||||
}
|
||||
merchantAccountService.save(merchantAccount);
|
||||
return success("添加成功");
|
||||
}
|
||||
|
||||
// 添加用户
|
||||
User user = new User();
|
||||
user.setUsername(merchantAccount.getPhone());
|
||||
user.setPhone(merchantAccount.getPhone());
|
||||
user.setPassword(userService.encodePassword(merchantAccount.getPassword()));
|
||||
user.setNickname(merchantAccount.getRealName());
|
||||
user.setIsAdmin(true);
|
||||
user.setPlatform("ADMIN");
|
||||
user.setMerchantId(merchantAccount.getMerchantId());
|
||||
userService.save(user);
|
||||
// 添加角色
|
||||
final UserRole userRole = new UserRole();
|
||||
userRole.setUserId(user.getUserId());
|
||||
userRole.setRoleId(merchantAccount.getRoleId());
|
||||
userRoleService.save(userRole);
|
||||
merchantAccount.setUserId(user.getUserId());
|
||||
// 保存账号
|
||||
if (merchantAccountService.save(merchantAccount)) {
|
||||
return success("添加成功");
|
||||
}
|
||||
return fail("添加失败");
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:merchantAccount:update')")
|
||||
@ApiOperation("修改商户账号")
|
||||
@PutMapping()
|
||||
public ApiResult<?> update(@RequestBody MerchantAccount merchantAccount) {
|
||||
if (merchantAccountService.updateById(merchantAccount)) {
|
||||
return success("修改成功");
|
||||
}
|
||||
return fail("修改失败");
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:merchantAccount:remove')")
|
||||
@ApiOperation("删除商户账号")
|
||||
@DeleteMapping("/{id}")
|
||||
public ApiResult<?> remove(@PathVariable("id") Integer id) {
|
||||
if (merchantAccountService.removeById(id)) {
|
||||
return success("删除成功");
|
||||
}
|
||||
return fail("删除失败");
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:merchantAccount:save')")
|
||||
@ApiOperation("批量添加商户账号")
|
||||
@PostMapping("/batch")
|
||||
public ApiResult<?> saveBatch(@RequestBody List<MerchantAccount> list) {
|
||||
if (merchantAccountService.saveBatch(list)) {
|
||||
return success("添加成功");
|
||||
}
|
||||
return fail("添加失败");
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:merchantAccount:update')")
|
||||
@ApiOperation("批量修改商户账号")
|
||||
@PutMapping("/batch")
|
||||
public ApiResult<?> removeBatch(@RequestBody BatchParam<MerchantAccount> batchParam) {
|
||||
if (batchParam.update(merchantAccountService, "id")) {
|
||||
return success("修改成功");
|
||||
}
|
||||
return fail("修改失败");
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:merchantAccount:remove')")
|
||||
@ApiOperation("批量删除商户账号")
|
||||
@DeleteMapping("/batch")
|
||||
public ApiResult<?> removeBatch(@RequestBody List<Integer> ids) {
|
||||
if (merchantAccountService.removeByIds(ids)) {
|
||||
return success("删除成功");
|
||||
}
|
||||
return fail("删除失败");
|
||||
}
|
||||
|
||||
@ApiOperation("根据手机号码查询商户账号信息")
|
||||
@GetMapping("/getMerchantAccountByPhone")
|
||||
public ApiResult<MerchantAccount> getMerchantAccountByPhone(MerchantAccountParam param){
|
||||
param.setTenantId(getTenantId());
|
||||
final MerchantAccount merchantAccount = merchantAccountMapper.getMerchantAccountByPhone(param);
|
||||
if(merchantAccount == null){
|
||||
return fail("账号不存在",null);
|
||||
}
|
||||
return success(merchantAccount);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user