// Copyright 2019 getensh.com. All rights reserved.
// Use of this source code is governed by getensh.com.

package ctrl_v1

import (
	"gd_management_gateway/errors"
	"gd_management_gateway/params/param_base"
	"gd_management_gateway/params/param_v1_0"
	"gd_management_gateway/rpc_apis"
	"gd_management_gateway/rpc_apis/gd_management"
	"fmt"
	"time"

	"gd_management_gateway/common.in/httper"
	"gd_management_gateway/common.in/task"
	"gd_management_gateway/common.in/utils"

	"github.com/astaxie/beego"
	"go.uber.org/zap"
)

// Operations about data api
type AccountingController struct {
	metadata interface{} // 中继元数据
	beego.Controller
	LogID string
}

// @Title 获取账单列表
// @Description 获取账单列表
// @Param   token    header   string true "token"
// @Param   uid    header   int64 true "admin id"
// @Param   page_number  query  int64   false "页号"
// @Param   merchant_id  query  int64   false "商户id"
// @Param   start_time  query  string   false "开始时间"
// @Param   end_time  query  string   false "结束时间"
// @Success 200 	{object} params.param_v1_0.BillListResp "响应信息"
// @Failure 500 	服务器错误
// @router /bill_list [get]
func (u *AccountingController) BillList() {
	u.LogID = fmt.Sprintf("BillList[%d]", time.Now().UnixNano())

	req := &param_v1_0.BillListReq{}
	getParamsTask := func() error {
		httper.FillRequireParams(u.Ctx, req, u.LogID)
		return nil
	}

	handleDataTask := func() error {
		mreq := gd_management.BillListReq{}
		mreq.MerchantId = req.MerchantId
		mreq.PageNumber = req.PageNumber
		mreq.StartTime = req.StartTime
		mreq.EndTime = req.EndTime
		reply, err := rpc_apis.Management.BillList(utils.NewContextFromBeegoCtx(u.Ctx), &mreq)
		if err != nil {
			l.Error("rpc",
				zap.String("call", "BillList"),
				zap.String("args", utils.MarshalJsonString(req)),
				zap.String("error", err.Error()))
			return errors.ErrorTransform(err)
		}
		resp := param_v1_0.BillListResp{
			SimpleResp: param_base.SimpleResp{
				Code: 0,
				Msg:  "SUCCESS",
			},
		}
		resp.Data = reply
		httper.JSON(u.Ctx, resp, u.LogID)
		return nil
	}

	// 执行以上定义的任务
	task.Do(&task.PanicRecover{
		Ctx:   u.Ctx,
		LogID: u.LogID}, u.Ctx,
		getParamsTask, handleDataTask,
	)
}

// @Title 获取充值列表
// @Description 获取充值列表
// @Param   token    header   string true "token"
// @Param   uid    header   int64 true "admin id"
// @Param   page_number  query  int64   false "页号"
// @Param   merchant_id  query  int64   false "商户id"
// @Param   start_time  query  string   false "开始时间"
// @Param   end_time  query  string   false "结束时间"
// @Success 200 	{object} params.param_v1_0.ChargeListResp "响应信息"
// @Failure 500 	服务器错误
// @router /charge_list [get]
func (u *AccountingController) ChargeList() {
	u.LogID = fmt.Sprintf("ChargeList[%d]", time.Now().UnixNano())

	req := &param_v1_0.ChargeListReq{}
	getParamsTask := func() error {
		httper.FillRequireParams(u.Ctx, req, u.LogID)
		return nil
	}

	handleDataTask := func() error {
		mreq := gd_management.ChargeListReq{}
		mreq.MerchantId = req.MerchantId
		mreq.PageNumber = req.PageNumber
		mreq.StartTime = req.StartTime
		mreq.EndTime = req.EndTime
		reply, err := rpc_apis.Management.ChargeList(utils.NewContextFromBeegoCtx(u.Ctx), &mreq)
		if err != nil {
			l.Error("rpc",
				zap.String("call", "ChargeList"),
				zap.String("args", utils.MarshalJsonString(req)),
				zap.String("error", err.Error()))
			return errors.ErrorTransform(err)
		}
		resp := param_v1_0.ChargeListResp{
			SimpleResp: param_base.SimpleResp{
				Code: 0,
				Msg:  "SUCCESS",
			},
		}
		resp.Data = reply
		httper.JSON(u.Ctx, resp, u.LogID)
		return nil
	}

	// 执行以上定义的任务
	task.Do(&task.PanicRecover{
		Ctx:   u.Ctx,
		LogID: u.LogID}, u.Ctx,
		getParamsTask, handleDataTask,
	)
}

