common_service.go 5.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. package service
  2. import (
  3. "XT_New/models"
  4. "fmt"
  5. "github.com/jinzhu/gorm"
  6. "time"
  7. )
  8. func GetInspectionMajor(orgid int64) (inspection []*models.XtInspectionReference, err error) {
  9. err = XTReadDB().Model(&inspection).Where("org_id = ? and status = 1", orgid).Group("project_name").Order("id asc").Find(&inspection).Error
  10. return inspection, err
  11. }
  12. func GetInspectionMinor(projectid int64) (inspection []*models.XtInspectionReference, err error) {
  13. err = XTReadDB().Model(&inspection).Where("project_id = ? and status = 1", projectid).Find(&inspection).Error
  14. return inspection, err
  15. }
  16. func GetInspectionRange(id int64) (models.XtInspectionReference, error) {
  17. reference := models.XtInspectionReference{}
  18. err := XTReadDB().Model(&reference).Where("id=? and status = 1", id).Find(&reference).Error
  19. return reference, err
  20. }
  21. func SaveInspection(standard *models.XtQualityControlStandard) error {
  22. err := XTWriteDB().Create(&standard).Error
  23. return err
  24. }
  25. func GetConfigurationlist(orgid int64, limit int64, page int64) (standard []*models.QualityControlStandard, total int64, err error) {
  26. db := XTReadDB().Table("xt_quality_control_standard as x").Where("x.status =1")
  27. if orgid > 0 {
  28. db = db.Where("x.user_org_id = ?", orgid)
  29. }
  30. table := XTReadDB().Table("xt_inspection_reference as s")
  31. fmt.Println(table)
  32. offset := (page - 1) * limit
  33. err = db.Order("x.sort asc,x.created_time desc").Group("x.id").Select("x.id,x.inspection_major,x.inspection_minor,x.min_range,x.large_range,x.sort,x.user_org_id,s.unit,s.project_name,s.item_name").Count(&total).
  34. Joins("left join xt_inspection_reference as s on s.id = x.inspection_minor").Offset(offset).Limit(limit).Scan(&standard).Error
  35. return standard, total, err
  36. }
  37. func GetConfigurationDetail(id int64) (models.XtQualityControlStandard, error) {
  38. standard := models.XtQualityControlStandard{}
  39. err := XTReadDB().Model(&standard).Where("id=? and status = 1", id).Find(&standard).Error
  40. return standard, err
  41. }
  42. func GetAllInspectionMinor(orgid int64) (standard []*models.XtInspectionReference, err error) {
  43. err = XTReadDB().Model(&standard).Where("org_id = ? and status = 1", orgid).Find(&standard).Error
  44. return standard, err
  45. }
  46. func UpdarteConfiguration(st *models.XtQualityControlStandard, id int64) error {
  47. err := XTWriteDB().Model(&st).Where("id = ?", id).Updates(map[string]interface{}{"inspection_major": st.InspectionMajor, "inspection_minor": st.InspectionMinor, "min_range": st.MinRange, "large_range": st.LargeRange, "sort": st.Sort, "updated_time": time.Now().Unix()}).Error
  48. return err
  49. }
  50. func DeleteConfiguration(id int64) (err error) {
  51. err = XTWriteDB().Model(models.XtQualityControlStandard{}).Where("id=?", id).Updates(map[string]interface{}{"status": 0, "updated_time": time.Now().Unix()}).Error
  52. return err
  53. }
  54. func GetAllInspectionData(orgid int64) (*models.XtInspectionReference, error) {
  55. diseases := models.XtInspectionReference{}
  56. err := XTReadDB().Model(&diseases).Where("org_id = ? and status = 1", orgid).Find(&diseases).Error
  57. if err == gorm.ErrRecordNotFound {
  58. return nil, err
  59. }
  60. if err != nil {
  61. return nil, err
  62. }
  63. return &diseases, nil
  64. }
  65. func GetAllInspectiondatatwo(orgid int64) (reference []*models.XtInspectionReference, err error) {
  66. err = XTReadDB().Model(&reference).Where("org_id = ? and status = 1", orgid).Group("project_name").Find(&reference).Error
  67. return reference, err
  68. }
  69. func GetInspectionMajorById(marjor int64) (*models.XtCheckConfiguration, error) {
  70. configuration := models.XtCheckConfiguration{}
  71. err := XTReadDB().Model(&configuration).Where("inspection_major = ? and status =1", marjor).Find(&configuration).Error
  72. if err == gorm.ErrRecordNotFound {
  73. return nil, err
  74. }
  75. if err != nil {
  76. return nil, err
  77. }
  78. return &configuration, nil
  79. }
  80. func CreateCheckConfiguration(configuration *models.XtCheckConfiguration) error {
  81. err := XTWriteDB().Create(&configuration).Error
  82. return err
  83. }
  84. func GetAllCheckList(orgid int64, page int64, limit int64) (check []*models.CheckConfiguration, total int64, err error) {
  85. db := XTReadDB().Table("xt_check_configuration as x").Where("x.status =1")
  86. table := XTReadDB().Table("xt_inspection_reference as r")
  87. fmt.Println(table)
  88. if orgid > 0 {
  89. db = db.Where("x.user_org_id = ?", orgid)
  90. }
  91. offset := (page - 1) * limit
  92. err = db.Group("x.id").Order("x.sort asc,x.created_time desc").Select("x.id,x.inspection_major,x.inspection_frequency,x.sort,x.user_org_id,r.project_name").Count(&total).
  93. Joins("left join xt_inspection_reference as r on r.project_id = x.inspection_major").Offset(offset).Limit(limit).Scan(&check).Error
  94. return check, total, err
  95. }
  96. func GetCheckDetail(id int64) (models.XtCheckConfiguration, error) {
  97. configuration := models.XtCheckConfiguration{}
  98. err := XTReadDB().Model(&configuration).Where("id=? and status =1", id).Find(&configuration).Error
  99. return configuration, err
  100. }
  101. func UpdateCheck(con *models.XtCheckConfiguration, id int64) error {
  102. err := XTWriteDB().Model(&con).Where("id=?", id).Updates(map[string]interface{}{"inspection_major": con.InspectionMajor, "inspection_frequency": con.InspectionFrequency, "sort": con.Sort, "updated_time": time.Now().Unix()}).Error
  103. return err
  104. }
  105. func DeleteCheck(id int64) error {
  106. err := XTWriteDB().Model(models.XtCheckConfiguration{}).Where("id=?", id).Updates(map[string]interface{}{"status": 0, "updated_time": time.Now().Unix()}).Error
  107. return err
  108. }