package org.jeecg.modules.hrm.controller;
|
|
import com.baomidou.mybatisplus.annotation.TableId;
|
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.annotations.Api;
|
import io.swagger.annotations.ApiOperation;
|
import lombok.extern.slf4j.Slf4j;
|
import org.apache.commons.lang3.StringUtils;
|
import org.jeecg.common.api.vo.Result;
|
import org.jeecg.common.aspect.annotation.AutoLog;
|
import org.jeecg.common.system.base.controller.JeecgController;
|
import org.jeecg.common.system.query.QueryGenerator;
|
import org.jeecg.modules.hrm.entity.HrmRoom;
|
import org.jeecg.modules.hrm.entity.HrmRoomSeat;
|
|
import org.jeecg.modules.hrm.service.IHrmRoomService;
|
import org.jeecg.modules.hrm.service.IHrmRoomSeatService;
|
import org.jeecg.modules.hrm.vo.HrmRoomVo;
|
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.factory.annotation.Autowired;
|
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.servlet.ModelAndView;
|
|
import javax.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpServletResponse;
|
import java.util.Arrays;
|
import java.util.List;
|
import java.util.Optional;
|
import java.util.stream.Collectors;
|
|
/**
|
* @Description: hrm_room
|
* @Author: jeecg-boot
|
* @Date: 2023-10-16
|
* @Version: V1.0
|
*/
|
@Api(tags="hrm_room")
|
@RestController
|
@RequestMapping("/hrm/room")
|
@Slf4j
|
public class HrmRoomController extends JeecgController<HrmRoom, IHrmRoomService> {
|
@Autowired
|
private IHrmRoomService hrmRoomService;
|
@Autowired
|
private IHrmRoomSeatService hrmRoomUserService;
|
@Autowired
|
private ISysUserService userService;
|
@Autowired
|
private ISysDepartService sysDepartService;
|
|
/**
|
* 分页列表查询
|
*
|
* @param hrmRoom
|
* @param pageNo
|
* @param pageSize
|
* @param req
|
* @return
|
*/
|
@AutoLog(value = "hrm_room-分页列表查询")
|
@ApiOperation(value="hrm_room-分页列表查询", notes="hrm_room-分页列表查询")
|
@GetMapping(value = "/list")
|
public Result<?> queryPageList(HrmRoom hrmRoom,
|
@RequestParam(name="pageNo", defaultValue="1") Integer pageNo,
|
@RequestParam(name="pageSize", defaultValue="10") Integer pageSize,
|
HttpServletRequest req) {
|
QueryWrapper<HrmRoom> queryWrapper = QueryGenerator.initQueryWrapper(hrmRoom, req.getParameterMap());
|
Page<HrmRoom> page = new Page<HrmRoom>(pageNo, pageSize);
|
Page<HrmRoomVo> page2 = new Page<HrmRoomVo>(pageNo, pageSize);
|
IPage<HrmRoom> pageList = hrmRoomService.page(page, queryWrapper);
|
comp(pageList, page2);
|
return Result.OK(page2);
|
}
|
|
private void comp(IPage<HrmRoom> pageList, Page<HrmRoomVo> page) {
|
List<HrmRoomSeat> allUserList = hrmRoomUserService.list();
|
List<SysUser> sysUserList = userService.list();
|
List<SysDepart> departList = sysDepartService.list();
|
List<HrmRoomVo> collect = pageList.getRecords().stream().map(item -> {
|
HrmRoomVo vo = new HrmRoomVo();
|
BeanUtils.copyProperties(item, vo);
|
List<HrmRoomSeat> userList = allUserList.stream().filter(i -> i.getRoomId().equals(item.getId())).collect(Collectors.toList());
|
//用户真实信息
|
userList.forEach(suser->{
|
|
Optional<SysUser> user = sysUserList.stream()
|
.filter(u -> u.getUsername().equals(suser.getUsername()))
|
.findFirst();
|
if(user.isPresent()){
|
suser.setRealname(user.get().getRealname());
|
}
|
|
|
|
});
|
//部门信息
|
if(!StringUtils.isEmpty(item.getDepart())){
|
Optional<SysDepart> depart = departList.stream()
|
.filter(u -> u.getId().equals(item.getDepart()))
|
.findFirst();
|
if (depart.isPresent()) {
|
vo.setDepartName(depart.get().getDepartName());
|
vo.setSort(depart.get().getDepartOrder());
|
}
|
|
}
|
|
vo.setUserList(userList);
|
return vo;
|
}).collect(Collectors.toList());
|
BeanUtils.copyProperties(pageList, page);
|
page.setRecords(collect);
|
}
|
|
/**
|
* 添加
|
*
|
* @param hrmRoom
|
* @return
|
*/
|
@AutoLog(value = "hrm_room-添加")
|
@ApiOperation(value="hrm_room-添加", notes="hrm_room-添加")
|
@PostMapping(value = "/add")
|
public Result<?> add(@RequestBody HrmRoom hrmRoom) {
|
hrmRoomService.save(hrmRoom);
|
return Result.OK("添加成功!");
|
}
|
|
/**
|
* 编辑
|
*
|
* @param hrmRoom
|
* @return
|
*/
|
@AutoLog(value = "hrm_room-编辑")
|
@ApiOperation(value="hrm_room-编辑", notes="hrm_room-编辑")
|
@PutMapping(value = "/edit")
|
public Result<?> edit(@RequestBody HrmRoom hrmRoom) {
|
hrmRoomService.updateById(hrmRoom);
|
return Result.OK("编辑成功!");
|
}
|
|
/**
|
* 通过id删除
|
*
|
* @param id
|
* @return
|
*/
|
@AutoLog(value = "hrm_room-通过id删除")
|
@ApiOperation(value="hrm_room-通过id删除", notes="hrm_room-通过id删除")
|
@DeleteMapping(value = "/delete")
|
public Result<?> delete(@RequestParam(name="id",required=true) String id) {
|
hrmRoomService.removeById(id);
|
return Result.OK("删除成功!");
|
}
|
|
/**
|
* 批量删除
|
*
|
* @param ids
|
* @return
|
*/
|
@AutoLog(value = "hrm_room-批量删除")
|
@ApiOperation(value="hrm_room-批量删除", notes="hrm_room-批量删除")
|
@DeleteMapping(value = "/deleteBatch")
|
public Result<?> deleteBatch(@RequestParam(name="ids",required=true) String ids) {
|
this.hrmRoomService.removeByIds(Arrays.asList(ids.split(",")));
|
return Result.OK("批量删除成功!");
|
}
|
|
/**
|
* 通过id查询
|
*
|
* @param id
|
* @return
|
*/
|
@AutoLog(value = "hrm_room-通过id查询")
|
@ApiOperation(value="hrm_room-通过id查询", notes="hrm_room-通过id查询")
|
@GetMapping(value = "/queryById")
|
public Result<?> queryById(@RequestParam(name="id",required=true) String id) {
|
HrmRoom hrmRoom = hrmRoomService.getById(id);
|
if(hrmRoom==null) {
|
return Result.error("未找到对应数据");
|
}
|
return Result.OK(hrmRoom);
|
}
|
|
/**
|
* 导出excel
|
*
|
* @param request
|
* @param hrmRoom
|
*/
|
@RequestMapping(value = "/exportXls")
|
public ModelAndView exportXls(HttpServletRequest request, HrmRoom hrmRoom) {
|
return super.exportXls(request, hrmRoom, HrmRoom.class, "hrm_room");
|
}
|
|
/**
|
* 通过excel导入数据
|
*
|
* @param request
|
* @param response
|
* @return
|
*/
|
@RequestMapping(value = "/importExcel", method = RequestMethod.POST)
|
public Result<?> importExcel(HttpServletRequest request, HttpServletResponse response) {
|
return super.importExcel(request, response, HrmRoom.class);
|
}
|
|
}
|