/*
 *      Copyright (c) 2018-2028, Chill Zhuang All rights reserved.
 *
 *  Redistribution and use in source and binary forms, with or without
 *  modification, are permitted provided that the following conditions are met:
 *
 *  Redistributions of source code must retain the above copyright notice,
 *  this list of conditions and the following disclaimer.
 *  Redistributions in binary form must reproduce the above copyright
 *  notice, this list of conditions and the following disclaimer in the
 *  documentation and/or other materials provided with the distribution.
 *  Neither the name of the dreamlu.net developer nor the names of its
 *  contributors may be used to endorse or promote products derived from
 *  this software without specific prior written permission.
 *  Author: Chill 庄骞 (smallchill@163.com)
 */
package org.security.trans.settings.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.apache.commons.lang.StringUtils;
import org.security.trans.settings.dto.DeviceInspectionSettingsDTO;
import org.security.trans.settings.entity.DeviceCategorySettings;
import org.security.trans.settings.entity.DeviceInspectionSettings;
import org.security.trans.settings.service.IDeviceCategorySettingsService;
import org.security.trans.settings.vo.DeviceInspectionSettingsVO;
import org.security.trans.settings.mapper.DeviceInspectionSettingsMapper;
import org.security.trans.settings.service.IDeviceInspectionSettingsService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springblade.core.tool.utils.Func;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.baomidou.mybatisplus.core.metadata.IPage;

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

/**
 * 系统配置-设备检查项设置 服务实现类
 *
 * @author BladeX
 * @since 2022-03-03
 */
@Service
public class DeviceInspectionSettingsServiceImpl extends ServiceImpl<DeviceInspectionSettingsMapper, DeviceInspectionSettings> implements IDeviceInspectionSettingsService {
//	@Autowired
//	private IDeviceCategorySettingsService deviceCategorySettingsService;

	@Override
	public IPage<DeviceInspectionSettingsVO> selectDeviceInspectionSettingsPage(IPage<DeviceInspectionSettingsDTO> page, DeviceInspectionSettingsDTO deviceInspectionSettingsDTO) {
		Page<DeviceInspectionSettings> deviceInspectionSettingsPage = new Page<>(page.getCurrent(), page.getSize());
		LambdaQueryWrapper<DeviceInspectionSettings> dpsLambdaQueryWrapper = new QueryWrapper<DeviceInspectionSettings>().lambda()
			.eq(StringUtils.isNotBlank(deviceInspectionSettingsDTO.getDeviceCatgId()), DeviceInspectionSettings::getDeviceCatgId, deviceInspectionSettingsDTO.getDeviceCatgId())
			.like(StringUtils.isNotBlank(deviceInspectionSettingsDTO.getName()), DeviceInspectionSettings::getName, deviceInspectionSettingsDTO.getName())
			.eq(StringUtils.isNotBlank(deviceInspectionSettingsDTO.getType()), DeviceInspectionSettings::getType, deviceInspectionSettingsDTO.getType());

		Page<DeviceInspectionSettings> resultPage = this.page(deviceInspectionSettingsPage, dpsLambdaQueryWrapper);
		List<DeviceInspectionSettings> DPSList = resultPage.getRecords();
		List<DeviceInspectionSettingsVO> dpsVOList = new ArrayList<>();
		DPSList.forEach(item -> {
//			DeviceCategorySettings deviceCategorySettings = deviceCategorySettingsService.getOne(new QueryWrapper<DeviceCategorySettings>().lambda().eq(DeviceCategorySettings::getId, item.getDeviceCatgId()));
			DeviceInspectionSettingsVO deviceInspectionSettingsVO = Func.copy(item, DeviceInspectionSettingsVO.class);
			assert deviceInspectionSettingsVO != null;
//			deviceInspectionSettingsVO.setDcName(Func.isNotEmpty(deviceCategorySettings)?deviceCategorySettings.getName():"");
			dpsVOList.add(deviceInspectionSettingsVO);
		});
		return new Page<DeviceInspectionSettingsVO>()
			.setRecords(dpsVOList)
			.setTotal(resultPage.getTotal())
			.setSize(resultPage.getSize())
			.setCurrent(resultPage.getCurrent()); }

}
