package com.yeejoin.amos.maintenance.business.controller;

import com.yeejoin.amos.boot.biz.common.bo.ReginParams;
import com.yeejoin.amos.maintenance.business.dto.PointDto;
import com.yeejoin.amos.maintenance.business.param.PointImportParam;
import com.yeejoin.amos.maintenance.business.param.PointImportQueryParam;
import com.yeejoin.amos.maintenance.business.param.PointParam;
import com.yeejoin.amos.maintenance.business.service.intfc.ICatalogTreeService;
import com.yeejoin.amos.maintenance.business.service.intfc.IPointService;
import com.yeejoin.amos.maintenance.business.util.*;
import com.yeejoin.amos.maintenance.business.vo.MaintenanceResourceData;
import com.yeejoin.amos.maintenance.business.vo.PointClassifyVo;
import com.yeejoin.amos.maintenance.business.vo.PointInputItemVo;
import com.yeejoin.amos.maintenance.business.vo.PointVo;
import com.yeejoin.amos.maintenance.core.common.request.CommonPageable;
import com.yeejoin.amos.maintenance.core.common.request.CommonRequest;
import com.yeejoin.amos.maintenance.core.framework.PersonIdentify;
import com.yeejoin.amos.maintenance.dao.entity.Point;
import com.yeejoin.amos.maintenance.dao.entity.PointClassify;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.util.ObjectUtils;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import org.typroject.tyboot.core.foundation.context.RequestContext;
import org.typroject.tyboot.core.foundation.enumeration.UserType;
import org.typroject.tyboot.core.restful.doc.TycloudOperation;

import javax.servlet.http.HttpServletResponse;
import java.util.*;

@RestController
@RequestMapping(value = "/api/point")
@Api(tags = "巡检点api")
public class PointController extends AbstractBaseController {

    private final Logger log = LoggerFactory.getLogger(PointController.class);

    @Autowired
    private IPointService iPointService;

    @Autowired
    private ICatalogTreeService catalogTreeService;

    /**
     * 增加巡检点
     *
     * @param pointParam
     * @return
     */
    @TycloudOperation(ApiLevel = UserType.AGENCY)
    @PersonIdentify
    @ApiOperation(value = "新增巡检点", notes = "新增巡检点")
    @PostMapping(value = "/addPoint", produces = "application/json;charset=UTF-8")
    public CommonResponse addPoint(@ApiParam(value = "巡检点", required = true) @RequestBody PointParam pointParam) {
        ReginParams reginParams = getSelectedOrgInfo();
        String loginOrgCode = getOrgCode(reginParams);
        ReginParams.PersonIdentity personIdentity = reginParams.getPersonIdentity();
        pointParam.getPoint().setCompanyId(personIdentity.getCompanyId());
        pointParam.getPoint().setCompanyName(personIdentity.getCompanyName());
        pointParam.getPoint().setOrgCode(loginOrgCode);
        pointParam.getPoint().setCreatorId(RequestContext.getExeUserId());
        Point point = iPointService.addPoint(pointParam);
        return CommonResponseUtil.success(point);

    }

    /**
     * 删除巡检点
     *
     * @param ids
     * @return
     */
    @TycloudOperation(ApiLevel = UserType.AGENCY)
    @ApiOperation(value = "删除巡检点", notes = "删除巡检点")
    @DeleteMapping(value = "/deletePoint", produces = "application/json;charset=UTF-8")
    public CommonResponse deletePoint(@ApiParam(value = "巡检点ID", required = true) @RequestParam Long[] ids) {
        try {
            iPointService.delPointById(ids);
            return CommonResponseUtil.success();
        } catch (Exception e) {
            log.error(e.getMessage(), e);
            return CommonResponseUtil.failure("删除巡检点失败");
        }
    }

    /**
     * 更新巡检点
     *
     * @param pointParam
     * @return
     */
    @TycloudOperation(ApiLevel = UserType.AGENCY)
    @PersonIdentify
    @ApiOperation(value = "更新巡检点", notes = "更新巡检点")
    @PutMapping(value = "/updatePoint", produces = "application/json;charset=UTF-8")
    public CommonResponse updatePoint(@ApiParam(value = "巡检点", required = true) @RequestBody PointParam pointParam) {
        try {
            ReginParams reginParams = getSelectedOrgInfo();
            ReginParams.PersonIdentity personIdentity = reginParams.getPersonIdentity();
            pointParam.getPoint().setCompanyId(personIdentity.getCompanyId());
            pointParam.getPoint().setCompanyName(personIdentity.getCompanyName());
            pointParam.getPoint().setCreatorId(RequestContext.getExeUserId());
            iPointService.updatePoint(pointParam);
            return CommonResponseUtil.success();
        } catch (Exception e) {
            log.error(e.getMessage(), e);
            return CommonResponseUtil.failure("更新巡检点失败");
        }
    }

