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

package implments

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

/******************************************************************************
 *
 * @Description              : HondaCalloffItemLst的默认查询条件
 *
 * @Author                   : 代码生成器创建
 *
 * @Date                     : 2021-11-09 13:35:31
 *
 ******************************************************************************/
var DefaultConditionOfHondaCalloffItemLst = grmi.NewCondition(
	map[string]grmi.ConditionItem{
		meta.HondaCalloffItemLst_CalloffId.UrlParameterName:       grmi.NewConditionItem(meta.HondaCalloffItemLst_CalloffId, grmi.Equal, true),
		meta.HondaCalloffItemLst_Pos.UrlParameterName:             grmi.NewConditionItem(meta.HondaCalloffItemLst_Pos, grmi.Equal, true),
		meta.HondaCalloffItemLst_CalloffDate.UrlParameterName:     grmi.NewConditionItem(meta.HondaCalloffItemLst_CalloffDate, grmi.Approximate, false),
		meta.HondaCalloffItemLst_CalloffTime.UrlParameterName:     grmi.NewConditionItem(meta.HondaCalloffItemLst_CalloffTime, grmi.Approximate, false),
		meta.HondaCalloffItemLst_PlanQty.UrlParameterName:         grmi.NewConditionItem(meta.HondaCalloffItemLst_PlanQty, grmi.Equal, false),
		meta.HondaCalloffItemLst_ConfigValue.UrlParameterName:     grmi.NewConditionItem(meta.HondaCalloffItemLst_ConfigValue, grmi.Equal, false),
		meta.HondaCalloffItemLst_ModelValue.UrlParameterName:      grmi.NewConditionItem(meta.HondaCalloffItemLst_ModelValue, grmi.Equal, false),
		meta.HondaCalloffItemLst_ColorValue.UrlParameterName:      grmi.NewConditionItem(meta.HondaCalloffItemLst_ColorValue, grmi.Equal, false),
		meta.HondaCalloffItemLst_ProductFamilyId.UrlParameterName: grmi.NewConditionItem(meta.HondaCalloffItemLst_ProductFamilyId, grmi.Equal, false),
		meta.HondaCalloffItemLst_VinNo.UrlParameterName:           grmi.NewConditionItem(meta.HondaCalloffItemLst_VinNo, grmi.Equal, false),
		meta.HondaCalloffItemLst_CtrlPara1.UrlParameterName:       grmi.NewConditionItem(meta.HondaCalloffItemLst_CtrlPara1, grmi.Equal, false),
		meta.HondaCalloffItemLst_CtrlPara2.UrlParameterName:       grmi.NewConditionItem(meta.HondaCalloffItemLst_CtrlPara2, grmi.Equal, false),
		meta.HondaCalloffItemLst_CtrlStr1.UrlParameterName:        grmi.NewConditionItem(meta.HondaCalloffItemLst_CtrlStr1, grmi.Equal, false),
		meta.HondaCalloffItemLst_CtrlStr2.UrlParameterName:        grmi.NewConditionItem(meta.HondaCalloffItemLst_CtrlStr2, grmi.Equal, false),
		meta.HondaCalloffItemLst_CtrlTime1.UrlParameterName:       grmi.NewConditionItem(meta.HondaCalloffItemLst_CtrlTime1, grmi.Approximate, false),
		meta.HondaCalloffItemLst_CtrlTime2.UrlParameterName:       grmi.NewConditionItem(meta.HondaCalloffItemLst_CtrlTime2, grmi.Approximate, false),
		meta.HondaCalloffItemLst_LastModify.UrlParameterName:      grmi.NewConditionItem(meta.HondaCalloffItemLst_LastModify, grmi.Approximate, false),
		meta.HondaCalloffItemLst_LastUser.UrlParameterName:        grmi.NewConditionItem(meta.HondaCalloffItemLst_LastUser, grmi.Equal, false),
		meta.HondaCalloffItemLst_CreateTime.UrlParameterName:      grmi.NewConditionItem(meta.HondaCalloffItemLst_CreateTime, grmi.Approximate, false),
	},
	nil,
)

/******************************************************************************
 *
 * @Description              : HondaCalloffItemLst的默认分页查询条件
 *
 * @Author                   : 代码生成器创建
 *
 * @Date                     : 2021-11-09 13:35:31
 *
 ******************************************************************************/
var DefaultConditionOfHondaCalloffItemLstAndPaging = grmi.NewCondition(
	DefaultConditionOfHondaCalloffItemLst.Items,
	grmi.NewPaging(),
)

/******************************************************************************
 *
 * @Struct Name              : HondaCalloffItemLstServiceImplement
 *-----------------------------------------------------------------------------
 *
 * @Description              : HondaCalloffItemLst的服务实现
 *
 * @Author                   : 代码生成器创建
 *
 * @Date                     : 2021-11-09 13:35:31
 *
 ******************************************************************************/
type HondaCalloffItemLstServiceImplement struct {
}

/******************************************************************************
 *
 * @Function Name            : NewHondaCalloffItemLstDAOImplement
 *-----------------------------------------------------------------------------
 *
 * @Description              : 创建一个HondaCalloffItemLstDAOImplement实例
 *
 * @Return Value             : HondaCalloffItemLstDAOImplement实例
 *
 * @Author                   : 代码生成器创建
 *
 * @Date                     : 2021-11-09 13:35:31
 *
 ******************************************************************************/
func NewHondaCalloffItemLstServiceImplement() *HondaCalloffItemLstServiceImplement {
	return &HondaCalloffItemLstServiceImplement{}
}

/******************************************************************************
 *
 * @Reference LAPP_ACURA_MOM_BACKEND/services/pln/HondaCalloffItemLstService.InsertOne
 *
 ******************************************************************************/
