package controllers

import (
	"ColdVerify_server/lib"
	"ColdVerify_server/models/Account"
	"ColdVerify_server/models/Distributor"
	"ColdVerify_server/models/Task"
)

// 获取管理员 关联ERP
func (c *AccountController) Account_List_All_For_ERP() {

	PowerList := Account.Read_Power_List_ALL_1()
	PowerMap := Account.UserPowerListToPowerMap(PowerList)
	T_name := c.GetString("T_name")
	var r_jsons lib.R_JSONS
	r_jsons.List = Account.Read_Admin_List_ALL_Power("", T_name, PowerMap)
	c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: r_jsons}
	c.ServeJSON()
	return
}

// 获取公司列表
func (c *UserController) User_List_All_For_ERP() {

	T_name := c.GetString("T_name")
	CreateDate := c.GetString("CreateDate")
	if len(CreateDate) > 0 && !lib.IsDateStr(CreateDate) {
		c.Data["json"] = lib.JSONS{Code: 202, Msg: "日期格式错误!"}
		c.ServeJSON()
		return
	}
	distributorList := Distributor.Read_Distributor_List_ALL("")
	distributorMap := Distributor.DistributorListToMap(distributorList)
	List, _ := Account.List_All_For_ERP(T_name, CreateDate, distributorMap)

	c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: List}
	c.ServeJSON()
	return
}

func (c *TaskController) Task_List_All_For_ERP() {

	T_reporting_pass_time := c.GetString("T_reporting_pass_time")
	if len(T_reporting_pass_time) > 0 && !lib.IsDateStr(T_reporting_pass_time) {
		c.Data["json"] = lib.JSONS{Code: 202, Msg: "日期格式错误!"}
		c.ServeJSON()
		return
	}
	List, _ := Task.Read_Task_List_For_ERP(T_reporting_pass_time)

	c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: List}
	c.ServeJSON()
	return
}