    /**
     * 根据ID查询巡检点信息
     *
     * @param id
     * @return
     */
    @TycloudOperation(ApiLevel = UserType.AGENCY)
    @ApiOperation(value = "查询巡检点信息", notes = "查询巡检点信息")
    @GetMapping(value = "/queryPointById/{id}", produces = "application/json;charset=UTF-8")
    public CommonResponse queryPointById(@ApiParam(value = "巡检点id", required = true) @PathVariable(name = "id") Long id) {
        try {
            Point point = iPointService.queryPointById(id);
            return CommonResponseUtil.success(point);
        } catch (Exception e) {
            log.error(e.getMessage(), e);
            return CommonResponseUtil.failure("查询巡检点失败");
        }
    }

    @TycloudOperation(ApiLevel = UserType.AGENCY)
    @ApiOperation(value = "查询巡检点详情<font color='blue'>手机app</font>)", notes = "查询巡检点详情<font color='blue'>手机app</font>)")
    @GetMapping(value = "/queryPointDetailById", produces = "application/json;charset=UTF-8")
    public CommonResponse queryPointDetailById(@ApiParam(value = "巡检点id", required = true) @RequestParam(name = "pointId") Long id) {
        try {
            Map point = iPointService.queryPointDetailById1(getToken(), getProduct(), getAppKey(), id);
            return CommonResponseUtil.success(point);
        } catch (Exception e) {
            log.error(e.getMessage(), e);
            return CommonResponseUtil.failure("查询巡检点详情失败");
        }

    }

    @TycloudOperation(ApiLevel = UserType.AGENCY)
    @ApiOperation(value = "查询巡检点详情<font color='blue'>手机app</font>)", notes = "查询巡检点详情<font color='blue'>手机app</font>)")
    @GetMapping(value = "/v2/queryPointDetailById", produces = "application/json;charset=UTF-8")
    public CommonResponse queryPointDetailByIdInVersion2(@ApiParam(value = "巡检点id", required = true) @RequestParam(name = "pointId") Long id) {
        try {
            Map point = iPointService.queryPointDetailByIdInVersion2(id);
            return CommonResponseUtil.success(point);
        } catch (Exception e) {
            log.error(e.getMessage(), e);
            return CommonResponseUtil.failure("查询巡检点详情失败");
        }

    }

    /**
     * 查询巡检点信息
     *
     * @param point
     * @return
     */
    @TycloudOperation(ApiLevel = UserType.AGENCY)
    @ApiOperation(value = "查询巡检点信息", notes = "查询巡检点信息")
    @PostMapping(value = "/list", produces = "application/json;charset=UTF-8")
    public CommonResponse listPoint(
            @ApiParam(value = "查询条件") @RequestBody(required = false) List<CommonRequest> queryRequests,
            @ApiParam(value = "分页参数", required = true, defaultValue = "pageNumber=0&pageSize=10") CommonPageable commonPageable) {
        ReginParams reginParams = getSelectedOrgInfo();
        String loginOrgCode = getOrgCode(reginParams);
        if (ObjectUtils.isEmpty(reginParams)) {
            return CommonResponseUtil.failure("用户session过期");
        }
        try {
            CommonRequest commonRequest = new CommonRequest();
            commonRequest.setName("orgCode");
            commonRequest.setValue(loginOrgCode);
            queryRequests.add(commonRequest);
            List<DaoCriteria> criterias = buildDaoCriterias(queryRequests, false, loginOrgCode, null);
            Page<PointVo> pointList = iPointService.queryPointInfo(criterias, commonPageable, loginOrgCode);
            return CommonResponseUtil.success(pointList);
        } catch (Exception e) {
            e.printStackTrace();
            log.error(e.getMessage(), e);
            return CommonResponseUtil.failure("查询巡检点信息失败");
        }
    }

