package org.jeecg.modules.orderplatform.util;

import org.apache.shiro.SecurityUtils;
import org.jeecg.common.system.vo.LoginUser;
import org.jeecg.modules.orderplatform.entity.PlatformOperateRecord;
import org.jeecg.modules.orderplatform.service.IPlatformOperateRecordService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
public class OperateRecordHandler {

    @Autowired
    IPlatformOperateRecordService platformOperateRecordService;

    /**
     * 审批记录
     */
    public void Approval(String code, String operate) {
        switch (operate) {
            //接单：
            case "ACCEPT_ORDER":
                saveOperateRecord(code, "", "接单成功");
                break;
            //销毁订单
            case "DESTROY_ORDER":
                saveOperateRecord(code, "", "销毁了订单");
                break;
            //驳回订单
            case "REJECT_ORDER":
                saveOperateRecord(code, "", "驳回了订单");
                break;
            //通过脚本
            case "ACCEPT_SCRIPT":
                saveOperateRecord("", code, "审批通过了脚本");
                break;
            //驳回脚本
            case "REJECT_SCRIPT":
                saveOperateRecord("", code, "审批驳回了脚本");
                break;
            //通过脚本
            case "ACCEPT_VIDEO":
                saveOperateRecord("", code, "审批通过了视频");
                break;
            //驳回脚本
            case "REJECT_VIDEO":
                saveOperateRecord("", code, "审批驳回了视频");
                break;
        }
    }

    /**
     * 提交记录
     */
    public void Submit(String code, String operate) {
        switch (operate) {
            //发起订单
            case "PAYOUT":
                saveOperateRecord(code, "", "发起了一个订单");
                break;
            //上传脚本
            case "SCRIPT":
                saveOperateRecord("", code, "上传了一个脚本");
                break;
            //上传视频
            case "VIDEO":
                saveOperateRecord("", code, "上传了一个视频");
                break;
        }
    }

    //操作记录入库
    private void saveOperateRecord(String order, String material, String operate) {
        //获取操作人Id
        String userId = ((LoginUser) SecurityUtils.getSubject().getPrincipal()).getId();
        PlatformOperateRecord platformOperateRecord = new PlatformOperateRecord();
        platformOperateRecord.setUserId(userId);
        platformOperateRecord.setOrderCode(order);
        platformOperateRecord.setMaterialCode(material);
        platformOperateRecord.setOperate(operate);
        platformOperateRecordService.save(platformOperateRecord);
    }
}
