Utils.java 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716
  1. package com.jtgh.yjpt.common;
  2. import java.io.IOException;
  3. import java.io.PrintWriter;
  4. import java.io.StringWriter;
  5. import java.lang.reflect.Field;
  6. import java.lang.reflect.Modifier;
  7. import java.math.BigDecimal;
  8. import java.math.RoundingMode;
  9. import java.security.MessageDigest;
  10. import java.security.NoSuchAlgorithmException;
  11. import java.text.SimpleDateFormat;
  12. import java.util.ArrayList;
  13. import java.util.Calendar;
  14. import java.util.Date;
  15. import java.util.HashMap;
  16. import java.util.Iterator;
  17. import java.util.List;
  18. import java.util.Locale;
  19. import java.util.ResourceBundle;
  20. import javax.persistence.criteria.CriteriaBuilder;
  21. import javax.persistence.criteria.CriteriaQuery;
  22. import javax.persistence.criteria.Predicate;
  23. import javax.persistence.criteria.Root;
  24. import javax.persistence.criteria.Subquery;
  25. import javax.servlet.http.HttpServletRequest;
  26. import javax.servlet.http.HttpSession;
  27. import org.springframework.jdbc.core.JdbcTemplate;
  28. import org.springframework.jdbc.support.rowset.SqlRowSet;
  29. import org.springframework.stereotype.Component;
  30. import org.springframework.util.StringUtils;
  31. import org.springframework.web.context.request.RequestContextHolder;
  32. import org.springframework.web.context.request.ServletRequestAttributes;
  33. import sun.misc.BASE64Decoder;
  34. import sun.misc.BASE64Encoder;
  35. import com.jtgh.qlyg.entity.ApplyFormItem;
  36. import com.jtgh.yjpt.common.servlet.InitServlet;
  37. import com.jtgh.yjpt.entity.BaseEntity;
  38. import com.jtgh.yjpt.entity.auth.UserEntity;
  39. import com.jtgh.yjpt.entity.common.AccessoryEntity;
  40. import com.jtgh.yjpt.entity.common.CodeEntity;
  41. import com.jtgh.yjpt.entity.common.TaskInfoEntity;
  42. import com.jtgh.yjpt.entity.qlyg.ApplyEntity;
  43. import com.jtgh.yjpt.entity.qlyg.ApplyProcessEntity;
  44. import com.jtgh.yjpt.webService.common.AuthHandler;
  45. import flex.messaging.FlexContext;
  46. /**
  47. * 系统静态工具方法类。
  48. */
  49. @Component
  50. public abstract class Utils {
  51. /**
  52. * 比较密码是否一致
  53. *
  54. * @param pwd
  55. * @param md5Pwd
  56. * @return
  57. */
  58. public static boolean pwdEquals(String pwd, String md5Pwd) {
  59. if (pwd == null || md5Pwd == null)
  60. return false;
  61. return md5Pwd.equals(encrypt(pwd));
  62. }
  63. /**
  64. * 返回MD5加密后的密码
  65. *
  66. * @param pwd
  67. * @return
  68. */
  69. public static String encrypt(String password) {
  70. String str = "";
  71. try {
  72. MessageDigest md = MessageDigest.getInstance("MD5");
  73. md.update(password.getBytes());
  74. byte b[] = md.digest();
  75. int i;
  76. StringBuffer buf = new StringBuffer("");
  77. for (int offset = 0; offset < b.length; offset++) {
  78. i = b[offset];
  79. if (i < 0)
  80. i += 256;
  81. if (i < 16)
  82. buf.append("0");
  83. buf.append(Integer.toHexString(i));
  84. }
  85. str = buf.toString();
  86. } catch (NoSuchAlgorithmException e) {
  87. e.printStackTrace();
  88. }
  89. return str;
  90. }
  91. /**
  92. * 二进制流解析为字符串
  93. *
  94. * @param content
  95. * @return
  96. */
  97. public static String encodeBase64(byte[] content) {
  98. BASE64Encoder encoder = new BASE64Encoder();
  99. return encoder.encode(content);
  100. }
  101. /**
  102. * 字符串解析为二进制流
  103. *
  104. * @param content
  105. * @return
  106. */
  107. public static byte[] decodeBase64(String content) {
  108. BASE64Decoder decoder = new BASE64Decoder();
  109. try {
  110. return decoder.decodeBuffer(content);
  111. } catch (IOException e) {
  112. e.printStackTrace();
  113. }
  114. return null;
  115. }
  116. /**
  117. * 获取资源文件
  118. *
  119. * @param bundle
  120. * 包名
  121. * @param key
  122. * @return
  123. */
  124. public static String getResource(String bundle, String key) {
  125. ResourceBundle resource = ResourceBundle.getBundle(Locale.getDefault()
  126. .toString() + "/" + bundle, Locale.getDefault(),
  127. Utils.class.getClassLoader());
  128. if (resource.containsKey(key))
  129. return resource.getString(key);
  130. return key;
  131. }
  132. /**
  133. * 服务器端判断客户端浏览器类型(IE/FF/SF)
  134. *
  135. * @param request
  136. * @return
  137. */
  138. public static String getBrowser(HttpServletRequest request) {
  139. String UserAgent = request.getHeader("USER-AGENT").toLowerCase();
  140. if (UserAgent != null) {
  141. if (UserAgent.indexOf("msie") >= 0)
  142. return "IE";
  143. if (UserAgent.indexOf("firefox") >= 0)
  144. return "FF";
  145. if (UserAgent.indexOf("safari") >= 0)
  146. return "SF";
  147. }
  148. return null;
  149. }
  150. /**
  151. * 根据开始日期和时间段,得到到期日
  152. *
  153. * @param startDate
  154. * @param during
  155. * @param type
  156. * 承诺时限单位(0天/1工作日/2月/3年)
  157. * @return
  158. */
  159. public static Date getDueDate(Date startDate, Integer during, String type) {
  160. if (startDate == null)
  161. return null;
  162. JdbcTemplate jdbcTemplate = (JdbcTemplate) ApplicationContextHelper
  163. .getBean(JdbcTemplate.class);
  164. if (during == null)
  165. during = 0;
  166. Calendar c = Calendar.getInstance();
  167. c.setTime(startDate);
  168. if (Constants.QLYG_APPLY_PROMISE_TYPE_DAY.equals(type)) {
  169. // 按天计算
  170. c.add(Calendar.DATE, during);
  171. } else if (Constants.QLYG_APPLY_PROMISE_TYPE_WORKING_DAY.equals(type)) {
  172. // 按工作日计算
  173. String sql = "SELECT 1 FROM T_YJPT_WORKING_CALENDAR WHERE WORKING_DATE=? AND IS_WORKING=?";
  174. SimpleDateFormat sf = new SimpleDateFormat("yyyyMMdd");
  175. while (during > 0) {
  176. String date = sf.format(c.getTime());
  177. if (c.get(Calendar.DAY_OF_WEEK) == Calendar.SATURDAY
  178. || c.get(Calendar.DAY_OF_WEEK) == Calendar.SUNDAY) {
  179. SqlRowSet rs = jdbcTemplate.queryForRowSet(sql, date,
  180. Constants.YES);
  181. if (rs.next()) {
  182. during--;
  183. }
  184. c.add(Calendar.DATE, 1);
  185. } else {
  186. SqlRowSet rs = jdbcTemplate.queryForRowSet(sql, date,
  187. Constants.NO);
  188. if (!rs.next()) {
  189. during--;
  190. }
  191. c.add(Calendar.DATE, 1);
  192. }
  193. }
  194. } else if (Constants.QLYG_APPLY_PROMISE_TYPE_MONTH.equals(type)) {
  195. // 按月计算
  196. c.add(Calendar.MONTH, during);
  197. } else if (Constants.QLYG_APPLY_PROMISE_TYPE_YEAR.equals(type)) {
  198. // 按年计算
  199. c.add(Calendar.YEAR, during);
  200. }
  201. return c.getTime();
  202. }
  203. /**
  204. * 根据开始日期和时间段,得到预警日期4/5
  205. *
  206. * @param startDate
  207. * @param during
  208. * @param type
  209. * 承诺时限单位(0天/1工作日/2月/3年)
  210. * @return
  211. */
  212. public static Date getWarnDate(Date startDate, Integer during, String type) {
  213. if (startDate == null)
  214. return null;
  215. if (during == null)
  216. during = 0;
  217. during = BigDecimal.valueOf(during * 0.8)
  218. .setScale(0, RoundingMode.CEILING).intValue();
  219. return getDueDate(startDate, during, type);
  220. }
  221. /**
  222. * 根据配置文件设置办件信息
  223. *
  224. * @param entity
  225. * @param processKey
  226. */
  227. public static void setApplyProperties(ApplyEntity entity, String processKey) {
  228. HashMap<String, Object> applyMap = GlobalData.qlygApplyMap
  229. .get(processKey);
  230. if (applyMap == null)
  231. return;
  232. Iterator<String> it = applyMap.keySet().iterator();
  233. while (it.hasNext()) {
  234. String key = it.next();
  235. try {
  236. ApplyEntity.class.getMethod(
  237. "set" + key.toUpperCase().substring(0, 1)
  238. + key.substring(1),
  239. applyMap.get(key).getClass()).invoke(entity,
  240. applyMap.get(key));
  241. } catch (Exception e) {
  242. e.printStackTrace();
  243. }
  244. }
  245. String orgId = Utils.getCurrentUser().getSzd().getByzd4();
  246. // 部门编码
  247. entity.setOrgId(orgId + "JT");
  248. // 权力编码前面10位的部门编号是所在地的备用字段4
  249. if (!StringUtils.isEmpty(entity.getItemId())) {
  250. entity.setItemId(orgId + "JT-" + entity.getItemId());
  251. }
  252. // 办理处室使用所在地的备用字段5
  253. entity.setDepartment(getCurrentUser().getSzd().getByzd5());
  254. }
  255. /**
  256. * 根据配置文件设置办件过程信息
  257. *
  258. * @param entity
  259. * @param processKey
  260. */
  261. public static void setApplyItemProperties(ApplyProcessEntity entity,
  262. String processKey, String taskKey) {
  263. HashMap<String, HashMap<String, Object>> applyMap = GlobalData.qlygApplyItemMap
  264. .get(processKey);
  265. if (applyMap == null)
  266. return;
  267. HashMap<String, Object> applyItemMap = applyMap.get(taskKey);
  268. if (applyItemMap == null)
  269. return;
  270. Iterator<String> it = applyItemMap.keySet().iterator();
  271. while (it.hasNext()) {
  272. String key = it.next();
  273. try {
  274. ApplyProcessEntity.class.getMethod(
  275. "set" + key.toUpperCase().substring(0, 1)
  276. + key.substring(1),
  277. applyItemMap.get(key).getClass()).invoke(entity,
  278. applyItemMap.get(key));
  279. } catch (Exception e) {
  280. e.printStackTrace();
  281. }
  282. }
  283. }
  284. /**
  285. * 根据配置文件生成办件基本信息form
  286. *
  287. * @param entity
  288. * @param processKey
  289. * @return
  290. */
  291. public static String getApplyForm(BaseEntity<?> entity, String processKey) {
  292. StringBuffer sb = new StringBuffer();
  293. sb.append("<?XML VERSION=\"1.0\" ENCODING=\"GBK\"?><FORMDATA>");
  294. if (processKey != null
  295. && GlobalData.qlygApplyFormMap.get(processKey) != null) {
  296. List<ApplyFormItem> list = (List<ApplyFormItem>) GlobalData.qlygApplyFormMap
  297. .get(processKey);
  298. if (list != null && list.size() > 0) {
  299. for (ApplyFormItem formItem : list) {
  300. sb.append("<DATA>");
  301. sb.append("<KEY>");
  302. sb.append(formItem.getKey());
  303. sb.append("</KEY>");
  304. sb.append("<NAME>");
  305. sb.append(formItem.getName());
  306. sb.append("</NAME>");
  307. sb.append("<VALUE>");
  308. try {
  309. if (formItem.getId() != null) {
  310. Object parentObj = entity;
  311. String[] props = formItem.getId().split("\\.");
  312. for (String prop : props) {
  313. Object obj = parentObj
  314. .getClass()
  315. .getMethod(
  316. "get"
  317. + prop.toUpperCase()
  318. .substring(0, 1)
  319. + prop.substring(1))
  320. .invoke(parentObj);
  321. parentObj = obj;
  322. if (parentObj == null) {
  323. break;
  324. }
  325. }
  326. if (parentObj == null) {
  327. // 空值
  328. } else if ("date".equals(formItem.getType())) {
  329. Date d = (Date) parentObj;
  330. sb.append(new SimpleDateFormat(
  331. "yyyy-MM-dd HH:mm:ss").format(d));
  332. } else {
  333. if (!StringUtils.isEmpty(formItem.getLocale())) {
  334. sb.append(getResource(formItem.getLocale(),
  335. parentObj.toString()));
  336. } else {
  337. sb.append(parentObj.toString());
  338. }
  339. }
  340. }
  341. } catch (Exception e) {
  342. e.printStackTrace();
  343. }
  344. sb.append("</VALUE>");
  345. sb.append("</DATA>");
  346. }
  347. }
  348. }
  349. sb.append("</FORMDATA>");
  350. return sb.toString();
  351. }
  352. /**
  353. * 设置对象属性
  354. *
  355. * @param obj
  356. * @param params
  357. * @param name
  358. * @param clazz
  359. */
  360. public static void setField(Object obj, Object params, String name,
  361. Class<?> clazz) {
  362. try {
  363. Field fld = clazz.getDeclaredField(name);
  364. int mod = fld.getModifiers();
  365. if (null == obj && Modifier.isStatic(mod)) {
  366. if (!Modifier.isFinal(mod)) {
  367. if (!fld.isAccessible())
  368. fld.setAccessible(true);
  369. fld.set(null, params);
  370. }
  371. } else {
  372. if (!fld.isAccessible())
  373. fld.setAccessible(true);
  374. fld.set(obj, params);
  375. }
  376. } catch (SecurityException e) {
  377. e.printStackTrace();
  378. } catch (NoSuchFieldException e) {
  379. e.printStackTrace();
  380. } catch (IllegalArgumentException e) {
  381. e.printStackTrace();
  382. } catch (IllegalAccessException e) {
  383. e.printStackTrace();
  384. }
  385. }
  386. /**
  387. * 获取session
  388. *
  389. * @return
  390. */
  391. public static HttpSession getSession() {
  392. if (FlexContext.getHttpRequest() != null) {
  393. HttpSession session = FlexContext.getHttpRequest().getSession();
  394. // System.out.println("Flex session id:" + session.getId());
  395. // flex客户端取session
  396. return session;
  397. }
  398. if (RequestContextHolder.getRequestAttributes() != null) {
  399. HttpSession session = ((ServletRequestAttributes) RequestContextHolder
  400. .getRequestAttributes()).getRequest().getSession();
  401. // System.out.println("Http session id:" + session.getId());
  402. return session;
  403. }
  404. return null;
  405. }
  406. public static Long JunitUserId = 1l;
  407. /**
  408. * 获取当前登录人
  409. *
  410. * @return
  411. */
  412. public static UserEntity getCurrentUser() {
  413. if (GlobalData.isJunit) {
  414. UserEntity testUser = new UserEntity();
  415. testUser.setId(JunitUserId);
  416. testUser.setCode("user_junit");
  417. testUser.setName("junit用户");
  418. return testUser;
  419. }
  420. HttpSession session = getSession();
  421. if (session == null) {
  422. if (AuthHandler.getCurrentUser() != null) {
  423. return AuthHandler.getCurrentUser();
  424. }
  425. return null;
  426. }
  427. Object user = session.getAttribute(GlobalData.USER_SESSION_KEY);
  428. return (UserEntity) user;
  429. }
  430. /**
  431. * WebService登录用户
  432. *
  433. * @return
  434. */
  435. public static UserEntity getWebServiceUser() {
  436. if (AuthHandler.getCurrentUser() != null) {
  437. return AuthHandler.getCurrentUser();
  438. }
  439. return null;
  440. }
  441. /**
  442. * 获取当前登录人姓名
  443. *
  444. * @return
  445. */
  446. public static String getCurrentUserCode() {
  447. HttpSession session = getSession();
  448. if (session != null) {
  449. Object user = session.getAttribute(GlobalData.USER_SESSION_KEY);
  450. if (user != null)
  451. return ((UserEntity) user).getCode();
  452. }
  453. return "";
  454. }
  455. /**
  456. * 获取当前登录人姓名
  457. *
  458. * @return
  459. */
  460. public static String getCurrentUserName() {
  461. HttpSession session = getSession();
  462. if (session != null) {
  463. Object user = session.getAttribute(GlobalData.USER_SESSION_KEY);
  464. if (user != null)
  465. return ((UserEntity) user).getName();
  466. }
  467. return "";
  468. }
  469. /**
  470. * 获取当前登录人所在地id
  471. *
  472. * @return
  473. */
  474. public static Long getCurrentUserSzd() {
  475. HttpSession session = getSession();
  476. if (session != null) {
  477. Object user = session.getAttribute(GlobalData.USER_SESSION_KEY);
  478. if (user != null && ((UserEntity) user).getSzd()!=null)
  479. return ((UserEntity) user).getSzd().getId();
  480. }
  481. return 0l;
  482. }
  483. /**
  484. * 根据所属区域代码获得webservice的ip
  485. *
  486. * @param ssqyId
  487. * @return
  488. */
  489. public static String getWsIpBySsqy(Long ssqyId) {
  490. if (ssqyId == null)
  491. return "";
  492. String wsIp = "";
  493. if (InitServlet.groupcodeMap.get(Constants.GROUP_CODE_SZD_WS_IP) != null) {
  494. List<CodeEntity> ips = InitServlet.groupcodeMap
  495. .get(Constants.GROUP_CODE_SZD_WS_IP);
  496. for (CodeEntity ip : ips) {
  497. if (ip.getParent() != null
  498. && ssqyId.toString().indexOf(
  499. ip.getParent().getId().toString()) == 0) {
  500. wsIp = ip.getCode();
  501. break;
  502. }
  503. }
  504. }
  505. return wsIp;
  506. }
  507. /**
  508. * 根据所属区域代码获得webservice的port
  509. *
  510. * @param ssqyId
  511. * @return
  512. */
  513. public static String getWsPortBySsqy(Long ssqyId) {
  514. if (ssqyId == null)
  515. return "";
  516. String wsPort = "";
  517. if (InitServlet.groupcodeMap.get(Constants.GROUP_CODE_SZD_WS_PORT) != null) {
  518. List<CodeEntity> ports = InitServlet.groupcodeMap
  519. .get(Constants.GROUP_CODE_SZD_WS_PORT);
  520. for (CodeEntity port : ports) {
  521. if (port.getParent() != null
  522. && ssqyId.toString().indexOf(
  523. port.getParent().getId().toString()) == 0) {
  524. wsPort = port.getCode();
  525. break;
  526. }
  527. }
  528. }
  529. return wsPort;
  530. }
  531. /**
  532. * 返回当前角色的上级角色
  533. *
  534. * @param currRole
  535. * @return
  536. */
  537. public static String getParentRole(String currRole) {
  538. if (StringUtils.isEmpty(currRole)
  539. || currRole.length() <= Constants.ROLE_LENGTH) {
  540. return "";
  541. }
  542. return currRole.substring(0, currRole.length() - Constants.ROLE_LENGTH);
  543. }
  544. public static List<Predicate> setWorkflowSpec(List<Predicate> list,
  545. CriteriaBuilder cb, CriteriaQuery<?> query,
  546. Root<? extends BaseEntity<?>> root, String lcStatus) {
  547. // 根据流程状态过滤
  548. if (null != lcStatus && !"".equals(lcStatus)) {
  549. if (String.valueOf(BaseEntity.RECORD_STATE_VALID).equals(lcStatus)
  550. || String.valueOf(BaseEntity.RECORD_STATE_COMPLETED)
  551. .equals(lcStatus)) {
  552. list.add(cb.equal(root.get("recordStatus").as(String.class),
  553. lcStatus));
  554. } else {
  555. Subquery<TaskInfoEntity> subquery = query
  556. .subquery(TaskInfoEntity.class);
  557. Root<TaskInfoEntity> taskRoot = subquery
  558. .from(TaskInfoEntity.class);
  559. subquery.select(taskRoot);
  560. List<Predicate> subQueryPredicates = new ArrayList<Predicate>();
  561. subQueryPredicates.add(cb.equal(
  562. root.get("id").as(String.class), taskRoot.get("busId")
  563. .as(String.class)));
  564. subQueryPredicates.add(cb.equal(
  565. taskRoot.get("currName").as(String.class), lcStatus));
  566. subQueryPredicates.add(cb.notEqual(
  567. taskRoot.get("state").as(Long.class),
  568. BaseEntity.RECORD_STATE_COMPLETED));
  569. // List<Predicate> subOrList = new
  570. // ArrayList<Predicate>();
  571. // subOrList.add(cb.equal(taskRoot
  572. // .get("roleCode").as(String.class),
  573. // getCurrentRoleCode(functionId)));
  574. // subOrList.add(cb.equal(taskRoot
  575. // .get("runner").as(UserEntity.class),
  576. // Utils.getCurrentUser()));
  577. // subQueryPredicates.add(cb.or(subOrList.toArray(new
  578. // Predicate[] {})));
  579. subquery.where(subQueryPredicates.toArray(new Predicate[] {}));
  580. list.add(cb.exists(subquery));
  581. }
  582. }
  583. return setQykjSpec(list,cb,query,root);
  584. }
  585. /**
  586. * 区域可见
  587. * @param list
  588. * @param cb
  589. * @param query
  590. * @param root
  591. * @return
  592. */
  593. public static List<Predicate> setQykjSpec(List<Predicate> list,
  594. CriteriaBuilder cb, CriteriaQuery<?> query,
  595. Root<? extends BaseEntity<?>> root) {
  596. List<Predicate> subOrList = new ArrayList<Predicate>();
  597. // 兼容空
  598. subOrList.add(cb.isNull(root.get("ssqy").as(Long.class)));
  599. // 省市级皆可见
  600. subOrList.add(cb.equal(root.get("ssqy").as(Long.class),
  601. Constants.SSQY_ALL));
  602. if (getCurrentUserSzd().equals(Constants.SZD_ID_PROVINCE)) {
  603. // 省级可见
  604. subOrList.add(cb.equal(root.get("ssqy").as(Long.class),
  605. Constants.SSQY_PROVINCE));
  606. } else {
  607. // 市级可见
  608. subOrList.add(cb.equal(root.get("ssqy").as(Long.class),
  609. Constants.SSQY_CITY));
  610. }
  611. list.add(cb.or(subOrList.toArray(new Predicate[] {})));
  612. return list;
  613. }
  614. /**
  615. * 将传入的附件拼成固定格式的String返回
  616. */
  617. public static String getWord(List<AccessoryEntity> list) {
  618. StringBuffer sbf = new StringBuffer();
  619. String str = "<?XML VERSION=\"1.0\" ENCODING=\"GBK\"?><DOCUMENTDATA>";
  620. sbf.append(str);
  621. if (list != null && list.size() > 0) {
  622. for (AccessoryEntity accessoryEntity : list) {
  623. sbf.append("<DOCUMENT>");
  624. sbf.append("<DOCUMENT_ID>").append(accessoryEntity.getId())
  625. .append("</DOCUMENT_ID>");
  626. sbf.append("<DOCUMENT_NAME>")
  627. .append(getResource("fileType", accessoryEntity
  628. .getType().getName()))
  629. .append("</DOCUMENT_NAME>");
  630. sbf.append("<FILE_NAME>").append(accessoryEntity.getName())
  631. .append("</FILE_NAME>");
  632. sbf.append("<FILE_CONTENT>")
  633. .append(encodeBase64(accessoryEntity.getContent()
  634. .getValue())).append("</FILE_CONTENT>");
  635. sbf.append("</DOCUMENT>");
  636. }
  637. }
  638. sbf.append("</DOCUMENTDATA>");
  639. return sbf.toString();
  640. }
  641. /**
  642. * 该天最早的时候
  643. *
  644. * @param date
  645. * @return
  646. */
  647. public static Date getDateFirstTime(Date date) {
  648. if (null == date) {
  649. return null;
  650. }
  651. Calendar c = Calendar.getInstance();
  652. c.setTime(date);
  653. c.set(java.util.Calendar.HOUR_OF_DAY, 0);
  654. c.set(java.util.Calendar.MINUTE, 0);
  655. c.set(java.util.Calendar.SECOND, 0);
  656. return c.getTime();
  657. }
  658. /**
  659. * 该天最迟的时候
  660. *
  661. * @param date
  662. * @return
  663. */
  664. public static Date getDateLastTime(Date date) {
  665. if (null == date) {
  666. return null;
  667. }
  668. Calendar c = Calendar.getInstance();
  669. c.setTime(date);
  670. c.set(java.util.Calendar.HOUR_OF_DAY, 23);
  671. c.set(java.util.Calendar.MINUTE, 59);
  672. c.set(java.util.Calendar.SECOND, 59);
  673. return c.getTime();
  674. }
  675. public static String getExeMsg(Throwable t) {
  676. StringWriter sw = new StringWriter();
  677. t.printStackTrace(new PrintWriter(sw));
  678. return sw.toString();
  679. }
  680. }