Explorar o código

数据字典
Signed-off-by: lijunqing <lijunqing@dashoo.cn>

lijunqing %!s(int64=6) %!d(string=hai) anos
pai
achega
1d0bb27df0

+ 15 - 0
src/dashoo.cn/backend/api/business/items/baseItems.go

@@ -50,3 +50,18 @@ type Base_ItemTreeDetails struct {
 	ModifiedUserId    int       `xorm:"INT(11)" form:"-" json:"-"`
 	ModifiedBy        string    `xorm:"VARCHAR(50)" form:"-" json:"-"`
 }
+
+type Base_ItemDetails_DetectionCycle struct {
+	Id                int       `xorm:"not null pk autoincr INT(10)"`
+	Name              string    `xorm:"comment('名称') VARCHAR(50)"`
+	Pid               int       `xorm:"comment('设备类型ID') INT(10)"`
+	DetectionNum      int       `xorm:"comment('检测周期数量') INT(10)"`
+	DetectionUnit     string       `xorm:"comment('检测周期单位') VARCHAR(10)"`
+	DeletionStateCode int       `xorm:"not null default 0 comment('是否删除') INT(10)"`
+	CreateOn          time.Time `xorm:"comment('创建时间') DATETIME"`
+	CreateuserId      string    `xorm:"comment('创建人ID') VARCHAR(50)"`
+	CreateBy          string    `xorm:"comment('创建人') VARCHAR(50)"`
+	ModifiedOn        time.Time `xorm:"comment('修改时间') DATETIME"`
+	ModifieduserId    string    `xorm:"comment('修改人ID') VARCHAR(50)"`
+	ModifiedBy        string    `xorm:"comment('修改人') VARCHAR(50)"`
+}

+ 120 - 0
src/dashoo.cn/backend/api/controllers/setting/items.go

