数据分析平台 报警设置窗口-按测试厂

This commit is contained in:
jh_peng 2025-04-29 14:33:26 +08:00
parent 01d57ff848
commit 58e060805f
3 changed files with 112 additions and 1 deletions

View File

@ -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)
}

View File

@ -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
}

View File

@ -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)
}
}