EquipmentMaintenancePlanController.java 24.2 KB
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489
package com.skua.modules.equipment.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.skua.aop.annotation.CustomExceptionAnno;
import com.skua.core.api.vo.Result;
import com.skua.core.aspect.annotation.AutoLog;
import com.skua.core.query.QueryGenerator;
import com.skua.core.util.DateUtils;
import com.skua.modules.common.service.ICommonSqlService;
import com.skua.modules.equipment.dto.EquipmentMaintenancePlanDTO;
import com.skua.modules.equipment.entity.EquipmentInfo;
import com.skua.modules.equipment.entity.EquipmentMaintenancePlan;
import com.skua.modules.equipment.entity.EquipmentMaintenanceTask;
import com.skua.modules.equipment.enums.EquipmentMaintenanceEnums;
import com.skua.modules.equipment.service.IEquipmentInfoService;
import com.skua.modules.equipment.service.IEquipmentMaintenancePlanService;
import com.skua.modules.equipment.service.IEquipmentMaintenanceTaskService;
import com.skua.modules.equipment.util.EquipmentUtils;
import com.skua.modules.equipment.vo.EquipmentInfoVO;
import com.skua.modules.equipment.vo.EquipmentMaintenancePlanVO;
import com.skua.redis.component.Key2ValueService;
import com.skua.redis.util.CustomRedisUtil;
import com.skua.tool.javassist.JavassistFactory;
import com.skua.tool.query.WrapperFactory;
import com.skua.tool.util.BeanExtUtils;
import com.skua.tool.util.UniqIdUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang.StringUtils;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.io.ClassPathResource;
import org.springframework.core.io.Resource;
import org.springframework.transaction.support.TransactionTemplate;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.multipart.MultipartHttpServletRequest;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.File;
import java.io.InputStream;
import java.io.OutputStream;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.stream.Collectors;

/**
 * 设备保养计划
 */
@Slf4j
@Api(tags = "设备保养计划")
@RestController
@RequestMapping("/equipment/equipmentMaintenancePlan")
public class EquipmentMaintenancePlanController {

    @Autowired
    private IEquipmentMaintenancePlanService equipmentMaintenancePlanService;
    @Autowired
    private IEquipmentMaintenanceTaskService equipmentMaintenanceTaskService;
    @Autowired
    private TransactionTemplate transactionTemplate;
    @Autowired
    private IEquipmentInfoService equipmentInfoService;
    @Autowired
    private ICommonSqlService commonSqlService;
    @Autowired
    private CustomRedisUtil customRedisUtil;
    @Autowired
    private Key2ValueService key2ValueService;

    /**
     * 分页列表查询
     *
     * @param equipmentMaintenancePlan
     * @param pageNo
     * @param pageSize
     * @param req
     * @return
     */
    @AutoLog(value = "设备保养计划-分页列表查询")
    @ApiOperation(value = "设备保养计划-分页列表查询", notes = "设备保养计划-分页列表查询")
    @CustomExceptionAnno(description = "设备保养计划-分页列表查询")
    @GetMapping(value = "/list")
    public Result<IPage<EquipmentMaintenancePlanVO>> queryPageList(EquipmentMaintenancePlan equipmentMaintenancePlan,
                                                                   @RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo,
                                                                   @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize,
                                                                   HttpServletRequest req) throws Exception {
        Result<IPage<EquipmentMaintenancePlanVO>> result = new Result<>();
        QueryWrapper<EquipmentMaintenancePlan> queryWrapper = QueryGenerator.initQueryWrapper(equipmentMaintenancePlan, req.getParameterMap());
        Page<EquipmentMaintenancePlan> page = new Page<>(pageNo, pageSize);
        IPage<EquipmentMaintenancePlan> pageList = equipmentMaintenancePlanService.page(page, queryWrapper);
        Map<String, String> sysUserVal2KeyMap = EquipmentUtils.convertFunc("sysUser", false);
        List<EquipmentMaintenancePlanVO> equipmentMaintenancePlanVOList = BeanExtUtils.beans2Beans(pageList.getRecords(), EquipmentMaintenancePlanVO.class, (targetFieldName, srcFieldVal) -> {
            if ("departId_dictText".equals(targetFieldName)) {
                return customRedisUtil.hget("sys_depart", srcFieldVal.toString(), "id", "depart_name");
            } else if ("planExecutor_dictText".equals(targetFieldName)) {
                return sysUserVal2KeyMap.getOrDefault("" + srcFieldVal, "" + srcFieldVal);
            }
            return srcFieldVal;
        });
        Page<EquipmentMaintenancePlanVO> pageVO = new Page<>(pageNo, pageSize);
        pageVO.setTotal(pageList.getTotal());
        pageVO.setRecords(equipmentMaintenancePlanVOList);
        result.setSuccess(true);
        result.setResult(pageVO);
        return result;
    }

