From 493ad64a1f17ceeb70ec834162a0ad3572d28d69 Mon Sep 17 00:00:00 2001
From: wangpengfei <274878379@qq.com>
Date: 星期五, 11 八月 2023 11:44:16 +0800
Subject: [PATCH] Merge branch 'master' into fly

---
 model/serviceContract.go            |    4 
 api/v1/serviceOrderStatus.go        |  112 ++++++++++++
 model/serviceOrder.go               |   80 ++++----
 model/interface.go                  |   13 +
 api/v1/serviceContract.go           |   17 +
 model/request/serviceOrderStatus.go |   22 ++
 service/serviceOrderStatus.go       |   75 ++++++++
 model/serviceOrderStatus.go         |  145 ++++++++++++++++
 router/serviceOrderStatus.go        |   17 +
 constvar/serviceOrderStatus.go      |   12 +
 10 files changed, 449 insertions(+), 48 deletions(-)

diff --git a/api/v1/serviceContract.go b/api/v1/serviceContract.go
index d354aa2..bd10717 100644
--- a/api/v1/serviceContract.go
+++ b/api/v1/serviceContract.go
@@ -6,6 +6,7 @@
 	"aps_crm/model/response"
 	"aps_crm/pkg/contextx"
 	"aps_crm/pkg/ecode"
+	"aps_crm/pkg/structx"
 	"github.com/gin-gonic/gin"
 )
 
@@ -26,13 +27,13 @@
 		return
 	}
 
