package com.fs.sop.domain;

import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.fs.common.annotation.Excel;
import lombok.Data;

import java.io.Serializable;
import java.time.LocalTime;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * sop模板对象 qw_sop_temp
 *
 * @author fs
 * @date 2024-09-26
 */
@Data
public class QwSopTemp implements Serializable
{

    /** id */
    @Excel(name = "模板编号")
    @TableId(type = IdType.INPUT)
    private String id;

    /** 模板标题 */

    @Excel(name = "模板标题")
    private String name;

    /** 规则 */
//    @Excel(name = "规则")
    private String setting;

    /** 状态 */
    @Excel(name = "状态")
    private String status;


    /** 排序 */
    @Excel(name = "排序")
    private Integer sort;

    /** 公司id */
    @Excel(name = "公司id")
    private Long companyId;

    @Excel(name = "间隔天数")
    private Integer gap;

    /**
    * 是否开启官方群发
    */
    @TableField(exist = false)
    private String openOfficial;
    @TableField(exist = false)
    private String openIsAtAll;
    private String corpId;

    /**
    * 模板类型
    */
    @Excel(name = "模板类型")
    private Integer sendType;

    /**
     * 模板类型:0-普通模板,1-总后台模板
     */
    @Excel(name = "模板类型")
    private Integer templateType;

    /**
     * 是否置顶:0-否,1-是
     */
    @Excel(name = "是否置顶")
    private Integer isTop;

    @Excel(name = "创建时间")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private String createTime;

    @Excel(name = "修改时间")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private String updateTime;

    private String createBy;

    private Long project;

    private Long courseId;

    @TableField(exist = false)
    private String modeContent;

    @TableField(exist = false)
    private List<Map<String, Object>> rules;

    @TableField(exist = false)
    private List<QwSopTempDay> list = new ArrayList<>();

    @TableField(exist = false)
    private LocalTime time;

    @TableField(exist = false)
    private boolean cuoser;

    @TableField(exist = false)
    private List<String> timeList;

    @TableField(exist = false)
    private List<String> timeDesc;

    /**
     * 销售部门
     */
    @TableField(exist = false)
    private List<Long> cuDeptIdList;

    @TableField(exist = false)
    private List<Long> userIds;

    @TableField(exist = false)
    private List<String> companyUserIds=new ArrayList<>();
    @TableField(exist = false)
    private Integer pageNum;
    @TableField(exist = false)
    private Integer pageSize;

    public List<String> getCompanyUserIds() {
        if (companyUserIds == null || companyUserIds.isEmpty()) {
            return companyUserIds;
        }

        // 直接在原始列表上修改
        for (int i = 0; i < companyUserIds.size(); i++) {
            String id = companyUserIds.get(i);
            if (id != null) {
                if (id.startsWith("dept_")) {
                    companyUserIds.set(i, id.substring(5));
                } else if (id.startsWith("company_")) {
                    companyUserIds.set(i, id.substring(8));
                } else if (id.startsWith("user_")) {
                    companyUserIds.set(i, id.substring(5));
                }
            }
        }
        return companyUserIds;
    }

    /**
     * 部门类型 00 管理员 01 员工
     */
    @TableField(exist = false)
    private String userType;

    @TableField(exist = false)
    private String createByName;

    @TableField(exist = false)
    private String createByDeptName;
}