    @AutoLog(value = "设备保养计划-设备详情")
    @ApiOperation(value = "设备保养计划-设备详情", notes = "设备保养计划-设备详情")
    @CustomExceptionAnno(description = "设备保养计划-设备详情")
    @GetMapping(value = "/infoDetail")
    public Result<List<EquipmentInfoVO>> infoDetailCtrl(@RequestParam("id") String id) throws Exception {
        Result<List<EquipmentInfoVO>> result = new Result<>();
        EquipmentMaintenancePlan equipmentMaintenancePlan = equipmentMaintenancePlanService.getById(id);
        String infoIds = equipmentMaintenancePlan.getInfoIds();
        QueryWrapper<EquipmentInfo> queryWrapper = new QueryWrapper<>();
        queryWrapper.in("id", Arrays.asList(infoIds.split(",")));
        List<EquipmentInfo> equipmentInfoList = equipmentInfoService.list(queryWrapper);
        Map<String, String> equipmentTypeVal2KeyMap = key2ValueService.dictKey2Val("equipment_equipment-type", false);
        List<EquipmentInfoVO> equipmentInfoVOList = BeanExtUtils.beans2Beans(equipmentInfoList, EquipmentInfoVO.class, (targetFieldName, srcFieldVal) -> {
            if ("departId_dictText".equals(targetFieldName) || "departIdName".equals(targetFieldName)) {
                return customRedisUtil.hget("sys_depart", srcFieldVal.toString(), "id", "depart_name");
            } else if ("equipmentType_dictText".equals(targetFieldName)) {
                return equipmentTypeVal2KeyMap.getOrDefault(srcFieldVal, "");
            }
            return srcFieldVal;
        });
        result.setSuccess(true);
        equipmentInfoVOList.forEach(item -> item.setEquipmentSparepartList(new ArrayList<>()));
        result.setResult(equipmentInfoVOList);
        return result;
    }

    @AutoLog(value = "设备保养计划-发布")
    @ApiOperation(value = "设备保养计划-发布", notes = "设备保养计划-发布")
    @GetMapping(value = "/publish")
    public Result<Object> publishCtrl(@RequestParam(name = "id") String id) {
        Result<Object> result = new Result<>();
        EquipmentMaintenancePlan equipmentMaintenancePlan = equipmentMaintenancePlanService.getById(id);
        if (equipmentMaintenancePlan.getReleaseStatus().equals(EquipmentMaintenanceEnums.PUBLISHED.getKey())) {
            result.setMessage("该保养计划已发布,无法重复发布!");
            return result;
        }
        if (equipmentMaintenancePlan.getInfoIds().isEmpty()) {
            result.setMessage("该保养尚未选择设备,无法发布!");
            return result;
        }
        this.handlePublish(equipmentMaintenancePlan);
        return result;
    }

