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.CrmSupplyInventoryOrderMsg;
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 InventoryOrderMsgDao extends BaseDao<CrmSupplyInventoryOrderMsg> {

    public void addMsg(User user, Short type, String inventoryId, String content) {
        CrmSupplyInventoryOrderMsg orderMsg = new CrmSupplyInventoryOrderMsg();
        orderMsg.setInventoryOrderId(inventoryId);
        orderMsg.setType(type);
        String newName = UserUtils.findName(user);
        orderMsg.setOperator(newName);
        orderMsg.setOperatorId(user.getId());
        orderMsg.setOperateTime(new Date());
        orderMsg.setContent(content);
        save(orderMsg);
    }

    public List<Record> listMsg(String id) {
        return Db.find("select * from crm_supply_inventory_order_msg where inventory_order_id = ? order by operate_time desc", id);
    }
}