    @TycloudOperation(ApiLevel = UserType.AGENCY)
    @ApiOperation(value = "查询巡检点信息", notes = "查询巡检点信息")
    @PostMapping(value = "/{ownerId}/list-with-item", produces = "application/json;charset=UTF-8")
    public CommonResponse listPointWithRoute(
            @ApiParam(value = "查询条件") @RequestBody(required = false) List<CommonRequest> queryRequests,
            @ApiParam(value = "分页参数", required = true, defaultValue = "pageNumber=0&pageSize=10") CommonPageable commonPageable,
            @PathVariable Long ownerId) {
        try {
            CommonRequest commonRequest = new CommonRequest();
            commonRequest.setName("ownerId");
            commonRequest.setValue(ownerId);
            queryRequests.add(commonRequest);
            List<DaoCriteria> criterias = buildDaoCriterias(queryRequests, false, null, null);
            Page<PointDto> pointList = iPointService.queryPointInfoWithItem(criterias, commonPageable, ownerId);
            return CommonResponseUtil.success(pointList);
        } catch (Exception e) {
            log.error(e.getMessage(), e);
            return CommonResponseUtil.failure("查询巡检点信息失败");
        }
    }

    /**
     * 查询巡检点信息
     *
     * @param point
     * @return
     */
    @TycloudOperation(ApiLevel = UserType.AGENCY)
    @ApiOperation(value = "查询所有检查点", notes = "查询所有检查点")
    @PostMapping(value = "/list/all", produces = "application/json;charset=UTF-8")
    public CommonResponse listAllPoint() {
        List<CommonRequest> queryRequests = new ArrayList<>();
        ReginParams reginParams = getSelectedOrgInfo();
        String loginOrgCode = getOrgCode(reginParams);
        CommonRequest commonRequest = new CommonRequest();
        commonRequest.setName("orgCode");
        commonRequest.setValue(loginOrgCode);
        queryRequests.add(commonRequest);
        List<DaoCriteria> criterias = buildDaoCriterias(queryRequests, false, loginOrgCode, null);
        return CommonResponseUtil.success(iPointService.queryAllPoint(criterias));
    }

    /**
     * 导入巡检点
     *
     * @param file
     * @return
     */
    @ApiOperation(value = "上传巡检点", notes = "上传巡检点")
    @RequestMapping(value = "/import", produces = "application/json;charset=UTF-8", method = RequestMethod.POST)
    public CommonResponse importPoint(@ApiParam(value = "导入数据文件", required = true) @RequestBody(required = true) MultipartFile file) {
        String fileName = file.getOriginalFilename();

        if (!fileName.endsWith(".xls")) {
            return CommonResponseUtil.failure("文件格式错误");
        }
        String userId = getUserId();
        ReginParams reginParams = getSelectedOrgInfo();
        String loginOrgCode = getOrgCode(reginParams);
        if (ObjectUtils.isEmpty(reginParams)) {
            return CommonResponseUtil.failure("用户session过期");
        }
        try {
            List<PointImportParam> list = FileHelper.importExcel(file, 0, 1, PointImportParam.class);
            iPointService.addImportPoint(list, loginOrgCode, userId);
            return CommonResponseUtil.success();
        } catch (Exception e) {
            e.printStackTrace();
            return CommonResponseUtil.failure("导入失败");
        }
    }

    @TycloudOperation(ApiLevel = UserType.AGENCY)
    @ApiOperation(value = "导入导入模板", notes = "导入导入模板")
    @PostMapping(value = "/exportTemplate", produces = "application/json;charset=UTF-8")
    public CommonResponse exportTemplate(HttpServletResponse response) {
        String userId = getUserId();
        ReginParams reginParams = getSelectedOrgInfo();
        String loginOrgCode = getOrgCode(reginParams);
        String fileName = "巡检点导入模板"; //模板名称
        String[] handers = {"点编号", "点名称", "是否为移动点", "计划外巡检是否评分", "是否允许离线巡检", "参考地址", "3维地图坐标", "3维地图楼层", "最少拍照数量", "最多拍照数量", "风险等级", "备注说明", "所属分类目录", "检查项目", "是否室内"}; //列标题
        List<String[]> downData = new ArrayList();
        String[] isScore = {"否", "是"};
        String[] isFixed = {"否", "是"};
        String[] offline = {"否", "是"};
        String[] isIndoor = {"否", "是"};
        String[] level = {"一级", "二级", "三级", "四级", "五级"};
        String[] catalog = catalogTreeService.getCataLogList(loginOrgCode);
        downData.add(isFixed);
        downData.add(isScore);
        downData.add(offline);
        downData.add(level);
        downData.add(catalog);
        downData.add(isIndoor);
        String[] downRows = {"2", "3", "4", "10", "12", "14"}; //下拉的列序号数组(序号从0开始)

        try {
            FileHelper.createExcelTemplate(fileName, handers, downData, downRows, response);
        } catch (Exception e) {
            CommonResponseUtil.failure(e.getMessage());
        }
        return CommonResponseUtil.success();
    }