-	errCode, serviceContract := checkServiceContractParams(params.ServiceContract)
-	if errCode != ecode.OK {
-		ctx.Fail(errCode)
+	serviceContract := new(model.ServiceContract)
+	if err := structx.AssignTo(params, serviceContract); err != nil {
+		ctx.Fail(ecode.ParamsErr)
 		return
 	}
 
-	errCode = serviceContractService.AddServiceContract(&serviceContract)
+	errCode := serviceContractService.AddServiceContract(serviceContract)
 	if errCode != ecode.OK {
 		ctx.Fail(errCode)
 		return
@@ -80,15 +81,15 @@
 		return
 	}
 
-	errCode, serviceContract := checkServiceContractParams(params.ServiceContract)
-	if errCode != ecode.OK {
-		ctx.Fail(errCode)
+	serviceContract := new(model.ServiceContract)
+	if err := structx.AssignTo(params, serviceContract); err != nil {
+		ctx.Fail(ecode.ParamsErr)
 		return
 	}
 
 	serviceContract.Id = params.Id
 
-	errCode = serviceContractService.UpdateServiceContract(&serviceContract)
+	errCode := serviceContractService.UpdateServiceContract(serviceContract)
 	if errCode != ecode.OK {
 		ctx.Fail(errCode)
 		return
diff --git a/api/v1/serviceOrderStatus.go b/api/v1/serviceOrderStatus.go
new file mode 100644
index 0000000..4a5e8c4
--- /dev/null
+++ b/api/v1/serviceOrderStatus.go
@@ -0,0 +1,112 @@
+package v1
+
+import (
+	"aps_crm/model/request"
+	"aps_crm/model/response"
+	"aps_crm/pkg/contextx"
+	"aps_crm/pkg/ecode"
+	"aps_crm/service"
+	"github.com/gin-gonic/gin"
+	"strconv"
+)
+
+type ServiceOrderStatusApi struct{}
+
+// Add
+// @Tags    鏈嶅姟鍗曠姸鎬�
+// @Summary	娣诲姞鏈嶅姟鍗曠姸鎬�
+// @Produce	application/json
+// @Param		object	body		request.AddServiceOrderStatus	true	"鏌ヨ鍙傛暟"
+// @Success	200		{object}	contextx.Response{}
+// @Router		/api/serviceOrderStatus/add [post]
+func (s *ServiceOrderStatusApi) Add(c *gin.Context) {
+	var params request.AddServiceOrderStatus
+	ctx, ok := contextx.NewContext(c, &params)
+	if !ok {
+		return
+	}
+
+	errCode := service.NewServiceOrderStatusService().AddServiceOrderStatus(&params.ServiceOrderStatus)
+	if errCode != ecode.OK {
+		ctx.Fail(errCode)
+		return
+	}
+
+	ctx.Ok()
+}
+
+// Delete
+// @Tags		鏈嶅姟鍗曠姸鎬�
+// @Summary	鍒犻櫎鏈嶅姟鍗曠姸鎬�
+// @Produce	application/json
+// @Param		id	path		int	true	"鏌ヨ鍙傛暟"
+// @Success	200	{object}	contextx.Response{}
+// @Router		/api/serviceOrderStatus/delete/{id} [delete]
+func (s *ServiceOrderStatusApi) Delete(c *gin.Context) {
+	ctx, ok := contextx.NewContext(c, nil)
+	if !ok {
+		return
+	}
+
+	id, _ := strconv.Atoi(c.Param("id"))
+	errCode := service.NewServiceOrderStatusService().DeleteServiceOrderStatus(id)
+	if errCode != ecode.OK {
+		ctx.Fail(errCode)
+		return
+	}
+
+	ctx.Ok()
+}
+
+// Update
+// @Tags		鏈嶅姟鍗曠姸鎬�
+// @Summary	鏇存柊鏈嶅姟鍗曠姸鎬�
+// @Produce	application/json
+// @Param		object	body		request.UpdateServiceOrderStatus	true	"鏌ヨ鍙傛暟"
+// @Success	200		{object}	contextx.Response{}
+// @Router		/api/serviceOrderStatus/update [put]
+func (s *ServiceOrderStatusApi) Update(c *gin.Context) {
+	var params request.UpdateServiceOrderStatus
+	ctx, ok := contextx.NewContext(c, &params)
+	if !ok {
+		return
+	}
+    if params.Id == 0 {
+        ctx.Fail(ecode.ParamsErr)
+    }
+    params.ServiceOrderStatus.Id = params.Id
+
+	errCode := service.NewServiceOrderStatusService().UpdateServiceOrderStatus(&params.ServiceOrderStatus)
+	if errCode != ecode.OK {
+		ctx.Fail(errCode)
+		return
+	}
+
+	ctx.Ok()
+}
+
+// List
+// @Tags		鏈嶅姟鍗曠姸鎬�
+// @Summary	鑾峰彇鏈嶅姟鍗曠姸鎬佸垪琛�
+// @Produce	application/json
+// @Param		object	query		request.GetServiceOrderStatusList	true	"鍙傛暟"
+// @Success	200	{object}	response.ListResponse{data=[]model.ServiceOrderStatus}
+// @Router		/api/serviceOrderStatus/list [get]
+func (s *ServiceOrderStatusApi) List(c *gin.Context) {
+	var params request.GetServiceOrderStatusList
+	ctx, ok := contextx.NewContext(c, &params)
+	if !ok {
+		return
+	}
+
+	serviceOrderStatus, total, errCode := service.NewServiceOrderStatusService().GetServiceOrderStatusList()
+	if errCode != ecode.OK {
+		ctx.Fail(errCode)
+		return
+	}
+
+	ctx.OkWithDetailed(response.ListResponse{
+		Data: serviceOrderStatus,
+		Count: total,
+	})
+}
diff --git a/constvar/serviceOrderStatus.go b/constvar/serviceOrderStatus.go
new file mode 100644
index 0000000..0085b8b
--- /dev/null
+++ b/constvar/serviceOrderStatus.go
@@ -0,0 +1,12 @@
+package constvar
+type ServiceOrderStatusQueryClass string
+
+const (
+	ServiceOrderStatusQueryClassExpireLessThen60Days ServiceOrderStatusQueryClass = ""
+)
+
+type ServiceOrderStatusKeywordType string
+
+const (
+	ServiceOrderStatusKeywordCustomerName   ServiceOrderStatusKeywordType = ""
+)
diff --git a/model/interface.go b/model/interface.go
new file mode 100644
index 0000000..c7b70d4
--- /dev/null
+++ b/model/interface.go
@@ -0,0 +1,13 @@
+package model
+
+import (
+	"github.com/shopspring/decimal"
+	"gorm.io/gorm"
+)
+
+type MoneyAdder interface {
+	AmountReceivableAdd(*gorm.DB, decimal.Decimal)
+	AmountReceivedAdd(*gorm.DB, decimal.Decimal)
+	AmountInvoicedAdd(*gorm.DB, decimal.Decimal)
+	AmountNotInvoicedAdd(*gorm.DB, decimal.Decimal)
+}
diff --git a/model/request/serviceOrderStatus.go b/model/request/serviceOrderStatus.go
new file mode 100644
index 0000000..7a4a71d
--- /dev/null
+++ b/model/request/serviceOrderStatus.go
@@ -0,0 +1,22 @@
+package request
+
+import (
+    "aps_crm/constvar"
+    "aps_crm/model"
+)
+
+type AddServiceOrderStatus struct {
+	model.ServiceOrderStatus
+}
+
+type UpdateServiceOrderStatus struct {
+	Id int `json:"id"`
+	model.ServiceOrderStatus
+}
+
+type GetServiceOrderStatusList struct {
+	PageInfo
+	QueryClass  constvar.ServiceOrderStatusQueryClass  `json:"queryClass" form:"queryClass"`
+	KeywordType constvar.ServiceOrderStatusKeywordType `json:"keywordType"  form:"keywordType"`
+	Keyword     string                       `json:"keyword" form:"keyword"`
+}
diff --git a/model/serviceContract.go b/model/serviceContract.go
index 0b64a4f..94acee1 100644
--- a/model/serviceContract.go
+++ b/model/serviceContract.go
@@ -18,6 +18,7 @@
 		Number                  string                `json:"number" gorm:"column:number;type:varchar(255);comment:鍚堝悓缂栧彿"`
 		MemberId                int                   `json:"memberId" gorm:"column:member_id;type:int;comment:璐熻矗浜篿d"`
 		ContactId               int                   `json:"contactId" gorm:"column:contact_id;type:int;comment:鑱旂郴浜篿d"`
+		Contact                 Contact               `json:"contact" gorm:"foreignKey:ContactId"`
 		SaleChanceId            int                   `json:"saleChanceId" gorm:"column:sale_chance_id;type:int;comment:閿�鍞満浼歩d"`
 		SaleChance              SaleChance            `json:"SaleChance" gorm:"foreignKey:SaleChanceId"`
 		SalesDetailsId          int                   `json:"salesDetailsId" gorm:"column:sales_details_id;type:int;comment:鍚堝悓璁㈠崟id"`
@@ -115,7 +116,8 @@
 			Preload("Products").
 			Preload("Client").
 			Preload("ServiceContractType").
-			Preload("ServiceContractStatus")
+			Preload("ServiceContractStatus").
+			Preload("Contact")
 	}
 
 	return db
diff --git a/model/serviceOrder.go b/model/serviceOrder.go
index 53fea15..528b730 100644
--- a/model/serviceOrder.go
+++ b/model/serviceOrder.go
@@ -5,6 +5,7 @@
 	"aps_crm/pkg/mysqlx"
 	"errors"
 	"fmt"
+	"github.com/shopspring/decimal"
 	"gorm.io/gorm"
 	"gorm.io/gorm/clause"
 )
@@ -12,45 +13,46 @@
 type (
 	// ServiceOrder 鏈嶅姟鍗�
 	ServiceOrder struct {
-		Id              int           `json:"id" gorm:"column:id;primary_key;AUTO_INCREMENT"`
-		ServiceNumber   string        `gorm:"column:service_number;type:varchar(255);not null;default:'';comment:'鏈嶅姟鍗曠紪鍙�'" json:"serviceNumber"` // 鏈嶅姟鍗曠紪鍙�
-		ClientId        int           `gorm:"column:client_id;type:int;not null;default:0;comment:'瀹㈡埛id'" json:"clientId"`                      // 瀹㈡埛id
-		Client          Client        `gorm:"foreignKey:ClientId"`
-		ContractId      int           `gorm:"column:contract_id;type:int;not null;default:0;comment:'鍚堝悓id'" json:"contractId"` // 鍚堝悓id
-		Contract        Contract      `gorm:"foreignKey:ContractId"`
-		OrderId         int           `gorm:"column:order_id;type:int;not null;default:0;comment:'閿�鍞鍗昳d'" json:"orderId"` // 閿�鍞鍗昳d
-		OrderManage     OrderManage   `gorm:"foreignKey:OrderId"`
-		Subject         string        `gorm:"column:subject;type:varchar(255);not null;default:'';comment:'涓婚'" json:"subject"` // 涓婚
-		ProductId       int           `gorm:"column:product_id;type:int;not null;default:0;comment:'浜у搧id'" json:"productId"`    // 浜у搧id
-		Product         Product       `gorm:"foreignKey:ProductId"`
-		ServiceTypeId   int           `gorm:"column:service_type_id;type:int;not null;default:0;comment:'鏈嶅姟鏂瑰紡id'" json:"serviceTypeId"` // 鏈嶅姟鏂瑰紡id
-		ServiceType     ServiceType   `gorm:"foreignKey:ServiceTypeId"`
-		ServiceManId    int           `gorm:"column:service_man_id;type:int;not null;default:0;comment:'鏈嶅姟浜哄憳'" json:"serviceManId"` // 鏈嶅姟浜哄憳
-		ContactId       int           `gorm:"linkman_id" json:"contactId"`                                                          // 鑱旂郴浜篿d
-		Contact         Contact       `gorm:"foreignKey:ContactId"`
-		Address         string        `gorm:"column:address;type:varchar(255);not null;default:'';comment:'涓婇棬鍦板潃'" json:"address"`           // 涓婇棬鍦板潃
-		PriorityLevelId int           `gorm:"column:priority_level_id;type:int;not null;default:0;comment:'浼樺厛绾у埆id'" json:"priorityLevelId"` // 浼樺厛绾у埆id
-		PriorityLevel   PriorityLevel `gorm:"foreignKey:PriorityLevelId"`
-		AppointmentTime string        `gorm:"appointment_time" json:"appointmentTime"`                                                // 棰勭害涓婇棬鏃堕棿
-		SaleChanceId    int           `gorm:"column:sale_chance_id;type:int;not null;default:0;comment:'閿�鍞満浼歩d'" json:"saleChanceId"` // 閿�鍞満浼歩d
-		SaleChance      SaleChance    `gorm:"foreignKey:SaleChanceId"`
-		FaultTypeId     int           `gorm:"column:severity_id;type:int;not null;default:0;comment:'鏁呴殰绫诲埆id'" json:"faultTypeId"` // 鏁呴殰绫诲埆id
-		FaultType       FaultType     `gorm:"foreignKey:FaultTypeId"`
-		SeverityId      int           `gorm:"column:severity_id;type:int;not null;default:0;comment:'涓ラ噸绋嬪害id'" json:"severity"` // 涓ラ噸绋嬪害id
-		Severity        Severity      `gorm:"foreignKey:SeverityId"`
-		Status          int           `gorm:"status" json:"status"`                                                                        // 澶勭悊鐘舵��
-		ExpectTime      string        `gorm:"column:expect_time;type:varchar(255);not null;default:'';comment:'甯屾湜澶勭悊鏃堕棿'" json:"expectTime"` // 甯屾湜澶勭悊鏃堕棿
-		RealTime        string        `gorm:"column:real_time;type:varchar(255);not null;default:'';comment:'瀹為檯澶勭悊鏃堕棿'" json:"realTime"`     // 瀹為檯澶勭悊鏃堕棿
-		CarFare         float64       `gorm:"car_fare" json:"carFare"`                                                                     // 浜ら�氳垂
-		ChargeAmount    float64       `gorm:"charge_amount" json:"chargeAmount"`                                                           // 鏀惰垂閲戦
-		TimeSpentId     int           `gorm:"column:time_spent_id;type:int;not null;default:0;comment:'鑺辫垂鏃堕棿'" json:"timeSpentId"`          // 鑺辫垂鏃堕棿
-		TimeSpent       TimeSpent     `gorm:"foreignKey:TimeSpentId"`
-		FaqId           int           `gorm:"column:problem_id;type:int;not null;default:0;comment:'甯歌闂id'" json:"faqId"` // 甯歌闂id
-		Faq             Faq           `gorm:"foreignKey:FaqId"`
-		ProblemDesc     string        `gorm:"column:subject;type:varchar(255);not null;default:'';comment:'涓婚'problem_desc" json:"problemDesc"`  // 闂鎻忚堪
-		Solution        string        `gorm:"column:solution;type:varchar(255);not null;default:'';comment:'瑙e喅鏂规硶'" json:"solution"`              // 瑙e喅鏂规硶
-		SolutionRemark  string        `gorm:"column:solution_remark;type:varchar(255);not null;default:'';comment:'鍐呴儴澶囨敞'" json:"solutionRemark"` // 鍐呴儴澶囨敞
-		Remark          string        `gorm:"column:remark;type:varchar(255);not null;default:'';comment:'澶囨敞'" json:"remark"`                    // 澶囨敞
+		Id                   int                `json:"id" gorm:"column:id;primary_key;AUTO_INCREMENT"`
+		ServiceNumber        string             `gorm:"column:service_number;type:varchar(255);not null;default:'';comment:鏈嶅姟鍗曠紪鍙�" json:"serviceNumber"` // 鏈嶅姟鍗曠紪鍙�
+		ClientId             int                `gorm:"column:client_id;type:int;not null;default:0;comment:瀹㈡埛id" json:"clientId"`                      // 瀹㈡埛id
+		Client               Client             `gorm:"foreignKey:ClientId"`
+		ContractId           int                `gorm:"column:contract_id;type:int;not null;default:0;comment:鍚堝悓id" json:"contractId"` // 鍚堝悓id
+		Contract             Contract           `gorm:"foreignKey:ContractId"`
+		OrderId              int                `gorm:"column:order_id;type:int;not null;default:0;comment:閿�鍞鍗昳d" json:"orderId"` // 閿�鍞鍗昳d
+		OrderManage          OrderManage        `gorm:"foreignKey:OrderId"`
+		Subject              string             `gorm:"column:subject;type:varchar(255);not null;default:'';comment:涓婚" json:"subject"` // 涓婚
+		ProductId            int                `gorm:"column:product_id;type:int;not null;default:0;comment:浜у搧id" json:"productId"`    // 浜у搧id
+		Product              Product            `gorm:"foreignKey:ProductId"`
+		ServiceTypeId        int                `gorm:"column:service_type_id;type:int;not null;default:0;comment:鏈嶅姟鏂瑰紡id" json:"serviceTypeId"` // 鏈嶅姟鏂瑰紡id
+		ServiceType          ServiceType        `gorm:"foreignKey:ServiceTypeId"`
+		ServiceManId         int                `gorm:"column:service_man_id;type:int;not null;default:0;comment:鏈嶅姟浜哄憳" json:"serviceManId"` // 鏈嶅姟浜哄憳
+		ContactId            int                `gorm:"linkman_id" json:"contactId"`                                                        // 鑱旂郴浜篿d
+		Contact              Contact            `gorm:"foreignKey:ContactId"`
+		Address              string             `gorm:"column:address;type:varchar(255);not null;default:'';comment:涓婇棬鍦板潃" json:"address"`           // 涓婇棬鍦板潃
+		PriorityLevelId      int                `gorm:"column:priority_level_id;type:int;not null;default:0;comment:浼樺厛绾у埆id" json:"priorityLevelId"` // 浼樺厛绾у埆id
+		PriorityLevel        PriorityLevel      `gorm:"foreignKey:PriorityLevelId"`
+		AppointmentTime      string             `gorm:"appointment_time" json:"appointmentTime"`                                              // 棰勭害涓婇棬鏃堕棿
+		SaleChanceId         int                `gorm:"column:sale_chance_id;type:int;not null;default:0;comment:閿�鍞満浼歩d" json:"saleChanceId"` // 閿�鍞満浼歩d
+		SaleChance           SaleChance         `gorm:"foreignKey:SaleChanceId"`
+		FaultTypeId          int                `gorm:"column:severity_id;type:int;not null;default:0;comment:鏁呴殰绫诲埆id" json:"faultTypeId"` // 鏁呴殰绫诲埆id
+		FaultType            FaultType          `gorm:"foreignKey:FaultTypeId"`
+		SeverityId           int                `gorm:"column:severity_id;type:int;not null;default:0;comment:涓ラ噸绋嬪害id" json:"severity"` // 涓ラ噸绋嬪害id
+		Severity             Severity           `gorm:"foreignKey:SeverityId"`
+		ServiceOrderStatusId int                `gorm:"column:service_order_status_id;type:int;not null;default:0;comment:鏈嶅姟鍗曠姸鎬乮d" json:"status"` // 澶勭悊鐘舵��
+		ServiceOrderStatus   ServiceOrderStatus `gorm:"foreignKey:ServiceOrderStatusId"`
+		ExpectTime           string             `gorm:"column:expect_time;type:varchar(255);not null;default:'';comment:甯屾湜澶勭悊鏃堕棿" json:"expectTime"`          // 甯屾湜澶勭悊鏃堕棿
+		RealTime             string             `gorm:"column:real_time;type:varchar(255);not null;default:'';comment:瀹為檯澶勭悊鏃堕棿" json:"realTime"`              // 瀹為檯澶勭悊鏃堕棿
+		CarFare              decimal.Decimal    `gorm:"column:car_fare;type:decimal(10,2);not null;default:'0.00';comment:甯屾湜澶勭悊鏃堕棿" json:"carFare"`           //浜ら�氳垂                                                                 // 浜ら�氳垂
+		ChargeAmount         decimal.Decimal    `gorm:"column:charge_amount;type:decimal(10,2);not null;default:'0.00';comment:甯屾湜澶勭悊鏃堕棿" json:"chargeAmount"` //鏀惰垂閲戦                                                       // 鏀惰垂閲戦
+		TimeSpentId          int                `gorm:"column:time_spent_id;type:int;not null;default:0;comment:鑺辫垂鏃堕棿" json:"timeSpentId"`                   // 鑺辫垂鏃堕棿
+		TimeSpent            TimeSpent          `gorm:"foreignKey:TimeSpentId"`
+		FaqId                int                `gorm:"column:faq_id;type:int;not null;default:0;comment:甯歌闂id" json:"faqId"` // 甯歌闂id
+		Faq                  Faq                `gorm:"foreignKey:FaqId"`
+		ProblemDesc          string             `gorm:"column:problem_desc;type:varchar(255);not null;default:'';comment:涓婚" json:"problemDesc"`         // 闂鎻忚堪
+		Solution             string             `gorm:"column:solution;type:varchar(255);not null;default:'';comment:瑙e喅鏂规硶" json:"solution"`              // 瑙e喅鏂规硶
+		SolutionRemark       string             `gorm:"column:solution_remark;type:varchar(255);not null;default:'';comment:鍐呴儴澶囨敞" json:"solutionRemark"` // 鍐呴儴澶囨敞
+		Remark               string             `gorm:"column:remark;type:varchar(255);not null;default:'';comment:澶囨敞" json:"remark"`                    // 澶囨敞
 	}
 
 	// ServiceOrderSearch 鏈嶅姟鍗曟悳绱㈡潯浠�
diff --git a/model/serviceOrderStatus.go b/model/serviceOrderStatus.go
new file mode 100644
index 0000000..b4b4046
--- /dev/null
+++ b/model/serviceOrderStatus.go
@@ -0,0 +1,145 @@
+package model
+
+import (
+	"aps_crm/constvar"
+	"aps_crm/pkg/mysqlx"
+	"errors"
+	"fmt"
+	"gorm.io/gorm"
+)
+
+type (
+	// ServiceOrderStatus 鏈嶅姟鍗曠姸鎬�
+	ServiceOrderStatus struct {
+		Id   int    `json:"id" gorm:"column:id;type:int;primary_key;AUTO_INCREMENT"`
+	    Name string `json:"name" gorm:"column:name;type:varchar(255);not null;default:'';comment:鍚嶇О"`
+	}
+
+	// ServiceOrderStatusSearch 鏈嶅姟鍗曠姸鎬佹悳绱㈡潯浠�
+	ServiceOrderStatusSearch struct {
+		ServiceOrderStatus
+		Orm *gorm.DB
+        QueryClass  constvar.ServiceOrderStatusQueryClass
+        KeywordType constvar.ServiceOrderStatusKeywordType
+        Keyword     string
+        PageNum  int
+        PageSize int
+	}
+)
+
+func (ServiceOrderStatus) TableName() string {
+	return "service_order_status"
+}
+
+func NewServiceOrderStatusSearch() *ServiceOrderStatusSearch {
+	return &ServiceOrderStatusSearch{
+		Orm: mysqlx.GetDB(),
+	}
+}
+
+func (slf *ServiceOrderStatusSearch) build() *gorm.DB {
+	var db = slf.Orm.Model(&ServiceOrderStatus{})
+	if slf.Id != 0 {
+		db = db.Where("id = ?", slf.Id)
+	}
+
+	return db
+}
+
+func (slf *ServiceOrderStatusSearch) Create(record *ServiceOrderStatus) error {
+	var db = slf.build()
+	return db.Create(record).Error
+}
+
+func (slf *ServiceOrderStatusSearch) CreateBatch(records []*ServiceOrderStatus) error {
+	var db = slf.build()
+	return db.Create(records).Error
+}
+
+func (slf *ServiceOrderStatusSearch) Delete() error {
+	var db = slf.build()
+	return db.Delete(&ServiceOrderStatus{}).Error
+}
+
+func (slf *ServiceOrderStatusSearch) Update(record *ServiceOrderStatus) error {
+	var db = slf.build()
+	return db.Updates(record).Error
+}
+
+func (slf *ServiceOrderStatusSearch) FindAll() ([]*ServiceOrderStatus, error) {
+	var db = slf.build()
+	var record = make([]*ServiceOrderStatus, 0)
+	err := db.Find(&record).Error
+	return record, err
+}
+
+func (slf *ServiceOrderStatusSearch) SetId(id int) *ServiceOrderStatusSearch {
+	slf.Id = id
+	return slf
+}
+
+func (slf *ServiceOrderStatusSearch) SetPage(page, size int) *ServiceOrderStatusSearch {
+	slf.PageNum, slf.PageSize = page, size
+	return slf
+}
+
+func (slf *ServiceOrderStatusSearch) SetOrm(tx *gorm.DB) *ServiceOrderStatusSearch {
+	slf.Orm = tx
+	return slf
+}
+
+func (slf *ServiceOrderStatusSearch) First() (*ServiceOrderStatus, error) {
+	var db = slf.build()
+	var record = new(ServiceOrderStatus)
+	err := db.First(record).Error
+	return record, err
+}
+
+func (slf *ServiceOrderStatusSearch) Updates(values interface{}) error {
+	var db = slf.build()
+	return db.Updates(values).Error
+}
+
+func (slf *ServiceOrderStatusSearch) Save(record *ServiceOrderStatus) error {
+	if record.Id == 0 {
+		return errors.New("id涓虹┖")
+	}
+	var db = slf.build()
+
+	if err := db.Save(record).Error; err != nil {
+		return fmt.Errorf("save err: %v, record: %+v", err, record)
+	}
+
+	return nil
+}
+
+func (slf *ServiceOrderStatusSearch) Find() ([]*ServiceOrderStatus, int64, error) {
+	var db = slf.build()
+	var records = make([]*ServiceOrderStatus, 0)
+	var total int64
+	if err := db.Count(&total).Error; err != nil {
+		return records, total, err
+	}
+	if slf.PageNum > 0 && slf.PageSize > 0 {
+		db = db.Limit(slf.PageSize).Offset((slf.PageNum - 1) * slf.PageSize)
+	}
+
+	err := db.Find(&records).Error
+	return records, total, err
+}
+
+// InitDefaultData 鍒濆鍖栨暟鎹�
+func (slf *ServiceOrderStatusSearch) InitDefaultData() error {
+	var (
+		db          = slf.Orm.Table(slf.TableName())
+		total int64 = 0
+	)
+	if err := db.Count(&total).Error; err != nil {
+		return err
+	}
+	if total != 0 {
+		return nil
+	}
+	records := []*ServiceOrderStatus{}
+	return slf.CreateBatch(records)
+}
diff --git a/router/serviceOrderStatus.go b/router/serviceOrderStatus.go
new file mode 100644
index 0000000..db61045
--- /dev/null
+++ b/router/serviceOrderStatus.go
@@ -0,0 +1,17 @@
+package router
+
+import (
+	v1 "aps_crm/api/v1"
+	"github.com/gin-gonic/gin"
+)
+
+func InitServiceOrderStatusRouter(router *gin.RouterGroup) {
+	ServiceOrderStatusRouter := router.Group("serviceOrderStatus")
+	ServiceOrderStatusApi := v1.ServiceOrderStatusApi{}
+	{
+		ServiceOrderStatusRouter.POST("add", ServiceOrderStatusApi.Add)             // 娣诲姞鏈嶅姟鍗曠姸鎬�
+		ServiceOrderStatusRouter.DELETE("delete/:id", ServiceOrderStatusApi.Delete) // 鍒犻櫎鏈嶅姟鍗曠姸鎬�
+		ServiceOrderStatusRouter.PUT("update", ServiceOrderStatusApi.Update)        // 鏇存柊鏈嶅姟鍗曠姸鎬�
+		ServiceOrderStatusRouter.GET("list", ServiceOrderStatusApi.List)            // 鑾峰彇鏈嶅姟鍗曠姸鎬佸垪琛�
+	}
+}
diff --git a/service/serviceOrderStatus.go b/service/serviceOrderStatus.go
new file mode 100644
index 0000000..5f56782
--- /dev/null
+++ b/service/serviceOrderStatus.go
@@ -0,0 +1,75 @@
+package service
+
+import (
+	"aps_crm/model"
+	"aps_crm/model/request"
+	"aps_crm/pkg/ecode"
+)
+
+type ServiceOrderStatusService struct{}
+
+func NewServiceOrderStatusService() ServiceOrderStatusService {
+	return ServiceOrderStatusService{}
+}
+
+func (ServiceOrderStatusService) AddServiceOrderStatus(serviceOrderStatus *model.ServiceOrderStatus) int {
+	err := model.NewServiceOrderStatusSearch().Create(serviceOrderStatus)
+	if err != nil {
+		return ecode.DBErr
+	}
+
+	return ecode.OK
+}
+
+func (ServiceOrderStatusService) GetServiceOrderStatus(id int) (*model.ServiceOrderStatus, int) {
+	serviceOrderStatus, err := model.NewServiceOrderStatusSearch().SetId(id).First()
+	if err != nil {
+		return nil, ecode.DBErr
+	}
+
+	return serviceOrderStatus, ecode.OK
+}
+
+func (ServiceOrderStatusService) DeleteServiceOrderStatus(id int) int {
+	err := model.NewServiceOrderStatusSearch().SetId(id).Delete()
+	if err != nil {
+		return ecode.DBErr
+	}
+	return ecode.OK
+}
+
+func (ServiceOrderStatusService) GetServiceOrderStatusList() ([]*model.ServiceOrderStatus, int64, int) {
+	list, total, err := model.NewServiceOrderStatusSearch().Find()
+	if err != nil {
+		return nil, 0, ecode.DBErr
+	}
+
+	return list, total, ecode.OK
+}
+
+func (ServiceOrderStatusService) UpdateServiceOrderStatuss(ServiceOrderStatuss []*request.UpdateServiceOrderStatus) int {
+	for _, v := range ServiceOrderStatuss {
+		// check ServiceOrderStatus exist
+		_, err := model.NewServiceOrderStatusSearch().SetId(v.Id).First()
+		if err != nil {
+			return ecode.DBErr
+		}
+
+		err = model.NewServiceOrderStatusSearch().SetId(v.Id).Updates(map[string]interface{}{
+
+		})
+		if err != nil {
+			return ecode.DBErr
+		}
+	}
+
+	return ecode.OK
+}
+
+func (ServiceOrderStatusService) UpdateServiceOrderStatus(serviceOrderStatus *model.ServiceOrderStatus) int {
+		err := model.NewServiceOrderStatusSearch().SetId(serviceOrderStatus.Id).Save(serviceOrderStatus)
+		if err != nil {
+			return ecode.DBErr
+		}
+	return ecode.OK
+}

--
Gitblit v1.8.0