From 993d3555339703c53ca14103d4d7899cde0d2e04 Mon Sep 17 00:00:00 2001
From: wangpengfei <274878379@qq.com>
Date: 星期五, 21 七月 2023 11:36:05 +0800
Subject: [PATCH] add

---
 api/v1/index.go                      |    2 
 api/v1/serviceContracts.go           |    2 
 service/dataServer.go                |    5 
 router/serviceContractType.go        |   20 +
 pkg/ecode/code.go                    |    7 
 docs/swagger.yaml                    |  122 ++++++++
 model/serviceContracts.go            |    2 
 docs/docs.go                         |  194 ++++++++++++
 docs/swagger.json                    |  194 ++++++++++++
 model/response/response.go           |    8 
 service/index.go                     |    1 
 model/index.go                       |    1 
 service/serviceContractType.go       |   69 ++++
 model/serviceContractType.go         |   85 +++++
 router/index.go                      |    2 
 api/v1/serviceContractType.go        |  113 +++++++
 model/request/serviceContractType.go |   15 +
 17 files changed, 832 insertions(+), 10 deletions(-)

diff --git a/api/v1/index.go b/api/v1/index.go
index de368c7..c0462e3 100644
--- a/api/v1/index.go
+++ b/api/v1/index.go
@@ -5,6 +5,7 @@
 )
 
 type Group struct {
+    ServiceContractTypeApi
     ServiceContractStatusApi
     OrderTypeApi
     ReportSourceApi
@@ -112,4 +113,5 @@
    reportSourceService    = service.ServiceGroup.ReportSourceService
    orderTypeService    = service.ServiceGroup.OrderTypeService
    serviceContractStatusService    = service.ServiceGroup.ServiceContractStatusService
+   serviceContractTypeService    = service.ServiceGroup.ServiceContractTypeService
 )
\ No newline at end of file
diff --git a/api/v1/serviceContractType.go b/api/v1/serviceContractType.go
new file mode 100644
index 0000000..0b23d5c
--- /dev/null
+++ b/api/v1/serviceContractType.go
@@ -0,0 +1,113 @@
+
+package v1
+
+import (
+	"aps_crm/model"
+	"aps_crm/model/request"
+	"aps_crm/model/response"
+	"aps_crm/pkg/contextx"
+	"aps_crm/pkg/ecode"
+	"github.com/gin-gonic/gin"
+	"strconv"
+)
+
+type ServiceContractTypeApi struct{}
+
+// Add
+//
+//	@Tags		ServiceContractType
+//	@Summary	娣诲姞鏈嶅姟鍚堝悓绫诲瀷
+//	@Produce	application/json
+//	@Param		object	body		request.AddServiceContractType	true	"鏌ヨ鍙傛暟"
+//	@Success	200		{object}	contextx.Response{}
+//	@Router		/api/serviceContractType/add [post]
+func (s *ServiceContractTypeApi) Add(c *gin.Context) {
+	var params request.AddServiceContractType
+	ctx, ok := contextx.NewContext(c, &params)
+	if !ok {
+		return
+	}
+
+	serviceContractType := new(model.ServiceContractType)
+	serviceContractType.Name = params.Name
+
+	errCode := serviceContractTypeService.AddServiceContractType(serviceContractType)
+	if errCode != ecode.OK {
+		ctx.Fail(errCode)
+		return
+	}
+
+	ctx.Ok()
+}
+
+// Delete
+//
+//	@Tags		ServiceContractType
+//	@Summary	鍒犻櫎鏈嶅姟鍚堝悓绫诲瀷
+//	@Produce	application/json
+//	@Param		id	path		int	true	"鏌ヨ鍙傛暟"
+//	@Success	200	{object}	contextx.Response{}
+//	@Router		/api/serviceContractType/delete/{id} [delete]
+func (s *ServiceContractTypeApi) Delete(c *gin.Context) {
+	ctx, ok := contextx.NewContext(c, nil)
+	if !ok {
+		return
+	}
+
+	id, _ := strconv.Atoi(c.Param("id"))
+	errCode := serviceContractTypeService.DeleteServiceContractType(id)
+	if errCode != ecode.OK {
+		ctx.Fail(errCode)
+		return
+	}
+
+	ctx.Ok()
+}
+
+// Update
+//
+//	@Tags		ServiceContractType
+//	@Summary	鏇存柊鏈嶅姟鍚堝悓绫诲瀷
+//	@Produce	application/json
+//	@Param		object	body		request.UpdateServiceContractTypes	true	"鏌ヨ鍙傛暟"
+//	@Success	200		{object}	contextx.Response{}
+//	@Router		/api/serviceContractType/update [put]
+func (s *ServiceContractTypeApi) Update(c *gin.Context) {
+	var params request.UpdateServiceContractTypes
+	ctx, ok := contextx.NewContext(c, &params)
+	if !ok {
+		return
+	}
+
+	errCode := serviceContractTypeService.UpdateServiceContractType(params.ServiceContractTypes)
+	if errCode != ecode.OK {
+		ctx.Fail(errCode)
+		return
+	}
+
+	ctx.Ok()
+}
+
+// List
+//
+//	@Tags		ServiceContractType
+//	@Summary	鑾峰彇鏈嶅姟鍚堝悓绫诲瀷鍒楄〃
+//	@Produce	application/json
+//	@Success	200	{object}	contextx.Response{data=response.ServiceContractTypeResponse}
+//	@Router		/api/serviceContractType/list [get]
+func (s *ServiceContractTypeApi) List(c *gin.Context) {
+	ctx, ok := contextx.NewContext(c, nil)
+	if !ok {
+		return
+	}
+
+	serviceContractTypes, errCode := serviceContractTypeService.GetServiceContractTypeList()
+	if errCode != ecode.OK {
+		ctx.Fail(errCode)
+		return
+	}
+
+	ctx.OkWithDetailed(response.ServiceContractTypeResponse{
+		List: serviceContractTypes,
+	})
+}
diff --git a/api/v1/serviceContracts.go b/api/v1/serviceContracts.go
index 71461ec..b04b77d 100644
--- a/api/v1/serviceContracts.go
+++ b/api/v1/serviceContracts.go
@@ -164,7 +164,7 @@
 	result.ContactId = serviceContract.ContactId
 	result.SaleChanceId = serviceContract.SaleChanceId
 	result.QuotationId = serviceContract.QuotationId
