Procházet zdrojové kódy

后端: 参数配置模块,新增按分类添加参数 查询列表及详情接口

baichengfei před 4 roky
rodič
revize
703a1a5709

+ 122 - 5
src/dashoo.cn/backend/api/controllers/setting/paramset.go

@@ -5,6 +5,7 @@ import (
 	"dashoo.cn/business3/parameter"
 	"dashoo.cn/utils"
 	"encoding/json"
+	"strconv"
 )
 
 // 系统参数设置
@@ -13,11 +14,19 @@ type ParamSetController struct {
 }
 
 type ParamSerModel struct {
-	IsInvestigate     bool `json:"isInvestigate"`
-	IsGetBarCode      bool `json:"isGetBarCode"`
-	SAddLimitMonth    string  `json:"sAddLimitMonth"`
-	SFlupLastDay      int  `json:"sFlupLastDay"`
-	STestFrontDay     int  `json:"sTestFrontDay"`
+	IsInvestigate  bool   `json:"isInvestigate"`
+	IsGetBarCode   bool   `json:"isGetBarCode"`
+	SAddLimitMonth string `json:"sAddLimitMonth"`
+	SFlupLastDay   int    `json:"sFlupLastDay"`
+	STestFrontDay  int    `json:"sTestFrontDay"`
+}
+type ParamModel struct {
+	// 每次新增变量参数时在这继续添加即可
+	CategoryId  string  `json:"categoryId"`
+	ParameterId string  `json:"parameterId"`
+	YearEvaGood float64 `json:"yearEvaGood"`
+	YearEvaPass float64 `json:"yearEvaPass"`
+	IsStartEva  bool    `json:"isStartEva"`
 }
 
 // @Title 保存参数设置
@@ -102,6 +111,114 @@ func (this *ParamSetController) ParamsetCheck() {
 	this.ServeJSON()
 }
 
+// @Title 按指定分类保存参数
+// @Description 按指定分类保存参数
+// @Param	body	body	business.device.DeviceChannels	"报警项目信息"
+// @Success	200	{object} controllers.Request
+// @router /specify-cate-save-params [put]
+func (this *ParamSetController) ContractParamSetPost() {
+	var model ParamModel
+	var jsonBlob = this.Ctx.Input.RequestBody
+	json.Unmarshal(jsonBlob, &model)
+
+	AccCode := model.CategoryId
+	ParameterId := model.ParameterId
+
+	var errInfo ErrorInfo
+	if AccCode == "" || ParameterId == "" {
+		errInfo.Message = "分类参数不能为空"
+		errInfo.Code = -1
+		this.Data["json"] = &errInfo
+		this.ServeJSON()
+	}
+	var paramEntity baseparameter.Base_Parameter
+	var paramEntityList []baseparameter.Base_Parameter
+	svc := baseparameter.GetBaseparameterService(utils.DBE)
+
+	svc.DeleteParam(AccCode, model.ParameterId) //删除指定分类的所有的参数
+
+	paramEntity.Categoryid = AccCode
+	paramEntity.Parameterid = ParameterId
+	paramEntity.Createuserid, _ = utils.StrTo(this.User.Id).Int()
+	paramEntity.Createby = this.User.Realname
+
+	var sisStartEva string
+	if model.IsStartEva {
+		sisStartEva = "true"
+	} else {
+		sisStartEva = "false"
+	}
+	paramEntity.Parametercode = "isStartEva"
+	paramEntity.Parametercontent = sisStartEva
+	paramEntityList = append(paramEntityList, paramEntity)
+	// 每次新增变量参数时在这处理后继续添加即可
+
+	paramEntity.Parametercode = "yearEvaGood"
+	paramEntity.Parametercontent = strconv.FormatFloat(model.YearEvaGood, 'f', 2, 64)
+	paramEntityList = append(paramEntityList, paramEntity)
+
+	paramEntity.Parametercode = "yearEvaPass"
+	paramEntity.Parametercontent = strconv.FormatFloat(model.YearEvaPass, 'f', 2, 64)
+	paramEntityList = append(paramEntityList, paramEntity)
+
+	_, err := svc.InsertEntity(&paramEntityList)
+
+	if err == nil {
+		errInfo.Message = utils.AlertProcess("参数设置成功!")
+		errInfo.Code = 0
+		this.Data["json"] = &errInfo
+		this.ServeJSON()
+	} else {
+		errInfo.Message = utils.AlertProcess("参数设置失败!" + err.Error())
+		errInfo.Code = -2
+		this.Data["json"] = &errInfo
+		this.ServeJSON()
+	}
+}
+
+// @Title 按指定分类获取参数列表
+// @Description 读取参数
+// @Success 200 {object} []baseparameter.Base_Parameter
+// @router /param-list [get]
+func (this *ParamSetController) GetParamList() {
+	CategoryId := this.GetString("categoryId")
+	parameterId := this.GetString("parameterId")
+	var errInfo ErrorDataInfo
+	if CategoryId == "" || parameterId == "" {
+		errInfo.Message = "分类参数不能为空"
+		errInfo.Code = -1
+		this.Data["json"] = &errInfo
+		this.ServeJSON()
+	}
+	var paramEntityList []baseparameter.Base_Parameter
+	svc := baseparameter.GetBaseparameterService(utils.DBE)
+	paramEntityList = svc.GetBaseparameterbyid(CategoryId, parameterId)
+	this.Data["json"] = &paramEntityList
+	this.ServeJSON()
+}
+
+// @Title 按分类获取参数详情
+// @Description 读取参数
+// @Success 200 {object} business.device.DeviceChannels
+// @router /get-param-by-cate [get]
+func (this *ParamSetController) GetParamByCategory() {
+	CategoryId := this.GetString("categoryId")
+	parameterId := this.GetString("parameterId")
+	parameterCode := this.GetString("parameterCode")
+	var errInfo ErrorDataInfo
+	if CategoryId == "" || parameterId == "" || parameterCode == "" {
+		errInfo.Message = "分类参数不能为空"
+		errInfo.Code = -1
+		this.Data["json"] = &errInfo
+		this.ServeJSON()
+	}
+	paramSvc := baseparameter.GetBaseparameterService(utils.DBE)
+	res := paramSvc.GetBaseparameterMessage(CategoryId, parameterId, parameterCode)
+
+	this.Data["json"] = res
+	this.ServeJSON()
+}
+
 // @Title 获取是否自动打印
 // @Description 获取是否自动打印
 // @Success 200 {object} business.device.DeviceChannels