@@ -3,6 +3,8 @@ package setting
 import (
 	"encoding/json"
 	"fmt"
+	"strconv"
+	"time"
 
 	"dashoo.cn/backend/api/business/items"
 	. "dashoo.cn/backend/api/controllers"
@@ -63,6 +65,124 @@ func (this *ItemsController) GetModel() {
 	this.ServeJSON()
 }
 
+// @Title 获取检测周期表信息
+// @Description 获取检测周期表信息
+// @Success 200 {object}
+// @router /getdetectionmodel [get]
+func (this *ItemsController) GetDetectionModel() {
+	svc := items.GetItemsService(utils.DBE)
+	page := this.GetPageInfoForm()
+	var entities []items.Base_ItemDetails_DetectionCycle
+	where := " 1=1 "
+	total := svc.GetPagingEntitiesWithOrder(page.CurrentPage, page.Size, "Id", false, &entities, where)
+	var datainfo DataInfo
+	datainfo.Items = entities
+	datainfo.CurrentItemCount = total
+	this.Data["json"] = &datainfo
+	this.ServeJSON()
+}
+
+// @Title 添加检测周期表信息
+// @Description 添加检测周期表信息
+// @Success 200 {object}
+// @router /adddetectionmodel [post]
+func (this *ItemsController) AddDetectionModel() {
+	var model items.Base_ItemDetails_DetectionCycle
+	var jsonblob = this.Ctx.Input.RequestBody
+	json.Unmarshal(jsonblob, &model)
+	svc := items.GetItemsService(utils.DBE)
+	var errinfo ErrorInfo
+
+	if model.Pid < 1 {
+		errinfo.Message = utils.AlertProcess("保存失败,请求信息不完整!")
+		errinfo.Code = -3
+		this.Data["json"] = &errinfo
+		this.ServeJSON()
+		return
+	}else{
+		var tempModel []items.Base_ItemDetails_DetectionCycle
+		svc.GetEntitysByWhere("Base_ItemDetails_DetectionCycle","Pid='"+strconv.Itoa(model.Pid)+"'",&tempModel)
+		if len(tempModel)>0{
+			errinfo.Message = utils.AlertProcess("保存失败,已有该类设备默认检测周期!")
+			errinfo.Code = -4
+			this.Data["json"] = &errinfo
+			this.ServeJSON()
+			return
+		}
+	}
+
+	model.CreateOn=time.Now()
+	model.CreateuserId=this.User.Id
+	model.CreateBy=this.User.Realname
+	_,err:=svc.InsertEntityBytblOne("Base_ItemDetails_DetectionCycle",&model)
+	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 = -1
+		this.Data["json"] = &errinfo
+		this.ServeJSON()
+	}
+}
+
+
+// @Title 添加检测周期表信息
+// @Description 添加检测周期表信息
+// @Success 200 {object}
+// @router /editdetectionmodel/:id [post]
+func (this *ItemsController) EditDetectionModel() {
+	id := this.Ctx.Input.Param(":id")
+	var model items.Base_ItemDetails_DetectionCycle
+	var jsonblob = this.Ctx.Input.RequestBody
+	json.Unmarshal(jsonblob, &model)
+	svc := items.GetItemsService(utils.DBE)
+	var errinfo ErrorInfo
+
+	model.ModifiedOn=time.Now()
+	model.ModifieduserId=this.User.Id
+	model.ModifiedBy=this.User.Realname
+
+	cols := []string{"DetectionUnit","DetectionNum","ModifiedOn","ModifieduserId","ModifiedBy"}
+	_,err:=svc.UpdateEntityByIdCols(id,&model,cols)
+	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 = -1
+		this.Data["json"] = &errinfo
+		this.ServeJSON()
+	}
+}
+
+// @Title 添加检测周期表信息
+// @Description 添加检测周期表信息
+// @Success 200 {object}
+// @router /deletedetectionmodel/:id [delete]
+func (this *ItemsController) DeleteDetectionModel() {
+	id := this.Ctx.Input.Param(":id")
+	var model items.Base_ItemDetails_DetectionCycle
+	svc := items.GetItemsService(utils.DBE)
+	var errinfo ErrorInfo
+
+	err:=svc.DeleteEntity(&model,"Id='"+id+"'")
+	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 = -1
+		this.Data["json"] = &errinfo
+		this.ServeJSON()
+	}
+}
 // @Title 子表添加(添加数据字典详情)
 // @Description 子表添加(添加数据字典详情)
 // @Param	body	body	business.device.DeviceChannels	"报警项目信息"

+ 350 - 0
src/dashoo.cn/frontend_web/src/pages/setting/systemitems/_opera/detectioncycleitemsdetail.vue