-	result.TypeId = serviceContract.TypeId
+	result.ServiceContractTypeId = serviceContract.TypeId
 	result.ServiceContractStatusId = serviceContract.StatusId
 	result.ServiceTimes = serviceContract.ServiceTimes
 	result.Terms = serviceContract.Terms
diff --git a/docs/docs.go b/docs/docs.go
index 0fb9be2..2c7bb37 100644
--- a/docs/docs.go
+++ b/docs/docs.go
@@ -4876,6 +4876,125 @@
                 }
             }
         },
+        "/api/serviceContractType/add": {
+            "post": {
+                "produces": [
+                    "application/json"
+                ],
+                "tags": [
+                    "ServiceContractType"
+                ],
+                "summary": "娣诲姞鏈嶅姟鍚堝悓绫诲瀷",
+                "parameters": [
+                    {
+                        "description": "鏌ヨ鍙傛暟",
+                        "name": "object",
+                        "in": "body",
+                        "required": true,
+                        "schema": {
+                            "$ref": "#/definitions/request.AddServiceContractType"
+                        }
+                    }
+                ],
+                "responses": {
+                    "200": {
+                        "description": "OK",
+                        "schema": {
+                            "$ref": "#/definitions/contextx.Response"
+                        }
+                    }
+                }
+            }
+        },
+        "/api/serviceContractType/delete/{id}": {
+            "delete": {
+                "produces": [
+                    "application/json"
+                ],
+                "tags": [
+                    "ServiceContractType"
+                ],
+                "summary": "鍒犻櫎鏈嶅姟鍚堝悓绫诲瀷",
+                "parameters": [
+                    {
+                        "type": "integer",
+                        "description": "鏌ヨ鍙傛暟",
+                        "name": "id",
+                        "in": "path",
+                        "required": true
+                    }
+                ],
+                "responses": {
+                    "200": {
+                        "description": "OK",
+                        "schema": {
+                            "$ref": "#/definitions/contextx.Response"
+                        }
+                    }
+                }
+            }
+        },
+        "/api/serviceContractType/list": {
+            "get": {
+                "produces": [
+                    "application/json"
+                ],
+                "tags": [
+                    "ServiceContractType"
+                ],
+                "summary": "鑾峰彇鏈嶅姟鍚堝悓绫诲瀷鍒楄〃",
+                "responses": {
+                    "200": {
+                        "description": "OK",
+                        "schema": {
+                            "allOf": [
+                                {
+                                    "$ref": "#/definitions/contextx.Response"
+                                },
+                                {
+                                    "type": "object",
+                                    "properties": {
+                                        "data": {
+                                            "$ref": "#/definitions/response.ServiceContractTypeResponse"
+                                        }
+                                    }
+                                }
+                            ]
+                        }
+                    }
+                }
+            }
+        },
+        "/api/serviceContractType/update": {
+            "put": {
+                "produces": [
+                    "application/json"
+                ],
+                "tags": [
+                    "ServiceContractType"
+                ],
+                "summary": "鏇存柊鏈嶅姟鍚堝悓绫诲瀷",
+                "parameters": [
+                    {
+                        "description": "鏌ヨ鍙傛暟",
+                        "name": "object",
+                        "in": "body",
+                        "required": true,
+                        "schema": {
+                            "$ref": "#/definitions/request.UpdateServiceContractTypes"
+                        }
+                    }
+                ],
+                "responses": {
+                    "200": {
+                        "description": "OK",
+                        "schema": {
+                            "$ref": "#/definitions/contextx.Response"
+                        }
+                    }
+                }
+            }
+        },
         "/api/serviceFeeManage/add": {
             "post": {
                 "produces": [
@@ -7129,6 +7248,9 @@
                 "serviceContractStatusId": {
                     "type": "integer"
                 },
+                "serviceContractTypeId": {
+                    "type": "integer"
+                },
                 "serviceTimes": {
                     "type": "integer"
                 },
@@ -7140,13 +7262,21 @@
                 },
                 "terms": {
                     "type": "string"
-                },
-                "typeId": {
-                    "type": "integer"
                 }
             }
         },
         "model.ServiceContractStatus": {
+            "type": "object",
+            "properties": {
+                "id": {
+                    "type": "integer"
+                },
+                "name": {
+                    "type": "string"
+                }
+            }
+        },
+        "model.ServiceContractType": {
             "type": "object",
             "properties": {
                 "id": {
@@ -8121,6 +8251,17 @@
             }
         },
         "request.AddServiceContractStatus": {
+            "type": "object",
+            "required": [
+                "name"
+            ],
+            "properties": {
+                "name": {
+                    "type": "string"
+                }
+            }
+        },
+        "request.AddServiceContractType": {
             "type": "object",
             "required": [
                 "name"
@@ -10057,6 +10198,35 @@
                 }
             }
         },
