Newer
Older
huludao / src / main / java / com / newfiber / modules / inspection / controller / EquMaintenanceWorkOrderController.java
package com.newfiber.modules.inspection.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.newfiber.common.utils.PageUtils;
import com.newfiber.common.utils.R;
import com.newfiber.modules.inspection.entity.EquMaintenanceApprovalEntity;
import com.newfiber.modules.inspection.entity.EquMaintenanceHandleEntity;
import com.newfiber.modules.inspection.entity.EquMaintenanceWorkOrderEntity;
import com.newfiber.modules.inspection.entity.EquTechnologicalProcessInfoEntity;
import com.newfiber.modules.inspection.enums.EApprovalStatus;
import com.newfiber.modules.inspection.service.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiOperationSupport;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;

import java.util.*;
import java.util.stream.Collectors;


/**
 * 设备报修处理
 *
 * @author xiey
 * @email sunlightcs@gmail.com
 * @date 2020-11-26 14:25:04
 */
@RestController
@RequestMapping("equworkorder")
@Api(value = "设备报修流程处理", tags = "设备报修流程处理")
public class EquMaintenanceWorkOrderController {
    @Autowired
    private EquMaintenanceWorkOrderService equMaintenanceWorkOrderService;
    @Autowired
    private EquMaintenanceApprovalService equMaintenanceApprovalService;
    @Autowired
    private EquMaintenanceHandleService equMaintenanceHandleService;
    @Autowired
    private EquTechnologicalProcessInfoService processInfoService;
    @Autowired
    private FileUploadService fileUploadService;

    /**
     * 设备报修信息列表
     */
    @ApiOperation(value = "查询报修信息列表")
    @ApiOperationSupport(order = 10)
    @PostMapping("/page")
    //@RequiresPermissions("business:equmaintenanceworkorder:list")
    public R list(@RequestBody Map<String, Object> params) {
        PageUtils page = equMaintenanceWorkOrderService.queryPage(params);

        return R.ok().put("page", page);
    }

    /**
     * 报修信息查询
     */
    @ApiOperation(value = "报修信息查询")
    @PostMapping("/reportInfo/{workOrderNo}")
    //@RequiresPermissions("business:equmaintenanceworkorder:reportInfo")
    public R reportInfo(@PathVariable("workOrderNo") String workOrderNo) {

        EquMaintenanceWorkOrderEntity approvalEntity = equMaintenanceWorkOrderService.getOne
                (new QueryWrapper<EquMaintenanceWorkOrderEntity>().eq("work_order_no", workOrderNo));

        Map<String, Object> map = new HashMap<>();
        /**获取上传的文件信息*/
        map.put("relation_id", workOrderNo);
        approvalEntity.setFileUploadEntityList(fileUploadService.listByMap(map));

        return R.ok().put("info", approvalEntity);
    }

    /**
     * 保存报修信息,审批流程信息
     */
    @ApiOperation(value = "保存报修信息,审批流程信息")
    @ApiOperationSupport(order = 20)
    @PostMapping("/save")
    //@RequiresPermissions("business:equmaintenanceworkorder:save")
    public R save(@RequestBody EquMaintenanceWorkOrderEntity equMaintenanceWorkOrder) {
        QueryWrapper<EquMaintenanceWorkOrderEntity> queryWrapper = new QueryWrapper<EquMaintenanceWorkOrderEntity>()
                .eq("equ_no", equMaintenanceWorkOrder.getEquNo());
        queryWrapper.and(Wrapper -> Wrapper
                .eq("work_order_type", EApprovalStatus.DOING.getKey()).or()
                .eq("work_order_type", EApprovalStatus.ADOPT.getKey()).or()
                .eq("work_order_type", EApprovalStatus.EX.getKey()));

        EquMaintenanceWorkOrderEntity workEntity = equMaintenanceWorkOrderService.getOne(queryWrapper);
        if (workEntity != null
                && workEntity.getWorkOrderType() != EApprovalStatus.END.getKey()
                && workEntity.getWorkOrderType() != EApprovalStatus.No.getKey()) {
            return R.error("设备已报修");
        }
        equMaintenanceWorkOrderService.saveMes(equMaintenanceWorkOrder);
        return R.ok();
    }

    /**
     * 修改报修信息
     */
    @ApiOperation(value = "修改报修信息")
    @ApiOperationSupport(order = 30)
    @PostMapping("/update")
    //@RequiresPermissions("business:equmaintenanceworkorder:update")
    public R update(@RequestBody EquMaintenanceWorkOrderEntity equMaintenanceWorkOrder) {

        equMaintenanceWorkOrderService.updateWorkOrder(equMaintenanceWorkOrder);

        return R.ok();
    }