@@ -0,0 +1,350 @@
+<template>
+  <div>
+    <el-breadcrumb class="heading">
+      <el-breadcrumb-item :to="{ path: '/' }">平台首页</el-breadcrumb-item>
+      <el-breadcrumb-item :to="{ path: '/setting/systemitems' }">数据字典</el-breadcrumb-item>
+      <el-breadcrumb-item>数据字典详情</el-breadcrumb-item>
+    </el-breadcrumb>
+
+    <el-card class="box-card">
+      <div slot="header">
+        <span>
+          <i class="icon icon-table2"></i> 数据字典详情 {{titlename}}
+        </span>
+        <span style="float: right">
+          <el-button size="small"
+                     type="primary"
+                     @click="opendatadialog(1,null,-1)">添加设备默认检测周期</el-button>
+          <el-button type="primary"
+                     class="el-button--small"
+                     onclick="window.history.go(-1)">返回</el-button>
+        </span>
+      </div>
+
+      <el-table :data="list"
+                border
+                style="width: 100%">
+        <el-table-column label="操作"
+                         width="65">
+          <template slot-scope="scope">
+            <el-button size="small"
+                       type="text"
+                       icon="el-icon-edit"
+                       title="编辑字典"
+                       @click="opendatadialog(2,scope.row,scope.$index);"></el-button>
+            <el-button size="small"
+                       style="margin-left:3px;"
+                       type="text"
+                       icon="el-icon-delete"
+                       title="删除"
+                       @click="deletedata(scope.row)"></el-button>
+          </template>
+        </el-table-column>
+        <el-table-column prop="Name"
+                         label="设备名称"
+                         show-overflow-tooltip></el-table-column>
+        <el-table-column label="检测周期"
+                         show-overflow-tooltip>
+                          <template slot-scope="scope">
+                            {{scope.row.DetectionNum+scope.row.DetectionUnit}}
+                          </template>
+                         </el-table-column>
+      </el-table>
+    </el-card>
+
+    <el-dialog :title="dialogtitle"
+               :visible.sync="datadialogVisible">
+      <el-form :model="itemsdetailinfoform"
+              
+               ref="itemsdetailinfoform">
+        <el-form-item label="设备分类"
+                      label-width="120px" required>
+          <el-select v-model="projectTypeId"
+                     :disabled="disableFlag"
+                     @change="projectTypeChange"
+                     style="width:100%"
+                     clearable
+                     filterable
+                     placeholder="请选择设备分类" >
+            <el-option v-for="item in projectTypeList"
+                       :key="item.Id"
+                       :label="item.FullName"
+                       :value="item.Id"></el-option>
+          </el-select>
+        </el-form-item>
+
+        <el-form-item label="检测周期数值"
+                      label-width="120px" required>
+          <el-input-number v-model="itemsdetailinfoform.DetectionNum"
+                           :min="1"
+                           style="width:100%"></el-input-number>
+        </el-form-item>
+
+        <el-form-item label="检测周期单位"
+                      label-width="120px" required>
+          <el-select v-model="detectionUnit"
+                     @change="detectionUnitChange"
+                     style="width:100%"
+                     placeholder="请选择">
+            <el-option v-for="item in detectionUnitOptions"
+                       :key="item.value"
+                       :label="item.label"
+                       :value="item.value">
+            </el-option>
+          </el-select>
+        </el-form-item>
+      </el-form>
+      <div slot="footer"
+           class="dialog-footer">
+        <el-button @click="datadialogVisible = false">取 消</el-button>
+        <el-button type="primary"
+                   @click="savedata('itemsdetailinfoform')">确 定</el-button>
+      </div>
+    </el-dialog>
+
+  </div>
+
+</template>
+
+<script>
+export default {
+  name: 'itemsdetail',
+  data () {
+    return {
+      projectTypeId: '',
+      Id: 0,
+      testTypeList: [],
+      projectTypeList: [],
+      titlename: '',
+      disableFlag: false,
+      currentItemCount: 0,
+      currentPage: 1,
+      size: 10,
+      detectionUnit: '天',
+
+      detectionUnitOptions: [{
+        value: '天',
+        label: '天'
+      }, {
+        value: '月',
+        label: '月'
+      }, {
+        value: '年',
+        label: '年'
+      }],
+
+      dialogtitle: '',
+      itemsdetailinfoform: {
+        Name: '',
+        pid: 0,
+        DetectionNum: 1,
+        DetectionUnit: ''
+
+      },
+      list: [],
+      datadialogVisible: false
+      // rulesitemsdetailinfoform: {
+
+      // }
+    }
+  },
+  created () {
+    let _this = this
+    let titlename = this.$route.query.name
+    if (titlename !== undefined) {
+      this.titlename = `【字典名-${titlename}】`
+    }
+    _this.initData()
+    _this.getProjectType()
+  },
+  methods: {
+    projectTypeChange (val) {
+      let _this = this
+      _this.itemsdetailinfoform.pid = val
+      let obj = {}
+      obj = _this.projectTypeList.find((item) => {
+        return item.Id === val
+      })
+      _this.itemsdetailinfoform.Name = obj.FullName
+    },
+    detectionUnitChange (val) {
+      let _this = this
+      _this.itemsdetailinfoform.DetectionUnit = val
+    },
+    getProjectType () {
+      let _this = this
+      _this.$axios.get('/testtype/testypetreeall', {})
+        .then(res => {
+          _this.testTypeList = res.data.items
+          if (!_this.testTypeList) {
+            return false
+          }
+          for (var i = 0; i < _this.testTypeList.length; i++) {
+            if (_this.testTypeList[i].ParentId === 0) {
+              _this.projectTypeList.push(_this.testTypeList[i])
+            }
+          }
+        })
+        .catch(err => {
+          console.error(err)
+        })
+    },
+    initData () {
+      let _this = this
+      const params = { _currentPage: _this.currentPage, _size: _this.size }
+
+      _this.$axios.get('/items/getdetectionmodel/', { params })
+        .then(res => {
+          console.log(res)
+          _this.list = res.data.items
+          _this.currentItemCount = res.data.currentItemCount
+        })
+        .catch(err => {
+          console.error(err)
+        })
+    },
+    clearitemsdetailinfoform () {
+      let _this = this
+      _this.projectTypeId = ''
+      _this.detectionUnit = '天'
+      _this.itemsdetailinfoform.DetectionNum = 1
+    },
+    deletedata (val) {
+      let _this = this
+      _this.$confirm('此操作将永久删除该数据, 是否继续?', '提示', {
+        confirmButtonText: '确定',
+        cancelButtonText: '取消',
+        type: 'warning'
+      }).then(() => {
+        _this.$axios.delete('/items/deletedetectionmodel/' + val.Id, null)
+          .then(res => {
+            if (res.data.code === 0) {
+              _this.$message({
+                type: 'success',
+                message: res.data.message
+              })
+              this.initData(this.$route.params.opera)
+            } else {
+              _this.$message({
+                type: 'warning',
+                message: res.data.message
+              })
+            }
+          })
+          .catch(() => { })
+      }).catch(() => { })
+    },
+    opendatadialog (item, v, index) {
+      let _this = this
+      _this.operatingitem = item // 判断添加删除的
+      _this.datadialogVisible = true
+      _this.clearitemsdetailinfoform()
+      if (item === 1) {
+        _this.dialogtitle = '添加'
+        _this.disableFlag = false
+      } else if (item === 2) {
+        _this.dialogtitle = `编辑`
+        _this.Id = v.Id
+        _this.projectTypeId = v.Pid
+        _this.disableFlag = true
+        _this.detectionUnit = v.DetectionUnit
+
+        _this.itemsdetailinfoform.DetectionUnit = v.DetectionUnit
+        _this.itemsdetailinfoform.DetectionNum = v.DetectionNum
+      }
+    },
+    savedata (formName) {
+      let _this = this
+      this.$refs[formName].validate((valid) => {
+        if (valid) {
+          if (_this.operatingitem === 1) {
+            this.$axios.post('/items/adddetectionmodel', _this.itemsdetailinfoform)
+              .then(res => {
+                if (res.data.code === 0) {
+                  _this.$message({
+                    type: 'success',
+                    message: res.data.message
+                  })
+                  _this.datadialogVisible = false
+                  this.initData()
+                } else {
+                  _this.$message({
+                    type: 'warning',
+                    message: res.data.message
+                  })
+                }
+              })
+              .catch(err => {
+                console.error(err)
+              })
+          } else if (_this.operatingitem === 2) {
+            _this.$axios.post('items/editdetectionmodel/' + _this.Id, _this.itemsdetailinfoform)
+              .then(res => {
+                if (res.data.code === 0) {
+                  _this.$message({
+                    type: 'success',
+                    message: res.data.message
+                  })
+                  _this.datadialogVisible = false
+                  this.initData()
+                } else {
+                  _this.$message({
+                    type: 'warning',
+                    message: res.data.message
+                  })
+                }
+              })
+              .catch(() => { })
+          }
+        } else {
+          return false
+        }
+      })
+    }
+
+  }
+}
+</script>
+
+<style lang="scss">
+.time {
+  font-size: 13px;
+  color: #999;
+}
+.bottom {
+  margin-top: 13px;
+  line-height: 12px;
+}
+.button {
+  padding: 0;
+  float: right;
+}
+.image {
+  width: 100%;
+  display: block;
+}
+.clearfix:before,
+.clearfix:after {
+  display: table;
+  content: "";
+}
+.clearfix:after {
+  clear: both;
+}
+.el-pagination {
+  margin: 1rem 0 2rem;
+  text-align: right;
+}
+.plab {
+  font-size: 13px;
+  color: #999;
+}
+.triggerone {
+  font-size: 13px;
+  margin-left: 80px;
+}
+.plab {
+  font-size: 13px;
+  color: #999;
+}
+</style>

