EquipmentRepairController.java 11.5 KB
package com.skua.modules.equipment.controller;

import java.util.Arrays;
import java.util.List;
import java.util.Map;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.skua.core.api.vo.Result;
import com.skua.core.aspect.annotation.AutoLog;
import com.skua.core.context.BaseContextHandler;
import com.skua.core.context.SpringContextUtils;
import com.skua.core.util.ConvertUtils;
import com.skua.modules.equipment.entity.EquipmentRepair;
import com.skua.modules.equipment.service.IEquipmentRepairService;
import com.skua.modules.equipment.vo.EquipmentRepairVO;
import com.skua.modules.flow.business.service.IFlowService;
import com.skua.modules.system.service.ISysDictService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;

/**
 * 设备维修流程
 */
@Slf4j
@Api(tags = "设备管理/设备维修/维修管理")
@RestController
@RequestMapping("/equipment/equipmentRepair")
public class EquipmentRepairController {

    @Autowired
    private IEquipmentRepairService equipmentRepairService;
    @Autowired
    private ISysDictService sysDictService;
    @Autowired
    private IFlowService flowService;

    /**
     * 	分页列表查询
     *
     * @param equipmentRepairVO
     * @param pageNo
     * @param pageSize
     * @return
     */
    @AutoLog(value = "设备维修流程-分页列表查询")
    @ApiOperation(value = "设备维修流程-分页列表查询", notes = "设备维修流程-分页列表查询")
    @GetMapping(value = "/list")
    public Result<IPage<EquipmentRepairVO>> queryPageList(EquipmentRepairVO equipmentRepairVO,
                                        @RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo,
                                        @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize) throws Exception {
    	Result<IPage<EquipmentRepairVO>> result = new Result<IPage<EquipmentRepairVO>>();
        Page<EquipmentRepairVO> pageList = new Page<EquipmentRepairVO>(pageNo, pageSize);
        if(StringUtils.isBlank(equipmentRepairVO.getDepartId())) {
        	equipmentRepairVO.setDepartId(BaseContextHandler.getDeparts());
        }
        Page<EquipmentRepairVO> equipmentRepairVOPage = equipmentRepairService.queryCustomPageList(pageList, equipmentRepairVO);//自定义查询
        result.setResult(equipmentRepairVOPage);
        result.setSuccess(true);
        return result;
    }
    /**
     * <pre>
     *	设备流程状态统计
     * </pre>
     * @param equipmentRepairVO
     * @return
     * @throws Exception
     * @author Li Yuanyuan, 2023年4月19日 下午6:11:32
     * @Description: TODO(这里描述这个方法的需求变更情况)
     */
    @AutoLog(value = "设备维修流程-分页列表查询")
    @ApiOperation(value = "设备维修流程-分页列表查询", notes = "设备维修流程-分页列表查询")
    @GetMapping(value = "/statistics")
    public Result<Map<String,Object>> statistics(EquipmentRepairVO equipmentRepairVO) throws Exception {
    	Result<Map<String,Object>> result = new Result<Map<String,Object>>();
    	if(StringUtils.isBlank(equipmentRepairVO.getDepartId())) {
        	equipmentRepairVO.setDepartId(BaseContextHandler.getDeparts());
        }
    	Map<String,Object> map = equipmentRepairService.statistics(equipmentRepairVO);
    	result.setResult(map);
    	result.setSuccess(true);
        return result;
    }


    @AutoLog(value = "设备维修流程-详情")
    @ApiOperation(value = "设备维修流程-详情", notes = "设备维修流程-详情")
    @GetMapping(value = "/detail")
    public Result<JSONObject> detail(String id) throws Exception {
        Result<JSONObject> result = new Result<>();

        EquipmentRepairVO equipmentRepairVO = new EquipmentRepairVO();
        equipmentRepairVO.setId(id);

        Page<EquipmentRepairVO> pageList = new Page<EquipmentRepairVO>(0, 10);
        List<EquipmentRepairVO> equipmentRepairVOs = equipmentRepairService.queryCustomPageList(pageList, equipmentRepairVO).getRecords();//自定义查询
        if(equipmentRepairVOs!=null&&equipmentRepairVOs.size()>0) {
        	JSONObject equipmentRepairJsonObject = sysDictService.translateTDictValue(equipmentRepairVOs.get(0));
        	result.setResult(equipmentRepairJsonObject);
        }else {
        	result.setResult(new JSONObject());
        }

        result.success("添加成功!");
        return result;
    }

    /**
     * 添加
     *
     * @param equipmentRepair
     * @return
     */
    @AutoLog(value = "设备维修流程-添加")
    @ApiOperation(value = "设备维修流程-添加", notes = "设备维修流程-添加")
    @PostMapping(value = "/add")
    public Result<EquipmentRepair> add(@RequestBody EquipmentRepair equipmentRepair) {
        Result<EquipmentRepair> result = new Result<EquipmentRepair>();
        try {
            equipmentRepairService.save(equipmentRepair);
            result.success("添加成功!");
        } catch (Exception e) {
            log.error(e.getMessage(), e);
            result.error500("操作失败");
        }
        return result;
    }

