priceexcel.jsp 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362
  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="${tjTarget == 0}">
  71. <c:forEach var="feed" items="${feedlist}">
  72. <th>理论</th>
  73. <th>实际</th>
  74. </c:forEach>
  75. <th>理论</th>
  76. <th>实际</th>
  77. </c:if>
  78. <c:if test="${tjTarget == 1}">
  79. <c:forEach var="feed" items="${feedlist}">
  80. <th>理论</th>
  81. </c:forEach>
  82. <th>理论</th>
  83. </c:if>
  84. <c:if test="${tjTarget == 2}">
  85. <c:forEach var="feed" items="${feedlist}">
  86. <th>实际</th>
  87. </c:forEach>
  88. <th>实际</th>
  89. </c:if>
  90. </tr>
  91. <%
  92. List list = (List) request.getAttribute("list");
  93. List feedlist = (List) request.getAttribute("feedlist");
  94. String tjType = (String) request.getAttribute("tjType");
  95. String tjTarget = (String) request.getAttribute("tjTarget");
  96. String strname = "";
  97. if(list.size() == 1){
  98. Map strnameMap = (Map)list.get(0);
  99. strname = (String)strnameMap.get("1");
  100. }
  101. if(list.size() > 0 && !"1".equals(strname)){
  102. //动态列头数组
  103. int fsize = feedlist.size();
  104. if("0".equals(tjTarget)){
  105. fsize = fsize*2;
  106. }
  107. Double[] feedstr = new Double[fsize];
  108. //动态合计值数组
  109. Double[] liststr;
  110. if("0".equals(tjTarget)){
  111. liststr = new Double[2];
  112. }else{
  113. liststr = new Double[1];
  114. }
  115. for (int i = 0; i < list.size(); i++) {
  116. int c = 0;
  117. int listC = 0;
  118. Map map = (Map) list.get(i);
  119. if("0".equals(tjType)){
  120. String n1 = (String)map.get("舍栏类别");
  121. %>
  122. <tr align="center" class="greb" style="height: 25px;">
  123. <td><c:out value="<%=n1 %>"/></td>
  124. <%
  125. }else if("1".equals(tjType)){
  126. String n1 = (String)map.get("舍栏");
  127. %>
  128. <tr align="center" class="greb" style="height: 25px;">
  129. <td><c:out value="<%=n1 %>"/></td>
  130. <%
  131. }else if("2".equals(tjType)){
  132. Date d1 = (Date)map.get("日期");
  133. %>
  134. <tr align="center" class="greb" style="height: 25px;">
  135. <td><c:out value="<%=d1 %>"/></td>
  136. <%
  137. }else if("3".equals(tjType)){
  138. String n1 = (String)map.get("TMR");
  139. %>
  140. <tr align="center" class="greb" style="height: 25px;">
  141. <td><c:out value="<%=n1 %>"/></td>
  142. <%
  143. }else if("4".equals(tjType)){
  144. String bc = "";
  145. Integer n1 = (Integer)map.get("班次");
  146. if(n1 == 1){
  147. bc = "早班1";
  148. }else if(n1 == 2){
  149. bc = "早班2";
  150. }else if(n1 == 3){
  151. bc = "中班1";
  152. }else if(n1 == 4){
  153. bc = "中班2";
  154. }else if(n1 == 5){
  155. bc = "晚班1";
  156. }else{
  157. bc = "晚班2";
  158. }
  159. %>
  160. <tr align="center" class="greb" style="height: 25px;">
  161. <td><c:out value="<%=bc %>"/></td>
  162. <%
  163. }
  164. if("0".equals(tjTarget)){
  165. for (int j = 0; j < feedlist.size(); j++){
  166. Map fmap = (Map) feedlist.get(j);
  167. String fname = (String)fmap.get("FNAME");
  168. String fname1 = fname+"|理论";
  169. String fname2 = fname+"|实际";
  170. Double newname1 = (Double)map.get(fname1);
  171. Double newname2 = (Double)map.get(fname2);
  172. if(newname1 != null && newname2 != null){
  173. BigDecimal bg = new BigDecimal(newname1);
  174. newname1 = bg.setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue();
  175. BigDecimal bg1 = new BigDecimal(newname2);
  176. newname2 = bg1.setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue();
  177. if(feedstr[c]==null){
  178. feedstr[c] = newname1;
  179. }else{
  180. feedstr[c] += newname1;
  181. }
  182. c++;
  183. if(feedstr[c]==null){
  184. feedstr[c] = newname2;
  185. }else{
  186. feedstr[c] += newname2;
  187. }
  188. c++;
  189. %>
  190. <td><c:out value="<%=newname1 %>"/></td>
  191. <td><c:out value="<%=newname2 %>"/></td>
  192. <%
  193. }else{
  194. if(feedstr[c]==null){
  195. feedstr[c] = 0.0;
  196. }else{
  197. feedstr[c] += 0.0;
  198. }
  199. c++;
  200. if(feedstr[c]==null){
  201. feedstr[c] = 0.0;
  202. }else{
  203. feedstr[c] += 0.0;
  204. }
  205. c++;
  206. %>
  207. <td>0.0</td>
  208. <td>0.0</td>
  209. <%
  210. }
  211. }
  212. BigDecimal sum1 = (BigDecimal)map.get("合计|理论");
  213. BigDecimal sum2 = (BigDecimal)map.get("合计|实际");
  214. if(liststr[listC]==null){
  215. liststr[listC] = sum1.doubleValue();
  216. }else{
  217. liststr[listC] += sum1.doubleValue();
  218. }
  219. listC++;
  220. if(liststr[listC]==null){
  221. liststr[listC] = sum2.doubleValue();
  222. }else{
  223. liststr[listC] += sum2.doubleValue();
  224. }
  225. listC++;
  226. %>
  227. <td><c:out value="<%=sum1 %>"/></td>
  228. <td><c:out value="<%=sum2 %>"/></td>
  229. </tr>
  230. <%
  231. }else if("1".equals(tjTarget)){
  232. for (int j = 0; j < feedlist.size(); j++){
  233. Map fmap = (Map) feedlist.get(j);
  234. String fname = (String)fmap.get("FNAME");
  235. String fname1 = fname+"|理论";
  236. Double newname1 = (Double)map.get(fname1);
  237. if(newname1 != null){
  238. BigDecimal bg = new BigDecimal(newname1);
  239. newname1 = bg.setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue();
  240. if(feedstr[c]==null){
  241. feedstr[c] = newname1;
  242. }else{
  243. feedstr[c] += newname1;
  244. }
  245. c++;
  246. %>
  247. <td><c:out value="<%=newname1 %>"/></td>
  248. <%
  249. }else{
  250. if(feedstr[c]==null){
  251. feedstr[c] = 0.0;
  252. }else{
  253. feedstr[c] += 0.0;
  254. }
  255. c++;
  256. %>
  257. <td>0.0</td>
  258. <%
  259. }
  260. }
  261. BigDecimal sum1 = (BigDecimal)map.get("合计|理论");
  262. if(liststr[listC]==null){
  263. liststr[listC] = sum1.doubleValue();
  264. }else{
  265. liststr[listC] += sum1.doubleValue();
  266. }
  267. listC++;
  268. %>
  269. <td><c:out value="<%=sum1 %>"/></td>
  270. </tr>
  271. <%
  272. }else if("2".equals(tjTarget)){
  273. for (int j = 0; j < feedlist.size(); j++){
  274. Map fmap = (Map) feedlist.get(j);
  275. String fname = (String)fmap.get("FNAME");
  276. String fname1 = fname+"|实际";
  277. Double newname1 = (Double)map.get(fname1);
  278. if(newname1 != null){
  279. BigDecimal bg = new BigDecimal(newname1);
  280. newname1 = bg.setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue();
  281. if(feedstr[c]==null){
  282. feedstr[c] = newname1;
  283. }else{
  284. feedstr[c] += newname1;
  285. }
  286. c++;
  287. %>
  288. <td><c:out value="<%=newname1 %>"/></td>
  289. <%
  290. }else{
  291. if(feedstr[c]==null){
  292. feedstr[c] = 0.0;
  293. }else{
  294. feedstr[c] += 0.0;
  295. }
  296. c++;
  297. %>
  298. <td>0.0</td>
  299. <%
  300. }
  301. }
  302. BigDecimal sum1 = (BigDecimal)map.get("合计|实际");
  303. if(liststr[listC]==null){
  304. liststr[listC] = sum1.doubleValue();
  305. }else{
  306. liststr[listC] += sum1.doubleValue();
  307. }
  308. listC++;
  309. %>
  310. <td><c:out value="<%=sum1 %>"/></td>
  311. </tr>
  312. <%
  313. }
  314. }
  315. %>
  316. <tr align="center" class="greb" style="height: 25px;">
  317. <td><c:out value="合计"/></td>
  318. <%
  319. for (int k = 0; k < feedstr.length; k++){
  320. String newF = String.format("%.2f", feedstr[k]);
  321. %>
  322. <td><c:out value="<%=newF %>"/></td>
  323. <%
  324. }
  325. for (int t = 0; t < liststr.length; t++){
  326. String newL = String.format("%.2f", liststr[t]);
  327. %>
  328. <td><c:out value="<%=newL %>"/></td>
  329. <%
  330. }
  331. %>
  332. </tr>
  333. <%
  334. }else{
  335. if("0".equals(tjTarget)){
  336. %>
  337. <tr align="center" class="greb" style="height: 25px;"><td colspan="${feedlistsize*2+3}">没有对应的结果</td></tr>
  338. <%
  339. }else{
  340. %>
  341. <tr align="center" class="greb" style="height: 25px;"><td colspan="${feedlistsize+2}">没有对应的结果</td></tr>
  342. <%
  343. }
  344. }
  345. %>
  346. </tbody>
  347. </table>
  348. </div>
  349. </body>
  350. </html>