    @TycloudOperation(ApiLevel = UserType.AGENCY)
    @ApiOperation(value = "查询巡检点信息", notes = "查询巡检点信息")
    @PostMapping(value = "/exportListPoint", produces = "application/json;charset=UTF-8")
    public CommonResponse exportListPoint(@ApiParam(value = "查询条件", required = false) @RequestBody(required = false) List<CommonRequest> queryRequests,
                                          @RequestParam(value = "exportType", required = false) int exportType,
                                          HttpServletResponse response) {
        ReginParams reginParams = getSelectedOrgInfo();
        String orgCode = getOrgCode(reginParams);
        if (ObjectUtils.isEmpty(reginParams)) {
            return CommonResponseUtil.failure("用户session过期");
        }
        try {
            PointImportQueryParam pointImportQueryParam = PointParamUtils.fillPointImportQuery(queryRequests);
            pointImportQueryParam.setOrgCode(orgCode);
            List<PointVo> pointList = iPointService.queryPointInfoListByIds(pointImportQueryParam);
            if (exportType == 0) {
                FileHelper.exportExcel(pointList, "巡检点列表", "巡检点信息", PointVo.class, "巡检点.xls", response);
            } else if (exportType == 1) {
                FileHelper.exportQRCode(pointList, "巡检点二维码", response);
            }
            return CommonResponseUtil.success("导出成功");
        } catch (Exception e) {
            log.error(e.getMessage(), e);
            return CommonResponseUtil.failure("查询巡检点信息失败");
        }
    }

    @TycloudOperation(ApiLevel = UserType.AGENCY)
    @ApiOperation(value = "查询巡检点信息", notes = "查询巡检点信息")
    @GetMapping(value = "/exportListPointByIds", produces = "application/json;charset=UTF-8")
    public CommonResponse exportListPointByIds(@ApiParam(value = "查询条件", required = false) @RequestParam(value = "ids", required = false) Long[] ids,
                                               @RequestParam(value = "exportType", required = false) int exportType,
                                               HttpServletResponse response) {
        ReginParams reginParams = getSelectedOrgInfo();
        String orgCode = getOrgCode(reginParams);
        if (ObjectUtils.isEmpty(reginParams)) {
            return CommonResponseUtil.failure("用户session过期");
        }
        try {
            List<Long> idList = Arrays.asList(ids);
            PointImportQueryParam pointImportQueryParam = new PointImportQueryParam();
            pointImportQueryParam.setPointIds(idList);
            pointImportQueryParam.setOrgCode(orgCode);
            List<PointVo> pointList = iPointService.queryPointInfoListByIds(pointImportQueryParam);
            if (exportType == 0) {
                FileHelper.exportExcel(pointList, "巡检点列表", "巡检点信息", PointVo.class, "巡检点.xls", response);
            } else if (exportType == 1) {
                FileHelper.exportQRCode(pointList, "巡检点二维码", response);
            }
            return CommonResponseUtil.success("导出成功");
        } catch (Exception e) {
            log.error(e.getMessage(), e);
            return CommonResponseUtil.failure("查询巡检点信息失败");
        }
    }

