package com.sifang.modules.supply.warehouse.dao;

import com.jfinal.plugin.activerecord.Db;
import com.jfinal.plugin.activerecord.Record;
import com.sifang.modules.supply.warehouse.entity.CrmSupplyPurchaseOrderMsg;
import com.sifang.modules.sys.common.entity.User;
import com.sifang.modules.sys.common.persistence.BaseDao;
import com.sifang.modules.sys.util.CrmUtils;
import org.springframework.stereotype.Repository;

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

@Repository
public class CrmSupplyPurchaseOrderMsgDao extends BaseDao<CrmSupplyPurchaseOrderMsg> {
    //操作类型：0.删除 1.创建 2.编辑 3.确认订单 4.检验 5 撤销 6 更改订单 7 报检
    public static final String STATUS_SC="0";
   public static final String STATUS_CJ="1";
   public static final String STATUS_BJ="2";
   public static final String STATUS_QRDD="3";
   public static final String STATUS_JY="4";
   public static final String STATUS_CX="5";
   public static final String STATUS_UPDATE="6";
   public static final String STATUS_INSPEC="7";

   public void addMsg(User user,String type,String purchaseId,String content,String msg){
      CrmSupplyPurchaseOrderMsg orderMsg=new CrmSupplyPurchaseOrderMsg();
      orderMsg.setPurchaseId(purchaseId);
      orderMsg.setType(type);
      orderMsg.setOperator(CrmUtils.getUserXM(user));
      orderMsg.setOperatorId(user.getId());
      orderMsg.setContent(content);
      orderMsg.setOperateTime(new Date());
      orderMsg.setMsg(msg);
      save(orderMsg);
   }

   public List<Record> getMsgs(String purchaseId){
      return Db.find(" SELECT * FROM `crm_supply_purchase_order_msg` WHERE purchase_id=? order by operate_time desc ",purchaseId);
   }
}
