package org.springblade.modules.external.ycbigdata.job.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import org.springblade.community.accessrecord.entity.AccessRecord;
import org.springblade.community.accessrecord.service.IAccessRecordService;
import org.springblade.community.agency.entity.Agency;
import org.springblade.community.agency.service.IAgencyService;
import org.springblade.community.building.entity.Building;
import org.springblade.community.building.service.IBuildingService;
import org.springblade.community.floor.entity.Floor;
import org.springblade.community.floor.service.IFloorService;
import org.springblade.community.houseuser.entity.Houseuser;
import org.springblade.community.houseuser.service.IHouseuserService;
import org.springblade.community.residential.entity.Residential;
import org.springblade.community.residential.service.IResidentialService;
import org.springblade.community.room.entity.Room;
import org.springblade.community.room.service.IRoomService;
import org.springblade.community.unit.entity.Unit;
import org.springblade.community.unit.service.IUnitService;
import org.springblade.core.mp.support.Condition;
import org.springblade.core.mp.support.Query;
import org.springblade.core.secure.BladeUser;
import org.springblade.core.tool.api.R;
import org.springblade.jobs.devicejob.entity.DeviceJob;
import org.springblade.jobs.devicejob.service.IDeviceJobService;
import org.springblade.jobs.reportjob.entity.ReportJob;
import org.springblade.jobs.reportjob.service.IReportJobService;
import org.springblade.modules.external.ycbigdata.community.vo.*;
import org.springblade.modules.external.ycbigdata.community.wrapper.*;
import org.springblade.modules.external.ycbigdata.job.vo.DeviceJobVO;
import org.springblade.modules.external.ycbigdata.job.vo.ReportJobVO;
import org.springblade.modules.external.ycbigdata.job.wrapper.DeviceJobWrapper;
import org.springblade.modules.external.ycbigdata.job.wrapper.ReportJobWrapper;
import org.springblade.system.orgposition.service.IOrgPositionService;
import org.springblade.utils.QueryWrapperUtil;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;


/**
 * Created By lidexi in 2021/3/16
 **/
@RestController
@AllArgsConstructor
@RequestMapping("/bigdata/job")
@Api(value = "工单管理-对外（银川大数据）接口", tags = "工单管理-对外（银川大数据）接口")
public class JobExternalController {

	private IOrgPositionService orgPositionService;
	private IDeviceJobService deviceJobService;
	private IReportJobService reportJobService;

	/**
	 * 获取设备工单列表
	 */
	@GetMapping("/devicejob/get")
	@ApiOperationSupport(order = 2)
	@ApiOperation(value = "获取设备工单列表", notes = "获取设备工单列表")
	public R<IPage<DeviceJobVO>> deviceJobList(DeviceJob deviceJob, Query query, BladeUser bladeUser) {
		LambdaQueryWrapper<DeviceJob> deviceJobLambdaQueryWrapper = new QueryWrapperUtil<DeviceJob>().getBasicQueryWrapper(DeviceJob::getOrgPosition, deviceJob, bladeUser, orgPositionService);
		IPage<DeviceJob> page = deviceJobService.page(Condition.getPage(query), deviceJobLambdaQueryWrapper.eq(DeviceJob::getTenantId, bladeUser.getTenantId()));
		return R.data(DeviceJobWrapper.build().pageVO(page));
	}

	/**
	 * 获取报事工单列表
	 */
	@GetMapping("/reportjob/get")
	@ApiOperationSupport(order = 2)
	@ApiOperation(value = "获取报事工单列表", notes = "获取报事工单列表")
	public R<IPage<ReportJobVO>> reportJobList(ReportJob reportJob, Query query, BladeUser bladeUser) {
		LambdaQueryWrapper<ReportJob> reportJobLambdaQueryWrapper = new QueryWrapperUtil<ReportJob>().getBasicQueryWrapper(ReportJob::getOrgPosition, reportJob, bladeUser, orgPositionService);
		IPage<ReportJob> page = reportJobService.page(Condition.getPage(query), reportJobLambdaQueryWrapper.eq(ReportJob::getTenantId, bladeUser.getTenantId()));
		return R.data(ReportJobWrapper.build().pageVO(page));
	}


}