+        "request.UpdateServiceContractType": {
+            "type": "object",
+            "required": [
+                "id",
+                "name"
+            ],
+            "properties": {
+                "id": {
+                    "type": "integer"
+                },
+                "name": {
+                    "type": "string"
+                }
+            }
+        },
+        "request.UpdateServiceContractTypes": {
+            "type": "object",
+            "required": [
+                "service_contract_type"
+            ],
+            "properties": {
+                "service_contract_type": {
+                    "type": "array",
+                    "items": {
+                        "$ref": "#/definitions/request.UpdateServiceContractType"
+                    }
+                }
+            }
+        },
         "request.UpdateServiceFeeManage": {
             "type": "object",
             "properties": {
@@ -10583,6 +10753,13 @@
                         "$ref": "#/definitions/model.ServiceContractStatus"
                     }
                 },
+                "serviceContractType": {
+                    "description": "鏈嶅姟鍚堝悓绫诲瀷",
+                    "type": "array",
+                    "items": {
+                        "$ref": "#/definitions/model.ServiceContractType"
+                    }
+                },
                 "solve_rate": {
                     "description": "瑙e喅鐜�",
                     "type": "array",
@@ -10914,6 +11091,17 @@
                 }
             }
         },
+        "response.ServiceContractTypeResponse": {
+            "type": "object",
+            "properties": {
+                "list": {
+                    "type": "array",
+                    "items": {
+                        "$ref": "#/definitions/model.ServiceContractType"
+                    }
+                }
+            }
+        },
         "response.ServiceContractsResponse": {
             "type": "object",
             "properties": {
diff --git a/docs/swagger.json b/docs/swagger.json
index cc5ad71..b95b3d4 100644
--- a/docs/swagger.json
+++ b/docs/swagger.json
@@ -4864,6 +4864,125 @@
                 }
             }
         },
