158 lines
4.6 KiB
Java
158 lines
4.6 KiB
Java
package com.cdzy.user.controller;
|
|
|
|
import cn.dev33.satoken.stp.StpUtil;
|
|
import com.cdzy.common.enums.Message;
|
|
import com.cdzy.common.model.JsonResult;
|
|
import com.cdzy.common.model.PageParam;
|
|
import com.cdzy.common.model.StaffDto;
|
|
import com.cdzy.user.model.entity.Staff;
|
|
import com.cdzy.user.model.vo.StaffIds;
|
|
import com.cdzy.user.service.StaffService;
|
|
import com.mybatisflex.core.paginate.Page;
|
|
import com.mybatisflex.core.query.QueryWrapper;
|
|
import jakarta.annotation.Resource;
|
|
import org.springframework.validation.annotation.Validated;
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
import java.util.List;
|
|
|
|
import static com.cdzy.user.model.entity.table.StaffTableDef.STAFF;
|
|
|
|
/**
|
|
* 员工控制层。
|
|
*
|
|
* @author attiya
|
|
* @since 2025-03-14
|
|
*/
|
|
@RestController
|
|
@RequestMapping("/staff")
|
|
public class StaffController {
|
|
|
|
@Resource
|
|
private StaffService staffService;
|
|
|
|
/**
|
|
* 添加。
|
|
*
|
|
* @param staff 员工信息
|
|
* @return {@code true} 添加成功,{@code false} 添加失败
|
|
*/
|
|
@PostMapping("save")
|
|
public JsonResult<?> save(@RequestBody Staff staff) {
|
|
QueryWrapper queryWrapper = QueryWrapper.create()
|
|
.where(STAFF.PHONE.eq(staff.getPhone()));
|
|
Staff one = staffService.getOne(queryWrapper);
|
|
if (one != null) {
|
|
return JsonResult.success(Message.REPEAT_PHONE);
|
|
}
|
|
staffService.save(staff);
|
|
return JsonResult.success();
|
|
}
|
|
|
|
/**
|
|
* 根据主键删除。
|
|
*
|
|
* @param id 主键
|
|
* @return {@code true} 删除成功,{@code false} 删除失败
|
|
*/
|
|
@DeleteMapping("remove/{id}")
|
|
public JsonResult<?> remove(@PathVariable("id") Long id) {
|
|
staffService.removeById(id);
|
|
return JsonResult.success();
|
|
}
|
|
|
|
/**
|
|
* 根据主键更新。
|
|
*
|
|
* @param staff 员工信息
|
|
* @return {@code true} 更新成功,{@code false} 更新失败
|
|
*/
|
|
@PostMapping("update")
|
|
public JsonResult<?> update(@RequestBody Staff staff) {
|
|
staffService.updateById(staff);
|
|
return JsonResult.success();
|
|
}
|
|
|
|
/**
|
|
* 查询所有。
|
|
*
|
|
* @return 所有数据
|
|
*/
|
|
@GetMapping("list")
|
|
public JsonResult<?> list() {
|
|
List<Staff> list = staffService.list();
|
|
return JsonResult.success(list);
|
|
}
|
|
|
|
/**
|
|
* 根据主键获取详细信息。
|
|
*
|
|
* @param id 主键
|
|
* @return 详情
|
|
*/
|
|
@GetMapping("getInfo/{id}")
|
|
public JsonResult<?> getInfo(@PathVariable("id") Long id) {
|
|
Staff staff = staffService.getById(id);
|
|
return JsonResult.success(staff);
|
|
}
|
|
|
|
/**
|
|
* 分页查询。
|
|
*
|
|
* @param pageParam 分页对象
|
|
* @return 分页对象
|
|
*/
|
|
@GetMapping("page")
|
|
public JsonResult<?> page(@Validated PageParam pageParam) {
|
|
Page<Staff> paged = staffService.page(pageParam.getPage());
|
|
return JsonResult.success(paged);
|
|
}
|
|
|
|
/**
|
|
* 根据凭证获取详细信息。
|
|
*
|
|
* @param token 凭证
|
|
* @return 详情
|
|
*/
|
|
@GetMapping("getInfoByToken")
|
|
public JsonResult<?> getInfo(@RequestParam("token") String token) {
|
|
Object loginId = StpUtil.getLoginIdByToken(token);
|
|
QueryWrapper queryWrapper = QueryWrapper.create()
|
|
.where(STAFF.STAFF_ID.eq(loginId));
|
|
StaffDto staff = staffService.getOneAs(queryWrapper, StaffDto.class);
|
|
return JsonResult.success(staff);
|
|
}
|
|
|
|
/**
|
|
* 批量查询员工信息。
|
|
*
|
|
* @param staffIds id集合
|
|
* @return 详情
|
|
*/
|
|
@PostMapping("getStaffsByIds")
|
|
public JsonResult<?> getStaffsByIds(@RequestBody @Validated StaffIds staffIds) {
|
|
QueryWrapper queryWrapper = QueryWrapper.create()
|
|
.where(STAFF.STAFF_ID.in(staffIds.getStaffIds()));
|
|
List<StaffDto> staffDtos = staffService.listAs(queryWrapper, StaffDto.class);
|
|
return JsonResult.success(staffDtos);
|
|
}
|
|
|
|
/**
|
|
* 批量查询员工信息。
|
|
*
|
|
* @param token 凭证
|
|
* @return 详情
|
|
*/
|
|
@PostMapping("getStaffsByLoginOrg")
|
|
public JsonResult<?> getStaffsByIds(@Validated PageParam pageParam, @RequestParam("token") String token) {
|
|
String id = (String)StpUtil.getLoginIdByToken(token);
|
|
StaffDto staffDto = (StaffDto)StpUtil.getSessionByLoginId(id).get(id);
|
|
QueryWrapper queryWrapper = QueryWrapper.create()
|
|
.where(STAFF.ORG_ID.eq(staffDto.getOrgId()))
|
|
.where(STAFF.STAFF_ID.ne(staffDto.getStaffId()));
|
|
Page<StaffDto> staffDtos = staffService.pageAs(pageParam.getPage(),queryWrapper, StaffDto.class);
|
|
return JsonResult.success(staffDtos);
|
|
}
|
|
|
|
}
|