|
@@ -1,6 +1,5 @@
|
|
|
package org.jeecg.modules.system.app.controller;
|
|
|
|
|
|
-import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
import io.swagger.v3.oas.annotations.Operation;
|
|
@@ -8,23 +7,28 @@ import io.swagger.v3.oas.annotations.tags.Tag;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import me.zhyd.oauth.utils.UuidUtils;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
+import org.apache.shiro.SecurityUtils;
|
|
|
import org.apache.shiro.authz.annotation.RequiresPermissions;
|
|
|
import org.jeecg.common.api.vo.Result;
|
|
|
import org.jeecg.common.aspect.annotation.AutoLog;
|
|
|
import org.jeecg.common.constant.CommonConstant;
|
|
|
import org.jeecg.common.system.base.controller.JeecgController;
|
|
|
-import org.jeecg.common.system.query.QueryGenerator;
|
|
|
+import org.jeecg.common.system.vo.LoginUser;
|
|
|
import org.jeecg.common.util.PasswordUtil;
|
|
|
import org.jeecg.common.util.oConvertUtils;
|
|
|
import org.jeecg.modules.base.service.BaseCommonService;
|
|
|
import org.jeecg.modules.system.app.entity.AppInstructor;
|
|
|
import org.jeecg.modules.system.app.service.IAppInstructorService;
|
|
|
+import org.jeecg.modules.system.app.vo.staff.StaffRequestVO;
|
|
|
+import org.jeecg.modules.system.app.vo.staff.StaffResponseVO;
|
|
|
import org.jeecg.modules.system.app.vo.staff.StaffSaveVO;
|
|
|
+import org.jeecg.modules.system.app.vo.staff.StaffVO;
|
|
|
import org.jeecg.modules.system.entity.SysDepart;
|
|
|
import org.jeecg.modules.system.entity.SysUser;
|
|
|
import org.jeecg.modules.system.service.ISysDepartService;
|
|
|
import org.jeecg.modules.system.service.ISysUserService;
|
|
|
import org.springframework.beans.BeanUtils;
|
|
|
+import org.springframework.beans.BeansException;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
@@ -57,7 +61,7 @@ public class AppInstructorController extends JeecgController<AppInstructor, IApp
|
|
|
/**
|
|
|
* 分页列表查询
|
|
|
*
|
|
|
- * @param appInstructor
|
|
|
+ * @param staffRequestVO
|
|
|
* @param pageNo
|
|
|
* @param pageSize
|
|
|
* @param req
|
|
@@ -66,15 +70,14 @@ public class AppInstructorController extends JeecgController<AppInstructor, IApp
|
|
|
//@AutoLog(value = "教练表-分页列表查询")
|
|
|
@Operation(summary="员工信息-分页列表查询")
|
|
|
@GetMapping(value = "/list")
|
|
|
- public Result<IPage<AppInstructor>> queryPageList(AppInstructor appInstructor,
|
|
|
- @RequestParam(name="pageNo", defaultValue="1") Integer pageNo,
|
|
|
- @RequestParam(name="pageSize", defaultValue="10") Integer pageSize,
|
|
|
- HttpServletRequest req) {
|
|
|
+ public Result<IPage<StaffResponseVO>> queryPageList(StaffRequestVO staffRequestVO,
|
|
|
+ @RequestParam(name="pageNo", defaultValue="1") Integer pageNo,
|
|
|
+ @RequestParam(name="pageSize", defaultValue="10") Integer pageSize,
|
|
|
+ HttpServletRequest req) {
|
|
|
|
|
|
-
|
|
|
- QueryWrapper<AppInstructor> queryWrapper = QueryGenerator.initQueryWrapper(appInstructor, req.getParameterMap());
|
|
|
+ LoginUser loginUser = (LoginUser) SecurityUtils.getSubject().getPrincipal();
|
|
|
Page<AppInstructor> page = new Page<AppInstructor>(pageNo, pageSize);
|
|
|
- IPage<AppInstructor> pageList = appInstructorService.page(page, queryWrapper);
|
|
|
+ IPage<StaffResponseVO> pageList = appInstructorService.findPage(page, staffRequestVO,loginUser.getOrgCode());
|
|
|
return Result.OK(pageList);
|
|
|
}
|
|
|
|
|
@@ -90,44 +93,61 @@ public class AppInstructorController extends JeecgController<AppInstructor, IApp
|
|
|
@PostMapping(value = "/add")
|
|
|
@Transactional
|
|
|
public Result<String> add(@RequestBody StaffSaveVO staffSaveVO) {
|
|
|
- SysUser user = new SysUser();
|
|
|
- AppInstructor appInstructor = new AppInstructor();
|
|
|
- if (StringUtils.isEmpty(staffSaveVO.getSelectedroles())){
|
|
|
- return Result.error("角色权限为空");
|
|
|
- }
|
|
|
- if (StringUtils.isEmpty(staffSaveVO.getSelecteddeparts())){
|
|
|
- return Result.error("所属部门为空");
|
|
|
- }
|
|
|
- if (staffSaveVO.getSelectedroles().indexOf("instructor")==0){
|
|
|
- if (staffSaveVO.getSelecteddeparts().contains(",")){
|
|
|
- return Result.error("该角色涉及教练,不允许多部门");
|
|
|
- }
|
|
|
- }
|
|
|
- SysDepart departById = sysDepartService.getDepartById(staffSaveVO.getSelecteddeparts());
|
|
|
try {
|
|
|
- BeanUtils.copyProperties(staffSaveVO,user);
|
|
|
- user.setId(UuidUtils.getUUID());
|
|
|
- user.setCreateTime(new Date());//设置创建时间
|
|
|
- String salt = oConvertUtils.randomGen(8);
|
|
|
- user.setSalt(salt);
|
|
|
- String passwordEncode = PasswordUtil.encrypt(user.getUsername(), user.getPassword(), salt);
|
|
|
- user.setPassword(passwordEncode);
|
|
|
- user.setStatus(1);
|
|
|
- user.setDelFlag(CommonConstant.DEL_FLAG_0);
|
|
|
- user.setUserIdentity(CommonConstant.USER_IDENTITY_1);
|
|
|
- //用户表字段org_code不能在这里设置他的值
|
|
|
- user.setOrgCode(departById.getOrgCode());
|
|
|
- // 保存用户走一个service 保证事务
|
|
|
- sysUserService.saveUser(user, staffSaveVO.getSelectedroles(), staffSaveVO.getSelecteddeparts(), null);
|
|
|
- baseCommonService.addLog("添加用户,username: " +user.getUsername() ,CommonConstant.LOG_TYPE_2, 2);
|
|
|
- } catch (Exception e) {
|
|
|
- log.error(e.getMessage(), e);
|
|
|
+ SysUser user = new SysUser();
|
|
|
+ AppInstructor appInstructor = new AppInstructor();
|
|
|
+ if (StringUtils.isEmpty(staffSaveVO.getSelectedroles())){
|
|
|
+ return Result.error("角色权限为空");
|
|
|
+ }
|
|
|
+ if (StringUtils.isEmpty(staffSaveVO.getSelecteddeparts())){
|
|
|
+ return Result.error("所属部门为空");
|
|
|
+ }
|
|
|
+ SysDepart departById =null;
|
|
|
+ if (staffSaveVO.getSelectedroles().indexOf("instructor")==0){
|
|
|
+ if (staffSaveVO.getSelecteddeparts().contains(",")){
|
|
|
+ return Result.error("该角色涉及教练,不允许多部门");
|
|
|
+ }
|
|
|
+ departById = sysDepartService.getDepartById(staffSaveVO.getSelecteddeparts());
|
|
|
+ }else {
|
|
|
+ String dept=null;
|
|
|
+ if (staffSaveVO.getSelecteddeparts().indexOf(",")>0){
|
|
|
+ dept=staffSaveVO.getSelecteddeparts().split(",")[0];
|
|
|
+ }else {
|
|
|
+ dept=staffSaveVO.getSelecteddeparts();
|
|
|
+ }
|
|
|
+ departById = sysDepartService.getDepartById(dept);
|
|
|
+ }
|
|
|
+ LoginUser loginUser = (LoginUser) SecurityUtils.getSubject().getPrincipal();
|
|
|
+ try {
|
|
|
+ BeanUtils.copyProperties(staffSaveVO,user);
|
|
|
+ user.setId(UuidUtils.getUUID());
|
|
|
+ user.setCreateBy(loginUser.getUsername());
|
|
|
+ user.setCreateTime(new Date());//设置创建时间
|
|
|
+ String salt = oConvertUtils.randomGen(8);
|
|
|
+ user.setSalt(salt);
|
|
|
+ String passwordEncode = PasswordUtil.encrypt(user.getUsername(), user.getPassword(), salt);
|
|
|
+ user.setPassword(passwordEncode);
|
|
|
+ user.setStatus(1);
|
|
|
+ user.setDelFlag(CommonConstant.DEL_FLAG_0);
|
|
|
+ user.setUserIdentity(CommonConstant.USER_IDENTITY_1);
|
|
|
+ //用户表字段org_code不能在这里设置他的值
|
|
|
+ user.setOrgCode(departById.getOrgCode());
|
|
|
+ // 保存用户走一个service 保证事务
|
|
|
+ sysUserService.saveUser(user, staffSaveVO.getSelectedroles(), staffSaveVO.getSelecteddeparts(), null);
|
|
|
+ baseCommonService.addLog("添加用户,username: " +user.getUsername() ,CommonConstant.LOG_TYPE_2, 2);
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error(e.getMessage(), e);
|
|
|
+ return Result.error("添加失败!");
|
|
|
+ }
|
|
|
+ BeanUtils.copyProperties(staffSaveVO,appInstructor);
|
|
|
+ appInstructor.setId(UuidUtils.getUUID());
|
|
|
+ appInstructor.setUserId(user.getId());
|
|
|
+ appInstructor.setDelFlag(CommonConstant.DEL_FLAG_0);
|
|
|
+ appInstructorService.save(appInstructor);
|
|
|
+ } catch (BeansException e) {
|
|
|
+ e.getMessage();
|
|
|
return Result.error("添加失败!");
|
|
|
}
|
|
|
- BeanUtils.copyProperties(staffSaveVO,appInstructor);
|
|
|
- appInstructor.setUserId(user.getId());
|
|
|
- appInstructor.setDelFlag(CommonConstant.DEL_FLAG_0);
|
|
|
- appInstructorService.save(appInstructor);
|
|
|
return Result.OK("添加成功!");
|
|
|
}
|
|
|
|
|
@@ -141,12 +161,72 @@ public class AppInstructorController extends JeecgController<AppInstructor, IApp
|
|
|
@Operation(summary="员工信息-编辑")
|
|
|
@RequiresPermissions("staff:edit")
|
|
|
@RequestMapping(value = "/edit", method = {RequestMethod.PUT,RequestMethod.POST})
|
|
|
+ @Transactional
|
|
|
public Result<String> edit(@RequestBody StaffSaveVO staffSaveVO) {
|
|
|
- if (staffSaveVO==null||StringUtils.isEmpty(staffSaveVO.getId())){
|
|
|
- return Result.error("编辑失败!请选择需要编辑的员工信息。");
|
|
|
+ try {
|
|
|
+ if (staffSaveVO==null||StringUtils.isEmpty(staffSaveVO.getId())){
|
|
|
+ return Result.error("编辑失败!请选择需要编辑的员工信息。");
|
|
|
+ }
|
|
|
+ StaffVO staffVO =sysUserService.findByUserIdStaff(staffSaveVO.getId());
|
|
|
+ if (staffVO==null){
|
|
|
+ return Result.error("编辑失败!未查询到需要编辑的员工信息。");
|
|
|
+ }
|
|
|
+ if (StringUtils.isEmpty(staffVO.getStaffId())){
|
|
|
+ return Result.error("编辑失败!未知员工信息");
|
|
|
+ }
|
|
|
+ if (StringUtils.isEmpty(staffSaveVO.getSelectedroles())){
|
|
|
+ return Result.error("角色权限为空");
|
|
|
+ }
|
|
|
+ if (StringUtils.isEmpty(staffSaveVO.getSelecteddeparts())){
|
|
|
+ return Result.error("所属部门为空");
|
|
|
+ }
|
|
|
+ SysDepart departById =null;
|
|
|
+ if (staffSaveVO.getSelectedroles().indexOf("instructor")==0){
|
|
|
+ if (staffSaveVO.getSelecteddeparts().contains(",")){
|
|
|
+ return Result.error("该角色涉及教练,不允许多部门");
|
|
|
+ }
|
|
|
+ departById = sysDepartService.getDepartById(staffSaveVO.getSelecteddeparts());
|
|
|
+ }else {
|
|
|
+ String dept=null;
|
|
|
+ if (staffSaveVO.getSelecteddeparts().indexOf(",")>0){
|
|
|
+ dept=staffSaveVO.getSelecteddeparts().split(",")[0];
|
|
|
+ }else {
|
|
|
+ dept=staffSaveVO.getSelecteddeparts();
|
|
|
+ }
|
|
|
+ departById = sysDepartService.getDepartById(dept);
|
|
|
+ }
|
|
|
+ LoginUser loginUser = (LoginUser) SecurityUtils.getSubject().getPrincipal();
|
|
|
+ SysUser sysUser = new SysUser();
|
|
|
+ BeanUtils.copyProperties(staffSaveVO,sysUser);
|
|
|
+ sysUser.setId(staffVO.getStaffId());
|
|
|
+ sysUser.setOrgCode(departById.getOrgCode());
|
|
|
+ sysUser.setUpdateBy(loginUser.getUsername());
|
|
|
+ sysUser.setUpdateTime(new Date());
|
|
|
+ sysUserService.editUser(sysUser, staffSaveVO.getSelectedroles(), staffSaveVO.getSelecteddeparts(), null, null);
|
|
|
+ boolean fal=StringUtils.isNotEmpty(staffVO.getInstructorId());
|
|
|
+ AppInstructor appInstructor = new AppInstructor();
|
|
|
+ BeanUtils.copyProperties(staffSaveVO,appInstructor);
|
|
|
+ if (staffSaveVO.getSelectedroles().indexOf("instructor")==0&&fal){
|
|
|
+ appInstructor.setId(staffVO.getInstructorId());
|
|
|
+ appInstructor.setUpdateBy(loginUser.getUsername());
|
|
|
+ appInstructor.setUpdateTime(new Date());
|
|
|
+ appInstructorService.updateById(appInstructor);
|
|
|
+ }else if (staffSaveVO.getSelectedroles().indexOf("instructor")==0&&!fal){
|
|
|
+ appInstructor.setId(UuidUtils.getUUID());
|
|
|
+ appInstructor.setUserId(sysUser.getId());
|
|
|
+ appInstructor.setDelFlag(CommonConstant.DEL_FLAG_0);
|
|
|
+ appInstructorService.save(appInstructor);
|
|
|
+ }else if (staffSaveVO.getSelectedroles().indexOf("instructor")!=0&&fal){
|
|
|
+ appInstructor.setId(staffVO.getInstructorId());
|
|
|
+ appInstructor.setDelFlag(CommonConstant.DEL_FLAG_1);
|
|
|
+ appInstructor.setUpdateBy(loginUser.getUsername());
|
|
|
+ appInstructor.setUpdateTime(new Date());
|
|
|
+ appInstructorService.updateById(appInstructor);
|
|
|
+ }
|
|
|
+ } catch (BeansException e) {
|
|
|
+ e.getMessage();
|
|
|
+ return Result.error("编辑失败!");
|
|
|
}
|
|
|
-// sysUserService.findByUserIdStaff(staffSaveVO.getId());
|
|
|
-// appInstructorService.updateById(appInstructor);
|
|
|
return Result.OK("编辑成功!");
|
|
|
}
|
|
|
|
|
@@ -160,8 +240,32 @@ public class AppInstructorController extends JeecgController<AppInstructor, IApp
|
|
|
@Operation(summary="员工信息-通过id删除")
|
|
|
@RequiresPermissions("staff:delete")
|
|
|
@DeleteMapping(value = "/delete")
|
|
|
+ @Transactional
|
|
|
public Result<String> delete(@RequestParam(name="id",required=true) String id) {
|
|
|
- appInstructorService.removeById(id);
|
|
|
+ try {
|
|
|
+ StaffVO staffVO =sysUserService.findByUserIdStaff(id);
|
|
|
+ if (staffVO==null){
|
|
|
+ return Result.OK("删除失败!未查询到信息");
|
|
|
+ }
|
|
|
+ LoginUser loginUser = (LoginUser) SecurityUtils.getSubject().getPrincipal();
|
|
|
+ SysUser sysUser = new SysUser();
|
|
|
+ sysUser.setId(staffVO.getStaffId());
|
|
|
+ sysUser.setDelFlag(CommonConstant.DEL_FLAG_1);
|
|
|
+ sysUser.setUpdateBy(loginUser.getUsername());
|
|
|
+ sysUser.setUpdateTime(new Date());
|
|
|
+ sysUserService.updateById(sysUser);
|
|
|
+ if (StringUtils.isNotEmpty(staffVO.getInstructorId())){
|
|
|
+ AppInstructor appInstructor = new AppInstructor();
|
|
|
+ appInstructor.setId(staffVO.getInstructorId());
|
|
|
+ appInstructor.setDelFlag(CommonConstant.DEL_FLAG_1);
|
|
|
+ appInstructor.setUpdateBy(loginUser.getUsername());
|
|
|
+ appInstructor.setUpdateTime(new Date());
|
|
|
+ appInstructorService.updateById(appInstructor);
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.getMessage();
|
|
|
+ return Result.error("删除失败!");
|
|
|
+ }
|
|
|
return Result.OK("删除成功!");
|
|
|
}
|
|
|
|