+        "/api/serviceContractType/add": {
+            "post": {
+                "produces": [
+                    "application/json"
+                ],
+                "tags": [
+                    "ServiceContractType"
+                ],
+                "summary": "娣诲姞鏈嶅姟鍚堝悓绫诲瀷",
+                "parameters": [
+                    {
+                        "description": "鏌ヨ鍙傛暟",
+                        "name": "object",
+                        "in": "body",
+                        "required": true,
+                        "schema": {
+                            "$ref": "#/definitions/request.AddServiceContractType"
+                        }
+                    }
+                ],
+                "responses": {
+                    "200": {
+                        "description": "OK",
+                        "schema": {
+                            "$ref": "#/definitions/contextx.Response"
+                        }
+                    }
+                }
+            }
+        },
+        "/api/serviceContractType/delete/{id}": {
+            "delete": {
+                "produces": [
+                    "application/json"
+                ],
+                "tags": [
+                    "ServiceContractType"
+                ],
+                "summary": "鍒犻櫎鏈嶅姟鍚堝悓绫诲瀷",
+                "parameters": [
+                    {
+                        "type": "integer",
+                        "description": "鏌ヨ鍙傛暟",
+                        "name": "id",
+                        "in": "path",
+                        "required": true
+                    }
+                ],
+                "responses": {
+                    "200": {
+                        "description": "OK",
+                        "schema": {
+                            "$ref": "#/definitions/contextx.Response"
+                        }
+                    }
+                }
+            }
+        },
+        "/api/serviceContractType/list": {
+            "get": {
+                "produces": [
+                    "application/json"
+                ],
+                "tags": [
+                    "ServiceContractType"
+                ],
+                "summary": "鑾峰彇鏈嶅姟鍚堝悓绫诲瀷鍒楄〃",
+                "responses": {
+                    "200": {
+                        "description": "OK",
+                        "schema": {
+                            "allOf": [
+                                {
+                                    "$ref": "#/definitions/contextx.Response"
+                                },
+                                {
+                                    "type": "object",
+                                    "properties": {
+                                        "data": {
+                                            "$ref": "#/definitions/response.ServiceContractTypeResponse"
+                                        }
+                                    }
+                                }
+                            ]
+                        }
+                    }
+                }
+            }
+        },
+        "/api/serviceContractType/update": {
+            "put": {
+                "produces": [
+                    "application/json"
+                ],
+                "tags": [
+                    "ServiceContractType"
+                ],
+                "summary": "鏇存柊鏈嶅姟鍚堝悓绫诲瀷",
+                "parameters": [
+                    {
+                        "description": "鏌ヨ鍙傛暟",
+                        "name": "object",
+                        "in": "body",
+                        "required": true,
+                        "schema": {
+                            "$ref": "#/definitions/request.UpdateServiceContractTypes"
+                        }
+                    }
+                ],
+                "responses": {
+                    "200": {
+                        "description": "OK",
+                        "schema": {
+                            "$ref": "#/definitions/contextx.Response"
+                        }
+                    }
+                }
+            }
+        },
         "/api/serviceFeeManage/add": {
             "post": {
                 "produces": [
@@ -7117,6 +7236,9 @@
                 "serviceContractStatusId": {
                     "type": "integer"
                 },
+                "serviceContractTypeId": {
+                    "type": "integer"
+                },
                 "serviceTimes": {
                     "type": "integer"
                 },
@@ -7128,13 +7250,21 @@
                 },
                 "terms": {
                     "type": "string"
-                },
-                "typeId": {
-                    "type": "integer"
                 }
             }
         },
         "model.ServiceContractStatus": {
+            "type": "object",
+            "properties": {
+                "id": {
+                    "type": "integer"
+                },
+                "name": {
+                    "type": "string"
+                }
+            }
+        },
+        "model.ServiceContractType": {
             "type": "object",
             "properties": {
                 "id": {
@@ -8109,6 +8239,17 @@
             }
         },
         "request.AddServiceContractStatus": {
+            "type": "object",
+            "required": [
+                "name"
+            ],
+            "properties": {
+                "name": {
+                    "type": "string"
+                }
+            }
+        },
+        "request.AddServiceContractType": {
             "type": "object",
             "required": [
                 "name"
@@ -10045,6 +10186,35 @@
                 }
             }
         },
+        "request.UpdateServiceContractType": {
+            "type": "object",
+            "required": [
+                "id",
+                "name"
+            ],
+            "properties": {
+                "id": {
+                    "type": "integer"
+                },
+                "name": {
+                    "type": "string"
+                }
+            }
+        },
+        "request.UpdateServiceContractTypes": {
+            "type": "object",
+            "required": [
+                "service_contract_type"
+            ],
+            "properties": {
+                "service_contract_type": {
+                    "type": "array",
+                    "items": {
+                        "$ref": "#/definitions/request.UpdateServiceContractType"
+                    }
+                }
+            }
+        },
         "request.UpdateServiceFeeManage": {
             "type": "object",
             "properties": {
@@ -10571,6 +10741,13 @@
                         "$ref": "#/definitions/model.ServiceContractStatus"
                     }
                 },
