// Copyright (c) Shenyang Leading Edge Intelligent Technology Co., Ltd. All rights reserved.

package implments

import (
	dal "LAPP_ACURA_MOM_BACKEND/dao/base"
	"LAPP_ACURA_MOM_BACKEND/db"
	"LAPP_ACURA_MOM_BACKEND/global"
	"LAPP_ACURA_MOM_BACKEND/grmi"
	meta "LAPP_ACURA_MOM_BACKEND/meta/base"
	model "LAPP_ACURA_MOM_BACKEND/models/base"
)

/******************************************************************************
 *
 * @Description              : AndonInfo的默认查询条件
 *
 * @Author                   : 代码生成器创建
 *
 * @Date                     : 2022-01-06 14:56:42
 *
 ******************************************************************************/
var DefaultConditionOfAndonInfo = grmi.NewCondition(
	map[string]grmi.ConditionItem{
		meta.AndonInfo_WorkLineId.UrlParameterName:  grmi.NewConditionItem(meta.AndonInfo_WorkLineId, grmi.Equal, false),
		meta.AndonInfo_PO.UrlParameterName:          grmi.NewConditionItem(meta.AndonInfo_PO, grmi.Equal, false),
		meta.AndonInfo_WorkPlaceId.UrlParameterName: grmi.NewConditionItem(meta.AndonInfo_WorkPlaceId, grmi.Equal, false),
		meta.AndonInfo_WorkPlaceNr.UrlParameterName: grmi.NewConditionItem(meta.AndonInfo_WorkPlaceNr, grmi.Equal, false),
		meta.AndonInfo_SerialId.UrlParameterName:    grmi.NewConditionItem(meta.AndonInfo_SerialId, grmi.Equal, false),
		meta.AndonInfo_OperationId.UrlParameterName: grmi.NewConditionItem(meta.AndonInfo_OperationId, grmi.Equal, false),
		meta.AndonInfo_RuleId.UrlParameterName:      grmi.NewConditionItem(meta.AndonInfo_RuleId, grmi.Equal, false),
		meta.AndonInfo_RuleDesc.UrlParameterName:    grmi.NewConditionItem(meta.AndonInfo_RuleDesc, grmi.Equal, false),
		meta.AndonInfo_CallTime.UrlParameterName:    grmi.NewConditionItem(meta.AndonInfo_CallTime, grmi.Approximate, false),
		meta.AndonInfo_ManageTime.UrlParameterName:  grmi.NewConditionItem(meta.AndonInfo_ManageTime, grmi.Approximate, false),
		meta.AndonInfo_IsActive.UrlParameterName:    grmi.NewConditionItem(meta.AndonInfo_IsActive, grmi.Equal, false),
		meta.AndonInfo_LastModify.UrlParameterName:  grmi.NewConditionItem(meta.AndonInfo_LastModify, grmi.Approximate, false),
		meta.AndonInfo_LastUser.UrlParameterName:    grmi.NewConditionItem(meta.AndonInfo_LastUser, grmi.Equal, false),
		meta.AndonInfo_CreateTime.UrlParameterName:  grmi.NewConditionItem(meta.AndonInfo_CreateTime, grmi.Approximate, false),
	},
	nil,
)

/******************************************************************************
 *
 * @Description              : AndonInfo的默认分页查询条件
 *
 * @Author                   : 代码生成器创建
 *
 * @Date                     : 2022-01-06 14:56:42
 *
 ******************************************************************************/
var DefaultConditionOfAndonInfoAndPaging = grmi.NewCondition(
	DefaultConditionOfAndonInfo.Items,
	grmi.NewPaging(),
)

/******************************************************************************
 *
 * @Struct Name              : AndonInfoServiceImplement
 *-----------------------------------------------------------------------------
 *
 * @Description              : AndonInfo的服务实现
 *
 * @Author                   : 代码生成器创建
 *
 * @Date                     : 2022-01-06 14:56:42
 *
 ******************************************************************************/
type AndonInfoServiceImplement struct {
}

