package com.sinosoft.em.evaluate.scoreGrade.service; import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException; import java.io.UnsupportedEncodingException; import java.util.List; import java.util.Map; import java.util.UUID; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import javax.ws.rs.POST; import javax.ws.rs.Path; import javax.ws.rs.ProduceMime; import javax.ws.rs.core.Context; import org.apache.log4j.Logger; import org.apache.poi.hssf.usermodel.HSSFCell; import org.apache.poi.hssf.usermodel.HSSFCellStyle; import org.apache.poi.hssf.usermodel.HSSFRow; import org.apache.poi.hssf.usermodel.HSSFSheet; import org.apache.poi.hssf.usermodel.HSSFWorkbook; import org.apache.poi.hssf.util.HSSFColor; import org.apache.poi.ss.usermodel.CellStyle; import org.apache.poi.hssf.util.Region; import org.apache.poi.ss.usermodel.Cell; import com.formaction.Utils; import com.formaction.service.CRUDServiceImpl; import com.formaction.vo.Msg; import com.persistence.service.exception.PersistenceException; import com.sinosoft.common.upLoad.service.UploadManageImpl; import com.sinosoft.em.evaluate.scoreGrade.dao.PengGuExcel; import com.sinosoft.em.evaluate.scoreGrade.dao.ScoreGradeDao; import com.sinosoft.lz.system.logon.vo.LoginInfo; @Path("/ScoreGradeService/") public class ScoreGradeServiceImpl implements ScoreGradeService { @Context private org.apache.cxf.jaxrs.ext.MessageContext mc; private final Logger log = Logger.getLogger(getClass()); @ProduceMime("application/json") @POST @Path("/getScoreGradeById") public String getScoreGradeById(String params) { String id = Utils.getParameter("id", params) == null ? "" : Utils .getParameter("id", params); try { ScoreGradeDao scoreGradeDao = new ScoreGradeDao(); return scoreGradeDao.getScoreGradeById(id); } catch (PersistenceException e) { // TODO Auto-generated catch block e.printStackTrace(); } return null; } @ProduceMime("application/json") @POST @Path("/getScoreGradeTrunkIds") public String getScoreGradeTrunkIds(String params) { String condition = Utils.getParameter("condition", params) == null ? "" : Utils .getParameter("condition", params); String evalId = Utils.getParameter("evalId", params) == null ? "" : Utils .getParameter("evalId", params); try { ScoreGradeDao scoreGradeDao = new ScoreGradeDao(); return scoreGradeDao.getScoreGradeTrunkIds(condition,evalId); } catch (PersistenceException e) { // TODO Auto-generated catch block e.printStackTrace(); } return null; } //保存================================================== @ProduceMime("application/json") @POST @Path("/saveSocre") public Msg saveSocre(String params) { String rows = Utils.getParameter("rows", params) == null ? "" : Utils .getParameter("rows", params); String evalId = Utils.getParameter("evalId", params) == null ? "" : Utils .getParameter("evalId", params); String resultTrunk = Utils.getParameter("resultTrunk", params) == null ? "" : Utils .getParameter("resultTrunk", params); //填报人 String realName = Utils.getParameter("realName", params) == null ? "" : Utils .getParameter("realName", params); //填报部门 String deptName = Utils.getParameter("deptName", params) == null ? "" : Utils .getParameter("deptName", params); //填报时间 String dateTime = Utils.getParameter("dateTime", params) == null ? "" : Utils .getParameter("dateTime", params); ScoreGradeDao scoreGradeDao = new ScoreGradeDao(); return scoreGradeDao.saveSocre(rows,evalId,resultTrunk,realName,deptName,dateTime); } //重置========================================================= @ProduceMime("application/json") @POST @Path("/reloadSocre") public String reloadSocre(String params) { String condition = Utils.getParameter("condition", params) == null ? "" : Utils .getParameter("condition", params); String evalId = Utils.getParameter("evalId", params) == null ? "" : Utils .getParameter("evalId", params); try { ScoreGradeDao scoreGradeDao = new ScoreGradeDao(); return scoreGradeDao.reloadSorce(condition,evalId); } catch (PersistenceException e) { // TODO Auto-generated catch block e.printStackTrace(); } return null; } /** * ====导出============================================================ * @throws FileNotFoundException */ @ProduceMime("application/json") @POST @Path("/ExportgetScoreGradeTrunkIds") public String ExportgetScoreGradeTrunkIds(String params) throws FileNotFoundException { String condition = Utils.getParameter("condition", params) == null ? "" : Utils .getParameter("condition", params); String evalId = Utils.getParameter("evalId", params) == null ? "" : Utils .getParameter("evalId", params); // resultTrunk String resultTrunk = Utils.getParameter("resultTrunk", params) == null ? "" : Utils .getParameter("resultTrunk", params); //评分单位 String [] result = resultTrunk.split(","); try { ScoreGradeDao scoreGradeDao = new ScoreGradeDao(); List> list = scoreGradeDao.ExportgetScoreGradeTrunkIds(condition,evalId); HttpServletRequest request = mc.getHttpServletRequest(); String filePath = request.getRealPath("excels"); String fileName = UUID.randomUUID().toString()+".xls"; FileOutputStream out = new FileOutputStream(filePath+"/"+fileName); log.info(filePath+"/"+fileName); try { HSSFWorkbook workbook = new HSSFWorkbook(); CellStyle cellStyle=workbook.createCellStyle(); cellStyle.setAlignment(HSSFCellStyle.ALIGN_CENTER); // 居中 cellStyle.setWrapText(true);//设置自动换行 //加边框 cellStyle.setBottomBorderColor(HSSFColor.BLACK.index); cellStyle.setBorderLeft(HSSFCellStyle.BORDER_MEDIUM); cellStyle.setLeftBorderColor(HSSFColor.BLACK.index); cellStyle.setBorderRight(HSSFCellStyle.BORDER_MEDIUM); cellStyle.setRightBorderColor(HSSFColor.BLACK.index); cellStyle.setBorderTop(HSSFCellStyle.BORDER_MEDIUM); cellStyle.setTopBorderColor(HSSFColor.BLACK.index); //一页 HSSFSheet childSheet = workbook.createSheet(); //设置列宽 childSheet.setColumnWidth(0, 5000); childSheet.setColumnWidth(1, 5000); childSheet.setColumnWidth(2, 5000); childSheet.setColumnWidth(3, 5000); childSheet.setColumnWidth(4, 5000); childSheet.setColumnWidth(5, 5000); childSheet.setColumnWidth(6, 5000); // 起始行 // 结束行 // 其实列 // 结束列 childSheet.addMergedRegion(new Region(0, (short)0, 0,(short)6)); CellStyle cellStyle1=workbook.createCellStyle(); cellStyle1.setWrapText(true); //换行 HSSFRow row0 = childSheet.createRow(0); row0.setHeight((short)1000); HSSFCell cell00 = row0.createCell(0); cell00.setCellType(Cell.CELL_TYPE_STRING); //按照String类型读取 cell00.setCellValue(" "); cell00.setCellStyle(cellStyle1); childSheet.addMergedRegion(new Region(1, (short)0, 1,(short)6)); HSSFCell cell10 = childSheet.createRow(1).createCell(0); cell10.setCellType(Cell.CELL_TYPE_STRING); //按照String类型读取 cell10.setCellValue("评估评分表"); cell10.setCellStyle(cellStyle); HSSFRow row2 = childSheet.createRow(2); HSSFCell cell20 = row2.createCell(0); cell20.setCellType(Cell.CELL_TYPE_STRING); //按照String类型读取 cell20.setCellValue("体系名"); HSSFCell cell21 = row2.createCell(1); cell21.setCellType(Cell.CELL_TYPE_STRING); //按照String类型读取 cell21.setCellValue("一级项目"); HSSFCell cell22 = row2.createCell(2); cell22.setCellType(Cell.CELL_TYPE_STRING); //按照String类型读取 cell22.setCellValue("二级项目"); HSSFCell cell23 = row2.createCell(3); cell23.setCellType(Cell.CELL_TYPE_STRING); //按照String类型读取 cell23.setCellValue("三级项目"); HSSFCell cell24 = row2.createCell(4); cell24.setCellType(Cell.CELL_TYPE_STRING); //按照String类型读取 cell24.setCellValue("评价内容"); //循环评分单位 表头 for(int i = 0;i detail = list.get(listSize+2-r); HSSFRow rows = childSheet.createRow(r); HSSFCell cell0 = rows.createCell(0); cell0.setCellType(Cell.CELL_TYPE_STRING); cell0.setCellValue(detail.get("TRUNK_NAME"));//体系名 HSSFCell cell1 = rows.createCell(1); cell1.setCellType(Cell.CELL_TYPE_STRING); cell1.setCellValue(detail.get("LEVEL_ONE")); HSSFCell cell2 = rows.createCell(2); cell2.setCellType(Cell.CELL_TYPE_STRING); cell2.setCellValue(detail.get("LEVEL_TWO")); HSSFCell cell3 = rows.createCell(3); cell3.setCellType(Cell.CELL_TYPE_STRING); cell3.setCellValue(detail.get("LEVEL_THREE")); HSSFCell cell4 = rows.createCell(4); cell4.setCellType(Cell.CELL_TYPE_STRING); cell4.setCellValue(detail.get("DETAIL")); for(int i = 0;i