123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179 |
- package new_mobile_api_controllers
-
- import (
- "XT_New/controllers"
- "XT_New/enums"
- "XT_New/models"
- "XT_New/service"
- "encoding/json"
- "fmt"
- "strconv"
- "time"
- )
-
- type CommonApiController struct {
- controllers.BaseAuthAPIController
- }
-
- func (this *CommonApiController) GetInspectionMajor() {
-
- major, err := service.GetInspectionMajor(0)
- if err != nil {
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
- return
- }
- this.ServeSuccessJSON(map[string]interface{}{
- "inspection": major,
- })
- }
-
- func (this *CommonApiController) GetInspectionMinor() {
- id, _ := this.GetInt64("id")
- minor, err := service.GetInspectionMinor(id)
- if err != nil {
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
- return
- }
- this.ServeSuccessJSON(map[string]interface{}{
- "inspection": minor,
- })
- }
-
- func (this *CommonApiController) GetInspectionRange() {
- id, _ := this.GetInt64("id")
- fmt.Println("id", id)
- inspectionRange, err := service.GetInspectionRange(id)
- if err != nil {
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
- return
- }
- this.ServeSuccessJSON(map[string]interface{}{
- "inspectionRange": inspectionRange,
- })
- }
-
- func (this *CommonApiController) SaveConfiguration() {
- adminInfo := this.GetAdminUserInfo()
- orgid := adminInfo.CurrentOrgId
- dataBody := make(map[string]interface{}, 0)
- err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
- fmt.Println("err", err)
- inspectionmajor := int64(dataBody["inspectionMajor"].(float64))
- fmt.Println("大项", inspectionmajor)
- inspectionMinor := int64(dataBody["inspectionMinor"].(float64))
- fmt.Println("小项", inspectionMinor)
- minrange := dataBody["min_range"].(string)
- fmt.Println("minragne", minrange)
- largerange := dataBody["large_range"].(string)
- fmt.Println("largerange", largerange)
- sort := dataBody["sort"].(string)
- sorts, err := strconv.ParseInt(sort, 10, 64)
- fmt.Println("sort", sort)
- standard := models.XtQualityControlStandard{
- InspectionMajor: inspectionmajor,
- InspectionMinor: inspectionMinor,
- MinRange: minrange,
- LargeRange: largerange,
- Sort: sorts,
- UserOrgId: orgid,
- Status: 1,
- CreatedTime: time.Now().Unix(),
- }
- fmt.Println(standard)
- err = service.SaveInspection(&standard)
- if err != nil {
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
- return
- }
- this.ServeSuccessJSON(map[string]interface{}{
- "standard": standard,
- })
- }
-
- func (this *CommonApiController) GetConfigurationlist() {
- limit, _ := this.GetInt64("limit")
- page, _ := this.GetInt64("page")
- adminUser := this.GetAdminUserInfo()
- orgid := adminUser.CurrentOrgId
- configurationlist, total, err := service.GetConfigurationlist(orgid, limit, page)
- if err != nil {
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
- return
- }
- this.ServeSuccessJSON(map[string]interface{}{
- "configurationlist": configurationlist,
- "total": total,
- })
- }
-
- func (this *CommonApiController) GetConfigurationDetail() {
- id, _ := this.GetInt64("id")
- fmt.Println("id是", id)
- detail, err := service.GetConfigurationDetail(id)
- if err != nil {
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
- return
- }
- this.ServeSuccessJSON(map[string]interface{}{
- "configurationdetail": detail,
- })
- }
-
- func (this *CommonApiController) GetAllInspectionminor() {
-
- minor, err := service.GetAllInspectionMinor(0)
- if err != nil {
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
- return
- }
- this.ServeSuccessJSON(map[string]interface{}{
- "minor": minor,
- })
- }
-
- func (this *CommonApiController) UpdateConfiguration() {
- id, _ := this.GetInt64("id")
- fmt.Println("id", id)
- dataBody := make(map[string]interface{}, 0)
- err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
- fmt.Println("err", err)
- inspectionmajor := int64(dataBody["inspectionMajor"].(float64))
- fmt.Println("大项", inspectionmajor)
- inspectionMinor := int64(dataBody["inspectionMinor"].(float64))
- fmt.Println("小项", inspectionMinor)
- minrange := dataBody["min_range"].(string)
- fmt.Println("minragne", minrange)
- largerange := dataBody["large_range"].(string)
- fmt.Println("largerange", largerange)
- sort := int64(dataBody["sort"].(float64))
-
- standard := models.XtQualityControlStandard{
- InspectionMajor: inspectionmajor,
- InspectionMinor: inspectionMinor,
- MinRange: minrange,
- LargeRange: largerange,
- Sort: sort,
- }
- err = service.UpdarteConfiguration(&standard, id)
- if err != nil {
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
- return
- }
- this.ServeSuccessJSON(map[string]interface{}{
- "standard": standard,
- })
- }
-
- func (this *CommonApiController) DeleteConfiguration() {
- id, _ := this.GetInt64("id")
- err := service.DeleteConfiguration(id)
- if err != nil {
- this.ServeFailJsonSend(enums.ErrorCodeDBDelete, "删除失败")
- return
- }
- returnData := make(map[string]interface{}, 0)
- returnData["msg"] = "ok"
- this.ServeSuccessJSON(returnData)
- return
- }
|