/******************************************************************************
 *
 * @Function Name            : NewAndonInfoDAOImplement
 *-----------------------------------------------------------------------------
 *
 * @Description              : 创建一个AndonInfoDAOImplement实例
 *
 * @Return Value             : AndonInfoDAOImplement实例
 *
 * @Author                   : 代码生成器创建
 *
 * @Date                     : 2022-01-06 14:56:42
 *
 ******************************************************************************/
func NewAndonInfoServiceImplement() *AndonInfoServiceImplement {
	return &AndonInfoServiceImplement{}
}

/******************************************************************************
 *
 * @Reference leit.com/LAPP_ACURA_MOM_BACKEND/services/base/AndonInfoService.InsertOne
 *
 ******************************************************************************/
func (impl *AndonInfoServiceImplement) InsertOne(user *global.User, entity *model.AndonInfo) error {

	grmi.Log(user, "/services/base/implments/AndonInfo.service.impl.go", "InsertOneAndonInfo", "插入一个AndonInfo")

	engine := db.Eloquent.Master()
	session := engine.NewSession()
	defer session.Close()
	dao := dal.NewAndonInfoDAO(session, user.UserId)
	record, err := dao.SelectOne()
	if err != nil {
		return err
	}
	if record != nil {
		return grmi.NewBusinessError("已经存在相同主键的记录!")
	}
	err = dao.InsertOne(entity)
	if err != nil {
		return err
	}
	return nil
}

/******************************************************************************
 *
 * @Reference leit.com/LAPP_ACURA_MOM_BACKEND/services/base/AndonInfoService.DeleteOne
 *
 ******************************************************************************/
func (impl *AndonInfoServiceImplement) DeleteOne(user *global.User) error {

	grmi.Log(user, "/services/base/implments/AndonInfo.service.impl.go", "DeleteOneAndonInfo", "删除一个AndonInfo")

	engine := db.Eloquent.Master()
	session := engine.NewSession()
	defer session.Close()
	dao := dal.NewAndonInfoDAO(session, user.UserId)
	record, err := dao.SelectOne()
	if err != nil {
		return err
	}
	if record == nil {
		return grmi.NewBusinessError("不存在指定记录!")
	}
	err = dao.DeleteOne()
	if err != nil {
		return err
	}
	return nil
}

/******************************************************************************
 *
 * @Reference leit.com/LAPP_ACURA_MOM_BACKEND/services/base/AndonInfoService.SelectOne
 *
 ******************************************************************************/
func (impl *AndonInfoServiceImplement) SelectOne(user *global.User) (*model.AndonInfo, error) {

	grmi.Log(user, "/services/base/implments/AndonInfo.service.impl.go", "SelectOneAndonInfo", "查询一个AndonInfo")

	engine := db.Eloquent.Master()
	session := engine.NewSession()
	defer session.Close()
	dao := dal.NewAndonInfoDAO(session, user.UserId)
	result, err := dao.SelectOne()
	if err != nil {
		return nil, err
	}
	return result, nil
}

/******************************************************************************
 *
 * @Reference leit.com/LAPP_ACURA_MOM_BACKEND/services/base/AndonInfoService.UpdateOne
 *
 ******************************************************************************/
func (impl *AndonInfoServiceImplement) UpdateOne(user *global.User, entity *model.AndonInfo) error {

	grmi.Log(user, "/services/base/implments/AndonInfo.service.impl.go", "UpdateOneAndonInfo", "修改一个AndonInfo")

	engine := db.Eloquent.Master()
	session := engine.NewSession()
	defer session.Close()
	dao := dal.NewAndonInfoDAO(session, user.UserId)
	record, err := dao.SelectOne()
	if err != nil {
		return err
	}
	if record == nil {
		return grmi.NewBusinessError("不存在指定记录!")
	}
	err = dao.UpdateOne(entity)
	if err != nil {
		return err
	}
	return nil
}

/******************************************************************************
 *
 * @Reference leit.com/LAPP_ACURA_MOM_BACKEND/services/base/AndonInfoService.Insert
 *
 ******************************************************************************/