+                "serviceContractType": {
+                    "description": "鏈嶅姟鍚堝悓绫诲瀷",
+                    "type": "array",
+                    "items": {
+                        "$ref": "#/definitions/model.ServiceContractType"
+                    }
+                },
                 "solve_rate": {
                     "description": "瑙e喅鐜�",
                     "type": "array",
@@ -10902,6 +11079,17 @@
                 }
             }
         },
+        "response.ServiceContractTypeResponse": {
+            "type": "object",
+            "properties": {
+                "list": {
+                    "type": "array",
+                    "items": {
+                        "$ref": "#/definitions/model.ServiceContractType"
+                    }
+                }
+            }
+        },
         "response.ServiceContractsResponse": {
             "type": "object",
             "properties": {
diff --git a/docs/swagger.yaml b/docs/swagger.yaml
index ba59af5..86d519f 100644
--- a/docs/swagger.yaml
+++ b/docs/swagger.yaml
@@ -841,6 +841,8 @@
         type: integer
       serviceContractStatusId:
         type: integer
+      serviceContractTypeId:
+        type: integer
       serviceTimes:
         type: integer
       signTime:
@@ -849,10 +851,15 @@
         type: string
       terms:
         type: string
-      typeId:
-        type: integer
     type: object
   model.ServiceContractStatus:
+    properties:
+      id:
+        type: integer
+      name:
+        type: string
+    type: object
+  model.ServiceContractType:
     properties:
       id:
         type: integer
@@ -1504,6 +1511,13 @@
         type: integer
     type: object
   request.AddServiceContractStatus:
+    properties:
+      name:
+        type: string
+    required:
+    - name
+    type: object
+  request.AddServiceContractType:
     properties:
       name:
         type: string
@@ -2812,6 +2826,25 @@
     required:
     - service_contract_status
     type: object
+  request.UpdateServiceContractType:
+    properties:
+      id:
+        type: integer
+      name:
+        type: string
+    required:
+    - id
+    - name
+    type: object
+  request.UpdateServiceContractTypes:
+    properties:
+      service_contract_type:
+        items:
+          $ref: '#/definitions/request.UpdateServiceContractType'
+        type: array
+    required:
+    - service_contract_type
+    type: object
   request.UpdateServiceFeeManage:
     properties:
       business_scope:
@@ -3171,6 +3204,11 @@
         items:
           $ref: '#/definitions/model.ServiceContractStatus'
         type: array
+      serviceContractType:
+        description: 鏈嶅姟鍚堝悓绫诲瀷
+        items:
+          $ref: '#/definitions/model.ServiceContractType'
+        type: array
       solve_rate:
         description: 瑙e喅鐜�
         items:
@@ -3381,6 +3419,13 @@
       list:
         items:
           $ref: '#/definitions/model.ServiceContractStatus'
+        type: array
+    type: object
+  response.ServiceContractTypeResponse:
+    properties:
+      list:
+        items:
+          $ref: '#/definitions/model.ServiceContractType'
         type: array
     type: object
   response.ServiceContractsResponse:
@@ -6413,6 +6458,79 @@
       summary: 鏇存柊鏈嶅姟鍚堝悓鐘舵��
       tags:
       - ServiceContractStatus
+  /api/serviceContractType/add:
+    post:
+      parameters:
+      - description: 鏌ヨ鍙傛暟
+        in: body
+        name: object
+        required: true
+        schema:
+          $ref: '#/definitions/request.AddServiceContractType'
+      produces:
+      - application/json
+      responses:
+        "200":
+          description: OK
+          schema:
+            $ref: '#/definitions/contextx.Response'
+      summary: 娣诲姞鏈嶅姟鍚堝悓绫诲瀷
+      tags:
+      - ServiceContractType
+  /api/serviceContractType/delete/{id}:
+    delete:
+      parameters:
+      - description: 鏌ヨ鍙傛暟
+        in: path
+        name: id
+        required: true
+        type: integer
+      produces:
+      - application/json
+      responses:
+        "200":
+          description: OK
+          schema:
+            $ref: '#/definitions/contextx.Response'
+      summary: 鍒犻櫎鏈嶅姟鍚堝悓绫诲瀷
+      tags:
+      - ServiceContractType
+  /api/serviceContractType/list:
+    get:
+      produces:
+      - application/json
+      responses:
+        "200":
+          description: OK
+          schema:
+            allOf:
+            - $ref: '#/definitions/contextx.Response'
+            - properties:
+                data:
+                  $ref: '#/definitions/response.ServiceContractTypeResponse'
+              type: object
+      summary: 鑾峰彇鏈嶅姟鍚堝悓绫诲瀷鍒楄〃
+      tags:
+      - ServiceContractType
+  /api/serviceContractType/update:
+    put:
+      parameters:
+      - description: 鏌ヨ鍙傛暟
+        in: body
+        name: object
+        required: true
+        schema:
+          $ref: '#/definitions/request.UpdateServiceContractTypes'
+      produces:
+      - application/json
+      responses:
+        "200":
+          description: OK
+          schema:
+            $ref: '#/definitions/contextx.Response'
+      summary: 鏇存柊鏈嶅姟鍚堝悓绫诲瀷
+      tags:
+      - ServiceContractType
   /api/serviceFeeManage/add:
     post:
       parameters:
diff --git a/model/index.go b/model/index.go
index 887f1e6..1afdc62 100644
--- a/model/index.go
+++ b/model/index.go
@@ -71,6 +71,7 @@
         ReportSource{},
         OrderType{},
         ServiceContractStatus{},
+        ServiceContractType{},
 	)
 	return err
 }