    /**
     * 处理发布
     *
     * @param equipmentMaintenancePlan
     */
    private void handlePublish(EquipmentMaintenancePlan equipmentMaintenancePlan) {
        Date planStartTime = equipmentMaintenancePlan.getPlanStartTime();
        Date planEndTime = equipmentMaintenancePlan.getPlanEndTime();
        Integer cycleWay = equipmentMaintenancePlan.getCycleWay();
        Integer cyclePeriod = equipmentMaintenancePlan.getCyclePeriod();
        long interval = 1L;
        if (cycleWay == 1) {
            // 日
            interval = (long) 1000 * 60 * 60 * 24;
        } else if (cycleWay == 2) {
            // 月
            interval = (long) 1000 * 60 * 60 * 24 * 30;
        } else if (cycleWay == 3) {
            // 年
            interval = (long) 1000 * 60 * 60 * 24 * 30 * 365;
        }
        interval *= cyclePeriod;
        long times = (planEndTime.getTime() - planStartTime.getTime()) / interval + 1;
        List<EquipmentMaintenanceTask> equipmentMaintenanceTaskList = new ArrayList<>();
        Date taskStartTime, taskEndTime;
        for (long i = 1; i <= times; i++) {
            taskStartTime = DateUtils.getDate(planStartTime.getTime() + (i - 1) * interval);
            taskEndTime = DateUtils.getDate(Math.min(planStartTime.getTime() + i * interval, planEndTime.getTime()));
            EquipmentMaintenanceTask equipmentMaintenanceTask = new EquipmentMaintenanceTask();
            String taskId = UniqIdUtils.getInstance().getUniqID();
            equipmentMaintenanceTask.setId(taskId);
            equipmentMaintenanceTask.setPlanId(equipmentMaintenancePlan.getId());
            String maintenanceTaskCode = "BYRW-" + DateUtils.format(new Date(), "YYYYMMdd" + "-" + System.currentTimeMillis());
            equipmentMaintenanceTask.setTaskCode(maintenanceTaskCode);
            equipmentMaintenanceTask.setTaskExecutor(equipmentMaintenancePlan.getPlanExecutor());
            equipmentMaintenanceTask.setTaskStatus(EquipmentMaintenanceEnums.NORMAL.getKey());
            equipmentMaintenanceTask.setTaskResult(EquipmentMaintenanceEnums.NOT_FINISH.getKey());
            equipmentMaintenanceTask.setTaskStartTime(taskStartTime);
            equipmentMaintenanceTask.setTaskEndTime(taskEndTime);
            equipmentMaintenanceTask.setInfoIds(equipmentMaintenancePlan.getInfoIds());
            equipmentMaintenanceTaskList.add(equipmentMaintenanceTask);
        }
        equipmentMaintenancePlan.setReleaseStatus(1);
        transactionTemplate.execute((transactionStatus -> {
            boolean val0 = equipmentMaintenanceTaskService.saveBatch(equipmentMaintenanceTaskList);
            boolean val1 = equipmentMaintenancePlanService.updateById(equipmentMaintenancePlan);
            if (val0 && val1) {
                return 1;
            }
            transactionStatus.setRollbackOnly();
            return 0;
        }));
    }

    /**
     * 添加
     *
     * @param equipmentMaintenancePlanDTO
     * @return
     */
    @AutoLog(value = "设备保养计划-添加")
    @ApiOperation(value = "设备保养计划-添加", notes = "设备保养计划-添加")
    @PostMapping(value = "/add")
    public Result<EquipmentMaintenancePlan> add(@RequestBody EquipmentMaintenancePlanDTO equipmentMaintenancePlanDTO) {
        Result<EquipmentMaintenancePlan> result = new Result<>();
        try {
            EquipmentMaintenancePlan equipmentMaintenancePlan = BeanExtUtils.bean2Bean(equipmentMaintenancePlanDTO, EquipmentMaintenancePlan.class);
            String planId = UniqIdUtils.getInstance().getUniqID();
            equipmentMaintenancePlan.setId(planId);
            String maintenancePlanCode = "BYJH-" + DateUtils.format(new Date(), "YYYYMMdd" + "-" + System.currentTimeMillis());
            equipmentMaintenancePlan.setPlanCode(maintenancePlanCode);
            equipmentMaintenancePlanService.save(equipmentMaintenancePlan);
            result.success("添加成功!");
        } catch (Exception e) {
            log.error(e.getMessage(), e);
            result.error500("操作失败: " + e.getMessage());
        }
        return result;
    }

    /**
     * 编辑
     *
     * @param equipmentMaintenancePlanDTO
     * @return
     */
    @AutoLog(value = "设备保养计划-编辑")
    @ApiOperation(value = "设备保养计划-编辑", notes = "设备保养计划-编辑")
    @PutMapping(value = "/edit")
    @CustomExceptionAnno(description = "设备保养计划-编辑")
    public Result<EquipmentMaintenancePlan> edit(@RequestBody EquipmentMaintenancePlanDTO equipmentMaintenancePlanDTO) throws Exception {
        Result<EquipmentMaintenancePlan> result = new Result<>();
        EquipmentMaintenancePlan equipmentMaintenancePlanEntity = equipmentMaintenancePlanService.getById(equipmentMaintenancePlanDTO.getId());
        if (equipmentMaintenancePlanEntity == null) {
            result.error500("未找到对应实体");
        } else {
            EquipmentMaintenancePlan equipmentMaintenancePlan = BeanExtUtils.bean2Bean(equipmentMaintenancePlanDTO, EquipmentMaintenancePlan.class);
            equipmentMaintenancePlanService.updateById(equipmentMaintenancePlan);
        }
        return result;
    }