// @Title 获取消费列表
// @Description 获取消费列表
// @Param   token    header   string true "token"
// @Param   uid    header   int64 true "admin id"
// @Param   page_number  query  int64   false "页号"
// @Param   merchant_id  query  int64   false "商户id"
// @Param   data_api_id  query  int64   false "数据api id"
// @Param   start_time  query  string   false "开始时间"
// @Param   end_time  query  string   false "结束时间"
// @Param   consume_order  query  int   false "消费排序"
// @Success 200 	{object} params.param_v1_0.ConsumeListResp "响应信息"
// @Failure 500 	服务器错误
// @router /consume_list [get]
func (u *AccountingController) ConsumeList() {
	u.LogID = fmt.Sprintf("ConsumeList[%d]", time.Now().UnixNano())

	req := &param_v1_0.ConsumeListReq{}
	getParamsTask := func() error {
		httper.FillRequireParams(u.Ctx, req, u.LogID)
		return nil
	}

	handleDataTask := func() error {
		mreq := gd_management.ConsumeListReq{}
		mreq.MerchantId = req.MerchantId
		mreq.PageNumber = req.PageNumber
		mreq.StartTime = req.StartTime
		mreq.EndTime = req.EndTime
		mreq.DataApiId = req.DataApiId
		mreq.ConsumeOrder = req.ConsumeOrder
		reply, err := rpc_apis.Management.ConsumeList(utils.NewContextFromBeegoCtx(u.Ctx), &mreq)
		if err != nil {
			l.Error("rpc",
				zap.String("call", "ConsumeList"),
				zap.String("args", utils.MarshalJsonString(req)),
				zap.String("error", err.Error()))
			return errors.ErrorTransform(err)
		}
		resp := param_v1_0.ConsumeListResp{
			SimpleResp: param_base.SimpleResp{
				Code: 0,
				Msg:  "SUCCESS",
			},
		}
		resp.Data = reply
		httper.JSON(u.Ctx, resp, u.LogID)
		return nil
	}

	// 执行以上定义的任务
	task.Do(&task.PanicRecover{
		Ctx:   u.Ctx,
		LogID: u.LogID}, u.Ctx,
		getParamsTask, handleDataTask,
	)
}

// @Title 消费趋势
// @Description 消费趋势
// @Param   token    header   string true "token"
// @Param   uid    header   int64 true "admin id"
// @Param   merchant_id  query  int64   false "商户id"
// @Param   data_api_id  query  int64   false "数据api id"
// @Param   start_time  query  string   false "开始时间"
// @Param   end_time  query  string   false "结束时间"
// @Success 200 	{object} params.param_v1_0.ConsumeTrendListResp "响应信息"
// @Failure 500 	服务器错误
// @router /consume_trend_list [get]
func (u *AccountingController) ConsumeTrendList() {
	u.LogID = fmt.Sprintf("ConsumeTrendList[%d]", time.Now().UnixNano())

	req := &param_v1_0.ConsumeTrendListReq{}
	getParamsTask := func() error {
		httper.FillRequireParams(u.Ctx, req, u.LogID)
		return nil
	}

	handleDataTask := func() error {
		mreq := gd_management.ConsumeTrendListReq{}
		mreq.MerchantId = req.MerchantId
		mreq.StartTime = req.StartTime
		mreq.EndTime = req.EndTime
		mreq.DataApiId = req.DataApiId
		reply, err := rpc_apis.Management.ConsumeTrendList(utils.NewContextFromBeegoCtx(u.Ctx), &mreq)
		if err != nil {
			l.Error("rpc",
				zap.String("call", "ConsumeTrendList"),
				zap.String("args", utils.MarshalJsonString(req)),
				zap.String("error", err.Error()))
			return errors.ErrorTransform(err)
		}
		resp := param_v1_0.ConsumeTrendListResp{
			SimpleResp: param_base.SimpleResp{
				Code: 0,
				Msg:  "SUCCESS",
			},
		}
		resp.Data = reply
		httper.JSON(u.Ctx, resp, u.LogID)
		return nil
	}

	// 执行以上定义的任务
	task.Do(&task.PanicRecover{
		Ctx:   u.Ctx,
		LogID: u.LogID}, u.Ctx,
		getParamsTask, handleDataTask,
	)
}

