package com.chushang.inspection.work.po;

import cn.hutool.core.date.DatePattern;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.chushang.common.mybatis.base.BaseEntity;

import java.io.Serial;
import java.io.Serializable;
import java.time.LocalDate;
import java.time.LocalTime;
import java.util.Date;

import com.chushang.inspection.terminal.enums.MerTypeOperation;
import com.chushang.inspection.work.enums.TerminalTypeOperation;
import com.chushang.inspection.work.enums.WorkTypeOperation;
import com.chushang.inspection.work.vo.WrkInfoDetailsVO;
import com.chushang.inspection.work.vo.WrkInfoStoreVO;
import com.chushang.inspection.work.vo.WrkInfoTerminalVO;
import com.chushang.inspection.work.vo.WrkInfoVO;
import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;

/**
  * @auther: zhao
  * @date: 2024/6/28 15:38
  */
/**
 * 江苏工行数据推送
 */
@Data
@EqualsAndHashCode
@AllArgsConstructor
@NoArgsConstructor
@TableName(value = "wrk_icbc_js")
public class WrkIcbcJs implements Serializable {
    @Serial
    private static final long serialVersionUID = 1L;
    /**
     * 主键
     */
    @TableId(value = "id", type = IdType.ASSIGN_ID)
    private Long id;

    /**
     * 工单id
     */
    @TableField(value = "wrk_id")
    private Long wrkId;

    /**
     * 终端id
     */
    @TableField(value = "terminal_id")
    private Long terminalId;

    /**
     * 商户id
     */
    @TableField(value = "store_id")
    private Long storeId;

    /**
     * 交易码
     */
    @TableField(value = "trans_code")
    private String transCode;

    /**
     * 商户 id
     */
    @TableField(value = "mer_id")
    private String merId;

    /**
     * 商户名
     */
    @TableField(value = "mer_name")
    private String merName;

    /**
     * 终端编号
     */
    @TableField(value = "term_id")
    private String termId;

    /**
     * 工单创建日期（yyyyMMdd）
     */
    @TableField(value = "start_date")
    private LocalDate startDate;

    /**
     * 工单编号
     */
    @TableField(value = "order_no")
    private String orderNo;

    /**
     * 工单类型
     */
    @TableField(value = "order_type")
    private String orderType;

    /**
     * 联系人
     */
    @TableField(value = "link_name")
    private String linkName;

    /**
     * 联系方式
     */
    @TableField(value = "contact_way")
    private String contactWay;

    /**
     * 商户地址
     */
    @TableField(value = "mer_address")
    private String merAddress;

    /**
     * 设备类型
     */
    @TableField(value = "device_type")
    private String deviceType;

    /**
     * 设备序列号
     */
    @TableField(value = "device_no")
    private String deviceNo;

    /**
     * 备注信息
     */
    @TableField(value = "note_msg")
    private String noteMsg;

    /**
     * 服务商编号
     */
    @TableField(value = "agent_id")
    private String agentId;

    /**
     * 请求日期
     */
    @TableField(value = "req_date")
    private LocalDate reqDate;

    /**
     * 请求时间
     */
    @TableField(value = "req_time")
    private LocalTime reqTime;

    /**
     * 工单状态
     */
    @TableField(value = "order_status")
    private String orderStatus;

    /**
     * 上传文件路径
     */
    @TableField(value = "file_path")
    private String filePath;

    /**
     * 描述信息
     */
    @TableField(value = "desc_info")
    private String descInfo;

    /**
     * 分行地区号
     */
    @TableField(value = "area")
    private String area;

    /**
     * 状态（1 下发  2 回送成功  3 回送失败）
     */
    @TableField(value = "`status`")
    private Integer status;

    /**
     * 商户类型
     */
    @TableField(value = "mer_type")
    private String merType;

    /**
     * 请求日期
     */
    @TableField(value = "comp_date")
    private LocalDate compDate;

    /**
     * 请求时间
     */
    @TableField(value = "comp_time")
    private LocalTime compTime;

    /**
     * 异常消息
     */
    @TableField(value = "resp_mssg")
    private String respMssg;

    /**
     * 是否为银行派单（1 是  2否）
     */
    @TableField(value = "is_bank")
    private Byte isBank;

    public WrkIcbcJs save(WrkInfoDetailsVO infoDetail, String area) {
        WrkInfoStoreVO infoStore = infoDetail.getInfoStore();
        WrkInfoVO wrkInfo = infoDetail.getWrkInfo();
        WrkInfoTerminalVO infoTerminal = infoDetail.getInfoTerminal();

        this.agentId = "000004";
        this.transCode = "1020";
        this.storeId = infoStore.getStoreId();
        this.merId = infoStore.getStoreNo();
        this.merName = infoStore.getStoreName();
        this.linkName = infoStore.getStoreContact();
        this.merType = MerTypeOperation.valueOfMerType(infoStore.getStoreType());
        this.contactWay = infoStore.getStorePhone();
        this.merAddress = infoStore.getStoreAddress();

        this.terminalId = infoTerminal.getTerminalId();
        this.termId = infoTerminal.getTerminalNo();
        this.deviceNo = infoTerminal.getTerminalNo();

        this.wrkId = wrkInfo.getWrkId();
        this.startDate = wrkInfo.getCreateTime().toLocalDate();
        this.orderNo = wrkInfo.getWorkNo();
        this.reqDate = wrkInfo.getCreateTime().toLocalDate();
        this.reqTime = wrkInfo.getCreateTime().toLocalTime();
        this.orderType = WorkTypeOperation.valueOfWorkType(wrkInfo.getWorkType());
        this.compDate = wrkInfo.getDisposeTime().toLocalDate();
        this.compTime = wrkInfo.getDisposeTime().toLocalTime();
        this.orderStatus = "1";
        this.area = area;

        this.deviceType = TerminalTypeOperation.valueOfTerminalType(infoTerminal.getTerminalType());
        return this;
    }

    public WrkIcbcJs push(WrkInfoDetailsVO infoDetail) {
        this.agentId = "000004";
        this.transCode = "1020";
        this.startDate = LocalDate.now();
        WrkInfoVO wrkInfo = infoDetail.getWrkInfo();
        WrkInfoStoreVO infoStore = infoDetail.getInfoStore();
        WrkInfoTerminalVO infoTerminal = infoDetail.getInfoTerminal();
        this.merName = infoStore.getStoreName();
        this.linkName = infoStore.getStoreContact();
        this.merType = MerTypeOperation.valueOfMerType(infoStore.getStoreType());
        this.contactWay = infoStore.getStorePhone();
        this.merAddress = infoStore.getStoreAddress();
        this.compDate = wrkInfo.getDisposeTime().toLocalDate();
        this.compTime = wrkInfo.getDisposeTime().toLocalTime();
        this.deviceNo = infoTerminal.getTerminalNo();
        this.orderStatus = "1";
        this.status = 3;
        return this;
    }
}
