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

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

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

@Repository
public class MaterialReturnOrderMsgDao extends BaseDao<CrmSupplyMaterialReturnOrderMsg> {
    //操作类型：0.删除 1.创建 2.编辑 3.发货 4.驳回
    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_BH = "4";

    public void addMsg(User user, String type, String orderId, String content) {
        CrmSupplyMaterialReturnOrderMsg orderMsg = new CrmSupplyMaterialReturnOrderMsg();
        orderMsg.setOrderId(orderId);
        orderMsg.setType(type);
        orderMsg.setOperator(CrmUtils.getUserXM(user));
        orderMsg.setOperatorId(user.getId());
        orderMsg.setContent(content);
        orderMsg.setOperateTime(new Date());
        save(orderMsg);
    }

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

    public List<CrmSupplyMaterialReturnOrderMsg> listMsgByOrderId(String id) {
        return find("from CrmSupplyMaterialReturnOrderMsg where orderId=:p1 order by operateTime desc", new Parameter(id));
    }
}