// @Title 商户数据api价格列表
// @Description 商户数据api价格列表
// @Param   token    header   string true "token"
// @Param   uid    header   int64 true "admin id"
// @Param   merchant_id  query  int64   false "商户id"
// @Success 200 	{object} params.param_v1_0.MerchantDataApiPriceListResp "响应信息"
// @Failure 500 	服务器错误
// @router /merchant_data_api_price_list [get]
func (u *AccountingController) MerchantDataApiPriceList() {
	u.LogID = fmt.Sprintf("MerchantDataApiPriceList[%d]", time.Now().UnixNano())

	req := &param_v1_0.MerchantDataApiPriceListReq{}
	getParamsTask := func() error {
		httper.FillRequireParams(u.Ctx, req, u.LogID)
		return nil
	}

	handleDataTask := func() error {
		mreq := gd_management.MerchantDataApiPriceListReq{}
		mreq.MerchantId = req.MerchantId
		reply, err := rpc_apis.Management.MerchantDataApiPriceList(utils.NewContextFromBeegoCtx(u.Ctx), &mreq)
		if err != nil {
			l.Error("rpc",
				zap.String("call", "MerchantDataApiPriceList"),
				zap.String("args", utils.MarshalJsonString(req)),
				zap.String("error", err.Error()))
			return errors.ErrorTransform(err)
		}
		resp := param_v1_0.MerchantDataApiPriceListResp{
			SimpleResp: param_base.SimpleResp{
				Code: 0,
				Msg:  "SUCCESS",
			},
		}
		resp.Data = reply
		httper.JSON(u.Ctx, resp, u.LogID)
		return nil
	}

	// 执行以上定义的任务
	task.Do(&task.PanicRecover{
		Ctx:   u.Ctx,
		LogID: u.LogID}, u.Ctx,
		getParamsTask, handleDataTask,
	)
}

