sysQuerySqlService.js 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235
  1. var sysQuerySqlServiceApp = angular.module('sysQuerySqlServiceApp',[]);
  2. sysQuerySqlServiceApp.service('sysQuerySqlService', ['$http','$jsonToFormData', 'BaseService','dataRightsService', function($http, $jsonToFormData, BaseService,dataRightsService) {
  3. var service = {
  4. init: function(scope) {
  5. this.scope = scope;
  6. scope.dsList = dsList;
  7. scope.sysQuerySql = sysQuerySql||{};
  8. if(scope.sysQuerySql&&scope.sysQuerySql[this.scope.buttonKey])
  9. scope.sysQuerySql[this.scope.buttonKey] = parseToJson(scope.sysQuerySql[this.scope.buttonKey]);
  10. this.scope.sysQuerySql[this.scope.buttonKey] = this.scope.sysQuerySql[this.scope.buttonKey]||[{inRow:0,name:"导出",triggerType:"onclick",isDefault:true,urlPath:"exports()"}];
  11. if(scope.sysQuerySql.categoryid)
  12. scope.sysQuerySql.categoryid = parseInt(scope.sysQuerySql.categoryid);
  13. scope.globalTypesDICList = globalTypesDICList;
  14. scope.sysQueryFields = sysQueryFields;
  15. scope.oldSysQueryFields = $.extend(true,[],scope.sysQueryFields);
  16. this.util = dataRightsService;
  17. this.showResponse = function(responseText){
  18. $.ligerDialog.closeWaitting();
  19. var obj = new com.hotent.form.ResultMessage(responseText);
  20. if (obj.isSuccess()) {
  21. $.ligerDialog.confirm( obj.getMessage()+",是否继续操作","提示信息", function(rtn) {
  22. if(rtn){
  23. window.location.href = location.href.getNewUrl();
  24. }else{
  25. window.location.href ="list.ht";
  26. }
  27. });
  28. } else {
  29. $.ligerDialog.error(obj.getMessage(),"提示信息");
  30. }
  31. };
  32. for(var i = 0 ,c;c=scope.sysQueryFields[i++];){
  33. if(!c.fieldName)
  34. c.fieldName = c.name;
  35. if(c.dataType=='date'&&!c.dateFormat)
  36. c.dateFormat = "yyyy-MM-dd";
  37. }
  38. },
  39. addUrl: function() {
  40. this.scope.sysQuerySql[this.scope.buttonKey].push({
  41. inRow:1
  42. })
  43. },
  44. delUrl: function(list,k) {
  45. if(k < 0 ) k = 0;
  46. for(var i = k||0 ; i < list.length ; i++){
  47. if(list[i].checked){
  48. list.splice(i,1);
  49. this.delUrl(list,i-1);
  50. break;
  51. }
  52. }
  53. },
  54. getControlTypeJson : function (dataType){
  55. var json = {1:"单行文本框",12:"自定义对话框",3:"数据字典",11:"下拉选项",4:"人员选择器(单选)",17:"角色选择器(单选)",18:"组织选择器(单选)",19:"岗位选择器(单选)",8:"人员选择器(多选)",5:"角色选择器(多选)",6:"组织选择器(多选)",7:"岗位选择器(多选)"};
  56. if(dataType == "date" || dataType == "timestamp")
  57. json[15] = "日期控件";
  58. return json;
  59. },
  60. getControlType:function(id,dataType){
  61. return this.getControlTypeJson(dataType)[id];
  62. },
  63. validSql : function(remind) {
  64. var obj =this.scope.sysQuerySql;
  65. var params = {
  66. sql : obj.sql,
  67. dsalias : obj.dsname
  68. };
  69. var flag = true;
  70. debugger;
  71. $.ajax({
  72. url: 'validSql.ht',
  73. type: 'POST',
  74. dataType: 'json',
  75. data:params,
  76. async:false,
  77. success: function(data) {
  78. if (data) {
  79. if(remind) {
  80. $.ligerDialog.success('<p><font color="green">验证通过!<br></font></p>');
  81. }
  82. } else {
  83. $.ligerDialog.error('<p><font color="red">验证不通过!<br></font></p>');
  84. flag = false;
  85. }
  86. }
  87. });
  88. return flag;
  89. },
  90. ctrlTypeSetting : function(field,urlTag) {
  91. var url= __ctx + "/platform/system/"+urlTag+"/editDetail.ht";
  92. var that = this;
  93. DialogUtil.open({
  94. height:400,
  95. width: 700,
  96. title : '控件设置',
  97. url: url,
  98. conf : {
  99. type : "ctrlType",
  100. field:$.extend(true,{},field),
  101. dicList:this.scope.globalTypesDICList
  102. },
  103. isResize: true,
  104. sucCall:function(rtn){
  105. field.dateFormat = rtn.dateFormat||"";
  106. field.format = rtn.dateFormat||"";
  107. field.controlType = rtn.controlType;
  108. field.controlContent = rtn.controlContent;
  109. that.scope.$digest();
  110. }
  111. });
  112. },
  113. alarmSetting : function(field,urlTag) {
  114. var url= __ctx + "/platform/system/"+urlTag+"/editDetail.ht";
  115. var that = this;
  116. DialogUtil.open({
  117. height:600,
  118. width: 800,
  119. title : '报警设置',
  120. url: url,
  121. conf : {
  122. type : "alarmSetting",
  123. field:$.extend(true,{},field)
  124. },
  125. isResize: true,
  126. sucCall:function(rtn){
  127. field.alarmSetting = rtn.alarmSetting;
  128. field.formater = rtn.formater;
  129. that.scope.$digest();
  130. }
  131. });
  132. },
  133. sqlSetting : function(field,urlTag) {
  134. var url= __ctx + "/platform/system/"+urlTag+"/editDetail.ht";
  135. var that = this;
  136. DialogUtil.open({
  137. height:600,
  138. width: 800,
  139. title : '报警设置',
  140. url: url,
  141. conf : {
  142. type : "sqlSetting",
  143. field:$.extend(true,{},field)
  144. },
  145. isResize: true,
  146. sucCall:function(rtn){
  147. field.resultFrom = rtn.resultFrom;
  148. }
  149. });
  150. },
  151. virtualSetting : function(field,urlTag,idx) {
  152. var url= __ctx + "/platform/system/"+urlTag+"/editDetail.ht";
  153. var that = this;
  154. var vitualField = {};
  155. vitualField.virtualFrom = field.fieldName;
  156. vitualField.fieldDesc = "";
  157. vitualField.sqlId = field.sqlId;
  158. vitualField.name = "";
  159. vitualField.isShow = 0;
  160. vitualField.isSearch = 0;
  161. vitualField.isVirtual = 1;
  162. vitualField.dataType = "varchar";
  163. vitualField.controlType = 1;
  164. if(field.controlType == 3) { //数据字典
  165. vitualField.resultFromType = 1;
  166. vitualField.resultFrom = field.controlContent;
  167. }else if(field.controlType == 11) {
  168. vitualField.resultFromType = 3;
  169. vitualField.resultFrom = field.controlContent;
  170. }else {
  171. vitualField.resultFromType = 2;
  172. }
  173. DialogUtil.open({
  174. height:400,
  175. width: 700,
  176. title : '虚拟列设置',
  177. url: url,
  178. conf : {
  179. type : "virtualSetting",
  180. field:vitualField,
  181. dicList:this.scope.globalTypesDICList
  182. },
  183. isResize: true,
  184. sucCall:function(rtn){
  185. rtn.fieldName = rtn.name;
  186. $.insert(that.scope.sysQueryFields,rtn,idx+1);
  187. that.scope.$digest();
  188. }
  189. });
  190. },
  191. customFormSubmit : function(buttonKey) {
  192. var obj = this.scope.sysQuerySql;
  193. var json = {
  194. id : obj.id,
  195. name : obj.name,
  196. alias : obj.alias,
  197. sql : obj.sql,
  198. dsalias : obj.dsalias,
  199. dsname : obj.dsname,
  200. supportTab : obj.supportTab,
  201. categoryid: obj.categoryid
  202. };
  203. json[buttonKey] = obj[buttonKey]?JSON.stringify(obj[buttonKey]):null;
  204. var $form = $('<form method="post" action="save.ht"></form>');
  205. var $input = $("<input type='hidden' name='jsonStr'/>");
  206. var $input2 = $("<input type='hidden' name='fieldJson'/>");
  207. $input.val(JSON2.stringify(json));
  208. $input2.val(this.getFieldListStr(this.scope.sysQueryFields));
  209. $form.append($input).append($input2);
  210. $form.ajaxForm({success:service.showResponse});
  211. $form.submit();
  212. },
  213. getFieldListStr : function(list){
  214. for(var i = 0 ; i < list.length ; i++){
  215. if(list[i].alarmSetting&&list[i].alarmSetting.length>0)
  216. for(var j = 0 ; j < list[i].alarmSetting.length ; j++){
  217. if(list[i].alarmSetting[j].hasOwnProperty("$$hashKey"))
  218. delete list[i].alarmSetting[j].$$hashKey;
  219. }
  220. }
  221. return this.util.listToString(list);
  222. },
  223. changeCheckBox : function(list,key,isCheck){
  224. for(var i = 0 ; i < list.length ; i++){
  225. list[i][key] = isCheck?0:1;
  226. }
  227. },
  228. hasVirtual : function(field){
  229. if(field.isVirtual==1 || field.isVirtual == undefined) return true;
  230. return false;
  231. }
  232. };
  233. return service;
  234. }
  235. ])