package com.gic.haoban.manage.api.dto;

import cn.hutool.core.collection.CollUtil;

import java.io.Serializable;
import java.util.List;
import java.util.Map;

/**
 * @description: 转移返回结果DTO
 * @Author: wenhua
 * @Date: 2023/2/3 10:47
 */
public class TransferActiveCodeDTO implements Serializable {

    private static final long serialVersionUID = 1L;

    /**
     * 转移总数
     */
    private Integer totalNum;
    /**
     * 成功总数
     */
    private Integer successNum;
    /**
     * 失败总数
     */
    private Integer failedNum;
    /**
     * 成功明细
     */
    private List<Map<String, String>> successList;
    /**
     * 失败明细
     */
    private List<Map<String, String>> failedList;

    public List<Map<String, String>> getSuccessList() {
        return successList;
    }

    public void setSuccessList(List<Map<String, String>> successList) {
        this.successList = successList;
    }

    public Integer getTotalNum() {
        return totalNum;
    }

    public void setTotalNum(Integer totalNum) {
        this.totalNum = totalNum;
    }

    public Integer getSuccessNum() {
        return successNum;
    }

    public void setSuccessNum(Integer successNum) {
        this.successNum = successNum;
    }

    public Integer getFailedNum() {
        return failedNum;
    }

    public void setFailedNum(Integer failedNum) {
        this.failedNum = failedNum;
    }

    public List<Map<String, String>> getFailedList() {
        return failedList;
    }

    public void setFailedList(List<Map<String, String>> failedList) {
        this.failedList = failedList;
    }

    //操作日志记录
    public String logRecord() {
        StringBuilder log = new StringBuilder();
        //记录单个转移的成功日志
        if (CollUtil.isNotEmpty(this.successList) && this.totalNum==1){
            Map<String, String> stringMap = this.successList.get(0);
            String handoverStaffPhone = null==stringMap.get("handoverStaffPhone")?"":stringMap.get("handoverStaffPhone");
            String takeoverStaffPhone = null==stringMap.get("takeoverStaffPhone")?"":stringMap.get("takeoverStaffPhone");
            log.append("将"+stringMap.get("handoverStaffName")+"-"+handoverStaffPhone+"的许可手动转移给"
                    +stringMap.get("takeoverStaffName")+"-"+takeoverStaffPhone);
            return log.toString();
        }
        log.append("共需转移" + this.totalNum + "，成功" + this.successNum + "，失败" + this.failedNum + "。");
        if (CollUtil.isNotEmpty(this.failedList)) {
            log.append("失败明细：");
            for (int i=1;i<=this.failedList.size();i++){
                Map<String, String> stringMap = this.failedList.get(i - 1);
                log.append(i+".（转移成员："+stringMap.get("handoverStaffName")+"，接收成员："+stringMap.get("takeoverStaffName")+"，失败原因错误码："+stringMap.get("errorCode")+"）；");
            }
            //去掉末尾分号
            String substring = log.substring(0, log.toString().length() - 1);
            return substring;
        }
        return log.toString();
    }
}
