运营商管理、角色管理优化
This commit is contained in:
parent
805244052a
commit
ad6c13ac99
@ -39,13 +39,7 @@ public class EbikeOperatorController {
|
||||
*/
|
||||
@PostMapping("save")
|
||||
public JsonResult<?> save(@Validated @RequestBody EbikeOperatorVo ebikeOperator) {
|
||||
EbikeOperator operator = EbikeOperator.builder()
|
||||
.operatorName(ebikeOperator.getOperatorName())
|
||||
.address(ebikeOperator.getAddress())
|
||||
.contactPhone(ebikeOperator.getContactPhone())
|
||||
.createBy(StpUtil.getLoginIdAsLong())
|
||||
.build();
|
||||
ebikeOperatorService.save(operator);
|
||||
ebikeOperatorService.saveOperator(ebikeOperator);
|
||||
return JsonResult.success();
|
||||
}
|
||||
|
||||
@ -55,7 +49,7 @@ public class EbikeOperatorController {
|
||||
* @param operatorId 主键
|
||||
* @return {@code true} 删除成功,{@code false} 删除失败
|
||||
*/
|
||||
@PostMapping("remove")
|
||||
@GetMapping("remove")
|
||||
public JsonResult<?> remove(@RequestParam("operatorId") Long operatorId) {
|
||||
ebikeOperatorService.removeById(operatorId);
|
||||
return JsonResult.success();
|
||||
|
||||
@ -3,12 +3,16 @@ package com.cdzy.staff.controller;
|
||||
import com.cdzy.common.model.request.PageParam;
|
||||
import com.cdzy.common.model.response.JsonResult;
|
||||
import com.cdzy.staff.model.entity.EbikeRole;
|
||||
import com.cdzy.staff.model.vo.EbikeRoleVo;
|
||||
import com.cdzy.staff.service.EbikeRoleService;
|
||||
import com.mybatisflex.core.paginate.Page;
|
||||
import com.mybatisflex.core.query.QueryWrapper;
|
||||
import com.mybatisflex.core.util.StringUtil;
|
||||
import jakarta.annotation.Resource;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.List;import static com.cdzy.staff.model.entity.table.EbikeRoleTableDef.EBIKE_ROLE;
|
||||
|
||||
/**
|
||||
* 员工角色表 控制层。
|
||||
@ -30,20 +34,20 @@ public class EbikeRoleController {
|
||||
* @return {@code true} 添加成功,{@code false} 添加失败
|
||||
*/
|
||||
@PostMapping("save")
|
||||
public JsonResult<?> save(@RequestBody EbikeRole ebikeRole) {
|
||||
ebikeRoleService.save(ebikeRole);
|
||||
public JsonResult<?> save(@Validated @RequestBody EbikeRoleVo ebikeRole) {
|
||||
ebikeRoleService.saveRole(ebikeRole);
|
||||
return JsonResult.success();
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据主键删除员工角色表。
|
||||
*
|
||||
* @param id 主键
|
||||
* @param roleId 角色主键
|
||||
* @return {@code true} 删除成功,{@code false} 删除失败
|
||||
*/
|
||||
@PostMapping("remove/{id}")
|
||||
public JsonResult<?> remove(@PathVariable Long id) {
|
||||
ebikeRoleService.removeById(id);
|
||||
@GetMapping("remove")
|
||||
public JsonResult<?> remove(@RequestParam("roleId") Long roleId) {
|
||||
ebikeRoleService.removeById(roleId);
|
||||
return JsonResult.success();
|
||||
}
|
||||
|
||||
@ -54,8 +58,8 @@ public class EbikeRoleController {
|
||||
* @return {@code true} 更新成功,{@code false} 更新失败
|
||||
*/
|
||||
@PostMapping("update")
|
||||
public JsonResult<?> update(@RequestBody EbikeRole ebikeRole) {
|
||||
ebikeRoleService.updateById(ebikeRole);
|
||||
public JsonResult<?> update(@Validated @RequestBody EbikeRoleVo ebikeRole) {
|
||||
ebikeRoleService.updateRole(ebikeRole);
|
||||
return JsonResult.success();
|
||||
}
|
||||
|
||||
@ -73,12 +77,11 @@ public class EbikeRoleController {
|
||||
/**
|
||||
* 根据员工角色表主键获取详细信息。
|
||||
*
|
||||
* @param id 员工角色表主键
|
||||
* @return 员工角色表详情
|
||||
*/
|
||||
@GetMapping("getInfo/{id}")
|
||||
public JsonResult<?> getInfo(@PathVariable Long id) {
|
||||
EbikeRole ebikeRole = ebikeRoleService.getById(id);
|
||||
@GetMapping("getInfo")
|
||||
public JsonResult<?> getInfo(@RequestParam("roleId") Long roleId) {
|
||||
EbikeRole ebikeRole = ebikeRoleService.getById(roleId);
|
||||
return JsonResult.success(ebikeRole);
|
||||
}
|
||||
|
||||
@ -89,8 +92,10 @@ public class EbikeRoleController {
|
||||
* @return 分页对象
|
||||
*/
|
||||
@GetMapping("page")
|
||||
public JsonResult<?> page(PageParam pageParam) {
|
||||
Page<EbikeRole> rolePage = ebikeRoleService.page(pageParam.getPage());
|
||||
public JsonResult<?> page(PageParam pageParam, String roleName) {
|
||||
QueryWrapper queryWrapper =QueryWrapper.create()
|
||||
.where(EBIKE_ROLE.ROLE_NAME.like(roleName, StringUtil.hasText(roleName)));
|
||||
Page<EbikeRole> rolePage = ebikeRoleService.page(pageParam.getPage(),queryWrapper);
|
||||
return JsonResult.success(rolePage);
|
||||
}
|
||||
|
||||
|
||||
@ -37,7 +37,7 @@ public class EbikeRole implements Serializable {
|
||||
private String roleName;
|
||||
|
||||
/**
|
||||
* 角色表示
|
||||
* 角色标识
|
||||
*/
|
||||
private String roleCode;
|
||||
|
||||
@ -65,10 +65,4 @@ public class EbikeRole implements Serializable {
|
||||
@Column(onInsertValue = "false")
|
||||
private Boolean sysAdmin;
|
||||
|
||||
@Column(onInsertValue = "false")
|
||||
private Boolean operatorAdmin;
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
@ -0,0 +1,52 @@
|
||||
package com.cdzy.staff.model.vo;
|
||||
|
||||
import jakarta.validation.constraints.NotBlank;
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import java.io.Serial;
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* 员工角色表 实体类。
|
||||
*
|
||||
* @author loves
|
||||
* @since 2025-08-08
|
||||
*/
|
||||
@Data
|
||||
@Builder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class EbikeRoleVo implements Serializable {
|
||||
|
||||
@Serial
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
private Long roleId;
|
||||
|
||||
/**
|
||||
* 角色名称
|
||||
*/
|
||||
@NotBlank(message = "角色名称不能为空")
|
||||
private String roleName;
|
||||
|
||||
/**
|
||||
* 角色标识
|
||||
*/
|
||||
@NotBlank(message = "角色标识不能为空")
|
||||
private String roleCode;
|
||||
|
||||
/**
|
||||
* 所属运营商
|
||||
*/
|
||||
@NotNull(message = "运营商ID不能为空")
|
||||
private Long operatorId;
|
||||
|
||||
/**
|
||||
* 描述
|
||||
*/
|
||||
private String description;
|
||||
}
|
||||
@ -13,4 +13,6 @@ import com.cdzy.staff.model.entity.EbikeOperator;
|
||||
public interface EbikeOperatorService extends IService<EbikeOperator> {
|
||||
|
||||
void updateOperator(EbikeOperatorVo ebikeOperator);
|
||||
|
||||
void saveOperator(EbikeOperatorVo ebikeOperator);
|
||||
}
|
||||
|
||||
@ -1,5 +1,6 @@
|
||||
package com.cdzy.staff.service;
|
||||
|
||||
import com.cdzy.staff.model.vo.EbikeRoleVo;
|
||||
import com.mybatisflex.core.service.IService;
|
||||
import com.cdzy.staff.model.entity.EbikeRole;
|
||||
|
||||
@ -11,4 +12,7 @@ import com.cdzy.staff.model.entity.EbikeRole;
|
||||
*/
|
||||
public interface EbikeRoleService extends IService<EbikeRole> {
|
||||
|
||||
void saveRole(EbikeRoleVo ebikeRole);
|
||||
|
||||
void updateRole(EbikeRoleVo ebikeRole);
|
||||
}
|
||||
|
||||
@ -6,10 +6,15 @@ import com.cdzy.staff.mapper.EbikeOperatorMapper;
|
||||
import com.cdzy.staff.model.entity.EbikeOperator;
|
||||
import com.cdzy.staff.model.vo.EbikeOperatorVo;
|
||||
import com.cdzy.staff.service.EbikeOperatorService;
|
||||
import com.mybatisflex.core.query.QueryWrapper;
|
||||
import com.mybatisflex.spring.service.impl.ServiceImpl;
|
||||
import jakarta.annotation.Resource;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
import static com.cdzy.staff.model.entity.table.EbikeOperatorTableDef.EBIKE_OPERATOR;
|
||||
|
||||
/**
|
||||
* 运营商信息表 服务层实现。
|
||||
*
|
||||
@ -32,14 +37,39 @@ public class EbikeOperatorServiceImpl extends ServiceImpl<EbikeOperatorMapper, E
|
||||
if (operatorOld == null){
|
||||
throw new EbikeException("该运营商不存在");
|
||||
}else {
|
||||
checkOperatorName(ebikeOperator);
|
||||
EbikeOperator operator = EbikeOperator.builder()
|
||||
.operatorId(operatorId)
|
||||
.operatorName(ebikeOperator.getOperatorName())
|
||||
.address(ebikeOperator.getAddress())
|
||||
.contactPhone(ebikeOperator.getContactPhone())
|
||||
.createBy((Long) StpUtil.getLoginId())
|
||||
.createBy(StpUtil.getLoginIdAsLong())
|
||||
.build();
|
||||
ebikeOperatorMapper.update(operator);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void saveOperator(EbikeOperatorVo ebikeOperator) {
|
||||
EbikeOperator operator = EbikeOperator.builder()
|
||||
.operatorName(ebikeOperator.getOperatorName())
|
||||
.address(ebikeOperator.getAddress())
|
||||
.contactPhone(ebikeOperator.getContactPhone())
|
||||
.createBy(StpUtil.getLoginIdAsLong())
|
||||
.build();
|
||||
ebikeOperatorMapper.insert(operator);
|
||||
}
|
||||
|
||||
public void checkOperatorName(EbikeOperatorVo ebikeOperator){
|
||||
QueryWrapper queryWrapper = QueryWrapper.create()
|
||||
.where(EBIKE_OPERATOR.OPERATOR_NAME.eq(ebikeOperator.getOperatorName()));
|
||||
EbikeOperator operator = ebikeOperatorMapper.selectOneByQuery(queryWrapper);
|
||||
if (operator != null){
|
||||
Long operatorId = ebikeOperator.getOperatorId();
|
||||
if (operatorId != null && !Objects.equals(operator.getOperatorId(), operatorId)){
|
||||
throw new EbikeException("该运营商名称已被占用");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,9 +1,15 @@
|
||||
package com.cdzy.staff.service.impl;
|
||||
|
||||
import com.cdzy.common.ex.EbikeException;
|
||||
import com.cdzy.staff.mapper.EbikeOperatorMapper;
|
||||
import com.cdzy.staff.model.entity.EbikeOperator;
|
||||
import com.cdzy.staff.model.vo.EbikeRoleVo;
|
||||
import com.mybatisflex.core.query.QueryWrapper;
|
||||
import com.mybatisflex.spring.service.impl.ServiceImpl;
|
||||
import com.cdzy.staff.model.entity.EbikeRole;
|
||||
import com.cdzy.staff.mapper.EbikeRoleMapper;
|
||||
import com.cdzy.staff.service.EbikeRoleService;
|
||||
import jakarta.annotation.Resource;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
/**
|
||||
@ -15,4 +21,63 @@ import org.springframework.stereotype.Service;
|
||||
@Service
|
||||
public class EbikeRoleServiceImpl extends ServiceImpl<EbikeRoleMapper, EbikeRole> implements EbikeRoleService {
|
||||
|
||||
@Resource
|
||||
private EbikeRoleMapper ebikeRoleMapper;
|
||||
|
||||
@Resource
|
||||
private EbikeOperatorMapper ebikeOperatorMapper;
|
||||
|
||||
@Override
|
||||
public void saveRole(EbikeRoleVo ebikeRole) {
|
||||
Long operatorId = ebikeRole.getOperatorId();
|
||||
checkOperator(operatorId);
|
||||
checkRoleCode(ebikeRole.getRoleCode());
|
||||
EbikeRole role = EbikeRole.builder()
|
||||
.roleName(ebikeRole.getRoleName())
|
||||
.operatorId(operatorId)
|
||||
.roleCode(ebikeRole.getRoleCode())
|
||||
.description(ebikeRole.getDescription())
|
||||
.build();
|
||||
ebikeRoleMapper.insert(role);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateRole(EbikeRoleVo ebikeRole) {
|
||||
Long operatorId = ebikeRole.getOperatorId();
|
||||
checkRole(ebikeRole.getRoleId());
|
||||
checkOperator(operatorId);
|
||||
checkRoleCode(ebikeRole.getRoleCode());
|
||||
EbikeRole role = EbikeRole.builder()
|
||||
.roleId(ebikeRole.getRoleId())
|
||||
.roleName(ebikeRole.getRoleName())
|
||||
.operatorId(operatorId)
|
||||
.roleCode(ebikeRole.getRoleCode())
|
||||
.description(ebikeRole.getDescription())
|
||||
.build();
|
||||
ebikeRoleMapper.update(role);
|
||||
}
|
||||
|
||||
public void checkOperator(Long operatorId){
|
||||
EbikeOperator ebikeOperator = ebikeOperatorMapper.selectOneById(operatorId);
|
||||
if (ebikeOperator == null) {
|
||||
throw new EbikeException("该运营商不存在");
|
||||
}
|
||||
}
|
||||
|
||||
public void checkRole(Long roleId){
|
||||
EbikeRole ebikeRole = ebikeRoleMapper.selectOneById(roleId);
|
||||
if (ebikeRole == null) {
|
||||
throw new EbikeException("该角色不存在");
|
||||
}
|
||||
}
|
||||
|
||||
public void checkRoleCode(String roleCode){
|
||||
QueryWrapper queryWrapper = QueryWrapper.create()
|
||||
.eq(EbikeRole::getRoleCode, roleCode);
|
||||
EbikeRole selected = ebikeRoleMapper.selectOneByQuery(queryWrapper);
|
||||
if (selected != null) {
|
||||
throw new EbikeException("该权限标识已被占用");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user