diff --git a/api/test.data/warning.go b/api/test.data/warning.go index cb921bd..2011a1a 100644 --- a/api/test.data/warning.go +++ b/api/test.data/warning.go @@ -98,3 +98,68 @@ func (S *SWarningService) Delete(c *gin.Context) { } response.OkWithData(test_data.DeleteWarning(&r), c) } + +// @Tags 数据分析平台 +// @Summary 调整报警设置信息-按测试厂 +// @Security ApiKeyAuth +// @accept application/json +// @Produce application/json +// @Param data body model.ProductionControl{} true "调整报警设置信息-按测试厂" +// @Success 200 {string} string "{"success":true,"data":{},"msg":"操作成功"}" +// @Router /testData/warning/factory [post] +func (S *SWarningService) UpdateWarningFactory(c *gin.Context) { + r := model.ProductionControl{} + _ = c.ShouldBind(&r) + if msg, ok := utils.ValidateInfo2CN(r); !ok { + response.FailWithMessage(msg, c) + return + } + if err := test_data.UpdateWarningFactory(&r); err != nil { + response.FailWithMessage(err.Error(), c) + return + } else { + response.Ok(c) + } +} + +// @Tags 数据分析平台 +// @Summary 分页查询报警设置信息-按测试厂 +// @Security ApiKeyAuth +// @accept application/json +// @Param page query int true "页数" +// @Param pageSize query int true "每页显示数量" +// @Param key_word query string false "关键词" +// @Success 200 {string} string "{"success":true,"data":{},"msg":"操作成功"}" +// @Router /testData/warning/factory [get] +func (S *SWarningService) ShowListWarningFactory(c *gin.Context) { + offset, limit, err := utils.PaginationLimitAndPage(c) + if err != nil { + response.FailWithMessage(err.Error(), c) + return + } + keyWord := c.Query("key_word") + warning, total, err := test_data.ShowListWarningFactory(offset, limit, keyWord) + if err != nil { + response.FailWithMessage(err.Error(), c) + return + } + response.OkWithData(gin.H{"warning": warning, "total": total}, c) +} + +// @Tags 数据分析平台 +// @Summary 删除报警设置信息-按测试厂 +// @Security ApiKeyAuth +// @accept application/json +// @Produce application/json +// @Param data body model.ProductionControl{} true "删除报警设置信息-按测试厂" +// @Success 200 {string} string "{"success":true,"data":{},"msg":"操作成功"}" +// @Router /testData/warning/factory [delete] +func (S *SWarningService) DeleteWarningFactory(c *gin.Context) { + r := model.ProductionControl{} + _ = c.ShouldBind(&r) + if msg, ok := utils.ValidateInfo2CN(r); !ok { + response.FailWithMessage(msg, c) + return + } + response.OkWithData(test_data.DeleteWarningFactory(&r), c) +} diff --git a/repository/test.data/warning.go b/repository/test.data/warning.go index 5ffd67f..6080b55 100644 --- a/repository/test.data/warning.go +++ b/repository/test.data/warning.go @@ -90,9 +90,52 @@ func ShowListWarning(offset, limit int, keyWord string) ([]*model.Warning, int64 func DeleteWarning(req *model.Warning) error { var warning *model.Warning - if errors.Is(global.PostGreSQL.First(&warning, req.ID).Error, gorm.ErrRecordNotFound) { + if errors.Is(global.PostGreSQL.Find(&warning, req.ID).Error, gorm.ErrRecordNotFound) { return errors.New("未找到需要删除的型号信息") } global.PostGreSQL.Delete(&warning) return nil } + +func UpdateWarningFactory(req *model.ProductionControl) error { + var warning *model.ProductionControl + if errors.Is(global.PostGreSQL.Where("factory = ?", req.Factory).Find(&warning).Error, gorm.ErrRecordNotFound) { + global.PostGreSQL.Create(&model.ProductionControl{ + Factory: req.Factory, + TestQuantityDiffH: req.TestQuantityDiffH, + TestQuantityDiffL: req.TestQuantityDiffL, + PassQuantityDiffH: req.PassQuantityDiffH, + PassQuantityDiffL: req.PassQuantityDiffL, + }) + } else { + global.PostGreSQL.Model(&req).Updates(map[string]interface{}{ + "test_quantity_diff_h": req.TestQuantityDiffH, + "test_quantity_diff_l": req.TestQuantityDiffL, + "pass_quantity_diff_h": req.PassQuantityDiffH, + "pass_quantity_diff_l": req.PassQuantityDiffL, + }) + } + return nil +} + +func ShowListWarningFactory(offset, limit int, keyWord string) ([]*model.ProductionControl, int64, error) { + var warnings []*model.ProductionControl + var total int64 + if keyWord == "" { + global.PostGreSQL.Find(&warnings). + Count(&total).Offset(offset).Limit(limit).Find(&warnings) + } else { + global.PostGreSQL.Where("factory LIKE ?", keyWord).Find(&warnings). + Count(&total).Offset(offset).Limit(limit).Find(&warnings) + } + return warnings, total, nil +} + +func DeleteWarningFactory(req *model.ProductionControl) error { + var warning *model.ProductionControl + if errors.Is(global.PostGreSQL.Find(&warning, req.ID).Error, gorm.ErrRecordNotFound) { + return errors.New("未找到需要删除的测试厂信息") + } + global.PostGreSQL.Delete(&warning) + return nil +} diff --git a/router/warning.go b/router/warning.go index 2e0dfd5..d870228 100644 --- a/router/warning.go +++ b/router/warning.go @@ -13,5 +13,8 @@ func InitWarningRouter(R *gin.RouterGroup) { warningGroup.GET("", warningService.ShowList) warningGroup.GET("selection", warningService.WarningSelection) warningGroup.DELETE("", warningService.Delete) + warningGroup.POST("factory", warningService.UpdateWarningFactory) + warningGroup.GET("factory", warningService.ShowListWarningFactory) + warningGroup.DELETE("factory", warningService.DeleteWarningFactory) } }