\ No newline at end of file
diff --git a/model/request/serviceContractType.go b/model/request/serviceContractType.go
new file mode 100644
index 0000000..4082df8
--- /dev/null
+++ b/model/request/serviceContractType.go
@@ -0,0 +1,15 @@
+
+package request
+
+type AddServiceContractType struct {
+	Name string `  json:"name" binding:"required"`
+}
+
+type UpdateServiceContractType struct {
+	Id   int    `json:"id" binding:"required"`
+	Name string `json:"name" binding:"required"`
+}
+
+type UpdateServiceContractTypes struct {
+	ServiceContractTypes []*UpdateServiceContractType `json:"service_contract_type" binding:"required"`
+}
diff --git a/model/response/response.go b/model/response/response.go
index dc71ab1..6592a89 100644
--- a/model/response/response.go
+++ b/model/response/response.go
@@ -180,6 +180,10 @@
 
 	DataResponse struct {
 
+		// 鏈嶅姟鍚堝悓绫诲瀷
+		ServiceContractType []*model.ServiceContractType `json:"serviceContractType"`
+
+
 		// 鏈嶅姟鍚堝悓鐘舵��
 		ServiceContractStatus []*model.ServiceContractStatus `json:"serviceContractStatus"`
 
@@ -270,4 +274,8 @@
 	ServiceContractStatusResponse struct {
 		List []*model.ServiceContractStatus `json:"list"`
 	}
+
+	ServiceContractTypeResponse struct {
+		List []*model.ServiceContractType `json:"list"`
+	}
 )
\ No newline at end of file
diff --git a/model/serviceContractType.go b/model/serviceContractType.go
new file mode 100644
index 0000000..086ca06
--- /dev/null
+++ b/model/serviceContractType.go
@@ -0,0 +1,85 @@
+package model
+
+import (
+	"aps_crm/pkg/mysqlx"
+	"gorm.io/gorm"
+)
+
+type (
+	// ServiceContractType 鍟嗘満闃舵
+	ServiceContractType struct {
+		Id   int    `json:"id" gorm:"column:id;primary_key;AUTO_INCREMENT"`
+		Name string `json:"name" gorm:"column:name;type:varchar(255);comment:鍟嗘満闃舵鍚嶇О"`
+	}
+   
+	ServiceContractTypeSearch struct {
+		ServiceContractType
+		Orm *gorm.DB
+	}
+)
+
+func (ServiceContractType) TableName() string {
+	return "service_contract_type"
+}
+
+func NewServiceContractTypeSearch() *ServiceContractTypeSearch {
+	return &ServiceContractTypeSearch{
+		Orm: mysqlx.GetDB(),
+	}
+}
+
+func (slf *ServiceContractTypeSearch) build() *gorm.DB {
+	var db = slf.Orm.Model(&ServiceContractType{})
+	if slf.Id != 0 {
+		db = db.Where("id = ?", slf.Id)
+	}
+	if slf.Name != "" {
+		db = db.Where("name = ?", slf.Name)
+	}
+
+	return db
+}
+
+func (slf *ServiceContractTypeSearch) Create(record *ServiceContractType) error {
+	var db = slf.build()
+	return db.Create(record).Error
+}
+
+func (slf *ServiceContractTypeSearch) Delete() error {
+	var db = slf.build()
+	return db.Delete(&ServiceContractType{}).Error
+}
+
+func (slf *ServiceContractTypeSearch) Update(record *ServiceContractType) error {
+	var db = slf.build()
+	return db.Updates(record).Error
+}
+
+func (slf *ServiceContractTypeSearch) Find() (*ServiceContractType, error) {
+	var db = slf.build()
+	var record = new(ServiceContractType)
+	err := db.First(record).Error
+	return record, err
+}
+
+func (slf *ServiceContractTypeSearch) FindAll() ([]*ServiceContractType, error) {
+	var db = slf.build()
+	var records = make([]*ServiceContractType, 0)
+	err := db.Find(&records).Error
+	return records, err
+}
+
+func (slf *ServiceContractTypeSearch) SetId(id int) *ServiceContractTypeSearch {
+	slf.Id = id
+	return slf
+}
+
+func (slf *ServiceContractTypeSearch) SetName(name string) *ServiceContractTypeSearch {
+	slf.Name = name
+	return slf
+}
+
+func (slf *ServiceContractTypeSearch) Updates(data map[string]interface{}) error {
+	var db = slf.build()
+	return db.Updates(data).Error
+}
diff --git a/model/serviceContracts.go b/model/serviceContracts.go
index e4a5eac..b2930ad 100644
--- a/model/serviceContracts.go
+++ b/model/serviceContracts.go
@@ -16,7 +16,7 @@
 		SaleChanceId            int       `json:"saleChanceId" gorm:"column:sale_chance_id;type:int;comment:閿�鍞満浼歩d"`
 		ContractId              int       `json:"contractId" gorm:"column:contract_id;type:int;comment:鍚堝悓id"`
 		QuotationId             int       `json:"quotationId" gorm:"column:quotation_id;type:int;comment:鎶ヤ环鍗昳d"`
