package cn.iocoder.yudao.module.mes.controller.admin.dv.borrow;
|
|
import cn.hutool.core.collection.CollUtil;
|
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.object.BeanUtils;
|
import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils;
|
import cn.iocoder.yudao.framework.apilog.core.annotation.ApiAccessLog;
|
import cn.iocoder.yudao.module.mes.controller.admin.dv.borrow.vo.MesDvBorrowPageReqVO;
|
import cn.iocoder.yudao.module.mes.controller.admin.dv.borrow.vo.MesDvBorrowRespVO;
|
import cn.iocoder.yudao.module.mes.controller.admin.dv.borrow.vo.MesDvBorrowSaveReqVO;
|
import cn.iocoder.yudao.module.mes.dal.dataobject.dv.borrow.MesDvBorrowDO;
|
import cn.iocoder.yudao.module.mes.dal.dataobject.dv.machinery.MesDvMachineryDO;
|
import cn.iocoder.yudao.module.mes.service.dv.borrow.MesDvBorrowService;
|
import cn.iocoder.yudao.module.mes.service.dv.machinery.MesDvMachineryService;
|
import cn.iocoder.yudao.module.system.api.user.AdminUserApi;
|
import cn.iocoder.yudao.module.system.api.user.dto.AdminUserRespDTO;
|
import io.swagger.v3.oas.annotations.Operation;
|
import io.swagger.v3.oas.annotations.Parameter;
|
import io.swagger.v3.oas.annotations.Parameters;
|
import io.swagger.v3.oas.annotations.tags.Tag;
|
import jakarta.annotation.Resource;
|
import jakarta.servlet.http.HttpServletResponse;
|
import jakarta.validation.Valid;
|
import org.springframework.security.access.prepost.PreAuthorize;
|
import org.springframework.validation.annotation.Validated;
|
import org.springframework.web.bind.annotation.*;
|
|
import java.io.IOException;
|
import java.util.Collections;
|
import java.util.List;
|
import java.util.Map;
|
|
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.convertSet;
|
|
@Tag(name = "管理后台 - MES 设备借用归还")
|
@RestController
|
@RequestMapping("/mes/dv/borrow")
|
@Validated
|
public class MesDvBorrowController {
|
|
@Resource
|
private MesDvBorrowService borrowService;
|
@Resource
|
private MesDvMachineryService machineryService;
|
@Resource
|
private AdminUserApi adminUserApi;
|
|
@PostMapping("/create")
|
@Operation(summary = "创建设备借用")
|
@PreAuthorize("@ss.hasPermission('mes:dv-borrow:create')")
|
public CommonResult<Long> createBorrow(@Valid @RequestBody MesDvBorrowSaveReqVO createReqVO) {
|
return success(borrowService.createBorrow(createReqVO));
|
}
|
|
@PutMapping("/update")
|
@Operation(summary = "更新设备借用")
|
@PreAuthorize("@ss.hasPermission('mes:dv-borrow:update')")
|
public CommonResult<Boolean> updateBorrow(@Valid @RequestBody MesDvBorrowSaveReqVO updateReqVO) {
|
borrowService.updateBorrow(updateReqVO);
|
return success(true);
|
}
|
|
@DeleteMapping("/delete")
|
@Operation(summary = "删除设备借用")
|
@Parameter(name = "id", description = "编号", required = true)
|
@PreAuthorize("@ss.hasPermission('mes:dv-borrow:delete')")
|
public CommonResult<Boolean> deleteBorrow(@RequestParam("id") Long id) {
|
borrowService.deleteBorrow(id);
|
return success(true);
|
}
|
|
@PutMapping("/return")
|
@Operation(summary = "设备归还", description = "归还后记录实际归还时间与归还状况,状态变为已归还")
|
@Parameters({
|
@Parameter(name = "id", description = "编号", required = true),
|
@Parameter(name = "returnCondition", description = "归还状况,如:完好、轻微磨损、需维修")
|
})
|
@PreAuthorize("@ss.hasPermission('mes:dv-borrow:update')")
|
public CommonResult<Boolean> returnBorrow(@RequestParam("id") Long id,
|
@RequestParam(value = "returnCondition", required = false) String returnCondition) {
|
borrowService.returnBorrow(id, returnCondition);
|
return success(true);
|
}
|
|
@GetMapping("/get")
|
@Operation(summary = "获得设备借用")
|
@Parameter(name = "id", description = "编号", required = true, example = "1024")
|
@PreAuthorize("@ss.hasPermission('mes:dv-borrow:query')")
|
public CommonResult<MesDvBorrowRespVO> getBorrow(@RequestParam("id") Long id) {
|
MesDvBorrowDO borrow = borrowService.getBorrow(id);
|
if (borrow == null) {
|
return success(null);
|
}
|
return success(buildBorrowRespVOList(Collections.singletonList(borrow)).get(0));
|
}
|
|
@GetMapping("/page")
|
@Operation(summary = "获得设备借用分页")
|
@PreAuthorize("@ss.hasPermission('mes:dv-borrow:query')")
|
public CommonResult<PageResult<MesDvBorrowRespVO>> getBorrowPage(@Valid MesDvBorrowPageReqVO pageReqVO) {
|
PageResult<MesDvBorrowDO> pageResult = borrowService.getBorrowPage(pageReqVO);
|
return success(new PageResult<>(buildBorrowRespVOList(pageResult.getList()), pageResult.getTotal()));
|
}
|
|
@GetMapping("/export-excel")
|
@Operation(summary = "导出设备借用 Excel")
|
@PreAuthorize("@ss.hasPermission('mes:dv-borrow:export')")
|
@ApiAccessLog(operateType = EXPORT)
|
public void exportBorrowExcel(@Valid MesDvBorrowPageReqVO pageReqVO,
|
HttpServletResponse response) throws IOException {
|
pageReqVO.setPageSize(PageParam.PAGE_SIZE_NONE);
|
List<MesDvBorrowDO> list = borrowService.getBorrowPage(pageReqVO).getList();
|
ExcelUtils.write(response, "设备借用.xls", "数据", MesDvBorrowRespVO.class, buildBorrowRespVOList(list));
|
}
|
|
private List<MesDvBorrowRespVO> buildBorrowRespVOList(List<MesDvBorrowDO> list) {
|
if (CollUtil.isEmpty(list)) {
|
return Collections.emptyList();
|
}
|
Map<Long, MesDvMachineryDO> machineryMap = machineryService.getMachineryMap(
|
convertSet(list, MesDvBorrowDO::getMachineryId));
|
Map<Long, AdminUserRespDTO> userMap = adminUserApi.getUserMap(
|
convertSet(list, MesDvBorrowDO::getBorrowerUserId));
|
return BeanUtils.toBean(list, MesDvBorrowRespVO.class, vo -> {
|
MapUtils.findAndThen(machineryMap, vo.getMachineryId(), machinery -> {
|
vo.setMachineryCode(machinery.getCode());
|
vo.setMachineryName(machinery.getName());
|
});
|
MapUtils.findAndThen(userMap, vo.getBorrowerUserId(),
|
user -> vo.setBorrowerUserName(user.getNickname()));
|
});
|
}
|
|
}
|