package cn.com.countrygarden.bi.main.service.project.impl;

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

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

import cn.com.countrygarden.bi.main.dao.project.ProjectSignMapper;
import cn.com.countrygarden.bi.main.model.project.ProjectSign;
import cn.com.countrygarden.bi.main.service.project.ProjectSignInfoService;
import cn.com.countrygarden.bi.main.service.project.ProjectSignService;

@Service
@Transactional
public class ProjectSignServiceImpl implements ProjectSignService {
	@Autowired
	ProjectSignMapper mapper;
	@Autowired
	ProjectSignInfoService projectSignInfoService;
	@Override
	public List<ProjectSign> search(ProjectSign p) {
		//ProjectSign p = new ProjectSign();
		//p.setIsDelete(0);
		
		return mapper.selectList(p);
	}

	@Override
	public Integer save(ProjectSign p, String userCode) {
		if(null == p.getId()) {
			p.setGmtCreate(new Date());
			p.setCreateBy(userCode);
			return mapper.insert(p);
		}else{
			ProjectSign old = mapper.selectByPrimaryKey(p.getId());
			old.setContractArea(p.getContractArea());
			old.setOrganName(p.getOrganName());
			old.setProposalOrganId(p.getProposalOrganId());
			old.setIsNew(old.getIsNew());
			old.setCorpType(p.getCorpType());
			old.setEndTime(p.getEndTime());
			old.setInMonth(p.getInMonth());
			old.setSingTimeStr(p.getSingTimeStr());
			old.setEndTimeStr(p.getEndTimeStr());
			old.setProjectNatureName(p.getProjectNatureName());
			old.setCorpTypeName(p.getCorpTypeName());
			old.setProjectName(p.getProjectName());
			old.setProjectNature(p.getProjectNature());
			old.setProvince(p.getProvince());
			return mapper.updateByPrimaryKey(old);
		}
		
	}

	@Override
	public Integer delete(Integer id) {
		 ProjectSign p = new ProjectSign();
		 p.setId(id);
		return mapper.delete(p);
	}

	@Override
	public ProjectSign findOne(Integer id) {
		
		return mapper.selectByPrimaryKey(id);
	}

}