// @Title 商户充值
// @Description 商户充值
// @Param   token    header   string true "token"
// @Param   uid    header   int64 true "admin id"
// @Param   body   body rpc_apis.gd_management.MerchantChargeReq   true "参数"
// @Success 200 	{object} params.param_v1_0.MerchantChargeResp "响应信息"
// @Failure 500 	服务器错误
// @router /merchant_charge [post]
func (u *AccountingController) MerchantCharge() {
	u.LogID = fmt.Sprintf("MerchantCharge[%d]", time.Now().UnixNano())

	req := &param_v1_0.MerchantChargeReq{}
	getParamsTask := func() error {
		httper.FillRequireParams(u.Ctx, req, u.LogID)
		return nil
	}

	// 加入行为日志
	/*AddActionLogTask := func() error {
		go func() {
			mreq := gd_management.ManagementDataApiGetQueryTypeReq{}
			mreq.QueryTypeId = req.Body.QueryTypeId
			reply, err := rpc_apis.Management.DataApiGetQueryType(utils.NewContextFromBeegoCtx(u.Ctx), &mreq)
			if err != nil {
				l.Error("rpc",
					zap.String("call", "DataApiGetQueryType"),
					zap.String("args", utils.MarshalJsonString(req)),
					zap.String("error", err.Error()))
				return
			}

			// 构建json
			contentBytes, _ := json.Marshal(req.Body)

			areq := gd_admin.AddActionLogReq{
				Uid:        req.Uid,
				Name:       reply.QueryTypeInfo.QueryTypeName,
				Modules:    "数据API",
				Func:       "数据api添加基础api",
				Content:    string(contentBytes),
				ModifyTime: time.Now().Format("2006-01-02 15:04:05"),
			}
			AddActionLog(areq)
		}()

		return nil
	}*/

	handleDataTask := func() error {
		userName := utils.GetUserNameFromToken(req.Token)
		req.Body.UserName = userName
		_, err := rpc_apis.Management.MerchantCharge(utils.NewContextFromBeegoCtx(u.Ctx), &req.Body)
		if err != nil {
			l.Error("rpc",
				zap.String("call", "MerchantCharge"),
				zap.String("args", utils.MarshalJsonString(req)),
				zap.String("error", err.Error()))
			return errors.ErrorTransform(err)
		}
		resp := param_v1_0.MerchantChargeResp{
			SimpleResp: param_base.SimpleResp{
				Code: 0,
				Msg:  "SUCCESS",
			},
		}
		httper.JSON(u.Ctx, resp, u.LogID)
		return nil
	}

	// 执行以上定义的任务
	task.Do(&task.PanicRecover{
		Ctx:   u.Ctx,
		LogID: u.LogID}, u.Ctx,
		getParamsTask, handleDataTask,
	)
}

// @Title 商户价格列表
// @Description 商户价格()列表
// @Param   token    header   string true "token"
// @Param   uid    header   int64 true "admin id"
// @Param   merchant_id  query  int64   false "商户id"
// @Param   merchant_type_list  query string   false "商户类型列表"
// @Param   arrearage_order  query  int   false "可欠费金额排序"
// @Param   page_number  query  int   false "页号"
// @Success 200 	{object} params.param_v1_0.MerchantPriceListResp "响应信息"
// @Failure 500 	服务器错误
// @router /merchant_price_list [get]
func (u *AccountingController) MerchantPriceList() {
	u.LogID = fmt.Sprintf("MerchantPriceList[%d]", time.Now().UnixNano())

	req := &param_v1_0.MerchantPriceListReq{}
	getParamsTask := func() error {
		httper.FillRequireParams(u.Ctx, req, u.LogID)
		return nil
	}

	handleDataTask := func() error {
		mreq := gd_management.MerchantPriceListReq{}
		mreq.MerchantId = req.MerchantId
		mreq.PageNumber = req.PageNumber
		mreq.ArrearageOrder = req.ArrearageOrder
		mreq.MerchantTypeList = req.MerchantTypeList
		reply, err := rpc_apis.Management.MerchantPriceList(utils.NewContextFromBeegoCtx(u.Ctx), &mreq)
		if err != nil {
			l.Error("rpc",
				zap.String("call", "MerchantPriceList"),
				zap.String("args", utils.MarshalJsonString(req)),
				zap.String("error", err.Error()))
			return errors.ErrorTransform(err)
		}
		resp := param_v1_0.MerchantPriceListResp{
			SimpleResp: param_base.SimpleResp{
				Code: 0,
				Msg:  "SUCCESS",
			},
		}
		resp.Data = reply
		httper.JSON(u.Ctx, resp, u.LogID)
		return nil
	}

	// 执行以上定义的任务
	task.Do(&task.PanicRecover{
		Ctx:   u.Ctx,
		LogID: u.LogID}, u.Ctx,
		getParamsTask, handleDataTask,
	)
}