-		TypeId                  int       `json:"typeId" gorm:"column:type_id;type:int;comment:鍚堝悓绫诲瀷id"`
+		ServiceContractTypeId   int       `json:"serviceContractTypeId" gorm:"column:service_contract_type_id;type:int;comment:鍚堝悓绫诲瀷id"`
 		SignTime                time.Time `json:"signTime" gorm:"column:sign_time;type:datetime;comment:绛剧害鏃堕棿"`
 		StartTime               time.Time `json:"startTime" gorm:"column:start_time;type:datetime;comment:寮�濮嬫椂闂�"`
 		EndTime                 time.Time `json:"endTime" gorm:"column:end_time;type:datetime;comment:缁撴潫鏃堕棿"`
diff --git a/pkg/ecode/code.go b/pkg/ecode/code.go
index 4edaaa3..a1079f6 100644
--- a/pkg/ecode/code.go
+++ b/pkg/ecode/code.go
@@ -335,4 +335,11 @@
 	ServiceContractStatusSetErr    = 4400004 // 璁剧疆鏈嶅姟鍚堝悓鐘舵�佸け璐�
 	ServiceContractStatusUpdateErr = 4400005 // 鏇存柊鏈嶅姟鍚堝悓鐘舵�佸け璐�
 
+
+	ServiceContractTypeExist     = 4400001 // 鏈嶅姟鍚堝悓绫诲瀷宸插瓨鍦�
+	ServiceContractTypeNotExist  = 4400002 // 鏈嶅姟鍚堝悓绫诲瀷涓嶅瓨鍦�
+	ServiceContractTypeListErr   = 4400003 // 鑾峰彇鏈嶅姟鍚堝悓绫诲瀷鍒楄〃澶辫触
+	ServiceContractTypeSetErr    = 4400004 // 璁剧疆鏈嶅姟鍚堝悓绫诲瀷澶辫触
+	ServiceContractTypeUpdateErr = 4400005 // 鏇存柊鏈嶅姟鍚堝悓绫诲瀷澶辫触
+
 )
\ No newline at end of file
diff --git a/router/index.go b/router/index.go
index 4adef30..dbe8532 100644
--- a/router/index.go
+++ b/router/index.go
@@ -11,6 +11,7 @@
 )
 
 type Group struct {
+    ServiceContractTypeRouter
     ServiceContractStatusRouter
     OrderTypeRouter
     ReportSourceRouter
@@ -141,6 +142,7 @@
         routerGroup.InitReportSourceRouter(PrivateGroup)
         routerGroup.InitOrderTypeRouter(PrivateGroup)
         routerGroup.InitServiceContractStatusRouter(PrivateGroup)
+        routerGroup.InitServiceContractTypeRouter(PrivateGroup)
 	}
 	return Router
 }
