| | |
| | | package org.jeecg.modules.eam.controller; |
| | | |
| | | import com.alibaba.fastjson.JSONObject; |
| | | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
| | | import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper; |
| | | import com.baomidou.mybatisplus.core.metadata.IPage; |
| | | import com.baomidou.mybatisplus.core.toolkit.ObjectUtils; |
| | | import com.baomidou.mybatisplus.core.toolkit.StringUtils; |
| | | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
| | | import io.swagger.annotations.Api; |
| | |
| | | import org.jeecg.common.util.oConvertUtils; |
| | | import org.jeecg.modules.eam.entity.*; |
| | | import org.jeecg.modules.eam.service.*; |
| | | import org.jeecg.modules.eam.vo.EquipmentAvailabilityVo; |
| | | import org.jeecgframework.poi.excel.ExcelImportUtil; |
| | | import org.jeecgframework.poi.excel.def.NormalExcelConstants; |
| | | import org.jeecgframework.poi.excel.entity.ExportParams; |
| | |
| | | import javax.servlet.http.HttpServletResponse; |
| | | import java.io.IOException; |
| | | import java.math.BigDecimal; |
| | | import java.text.ParseException; |
| | | import java.util.*; |
| | | import java.util.stream.Collectors; |
| | | |
| | |
| | | HttpServletRequest req) { |
| | | Page<RepairOrder> page = new Page<RepairOrder>(pageNo, pageSize); |
| | | IPage<RepairOrder> pageList = repairOrderService.getRepairOrderList(page, repairOrder); |
| | | for(RepairOrder repairOrder1 : pageList.getRecords()){ |
| | | if(StringUtils.isNotBlank(repairOrder1.getReportRepairId())){ |
| | | EquipmentReportRepair equipmentReportRepair = equipmentReportRepairService.getById(repairOrder1.getReportRepairId()); |
| | | repairOrder1.setReportRepairNum(equipmentReportRepair.getNum()); |
| | | } |
| | | if(StringUtils.isNotBlank(repairOrder1.getProjectMaintenanceOrderId())){ |
| | | ProjectMaintenanceOrderDetail projectMaintenanceOrderDetail = projectMaintenanceOrderDetailService.getById(repairOrder1.getProjectMaintenanceOrderId()); |
| | | repairOrder1.setProjectMaintenanceOrderNum(projectMaintenanceOrderDetail.getTaskNum()); |
| | | } |
| | | |
| | | String id = repairOrder1.getId(); |
| | | QueryWrapper<RepairOrderActualWorkHours> wrapper = new QueryWrapper<>(); |
| | | wrapper.eq("repair_order_id", id) |
| | | .eq("del_flag", 0); |
| | | wrapper.select("sum(actual_hour) as actualHour"); |
| | | Map<String, Object> map = repairOrderActualWorkHoursService.getMap(wrapper); |
| | | BigDecimal actualHour = new BigDecimal(0); |
| | | if (map != null) { |
| | | actualHour = (BigDecimal) map.get("actualHour"); |
| | | } |
| | | repairOrder1.setActualHour(actualHour); |
| | | } |
| | | // for(RepairOrder repairOrder1 : pageList.getRecords()){ |
| | | // if(StringUtils.isNotBlank(repairOrder1.getReportRepairId())){ |
| | | // EquipmentReportRepair equipmentReportRepair = equipmentReportRepairService.getById(repairOrder1.getReportRepairId()); |
| | | // repairOrder1.setReportRepairNum(equipmentReportRepair.getNum()); |
| | | // } |
| | | // if(StringUtils.isNotBlank(repairOrder1.getProjectMaintenanceOrderId())){ |
| | | // ProjectMaintenanceOrderDetail projectMaintenanceOrderDetail = projectMaintenanceOrderDetailService.getById(repairOrder1.getProjectMaintenanceOrderId()); |
| | | // repairOrder1.setProjectMaintenanceOrderNum(projectMaintenanceOrderDetail.getTaskNum()); |
| | | // } |
| | | // |
| | | // String id = repairOrder1.getId(); |
| | | // QueryWrapper<RepairOrderActualWorkHours> wrapper = new QueryWrapper<>(); |
| | | // wrapper.eq("repair_order_id", id) |
| | | // .eq("del_flag", 0); |
| | | // wrapper.select("sum(actual_hour) as actualHour"); |
| | | // Map<String, Object> map = repairOrderActualWorkHoursService.getMap(wrapper); |
| | | // BigDecimal actualHour = new BigDecimal(0); |
| | | // if (map != null) { |
| | | // actualHour = (BigDecimal) map.get("actualHour"); |
| | | // } |
| | | // repairOrder1.setActualHour(actualHour); |
| | | // } |
| | | return Result.OK(pageList); |
| | | } |
| | | |
| | |
| | | public Result<?> orderStart(@RequestBody RepairOrder repairOrder){ |
| | | if(StringUtils.isNotBlank(repairOrder.getReportRepairId())){ |
| | | EquipmentReportRepair equipmentReportRepair = equipmentReportRepairService.getById(repairOrder.getReportRepairId()); |
| | | equipmentReportRepair.setStatus("3"); |
| | | equipmentReportRepair.setStatus("2"); |
| | | equipmentReportRepairService.updateById(equipmentReportRepair); |
| | | if(StringUtils.isNotBlank(equipmentReportRepair.getEquipmentId())){ |
| | | Equipment equipment = equipmentService.getById(equipmentReportRepair.getEquipmentId()); |
| | |
| | | projectMaintenanceOrder.setTypeStatus("underExecution"); |
| | | projectMaintenanceOrderService.updateById(projectMaintenanceOrder); |
| | | } |
| | | return Result.OK(repairOrderService.update(new UpdateWrapper<RepairOrder>().set("status",3).set("actual_start_time",new Date(System.currentTimeMillis())).eq("id",repairOrder.getId()))); |
| | | repairOrder |
| | | .setStatus("3") |
| | | .setActualStartTime(new Date()) |
| | | .setRepairOrderUda1("normal"); |
| | | repairOrderService.updateById(repairOrder); |
| | | return Result.OK("开工成功"); |
| | | } |
| | | /** |
| | | * 工单报工 |
| | |
| | | * @return |
| | | */ |
| | | @PutMapping(value = "/report") |
| | | @Transactional(rollbackFor = {Exception.class}) |
| | | public Result<?> orderReport(@RequestBody RepairOrder repairOrder){ |
| | | String id = repairOrder.getId(); |
| | | List<RepairOrderActualWorkHours> hoursList = repairOrderActualWorkHoursService.list(new QueryWrapper<RepairOrderActualWorkHours>().eq("repair_order_id",id).eq("del_flag",0)); |
| | | List<RepairOrderActualWorkHours> mainStuff = repairOrderActualWorkHoursService.list(new QueryWrapper<RepairOrderActualWorkHours>().eq("repair_order_id",id).eq("del_flag",0).eq("principal_contractor","1")); |
| | | if(hoursList.size()<2){ |
| | | return Result.error("操作失败,请至少添加两个承修人"); |
| | | } |
| | | if(mainStuff.size()!=1){ |
| | | return Result.error("操作失败,请添加主承修人,有且只有一个"); |
| | | } |
| | | if(StringUtils.isNotBlank(repairOrder.getProjectMaintenanceOrderId())){ |
| | | //判断项目性维修子表状态 |
| | | ProjectMaintenanceOrderDetail projectMaintenanceOrderDetail = projectMaintenanceOrderDetailService.getById(repairOrder.getProjectMaintenanceOrderId()); |
| | |
| | | } |
| | | LoginUser user= (LoginUser)SecurityUtils.getSubject().getPrincipal(); |
| | | if(StringUtils.isNotBlank(repairOrder.getReportRepairId())){ |
| | | equipmentReportRepairService.update(new UpdateWrapper<EquipmentReportRepair>().eq("id",repairOrder.getReportRepairId()).set("status",3)); |
| | | equipmentReportRepairService.update(new UpdateWrapper<EquipmentReportRepair>().eq("id",repairOrder.getReportRepairId()).set("status",4)); |
| | | } |
| | | return Result.OK(repairOrderService.update(new UpdateWrapper<RepairOrder>().set("status",4).set("actual_end_time",new Date(System.currentTimeMillis())).set("recipient_user_id",user.getId()).eq("id",repairOrder.getId()))); |
| | | Date now = new Date(); |
| | | Date start = repairOrder.getActualStartTime(); |
| | | long timeDifference = now.getTime() - start.getTime(); |
| | | BigDecimal hours = new BigDecimal(timeDifference) |
| | | .divide(new BigDecimal(60 * 60 * 1000), 3, BigDecimal.ROUND_HALF_EVEN); |
| | | repairOrder.setStatus("4"); |
| | | repairOrder.setActualEndTime(now); |
| | | repairOrder.setActualHour(hours); |
| | | repairOrder.setRecipientUserId(mainStuff.get(0).getUserId()); |
| | | repairOrderService.updateById(repairOrder); |
| | | if(StringUtils.isNotBlank(repairOrder.getEquipmentId())){ |
| | | Equipment equipment = equipmentService.getById(repairOrder.getEquipmentId()); |
| | | equipment.setEquipmentStatus("4"); |
| | | equipmentService.updateById(equipment); |
| | | } |
| | | return Result.OK("报工成功"); |
| | | } |
| | | /** |
| | | * 工单撤销 |
| | |
| | | equipmentReportRepairService.updateBatchById(equipmentReportRepairs); |
| | | return Result.OK("领取成功"); |
| | | } |
| | | /** |
| | | * 工单等备件 |
| | | * @param repairOrder |
| | | * @return |
| | | */ |
| | | @PutMapping(value = "/handleSpare") |
| | | @Transactional(rollbackFor = {Exception.class}) |
| | | public Result<?> handleSpare(@RequestBody RepairOrder repairOrder){ |
| | | repairOrder.setRepairOrderUda2(new Date()); |
| | | repairOrder.setRepairOrderUda1("needSpare"); |
| | | repairOrderService.updateById(repairOrder); |
| | | if(StringUtils.isNotBlank(repairOrder.getEquipmentId())){ |
| | | Equipment equipment = equipmentService.getById(repairOrder.getEquipmentId()); |
| | | equipment.setEquipmentStatus("8"); |
| | | equipmentService.updateById(equipment); |
| | | } |
| | | return Result.OK("操作成功"); |
| | | } |
| | | /** |
| | | * 工单停止等备件 |
| | | * @param repairOrder |
| | | * @return |
| | | */ |
| | | @PutMapping(value = "/handleSpareStop") |
| | | @Transactional(rollbackFor = {Exception.class}) |
| | | public Result<?> handleSpareStop(@RequestBody RepairOrder repairOrder){ |
| | | Date now = new Date(); |
| | | Date start = repairOrder.getRepairOrderUda2(); |
| | | long timeDifference = now.getTime() - start.getTime(); |
| | | BigDecimal hours = new BigDecimal(timeDifference) |
| | | .divide(new BigDecimal(60 * 60 * 1000), 3, BigDecimal.ROUND_HALF_EVEN); |
| | | repairOrder.setRepairOrderUda3(now); |
| | | repairOrder.setRepairOrderUda1("normal"); |
| | | repairOrder.setSpareTime(hours); |
| | | repairOrderService.updateById(repairOrder); |
| | | if(StringUtils.isNotBlank(repairOrder.getEquipmentId())){ |
| | | Equipment equipment = equipmentService.getById(repairOrder.getEquipmentId()); |
| | | equipment.setEquipmentStatus("7"); |
| | | equipmentService.updateById(equipment); |
| | | } |
| | | return Result.OK("操作成功"); |
| | | } |
| | | /** |
| | | * 工单等加工件 |
| | | * @param repairOrder |
| | | * @return |
| | | */ |
| | | @PutMapping(value = "/handlePart") |
| | | @Transactional(rollbackFor = {Exception.class}) |
| | | public Result<?> handlePart(@RequestBody RepairOrder repairOrder){ |
| | | repairOrder.setRepairOrderUda4(new Date()); |
| | | repairOrder.setRepairOrderUda1("needPart"); |
| | | repairOrderService.updateById(repairOrder); |
| | | if(StringUtils.isNotBlank(repairOrder.getEquipmentId())){ |
| | | Equipment equipment = equipmentService.getById(repairOrder.getEquipmentId()); |
| | | equipment.setEquipmentStatus("9"); |
| | | equipmentService.updateById(equipment); |
| | | } |
| | | return Result.OK("操作成功"); |
| | | } |
| | | /** |
| | | * 工单停止等加工件 |
| | | * @param repairOrder |
| | | * @return |
| | | */ |
| | | @PutMapping(value = "/handlePartStop") |
| | | @Transactional(rollbackFor = {Exception.class}) |
| | | public Result<?> handlePartStop(@RequestBody RepairOrder repairOrder){ |
| | | Date now = new Date(); |
| | | Date start = repairOrder.getRepairOrderUda4(); |
| | | long timeDifference = now.getTime() - start.getTime(); |
| | | BigDecimal hours = new BigDecimal(timeDifference) |
| | | .divide(new BigDecimal(60 * 60 * 1000), 3, BigDecimal.ROUND_HALF_EVEN); |
| | | repairOrder.setRepairOrderUda5(now); |
| | | repairOrder.setRepairOrderUda1("normal"); |
| | | repairOrder.setPartTime(hours); |
| | | repairOrderService.updateById(repairOrder); |
| | | if(StringUtils.isNotBlank(repairOrder.getEquipmentId())){ |
| | | Equipment equipment = equipmentService.getById(repairOrder.getEquipmentId()); |
| | | equipment.setEquipmentStatus("7"); |
| | | equipmentService.updateById(equipment); |
| | | } |
| | | return Result.OK("操作成功"); |
| | | } |
| | | |
| | | /** |
| | | * 设备完好率 |
| | | * |
| | | * @return |
| | | */ |
| | | @GetMapping("/equipmentAvailability") |
| | | public JSONObject equipmentAvailability(@RequestParam Map<String, String> query) throws ParseException { |
| | | List<EquipmentAvailabilityVo> list = repairOrderService.equipmentAvailability(query); |
| | | JSONObject jsonObject = new JSONObject(); |
| | | jsonObject.put("data",list); |
| | | return jsonObject; |
| | | } |
| | | |
| | | /** |
| | | * 设备可开动率 |
| | | * |
| | | * @return |
| | | */ |
| | | @GetMapping("/getStartRate") |
| | | public JSONObject getStartRate(@RequestParam Map<String, String> query) throws ParseException { |
| | | List<EquipmentAvailabilityVo> list = repairOrderService.getStartRate(query); |
| | | JSONObject jsonObject = new JSONObject(); |
| | | jsonObject.put("data",list); |
| | | return jsonObject; |
| | | } |
| | | } |