    @TycloudOperation(ApiLevel = UserType.AGENCY)
    @ApiOperation(value = "查询巡检点信息(<font color='blue'>手机app</font>)", notes = "查询巡检点信息(<font color='blue'>手机app</font>)")
    @PostMapping(value = "/queryPointByPage", produces = "application/json;charset=UTF-8")
    public CommonResponse queryPointByPage(
            @ApiParam(value = "查询条件", required = false) @RequestBody(required = false) List<CommonRequest> queryRequests,
            @ApiParam(value = "分页参数", required = true, defaultValue = "pageNumber=0&pageSize=10") CommonPageable commonPageable) {

        ReginParams reginParams = getSelectedOrgInfo();
        String orgCode = getOrgCode(reginParams);
        if (ObjectUtils.isEmpty(reginParams)) {
            return CommonResponseUtil.failure("用户session过期");
        }
        try {
            CommonRequest commonRequest = new CommonRequest();
            commonRequest.setName("orgCode");
            commonRequest.setValue(orgCode);
            queryRequests.add(commonRequest);
            HashMap<String, Object> param = PointParamUtils.fillTaskInfo(queryRequests);
            Page<PointVo> pointList = iPointService.queryPointByPage(param, commonPageable);
            return CommonResponseUtil.success(pointList);
        } catch (Exception e) {
            log.error(e.getMessage(), e);
            return CommonResponseUtil.failure("查询巡检点信息失败");
        }
    }

    @TycloudOperation(ApiLevel = UserType.AGENCY)
    @ApiOperation(value = "查询用户登录公司全部巡检点", notes = "查询用户登录公司全部巡检点")
    @GetMapping(value = "/authPoints", produces = "application/json;charset=UTF-8")
    public CommonResponse listPoint(@ApiParam(value = "巡检点编码", required = false) @RequestParam("ids") List<String> ids,
                                    @ApiParam(value = "巡检点名称", required = false) @RequestParam("names") List<String> names) {
        ReginParams reginParams = getSelectedOrgInfo();
        String orgCode = getOrgCode(reginParams);
        try {
            List<Point> list = iPointService.queryPointList(ids, names, orgCode);
            return CommonResponseUtil.success(list);
        } catch (Exception e) {
            return CommonResponseUtil.failure(e.getMessage());
        }
    }

    /**
     * 查询巡检点信息及所包含得分类
     *
     * @param code
     * @param name
     * @return
     */
    @TycloudOperation(ApiLevel = UserType.AGENCY)
    @ApiOperation(value = "查询用户登录公司全部巡检点", notes = "查询用户登录公司全部巡检点")
    @GetMapping(value = "/queryPoints", produces = "application/json;charset=UTF-8")
    public CommonResponse queryPoints(@ApiParam(value = "巡检点编码", required = false) @RequestParam("code") String code,
                                      @ApiParam(value = "巡检点名称", required = false) @RequestParam("name") String name) {
        ReginParams reginParams = getSelectedOrgInfo();
        String orgCode = getOrgCode(reginParams);
        try {
            List<HashMap<String, Object>> list = iPointService.findPointList(code, name, orgCode);
            return CommonResponseUtil.success(list);
        } catch (Exception e) {
            log.error(e.getMessage());
            return CommonResponseUtil.failure(e.getMessage());
        }
    }

    /**
     * 另存巡检点
     *
     * @param ids
     * @return
     */
    @TycloudOperation(ApiLevel = UserType.AGENCY)
    @ApiOperation(value = "另存巡检点", notes = "另存巡检点")
    @PostMapping(value = "/saveAs", produces = "application/json;charset=UTF-8")
    public CommonResponse saveAs(@ApiParam(value = "巡检点id集合", required = true) @RequestParam Long[] ids) {
        try {
            List<String> list = iPointService.qryPointNoList(null, (long) -1);
            for (Long id : ids) {
                Point point = iPointService.queryPointById(id);
                if (list.contains(point.getPointNo() + "_copy")) {
                    return CommonResponseUtil.failure("巡检点" + point.getPointNo() + "已另存!");
                }
            }
            iPointService.saveAs(ids);
            return CommonResponseUtil.success();
        } catch (Exception e) {
            log.error(e.getMessage(), e);
            return CommonResponseUtil.failure("另存巡检点失败");
        }
    }

    /**
     * 查询巡检点的巡检项
     *
     * @param id
     * @return
     */
    @TycloudOperation(ApiLevel = UserType.AGENCY)
    @ApiOperation(value = "查询巡检点的巡检项", notes = "查询巡检点的巡检项")
    @PostMapping(value = "/queryPointInputItem", produces = "application/json;charset=UTF-8")
    public CommonResponse queryPointInputItem(@ApiParam(value = "巡检点id", required = true) @RequestParam Long pointId) {
        try {
            List<PointInputItemVo> pointInputItemList = iPointService.queryPointInputItem(pointId);
            return CommonResponseUtil.success(pointInputItemList);
        } catch (Exception e) {
            log.error(e.getMessage(), e);
            return CommonResponseUtil.failure("查询巡检点的巡检项失败");
        }
    }