// @Title 设置商户数据api单价
// @Description 设置商户数据api单价
// @Param   token    header   string true "token"
// @Param   uid    header   int64 true "admin id"
// @Param   body   body rpc_apis.gd_management.SetMerchantDataApiPriceReqReq   true "参数"
// @Success 200 	{object} params.param_v1_0.SetMerchantDataApiPriceReqResp "响应信息"
// @Failure 500 	服务器错误
// @router /merchant_data_api_price [put]
func (u *AccountingController) SetMerchantDataApiPriceReq() {
	u.LogID = fmt.Sprintf("SetMerchantDataApiPriceReq[%d]", time.Now().UnixNano())

	req := &param_v1_0.SetMerchantDataApiPriceReq{}
	getParamsTask := func() error {
		httper.FillRequireParams(u.Ctx, req, u.LogID)
		return nil
	}

	// 加入行为日志
	/*AddActionLogTask := func() error {
		go func() {
			mreq := gd_management.ManagementDataApiGetQueryTypeReq{}
			mreq.QueryTypeId = req.Body.QueryTypeId
			reply, err := rpc_apis.Management.DataApiGetQueryType(utils.NewContextFromBeegoCtx(u.Ctx), &mreq)
			if err != nil {
				l.Error("rpc",
					zap.String("call", "DataApiGetQueryType"),
					zap.String("args", utils.MarshalJsonString(req)),
					zap.String("error", err.Error()))
				return
			}

			// 构建json
			contentBytes, _ := json.Marshal(req.Body)

			areq := gd_admin.AddActionLogReq{
				Uid:        req.Uid,
				Name:       reply.QueryTypeInfo.QueryTypeName,
				Modules:    "数据API",
				Func:       "数据api添加基础api",
				Content:    string(contentBytes),
				ModifyTime: time.Now().Format("2006-01-02 15:04:05"),
			}
			AddActionLog(areq)
		}()

		return nil
	}*/

	handleDataTask := func() error {
		_, err := rpc_apis.Management.SetMerchantDataApiPrice(utils.NewContextFromBeegoCtx(u.Ctx), &req.Body)
		if err != nil {
			l.Error("rpc",
				zap.String("call", "SetMerchantDataApiPrice"),
				zap.String("args", utils.MarshalJsonString(req)),
				zap.String("error", err.Error()))
			return errors.ErrorTransform(err)
		}
		resp := param_v1_0.SetMerchantDataApiPriceResp{
			SimpleResp: param_base.SimpleResp{
				Code: 0,
				Msg:  "SUCCESS",
			},
		}
		httper.JSON(u.Ctx, resp, u.LogID)
		return nil
	}

	// 执行以上定义的任务
	task.Do(&task.PanicRecover{
		Ctx:   u.Ctx,
		LogID: u.LogID}, u.Ctx,
		getParamsTask, handleDataTask,
	)
}

// @Title 设置商户类型
// @Description 设置商户类型
// @Param   token    header   string true "token"
// @Param   uid    header   int64 true "admin id"
// @Param   body   body rpc_apis.gd_management.SetMerchantTypeReq   true "参数"
// @Success 200 	{object} params.param_v1_0.SetMerchantTypeResp "响应信息"
// @Failure 500 	服务器错误
// @router /merchant_type [put]
func (u *AccountingController) SetMerchantType() {
	u.LogID = fmt.Sprintf("SetMerchantType[%d]", time.Now().UnixNano())

	req := &param_v1_0.SetMerchantTypeReq{}
	getParamsTask := func() error {
		httper.FillRequireParams(u.Ctx, req, u.LogID)
		return nil
	}

	// 加入行为日志
	/*AddActionLogTask := func() error {
		go func() {
			mreq := gd_management.ManagementDataApiGetQueryTypeReq{}
			mreq.QueryTypeId = req.Body.QueryTypeId
			reply, err := rpc_apis.Management.DataApiGetQueryType(utils.NewContextFromBeegoCtx(u.Ctx), &mreq)
			if err != nil {
				l.Error("rpc",
					zap.String("call", "DataApiGetQueryType"),
					zap.String("args", utils.MarshalJsonString(req)),
					zap.String("error", err.Error()))
				return
			}

			// 构建json
			contentBytes, _ := json.Marshal(req.Body)

			areq := gd_admin.AddActionLogReq{
				Uid:        req.Uid,
				Name:       reply.QueryTypeInfo.QueryTypeName,
				Modules:    "数据API",
				Func:       "数据api添加基础api",
				Content:    string(contentBytes),
				ModifyTime: time.Now().Format("2006-01-02 15:04:05"),
			}
			AddActionLog(areq)
		}()

		return nil
	}*/

	handleDataTask := func() error {
		_, err := rpc_apis.Management.SetMerchantType(utils.NewContextFromBeegoCtx(u.Ctx), &req.Body)
		if err != nil {
			l.Error("rpc",
				zap.String("call", "SetMerchantType"),
				zap.String("args", utils.MarshalJsonString(req)),
				zap.String("error", err.Error()))
			return errors.ErrorTransform(err)
		}
		resp := param_v1_0.SetMerchantTypeResp{
			SimpleResp: param_base.SimpleResp{
				Code: 0,
				Msg:  "SUCCESS",
			},
		}
		httper.JSON(u.Ctx, resp, u.LogID)
		return nil
	}

	// 执行以上定义的任务
	task.Do(&task.PanicRecover{
		Ctx:   u.Ctx,
		LogID: u.LogID}, u.Ctx,
		getParamsTask, handleDataTask,
	)
}

