sysconfigCtrl.js 15 KB

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