    /**
     * 通过id删除
     *
     * @param id
     * @return
     */
    @AutoLog(value = "设备保养计划-通过id删除")
    @ApiOperation(value = "设备保养计划-通过id删除", notes = "设备保养计划-通过id删除")
    @DeleteMapping(value = "/delete")
    public Result<?> delete(@RequestParam(name = "id") String id) {
        try {
            QueryWrapper<?> queryWrapper = new QueryWrapper<>();
            queryWrapper.eq("plan_id", id);
            List<Map<String, Object>> mapList = commonSqlService.queryWrapperForList("select id as taskId from equipment_maintenance_task", queryWrapper);
            List<String> taskIdList = new ArrayList<>();
            for (Map<String, Object> item : mapList) {
                taskIdList.add("" + item.get("taskId"));
            }
            transactionTemplate.execute((transactionStatus) -> {
                // 保养计划
                boolean val0 = equipmentMaintenancePlanService.removeById(id);
                // 保养任务
                Integer val1 = commonSqlService.deleteWrapper("equipment_maintenance_task", queryWrapper);
                // 保养关联
                Integer val2 = 0;
                if (!taskIdList.isEmpty()) {
                    QueryWrapper<?> queryWrapper2 = new QueryWrapper<>();
                    queryWrapper2.in("task_id", taskIdList)
                            .isNull("record_id");
                    val2 = commonSqlService.deleteWrapper("equipment_maintenance_record_child", queryWrapper2);
                }
                if (val0 && val1 >= 0 && val2 >= 0) {
                    return 1;
                }
                transactionStatus.setRollbackOnly();
                return 0;
            });
        } 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<EquipmentMaintenancePlan> deleteBatch(@RequestParam(name = "ids", required = true) String ids) {
        Result<EquipmentMaintenancePlan> result = new Result<>();
        if (ids == null || "".equals(ids.trim())) {
            result.error500("参数不识别!");
        } else {
            List<String> planIdList = Arrays.asList(ids.split(","));
            QueryWrapper<?> queryWrapper = new QueryWrapper<>();
            queryWrapper.in("plan_id", planIdList);
            List<Map<String, Object>> mapList = commonSqlService.queryWrapperForList("select id as taskId from equipment_maintenance_task", queryWrapper);
            List<String> taskIdList = new ArrayList<>();
            for (Map<String, Object> item : mapList) {
                taskIdList.add("" + item.get("taskId"));
            }
            QueryWrapper<?> queryWrapper2 = new QueryWrapper<>();
            queryWrapper2.in("task_id", taskIdList)
                    .isNull("record_id");
            transactionTemplate.execute((transactionStatus) -> {
                boolean val0 = equipmentMaintenancePlanService.removeByIds(planIdList);
                Integer val1 = commonSqlService.deleteWrapper("equipment_maintenance_task", queryWrapper);
                Integer val2 = commonSqlService.deleteWrapper("equipment_maintenance_record_child", queryWrapper2);
                if (val0 && val1 >= 0 && val2 >= 0) {
                    return 1;
                }
                transactionStatus.setRollbackOnly();
                return 0;
            });
            result.success("批量删除成功!");
        }
        return result;
    }

    @AutoLog(value = "设备保养计划-excel模板")
    @ApiOperation(value = "设备保养计划-excel模板", notes = "设备保养计划-excel模板")
    @GetMapping(value = "/downloadTemplate")
    public void downLoadTemplateCtrl(HttpServletRequest request, HttpServletResponse response) {
        try {
            Resource resource = new ClassPathResource("templates" + File.separator + "template-plan-qdhd.xls");
            InputStream inputStream = resource.getInputStream();
            OutputStream outputStream = response.getOutputStream();
            byte[] buf = new byte[1024];
            int len;
            while ((len = inputStream.read(buf)) > 0) {
                outputStream.write(buf, 0, len);
            }
            response.flushBuffer();
            outputStream.close();
        } catch (Exception e) {
            e.printStackTrace();
            log.error("设备保养计划-excel模板fail: {}", e.getMessage());
        }
    }

    @AutoLog(value = "设备保养计划-excel导入")
    @ApiOperation(value = "设备保养计划-excel导入", notes = "设备保养计划-excel导入")
    @RequestMapping(value = "/importExcel", method = RequestMethod.POST)
    public Result<?> importExcel(HttpServletRequest request, HttpServletResponse response) throws Exception {
        Result<?> result = new Result<>();
        Class sysDictClass = JavassistFactory
                .create()
                .className("SysDict")
                .field("id", String.class)
                .buildClass();
        Class sysDictItemClass = JavassistFactory
                .create()
                .className("SysDictItem")
                .field("dictId", String.class)
                .field("itemText", String.class)
                .field("itemValue", String.class)
                .buildClass();
        MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request;
        Map<String, MultipartFile> fileMap = multipartRequest.getFileMap();
        List<EquipmentMaintenancePlan> planList = new ArrayList<>();
        Map<String, String> departKey2ValMap = EquipmentUtils.convertFunc("depart", true);
        Map<String, String> sysUserKey2ValMap = EquipmentUtils.convertFunc("sysUser", true);
        for (Map.Entry<String, MultipartFile> entity : fileMap.entrySet()) {
            // 获取上传文件对象
            MultipartFile multipartFile = entity.getValue();
            String filename = multipartFile.getOriginalFilename();
            if (StringUtils.isEmpty(filename)) {
                continue;
            }
            InputStream inputStream = multipartFile.getInputStream();
            Workbook workbook;
            try {
                workbook = new XSSFWorkbook(inputStream);
            } catch (Exception e) {
                workbook = new HSSFWorkbook(inputStream);
            }
            // 获取第一个sheet
            Sheet sheet0 = workbook.getSheetAt(0);
            // 从第一行开始
            for (int i = 1; i <= sheet0.getLastRowNum(); i++) {
                Row curRow = sheet0.getRow(i);
                EquipmentMaintenancePlan plan = new EquipmentMaintenancePlan();
                // 所属机构
                String departId_dictText = curRow.getCell(0).getStringCellValue();
                String departId = departKey2ValMap.get(departId_dictText);
                plan.setDepartId(departId);
                // 保养计划名称
                String planName = curRow.getCell(1).getStringCellValue();
                plan.setPlanName(planName);
                // 保养内容
                String planContent_dictText = curRow.getCell(2).getStringCellValue();
                List<Map<String, Object>> planContentMapList = WrapperFactory
                        .joinWrapper()
                        .select("item_value")
                        .from(sysDictClass)
                        .innerJoin(sysDictItemClass, sysDictItemClass.getDeclaredField("dictId"), sysDictClass.getDeclaredField("id"))
                        .where()
                        .in(true, "item_text", Arrays.asList(planContent_dictText.split(",")))
                        .queryWrapperForList();
                String planContent = planContentMapList.stream().map(item -> "" + item.get("item_value")).collect(Collectors.joining(","));
                plan.setPlanContent(planContent);
                // 执行人
                String planExecutor_dictText = curRow.getCell(3).getStringCellValue();
                plan.setPlanExecutor(sysUserKey2ValMap.get(planExecutor_dictText));
                // 开始时间
                SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
                String planStartTime = simpleDateFormat.format(curRow.getCell(4).getDateCellValue());
                plan.setPlanStartTime(DateUtils.parseDate(planStartTime, "yyyy-MM-dd HH:mm:ss"));
                // 结束时间
                String planEndTime = simpleDateFormat.format(curRow.getCell(5).getDateCellValue());
                plan.setPlanEndTime(DateUtils.parseDate(planEndTime, "yyyy-MM-dd HH:mm:ss"));
                // 循环周期
                curRow.getCell(6).setCellType(Cell.CELL_TYPE_STRING);
                String cyclePeriod = curRow.getCell(6).getStringCellValue();
                plan.setCyclePeriod(Integer.parseInt(cyclePeriod));
                // 循环方式
                curRow.getCell(7).setCellType(Cell.CELL_TYPE_STRING);
                String cycleWay = curRow.getCell(7).getStringCellValue();
                switch (cycleWay) {
                    case "日":
                        plan.setCycleWay(1);
                        break;
                    case "月":
                        plan.setCycleWay(2);
                        break;
                    case "年":
                        plan.setCycleWay(3);
                        break;
                }
                // 限制时长
                curRow.getCell(8).setCellType(Cell.CELL_TYPE_STRING);
                String planTimeLimit = curRow.getCell(8).getStringCellValue();
                plan.setPlanTimeLimit(Integer.parseInt(planTimeLimit));
                // 说明
                try {
                    String description = curRow.getCell(9).getStringCellValue();
                    plan.setDescription(description);
                } catch (Exception e) {
                    e.printStackTrace();
                }
                // 设备ID
                String equipmentNames = curRow.getCell(10).getStringCellValue();
                List<Map<String, Object>> equipmentIdList = WrapperFactory
                        .joinWrapper()
                        .select("id")
                        .from(EquipmentInfo.class)
                        .where()
                        .in(true, "equipment_name", Arrays.asList(equipmentNames.split(",")))
                        .queryWrapperForList();
                String infoIds = equipmentIdList.stream().map(item -> "" + item.get("id")).collect(Collectors.joining(","));
                plan.setInfoIds(infoIds);
                String maintenancePlanCode = "BYJH-" + DateUtils.format(new Date(), "YYYYMMdd" + "-" + System.currentTimeMillis());
                plan.setPlanCode(maintenancePlanCode);
                planList.add(plan);
            }
        }
        equipmentMaintenancePlanService.saveBatch(planList);
        return result;
    }

}