// @Title 账单详情列表
// @Description 商户价格()列表
// @Param   token    header   string true "token"
// @Param   uid    header   int64 true "admin id"
// @Param   merchant_id  query  int64   true "商户id"
// @Param   bill_id  query  int64   true "账单id"
// @Param   month  query  string   true "月份（2022-02）"
// @Success 200 	{object} params.param_v1_0.BillDetailListResp "响应信息"
// @Failure 500 	服务器错误
// @router /bill_detail_list [get]
func (u *AccountingController) BillDetailList() {
	u.LogID = fmt.Sprintf("BillDetailList[%d]", time.Now().UnixNano())

	req := &param_v1_0.BillDetailListReq{}
	getParamsTask := func() error {
		httper.FillRequireParams(u.Ctx, req, u.LogID)
		return nil
	}

	handleDataTask := func() error {
		mreq := gd_management.BillDetailListReq{}
		mreq.MerchantId = req.MerchantId
		mreq.Month = req.Month
		mreq.BillId = req.BillId
		reply, err := rpc_apis.Management.BillDetailList(utils.NewContextFromBeegoCtx(u.Ctx), &mreq)
		if err != nil {
			l.Error("rpc",
				zap.String("call", "BillDetailList"),
				zap.String("args", utils.MarshalJsonString(req)),
				zap.String("error", err.Error()))
			return errors.ErrorTransform(err)
		}
		resp := param_v1_0.BillDetailListResp{
			SimpleResp: param_base.SimpleResp{
				Code: 0,
				Msg:  "SUCCESS",
			},
		}
		resp.Data = reply
		httper.JSON(u.Ctx, resp, u.LogID)
		return nil
	}

	// 执行以上定义的任务
	task.Do(&task.PanicRecover{
		Ctx:   u.Ctx,
		LogID: u.LogID}, u.Ctx,
		getParamsTask, handleDataTask,
	)
}

