package cn.tsy.idsse.dsds.service.dict;

import java.time.LocalDateTime;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import cn.hme.framework.web.exception.BusinessException;
import cn.hme.framework.web.helper.FrameAssertHelper;
import cn.tsy.data.idsse.dsds.mapper.dict.DictPlatformMapper;
import cn.tsy.data.idsse.dsds.model.dict.DictPlatform;

@Service
public class DictPlatformService {

	@Autowired
	private DictPlatformMapper mPlatform;

	/***********************
	 * 增加或者修改
	 */
	public void editPlatform(DictPlatform platform) {
		FrameAssertHelper.isNotEmpty(platform.getPlatform_name(), "平台类型名称不允许为空！");
		// 判断类型是否存在
		List<DictPlatform> list = this.mPlatform.selectListByColumn("platform_name", platform.getPlatform_name());
		if (platform.getTsy_id() != null) {
			if (list.size() > 0 && list.get(0).getTsy_id() - platform.getTsy_id() != 0)
				throw new BusinessException("平台类型名称【" + platform.getPlatform_name() + "】已经存在，请检查！");
			// platform.setCreate_time(LocalDateTime.now());
			this.mPlatform.update(platform);
		} else {
			FrameAssertHelper.isEmpty(list, "平台类型名称【" + platform.getPlatform_name() + "】已经存在，请检查！");
			platform.setCreate_time(LocalDateTime.now());
			this.mPlatform.insert(platform);
		}
	}

	/*****************************
	 * 删除，
	 */
	public void deletePlatform(int platform_id) {
		/**************
		 * @todo 需要去判断是否真的可以删除
		 */
		this.mPlatform.deleteByKey(platform_id);
	}
}
