package com.gic.haoban.manage.service.service.impl;

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

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

import com.gic.commons.util.EntityUtil;
import com.gic.haoban.common.utils.StringUtil;
import com.gic.haoban.manage.api.dto.ApplicationTemplateDTO;
import com.gic.haoban.manage.service.dao.mapper.TabHaobanApplicationTemplateMapper;
import com.gic.haoban.manage.service.entity.TabHaobanApplicationTemplate;
import com.gic.haoban.manage.service.service.ApplicationTemplateService;

@Service
public class ApplicationTemplateServiceImpl implements ApplicationTemplateService {
	
	@Autowired
	private TabHaobanApplicationTemplateMapper mapper;

	@Override
	public ApplicationTemplateDTO selectByTemplateName(String templateName) {
		return EntityUtil.changeEntityByJSON(ApplicationTemplateDTO.class,mapper.selectByTemplateName(templateName));
	}

	@Override
	public String insertTemplate(ApplicationTemplateDTO template) {
		String uuId = StringUtil.randomUUID();
		template.setApplicationTemplateId(uuId);
		template.setCreateTime(new Date());
		template.setUpdateTime(new Date());
		template.setStatusFlag(1);
		mapper.insertSelective(EntityUtil.changeEntityByJSON(TabHaobanApplicationTemplate.class, template));
		return uuId;
	}

	@Override
	public void delTemplate(String templateId) {
		mapper.deleteByPrimaryKey(templateId);
	}

	@Override
	public ApplicationTemplateDTO selectByTemplateId(String applicationTemplateId) {
		return EntityUtil.changeEntityByJSON(ApplicationTemplateDTO.class, mapper.selectByPrimaryKey(applicationTemplateId));
	}

	@Override
	public void editTemplate(ApplicationTemplateDTO old) {
		old.setUpdateTime(new Date());
		mapper.updateByPrimaryKeySelective(EntityUtil.changeEntityByJSON(TabHaobanApplicationTemplate.class, old));
		
	}

	@Override
	public List<ApplicationTemplateDTO> listByTemplateName(String applicationTemplateName) {
		return EntityUtil.changeEntityListByJSON(ApplicationTemplateDTO.class, mapper.listByTemplateName(applicationTemplateName));
	}

	@Override
	public ApplicationTemplateDTO selectDefaultTemplate() {
		return EntityUtil.changeEntityByJSON(ApplicationTemplateDTO.class, mapper.selectDefaultTemplate());
	}

}