// @Title 更新账单详情（设置计费量）
// @Description 更新账单详情（设置计费量）
// @Param   token    header   string true "token"
// @Param   uid    header   int64 true "admin id"
// @Param   body   body rpc_apis.gd_management.UpdateBillDetailReq   true "参数"
// @Success 200 	{object} params.param_v1_0.UpdateBillDetailResp "响应信息"
// @Failure 500 	服务器错误
// @router /bill_detail [put]
func (u *AccountingController) UpdateBillDetail() {
	u.LogID = fmt.Sprintf("UpdateBillDetail[%d]", time.Now().UnixNano())

	req := &param_v1_0.UpdateBillDetailReq{}
	getParamsTask := func() error {
		httper.FillRequireParams(u.Ctx, req, u.LogID)
		return nil
	}

	// 加入行为日志
	/*AddActionLogTask := func() error {
		go func() {
			mreq := gd_management.ManagementDataApiGetQueryTypeReq{}
			mreq.QueryTypeId = req.Body.QueryTypeId
			reply, err := rpc_apis.Management.DataApiGetQueryType(utils.NewContextFromBeegoCtx(u.Ctx), &mreq)
			if err != nil {
				l.Error("rpc",
					zap.String("call", "DataApiGetQueryType"),
					zap.String("args", utils.MarshalJsonString(req)),
					zap.String("error", err.Error()))
				return
			}

			// 构建json
			contentBytes, _ := json.Marshal(req.Body)

			areq := gd_admin.AddActionLogReq{
				Uid:        req.Uid,
				Name:       reply.QueryTypeInfo.QueryTypeName,
				Modules:    "数据API",
				Func:       "数据api添加基础api",
				Content:    string(contentBytes),
				ModifyTime: time.Now().Format("2006-01-02 15:04:05"),
			}
			AddActionLog(areq)
		}()

		return nil
	}*/

	handleDataTask := func() error {
		userName := utils.GetUserNameFromToken(req.Token)
		req.Body.UserName = userName
		_, err := rpc_apis.Management.UpdateBillDetail(utils.NewContextFromBeegoCtx(u.Ctx), &req.Body)
		if err != nil {
			l.Error("rpc",
				zap.String("call", "UpdateBillDetail"),
				zap.String("args", utils.MarshalJsonString(req)),
				zap.String("error", err.Error()))
			return errors.ErrorTransform(err)
		}
		resp := param_v1_0.UpdateBillDetailResp{
			SimpleResp: param_base.SimpleResp{
				Code: 0,
				Msg:  "SUCCESS",
			},
		}
		httper.JSON(u.Ctx, resp, u.LogID)
		return nil
	}

	// 执行以上定义的任务
	task.Do(&task.PanicRecover{
		Ctx:   u.Ctx,
		LogID: u.LogID}, u.Ctx,
		getParamsTask, handleDataTask,
	)
}

// @Title 添加账单备注
// @Description 添加账单备注
// @Param   token    header   string true "token"
// @Param   uid    header   int64 true "admin id"
// @Param   body   body rpc_apis.gd_management.BillRemarkReq   true "参数"
// @Success 200 	{object} params.param_v1_0.BillRemarkResp "响应信息"
// @Failure 500 	服务器错误
// @router /bill_remark [put]
func (u *AccountingController) BillRemark() {
	u.LogID = fmt.Sprintf("UpdateBillDetail[%d]", time.Now().UnixNano())

	req := &param_v1_0.BillRemarkReq{}
	getParamsTask := func() error {
		httper.FillRequireParams(u.Ctx, req, u.LogID)
		return nil
	}

	// 加入行为日志
	/*AddActionLogTask := func() error {
		go func() {
			mreq := gd_management.ManagementDataApiGetQueryTypeReq{}
			mreq.QueryTypeId = req.Body.QueryTypeId
			reply, err := rpc_apis.Management.DataApiGetQueryType(utils.NewContextFromBeegoCtx(u.Ctx), &mreq)
			if err != nil {
				l.Error("rpc",
					zap.String("call", "DataApiGetQueryType"),
					zap.String("args", utils.MarshalJsonString(req)),
					zap.String("error", err.Error()))
				return
			}

			// 构建json
			contentBytes, _ := json.Marshal(req.Body)

			areq := gd_admin.AddActionLogReq{
				Uid:        req.Uid,
				Name:       reply.QueryTypeInfo.QueryTypeName,
				Modules:    "数据API",
				Func:       "数据api添加基础api",
				Content:    string(contentBytes),
				ModifyTime: time.Now().Format("2006-01-02 15:04:05"),
			}
			AddActionLog(areq)
		}()

		return nil
	}*/

	handleDataTask := func() error {
		_, err := rpc_apis.Management.BillRemark(utils.NewContextFromBeegoCtx(u.Ctx), &req.Body)
		if err != nil {
			l.Error("rpc",
				zap.String("call", "BillRemark"),
				zap.String("args", utils.MarshalJsonString(req)),
				zap.String("error", err.Error()))
			return errors.ErrorTransform(err)
		}
		resp := param_v1_0.BillRemarkResp{
			SimpleResp: param_base.SimpleResp{
				Code: 0,
				Msg:  "SUCCESS",
			},
		}
		httper.JSON(u.Ctx, resp, u.LogID)
		return nil
	}

	// 执行以上定义的任务
	task.Do(&task.PanicRecover{
		Ctx:   u.Ctx,
		LogID: u.LogID}, u.Ctx,
		getParamsTask, handleDataTask,
	)
}