+ 20 - 15
src/dashoo.cn/frontend_web/src/pages/setting/systemitems/index.vue

@@ -38,9 +38,15 @@
             <router-link :to="'/setting/systemitems/'+scope.row.Id+'/itemsdetail?name=' + scope.row.FullName">
               <el-button v-if="scope.row.IsTree == 0" type="text" title="编辑字典" size="small" icon="el-icon-edit"></el-button>
             </router-link>
-             <router-link :to="'/setting/systemitems/'+scope.row.Id + '/treeitemsdetail?name=' + scope.row.FullName">
+             
+            <router-link :to="'/setting/systemitems/'+scope.row.Id + '/treeitemsdetail?name=' + scope.row.FullName">
               <el-button v-show="scope.row.IsTree == 1" size="small" type="text" style="margin-left: 5px" title="编辑字典" icon="el-icon-edit"></el-button>
             </router-link>
+            
+            <router-link :to="'/setting/systemitems/'+scope.row.Id + '/detectioncycleitemsdetail?name=' + scope.row.FullName">
+              <el-button v-show="scope.row.IsTree == 2" size="small" type="text" style="margin-left: 5px" title="编辑字典" icon="el-icon-edit"></el-button>
+            </router-link>
+          
           </template>
         </el-table-column>
         <!-- <el-table-column  prop="Code" label="编码" show-overflow-tooltip></el-table-column> -->