func (impl *AndonInfoServiceImplement) Insert(user *global.User, entities *[]model.AndonInfo) error {

	grmi.Log(user, "/services/base/implments/AndonInfo.service.impl.go", "InsertAndonInfo", "插入多个AndonInfo")

	engine := db.Eloquent.Master()
	session := engine.NewSession()
	defer session.Close()
	dao := dal.NewAndonInfoDAO(session, user.UserId)

	err := dao.Insert(entities)
	if err != nil {
		return err
	}
	return nil
}

/******************************************************************************
 *
 * @Reference leit.com/LAPP_ACURA_MOM_BACKEND/services/base/AndonInfoService.Delete
 *
 ******************************************************************************/
func (impl *AndonInfoServiceImplement) Delete(user *global.User, entities *[]model.AndonInfo) error {

	grmi.Log(user, "/services/base/implments/AndonInfo.service.impl.go", "DeleteAndonInfo", "删除多个AndonInfo")

	engine := db.Eloquent.Master()
	session := engine.NewSession()
	defer session.Close()
	dao := dal.NewAndonInfoDAO(session, user.UserId)
	err := dao.Delete(entities)
	if err != nil {
		return err
	}
	return nil
}

/******************************************************************************
 *
 * @Reference leit.com/LAPP_ACURA_MOM_BACKEND/services/base/AndonInfoService.Select
 *
 ******************************************************************************/
func (impl *AndonInfoServiceImplement) Select(user *global.User, urlParameters map[string]string) ([]model.AndonInfo, error) {

	grmi.Log(user, "/services/base/implments/AndonInfo.service.impl.go", "SelectAndonInfo", "查询AndonInfo")

	condition := DefaultConditionOfAndonInfoAndPaging
	engine := db.Eloquent.Master()
	session := engine.NewSession()
	defer session.Close()
	predicates, err := condition.BuildPredicates(urlParameters)
	if err != nil {
		return nil, err
	}
	dao := dal.NewAndonInfoDAO(session, user.UserId)
	result, err := dao.Select(predicates, condition.OrderByFields)
	if err != nil {
		return nil, err
	}
	return result, nil
}

/******************************************************************************
 *
 * @Reference leit.com/LAPP_ACURA_MOM_BACKEND/services/base/AndonInfoService.SelectAndPaging
 *
 ******************************************************************************/
func (impl *AndonInfoServiceImplement) SelectAndPaging(user *global.User, urlParameters map[string]string) (grmi.PagingResult, error) {

	grmi.Log(user, "/services/base/implments/AndonInfo.service.impl.go", "SelectAndonInfo", "查询AndonInfo")

	condition := DefaultConditionOfAndonInfoAndPaging
	engine := db.Eloquent.Master()
	session := engine.NewSession()
	defer session.Close()
	predicates, err := condition.BuildPredicates(urlParameters)
	if err != nil {
		return grmi.EmptyPagingResult, err
	}
	dao := dal.NewAndonInfoDAO(session, user.UserId)
	condition.Fill(urlParameters)
	result, err := dao.SelectAndPaging(condition.Paging, predicates, condition.OrderByFields)
	if err != nil {
		return grmi.EmptyPagingResult, err
	}
	return result, nil
}

/******************************************************************************
 *
 * @Reference leit.com/LAPP_ACURA_MOM_BACKEND/services/base/AndonInfoService.Update
 *
 ******************************************************************************/
func (impl *AndonInfoServiceImplement) Update(user *global.User, entities *[]model.AndonInfo) error {

	grmi.Log(user, "/services/base/implments/AndonInfo.service.impl.go", "UpdateAndonInfo", "修改多个AndonInfo")

	engine := db.Eloquent.Master()
	session := engine.NewSession()
	defer session.Close()
	dao := dal.NewAndonInfoDAO(session, user.UserId)

	err := dao.Update(entities)
	if err != nil {
		return err
	}
	return nil
}
