TEST.js 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532
  1. print( "积分分发:------------------------------------------" );
  2. var Config = {
  3. personPointCategoryAlias : "积分-个人积分",
  4. unitPointCategoryAlias : "积分-部门积分",
  5. pointLogCategoryAlias : "积分-积分记录",
  6. query : "pointManagerQuery",
  7. unitPointView : "unitPointView",
  8. companyLevel : 1,
  9. departmentLevel_1 : 2
  10. };
  11. var _self = this;
  12. var applications = this.Action.applications;
  13. var Utils = {
  14. getUserFlag : function( json ){
  15. return json.flag || json.distinguishedName || json.unique || json.employee || json.mobile || json.id;
  16. },
  17. getKeyEqualObjFromArray : function( sourceArray, sourceKey, value ){
  18. for( var i=0; i<sourceArray.length; i++ ){
  19. if( sourceArray[i][sourceKey] === value ){
  20. return sourceArray[i];
  21. }
  22. }
  23. return null;
  24. },
  25. parseResp : function( resp ){
  26. if( !resp || resp === null ){
  27. return {
  28. "type": "error",
  29. message : "服务响应是null"
  30. }
  31. }else{
  32. var json = JSON.parse( resp.toString() );
  33. return json;
  34. }
  35. },
  36. getFailText : function( json ){
  37. //{
  38. // "type": "error",
  39. // "message": "手机号错误:15268803358, 手机号已有值重复.",
  40. // "date": "2018-08-05 02:51:35",
  41. // "spent": 5,
  42. // "size": -1,
  43. // "count": 0,
  44. // "position": 0,
  45. // "prompt": "com.x.organization.assemble.control.jaxrs.person.ExceptionMobileDuplicate"
  46. //}
  47. var text;
  48. if( json.message ){
  49. text = json.message + ( json.prompt ? "("+json.prompt + ")" : "" );
  50. }else if( json.prompt ){
  51. text = json.prompt;
  52. }else{
  53. text = "未知异常";
  54. }
  55. print(text);
  56. return text;
  57. },
  58. processError : function( e, text ){
  59. e.printStackTrace();
  60. var errorText = text + " " + e.name + ": " + e.message;
  61. print(errorText);
  62. return errorText;
  63. },
  64. arrayIndexOf : function( array, target ){
  65. for( var i=0; i<array.length; i++ ){
  66. if( array[i] == target )return i;
  67. }
  68. return -1;
  69. },
  70. objectClone : function (obj) {
  71. if (null == obj || "object" != typeof obj) return obj;
  72. if ( typeof obj.length==='number'){ //数组
  73. var copy = [];
  74. for (var i = 0, len = obj.length; i < len; ++i) {
  75. copy[i] = Utils.objectClone(obj[i]);
  76. }
  77. return copy;
  78. }else{
  79. var copy = {};
  80. for (var attr in obj) {
  81. copy[attr] = Utils.objectClone(obj[attr]);
  82. }
  83. return copy;
  84. }
  85. },
  86. typeOf : function( obj ){
  87. if (item == null) return 'null';
  88. if (item.$family != null) return item.$family();
  89. if (item.constructor == Array) return 'array';
  90. if (item.nodeName){
  91. if (item.nodeType == 1) return 'element';
  92. if (item.nodeType == 3) return (/\S/).test(item.nodeValue) ? 'textnode' : 'whitespace';
  93. } else if (typeof item.length == 'number'){
  94. if (item.callee) return 'arguments';
  95. //if ('item' in item) return 'collection';
  96. }
  97. return typeof item;
  98. //if( obj === null )return "null";
  99. //if( "object" !== typeof obj )return typeof obj;
  100. //return typeof obj.length==='number' ? 'array' : 'object';
  101. }
  102. };
  103. var Org = {
  104. getSuperUnitByLevel : function(name, level){
  105. var unitList = _self.org.listSupUnit(name, true);
  106. var result;
  107. if(unitList){
  108. unitList.each( function(u){
  109. if( u.level == level ){
  110. result = u.distinguishedName
  111. }
  112. })
  113. }
  114. return result;
  115. }
  116. };
  117. var Calendar = {
  118. getLastMonth : function( date ) {
  119. var Date = Java.type("java.util.Date");
  120. if( !date ){
  121. date = new Date();
  122. }
  123. var sdf = new java.text.SimpleDateFormat("yyyy-MM-dd");
  124. var array = sdf.format( date ).split("-");
  125. var date_lastMonth = sdf.parse( array[0] + "-" + array[1] + "-" + "01");
  126. var Calendar = Java.type("java.util.Calendar");
  127. var c = Calendar.getInstance();
  128. c.setTime(date_lastMonth);
  129. c.add(Calendar.MONTH, -1);
  130. return c.get(Calendar.YEAR) + "-" + (c.get(Calendar.MONTH) + 1);
  131. }
  132. };
  133. //个人积分分发 start:------------------------------------------
  134. print( "个人门积分分发 start:------------------------------------------" );
  135. var PersonPointDispatch = function( identity ){
  136. if( Utils.typeOf( identity ) === "object" ){
  137. this.identityDn = identity.distinguishedName;
  138. this.personDn = identity.person;
  139. }else{
  140. this.identityDn = identity;
  141. var personList = _self.org.listPersonWithIdentity( identity );
  142. if( personList && Utils.typeOf( personList ) == "array" )this.personDn = personList[0].distinguishedName;
  143. }
  144. };
  145. var PPD = PersonPointDispatch;
  146. PPD.prototype.getCategory = function(){
  147. if( !_self.personPointCategory ){
  148. var o = applications.putQuery('x_cms_assemble_control', "categoryinfo/alias/" + Config.personPointCategoryAlias );
  149. var json = Utils.parseResp( o );
  150. _self.personPointCategory = json.data;
  151. }
  152. return _self.personPointCategory;
  153. };
  154. PPD.prototype.getProfile = function(){
  155. if( !this.profileId ){
  156. var uri = "document/filter/list/(0)/next/1";
  157. var filter = {
  158. categoryAliasList : [ Config.personPointCategoryAlias ],
  159. publisherList : [ this.personDn ]
  160. };
  161. var o = applications.putQuery('x_cms_assemble_control',uri, JSON.stringify(filter) );
  162. var json = Utils.parseResp( o );
  163. if( json.data.length === 0 ){
  164. this.profileId = null;
  165. this.profile = null;
  166. }else{
  167. this.profileId = json.data[0].id;
  168. }
  169. }
  170. //print( "积分分发:" + JSON.stringify( json.data ) );
  171. if( this.profileId ){
  172. var o1 = applications.getQuery('x_cms_assemble_control', "data/document/"+this.profileId ); //只获取数据
  173. var json1 = Utils.parseResp( o1 );
  174. this.profile = json1.data;
  175. }
  176. return this.profile;
  177. };
  178. PPD.prototype.saveProfile = function( data ){
  179. // data = {
  180. // pointType
  181. // getedPoint
  182. // projectText
  183. // }
  184. this.getProfile();
  185. if( !this.profile ){
  186. this.createProfile( data );
  187. }else{
  188. this.updateProfile( data );
  189. }
  190. };
  191. PPD.prototype.createProfile = function( data ){
  192. var company = _self.org.getUnitByIdentity( this.identityDn, Config.companyLevel );
  193. var person = _self.org.getPerson( this.personDn );
  194. var categoryData = this.getCategory();
  195. var doc = {
  196. //"id" : this.documentAction.getUUID(),
  197. "isNewDocument" : true,
  198. "title": this.personDn.split("@")[0]+"个人积分",
  199. "creatorIdentity": this.identityDn,
  200. "appId" : categoryData.appId,
  201. "attachmentList" : [],
  202. "form" : categoryData.formId,
  203. "formName" :categoryData.formName,
  204. //"docStatus" : "draft",
  205. "categoryName" : categoryData.name || categoryData.categoryName,
  206. "categoryId" : categoryData.id,
  207. "categoryAlias" : Config.personPointCategoryAlias,
  208. "docData" : {
  209. "person" : Utils.typeOf( person ) == "array" ? person[0] : person,
  210. "personDn" : this.personDn,
  211. "annualPoint" : data.getedPoint,
  212. "permanentPoint" : data.getedPoint,
  213. "convertiblePoint" : data.getedPoint,
  214. "convertedPoint" : "0",
  215. "currentYear" : new Date().getFullYear(),
  216. "companyDn" : Utils.typeOf( company ) == "array" ? company[0].distinguishedName : company.distinguishedName
  217. }
  218. };
  219. this.updatePointTypeData( doc.docData, data, true );
  220. var o = applications.putQuery('x_cms_assemble_control', "document/publish/content", JSON.stringify(doc) );
  221. var json = Utils.parseResp( o );
  222. this.profileId = json.data.id;
  223. };
  224. PPD.prototype.updateProfile = function( data, operation ){ //只保存数据
  225. var doc = this.profile;
  226. if( operation === "add" ){ //新增积分
  227. doc.permanentPoint = ( doc.permanentPoint ? parseInt( doc.permanentPoint ) : 0 ) + parseInt( data.getedPoint );
  228. var year = new Date().getFullYear();
  229. if( parseInt(doc.currentYear) !== year ){
  230. doc.annualPoint = data.getedPoint;
  231. doc.convertiblePoint = data.getedPoint;
  232. this.updatePointTypeData( doc, data, false );
  233. doc.currentYear = year;
  234. }else{
  235. doc.annualPoint = ( doc.annualPoint ? parseInt( doc.annualPoint ) : 0 ) + parseInt( data.getedPoint );
  236. doc.convertiblePoint = ( doc.convertiblePoint ? parseInt( doc.convertiblePoint ) : 0 ) + parseInt( data.getedPoint );
  237. this.updatePointTypeData( doc, data, true );
  238. }
  239. }
  240. var o = applications.putQuery('x_cms_assemble_control', "data/document/"+this.profileId, JSON.stringify(doc) );
  241. var json = Utils.parseResp( o );
  242. };
  243. PPD.prototype.updatePointTypeData = function( docData, data, isCurrentYear ){
  244. var typeJson = docData[ "typeJson" ] = docData[ "typeJson" ] || {};
  245. var typeData = typeJson[ data.pointType ] = typeJson[ data.pointType ] || {};
  246. this.updatePoint( typeData, data.getedPoint, isCurrentYear );
  247. this.updateProjectData( typeData, data, isCurrentYear )
  248. };
  249. PPD.prototype.updateProjectData = function( typeData, data, isCurrentYear ){
  250. var projectJson = typeData[ "projectJson" ] = typeData[ "projectJson" ] || {};
  251. var projectData = projectJson[ data.projectText ] = projectJson[ data.projectText ] || {};
  252. this.updatePoint( projectData, data.getedPoint, isCurrentYear );
  253. };
  254. PPD.prototype.updatePoint = function( d, getedPoint, isCurrentYear ){
  255. var point = parseInt(data.getedPoint);
  256. if( !isCurrentYear ){
  257. d.annualPoint = point;
  258. }else{
  259. d.annualPoint = ( d.annualPoint ? parseInt( d.annualPoint ) : 0 ) + point;
  260. }
  261. d.permanentPoint = ( d.permanentPoint ? parseInt( d.permanentPoint ) : 0 ) + point;
  262. };
  263. //个人积分分发 end:------------------------------------------
  264. print( "个人积分分发 end:------------------------------------------" );
  265. print( "部门积分分发 start:------------------------------------------" );
  266. //部门积分分发 start:------------------------------------------"
  267. var UnitPointDispatch = function( identity, unit ){
  268. var identityDn = this.identityDn = Utils.typeOf( identity ) === "string" ? identity : identity.distinguishedName;
  269. if( unit ){
  270. if( Utils.typeOf( unit ) === "object" ){
  271. this.unit = unit;
  272. this.unitDn = unit.distinguishedName
  273. }else{
  274. this.unit = _self.org.getUnit( unit )[0];
  275. this.unitDn = unit;
  276. }
  277. }else{
  278. var unitList = _self.org.getUnitByIdentity( identityDn, Config.departmentLevel_1 );
  279. if( unitList && Utils.typeOf( unitList ) === "array" ){
  280. this.unit = unitList[0];
  281. this.unitDn = this.unit.distinguishedName
  282. }
  283. }
  284. var Date = Java.type( "java.util.Date" );
  285. var date = new Date();
  286. //this.currentDate = new java.text.SimpleDateFormat("yyyy-MM-dd").format( date );
  287. this.currentMonth = new java.text.SimpleDateFormat("yyyy-MM").format( date );
  288. this.currentYear = new java.text.SimpleDateFormat("yyyy").format( date );
  289. this.preMonth = Calendar.getLastMonth( date );
  290. };
  291. var UPD = UnitPointDispatch;
  292. UPD.prototype.getCategory = function(){
  293. if( !_self.unitPointCategory ){
  294. var o = applications.putQuery('x_cms_assemble_control', "categoryinfo/alias/" + Config.unitPointCategoryAlias );
  295. var json = Utils.parseResp( o );
  296. _self.unitPointCategory = json.data;
  297. }
  298. return _self.unitPointCategory;
  299. };
  300. UPD.prototype.getProfile = function(){
  301. if( !this.profileId ){
  302. var uri = "view/flag/"+ Config.unitPointView +"/query/" + Config.query + "/execute";
  303. var filterList = {"filterList": [{
  304. "logic":"and",
  305. "path": "unitDn",
  306. "comparison":"equals",
  307. "value": this.unitDn,
  308. "formatType":"textValue"
  309. }]};
  310. var o = applications.putQuery('x_query_assemble_surface', uri, JSON.stringify( filterList ) );
  311. var json = Utils.parseResp( o );
  312. if( json && json.data && json.data.grid && json.data.grid.length > 0 ){
  313. this.profileId = json.data.grid[0].bundle;
  314. }else{
  315. this.profileId = null;
  316. this.profile = null;
  317. }
  318. }
  319. if( this.profileId ){
  320. var o1 = applications.getQuery('x_cms_assemble_control', "data/document/"+this.profileId ); //只获取数据
  321. var json1 = Utils.parseResp( o1 );
  322. this.profile = json1.data;
  323. }
  324. return this.profile;
  325. };
  326. UPD.prototype.saveProfile = function( data ){
  327. // data = {
  328. // pointType
  329. // getedPoint
  330. // projectText
  331. // }
  332. this.getProfile();
  333. if( !this.profile ){
  334. this.createProfile( data );
  335. }else{
  336. this.updateProfile( data );
  337. }
  338. };
  339. UPD.prototype.createProfile = function( data ){
  340. var categoryData = this.getCategory();
  341. var doc = {
  342. //"id" : this.documentAction.getUUID(),
  343. "isNewDocument" : true,
  344. "title": this.unitDn.split("@")[0]+"部门积分",
  345. "creatorIdentity": this.identityDn,
  346. "appId" : categoryData.appId,
  347. "attachmentList" : [],
  348. "form" : categoryData.formId,
  349. "formName" :categoryData.formName,
  350. //"docStatus" : "draft",
  351. "categoryName" : categoryData.name || categoryData.categoryName,
  352. "categoryId" : categoryData.id,
  353. "categoryAlias" : Config.unitPointCategoryAlias,
  354. "docData" : {
  355. "unit" : this.unit,
  356. "unitDn" : this.unitDn,
  357. "annualPoint" : data.getedPoint,
  358. "permanentPoint" : data.getedPoint,
  359. "currentYear" : this.currentYear,
  360. "currentMonth" : this.currentMonth,
  361. "companyDn" : Org.getSuperUnitByLevel( this.unitDn, Config.companyLevel )
  362. }
  363. };
  364. this.updatePointTypeData( doc.docData, data, true, true );
  365. var o = applications.putQuery('x_cms_assemble_control', "document/publish/content", JSON.stringify(doc) );
  366. var json = Utils.parseResp( o );
  367. this.profileId = json.data.id;
  368. };
  369. UPD.prototype.updateProfile = function( data, operation ){ //只保存数据
  370. var doc = this.profile;
  371. var isCurrentMonth = doc.currentMonth === this.currentMonth;
  372. if( !isCurrentMonth ){
  373. doc.annualPoint_preMonth = doc.annualPoint || 0;
  374. doc.permanentPoint_preMonth = doc.permanentPoint || 0;
  375. doc.currentMonth = this.currentMonth;
  376. doc.preMonth = this.preMonth;
  377. }
  378. doc.permanentPoint = ( doc.permanentPoint ? parseInt( doc.permanentPoint ) : 0 ) + parseInt( data.getedPoint );
  379. if( parseInt(doc.currentYear) !== this.currentYear ){
  380. doc.annualPoint = data.getedPoint;
  381. this.updatePointTypeData( doc, data, false, isCurrentMonth );
  382. doc.currentYear = this.currentYear;
  383. }else{
  384. doc.annualPoint = ( doc.annualPoint ? parseInt( doc.annualPoint ) : 0 ) + parseInt( data.getedPoint );
  385. this.updatePointTypeData( doc, data, true, isCurrentMonth );
  386. }
  387. var o = applications.putQuery('x_cms_assemble_control', "data/document/"+this.profileId, JSON.stringify(doc) );
  388. var json = Utils.parseResp( o );
  389. };
  390. UPD.prototype.updatePointTypeData = function( docData, data, isCurrentYear, isCurrentMonth ){
  391. var typeJson = docData[ "typeJson" ] = docData[ "typeJson" ] || {};
  392. var typeData = typeJson[ data.pointType ] = typeJson[ data.pointType ] || {};
  393. this.updatePoint( typeData, data.getedPoint, isCurrentYear, isCurrentMonth );
  394. this.updateProjectData( typeData, data, isCurrentYear, isCurrentMonth )
  395. };
  396. UPD.prototype.updateProjectData = function( typeData, data, isCurrentYear, isCurrentMonth ){
  397. var projectJson = typeData[ "projectJson" ] = typeData[ "projectJson" ] || {};
  398. var projectData = projectJson[ data.projectText ] = projectJson[ data.projectText ] || {};
  399. this.updatePoint( projectData, data.getedPoint, isCurrentYear, isCurrentMonth );
  400. };
  401. UPD.prototype.updatePoint = function( d, getedPoint, isCurrentYear, isCurrentMonth ){
  402. var point = parseInt(data.getedPoint);
  403. if( !isCurrentMonth ){
  404. //if( !isCurrentYear ){
  405. // d.annualPoint_preMonth = d.annualPoint || 0;
  406. //}else{
  407. // d.annualPoint_preMonth = 0;
  408. //}
  409. d.annualPoint_preMonth = d.annualPoint || 0;
  410. d.permanentPoint_preMonth = d.permanentPoint || 0;
  411. }
  412. if( !isCurrentYear ){
  413. d.annualPoint = point;
  414. }else{
  415. d.annualPoint = ( d.annualPoint ? parseInt( d.annualPoint ) : 0 ) + point;
  416. }
  417. d.permanentPoint = ( d.permanentPoint ? parseInt( d.permanentPoint ) : 0 ) + point;
  418. };
  419. //部门积分分发 end:------------------------------------------"
  420. print( "部门积分分发 end:------------------------------------------" );
  421. print( "积分记录 start:------------------------------------------" );
  422. //"积分记录 start:------------------------------------------"
  423. var PointLog = {
  424. getCategory : function(){
  425. if( !_self.unitPointCategory ){
  426. var o = applications.putQuery('x_cms_assemble_control', "categoryinfo/alias/" + Config.pointLogCategoryAlias );
  427. var json = Utils.parseResp( o );
  428. _self.unitPointCategory = json.data;
  429. }
  430. return _self.unitPointCategory;
  431. },
  432. saveDoc : function( data, identity, unit, company ){
  433. var identityDn = Utils.typeOf( identity ) === "string" ? identity : identity.distinguishedName;
  434. var personDn, unitDn, companyDn;
  435. if( Utils.typeOf( identity ) === "object" )personDn = identity.person;
  436. if( !personDn ){
  437. var personList = _self.org.listPersonWithIdentity( identity );
  438. if( personList && personList.length > 0 )personDn = personList[0].distinguishedName;
  439. }
  440. if( unit ){
  441. unitDn = Utils.typeOf( unit ) === "string" ? unit : unit.distinguishedName;
  442. }else{
  443. unit = _self.org.getUnitByIdentity( identityDn, Config.departmentLevel_1 );
  444. if(unit && unit.length > 0)unitDn = unit[0].distinguishedName
  445. }
  446. if( company ) {
  447. companyDn = Utils.typeOf(company) === "string" ? company : company.distinguishedName;
  448. }else{
  449. company = _self.org.getUnitByIdentity( identityDn, Config.companyLevel );
  450. if(company && company.length > 0)companyDn = company[0].distinguishedName;
  451. }
  452. var Date = Java.type( "java.util.Date" );
  453. var nowStr = new java.text.SimpleDateFormat("yyyy-MM-dd").format(new Date());
  454. var categoryData = PointLog.getCategory();
  455. var doc = {
  456. //"id" : this.documentAction.getUUID(),
  457. "isNewDocument" : true,
  458. "title": "积分记录",
  459. "creatorIdentity": identityDn,
  460. "appId" : categoryData.appId,
  461. "attachmentList" : [],
  462. "form" : categoryData.formId,
  463. "formName" :categoryData.formName,
  464. //"docStatus" : "draft",
  465. "categoryName" : categoryData.name || categoryData.categoryName,
  466. "categoryId" : categoryData.id,
  467. "categoryAlias" : Config.unitPointCategoryAlias,
  468. "docData" : {
  469. "personDn" : personDn,
  470. "unitDn" : unitDn,
  471. "companyDn" : companyDn,
  472. "projectText" : data.projectText,
  473. "projectName" : data.projectName,
  474. "getedPoint" : "getedPoint",
  475. "date" : nowStr
  476. }
  477. };
  478. var o = applications.putQuery('x_cms_assemble_control', "document/publish/content", JSON.stringify(doc) );
  479. var json = Utils.parseResp( o );
  480. this.profileId = json.data.id;
  481. }
  482. };
  483. //"积分记录 end:------------------------------------------"
  484. print( "积分记录 end:------------------------------------------" )
  485. this.define("dispachPersonFlow", function(){
  486. var identityDn = this.workContext.getWork().creatorIdentity;
  487. var ppd = new PersonPointDispatch( identityDn );
  488. ppd.saveProfile( {
  489. pointType : this.data.pointType,
  490. projectText : this.data.projectText,
  491. getedPoint : this.data.getedPoint
  492. });
  493. var upd = new UnitPointDispatch( identityDn );
  494. upd.saveProfile({
  495. pointType : this.data.pointType,
  496. projectText : this.data.projectText,
  497. getedPoint : this.data.getedPoint
  498. });
  499. PointLog.saveDoc({
  500. pointType : this.data.pointType,
  501. projectText : this.data.projectText,
  502. getedPoint : this.data.getedPoint
  503. }, identityDn )
  504. }.bind(this));