package com.palmnest.dao.release.impl;

import com.palmnest.dao.hibernate.GenericDaoHibernate;
import com.palmnest.dao.release.GoodsCompanyDao;
import com.palmnest.dao.release.GoodsDetailDao;
import com.palmnest.model.release.GoodsCompany;
import com.palmnest.model.release.GoodsDetail;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
import java.util.Map;

@Repository("goodsCompanyDao")
@Transactional
public class GoodsCompanyDaoImpl extends GenericDaoHibernate<GoodsCompany, Long> implements GoodsCompanyDao {
    public GoodsCompanyDaoImpl() {
        super(GoodsCompany.class);
    }

    @Override
    public List<Map<String, Object>> getGoodsCompany(Long orgId) {
        String sql ="select type,company_name companyName from tb_goods_company where org_id="+orgId;
        return getJdbcTemplate().queryForList(sql.toString());
    }

    @Override
    public void updateGoodsCompany(Long orgId, String companyName,String type) {

      String sql="update tb_goods_company set  type="+type;
      if(companyName!=null){
          sql+=",company_name='"+companyName+"'";
      }
       sql+=" where org_id="+orgId;
        int count = getSession().createSQLQuery(sql.toString()).executeUpdate();
    }

    @Override
    public void addGoodsCompany(Long orgId, String companyName,String type) {
        String sql="insert into tb_goods_company(org_id,company_name,type) value ("+orgId+",'"+companyName+"',"+type+")";
        int count = getSession().createSQLQuery(sql.toString()).executeUpdate();
    }
}
