/**
 * 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.operation.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.apache.commons.compress.utils.Lists;
import org.springblade.modules.operation.pojo.dto.OperationServiceMeasuresDTO;
import org.springblade.modules.operation.pojo.dto.OperationServiceTypeDTO;
import org.springblade.modules.operation.pojo.entity.OperationServiceMeasuresEntity;
import org.springblade.modules.operation.pojo.entity.OperationServiceTypeEntity;
import org.springblade.modules.operation.pojo.vo.OperationServiceMeasuresVO;
import org.springblade.modules.operation.excel.OperationServiceMeasuresExcel;
import org.springblade.modules.operation.mapper.OperationServiceMeasuresMapper;
import org.springblade.modules.operation.service.IOperationServiceMeasuresService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import org.springblade.core.mp.base.BaseServiceImpl;

import java.util.Date;
import java.util.List;

/**
 * 服务措施表 服务实现类
 *
 * @author lzp
 * @since 2024-06-18
 */
@Service
public class OperationServiceMeasuresServiceImpl extends ServiceImpl<OperationServiceMeasuresMapper, OperationServiceMeasuresEntity> implements IOperationServiceMeasuresService {

	@Autowired
	OperationServiceTypeServiceImpl typeService;
	@Override
	public IPage<OperationServiceMeasuresVO> selectOperationServiceMeasuresPage(IPage<OperationServiceMeasuresVO> page, OperationServiceMeasuresVO operationServiceMeasures) {
		return page.setRecords(baseMapper.selectOperationServiceMeasuresPage(page, operationServiceMeasures));
	}


	@Override
	public List<OperationServiceMeasuresExcel> exportOperationServiceMeasures(Wrapper<OperationServiceMeasuresEntity> queryWrapper) {
		List<OperationServiceMeasuresExcel> operationServiceMeasuresList = baseMapper.exportOperationServiceMeasures(queryWrapper);
		//operationServiceMeasuresList.forEach(operationServiceMeasures -> {
		//	operationServiceMeasures.setTypeName(DictCache.getValue(DictEnum.YES_NO, OperationServiceMeasures.getType()));
		//});
		return operationServiceMeasuresList;
	}

	@Override
	public boolean saveServiceMeasures(OperationServiceMeasuresDTO dto) {
		List<OperationServiceMeasuresEntity> list = Lists.newArrayList();
		OperationServiceTypeEntity type = typeService.getById(dto.getServiceTypeId());
		Date date=new Date();
		for(String name :dto.getMeasures()){
			OperationServiceMeasuresEntity entity = new OperationServiceMeasuresDTO();
			entity.setServiceMeasures(name);
			entity.setServiceType(type.getName());
			entity.setServiceTypeId(dto.getServiceTypeId());
			entity.setIsDeleted(0);
			entity.setCreateTime(date);
			list.add(entity);
		}
		return saveBatch(list,list.size());
	}

}