@@ -66,7 +72,7 @@
 <script>
   export default {
     name: 'systemitems',
-    data() {
+    data () {
       return {
         searchkey: '',
         currentItemCount: 0,
@@ -96,12 +102,12 @@
         formLabelWidth: '120px'
       }
     },
-    created() {
+    created () {
       // initial data
       this.initData()
     },
     methods: {
-      initData() {
+      initData () {
         let _this = this
         // paginate
         const params = {
@@ -111,8 +117,8 @@
         }
         // request
         this.$axios.get('items/list', {
-            params
-          })
+          params
+        })
           .then(res => {
             // response
             // console.log(res.data.items)
@@ -124,39 +130,38 @@
             console.error(err)
           })
       },
-      jstimehandle(val) {
+      jstimehandle (val) {
         val = val.replace('T', ' ')
         return val.substring(0, 10)
       },
-      clicksearch() {
+      clicksearch () {
         this.currentPage = 1
         this.initData()
       },
-      handleSelectionChange(val) {
+      handleSelectionChange (val) {
         this.selectlist = val
       },
-      handleSizeChange(value) {
+      handleSizeChange (value) {
         this.size = value
         this.currentPage = 1
         this.initData()
       },
-      handleCurrentChange(value) {
+      handleCurrentChange (value) {
         this.currentPage = value
         this.initData()
       },
-      handleRemove(file, fileList) {
+      handleRemove (file, fileList) {
         console.log(file, fileList)
       },
-      handlePreview(file) {
+      handlePreview (file) {
         console.log(file)
       },
-      clearSearch() {
+      clearSearch () {
         this.searchkey = ''
         this.initData()
       }
     }
   }
-
 </script>
 
 <style lang="scss">