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.TemplateEnterpriseRelatedDTO;
import com.gic.haoban.manage.service.dao.mapper.TabHaobanTemplateEnterpriseRelationMapper;
import com.gic.haoban.manage.service.entity.TabHaobanTemplateEnterpriseRelation;
import com.gic.haoban.manage.service.service.TemplateEnterpriseRelatedService;

@Service
public class TemplateEnterpriseRelatedServiceImpl implements TemplateEnterpriseRelatedService {

	@Autowired
	private TabHaobanTemplateEnterpriseRelationMapper mapper;
	
	@Override
	public List<TemplateEnterpriseRelatedDTO> listEnterpriseByTemplateId(String templateId) {
		return EntityUtil.changeEntityListByJSON(TemplateEnterpriseRelatedDTO.class, mapper.listEnterpriseByTemplateId(templateId));
	}

	@Override
	public TemplateEnterpriseRelatedDTO selectByWxEnterpriseId(String wxEnterpriseId) {
		return EntityUtil.changeEntityByJSON(TemplateEnterpriseRelatedDTO.class, mapper.selectByWxEnterpriseId(wxEnterpriseId));
	}

	@Override
	public void insert(TemplateEnterpriseRelatedDTO dto) {
		dto.setTemplateEnterpriseRelationId(StringUtil.randomUUID());
		dto.setCreateTime(new Date());
		dto.setUpdateTime(new Date());
		dto.setStatusFlag(1);
		mapper.insert(EntityUtil.changeEntityByJSON(TabHaobanTemplateEnterpriseRelation.class, dto));
	}

	@Override
	public void update(TemplateEnterpriseRelatedDTO dto) {
		dto.setUpdateTime(new Date());
		mapper.updateByPrimaryKeySelective(EntityUtil.changeEntityByJSON(TabHaobanTemplateEnterpriseRelation.class, dto));
	}

	@Override
	public List<TemplateEnterpriseRelatedDTO> listEnterpriseByParams(String applicationTemplateId, List<String> wxEnterpriseIds,
			String wxEnterpriseName) {
		return EntityUtil.changeEntityListByJSON(TemplateEnterpriseRelatedDTO.class, mapper.listEnterpriseByParams(applicationTemplateId,wxEnterpriseIds,wxEnterpriseName));
	}

}
