123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139 |
- package service
-
- import (
- "XT_New/models"
- "fmt"
- "github.com/jinzhu/gorm"
- "time"
- )
-
- func GetInspectionMajor(orgid int64) (inspection []*models.XtInspectionReference, err error) {
-
- err = XTReadDB().Model(&inspection).Where("org_id = ? and status = 1", orgid).Group("project_name").Order("id asc").Find(&inspection).Error
- return inspection, err
- }
-
- func GetInspectionMinor(projectid int64) (inspection []*models.XtInspectionReference, err error) {
-
- err = XTReadDB().Model(&inspection).Where("project_id = ? and status = 1", projectid).Find(&inspection).Error
- return inspection, err
- }
-
- func GetInspectionRange(id int64) (models.XtInspectionReference, error) {
- reference := models.XtInspectionReference{}
- err := XTReadDB().Model(&reference).Where("id=? and status = 1", id).Find(&reference).Error
- return reference, err
- }
-
- func SaveInspection(standard *models.XtQualityControlStandard) error {
-
- err := XTWriteDB().Create(&standard).Error
- return err
- }
-
- func GetConfigurationlist(orgid int64, limit int64, page int64) (standard []*models.QualityControlStandard, total int64, err error) {
-
- db := XTReadDB().Table("xt_quality_control_standard as x").Where("x.status =1")
- if orgid > 0 {
- db = db.Where("x.user_org_id = ?", orgid)
- }
- table := XTReadDB().Table("xt_inspection_reference as s")
- fmt.Println(table)
- offset := (page - 1) * limit
- 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).
- Joins("left join xt_inspection_reference as s on s.id = x.inspection_minor").Offset(offset).Limit(limit).Scan(&standard).Error
- return standard, total, err
- }
-
- func GetConfigurationDetail(id int64) (models.XtQualityControlStandard, error) {
- standard := models.XtQualityControlStandard{}
- err := XTReadDB().Model(&standard).Where("id=? and status = 1", id).Find(&standard).Error
- return standard, err
- }
-
- func GetAllInspectionMinor(orgid int64) (standard []*models.XtInspectionReference, err error) {
-
- err = XTReadDB().Model(&standard).Where("org_id = ? and status = 1", orgid).Find(&standard).Error
- return standard, err
- }
-
- func UpdarteConfiguration(st *models.XtQualityControlStandard, id int64) error {
-
- 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
- return err
- }
-
- func DeleteConfiguration(id int64) (err error) {
-
- err = XTWriteDB().Model(models.XtQualityControlStandard{}).Where("id=?", id).Updates(map[string]interface{}{"status": 0, "updated_time": time.Now().Unix()}).Error
- return err
- }
-
- func GetAllInspectionData(orgid int64) (*models.XtInspectionReference, error) {
- diseases := models.XtInspectionReference{}
- err := XTReadDB().Model(&diseases).Where("org_id = ? and status = 1", orgid).Find(&diseases).Error
- if err == gorm.ErrRecordNotFound {
- return nil, err
- }
- if err != nil {
- return nil, err
- }
- return &diseases, nil
- }
-
- func GetAllInspectiondatatwo(orgid int64) (reference []*models.XtInspectionReference, err error) {
-
- err = XTReadDB().Model(&reference).Where("org_id = ? and status = 1", orgid).Group("project_name").Find(&reference).Error
- return reference, err
- }
-
- func GetInspectionMajorById(marjor int64) (*models.XtCheckConfiguration, error) {
- configuration := models.XtCheckConfiguration{}
- err := XTReadDB().Model(&configuration).Where("inspection_major = ? and status =1", marjor).Find(&configuration).Error
- if err == gorm.ErrRecordNotFound {
- return nil, err
- }
- if err != nil {
- return nil, err
- }
- return &configuration, nil
- }
-
- func CreateCheckConfiguration(configuration *models.XtCheckConfiguration) error {
- err := XTWriteDB().Create(&configuration).Error
- return err
- }
-
- func GetAllCheckList(orgid int64, page int64, limit int64) (check []*models.CheckConfiguration, total int64, err error) {
-
- db := XTReadDB().Table("xt_check_configuration as x").Where("x.status =1")
- table := XTReadDB().Table("xt_inspection_reference as r")
- fmt.Println(table)
- if orgid > 0 {
- db = db.Where("x.user_org_id = ?", orgid)
- }
- offset := (page - 1) * limit
- 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).
- Joins("left join xt_inspection_reference as r on r.project_id = x.inspection_major").Offset(offset).Limit(limit).Scan(&check).Error
- return check, total, err
- }
-
- func GetCheckDetail(id int64) (models.XtCheckConfiguration, error) {
-
- configuration := models.XtCheckConfiguration{}
- err := XTReadDB().Model(&configuration).Where("id=? and status =1", id).Find(&configuration).Error
- return configuration, err
- }
-
- func UpdateCheck(con *models.XtCheckConfiguration, id int64) error {
-
- 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
- return err
- }
-
- func DeleteCheck(id int64) error {
-
- err := XTWriteDB().Model(models.XtCheckConfiguration{}).Where("id=?", id).Updates(map[string]interface{}{"status": 0, "updated_time": time.Now().Unix()}).Error
- return err
- }
|