materialsexcel.jsp 10.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371
  1. <%@ page language="java" contentType="text/html; charset=gbk"%>
  2. <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
  3. <%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
  4. <%@ page import="com.kpt.common.Util" %>
  5. <%@page import="java.util.List"%>
  6. <%@page import="java.util.Map"%>
  7. <%@page import="java.util.Date"%>
  8. <%@page import="java.util.ArrayList"%>
  9. <%@page import="java.math.BigDecimal"%>
  10. <html xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:x="urn:schemas-microsoft-com:office:excel" xmlns="http://www.w3.org/TR/REC-html40">
  11. <meta http-equiv="Content-Type" content="text/html; charset=GBK" />
  12. <%
  13. String str = Util.getHeaderType(request,"用料分析");
  14. response.setContentType("application/vnd.ms-excel;charset=gbk");response.setHeader("Content-disposition",str);
  15. %>
  16. <head>
  17. <style>
  18. .STYLE1 {color: #FFFFFF}
  19. </style>
  20. <!--[if gte mso 9]><xml>
  21. <x:ExcelWorkbook>
  22. <x:ExcelWorksheets>
  23. <x:ExcelWorksheet>
  24. <x:Name>readers</x:Name>
  25. <x:WorksheetOptions>
  26. <x:Print>
  27. <x:ValidPrinterInfo />
  28. </x:Print>
  29. </x:WorksheetOptions>
  30. </x:ExcelWorksheet>
  31. </x:ExcelWorksheets>
  32. </x:ExcelWorkbook>
  33. </xml><![endif]-->
  34. </head>
  35. <body style="margin:0";>
  36. <div class="content">
  37. <table cellspacing="1" cellpadding="0" border="0" style="width:1400px;" class="tabsty">
  38. <tbody>
  39. <tr align="center" style="height: 25px;">
  40. <th>饲料名称</th>
  41. <c:if test="${tjTarget == 0}">
  42. <c:forEach var="feed" items="${feedlist}">
  43. <th colspan="2"><c:out value="${feed.FNAME}" /></th>
  44. </c:forEach>
  45. <th colspan="2">合计</th>
  46. </c:if>
  47. <c:if test="${tjTarget != 0}">
  48. <c:forEach var="feed" items="${feedlist}">
  49. <th><c:out value="${feed.FNAME}" /></th>
  50. </c:forEach>
  51. <th>合计</th>
  52. </c:if>
  53. </tr>
  54. <tr align="center" style="height: 25px;">
  55. <c:if test="${tjType == 0}">
  56. <th>舍栏类别</th>
  57. </c:if>
  58. <c:if test="${tjType == 1}">
  59. <th>舍栏</th>
  60. </c:if>
  61. <c:if test="${tjType == 2}">
  62. <th>日期</th>
  63. </c:if>
  64. <c:if test="${tjType == 3}">
  65. <th>TM</th>
  66. </c:if>
  67. <c:if test="${tjType == 4}">
  68. <th>班次</th>
  69. </c:if>
  70. <c:if test="${tjType == 5}">
  71. <th>车次</th>
  72. </c:if>
  73. <c:if test="${tjTarget == 0}">
  74. <c:forEach var="feed" items="${feedlist}">
  75. <th>理论</th>
  76. <th>实际</th>
  77. </c:forEach>
  78. <th>理论</th>
  79. <th>实际</th>
  80. </c:if>
  81. <c:if test="${tjTarget == 1}">
  82. <c:forEach var="feed" items="${feedlist}">
  83. <th>理论</th>
  84. </c:forEach>
  85. <th>理论</th>
  86. </c:if>
  87. <c:if test="${tjTarget == 2}">
  88. <c:forEach var="feed" items="${feedlist}">
  89. <th>实际</th>
  90. </c:forEach>
  91. <th>实际</th>
  92. </c:if>
  93. </tr>
  94. <%
  95. List list = (List) request.getAttribute("list");
  96. List feedlist = (List) request.getAttribute("feedlist");
  97. String tjType = (String) request.getAttribute("tjType");
  98. String tjTarget = (String) request.getAttribute("tjTarget");
  99. String strname = "";
  100. if(list.size() == 1){
  101. Map strnameMap = (Map)list.get(0);
  102. strname = (String)strnameMap.get("1");
  103. }
  104. if(list.size() > 0 && !"1".equals(strname)){
  105. //动态列头数组
  106. int fsize = feedlist.size();
  107. if("0".equals(tjTarget)){
  108. fsize = fsize*2;
  109. }
  110. Double[] feedstr = new Double[fsize];
  111. //动态合计值数组
  112. Double[] liststr;
  113. if("0".equals(tjTarget)){
  114. liststr = new Double[2];
  115. }else{
  116. liststr = new Double[1];
  117. }
  118. for (int i = 0; i < list.size(); i++) {
  119. int c = 0;
  120. int listC = 0;
  121. Map map = (Map) list.get(i);
  122. if("0".equals(tjType)){
  123. String n1 = (String)map.get("舍栏类别");
  124. %>
  125. <tr align="center" class="greb" style="height: 25px;">
  126. <td><c:out value="<%=n1 %>"/></td>
  127. <%
  128. }else if("1".equals(tjType)){
  129. String n1 = (String)map.get("舍栏");
  130. %>
  131. <tr align="center" class="greb" style="height: 25px;">
  132. <td><c:out value="<%=n1 %>"/></td>
  133. <%
  134. }else if("2".equals(tjType)){
  135. Date d1 = (Date)map.get("日期");
  136. %>
  137. <tr align="center" class="greb" style="height: 25px;">
  138. <td><c:out value="<%=d1 %>"/></td>
  139. <%
  140. }else if("3".equals(tjType)){
  141. String n1 = (String)map.get("TMR");
  142. %>
  143. <tr align="center" class="greb" style="height: 25px;">
  144. <td><c:out value="<%=n1 %>"/></td>
  145. <%
  146. }else if("4".equals(tjType)){
  147. String bc = "";
  148. Integer n1 = (Integer)map.get("班次");
  149. if(n1 == 1){
  150. bc = "早班1";
  151. }else if(n1 == 2){
  152. bc = "早班2";
  153. }else if(n1 == 3){
  154. bc = "中班1";
  155. }else if(n1 == 4){
  156. bc = "中班2";
  157. }else if(n1 == 5){
  158. bc = "晚班1";
  159. }else{
  160. bc = "晚班2";
  161. }
  162. %>
  163. <tr align="center" class="greb" style="height: 25px;">
  164. <td><c:out value="<%=bc %>"/></td>
  165. <%
  166. }else if("5".equals(tjType)){
  167. String n1 = (String)map.get("车次");
  168. %>
  169. <tr align="center" class="greb" style="height: 25px;">
  170. <td><c:out value="<%=n1 %>"/></td>
  171. <%
  172. }
  173. if("0".equals(tjTarget)){
  174. for (int j = 0; j < feedlist.size(); j++){
  175. Map fmap = (Map) feedlist.get(j);
  176. String fname = (String)fmap.get("FNAME");
  177. String fname1 = fname+"|理论";
  178. String fname2 = fname+"|实际";
  179. Double newname1 = (Double)map.get(fname1);
  180. Double newname2 = (Double)map.get(fname2);
  181. if(newname1 != null && newname2 != null){
  182. BigDecimal bg = new BigDecimal(newname1);
  183. newname1 = bg.setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue();
  184. BigDecimal bg1 = new BigDecimal(newname2);
  185. newname2 = bg1.setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue();
  186. if(feedstr[c]==null){
  187. feedstr[c] = newname1;
  188. }else{
  189. feedstr[c] += newname1;
  190. }
  191. c++;
  192. if(feedstr[c]==null){
  193. feedstr[c] = newname2;
  194. }else{
  195. feedstr[c] += newname2;
  196. }
  197. c++;
  198. %>
  199. <td><c:out value="<%=newname1 %>"/></td>
  200. <td><c:out value="<%=newname2 %>"/></td>
  201. <%
  202. }else{
  203. if(feedstr[c]==null){
  204. feedstr[c] = 0.0;
  205. }else{
  206. feedstr[c] += 0.0;
  207. }
  208. c++;
  209. if(feedstr[c]==null){
  210. feedstr[c] = 0.0;
  211. }else{
  212. feedstr[c] += 0.0;
  213. }
  214. c++;
  215. %>
  216. <td>0.0</td>
  217. <td>0.0</td>
  218. <%
  219. }
  220. }
  221. BigDecimal sum1 = (BigDecimal)map.get("合计|理论");
  222. BigDecimal sum2 = (BigDecimal)map.get("合计|实际");
  223. if(liststr[listC]==null){
  224. liststr[listC] = sum1.doubleValue();
  225. }else{
  226. liststr[listC] += sum1.doubleValue();
  227. }
  228. listC++;
  229. if(liststr[listC]==null){
  230. liststr[listC] = sum2.doubleValue();
  231. }else{
  232. liststr[listC] += sum2.doubleValue();
  233. }
  234. listC++;
  235. %>
  236. <td><c:out value="<%=sum1 %>"/></td>
  237. <td><c:out value="<%=sum2 %>"/></td>
  238. </tr>
  239. <%
  240. }else if("1".equals(tjTarget)){
  241. for (int j = 0; j < feedlist.size(); j++){
  242. Map fmap = (Map) feedlist.get(j);
  243. String fname = (String)fmap.get("FNAME");
  244. String fname1 = fname+"|理论";
  245. Double newname1 = (Double)map.get(fname1);
  246. if(newname1 != null){
  247. BigDecimal bg = new BigDecimal(newname1);
  248. newname1 = bg.setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue();
  249. if(feedstr[c]==null){
  250. feedstr[c] = newname1;
  251. }else{
  252. feedstr[c] += newname1;
  253. }
  254. c++;
  255. %>
  256. <td><c:out value="<%=newname1 %>"/></td>
  257. <%
  258. }else{
  259. if(feedstr[c]==null){
  260. feedstr[c] = 0.0;
  261. }else{
  262. feedstr[c] += 0.0;
  263. }
  264. c++;
  265. %>
  266. <td>0.0</td>
  267. <%
  268. }
  269. }
  270. BigDecimal sum1 = (BigDecimal)map.get("合计|理论");
  271. if(liststr[listC]==null){
  272. liststr[listC] = sum1.doubleValue();
  273. }else{
  274. liststr[listC] += sum1.doubleValue();
  275. }
  276. listC++;
  277. %>
  278. <td><c:out value="<%=sum1 %>"/></td>
  279. </tr>
  280. <%
  281. }else if("2".equals(tjTarget)){
  282. for (int j = 0; j < feedlist.size(); j++){
  283. Map fmap = (Map) feedlist.get(j);
  284. String fname = (String)fmap.get("FNAME");
  285. String fname1 = fname+"|实际";
  286. Double newname1 = (Double)map.get(fname1);
  287. if(newname1 != null){
  288. BigDecimal bg = new BigDecimal(newname1);
  289. newname1 = bg.setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue();
  290. if(feedstr[c]==null){
  291. feedstr[c] = newname1;
  292. }else{
  293. feedstr[c] += newname1;
  294. }
  295. c++;
  296. %>
  297. <td><c:out value="<%=newname1 %>"/></td>
  298. <%
  299. }else{
  300. if(feedstr[c]==null){
  301. feedstr[c] = 0.0;
  302. }else{
  303. feedstr[c] += 0.0;
  304. }
  305. c++;
  306. %>
  307. <td>0.0</td>
  308. <%
  309. }
  310. }
  311. BigDecimal sum1 = (BigDecimal)map.get("合计|实际");
  312. if(liststr[listC]==null){
  313. liststr[listC] = sum1.doubleValue();
  314. }else{
  315. liststr[listC] += sum1.doubleValue();
  316. }
  317. listC++;
  318. %>
  319. <td><c:out value="<%=sum1 %>"/></td>
  320. </tr>
  321. <%
  322. }
  323. }
  324. %>
  325. <tr align="center" class="greb" style="height: 25px;">
  326. <td><c:out value="合计"/></td>
  327. <%
  328. for (int k = 0; k < feedstr.length; k++){
  329. String newF = String.format("%.2f", feedstr[k]);
  330. %>
  331. <td><c:out value="<%=newF %>"/></td>
  332. <%
  333. }
  334. for (int t = 0; t < liststr.length; t++){
  335. String newL = String.format("%.2f", liststr[t]);
  336. %>
  337. <td><c:out value="<%=newL %>"/></td>
  338. <%
  339. }
  340. %>
  341. </tr>
  342. <%
  343. }else{
  344. if("0".equals(tjTarget)){
  345. %>
  346. <tr align="center" class="greb" style="height: 25px;"><td colspan="${feedlistsize*2+3}">没有对应的结果</td></tr>
  347. <%
  348. }else{
  349. %>
  350. <tr align="center" class="greb" style="height: 25px;"><td colspan="${feedlistsize+2}">没有对应的结果</td></tr>
  351. <%
  352. }
  353. }
  354. %>
  355. </tbody>
  356. </table>
  357. </div>
  358. </body>
  359. </html>