|
@@ -0,0 +1,125 @@
|
|
|
+package com.xjrsoft.module.room.controller;
|
|
|
+
|
|
|
+import cn.hutool.core.bean.BeanUtil;
|
|
|
+import cn.hutool.core.util.ObjectUtil;
|
|
|
+import cn.hutool.core.util.StrUtil;
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
+import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
|
+import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
|
+import com.xjrsoft.common.constant.GlobalConstant;
|
|
|
+import com.baomidou.mybatisplus.core.toolkit.StringPool;
|
|
|
+import com.xjrsoft.common.page.ConventPage;
|
|
|
+import com.xjrsoft.common.page.PageOutput;
|
|
|
+import com.xjrsoft.common.model.result.RT;
|
|
|
+import com.xjrsoft.common.utils.VoToColumnUtil;
|
|
|
+import com.xjrsoft.module.room.dto.AddRoomBedDto;
|
|
|
+import com.xjrsoft.module.room.dto.UpdateRoomBedDto;
|
|
|
+import cn.dev33.satoken.annotation.SaCheckPermission;
|
|
|
+import com.alibaba.excel.EasyExcel;
|
|
|
+import org.springframework.web.multipart.MultipartFile;
|
|
|
+import java.io.IOException;
|
|
|
+import com.alibaba.excel.support.ExcelTypeEnum;
|
|
|
+import org.springframework.http.ResponseEntity;
|
|
|
+import java.io.ByteArrayOutputStream;
|
|
|
+import java.util.ArrayList;
|
|
|
+
|
|
|
+import com.xjrsoft.module.room.dto.RoomBedPageDto;
|
|
|
+import com.xjrsoft.module.room.entity.RoomBed;
|
|
|
+import com.xjrsoft.module.room.service.IRoomBedService;
|
|
|
+import com.xjrsoft.module.room.vo.RoomBedPageVo;
|
|
|
+
|
|
|
+import com.xjrsoft.module.room.vo.RoomBedVo;
|
|
|
+import io.swagger.annotations.Api;
|
|
|
+import io.swagger.annotations.ApiOperation;
|
|
|
+import lombok.AllArgsConstructor;
|
|
|
+import org.springframework.web.bind.annotation.*;
|
|
|
+
|
|
|
+import javax.validation.Valid;
|
|
|
+import javax.validation.constraints.NotNull;
|
|
|
+import java.util.List;
|
|
|
+
|
|
|
+/**
|
|
|
+* @title: 寝室床位
|
|
|
+* @Author dzx
|
|
|
+* @Date: 2023-12-27
|
|
|
+* @Version 1.0
|
|
|
+*/
|
|
|
+@RestController
|
|
|
+@RequestMapping("/room" + "/roomBed")
|
|
|
+@Api(value = "/room" + "/roomBed",tags = "寝室床位代码")
|
|
|
+@AllArgsConstructor
|
|
|
+public class RoomBedController {
|
|
|
+
|
|
|
+
|
|
|
+ private final IRoomBedService roomBedService;
|
|
|
+
|
|
|
+ @GetMapping(value = "/page")
|
|
|
+ @ApiOperation(value="寝室床位列表(分页)")
|
|
|
+ @SaCheckPermission("roombed:detail")
|
|
|
+ public RT<PageOutput<RoomBedPageVo>> page(@Valid RoomBedPageDto dto){
|
|
|
+
|
|
|
+ LambdaQueryWrapper<RoomBed> queryWrapper = new LambdaQueryWrapper<>();
|
|
|
+ queryWrapper
|
|
|
+ .orderByDesc(RoomBed::getId)
|
|
|
+ .select(RoomBed.class,x -> VoToColumnUtil.fieldsToColumns(RoomBedPageVo.class).contains(x.getProperty()));
|
|
|
+ IPage<RoomBed> page = roomBedService.page(ConventPage.getPage(dto), queryWrapper);
|
|
|
+ PageOutput<RoomBedPageVo> pageOutput = ConventPage.getPageOutput(page, RoomBedPageVo.class);
|
|
|
+ return RT.ok(pageOutput);
|
|
|
+ }
|
|
|
+
|
|
|
+ @GetMapping(value = "/info")
|
|
|
+ @ApiOperation(value="根据id查询寝室床位信息")
|
|
|
+ @SaCheckPermission("roombed:detail")
|
|
|
+ public RT<RoomBedVo> info(@RequestParam Long id){
|
|
|
+ RoomBed roomBed = roomBedService.getById(id);
|
|
|
+ if (roomBed == null) {
|
|
|
+ return RT.error("找不到此数据!");
|
|
|
+ }
|
|
|
+ return RT.ok(BeanUtil.toBean(roomBed, RoomBedVo.class));
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ @PostMapping
|
|
|
+ @ApiOperation(value = "新增寝室床位")
|
|
|
+ @SaCheckPermission("roombed:add")
|
|
|
+ public RT<Boolean> add(@Valid @RequestBody AddRoomBedDto dto){
|
|
|
+ RoomBed roomBed = BeanUtil.toBean(dto, RoomBed.class);
|
|
|
+ boolean isSuccess = roomBedService.save(roomBed);
|
|
|
+ return RT.ok(isSuccess);
|
|
|
+ }
|
|
|
+
|
|
|
+ @PutMapping
|
|
|
+ @ApiOperation(value = "修改寝室床位")
|
|
|
+ @SaCheckPermission("roombed:edit")
|
|
|
+ public RT<Boolean> update(@Valid @RequestBody UpdateRoomBedDto dto){
|
|
|
+
|
|
|
+ RoomBed roomBed = BeanUtil.toBean(dto, RoomBed.class);
|
|
|
+ return RT.ok(roomBedService.updateById(roomBed));
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ @DeleteMapping
|
|
|
+ @ApiOperation(value = "删除寝室床位")
|
|
|
+ @SaCheckPermission("roombed:delete")
|
|
|
+ public RT<Boolean> delete(@Valid @RequestBody List<Long> ids){
|
|
|
+ return RT.ok(roomBedService.removeBatchByIds(ids));
|
|
|
+
|
|
|
+ }
|
|
|
+ @PostMapping("/import")
|
|
|
+ @ApiOperation(value = "导入")
|
|
|
+ public RT<Boolean> importData(@RequestParam MultipartFile file) throws IOException {
|
|
|
+ List<RoomBedPageVo> savedDataList = EasyExcel.read(file.getInputStream()).head(RoomBedPageVo.class).sheet().doReadSync();
|
|
|
+ Boolean result = roomBedService.saveBatch(BeanUtil.copyToList(savedDataList, RoomBed.class));
|
|
|
+ return RT.ok(result);
|
|
|
+ }
|
|
|
+
|
|
|
+ @GetMapping("/export")
|
|
|
+ @ApiOperation(value = "导出")
|
|
|
+ public ResponseEntity<byte[]> exportData(@Valid RoomBedPageDto dto, @RequestParam(defaultValue = "false") Boolean isTemplate) {
|
|
|
+ List<RoomBedPageVo> customerList = isTemplate != null && isTemplate ? new ArrayList<>() : ((PageOutput<RoomBedPageVo>) page(dto).getData()).getList();
|
|
|
+ ByteArrayOutputStream bot = new ByteArrayOutputStream();
|
|
|
+ EasyExcel.write(bot, RoomBedPageVo.class).automaticMergeHead(false).excelType(ExcelTypeEnum.XLSX).sheet().doWrite(customerList);
|
|
|
+
|
|
|
+ return RT.fileStream(bot.toByteArray(), "RoomBed" + ExcelTypeEnum.XLSX.getValue());
|
|
|
+ }
|
|
|
+}
|