package cokr.xit.fims.eqplc.service.bean;

import java.util.List;
import javax.annotation.Resource;
import org.springframework.stereotype.Component;
import cokr.xit.fims.eqplc.Eqplc;
import cokr.xit.fims.eqplc.EqplcQuery;
import cokr.xit.fims.eqplc.dao.EqplcMapper;
import cokr.xit.foundation.component.AbstractBean;
import cokr.xit.foundation.data.DataObject;

@Component("eqplcBean")
public class EqplcBean extends AbstractBean {
	@Resource(name = "eqplcMapper")
	private EqplcMapper eqplcMapper;

	public List<DataObject> getList(EqplcQuery req) {
		return eqplcMapper.selectList(req);
	}
	
	public DataObject getOne(String req) {
		return eqplcMapper.selectOne(req);
	}	
	
	public String insert(Eqplc req) {		
		req.setEqplcCd(eqplcMapper.selectNextNo());
		req.setCmpnyCd("001");

		int rtnNocs = eqplcMapper.insert(req);
		if (rtnNocs != 1)
			throw new RuntimeException("단속장비 장소 정보 등록에 실패하였습니다.");

		return "[S] 작업이 정상 처리 되었습니다.";
	}	
		
	public String update(Eqplc req) {
		
		int rtnNocs = eqplcMapper.update(req);
		if (rtnNocs != 1)
			throw new RuntimeException("단속장비 장소 정보 수정에 실패하였습니다.");

		return "[S] 작업이 정상 처리 되었습니다.";
	}
}