    /**
     * 查询巡检点的巡检项
     *
     * @param id
     * @return
     */
    @TycloudOperation(ApiLevel = UserType.AGENCY)
    @ApiOperation(value = "查询巡检点的巡检项", notes = "查询巡检点的巡检项")
    @GetMapping(value = "/queryEquipPointInputItem", produces = "application/json;charset=UTF-8")
    public CommonResponse queryEquipPointInputItem(@ApiParam(value = "巡检点id", required = true) @RequestParam Long pointId) {
        try {
            List<Map<String, Object>> pointInputItemList = iPointService.queryEquipPointInputItem(pointId);
            return CommonResponseUtil.success(pointInputItemList);
        } catch (Exception e) {
            log.error(e.getMessage(), e);
            return CommonResponseUtil.failure("查询巡检点的巡检项失败");
        }
    }

    /**
     * 查询巡检点的分类
     *
     * @param id
     * @return
     */
    @TycloudOperation(ApiLevel = UserType.AGENCY)
    @ApiOperation(value = "查询巡检点的分类", notes = "查询巡检点的分类")
    @PostMapping(value = "/queryPointClassify", produces = "application/json;charset=UTF-8")
    public CommonResponse queryPointClassify(@ApiParam(value = "巡检点id", required = true) @RequestParam Long pointId) {
        try {
            List<PointClassify> pointClassify = iPointService.queryPointClassify(pointId);
            return CommonResponseUtil.success(pointClassify);
        } catch (Exception e) {
            log.error(e.getMessage(), e);
            return CommonResponseUtil.failure("查询巡检点的分类失败");
        }
    }

    /**
     * 根据分类id查询对应项
     *
     * @param id
     * @return
     */
    @TycloudOperation(ApiLevel = UserType.AGENCY)
    @ApiOperation(value = "根据分类id查询对应项", notes = "根据分类id查询对应项")
    @PostMapping(value = "/queryPointInputItemByClassify", produces = "application/json;charset=UTF-8")
    public CommonResponse queryPointInputItemByClassify(@ApiParam(value = "巡检点id", required = true) @RequestParam Long pointId,
                                                        @ApiParam(value = "巡检点分类id", required = true) @RequestParam Long classifyId) {
        try {
            List<PointInputItemVo> pointInputItem = iPointService.queryPointInputItemByClassify(pointId, classifyId);
            return CommonResponseUtil.success(pointInputItem);
        } catch (Exception e) {
            log.error(e.getMessage(), e);
            return CommonResponseUtil.failure("根据分类id查询对应项失败");
        }
    }

    /**
     * 根据点id查询点的分类及对应项
     *
     * @param id
     * @return
     */
    @TycloudOperation(ApiLevel = UserType.AGENCY)
    @ApiOperation(value = "根据点id查询点的分类及对应项", notes = "根据点id查询点的分类及对应项")
    @PostMapping(value = "/queryPointClassifyWithInputItem", produces = "application/json;charset=UTF-8")
    public CommonResponse queryPointClassifyWithInputItem(@ApiParam(value = "巡检点id", required = true) @RequestParam Long pointId) {
        try {
            Map<String, PointClassifyVo> classifyNameWithInputItemIdMap = iPointService.queryPointClassifyWithInputItemVo(pointId);
            return CommonResponseUtil.success(classifyNameWithInputItemIdMap);
        } catch (Exception e) {
            log.error(e.getMessage(), e);
            return CommonResponseUtil.failure("根据点id查询点的分类及对应项失败");
        }
    }

    /**
     * 查询巡检点信息
     *
     * @param point
     * @return
     */
    @TycloudOperation(ApiLevel = UserType.AGENCY)
    @ApiOperation(value = "查询巡检点编号信息", notes = "查询巡检点编号信息")
    @GetMapping(value = "/queryPointNo/{pointId}", produces = "application/json;charset=UTF-8")
    public CommonResponse queryPointNoList(
            @ApiParam(value = "巡检点id", required = true) @PathVariable(name = "pointId") Long pointId,
            @ApiParam(value = "查询条件", required = false) @RequestBody(required = false) List<CommonRequest> queryRequests) {
        ReginParams reginParams = getSelectedOrgInfo();
        String loginOrgCode = getOrgCode(reginParams);
        if (ObjectUtils.isEmpty(reginParams)) {
            return CommonResponseUtil.failure("用户session过期");
        }
        try {
            CommonRequest commonRequest = new CommonRequest();
            commonRequest.setName("orgCode");
            commonRequest.setValue(loginOrgCode);
            if (queryRequests == null) {
                queryRequests = new ArrayList<>();
            }
            queryRequests.add(commonRequest);
            List<DaoCriteria> criterias = buildDaoCriterias(queryRequests, false, loginOrgCode, null);
            List<String> pointNoList = iPointService.qryPointNoList(criterias, pointId);
            return CommonResponseUtil.success(pointNoList);
        } catch (Exception e) {
            log.error(e.getMessage(), e);
            return CommonResponseUtil.failure("查询巡检点编号信息失败");
        }
    }


