员工数据隔离、运营商功能实现
This commit is contained in:
parent
f61c8d4c84
commit
4e36ecb023
@ -1,11 +1,15 @@
|
|||||||
package com.cdzy.staff.controller;
|
package com.cdzy.staff.controller;
|
||||||
|
|
||||||
|
import cn.dev33.satoken.stp.StpUtil;
|
||||||
import com.cdzy.common.model.request.PageParam;
|
import com.cdzy.common.model.request.PageParam;
|
||||||
import com.cdzy.common.model.response.JsonResult;
|
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.entity.EbikeOperator;
|
||||||
|
import com.cdzy.staff.model.vo.EbikeOperatorVo;
|
||||||
import com.cdzy.staff.service.EbikeOperatorService;
|
import com.cdzy.staff.service.EbikeOperatorService;
|
||||||
import com.mybatisflex.core.paginate.Page;
|
import com.mybatisflex.core.paginate.Page;
|
||||||
import jakarta.annotation.Resource;
|
import jakarta.annotation.Resource;
|
||||||
|
import org.springframework.validation.annotation.Validated;
|
||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@ -30,20 +34,26 @@ public class EbikeOperatorController {
|
|||||||
* @return {@code true} 添加成功,{@code false} 添加失败
|
* @return {@code true} 添加成功,{@code false} 添加失败
|
||||||
*/
|
*/
|
||||||
@PostMapping("save")
|
@PostMapping("save")
|
||||||
public JsonResult<?> save(@RequestBody EbikeOperator ebikeOperator) {
|
public JsonResult<?> save(@Validated @RequestBody EbikeOperatorVo ebikeOperator) {
|
||||||
ebikeOperatorService.save(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();
|
return JsonResult.success();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 根据主键删除运营商信息表。
|
* 根据主键删除运营商信息表。
|
||||||
*
|
*
|
||||||
* @param id 主键
|
* @param operatorId 主键
|
||||||
* @return {@code true} 删除成功,{@code false} 删除失败
|
* @return {@code true} 删除成功,{@code false} 删除失败
|
||||||
*/
|
*/
|
||||||
@PostMapping("remove/{id}")
|
@PostMapping("remove")
|
||||||
public JsonResult<?> remove(@PathVariable Long id) {
|
public JsonResult<?> remove(@RequestParam("operatorId") Long operatorId) {
|
||||||
ebikeOperatorService.removeById(id);
|
ebikeOperatorService.removeById(operatorId);
|
||||||
return JsonResult.success();
|
return JsonResult.success();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -54,8 +64,8 @@ public class EbikeOperatorController {
|
|||||||
* @return {@code true} 更新成功,{@code false} 更新失败
|
* @return {@code true} 更新成功,{@code false} 更新失败
|
||||||
*/
|
*/
|
||||||
@PostMapping("update")
|
@PostMapping("update")
|
||||||
public JsonResult<?> update(@RequestBody EbikeOperator ebikeOperator) {
|
public JsonResult<?> update(@Validated @RequestBody EbikeOperatorVo ebikeOperator) {
|
||||||
ebikeOperatorService.updateById(ebikeOperator);
|
ebikeOperatorService.updateOperator(ebikeOperator);
|
||||||
return JsonResult.success();
|
return JsonResult.success();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -70,14 +80,15 @@ public class EbikeOperatorController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 根据运营商信息表主键获取详细信息。
|
* 根据Token获取运营商信息详细信息。
|
||||||
*
|
*
|
||||||
* @param id 运营商信息表主键
|
|
||||||
* @return 运营商信息表详情
|
* @return 运营商信息表详情
|
||||||
*/
|
*/
|
||||||
@GetMapping("getInfo/{id}")
|
@GetMapping("getInfo")
|
||||||
public JsonResult<?> getInfo(@PathVariable Long id) {
|
public JsonResult<?> getInfo() {
|
||||||
EbikeOperator ebikeOperatorServiceById = ebikeOperatorService.getById(id);
|
String loginId = (String) StpUtil.getLoginId();
|
||||||
|
StaffInfo staffInfo = (StaffInfo) StpUtil.getSession().get(loginId);
|
||||||
|
EbikeOperator ebikeOperatorServiceById = ebikeOperatorService.getById(staffInfo.getOperatorId());
|
||||||
return JsonResult.success(ebikeOperatorServiceById);
|
return JsonResult.success(ebikeOperatorServiceById);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -85,12 +96,12 @@ public class EbikeOperatorController {
|
|||||||
/**
|
/**
|
||||||
* 运营商详细信息。
|
* 运营商详细信息。
|
||||||
*
|
*
|
||||||
* @param id 运营商信息表主键
|
* @param operatorId 运营商信息表主键
|
||||||
* @return 运营商信息表详情
|
* @return 运营商信息表详情
|
||||||
*/
|
*/
|
||||||
@GetMapping("getInfo")
|
@GetMapping("getInfo")
|
||||||
public JsonResult<?> getInfoById(Long id) {
|
public JsonResult<?> getInfoById(@RequestParam("operatorId") Long operatorId) {
|
||||||
EbikeOperator ebikeOperatorServiceById = ebikeOperatorService.getById(id);
|
EbikeOperator ebikeOperatorServiceById = ebikeOperatorService.getById(operatorId);
|
||||||
return JsonResult.success(ebikeOperatorServiceById);
|
return JsonResult.success(ebikeOperatorServiceById);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -2,7 +2,6 @@ package com.cdzy.staff.model.entity;
|
|||||||
|
|
||||||
import com.mybatisflex.annotation.Column;
|
import com.mybatisflex.annotation.Column;
|
||||||
import com.mybatisflex.annotation.Id;
|
import com.mybatisflex.annotation.Id;
|
||||||
import com.mybatisflex.annotation.KeyType;
|
|
||||||
import com.mybatisflex.annotation.Table;
|
import com.mybatisflex.annotation.Table;
|
||||||
import lombok.AllArgsConstructor;
|
import lombok.AllArgsConstructor;
|
||||||
import lombok.Builder;
|
import lombok.Builder;
|
||||||
@ -31,6 +30,7 @@ public class EbikeOperator implements Serializable {
|
|||||||
private static final long serialVersionUID = 1L;
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
@Id
|
@Id
|
||||||
|
@Column(tenantId = true)
|
||||||
private Long operatorId;
|
private Long operatorId;
|
||||||
|
|
||||||
private String name;
|
private String name;
|
||||||
|
|||||||
@ -37,6 +37,7 @@ public class EbikeOperatorStaff implements Serializable {
|
|||||||
|
|
||||||
private String salt;
|
private String salt;
|
||||||
|
|
||||||
|
@Column(tenantId = true)
|
||||||
private Long operatorId;
|
private Long operatorId;
|
||||||
|
|
||||||
private Integer status;
|
private Integer status;
|
||||||
|
|||||||
@ -2,7 +2,6 @@ package com.cdzy.staff.model.entity;
|
|||||||
|
|
||||||
import com.mybatisflex.annotation.Column;
|
import com.mybatisflex.annotation.Column;
|
||||||
import com.mybatisflex.annotation.Id;
|
import com.mybatisflex.annotation.Id;
|
||||||
import com.mybatisflex.annotation.KeyType;
|
|
||||||
import com.mybatisflex.annotation.Table;
|
import com.mybatisflex.annotation.Table;
|
||||||
import lombok.AllArgsConstructor;
|
import lombok.AllArgsConstructor;
|
||||||
import lombok.Builder;
|
import lombok.Builder;
|
||||||
@ -34,6 +33,7 @@ public class EbikeRole implements Serializable {
|
|||||||
|
|
||||||
private String roleName;
|
private String roleName;
|
||||||
|
|
||||||
|
@Column(tenantId = true)
|
||||||
private Long operatorId;
|
private Long operatorId;
|
||||||
|
|
||||||
private String description;
|
private String description;
|
||||||
|
|||||||
@ -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;
|
||||||
|
}
|
||||||
@ -1,5 +1,6 @@
|
|||||||
package com.cdzy.staff.service;
|
package com.cdzy.staff.service;
|
||||||
|
|
||||||
|
import com.cdzy.staff.model.vo.EbikeOperatorVo;
|
||||||
import com.mybatisflex.core.service.IService;
|
import com.mybatisflex.core.service.IService;
|
||||||
import com.cdzy.staff.model.entity.EbikeOperator;
|
import com.cdzy.staff.model.entity.EbikeOperator;
|
||||||
|
|
||||||
@ -11,4 +12,5 @@ import com.cdzy.staff.model.entity.EbikeOperator;
|
|||||||
*/
|
*/
|
||||||
public interface EbikeOperatorService extends IService<EbikeOperator> {
|
public interface EbikeOperatorService extends IService<EbikeOperator> {
|
||||||
|
|
||||||
|
void updateOperator(EbikeOperatorVo ebikeOperator);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,9 +1,13 @@
|
|||||||
package com.cdzy.staff.service.impl;
|
package com.cdzy.staff.service.impl;
|
||||||
|
|
||||||
import com.mybatisflex.spring.service.impl.ServiceImpl;
|
import cn.dev33.satoken.stp.StpUtil;
|
||||||
import com.cdzy.staff.model.entity.EbikeOperator;
|
import com.cdzy.common.ex.EbikeException;
|
||||||
import com.cdzy.staff.mapper.EbikeOperatorMapper;
|
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.cdzy.staff.service.EbikeOperatorService;
|
||||||
|
import com.mybatisflex.spring.service.impl.ServiceImpl;
|
||||||
|
import jakarta.annotation.Resource;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -15,4 +19,27 @@ import org.springframework.stereotype.Service;
|
|||||||
@Service
|
@Service
|
||||||
public class EbikeOperatorServiceImpl extends ServiceImpl<EbikeOperatorMapper, EbikeOperator> implements EbikeOperatorService{
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user