package implments

import (
	"LAPP_LF_MOM_BACKEND/conf"
	"LAPP_LF_MOM_BACKEND/infra/logger"
	model "LAPP_LF_MOM_BACKEND/models/api"
	"LAPP_LF_MOM_BACKEND/utils"
	"LAPP_LF_MOM_BACKEND/web/models"
	"encoding/json"
)


/******************************************************************************
 *
 * @Struct Name              : AndonServiceImplement
 *-----------------------------------------------------------------------------
 *
 * @Description              : AndonService的服务实现
 *
 * @Author                   : zhangxin
 *
 * @Date                     : 2021-05-17
 *
 ******************************************************************************/
type AndonServiceImplement struct {
}

/******************************************************************************
 *
 * @Function Name            : AndonServiceImplement
 *-----------------------------------------------------------------------------
 *
 * @Description              : 创建一个AndonServiceImplement实例
 *
 * @Return Value             : AndonServiceImplement实例
 *
 * @Author                   : zhangxin
 *
 * @Date                     : 2021-05-17
 *
 ******************************************************************************/
func NewAndonServiceImplement() *AndonServiceImplement {
	return &AndonServiceImplement{}
}


/******************************************************************************
 *
 * @Reference LAPP_LF_MOM_BACKEND/services/api/Andon.Receive
 *
 ******************************************************************************/
func (impl *AndonServiceImplement) TouchOff(user *models.Usertab) (response model.Andon, err error) {
	log, _ := logger.NewLogger(user.Userid, "API")
	url := conf.DbConfig.AndonTouchOff
	data := []byte("{}")
	body, err := utils.Post(url, data)
	if err != nil {
		log.Error("TouchOff send post request failed, error:" + err.Error())
		return response, err
	}
	err = json.Unmarshal(body, &response)
	if err != nil {
		log.Error("TouchOff unmarshal mes response failed, error:" + err.Error())
		return response, err
	}

	return response, nil
}