    /**
     * 编辑
     *
     * @param equipmentRepair
     * @return
     */
    @AutoLog(value = "设备维修流程-编辑")
    @ApiOperation(value = "设备维修流程-编辑", notes = "设备维修流程-编辑")
    @PutMapping(value = "/edit")
    public Result<EquipmentRepair> edit(@RequestBody EquipmentRepair equipmentRepair) {
        Result<EquipmentRepair> result = new Result<EquipmentRepair>();
        EquipmentRepair equipmentRepairEntity = equipmentRepairService.getById(equipmentRepair.getId());
        if (equipmentRepairEntity == null) {
            result.error500("未找到对应实体");
        } else {
            boolean ok = equipmentRepairService.updateById(equipmentRepair);
            if (ok) {
                result.success("修改成功!");
            }
        }
        return result;
    }

    /**
     * 通过id删除
     *
     * @param id
     * @return
     */
    @AutoLog(value = "设备维修流程-通过id删除")
    @ApiOperation(value = "设备维修流程-通过id删除", notes = "设备维修流程-通过id删除")
    @DeleteMapping(value = "/delete")
    public Result<?> delete(@RequestParam(name = "id", required = true) String id) {
        try {
            equipmentRepairService.removeById(id);
        } catch (Exception e) {
            log.error("删除失败: {}", e.getMessage());
            return Result.error("删除失败!");
        }
        return Result.ok("删除成功!");
    }

    /**
     * 批量删除
     *
     * @param ids
     * @return
     */
    @AutoLog(value = "设备维修流程-批量删除")
    @ApiOperation(value = "设备维修流程-批量删除", notes = "设备维修流程-批量删除")
    @DeleteMapping(value = "/deleteBatch")
    public Result<EquipmentRepair> deleteBatch(@RequestParam(name = "ids", required = true) String ids) {
        Result<EquipmentRepair> result = new Result<EquipmentRepair>();
        if (ids == null || "".equals(ids.trim())) {
            result.error500("参数不识别!");
        } else {
            this.equipmentRepairService.removeByIds(Arrays.asList(ids.split(",")));
            result.success("删除成功!");
        }
        return result;
    }

    /**
     * 通过id查询
     *
     * @param id
     * @return
     */
    @AutoLog(value = "设备维修流程-通过id查询")
    @ApiOperation(value = "设备维修流程-通过id查询", notes = "设备维修流程-通过id查询")
    @GetMapping(value = "/queryById")
    public Result<EquipmentRepair> queryById(@RequestParam(name = "id", required = true) String id) {
        Result<EquipmentRepair> result = new Result<EquipmentRepair>();
        EquipmentRepair equipmentRepair = equipmentRepairService.getById(id);
        if (equipmentRepair == null) {
            result.error500("未找到对应实体");
        } else {
            result.setResult(equipmentRepair);
            result.setSuccess(true);
        }
        return result;
    }

    /**
     * <pre>
     * 	故障报修流程发起
     * </pre>
     * @param equipmentRepair
     * @return
     * @throws Exception
     * @author Li Yuanyuan, 2023年4月18日 下午4:04:56
     * @Description: TODO(这里描述这个方法的需求变更情况)
     */
    @AutoLog(value = "故障报修-流程发起")
    @ApiOperation(value = "故障报修-流程发起", notes = "故障报修-流程发起")
    @PostMapping(value = "/startProcess")
    public Result<EquipmentRepairVO> startProcess(@RequestBody EquipmentRepair equipmentRepair) throws Exception {
        Result<EquipmentRepairVO> result = new Result<>();
        equipmentRepairService.startProcess(result,equipmentRepair);
        return result;
    }

    @AutoLog(value = "故障接修")
    @ApiOperation(value = "故障接修", notes = "故障接修")
    @PostMapping(value = "/task-gzjx")
    public Result<EquipmentRepairVO> taskGzjx(@RequestBody EquipmentRepairVO equipmentRepairVO) throws Exception {
        Result<EquipmentRepairVO> result = new Result<>();
        equipmentRepairService.taskGzjx(result,equipmentRepairVO);
        return result;
    }

    @AutoLog(value = "自修、外委")
    @ApiOperation(value = "自修、外委", notes = "自修、外委")
    @PostMapping(value = "/task-wx")
    public Result<EquipmentRepairVO> taskWx(@RequestBody EquipmentRepairVO equipmentRepairVO) throws Exception {
        Result<EquipmentRepairVO> result = new Result<>();
        equipmentRepairService.taskWx(result,equipmentRepairVO);
        return result;
    }

    @AutoLog(value = "故障验收")
    @ApiOperation(value = "故障验收", notes = "故障验收")
    @PostMapping(value = "/task-gzys")
    public Result<EquipmentRepairVO> taskGzys(@RequestBody EquipmentRepairVO equipmentRepairVO) throws Exception {
        Result<EquipmentRepairVO> result = new Result<>();
        equipmentRepairService.taskgzys(result,equipmentRepairVO);
        return result;
    }

    @ApiOperation(value="删除工作流数据", notes="删除工作流数据")
	@GetMapping(value = "/deleteFlowData")
	public Result<String> deleteFlowData() {
		Result<String> result = new Result<String>();
		JdbcTemplate masterDB = (JdbcTemplate)SpringContextUtils.getBean("master");
		String sql="select process_instance_id from equipment_repair where process_instance_id is not null and process_instance_id!=''";
		List<Map<String, Object>> list = masterDB.queryForList(sql);

		list.forEach(map ->{
			String processInstanceId = ConvertUtils.getString(map.get("process_instance_id"));
			try {
				flowService.deleteProcessInstanceById(processInstanceId,"批量删除");
				System.out.println("删除流程实例成功:"+processInstanceId);
			} catch (Exception e) {
				System.out.println("流程实例id缺失:"+processInstanceId);
			}
		});
		result.setSuccess(true);
		return result;
	}

}