/**
 * BladeX Commercial License Agreement
 * Copyright (c) 2018-2099, https://bladex.cn. All rights reserved.
 * <p>
 * Use of this software is governed by the Commercial License Agreement
 * obtained after purchasing a license from BladeX.
 * <p>
 * 1. This software is for development use only under a valid license
 * from BladeX.
 * <p>
 * 2. Redistribution of this software's source code to any third party
 * without a commercial license is strictly prohibited.
 * <p>
 * 3. Licensees may copyright their own code but cannot use segments
 * from this software for such purposes. Copyright of this software
 * remains with BladeX.
 * <p>
 * Using this software signifies agreement to this License, and the software
 * must not be used for illegal purposes.
 * <p>
 * THIS SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY. The author is
 * not liable for any claims arising from secondary or illegal development.
 * <p>
 * Author: Chill Zhuang (bladejava@qq.com)
 */
package org.springblade.modules.material.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import org.springblade.common.cache.DictCache;
import org.springblade.common.enums.DictEnum;
import org.springblade.core.mp.base.BaseServiceImpl;
import org.springblade.core.tool.utils.BeanUtil;
import org.springblade.modules.material.excel.MaterialEngineerExcel;
import org.springblade.modules.material.pojo.entity.MaterialEngineerEntity;
import org.springblade.modules.material.pojo.entity.MaterialOperationEntity;
import org.springblade.modules.material.pojo.vo.MaterialOperationVO;
import org.springblade.modules.material.excel.MaterialOperationExcel;
import org.springblade.modules.material.mapper.MaterialOperationMapper;
import org.springblade.modules.material.service.IMaterialOperationService;
import org.springblade.modules.nh.pojo.entity.MonitorInverterDailyStatEntity;
import org.springframework.stereotype.Service;
import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

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

/**
 * 运维商库存 服务实现类
 *
 * @author cswang
 * @since 2024-08-25
 */
@Service
public class MaterialOperationServiceImpl extends BaseServiceImpl<MaterialOperationMapper, MaterialOperationEntity> implements IMaterialOperationService {

	@Override
	public IPage<MaterialOperationVO> selectMaterialOperationPage(IPage<MaterialOperationVO> page, MaterialOperationVO materialOperation) {
		return page.setRecords(baseMapper.selectMaterialOperationPage(page, materialOperation));
	}


	@Override
	public List<MaterialOperationExcel> exportMaterialOperation(Wrapper<MaterialOperationEntity> queryWrapper) {
		List<MaterialOperationEntity> materialEngineerList = this.list(queryWrapper);
		List<MaterialOperationExcel> excelList = new ArrayList<>();
		materialEngineerList.forEach(material -> {
			MaterialOperationExcel excel = new MaterialOperationExcel();
			BeanUtil.copyProperties(material,excel);
			excel.setBrandStr(DictCache.getValue(DictEnum.BRAND, material.getBrand()));
			excel.setTypeStr(DictCache.getValue(DictEnum.WL_TYPE, material.getType()));
			excelList.add(excel);
//			materialEngineer.setTypeName(DictCache.getValue(DictEnum.YES_NO, MaterialEngineer.getType()));
		});
		return excelList;
	}

	public MaterialOperationEntity findByMateId(String mateId,String siteId){
		LambdaQueryWrapper<MaterialOperationEntity> queryWrapper = new LambdaQueryWrapper<>();
		queryWrapper.eq(MaterialOperationEntity::getMaterialId,mateId).eq(MaterialOperationEntity::getCompanyId,siteId);
		return getOne(queryWrapper);
	}


}
