员工数据隔离、运营商功能实现

This commit is contained in:
attiya 2025-09-03 09:35:01 +08:00
parent f61c8d4c84
commit 4e36ecb023
7 changed files with 94 additions and 20 deletions

View File

@ -1,11 +1,15 @@
package com.cdzy.staff.controller;
import cn.dev33.satoken.stp.StpUtil;
import com.cdzy.common.model.request.PageParam;
import com.cdzy.common.model.response.JsonResult;
import com.cdzy.staff.model.dto.StaffInfo;
import com.cdzy.staff.model.entity.EbikeOperator;
import com.cdzy.staff.model.vo.EbikeOperatorVo;
import com.cdzy.staff.service.EbikeOperatorService;
import com.mybatisflex.core.paginate.Page;
import jakarta.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import java.util.List;
@ -30,20 +34,26 @@ public class EbikeOperatorController {
* @return {@code true} 添加成功{@code false} 添加失败
*/
@PostMapping("save")
public JsonResult<?> save(@RequestBody EbikeOperator ebikeOperator) {
ebikeOperatorService.save(ebikeOperator);
public JsonResult<?> save(@Validated @RequestBody EbikeOperatorVo ebikeOperator) {
EbikeOperator operator = EbikeOperator.builder()
.name(ebikeOperator.getName())
.address(ebikeOperator.getAddress())
.contactPhone(ebikeOperator.getContactPhone())
.createBy((Long) StpUtil.getLoginId())
.build();
ebikeOperatorService.save(operator);
return JsonResult.success();
}
/**
* 根据主键删除运营商信息表
*
* @param id 主键
* @param operatorId 主键
* @return {@code true} 删除成功{@code false} 删除失败
*/
@PostMapping("remove/{id}")
public JsonResult<?> remove(@PathVariable Long id) {
ebikeOperatorService.removeById(id);
@PostMapping("remove")
public JsonResult<?> remove(@RequestParam("operatorId") Long operatorId) {
ebikeOperatorService.removeById(operatorId);
return JsonResult.success();
}
@ -54,8 +64,8 @@ public class EbikeOperatorController {
* @return {@code true} 更新成功{@code false} 更新失败
*/
@PostMapping("update")
public JsonResult<?> update(@RequestBody EbikeOperator ebikeOperator) {
ebikeOperatorService.updateById(ebikeOperator);
public JsonResult<?> update(@Validated @RequestBody EbikeOperatorVo ebikeOperator) {
ebikeOperatorService.updateOperator(ebikeOperator);
return JsonResult.success();
}
@ -70,14 +80,15 @@ public class EbikeOperatorController {
}
/**
* 根据运营商信息表主键获取详细信息
* 根据Token获取运营商信息详细信息
*
* @param id 运营商信息表主键
* @return 运营商信息表详情
*/
@GetMapping("getInfo/{id}")
public JsonResult<?> getInfo(@PathVariable Long id) {
EbikeOperator ebikeOperatorServiceById = ebikeOperatorService.getById(id);
@GetMapping("getInfo")
public JsonResult<?> getInfo() {
String loginId = (String) StpUtil.getLoginId();
StaffInfo staffInfo = (StaffInfo) StpUtil.getSession().get(loginId);
EbikeOperator ebikeOperatorServiceById = ebikeOperatorService.getById(staffInfo.getOperatorId());
return JsonResult.success(ebikeOperatorServiceById);
}
@ -85,12 +96,12 @@ public class EbikeOperatorController {
/**
* 运营商详细信息
*
* @param id 运营商信息表主键
* @param operatorId 运营商信息表主键
* @return 运营商信息表详情
*/
@GetMapping("getInfo")
public JsonResult<?> getInfoById(Long id) {
EbikeOperator ebikeOperatorServiceById = ebikeOperatorService.getById(id);
public JsonResult<?> getInfoById(@RequestParam("operatorId") Long operatorId) {
EbikeOperator ebikeOperatorServiceById = ebikeOperatorService.getById(operatorId);
return JsonResult.success(ebikeOperatorServiceById);
}

View File

@ -2,7 +2,6 @@ package com.cdzy.staff.model.entity;
import com.mybatisflex.annotation.Column;
import com.mybatisflex.annotation.Id;
import com.mybatisflex.annotation.KeyType;
import com.mybatisflex.annotation.Table;
import lombok.AllArgsConstructor;
import lombok.Builder;
@ -31,6 +30,7 @@ public class EbikeOperator implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@Column(tenantId = true)
private Long operatorId;
private String name;

View File

@ -37,6 +37,7 @@ public class EbikeOperatorStaff implements Serializable {
private String salt;
@Column(tenantId = true)
private Long operatorId;
private Integer status;

View File

@ -2,7 +2,6 @@ package com.cdzy.staff.model.entity;
import com.mybatisflex.annotation.Column;
import com.mybatisflex.annotation.Id;
import com.mybatisflex.annotation.KeyType;
import com.mybatisflex.annotation.Table;
import lombok.AllArgsConstructor;
import lombok.Builder;
@ -34,6 +33,7 @@ public class EbikeRole implements Serializable {
private String roleName;
@Column(tenantId = true)
private Long operatorId;
private String description;

View File

@ -0,0 +1,33 @@
package com.cdzy.staff.model.vo;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.Pattern;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.io.Serial;
import java.io.Serializable;
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class EbikeOperatorVo implements Serializable {
@Serial
private static final long serialVersionUID = 1L;
private Long operatorId;
@NotBlank(message = "运营商名称不能为空")
private String name;
@NotBlank(message = "运营商地址不能为空")
private String address;
@NotBlank(message = "运营商联系手机号不能为空")
@Pattern(regexp = "^1[3-9]\\d{9}$", message = "联系手机号格式错误")
private String contactPhone;
}

View File

@ -1,5 +1,6 @@
package com.cdzy.staff.service;
import com.cdzy.staff.model.vo.EbikeOperatorVo;
import com.mybatisflex.core.service.IService;
import com.cdzy.staff.model.entity.EbikeOperator;
@ -11,4 +12,5 @@ import com.cdzy.staff.model.entity.EbikeOperator;
*/
public interface EbikeOperatorService extends IService<EbikeOperator> {
void updateOperator(EbikeOperatorVo ebikeOperator);
}

View File

@ -1,9 +1,13 @@
package com.cdzy.staff.service.impl;
import com.mybatisflex.spring.service.impl.ServiceImpl;
import com.cdzy.staff.model.entity.EbikeOperator;
import cn.dev33.satoken.stp.StpUtil;
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.EbikeOperatorVo;
import com.cdzy.staff.service.EbikeOperatorService;
import com.mybatisflex.spring.service.impl.ServiceImpl;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;
/**
@ -15,4 +19,27 @@ import org.springframework.stereotype.Service;
@Service
public class EbikeOperatorServiceImpl extends ServiceImpl<EbikeOperatorMapper, EbikeOperator> implements EbikeOperatorService{
@Resource
private EbikeOperatorMapper ebikeOperatorMapper;
@Override
public void updateOperator(EbikeOperatorVo ebikeOperator) {
Long operatorId = ebikeOperator.getOperatorId();
if (operatorId == null){
throw new EbikeException("运营商ID不能为空");
}else {
EbikeOperator operatorOld = ebikeOperatorMapper.selectOneById(operatorId);
if (operatorOld == null){
throw new EbikeException("该运营商不存在");
}else {
EbikeOperator operator = EbikeOperator.builder()
.name(ebikeOperator.getName())
.address(ebikeOperator.getAddress())
.contactPhone(ebikeOperator.getContactPhone())
.createBy((Long) StpUtil.getLoginId())
.build();
ebikeOperatorMapper.update(operator);
}
}
}
}