package selling.sunshine.dao.impl;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Repository;
import selling.sunshine.dao.BaseDao;
import selling.sunshine.dao.FollowerDao;
import selling.sunshine.utils.ResponseCode;
import selling.sunshine.utils.ResultData;
import selling.wechat.model.Follower;

/**
 * Created by sunshine on 5/25/16.
 */
@Repository
public class FollowerDaoImpl extends BaseDao implements FollowerDao {

    private Logger logger = LoggerFactory.getLogger(FollowerDaoImpl.class);

    private Object lock = new Object();

    @Override
    public ResultData insertFollower(Follower follower) {
        ResultData result = new ResultData();
        synchronized (lock) {
            try {
                sqlSession.insert("selling.wechat.insert", follower);
                result.setData(follower);
            } catch (Exception e) {
                logger.error(e.getMessage());
                result.setResponseCode(ResponseCode.RESPONSE_ERROR);
                result.setDescription(e.getMessage());
            } finally {
                return result;
            }
        }
    }

    @Override
    public ResultData blockFollower(String openId) {
        ResultData result = new ResultData();
        synchronized (lock) {
            try {
                sqlSession.update("selling.wechat.block", openId);
            } catch (Exception e) {
                logger.error(e.getMessage());
                result.setResponseCode(ResponseCode.RESPONSE_ERROR);
                result.setDescription(e.getMessage());
            } finally {
                return result;
            }
        }
    }
}

@@ -343,16 +343,37 @@
 r;%0A%0A/**%0A
+ * %E5%BE%AE%E4%BF%A1%E6%9C%8D%E5%8A%A1%E5%8F%B7%E5%85%B3%E6%B3%A8%E7%94%A8%E6%88%B7%E4%B8%8E%E6%8C%81%E4%B9%85%E5%B1%82%E4%BA%A4%E4%BA%92%E6%8E%A5%E5%8F%A3%0A
  * Creat
@@ -485,17 +485,16 @@
 erDao %7B%0A
-%0A
     priv
@@ -599,24 +599,103 @@
  Object();%0A%0A
+    /**%0A     * %E6%B7%BB%E5%8A%A0%E5%85%B3%E6%B3%A8%E7%94%A8%E6%88%B7%E4%BF%A1%E6%81%AF%E8%AE%B0%E5%BD%95%0A     *%0A     * @param follower%0A     * @return%0A     */%0A
     @Overrid
@@ -972,39 +972,115 @@
         
-%7D catch (Exception e) %7B
+    sqlSession.commit();%0A            %7D catch (Exception e) %7B%0A                sqlSession.rollback();
 %0A       
@@ -1328,16 +1328,103 @@
 %0A    %7D%0A%0A
+    /**%0A     * %E7%94%A8%E6%88%B7%E5%8F%96%E6%B6%88%E5%85%B3%E6%B3%A8%E6%97%B6,%E5%88%A0%E9%99%A4%E7%94%A8%E6%88%B7%E4%BF%A1%E6%81%AF(%E6%A0%87%E8%AE%B0%E5%88%A0%E9%99%A4)%0A     *%0A     * @param openId%0A     * @return%0A     */%0A
     @Ove
@@ -1655,39 +1655,115 @@
         
-%7D catch (Exception e) %7B
+    sqlSession.commit();%0A            %7D catch (Exception e) %7B%0A                sqlSession.rollback();
 %0A       

optimize follower dao