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

import com.sifang.modules.supply.order.entity.CrmSupplyException;
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.entity.Ascription;
import com.sifang.modules.sys.entity.Operator;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Isolation;
import org.springframework.transaction.annotation.Transactional;

import java.util.Date;

/**
 * @author hongzq
 */
@Repository
public class SupplyExceptionDao extends BaseDao<CrmSupplyException> {

    @Transactional(rollbackFor = Exception.class)
    public void saveException(String code, String type, String remarks, String status, Date placeOrderTime, Ascription ascription, Operator operator){
        CrmSupplyException ex = new CrmSupplyException();
        ex.setCode(code);
        ex.setType(type);
        ex.setRemarks(remarks);
        ex.setStatus(status);
        ex.setCreateTime(new Date());
        ex.setOperatorId(operator.getUserId());
        ex.setOperatorName(operator.getUserName());
        ex.setOperatorTime(new Date());
        ex.setPlaceOrderTime(placeOrderTime);
        ex.setAscriptionId(ascription.getAscriptionId());
        ex.setAscriptionName(ascription.getAscriptionName());
        save(ex);
    }

    @Transactional(rollbackFor = Exception.class)
    public void saveException(String code, String type, String remarks, String status, Date placeOrderTime, Ascription ascription){
        User user = UserUtils.getUser();
        saveException(code, type, remarks, status, placeOrderTime, ascription, Operator.of(user));
    }

}