    @TycloudOperation(ApiLevel = UserType.AGENCY)
    @ApiOperation(value = "新*巡检点筛选分页列表", notes = "新*巡检点筛选分页列表")
    @GetMapping(value = "/list-new", produces = "application/json;charset=UTF-8")
    public CommonResponse queryPointList4Route(
            @ApiParam(value = "区域") @RequestParam(value = "riskSourceId", required = false) Long riskSourceId,
            @ApiParam(value = "点编号") @RequestParam(value = "pointNo", required = false) String pointNo,
            @ApiParam(value = "点名称") @RequestParam(value = "name", required = false) String name,
            @RequestParam(value = "current", defaultValue = "1") int current,
            @RequestParam(value = "size", defaultValue = "10") int size) {
        return CommonResponseUtil.success(iPointService.queryPointList4Route(riskSourceId, pointNo, name, current, size));
    }

    @TycloudOperation(ApiLevel = UserType.AGENCY)
    @ApiOperation(value = "新*查询巡检点列表", notes = "新*查询巡检点列表")
    @GetMapping(value = "/route-list-new", produces = "application/json;charset=UTF-8")
    public CommonResponse queryPointListByRouteId(
            @ApiParam(value = "线路ID") @RequestParam(value = "routeId") Long routeId) {
        return CommonResponseUtil.success(iPointService.queryPointListByRouteId(routeId));
    }

    @TycloudOperation(ApiLevel = UserType.AGENCY)
    @ApiOperation(value = "新*查询巡检点对应设备列表", notes = "新*查询巡检点对应设备列表")
    @GetMapping(value = "/equip-list-new", produces = "application/json;charset=UTF-8")
    public CommonResponse queryEquipListByPointId(
            @ApiParam(value = "巡检点ID") @RequestParam(value = "pointId") Long pointId) {
        return CommonResponseUtil.success(iPointService.queryEquipListByPointId(pointId));
    }

    @TycloudOperation(ApiLevel = UserType.AGENCY)
    @ApiOperation(value = "新*查询巡检点对应设备列表", notes = "新*查询巡检点对应设备列表")
    @GetMapping(value = "/item-list-new", produces = "application/json;charset=UTF-8")
    public CommonResponse queryItemList4RoutePoint(
            @ApiParam(value = "巡检点ID") @RequestParam(value = "pointId") Long pointId,
            @ApiParam(value = "设备ID") @RequestParam(value = "classifyId") Long classifyId) {
        return CommonResponseUtil.success(iPointService.queryItemList4RoutePoint(pointId, classifyId));
    }

    /**
     * 获取所属区域树
     *
     * @return
     */
    @TycloudOperation(ApiLevel = UserType.AGENCY)
    @ApiOperation(value = "新*查询巡检点列表", notes = "新*查询巡检点列表")
    @GetMapping(value = "/regionTress", produces = "application/json;charset=UTF-8")
    public CommonResponse getRegionTress() {
        return CommonResponseUtil.success(iPointService.getRegionTress());
    }

    /**
     * 同步点
     *
     * @return
     */
    @TycloudOperation(ApiLevel = UserType.AGENCY)
    @ApiOperation(value = "装备维保项", notes = "装备维保项")
    @RequestMapping(value = "/equipmentInput", produces = "application/json;charset=UTF-8", method = RequestMethod.POST)
    public CommonResponse syncSavePoint(
            @ApiParam(value = "同步请求参数") @RequestBody() List<MaintenanceResourceData> list) {
        ReginParams reginParams = getSelectedOrgInfo();
        iPointService.syncSavePoint(list, reginParams);
        return CommonResponseUtil.success();
    }


}