    /**
     * 删除报修信息
     */
    @ApiOperation(value = "删除报修信息")
    @ApiOperationSupport(order = 40)
    @PostMapping("/delete")
    @Transactional
    //@RequiresPermissions("business:equmaintenanceworkorder:delete")
    public R delete(@RequestBody Integer[] ids) {

        List<EquMaintenanceWorkOrderEntity> entityList = equMaintenanceWorkOrderService.listByIds(Arrays.asList(ids));
        processInfoService.remove(new QueryWrapper<EquTechnologicalProcessInfoEntity>()
                .in("repair_no", entityList.stream()
                        .map(EquMaintenanceWorkOrderEntity::getWorkOrderNo).distinct()
                        .collect(Collectors.toList())));

        equMaintenanceWorkOrderService.removeByIds(Arrays.asList(ids));

        return R.ok();
    }

    /**
     * 查询报修审批流程信息
     */
    @ApiOperation(value = "查询报修审批流程信息")
    @ApiOperationSupport(order = 50)
    @PostMapping("/approvalInfo/{workOrderNo}")
    //@RequiresPermissions("business:equmaintenanceworkorder:planPage")
    public R approvalInfo(@PathVariable("workOrderNo") String workOrderNo) {

        Map<String, Object> map = new HashMap<>();
        map.put("repair_no", workOrderNo);
        List<EquTechnologicalProcessInfoEntity> infoEntities = processInfoService.listByMap(map);

        return R.ok().put("info", infoEntities);
    }

    /**
     * 查询报修计划信息
     */
    @ApiOperation(value = "查询报修计划信息")
    @ApiOperationSupport(order = 50)
    @PostMapping("/planInfo/{workOrderNo}")
    //@RequiresPermissions("business:equmaintenanceworkorder:planPage")
    public R planInfo(@PathVariable("workOrderNo") String workOrderNo) {

        EquMaintenanceApprovalEntity approvalEntity = equMaintenanceApprovalService.getOne
                (new QueryWrapper<EquMaintenanceApprovalEntity>().eq("work_order_no", workOrderNo));

        return R.ok().put("info", approvalEntity);
    }

    /**
     * 保存报修计划信息,维修信息
     */
    @ApiOperation(value = "保存报修计划信息,维修信息")
    @ApiOperationSupport(order = 60)
    @PostMapping("/planSave")
    //@RequiresPermissions("business:equmaintenanceworkorder:planSave")
    public R planSave(@RequestBody Map<String, Object> params) {
        equMaintenanceWorkOrderService.planSave(params);

        return R.ok();
    }

    /**
     * 修改报修计划信息
     */
    @ApiOperation(value = "修改报修计划信息")
    @ApiOperationSupport(order = 70)
    @PostMapping("/planUpdate")
    //@RequiresPermissions("business:equmaintenanceworkorder:planUpdate")
    public R planUpdate(@RequestBody Map<String, Object> params) {

        String orderNo = (String) params.get("workOrderNo");
        EquMaintenanceApprovalEntity approvalEntity = equMaintenanceApprovalService.getOne
                (new QueryWrapper<EquMaintenanceApprovalEntity>().eq("work_order_no", orderNo));

        if (new Date().getTime() - approvalEntity.getReceiptTime().getTime() > 60 * 60 * 1000) {
            return R.error("已超时无法修改.");
        }

        equMaintenanceWorkOrderService.planSave(params);

        return R.ok();
    }

    /**
     * 查询设备处理信息列表
     */
    @ApiOperation(value = "查询设备处理信息列表")
    @ApiOperationSupport(order = 80)
    @PostMapping("/repairPage")
    //@RequiresPermissions("business:equmaintenanceworkorder:list")
    public R repairPage(@RequestBody Map<String, Object> params) {
        PageUtils page = equMaintenanceHandleService.queryPage(params);

        return R.ok().put("page", page);
    }

    /**
     * 查询处理信息
     */
    @ApiOperation(value = "查询处理信息")
    @ApiOperationSupport(order = 90)
    @PostMapping("/repairInfo/{workOrderNo}")
    //@RequiresPermissions("business:equmaintenanceworkorder:planPage")
    public R repairInfo(@PathVariable("workOrderNo") String workOrderNo) {

        EquMaintenanceHandleEntity handleEntity = equMaintenanceHandleService.getOne
                (new QueryWrapper<EquMaintenanceHandleEntity>().eq("work_order_no", workOrderNo));

        Map<String, Object> map = new HashMap<>();
        /**获取上传的文件信息*/
        map.put("relation_id", handleEntity.getHandleNo());
        handleEntity.setFileUploadEntityList(fileUploadService.listByMap(map));

        return R.ok().put("info", handleEntity);
    }

    /**
     * 修改处理信息
     */
    @ApiOperation(value = "修改处理信息")
    @ApiOperationSupport(order = 100)
    @PostMapping("/repairUpdate")
    //@RequiresPermissions("business:equmaintenanceworkorder:repairUpdate")
    public R repairUpdate(@RequestBody EquMaintenanceHandleEntity handleEntity) {

        equMaintenanceWorkOrderService.updateMes(handleEntity);

        return R.ok();
    }

}