sysconfigCtrl.js 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315
  1. "use strict";
  2. app.controller("sysconfigCtrl", ["$rootScope", "$scope", "$state", "$timeout", "$interval", "$modal", "$window", "SweetAlert", "i18nService", "uiGridConstants", "uiGridGroupingConstants", "Restangular", "api_sysinfo", "api_is_category", "api_bpm_data", function (t, a, n, e, i, s, r, o, l, u, d, c, g, api_is_category, api_bpm_data) {
  3. a.langs = l.getAllLangs(), a.lang = "zh-cn", l.setCurrentLang(a.lang);
  4. var f = (t.user, r._, {
  5. idx: 0,
  6. sum: 1e3
  7. });
  8. // a.autoCloseIncidentHour = 24;//默认24小时自动关单
  9. a.changeAutoCloseIncidentHour = function(e){
  10. var v = parseFloat(e.target.value)?parseFloat(e.target.value):0;
  11. a.autoCloseIncidentHour.valueconfig = v > 0 ? v : 0;
  12. }
  13. a.changeUpdatePwdMonth = function(e){
  14. var v = parseFloat(e.target.value)?parseFloat(e.target.value):0;
  15. a.updatePwdMonth.valueconfig = v > 0 ? v : 0;
  16. }
  17. function convertListToTree(data, treeMap) {
  18. var idToNodeMap = {}; //Keeps track of nodes using id as key, for fast lookup
  19. var root = null; //Initially set our loop to null
  20. var parentNode = null;
  21. //loop over data
  22. for (var i = 0; i < data.length; i++) {
  23. var datum = data[i];
  24. //each node will have children, so let's give it a "children" poperty
  25. datum.children = [];
  26. //add an entry for this node to the map so that any future children can
  27. //lookup the parent
  28. idToNodeMap[datum.id] = datum;
  29. //Does this node have a parent?
  30. if (typeof datum.parent === "undefined" || datum.parent == null) {
  31. //Doesn't look like it, so this node is the root of the tree
  32. root = datum;
  33. treeMap[datum.id] = root;
  34. } else {
  35. //This node has a parent, so let's look it up using the id
  36. parentNode = idToNodeMap[datum.parent.id];
  37. //We don't need this property, so let's delete it.
  38. delete datum.parent;
  39. //Let's add the current node as a child of the parent node.
  40. parentNode.children.push(datum);
  41. }
  42. }
  43. return root;
  44. }
  45. function convertParentToChildList(data) {
  46. var treeMap = {};
  47. var list = [];
  48. convertListToTree(data, treeMap);
  49. angular.forEach(treeMap, function (item) {
  50. list.push(item);
  51. });
  52. return list;
  53. }
  54. // 将事件分类搜索结果返回的数据整理成children模式
  55. function transform(nodes) {
  56. var treeConverter = {
  57. result: null, //转化后的结果,是根节点,所有节点都是从根节点长出来的
  58. attributeName: 'id', //节点唯一标识符
  59. needFind: true, //是否查询节点在result中已经存在,为了优化效率
  60. transform: function (node) { //转化递归函数,参数:一个待插入节点
  61. if (node.parent != null) { //该节点有父节点
  62. var newNode = this.transform(node.parent); //递归进入,返回值为一个节点,用作父节点,该父节点必然存在于result中,这点由下面的算法可以控制
  63. if (this.needFind) {
  64. for (var i = 0; i < newNode.children.length; i++) { //查找要插入的node子节点是否在newNode这个父节点中存在
  65. if (newNode.children[i][this.attributeName] === node[this.attributeName]) {
  66. return newNode.children[i]; //存在的话直接返回newNode父节点内的该子节点,该子节点必然存在于result中,作为返回值它将被用作上级递归的newNode,因此newNode必然存在于result中
  67. }
  68. }
  69. }
  70. this.needFind = false; //不存在的话,关闭之后递归的循环判断,因为待插入node节点不存在于result中,故而它的子节点一定不存在于result中,不用再循环判断
  71. // delete node.parent; //删除该节点的parent属性,如果有的话
  72. node.children = []; //因为确定是要新插入的节点,没有children:[]属性,故给该节点增加children:[]属性
  73. newNode.children.push(node); //将该node节点push进newNode的子节点数组中
  74. return node; //return该新插入节点,作为递归返回值给上层,用作newNode父节点,node存在于result中故newNode存在于result中
  75. } else if (node.parent == null) { //该叶节点没有父节点,即为根节点
  76. // delete node.parent; //删除该节点的parent属性,如果有的话
  77. if (this.result == null) { //根节点不存在
  78. node.children = []; //给该节点增加children:[]属性
  79. return this.result = node; //该节点赋给result,并return根节点,作为返回值它将被用作上级递归的newNode,因此newNode必然存在于result中
  80. } else {
  81. node.children = [];
  82. // 顶级去重
  83. for (var i = 0; i < this.result.children.length; i++) {
  84. if (this.result.children[i][this.attributeName] === node[this.attributeName]) {
  85. return this.result.children[i];
  86. }
  87. }
  88. this.result.children.push(node)
  89. return node // 直接return根节点,作为返回值它将被用作上级递归的newNode,因此newNode必然存在于result中
  90. }
  91. }
  92. },
  93. getWhole: function (nodes, attributeName) { //传入整个叶子节点数组,attributeName作为节点唯一标识符属性,返回整个转化结果
  94. var _node = {};
  95. _node.children = [];
  96. this.result = _node; //重置根节点
  97. this.attributeName = attributeName == null ? 'id' : attributeName; //唯一标识符默认为“id”
  98. nodes = JSON.parse(JSON.stringify(nodes)); //复制出一个新的节点对象作为参数,保证不改变原有数据
  99. nodes.forEach(item => { //循环调用转化方法
  100. this.needFind = true; //重置开启节点是否已存在判断,保证不插入重复节点
  101. this.transform(item);
  102. })
  103. return this.result; //返回根节点
  104. }
  105. }
  106. var result = treeConverter.getWhole(nodes); //调用
  107. return result;
  108. }
  109. a.select_treedata = [];
  110. t.bala1 = a.try_async_load = function (s, fn, showValue) {
  111. if (s) {
  112. var filterKeyword = s.filterKeyword;
  113. }
  114. var postData = {
  115. "idx": 0,
  116. "sum": 1000
  117. }
  118. if (filterKeyword) {
  119. postData.incidentcategory = { selectType: "pinyin_qs", category: filterKeyword }
  120. }
  121. a.my_data = [];
  122. a.doing_async = true;
  123. api_bpm_data.fetchDataList('incidentcategory', postData).then(function (response) {
  124. if (response.status == 200) {
  125. var data = response.list;
  126. if (filterKeyword) {
  127. data.forEach(e => {
  128. e.isExpanded = true;
  129. })
  130. var li = transform(data).children;
  131. console.log(li)
  132. fn(li)
  133. return;
  134. } else {
  135. var objects = [];
  136. for (var i = 0; i < data.length; i++) {
  137. var object = {};
  138. object.id = data[i].id;
  139. object.parent = data[i].parent;
  140. object.category = data[i].category;
  141. object.isExpanded = true;
  142. objects.push(object);
  143. }
  144. a.my_data = convertParentToChildList(objects);
  145. a.select_treedata = angular.copy(a.my_data);
  146. if(showValue){
  147. console.log(a.select_treedata);
  148. var itemValue = a.select_treedata.find(v => v.id == showValue.valueconfig);
  149. if(itemValue){
  150. itemValue.selected = true;
  151. }else{
  152. selectChildrenItem(a.select_treedata, showValue);
  153. }
  154. }
  155. }
  156. if (a.my_data.length > 0) {
  157. a.doing_async = false;
  158. }
  159. } else {
  160. SweetAlert.swal({
  161. title: "系统错误!",
  162. text: "请刷新重试!",
  163. type: "error"
  164. });
  165. }
  166. });
  167. };
  168. function selectChildrenItem(arr, showValue){
  169. var arrs = [];
  170. arr.forEach(v => {
  171. if(Array.isArray(v.children) && v.children.length){
  172. arrs = arrs.concat(v.children);
  173. }
  174. })
  175. var itemValue = arrs.find(v => v.id == showValue.valueconfig);
  176. if(itemValue){
  177. itemValue.selected = true;
  178. }else{
  179. selectChildrenItem(arrs, showValue);
  180. }
  181. }
  182. //保存
  183. a.savesystem = function () {
  184. var arr = {};
  185. arr.systemConfiguration = [];
  186. angular.forEach(a.baseConfig, function (v) {
  187. if (v.keyconfig == 'pwd' || v.keyconfig == 'conversationSeconds') {
  188. arr.systemConfiguration.push(v);//用户默认密码,登录有效时长
  189. }
  190. })
  191. arr.systemConfiguration.push(a.repairMain);//报修主体
  192. arr.systemConfiguration.push(a.ifCreate);//自动建单
  193. arr.systemConfiguration.push(a.reqHasCategory);//是否选择事件分类
  194. arr.systemConfiguration.push(a.incidentWithConsumable);//是否需要绑定耗材
  195. arr.systemConfiguration.push(a.wxIncidentWithCmdb);//是否需要绑定资产
  196. arr.systemConfiguration.push(a.requesterLgoinType);//保修人登录方式
  197. arr.systemConfiguration.push(a.autoCloseIncidentHour);//自动关单小时
  198. arr.systemConfiguration.push(a.updatePwdMonth);//密码强制修改时间
  199. if(a.cifilter_classic){
  200. a.alarmCategory.valueconfig = a.cifilter_classic.id + '';
  201. arr.systemConfiguration.push(a.alarmCategory);//默认的告警转换分类
  202. }else{
  203. a.alarmCategory.valueconfig = '';
  204. arr.systemConfiguration.push(a.alarmCategory);//默认的告警转换分类
  205. }
  206. console.log(arr,99999);
  207. g.addData("systemConfiguration", arr).then(function (t) {
  208. if (t.status == 200) {
  209. //获取报修主体
  210. api_is_category.isCategory({ "idx": 0, "sum": 1000 })
  211. .then(function (res) {
  212. if (res.status == 200) {
  213. //存储报修主体到缓存
  214. var list = res.list;
  215. var repairMain = list.find((v) => v.keyconfig == "repairMain"); //报修主体
  216. var incidentWithConsumable = list.find(
  217. (v) => v.keyconfig == "incidentWithConsumable"
  218. ); //是否绑定耗材
  219. var wxIncidentWithCmdb = list.find(
  220. (v) => v.keyconfig == "wxIncidentWithCmdb"
  221. ); //是否绑定资产
  222. sessionStorage.setItem(
  223. "repair_main",
  224. JSON.stringify(repairMain)
  225. );
  226. sessionStorage.setItem(
  227. "incidentWithConsumable",
  228. incidentWithConsumable.valueconfig
  229. );
  230. sessionStorage.setItem(
  231. "wxIncidentWithCmdb",
  232. wxIncidentWithCmdb.valueconfig
  233. );
  234. o.swal({
  235. title: "保存成功!",
  236. type: "success",
  237. confirmButtonColor: "#007AFF"
  238. })
  239. }
  240. })
  241. .catch(function (err) {
  242. console.log(err)
  243. })
  244. } else {
  245. o.swal({
  246. title: "操作异常!",
  247. text: "系统异常,请稍后重试,或者联系管理员!",
  248. type: "error"
  249. })
  250. }
  251. })
  252. }, a.ldloading = {}, a.refreshData = function (t, n) {
  253. a.ldloading[t.replace("-", "_")] = !0, angular.isUndefined(n) && (n = f), a.myData = [], g.fetchDataList("systemConfiguration", n).then(function (n) {
  254. if (n.status == 200) {
  255. var e = c.stripRestangular(n);
  256. a.myData = e.list, a.ldloading[t.replace("-", "_")] = !1
  257. console.log(a.myData);
  258. a.baseConfig = [];//基本配置
  259. a.cacheConfig = [];//缓存配置
  260. a.repairMain = {};//报修主体
  261. console.log(a.myData,77777)
  262. angular.forEach(a.myData, function (v, i) {
  263. if (v.keyconfig == 'pwd' || v.keyconfig == 'conversationSeconds' || v.keyconfig == 'formUri' || v.keyconfig == 'localhost' || v.keyconfig == 'verificationPath' || v.keyconfig == 'docpath') {
  264. a.baseConfig.push(v);//基本配置
  265. }
  266. if (v.keyconfig == 'userRedisIp' || v.keyconfig == 'userRedisPort') {
  267. a.cacheConfig.push(v);//缓存配置
  268. }
  269. if (v.keyconfig == 'repairMain') {
  270. a.repairMain = v;//报修主体
  271. }
  272. if (v.keyconfig == 'ifCreate') {
  273. a.ifCreate = v;//自动建单
  274. }
  275. if (v.keyconfig == 'reqHasCategory') {
  276. a.reqHasCategory = v;//是否选择事件分类
  277. }
  278. if (v.keyconfig == 'incidentWithConsumable') {
  279. a.incidentWithConsumable = v;//是否需要绑定耗材
  280. }
  281. if (v.keyconfig == 'wxIncidentWithCmdb') {
  282. a.wxIncidentWithCmdb = v;//是否需要绑定资产
  283. }
  284. if (v.keyconfig == 'requesterLgoinType') {
  285. a.requesterLgoinType = v;//报修人登录方式
  286. }
  287. if (v.keyconfig == 'autoCloseIncidentHour') {
  288. v.valueconfig = parseFloat(v.valueconfig)
  289. a.autoCloseIncidentHour = v;//自动关单小时
  290. }
  291. if (v.keyconfig == 'updatePwdMonth') {
  292. v.valueconfig = parseFloat(v.valueconfig)
  293. a.updatePwdMonth = v;//密码强制修改时间
  294. }
  295. if (v.keyconfig == 'alarmCategory') {
  296. a.alarmCategory = v;
  297. a.try_async_load(null, null, v);
  298. }
  299. })
  300. }else{
  301. console.log(n.status);
  302. }
  303. }, function () {
  304. a.ldloading[t.replace("-", "_")] = !1
  305. })
  306. }, a.refreshData("expand-right", f)
  307. }]);