// @Title 生成账单
// @Description 生成账单
// @Param   token    header   string true "token"
// @Param   uid    header   int64 true "admin id"
// @Param   month  query  int64   false "页号"
// @Success 200 	{object} params.param_v1_0.BillListResp "响应信息"
// @Failure 500 	服务器错误
// @router /generate_bill [get]
func (u *AccountingController) GenerateBill() {
	u.LogID = fmt.Sprintf("GenerateBill[%d]", time.Now().UnixNano())

	req := &param_v1_0.GenerateBillReq{}
	getParamsTask := func() error {
		httper.FillRequireParams(u.Ctx, req, u.LogID)
		return nil
	}

	handleDataTask := func() error {
		mreq := gd_management.GenerateBillReq{}
		mreq.Month = req.Month
		reply, err := rpc_apis.Management.GenerateBill(utils.NewContextFromBeegoCtx(u.Ctx), &mreq)
		if err != nil {
			l.Error("rpc",
				zap.String("call", "GenerateBill"),
				zap.String("args", utils.MarshalJsonString(req)),
				zap.String("error", err.Error()))
			return errors.ErrorTransform(err)
		}
		resp := param_v1_0.GenerateBillResp{
			SimpleResp: param_base.SimpleResp{
				Code: 0,
				Msg:  "SUCCESS",
			},
		}
		resp.Data = reply
		httper.JSON(u.Ctx, resp, u.LogID)
		return nil
	}

	// 执行以上定义的任务
	task.Do(&task.PanicRecover{
		Ctx:   u.Ctx,
		LogID: u.LogID}, u.Ctx,
		getParamsTask, handleDataTask,
	)
}

// @Title 账单导出Excel
// @Description 账单导出Excel
// @Param   token    header   string true "token"
// @Param   uid    header   int64 true "admin id"
// @Param   merchant_id  query  int64   true "商户id"
// @Param   bill_id  query  int64   true "账单id"
// @Param   month  query  string   true "月份（2022-02）"
// @Success 200 	{object} params.param_v1_0.BillExportExcelResp "响应信息"
// @Failure 500 	服务器错误
// @router /bill_export_excel [get]
func (u *AccountingController) BillExportExcel() {
	u.LogID = fmt.Sprintf("BillExportExcel[%d]", time.Now().UnixNano())

	req := &param_v1_0.BillExportExcelReq{}
	getParamsTask := func() error {
		httper.FillRequireParams(u.Ctx, req, u.LogID)
		return nil
	}

	handleDataTask := func() error {
		mreq := gd_management.BillExportExcelReq{}
		mreq.MerchantId = req.MerchantId
		mreq.Month = req.Month
		mreq.BillId = req.BillId
		reply, err := rpc_apis.Management.BillExportExcel(utils.NewContextFromBeegoCtx(u.Ctx), &mreq)
		if err != nil {
			l.Error("rpc",
				zap.String("call", "BillExportExcel"),
				zap.String("args", utils.MarshalJsonString(req)),
				zap.String("error", err.Error()))
			return errors.ErrorTransform(err)
		}
		resp := param_v1_0.BillExportExcelResp{
			SimpleResp: param_base.SimpleResp{
				Code: 0,
				Msg:  "SUCCESS",
			},
		}
		resp.Data = reply
		httper.JSON(u.Ctx, resp, u.LogID)
		return nil
	}

	// 执行以上定义的任务
	task.Do(&task.PanicRecover{
		Ctx:   u.Ctx,
		LogID: u.LogID}, u.Ctx,
		getParamsTask, handleDataTask,
	)
}
