b4ae126706c32e5e0aad1ce72b55b34fbfb51bf1.svn-base 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254
  1. package com.kingdee.shr.customer.gtiit.rpt;
  2. import java.math.BigDecimal;
  3. import java.math.RoundingMode;
  4. import java.sql.SQLException;
  5. import java.util.ArrayList;
  6. import java.util.HashMap;
  7. import java.util.LinkedHashMap;
  8. import java.util.List;
  9. import java.util.Map;
  10. import javax.servlet.http.HttpServletRequest;
  11. import javax.servlet.http.HttpServletResponse;
  12. import org.springframework.ui.ModelMap;
  13. import com.alibaba.fastjson.JSON;
  14. import com.alibaba.fastjson.JSONObject;
  15. import com.cloudera.impala.jdbc4.internal.apache.log4j.Logger;
  16. import com.kingdee.bos.BOSException;
  17. import com.kingdee.bos.Context;
  18. import com.kingdee.eas.util.app.DbUtil;
  19. import com.kingdee.jdbc.rowset.IRowSet;
  20. import com.kingdee.shr.base.syssetting.context.SHRContext;
  21. import com.kingdee.shr.base.syssetting.exception.SHRWebException;
  22. import com.kingdee.shr.base.syssetting.web.handler.ListHandler;
  23. import com.kingdee.shr.base.syssetting.web.json.JSONUtils;
  24. import com.kingdee.shr.customer.gtiit.util.ContractRptUtil;
  25. import com.kingdee.shr.customer.gtiit.util.DateTimeUtils;
  26. import com.kingdee.shr.customer.gtiit.util.ExportUtils;
  27. import com.kingdee.shr.customer.gtiit.util.NewExportUtils;
  28. import com.kingdee.shr.customer.gtiit.util.RptUtils;
  29. /**
  30. * 全部合同报表
  31. * @author ISSUSER
  32. *
  33. */
  34. public class ContractListReportALLListHandler extends ListHandler {
  35. private static Logger logger = Logger.getLogger("com.kingdee.shr.customer.gtiit.rpt.ContractListReportALLListHandler");
  36. Context ctx = SHRContext.getInstance().getContext();
  37. private int totalCount;
  38. public ContractListReportALLListHandler() {
  39. }
  40. public String getGridColModelAction(HttpServletRequest request, HttpServletResponse response, ModelMap modelMap)
  41. throws SHRWebException, BOSException, SQLException {
  42. List<String> colNames = this.getcolNamesAction();
  43. List<Map<String, Object>> colModel = this.getcolModelAction();
  44. LinkedHashMap<String, Object> map = new LinkedHashMap<String, Object>();
  45. map.put("colNames", colNames);
  46. map.put("colModel", colModel);
  47. JSONUtils.writeJson(response, map);
  48. return null;
  49. }
  50. public void getGridDataAction(HttpServletRequest request, HttpServletResponse response, ModelMap modelMap)
  51. throws BOSException, SQLException, SHRWebException {
  52. int rows = Integer.parseInt(request.getParameter("rows"));
  53. int page = Integer.parseInt(request.getParameter("page"));
  54. List<Map<String, Object>> maplist = new ArrayList<Map<String, Object>>();
  55. int num = 0;
  56. // 获取报表查询过滤条件
  57. List<String> qfNames = new ArrayList<>();
  58. qfNames.add("personStatus");
  59. qfNames.add("queryTime");
  60. qfNames.add("workerCategory");
  61. qfNames.add("job");
  62. qfNames.add("contractDate");
  63. String parameter = request.getParameter("fastFilterItems");
  64. JSONObject paramJson = JSON.parseObject(parameter);
  65. Map<String, Object> rptSQLFilterate = RptUtils.getRptSQLFilterate(paramJson, qfNames);
  66. // 获取报表数据源
  67. String sqlInfo = ContractRptUtil.getContractSql(rptSQLFilterate);
  68. IRowSet rs = DbUtil.executeQuery(this.ctx, sqlInfo);
  69. while (rs.next()) {
  70. ++num;
  71. if (num >= rows * (page - 1) + 1 && num <= rows * page) {
  72. Map<String, Object> map = new HashMap<String, Object>();
  73. map.put("PersonNumber", rs.getString("PersonNumber"));
  74. map.put("LastName", rs.getString("LastName"));
  75. map.put("FirstName", rs.getString("FirstName"));
  76. map.put("EnglishName", rs.getString("EnglishName"));
  77. map.put("Department", rs.getString("Department"));
  78. map.put("Position", rs.getString("Positions"));
  79. map.put("JobName", rs.getString("JobName"));
  80. map.put("WorkerCategory", rs.getString("WorkerCategory"));
  81. map.put("PersonType", rs.getString("PersonType"));
  82. map.put("FullorPartTime", rs.getString("FullorPartTime"));
  83. map.put("HireDate", rs.getDate("HireDate") == null ? null
  84. : DateTimeUtils.dateFormat(rs.getDate("HireDate"), "yyyy-MM-dd"));
  85. map.put("ProbationEndDate", rs.getDate("ProbationEndDate") == null ? null
  86. : DateTimeUtils.dateFormat(rs.getDate("ProbationEndDate"), "yyyy-MM-dd"));
  87. map.put("ContractNo", rs.getString("ContractNo"));
  88. map.put("Type", rs.getString("Type"));
  89. map.put("CommencingDate", rs.getDate("CommencingDate") == null ? null
  90. : DateTimeUtils.dateFormat(rs.getDate("CommencingDate"), "yyyy-MM-dd"));
  91. map.put("ExpiredDate", rs.getDate("ExpiredDate") == null ? null
  92. : DateTimeUtils.dateFormat(rs.getDate("ExpiredDate"), "yyyy-MM-dd"));
  93. String YearsOfService = rs.getString("YearsOfService");
  94. BigDecimal bgyears=new BigDecimal(YearsOfService);
  95. //YearsOfService = YearsOfService.substring(0, (YearsOfService.indexOf(".") + 2));
  96. // 四舍五入保留两位
  97. BigDecimal toYearsOfService = bgyears.setScale(2, RoundingMode.HALF_UP);
  98. logger.error("服务年限的保留两位"+toYearsOfService);
  99. System.out.println("服务年限的保留两位"+toYearsOfService);
  100. //YearsOfService = YearsOfService.substring(0, (YearsOfService.indexOf(".") + 2));
  101. map.put("YearsOfService", toYearsOfService.toString());
  102. maplist.add(map);
  103. }
  104. }
  105. this.totalCount = num;
  106. Map<String, Object> gridDataMap = new LinkedHashMap<String, Object>();
  107. if (this.totalCount % rows == 0) {
  108. gridDataMap.put("total", this.totalCount / rows);
  109. } else {
  110. gridDataMap.put("total", this.totalCount / rows + 1);
  111. }
  112. gridDataMap.put("page", page);
  113. gridDataMap.put("records", this.totalCount);
  114. gridDataMap.put("rows", maplist);
  115. JSONUtils.writeJson(response, gridDataMap);
  116. }
  117. public ArrayList<String> getcolNamesAction() throws SHRWebException {
  118. ArrayList<String> list = new ArrayList<String>();
  119. list.add("Person Number 工号");
  120. list.add("Last Name 姓");
  121. list.add("First Name 名");
  122. list.add("English Name 英文名");
  123. list.add("Department 部门名称");
  124. list.add("Position 职位名称");
  125. list.add("Job Name 职务");
  126. list.add("Worker Category 员工类别");
  127. list.add("Person Type 人员类型");
  128. list.add("Full or Part Time 全职或兼职");
  129. list.add("Hire Date 雇佣日期");
  130. list.add("Probation End Date 试用期结束日期");
  131. list.add("Contract/Agreement No. 合同/协议编码");
  132. list.add("Type 类型");
  133. list.add("Commencing Date 开始时间");
  134. list.add("Expired Date 结束时间");
  135. list.add("Service life 服务年限");
  136. return list;
  137. }
  138. public List<Map<String, Object>> getcolModelAction() {
  139. List<Map<String, Object>> modelColList = new ArrayList<Map<String, Object>>();
  140. modelColList.add(this.buildColModelMap("PersonNumber", "Person Number 工号", 120));
  141. modelColList.add(this.buildColModelMap("LastName", "Last Name 姓", 120));
  142. modelColList.add(this.buildColModelMap("FirstName", "First Name 名", 120));
  143. modelColList.add(this.buildColModelMap("EnglishName", "English Name 英文名", 120));
  144. modelColList.add(this.buildColModelMap("Department", "Department 部门名称", 120));
  145. modelColList.add(this.buildColModelMap("Position", "Position 职位名称", 120));
  146. modelColList.add(this.buildColModelMap("JobName", "Job Name 职务", 120));
  147. modelColList.add(this.buildColModelMap("WorkerCategory", "Worker Category 员工类别", 120));
  148. modelColList.add(this.buildColModelMap("PersonType", "Person Type 人员类型", 120));
  149. modelColList.add(this.buildColModelMap("FullorPartTime", "Full or Part Time 全职或兼职", 120));
  150. modelColList.add(this.buildColModelMap("HireDate", "Hire Date 雇佣日期", 120));
  151. modelColList.add(this.buildColModelMap("ProbationEndDate", "Probation End Date 试用期结束日期", 120));
  152. modelColList.add(this.buildColModelMap("ContractNo", "Contract/Agreement No. 合同/协议编码", 120));
  153. modelColList.add(this.buildColModelMap("Type", "Type 类型", 120));
  154. modelColList.add(this.buildColModelMap("CommencingDate", "Commencing Date 开始时间", 120));
  155. modelColList.add(this.buildColModelMap("ExpiredDate", "Expired Date 结束时间", 120));
  156. modelColList.add(this.buildColModelMap("YearsOfService", "Service life 服务年限", 120));
  157. return modelColList;
  158. }
  159. private Map<String, Object> buildColModelMap(String index, String label, int width) {
  160. return this.buildColModelMap(index, label, width, false, false, false);
  161. }
  162. private Map<String, Object> buildColModelMap(String index, String label, int width, boolean rowspan, boolean isKey,
  163. boolean isHedden) {
  164. Map<String, Object> gridIdMap = new LinkedHashMap<String, Object>();
  165. gridIdMap.put("index", index);
  166. gridIdMap.put("name", index);
  167. gridIdMap.put("label", label);
  168. gridIdMap.put("width", width);
  169. if (rowspan) {
  170. gridIdMap.put("rowspan", rowspan);
  171. }
  172. if (isKey) {
  173. gridIdMap.put("key", isKey);
  174. }
  175. if (isHedden) {
  176. gridIdMap.put("hidden", isHedden);
  177. }
  178. return gridIdMap;
  179. }
  180. public String toExcelAction(HttpServletRequest request, HttpServletResponse response, ModelMap modelMap)
  181. throws BOSException, SQLException, SHRWebException {
  182. List<String> qfNames = new ArrayList<>();
  183. qfNames.add("personStatus");
  184. qfNames.add("queryTime");
  185. qfNames.add("workerCategory");
  186. qfNames.add("job");
  187. qfNames.add("contractDate");
  188. String parameter = request.getParameter("fastFilterItems");
  189. JSONObject paramJson = JSON.parseObject(parameter);
  190. Map<String, Object> rptSQLFilterate = RptUtils.getRptSQLFilterate(paramJson, qfNames);
  191. // 获取报表数据源
  192. String sqlInfo = ContractRptUtil.getContractSql(rptSQLFilterate);
  193. IRowSet rs = DbUtil.executeQuery(this.ctx, sqlInfo);
  194. LinkedHashMap<String,String> selectFieldsTypeMap =new LinkedHashMap<String, String>();
  195. String stringType ="String_@";
  196. String dateType ="Date_yyyy/MM/dd";
  197. selectFieldsTypeMap.put("PersonNumber","Number_0_%s");
  198. selectFieldsTypeMap.put("LastName",stringType);
  199. selectFieldsTypeMap.put("FirstName",stringType);
  200. selectFieldsTypeMap.put("EnglishName",stringType);
  201. selectFieldsTypeMap.put("Department",stringType);
  202. selectFieldsTypeMap.put("Positions",stringType);
  203. selectFieldsTypeMap.put("JobName",stringType);
  204. selectFieldsTypeMap.put("WorkerCategory",stringType);
  205. selectFieldsTypeMap.put("PersonType",stringType);
  206. selectFieldsTypeMap.put("FullorPartTime",stringType);
  207. selectFieldsTypeMap.put("HireDate",dateType);
  208. selectFieldsTypeMap.put("ProbationEndDate",dateType);
  209. selectFieldsTypeMap.put("ContractNo",stringType);
  210. selectFieldsTypeMap.put("Type",stringType);
  211. selectFieldsTypeMap.put("CommencingDate",dateType);
  212. selectFieldsTypeMap.put("ExpiredDate",dateType);
  213. selectFieldsTypeMap.put("Yearsofservice","Number_0.0_%s");
  214. // 列名的标题
  215. ArrayList<String> list = new ArrayList<String>();
  216. list.add("Person Number 工号");
  217. list.add("Last Name 姓");
  218. list.add("First Name 名");
  219. list.add("English Name 英文名");
  220. list.add("Department 部门名称");
  221. list.add("Position 职位名称");
  222. list.add("Job Name 职务");
  223. list.add("Worker Category 员工类别");
  224. list.add("Person Type 人员类型");
  225. list.add("Full or Part Time 全职或兼职");
  226. list.add("Hire Date 雇佣日期");
  227. list.add("Probation End Date 试用期结束日期");
  228. list.add("Contract/Agreement No. 合同/协议编码");
  229. list.add("Type 类型");
  230. list.add("Commencing Date 开始时间");
  231. list.add("Expired Date 结束时间");
  232. list.add("Service life 服务年限");
  233. NewExportUtils.exportData(response, rs, "ContractListReportALL.xlsx",selectFieldsTypeMap,list);
  234. return null;
  235. }
  236. }