123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323 |
- package new_mobile_api_controllers
-
- import (
- "XT_New/controllers"
- "XT_New/enums"
- "XT_New/models"
- "XT_New/service"
- "encoding/json"
- "fmt"
- "github.com/jinzhu/gorm"
- "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
- }
-
- func (this *CommonApiController) GetAllInspectiondata() {
- adminUser := this.GetAdminUserInfo()
- orgid := adminUser.CurrentOrgId
-
- //查询该机构是否有数据
- _, errcode := service.GetAllInspectionData(orgid)
- if errcode == gorm.ErrRecordNotFound {
- inspection, err := service.GetAllInspectiondatatwo(0)
- if err != nil {
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
- return
- }
- this.ServeSuccessJSON(map[string]interface{}{
- "inspection": inspection,
- })
- } else if errcode == nil {
- inspection, err := service.GetAllInspectiondatatwo(orgid)
- if err != nil {
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
- return
- }
- this.ServeSuccessJSON(map[string]interface{}{
- "inspection": inspection,
- })
- }
-
- }
-
- func (this *CommonApiController) SaveCheckConfiguration() {
- dataBody := make(map[string]interface{}, 0)
- err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
- fmt.Println("err", err)
- adminUser := this.GetAdminUserInfo()
- orgid := adminUser.CurrentOrgId
- inspectionmajor := int64(dataBody["inspectionMajor"].(float64))
- fmt.Println("大项", inspectionmajor)
- frequency := dataBody["frequency"].(string)
- fmt.Println("凭次", frequency)
- sort := dataBody["sort"].(string)
- sorts, err := strconv.ParseInt(sort, 10, 64)
- fmt.Println("sort", sort)
- _, errcode := service.GetInspectionMajorById(inspectionmajor)
- if errcode == gorm.ErrRecordNotFound {
- configuration := models.XtCheckConfiguration{
- InspectionMajor: inspectionmajor,
- InspectionFrequency: frequency,
- Sort: sorts,
- UserOrgId: orgid,
- Status: 1,
- CreatedTime: time.Now().Unix(),
- }
- err := service.CreateCheckConfiguration(&configuration)
- if err != nil {
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
- return
- }
- this.ServeSuccessJSON(map[string]interface{}{
- "configuration": configuration,
- })
- } else if errcode == nil {
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
- return
- }
- }
-
- func (this *CommonApiController) GetAllCheckList() {
- adminUser := this.GetAdminUserInfo()
- orgid := adminUser.CurrentOrgId
- fmt.Println("org", orgid)
- page, _ := this.GetInt64("page")
- limit, _ := this.GetInt64("limit")
- checkList, total, err := service.GetAllCheckList(orgid, page, limit)
- if err != nil {
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
- return
- }
- this.ServeSuccessJSON(map[string]interface{}{
- "checklist": checkList,
- "total": total,
- })
- }
-
- func (this *CommonApiController) GetCheckdetail() {
-
- id, _ := this.GetInt64("id")
- detail, err := service.GetCheckDetail(id)
- if err != nil {
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
- return
- }
- this.ServeSuccessJSON(map[string]interface{}{
- "checkdetail": detail,
- })
- }
-
- func (this *CommonApiController) UpdateCheck() {
- id, _ := this.GetInt64("id")
- fmt.Println(id)
- dataBody := make(map[string]interface{}, 0)
- err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
- fmt.Println(err)
- inspectionmajor := int64(dataBody["inspectionMajor"].(float64))
- fmt.Println("大项", inspectionmajor)
- frequency := dataBody["frequency"].(string)
- fmt.Println("凭次", frequency)
- sort := int64(dataBody["sort"].(float64))
- fmt.Println("sort", sort)
-
- Inspection, err := service.GetInspectionMajorById(inspectionmajor)
- if Inspection.ID > 0 && Inspection.ID != id {
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
- return
- }
-
- configuration := models.XtCheckConfiguration{
- InspectionMajor: inspectionmajor,
- InspectionFrequency: frequency,
- Sort: sort,
- }
-
- err = service.UpdateCheck(&configuration, id)
- if err != nil {
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
- return
- }
- this.ServeSuccessJSON(map[string]interface{}{
- "configuration": configuration,
- })
- }
-
- func (this *CommonApiController) DeleteCheck() {
- id, _ := this.GetInt64("id")
- err := service.DeleteCheck(id)
- if err != nil {
- this.ServeFailJsonSend(enums.ErrorCodeDBDelete, "删除失败")
- return
- }
- returnData := make(map[string]interface{}, 0)
- returnData["msg"] = "ok"
- this.ServeSuccessJSON(returnData)
- return
- }
|