func (impl *HondaCalloffItemLstServiceImplement) InsertOne(user *global.User, entity *model.HondaCalloffItemLst) error {

	grmi.Log(user, "/services/pln/implments/HondaCalloffItemLst.service.impl.go", "InsertOneHondaCalloffItemLst", "插入一个HondaCalloffItemLst")

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

/******************************************************************************
 *
 * @Reference LAPP_ACURA_MOM_BACKEND/services/pln/HondaCalloffItemLstService.DeleteOne
 *
 ******************************************************************************/
func (impl *HondaCalloffItemLstServiceImplement) DeleteOne(user *global.User, calloffId string, pos int) error {

	grmi.Log(user, "/services/pln/implments/HondaCalloffItemLst.service.impl.go", "DeleteOneHondaCalloffItemLst", "删除一个HondaCalloffItemLst")

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

/******************************************************************************
 *
 * @Reference LAPP_ACURA_MOM_BACKEND/services/pln/HondaCalloffItemLstService.SelectOne
 *
 ******************************************************************************/
func (impl *HondaCalloffItemLstServiceImplement) SelectOne(user *global.User, calloffId string, pos int) (*model.HondaCalloffItemLst, error) {

	grmi.Log(user, "/services/pln/implments/HondaCalloffItemLst.service.impl.go", "SelectOneHondaCalloffItemLst", "查询一个HondaCalloffItemLst")

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

/******************************************************************************
 *
 * @Reference LAPP_ACURA_MOM_BACKEND/services/pln/HondaCalloffItemLstService.UpdateOne
 *
 ******************************************************************************/
func (impl *HondaCalloffItemLstServiceImplement) UpdateOne(user *global.User, entity *model.HondaCalloffItemLst) error {

	grmi.Log(user, "/services/pln/implments/HondaCalloffItemLst.service.impl.go", "UpdateOneHondaCalloffItemLst", "修改一个HondaCalloffItemLst")

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

/******************************************************************************
 *
 * @Reference LAPP_ACURA_MOM_BACKEND/services/pln/HondaCalloffItemLstService.Insert
 *
 ******************************************************************************/
func (impl *HondaCalloffItemLstServiceImplement) Insert(user *global.User, entities *[]model.HondaCalloffItemLst) error {

	grmi.Log(user, "/services/pln/implments/HondaCalloffItemLst.service.impl.go", "InsertHondaCalloffItemLst", "插入多个HondaCalloffItemLst")

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

	for _, entity := range *entities {
		record, err := dao.SelectOne(entity.CalloffId, entity.Pos)
		if err != nil {
			return err
		}
		if record != nil {
			return grmi.NewBusinessError("已经存在相同主键的记录!")
		}
	}

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

/******************************************************************************
 *
 * @Reference LAPP_ACURA_MOM_BACKEND/services/pln/HondaCalloffItemLstService.Delete
 *
 ******************************************************************************/
func (impl *HondaCalloffItemLstServiceImplement) Delete(user *global.User, entities *[]model.HondaCalloffItemLst) error {

	grmi.Log(user, "/services/pln/implments/HondaCalloffItemLst.service.impl.go", "DeleteHondaCalloffItemLst", "删除多个HondaCalloffItemLst")

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

	for _, entity := range *entities {
		record, err := dao.SelectOne(entity.CalloffId, entity.Pos)
		if err != nil {
			return err
		}
		if record == nil {
			return grmi.NewBusinessError("不存在指定记录!")
		}
	}

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

/******************************************************************************
 *
 * @Reference LAPP_ACURA_MOM_BACKEND/services/pln/HondaCalloffItemLstService.Select
 *
 ******************************************************************************/
func (impl *HondaCalloffItemLstServiceImplement) Select(user *global.User, urlParameters map[string]string) ([]model.HondaCalloffItemLst, error) {

	grmi.Log(user, "/services/pln/implments/HondaCalloffItemLst.service.impl.go", "SelectHondaCalloffItemLst", "查询HondaCalloffItemLst")

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

/******************************************************************************
 *
 * @Reference LAPP_ACURA_MOM_BACKEND/services/pln/HondaCalloffItemLstService.SelectAndPaging
 *
 ******************************************************************************/
func (impl *HondaCalloffItemLstServiceImplement) SelectAndPaging(user *global.User, urlParameters map[string]string) (grmi.PagingResult, error) {

	grmi.Log(user, "/services/pln/implments/HondaCalloffItemLst.service.impl.go", "SelectHondaCalloffItemLst", "查询HondaCalloffItemLst")

	condition := DefaultConditionOfHondaCalloffItemLstAndPaging
	engine := db.Eloquent.Master()
	session := engine.NewSession()
	defer session.Close()
	predicates, err := condition.BuildPredicates(urlParameters)
	if err != nil {
		return grmi.EmptyPagingResult, err
	}
	dao := dal.NewHondaCalloffItemLstDAO(session, user.PlantNr, 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 LAPP_ACURA_MOM_BACKEND/services/pln/HondaCalloffItemLstService.Update
 *
 ******************************************************************************/
func (impl *HondaCalloffItemLstServiceImplement) Update(user *global.User, entities *[]model.HondaCalloffItemLst) error {

	grmi.Log(user, "/services/pln/implments/HondaCalloffItemLst.service.impl.go", "UpdateHondaCalloffItemLst", "修改多个HondaCalloffItemLst")

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

	for _, entity := range *entities {
		record, err := dao.SelectOne(entity.CalloffId, entity.Pos)
		if err != nil {
			return err
		}
		if record == nil {
			return grmi.NewBusinessError("不存在指定记录!")
		}
	}

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