/**
 * 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.springblade.core.log.exception.ServiceException;
import org.springblade.core.secure.BladeUser;
import org.springblade.core.secure.utils.AuthUtil;
import org.springblade.core.tool.utils.StringUtil;
import org.springblade.modules.operation.pojo.entity.OperationTechnicalDataEntity;
import org.springblade.modules.operation.pojo.vo.OperationTechnicalDataVO;
import org.springblade.modules.operation.excel.OperationTechnicalDataExcel;
import org.springblade.modules.operation.mapper.OperationTechnicalDataMapper;
import org.springblade.modules.operation.service.IOperationTechnicalDataService;
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 org.springframework.transaction.annotation.Transactional;

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

/**
 * 技术资料表 服务实现类
 *
 * @author BladeX
 * @since 2024-06-26
 */
@Service
public class OperationTechnicalDataServiceImpl extends ServiceImpl<OperationTechnicalDataMapper, OperationTechnicalDataEntity> implements IOperationTechnicalDataService {

	@Override
	public IPage<OperationTechnicalDataVO> selectOperationTechnicalDataPage(IPage<OperationTechnicalDataVO> page, OperationTechnicalDataVO operationTechnicalData) {
		return page.setRecords(baseMapper.selectOperationTechnicalDataPage(page, operationTechnicalData));
	}


	@Override
	public List<OperationTechnicalDataExcel> exportOperationTechnicalData(Wrapper<OperationTechnicalDataEntity> queryWrapper) {
		List<OperationTechnicalDataExcel> operationTechnicalDataList = baseMapper.exportOperationTechnicalData(queryWrapper);
		return operationTechnicalDataList;
	}

	@Override
	@Transactional(rollbackFor = Exception.class)
	public boolean addTechnical(OperationTechnicalDataEntity dataEntity) {
		BladeUser user = AuthUtil.getUser();
		if(StringUtil.isBlank(dataEntity.getName())){
			throw new ServiceException("标题不能为空!");
		}
		if(StringUtil.isBlank(dataEntity.getHref())){
			throw new ServiceException("附件不能为空!");
		}
		dataEntity.setCreator(user.getNickName());
		dataEntity.setStatus("0");
		dataEntity.setCreateTime(new Date());
		dataEntity.setCreateBy(String.valueOf(user.getUserId()));
		return save(dataEntity);
	}

	@Override
	public boolean updateTechnical(OperationTechnicalDataEntity dataEntity) {
		BladeUser user = AuthUtil.getUser();
		dataEntity.setUpdateTime(new Date());
		dataEntity.setUpdateName(user.getNickName());
		return updateById(dataEntity);
	}

	@Override
	public boolean deleteTechnical(String ids) {
		BladeUser user = AuthUtil.getUser();
		int i=baseMapper.deleteTechnical(ids,user.getNickName());
		return i>0?true:false;
	}

}
