|
@@ -0,0 +1,149 @@
|
|
|
+package cn.iocoder.yudao.module.pms.controller.admin.iotdeviceallotlog;
|
|
|
+
|
|
|
+import cn.hutool.core.collection.CollUtil;
|
|
|
+import cn.iocoder.yudao.framework.apilog.core.annotation.ApiAccessLog;
|
|
|
+import cn.iocoder.yudao.framework.common.pojo.CommonResult;
|
|
|
+import cn.iocoder.yudao.framework.common.pojo.PageParam;
|
|
|
+import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
|
|
+import cn.iocoder.yudao.framework.common.util.collection.MapUtils;
|
|
|
+import cn.iocoder.yudao.framework.common.util.number.NumberUtils;
|
|
|
+import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
|
|
|
+import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils;
|
|
|
+import cn.iocoder.yudao.module.pms.controller.admin.iotdeviceallotlog.vo.IotDeviceAllotLogPageReqVO;
|
|
|
+import cn.iocoder.yudao.module.pms.controller.admin.iotdeviceallotlog.vo.IotDeviceAllotLogRespVO;
|
|
|
+import cn.iocoder.yudao.module.pms.controller.admin.iotdeviceallotlog.vo.IotDeviceAllotLogSaveReqVO;
|
|
|
+import cn.iocoder.yudao.module.pms.controller.admin.vo.IotDeviceRespVO;
|
|
|
+import cn.iocoder.yudao.module.pms.dal.dataobject.IotDeviceDO;
|
|
|
+import cn.iocoder.yudao.module.pms.dal.dataobject.iotdeviceallotlog.IotDeviceAllotLogDO;
|
|
|
+import cn.iocoder.yudao.module.pms.service.IotDeviceService;
|
|
|
+import cn.iocoder.yudao.module.pms.service.iotdeviceallotlog.IotDeviceAllotLogService;
|
|
|
+import cn.iocoder.yudao.module.system.api.user.AdminUserApi;
|
|
|
+import cn.iocoder.yudao.module.system.api.user.dto.AdminUserRespDTO;
|
|
|
+import cn.iocoder.yudao.module.system.dal.dataobject.dept.DeptDO;
|
|
|
+import cn.iocoder.yudao.module.system.service.dept.DeptService;
|
|
|
+import io.swagger.v3.oas.annotations.Operation;
|
|
|
+import io.swagger.v3.oas.annotations.Parameter;
|
|
|
+import io.swagger.v3.oas.annotations.tags.Tag;
|
|
|
+import org.springframework.security.access.prepost.PreAuthorize;
|
|
|
+import org.springframework.validation.annotation.Validated;
|
|
|
+import org.springframework.web.bind.annotation.*;
|
|
|
+
|
|
|
+import javax.annotation.Resource;
|
|
|
+import javax.servlet.http.HttpServletResponse;
|
|
|
+import javax.validation.Valid;
|
|
|
+import java.io.IOException;
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.Collections;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
+import java.util.stream.Stream;
|
|
|
+
|
|
|
+import static cn.iocoder.yudao.framework.apilog.core.enums.OperateTypeEnum.EXPORT;
|
|
|
+import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
|
|
|
+import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertList;
|
|
|
+import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertListByFlatMap;
|
|
|
+
|
|
|
+@Tag(name = "管理后台 - 设备调拨日志")
|
|
|
+@RestController
|
|
|
+@RequestMapping("/pms/iot-device-allot-log")
|
|
|
+@Validated
|
|
|
+public class IotDeviceAllotLogController {
|
|
|
+
|
|
|
+ @Resource
|
|
|
+ private IotDeviceAllotLogService iotDeviceAllotLogService;
|
|
|
+ @Resource
|
|
|
+ private AdminUserApi adminUserApi;
|
|
|
+ @Resource
|
|
|
+ private IotDeviceService iotDeviceService;
|
|
|
+ @Resource
|
|
|
+ private DeptService deptService;
|
|
|
+
|
|
|
+ @PostMapping("/create")
|
|
|
+ @Operation(summary = "创建设备调拨日志")
|
|
|
+ @PreAuthorize("@ss.hasPermission('pms:iot-device-allot-log:create')")
|
|
|
+ public CommonResult<Long> createIotDeviceAllotLog(@Valid @RequestBody IotDeviceAllotLogSaveReqVO createReqVO) {
|
|
|
+ return success(iotDeviceAllotLogService.createIotDeviceAllotLog(createReqVO));
|
|
|
+ }
|
|
|
+
|
|
|
+ @PutMapping("/update")
|
|
|
+ @Operation(summary = "更新设备调拨日志")
|
|
|
+ @PreAuthorize("@ss.hasPermission('pms:iot-device-allot-log:update')")
|
|
|
+ public CommonResult<Boolean> updateIotDeviceAllotLog(@Valid @RequestBody IotDeviceAllotLogSaveReqVO updateReqVO) {
|
|
|
+ iotDeviceAllotLogService.updateIotDeviceAllotLog(updateReqVO);
|
|
|
+ return success(true);
|
|
|
+ }
|
|
|
+
|
|
|
+ @DeleteMapping("/delete")
|
|
|
+ @Operation(summary = "删除设备调拨日志")
|
|
|
+ @Parameter(name = "id", description = "编号", required = true)
|
|
|
+ @PreAuthorize("@ss.hasPermission('pms:iot-device-allot-log:delete')")
|
|
|
+ public CommonResult<Boolean> deleteIotDeviceAllotLog(@RequestParam("id") Long id) {
|
|
|
+ iotDeviceAllotLogService.deleteIotDeviceAllotLog(id);
|
|
|
+ return success(true);
|
|
|
+ }
|
|
|
+
|
|
|
+ @GetMapping("/get")
|
|
|
+ @Operation(summary = "获得设备调拨日志")
|
|
|
+ @Parameter(name = "id", description = "编号", required = true, example = "1024")
|
|
|
+ @PreAuthorize("@ss.hasPermission('pms:iot-device-allot-log:query')")
|
|
|
+ public CommonResult<IotDeviceAllotLogRespVO> getIotDeviceAllotLog(@RequestParam("id") Long id) {
|
|
|
+ IotDeviceAllotLogDO iotDeviceAllotLog = iotDeviceAllotLogService.getIotDeviceAllotLog(id);
|
|
|
+ return success(BeanUtils.toBean(iotDeviceAllotLog, IotDeviceAllotLogRespVO.class));
|
|
|
+ }
|
|
|
+
|
|
|
+ @GetMapping("/page")
|
|
|
+ @Operation(summary = "获得设备调拨日志分页")
|
|
|
+ @PreAuthorize("@ss.hasPermission('pms:iot-device-allot-log:query')")
|
|
|
+ public CommonResult<PageResult<IotDeviceAllotLogRespVO>> getIotDeviceAllotLogPage(@Valid IotDeviceAllotLogPageReqVO pageReqVO) {
|
|
|
+ PageResult<IotDeviceAllotLogDO> pageResult = iotDeviceAllotLogService.getIotDeviceAllotLogPage(pageReqVO);
|
|
|
+ return success(new PageResult<>(buildDeviceAllotList(pageResult.getList()), pageResult.getTotal()));
|
|
|
+ }
|
|
|
+
|
|
|
+ @GetMapping("/export-excel")
|
|
|
+ @Operation(summary = "导出设备调拨日志 Excel")
|
|
|
+ @PreAuthorize("@ss.hasPermission('pms:iot-device-allot-log:export')")
|
|
|
+ @ApiAccessLog(operateType = EXPORT)
|
|
|
+ public void exportIotDeviceAllotLogExcel(@Valid IotDeviceAllotLogPageReqVO pageReqVO,
|
|
|
+ HttpServletResponse response) throws IOException {
|
|
|
+ pageReqVO.setPageSize(PageParam.PAGE_SIZE_NONE);
|
|
|
+ List<IotDeviceAllotLogDO> list = iotDeviceAllotLogService.getIotDeviceAllotLogPage(pageReqVO).getList();
|
|
|
+ // 导出 Excel
|
|
|
+ ExcelUtils.write(response, "设备调拨日志.xls", "数据", IotDeviceAllotLogRespVO.class,
|
|
|
+ BeanUtils.toBean(list, IotDeviceAllotLogRespVO.class));
|
|
|
+ }
|
|
|
+
|
|
|
+ private List<IotDeviceAllotLogRespVO> buildDeviceAllotList(List<IotDeviceAllotLogDO> deviceAllots) {
|
|
|
+ if (CollUtil.isEmpty(deviceAllots)) {
|
|
|
+ return Collections.emptyList();
|
|
|
+ }
|
|
|
+ // 将调拨前部门、调拨后部门id设置到相同的集合
|
|
|
+ List<Long> deptIds = new ArrayList<>();
|
|
|
+ deviceAllots.forEach(deviceAllot -> {
|
|
|
+ deptIds.add(deviceAllot.getOldDeptId());
|
|
|
+ deptIds.add(deviceAllot.getNewDeptId());
|
|
|
+ });
|
|
|
+ // 调拨前部门集合
|
|
|
+ Map<Long, DeptDO> deptMap = deptService.getDeptMap(deptIds);
|
|
|
+ // 操作人集合
|
|
|
+ Map<Long, AdminUserRespDTO> userMap = adminUserApi.getUserMap(convertListByFlatMap(deviceAllots,
|
|
|
+ allot -> Stream.of(NumberUtils.parseLong(allot.getCreator()))));
|
|
|
+ // 组装设备信息
|
|
|
+ Map<Long, IotDeviceRespVO> deviceMap = iotDeviceService.getDeviceMap(convertListByFlatMap(deviceAllots,
|
|
|
+ allot -> Stream.of(allot.getDeviceId())));
|
|
|
+ // 2. 转换成 VO
|
|
|
+ return BeanUtils.toBean(deviceAllots, IotDeviceAllotLogRespVO.class, allotVO -> {
|
|
|
+ // 设置设备相关信息
|
|
|
+ MapUtils.findAndThen(deviceMap, allotVO.getDeviceId(),
|
|
|
+ device -> allotVO.setDeviceName(device.getDeviceName()));
|
|
|
+ MapUtils.findAndThen(deviceMap, allotVO.getDeviceId(),
|
|
|
+ device -> allotVO.setDeviceCode(device.getDeviceCode()));
|
|
|
+ // 设置 调拨前部门 调拨后部门信息
|
|
|
+ MapUtils.findAndThen(deptMap, allotVO.getOldDeptId(), dept -> allotVO.setOldDeptName(dept.getName()));
|
|
|
+ MapUtils.findAndThen(deptMap, allotVO.getNewDeptId(), dept -> allotVO.setNewDeptName(dept.getName()));
|
|
|
+ // 设置操作人信息
|
|
|
+ MapUtils.findAndThen(userMap, NumberUtils.parseLong(allotVO.getCreator()),
|
|
|
+ user -> allotVO.setCreatorName(user.getNickname()));
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+}
|