package org.jeecg.modules.checkData.equipmentCheckData.controller;


import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.jeecg.common.api.vo.Result;
import org.jeecg.common.aspect.annotation.AutoLog;
import org.jeecg.modules.checkData.equipmentCheckData.dto.RecordsMasterCheckDTO;
import org.jeecg.modules.checkData.equipmentCheckData.entity.RecordsMasterCheck;
import org.jeecg.modules.checkData.equipmentCheckData.entity.TrackBedManagementCheck;
import org.jeecg.modules.checkData.equipmentCheckData.service.IRecordsMasterCheckService;
import org.jeecg.modules.checkData.equipmentCheckData.service.ITrackBedManagementCheckService;
import org.jeecg.modules.checkData.equipmentCheckData.vo.RecordsMasterCheckVO;
import org.jeecg.modules.checkData.equipmentCheckData.vo.TrackBedManagementCheckVO;
import org.jeecg.modules.deviceAsset.entity.TrackBedManagement;
import org.jeecg.modules.deviceAsset.service.ITrackBedManagementService;
import org.jeecg.modules.utils.BeanCopyUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.jeecg.common.system.base.controller.JeecgController;

import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 * 设备检查记录主表 前端控制器
 * </p>
 *
 * @author hkl
 * @since 2023-07-07
 */
@RestController
@RequestMapping("/recordsMaster/check")
@Api(tags = "设备检查记录主表控制器")
public class RecordsMasterCheckController extends JeecgController<RecordsMasterCheck, IRecordsMasterCheckService> {
    @Autowired
    private ITrackBedManagementService trackBedManagementService;
    @Autowired
    private ITrackBedManagementCheckService trackBedManagementCheckService;
    /**
     * 设备检查记录-分页列表查询
     *
     * @param pageNo
     * @param pageSize
     * @param dto
     * @return
     */
    @AutoLog(value = "设备检查记录-分页列表查询")
    @ApiOperation(value = "设备检查记录-分页列表查询", notes = "设备检查记录-分页列表查询")
    @GetMapping(value = "/list")
    public Result<IPage<RecordsMasterCheckVO>> queryPageList(@RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo,
                                                             @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize,
                                                             RecordsMasterCheckDTO dto) {
        Page<RecordsMasterCheckVO> pageData = new Page<>(pageNo, pageSize);
        pageData = this.service.queryPageList(pageData, dto);
        return Result.OK(pageData);
    }

    /**
     * 根据区间id和线别id查询道床列表
     * @param sectionId
     * @param lineAliasId
     * @return
     */
    @AutoLog(value = "根据区间id查询道床列表")
    @ApiOperation(value = "根据区间id查询道床列表", notes = "根据区间id和线别id查询道床列表")
    @GetMapping(value = "/getTrackBedBySubwayIdAndLineId")
    public Result<List<TrackBedManagement>> getTrackBedBySubwayIdAndLineId(@ApiParam(name = "区间id") String sectionId,
                                                      @ApiParam(name = "线别id") String lineAliasId) {
        List<TrackBedManagement> listResult = trackBedManagementService.lambdaQuery()
                .eq(ObjectUtil.isNotEmpty(sectionId), TrackBedManagement::getSectionId, sectionId)
                .eq(ObjectUtil.isNotEmpty(lineAliasId), TrackBedManagement::getLineAliasId, lineAliasId)
                .orderByAsc(TrackBedManagement::getCreateTime)
                .list();
        return Result.OK(listResult);
    }
    /**
     * 根据道床使用情况记录数据表的道床id查询对应的实用情况
     * @param managementId 道床id
     * @return
     */
    @AutoLog(value = "根据道床使用情况记录数据表的道床id和检查记录主表的id查询对应的实用情况")
    @ApiOperation(value = "根据道床使用情况记录数据表的道床id和检查记录主表的id查询对应的实用情况", notes = "根据道床使用情况记录数据表的道床id和检查记录主表的id查询对应的实用情况")
    @GetMapping(value = "/getTrackBedByManagementIdAndRecordId")
    public Result<List<TrackBedManagementCheckVO>> getTrackBedByManagementId(@ApiParam(name = "道床id") String managementId,@ApiParam(name = "检查记录表主键id") String recordId) {
        List<TrackBedManagementCheck> listResult = trackBedManagementCheckService.lambdaQuery()
                .eq(ObjectUtil.isNotEmpty(managementId), TrackBedManagementCheck::getTrakBedManagementId, managementId)
                .eq(ObjectUtil.isNotEmpty(recordId), TrackBedManagementCheck::getRecordsMasterCheckId, recordId)
                .eq(TrackBedManagementCheck::getDelFlag,"0")
                .orderByAsc(TrackBedManagementCheck::getCreateTime)
                .list();
        if(listResult!=null){
            List<TrackBedManagementCheckVO> resultList = BeanCopyUtil.copyListProperties(listResult, TrackBedManagementCheckVO::new);
            return Result.OK(resultList);
        }
        return Result.OK(new ArrayList<>());
    }

}
