| | |
| | | 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.system.vo.LoginUser; |
| | | import org.jeecg.common.util.oConvertUtils; |
| | | import org.jeecg.modules.eam.entity.*; |
| | | import org.jeecg.modules.eam.mapper.RepairOrderMapper; |
| | | import org.jeecg.modules.eam.service.*; |
| | | import org.jeecg.modules.eam.vo.EquipmentAvailabilityVo; |
| | | import org.jeecg.modules.eam.vo.RepairReportExportVo; |
| | | import org.jeecg.modules.system.entity.SysUser; |
| | | import org.jeecg.modules.system.mapper.SysUserMapper; |
| | | import org.jeecgframework.poi.excel.ExcelImportUtil; |
| | | import org.jeecgframework.poi.excel.def.NormalExcelConstants; |
| | | import org.jeecgframework.poi.excel.entity.ExportParams; |
| | | import org.jeecgframework.poi.excel.entity.ImportParams; |
| | | import org.jeecgframework.poi.excel.view.JeecgEntityExcelView; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.beans.factory.annotation.Value; |
| | | import org.springframework.context.annotation.Lazy; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | import org.springframework.web.bind.annotation.*; |
| | |
| | | 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; |
| | | |
| | |
| | | @Autowired |
| | | @Lazy |
| | | private IProjectMaintenanceOrderService projectMaintenanceOrderService; |
| | | @Autowired |
| | | @Lazy |
| | | private IdentityService sysIdentityService; |
| | | @Autowired |
| | | private RepairOrderMapper repairOrderMapper; |
| | | @Autowired |
| | | private SysUserMapper sysUserMapper; |
| | | @Value("${jeecg.path.upload}") |
| | | private String upLoadPath; |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | |
| | | 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()); |
| | | } |
| | | List<RepairOrder> records = pageList.getRecords(); |
| | | for (RepairOrder record : records) { |
| | | record.setFaultCauseCount("故障原因统计"); |
| | | List<Map<String, Object>> allFaultCause = repairOrderService.getAllFaultCause(); |
| | | record.setAllFaultCause(allFaultCause); |
| | | |
| | | 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); |
| | | String equipmentId = record.getEquipmentId(); |
| | | List<Map<String, Object>> faultCause = repairOrderService.getFaultCause(equipmentId); |
| | | record.setEquipmentFaultCause(faultCause); |
| | | } |
| | | // 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); |
| | | } |
| | | |
| | |
| | | return Result.OK("批量删除成功!"); |
| | | } |
| | | |
| | | /** |
| | | * 导出 |
| | | * @return |
| | | */ |
| | | //@RequiresPermissions("org.jeecg.modules.demo:mom_eam_repair_order:exportXls") |
| | | @RequestMapping(value = "/exportXls") |
| | | public ModelAndView exportXls(HttpServletRequest request, RepairOrder repairOrder) { |
| | | return super.exportXls(request, repairOrder, RepairOrder.class, "维修工单"); |
| | | } |
| | | @RequestMapping(value = "/exportXls") |
| | | public ModelAndView exportXls(HttpServletRequest request, RepairOrder repairOrder) { |
| | | // Step.1 组装查询条件 |
| | | String title = "维修履历"; |
| | | LoginUser sysUser = (LoginUser) SecurityUtils.getSubject().getPrincipal(); |
| | | // Step.2 获取导出数据 |
| | | if(StringUtils.isNotBlank(repairOrder.getUserId())){ |
| | | SysUser user = sysUserMapper.selectById(repairOrder.getUserId()); |
| | | repairOrder.setTeamId(user.getTeamId()); |
| | | }else{ |
| | | repairOrder.setTeamId(""); |
| | | } |
| | | List<String> equipNums = new ArrayList<>(); |
| | | if(StringUtils.isNotBlank(repairOrder.getNums())){ |
| | | equipNums = Arrays.asList(repairOrder.getNums().trim().split("\n")).stream().filter(num->!num.equals("\n")).collect(Collectors.toList()); |
| | | } |
| | | List<RepairOrder> exportList = repairOrderMapper.getRepairOrderList(null,repairOrder.getId(), |
| | | repairOrder.getNum(), |
| | | repairOrder.getEquipmentNum(), |
| | | repairOrder.getEquipmentName(), |
| | | repairOrder.getStatus(), |
| | | repairOrder.getRepairOrderType(), |
| | | repairOrder.getEquipmentCategoryId(), |
| | | repairOrder.getFactoryModelId(), |
| | | repairOrder.getSpecificEquipment(), |
| | | repairOrder.getTeamId(), |
| | | equipNums, |
| | | repairOrder.getRepairOrderUda1(), |
| | | repairOrder.getFaultStartTime(), |
| | | repairOrder.getFaultEndTime(), |
| | | repairOrder.getCreateStartTime(), |
| | | repairOrder.getCreateEndTime(), |
| | | repairOrder.getEquipmentImportanceId(), |
| | | repairOrder.getFaultCause()); |
| | | |
| | | // Step.3 AutoPoi 导出Excel |
| | | ModelAndView mv = new ModelAndView(new JeecgEntityExcelView()); |
| | | //此处设置的filename无效 ,前端会重更新设置一下 |
| | | mv.addObject(NormalExcelConstants.FILE_NAME, title); |
| | | mv.addObject(NormalExcelConstants.CLASS, RepairOrder.class); |
| | | //update-begin--Author:liusq Date:20210126 for:图片导出报错,ImageBasePath未设置-------------------- |
| | | ExportParams exportParams=new ExportParams(title + "报表", "导出人:" + sysUser.getRealname(), title); |
| | | exportParams.setImageBasePath(upLoadPath); |
| | | //update-end--Author:liusq Date:20210126 for:图片导出报错,ImageBasePath未设置---------------------- |
| | | mv.addObject(NormalExcelConstants.PARAMS,exportParams); |
| | | mv.addObject(NormalExcelConstants.DATA_LIST, exportList); |
| | | return mv; |
| | | } |
| | | |
| | | /** |
| | | * 导入 |
| | |
| | | IPage<RepairOrderDetail> pageList = repairOrderDetailService.page(page, queryWrapper); |
| | | return Result.OK(pageList); |
| | | } |
| | | |
| | | @GetMapping(value = "/pageRepairOrderDetailByMainId") |
| | | public Result<IPage<RepairOrderDetail>> pageRepairOrderDetailByMainId(@RequestParam("pageNo") Integer pageNo, |
| | | @RequestParam("pageSize") Integer pageSize, |
| | | @RequestParam Map<String, Object> params) { |
| | | IPage<RepairOrderDetail> pageList = repairOrderDetailService.pageRepairOrderDetailByMainId(pageNo, pageSize, params); |
| | | return Result.OK(pageList); |
| | | } |
| | | |
| | | /** |
| | | * 添加 |
| | |
| | | * @return |
| | | */ |
| | | @PutMapping(value = "/start") |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public Result<?> orderStart(@RequestBody RepairOrder repairOrder){ |
| | | if(StringUtils.isNotBlank(repairOrder.getReportRepairId())){ |
| | | EquipmentReportRepair equipmentReportRepair = equipmentReportRepairService.getById(repairOrder.getReportRepairId()); |
| | | equipmentReportRepair.setStatus("2"); |
| | | equipmentReportRepairService.updateById(equipmentReportRepair); |
| | | if(StringUtils.isNotBlank(equipmentReportRepair.getEquipmentId())){ |
| | | Equipment equipment = equipmentService.getById(equipmentReportRepair.getEquipmentId()); |
| | | equipment.setEquipmentStatus("7"); |
| | | equipmentService.updateById(equipment); |
| | | } |
| | | } |
| | | if(StringUtils.isNotBlank(repairOrder.getProjectMaintenanceOrderId())){ |
| | | //判断项目性维修子表状态 |
| | | ProjectMaintenanceOrderDetail projectMaintenanceOrderDetail = projectMaintenanceOrderDetailService.getById(repairOrder.getProjectMaintenanceOrderId()); |
| | |
| | | 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("报工成功"); |
| | | } |
| | | /** |
| | | * 工单撤销 |
| | |
| | | } |
| | | return Result.OK(repairOrderService.update(new UpdateWrapper<RepairOrder>().set("status",7).eq("id",repairOrder.getId()))); |
| | | } |
| | | @PostMapping("addBySelectReport") |
| | | public Result<?> addBySelectReport(@RequestBody List<EquipmentReportRepair> equipmentReportRepairs){ |
| | | LoginUser user= (LoginUser)SecurityUtils.getSubject().getPrincipal(); |
| | | for(EquipmentReportRepair equipmentReportRepair:equipmentReportRepairs){ |
| | | String num = sysIdentityService.getNumByTypeAndLength("RepairOrder",4); |
| | | Equipment equipment = equipmentService.getById(equipmentReportRepair.getEquipmentId()); |
| | | equipmentReportRepair.setStatus("2"); |
| | | RepairOrder repairOrder = new RepairOrder(); |
| | | repairOrder.setNum(num); |
| | | repairOrder.setReportRepairId(equipmentReportRepair.getId()); |
| | | repairOrder.setStatus("2"); |
| | | repairOrder.setEquipmentId(equipment.getId()); |
| | | repairOrder.setTeamId(equipment.getTeamId()); |
| | | repairOrder.setDepartId(equipment.getUseId()); |
| | | repairOrder.setFaultDescription(equipmentReportRepair.getFaultDescription()); |
| | | repairOrder.setFaultTime(equipmentReportRepair.getFaultTime()); |
| | | repairOrder.setResponsibilityId(user.getId()); |
| | | repairOrder.setRepairOrderType(0); |
| | | repairOrder.setDelFlag(0); |
| | | repairOrderService.save(repairOrder); |
| | | } |
| | | 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; |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 设备维修柱状图 |
| | | * qsw 2024-7-11 |
| | | */ |
| | | @GetMapping("getFaultCausePie") |
| | | public Result<?> getFaultCausePie(@RequestParam Map<String, Object> params) { |
| | | List<Map<String, Object>> faultCausePie = repairOrderService.getFaultCausePie(params); |
| | | return Result.ok(faultCausePie); |
| | | } |
| | | |
| | | /** |
| | | * 设备维修扇形图 |
| | | * qsw 2024-7-11 |
| | | */ |
| | | @GetMapping("getFaultCauseBar") |
| | | public Result<?> getFaultCauseBar(@RequestParam Map<String, Object> params) { |
| | | List<Map<String, Object>> faultCauseBar = repairOrderService.getFaultCauseBar(params); |
| | | return Result.ok(faultCauseBar); |
| | | } |
| | | |
| | | |
| | | /** |
| | | * MTPF |
| | | * qsw 2024-7-11 |
| | | */ |
| | | @GetMapping("getMTPF") |
| | | public Result<?> getMTPF(@RequestParam("pageNo") Integer pageNo, |
| | | @RequestParam("pageSize") Integer pageSize, |
| | | @RequestParam Map<String, Object> params) { |
| | | IPage<Map<String, Object>> mtpf = repairOrderService.getMTPF(pageNo, pageSize, params); |
| | | return Result.ok(mtpf); |
| | | } |
| | | |
| | | } |