/**
 * 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.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.apache.commons.compress.utils.Lists;
import org.springblade.core.tool.utils.StringUtil;
import org.springblade.modules.operation.pojo.dto.OperationServiceTypeDTO;
import org.springblade.modules.operation.pojo.entity.OperationServiceTypeEntity;
import org.springblade.modules.operation.pojo.vo.OperationServiceTypeVO;
import org.springblade.modules.operation.excel.OperationServiceTypeExcel;
import org.springblade.modules.operation.mapper.OperationServiceTypeMapper;
import org.springblade.modules.operation.service.IOperationServiceTypeService;
import org.springframework.stereotype.Service;
import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;

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

/**
 * 服务类型基础信息 服务实现类
 *
 * @author BladeX
 * @since 2024-06-17
 */
@Service
public class OperationServiceTypeServiceImpl extends ServiceImpl<OperationServiceTypeMapper, OperationServiceTypeEntity> implements IOperationServiceTypeService {

	@Override
	public IPage<OperationServiceTypeVO> selectOperationServiceTypePage(IPage<OperationServiceTypeVO> page, OperationServiceTypeVO operationServiceType) {
		return page.setRecords(baseMapper.selectOperationServiceTypePage(page, operationServiceType));
	}

	@Override
	public List<OperationServiceTypeVO> pageServiceType() {
		return baseMapper.pageServiceType();
	}


	@Override
	public List<OperationServiceTypeExcel> exportOperationServiceType(Wrapper<OperationServiceTypeEntity> queryWrapper) {
		List<OperationServiceTypeExcel> operationServiceTypeList = baseMapper.exportOperationServiceType(queryWrapper);
		//operationServiceTypeList.forEach(operationServiceType -> {
		//	operationServiceType.setTypeName(DictCache.getValue(DictEnum.YES_NO, OperationServiceType.getType()));
		//});
		return operationServiceTypeList;
	}

	@Override
	public boolean saveList(OperationServiceTypeDTO dto) {

			List<OperationServiceTypeEntity> types = Lists.newArrayList();
			int sort =1;
			for(OperationServiceTypeEntity entity :dto.getTypelist()){
				entity.setSort(sort);
				entity.setCreateTime(new Date());
				entity.setStatus("0");
				sort ++;
				types.add(entity);
			}
			return saveBatch(types);
	}

	@Override
	public boolean deleteStatus(String id) {
		if(StringUtil.isBlank(id)) return false;
		LambdaUpdateWrapper<OperationServiceTypeEntity> updateWrapper = new LambdaUpdateWrapper<>();
		updateWrapper
			.eq(OperationServiceTypeEntity::getId,id);
			updateWrapper.set(OperationServiceTypeEntity::getStatus,"1");
		return this.update(updateWrapper);
	}

}
