package cn.springmvc.service.impl;

import java.util.List;

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

import cn.springmvc.dao.PriceTagDAO;
import cn.springmvc.model.PriceTag;
import cn.springmvc.service.PriceTagService;

@Service
public class PriceTagServiceImpl implements PriceTagService {
	
	@Autowired
	private PriceTagDAO priceTagDao;

	public int insertPriceTag(PriceTag pt) throws Exception{
		try{
			priceTagDao.insertPriceTag(pt);
		} catch (Exception ex) {
			ex.printStackTrace();
			return -1;
		}
		return 0;
	}

	public List<PriceTag> selectAllPriceTags() throws Exception{
		return priceTagDao.selectAllPriceTags();
	}

	public int deletePriceTag(String id) throws Exception{
		try {
			PriceTag pt = priceTagDao.selectPriceTagsById(id);
			if (pt == null) {
				return -1;
			}
			priceTagDao.deletePriceTag(id);
		} catch (Exception e) {
			e.printStackTrace();
			return -1;
		}
		return 0;
	}

	public int updatePriceTag(PriceTag pt) throws Exception{
		try {
			int id = pt.getId();
			PriceTag priceTag = priceTagDao.selectPriceTagsById(String.valueOf(id));
			if (priceTag == null) {
				return -1;
			}
			
			priceTagDao.updatePriceTag(pt);
		} catch (Exception e) {
			e.printStackTrace();
			return -1;
		}
		
		return 0;
	}

	public List<PriceTag> selectPriceTagsByParams(PriceTag pt) throws Exception{
		// TODO Auto-generated method stub
		return null;
	}

	public PriceTag selectPriceTagById(String id) throws Exception {
		return priceTagDao.selectPriceTagsById(id);
	}

}

@@ -403,16 +403,25 @@
 agDao;%0A%0A
+%09// %E6%B7%BB%E5%8A%A0%E4%BB%B7%E7%AD%BE%0A
 %09public 
@@ -466,24 +466,24 @@
  Exception%7B%0A
-
 %09%09try%7B%0A%09%09%09pr
@@ -703,24 +703,33 @@
 Tags();%0A%09%7D%0A%0A
+%09// %E5%88%A0%E9%99%A4%E4%BB%B7%E7%AD%BE%0A
 %09public int 
@@ -780,16 +780,31 @@
 %09%09try %7B%0A
+%09%09%09// %E5%88%A4%E6%96%AD%E4%BB%B7%E7%AD%BE%E6%98%AF%E5%90%A6%E5%AD%98%E5%9C%A8%0A
 %09%09%09Price
@@ -874,33 +874,33 @@
 ) %7B%0A%09%09%09%09return -
-1
+2
 ;%0A%09%09%09%7D%0A%09%09%09priceT
@@ -1001,32 +1001,42 @@
 %09%09return 0;%0A%09%7D%0A%0A
+%09// %E6%9B%B4%E6%96%B0%E4%BB%B7%E7%AD%BE %0A
 %09public int upda
@@ -1085,16 +1085,32 @@
 %09%09try %7B%0A
+%09%09%09//  %E5%88%A4%E6%96%AD%E4%BB%B7%E7%AD%BE%E6%98%AF%E5%90%A6%E5%AD%98%E5%9C%A8%0A
 %09%09%09int i
@@ -1236,25 +1236,25 @@
 %09%09%09%09return -
-1
+2
 ;%0A%09%09%09%7D%0A%09%09%09%0A%09
@@ -1504,24 +1504,35 @@
 n null;%0A%09%7D%0A%0A
+%09// %E6%9F%A5%E8%AF%A2%E5%8D%95%E4%B8%AA%E4%BB%B7%E7%AD%BE%0A
 %09public Pric

add error code