\ No newline at end of file
diff --git a/router/serviceContractType.go b/router/serviceContractType.go
new file mode 100644
index 0000000..f2ad947
--- /dev/null
+++ b/router/serviceContractType.go
@@ -0,0 +1,20 @@
+
+package router
+
+import (
+	v1 "aps_crm/api/v1"
+	"github.com/gin-gonic/gin"
+)
+
+type ServiceContractTypeRouter struct{}
+
+func (s *ServiceContractTypeRouter) InitServiceContractTypeRouter(router *gin.RouterGroup) {
+	serviceContractTypeRouter := router.Group("serviceContractType")
+	serviceContractTypeApi := v1.ApiGroup.ServiceContractTypeApi
+	{
+		serviceContractTypeRouter.POST("add", serviceContractTypeApi.Add)             // 娣诲姞$CName$
+		serviceContractTypeRouter.DELETE("delete/:id", serviceContractTypeApi.Delete) // 鍒犻櫎$CName$
+		serviceContractTypeRouter.PUT("update", serviceContractTypeApi.Update)        // 鏇存柊$CName$
+		serviceContractTypeRouter.GET("list", serviceContractTypeApi.List)            // 鑾峰彇$CName$鍒楄〃
+	}
+}
\ No newline at end of file
diff --git a/service/dataServer.go b/service/dataServer.go
index d14e783..7487205 100644
--- a/service/dataServer.go
+++ b/service/dataServer.go
@@ -111,6 +111,11 @@
 	data.ServiceContractStatus = serviceContractStatusList
 
 
+	// get ServiceContractType list
+	serviceContractTypeList, _ := ServiceGroup.GetServiceContractTypeList()
+	data.ServiceContractType = serviceContractTypeList
+
+
 	errCode = ecode.OK
 
 	return
diff --git a/service/index.go b/service/index.go
index 013dce5..ec24cb1 100644
--- a/service/index.go
+++ b/service/index.go
@@ -52,6 +52,7 @@
     ReportSourceService
     OrderTypeService
     ServiceContractStatusService
+    ServiceContractTypeService
 }
 
 var ServiceGroup = new(Group)
\ No newline at end of file
diff --git a/service/serviceContractType.go b/service/serviceContractType.go
new file mode 100644
index 0000000..3416fb4
--- /dev/null
+++ b/service/serviceContractType.go
@@ -0,0 +1,69 @@
+
+package service
+
+import (
+	"aps_crm/model"
+	"aps_crm/model/request"
+	"aps_crm/pkg/ecode"
+)
+
+type ServiceContractTypeService struct{}
+
+func (ServiceContractTypeService) AddServiceContractType(serviceContractType *model.ServiceContractType) int {
+	err := model.NewServiceContractTypeSearch().Create(serviceContractType)
+	if err != nil {
+		return ecode.ServiceContractTypeExist
+	}
+
+	return ecode.OK
+}
+
+func (ServiceContractTypeService) DeleteServiceContractType(id int) int {
+	_, err := model.NewServiceContractTypeSearch().SetId(id).Find()
+	if err != nil {
+		return ecode.ServiceContractTypeNotExist
+	}
+
+	err = model.NewServiceContractTypeSearch().SetId(id).Delete()
+	if err != nil {
+		return ecode.ServiceContractTypeNotExist
+	}
+	return ecode.OK
+}
+
+func (ServiceContractTypeService) GetServiceContractTypeList() ([]*model.ServiceContractType, int) {
+	list, err := model.NewServiceContractTypeSearch().FindAll()
+	if err != nil {
+		return nil, ecode.ServiceContractTypeListErr
+	}
+
+	return list, ecode.OK
+}
+
+func (ServiceContractTypeService) UpdateServiceContractType(serviceContractTypes []*request.UpdateServiceContractType) int {
+	for _, v := range serviceContractTypes {
+		// check serviceContractType exist
+		_, err := model.NewServiceContractTypeSearch().SetId(v.Id).Find()
+		if err != nil {
+			return ecode.ServiceContractTypeNotExist
+		}
+
+		err = model.NewServiceContractTypeSearch().SetId(v.Id).Updates(map[string]interface{}{
+			"name": v.Name,
+		})
+		if err != nil {
+			return ecode.ServiceContractTypeSetErr
+		}
+	}
+
+	return ecode.OK
+}
+
+func (ServiceContractTypeService) GetServiceContractTypeDetail(id int) (*model.ServiceContractType, int) {
+	serviceContractType, err := model.NewServiceContractTypeSearch().SetId(id).Find()
+	if err != nil {
+		return nil, ecode.ServiceContractTypeNotExist
+	}
+
+	return serviceContractType, ecode.OK
+}

--
Gitblit v1.8.0