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.CrmSupplyAllocationOrderMsg;
import com.sifang.modules.supply.warehouse.entity.CrmSupplyPurchaseOrderMsg;
import com.sifang.modules.sys.common.UserUtils;
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 CrmSupplyAllocationOrderMsgDao extends BaseDao<CrmSupplyAllocationOrderMsg> {

    public void addMsg(User user, String type, String orderId, String content, String msg){
        CrmSupplyAllocationOrderMsg orderMsg=new CrmSupplyAllocationOrderMsg();
        orderMsg.setAllocationOrderId(orderId);
        orderMsg.setType(type);
        String newName = UserUtils.findName(user);
        orderMsg.setOperator(newName);
        orderMsg.setOperatorId(user.getId());
        orderMsg.setContent(content);
        orderMsg.setOperateTime(new Date());
        orderMsg.setMsg(msg);
        save(orderMsg);
    }

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