package com.bysj.action; import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import java.util.ArrayList; import java.util.UUID; import org.apache.struts2.ServletActionContext; import org.springframework.context.annotation.Scope; import org.springframework.stereotype.Controller; import javax.annotation.Resource; import javax.servlet.http.HttpServletResponse; import java.util.List; import com.opensymphony.xwork2.ActionContext; import com.opensymphony.xwork2.ActionSupport; import com.bysj.utils.ExportExcelUtil; import com.bysj.dao.Bo1DAO; import com.bysj.domain.Bo1; import com.bysj.dao.BoTDAO; import com.bysj.domain.BoT; @Controller @Scope("prototype") public class Bo1Action extends ActionSupport { /*ͼƬ�ֶ�bookPhoto�������*/ private File bookPhotoFile; private String bookPhotoFileFileName; private String bookPhotoFileContentType; public File getBookPhotoFile() { return bookPhotoFile; } public void setBookPhotoFile(File bookPhotoFile) { this.bookPhotoFile = bookPhotoFile; } public String getBookPhotoFileFileName() { return bookPhotoFileFileName; } public void setBookPhotoFileFileName(String bookPhotoFileFileName) { this.bookPhotoFileFileName = bookPhotoFileFileName; } public String getBookPhotoFileContentType() { return bookPhotoFileContentType; } public void setBookPhotoFileContentType(String bookPhotoFileContentType) { this.bookPhotoFileContentType = bookPhotoFileContentType; } /*�������Ҫ��ѯ������:ͼ��������*/ private String barcode; public void setBarcode(String barcode) { this.barcode = barcode; } public String getBarcode() { return this.barcode; } /*�������Ҫ��ѯ������:ͼ�����*/ private String bookName; public void setBookName(String bookName) { this.bookName = bookName; } public String getBookName() { return this.bookName; } /*�������Ҫ��ѯ������:ͼ���������*/ private BoT boT; public void setBoT(BoT boT) { this.boT = boT; } public BoT getBoT() { return this.boT; } /*�������Ҫ��ѯ������:��������*/ private String publishDate; public void setPublishDate(String publishDate) { this.publishDate = publishDate; } public String getPublishDate() { return this.publishDate; } /*��ǰ�ڼ�ҳ*/ private int currentPage; public void setCurrentPage(int currentPage) { this.currentPage = currentPage; } public int getCurrentPage() { return currentPage; } /*һ������ҳ*/ private int totalPage; public void setTotalPage(int totalPage) { this.totalPage = totalPage; } public int getTotalPage() { return totalPage; } /*��ǰ��ѯ���ܼ�¼��Ŀ*/ private int recordNumber; public void setRecordNumber(int recordNumber) { this.recordNumber = recordNumber; } public int getRecordNumber() { return recordNumber; } /*ҵ������*/ @Resource Bo1DAO bo1DAO; @Resource BoTDAO boTDAO; /*�������Bo1����*/ private Bo1 bo1; public void setBo1(Bo1 bo1) { this.bo1 = bo1; } public Bo1 getBo1() { return this.bo1; } /*��ת�����ͼ����ͼ*/ public String AddView() { ActionContext ctx = ActionContext.getContext(); /*��ѯ���е�BoT��Ϣ*/ List<BoT> boTList = boTDAO.QueryAllBoTInfo(); ctx.put("boTList", boTList); return "add_view"; } /*���ͼ����Ϣ*/ @SuppressWarnings("deprecation") public String AddBo1() { ActionContext ctx = ActionContext.getContext(); /*��֤ͼ���������Ƿ��Ѿ�����*/ String barcode = bo1.getBarcode(); Bo1 db_bo1 = bo1DAO.GetBo1ByBarcode(barcode); if(null != db_bo1) { ctx.put("error", java.net.URLEncoder.encode("��ͼ���������Ѿ�����!")); return "error"; } try { if(true) { BoT boT = boTDAO.GetBoTByBookTypeId(bo1.getBoT().getBookTypeId()); bo1.setBoT(boT); } String path = ServletActionContext.getServletContext().getRealPath("/upload"); /*����ͼƬ�ϴ�*/ String bookPhotoFileName = ""; if(bookPhotoFile != null) { InputStream is = new FileInputStream(bookPhotoFile); String fileContentType = this.getBookPhotoFileContentType(); if(fileContentType.equals("image/jpeg") || fileContentType.equals("image/pjpeg")) bookPhotoFileName = UUID.randomUUID().toString() + ".jpg"; else if(fileContentType.equals("image/gif")) bookPhotoFileName = UUID.randomUUID().toString() + ".gif"; else { ctx.put("error", java.net.URLEncoder.encode("�ϴ�ͼƬ��ʽ����ȷ!")); return "error"; } File file = new File(path, bookPhotoFileName); OutputStream os = new FileOutputStream(file); byte[] b = new byte[1024]; int bs = 0; while ((bs = is.read(b)) > 0) { os.write(b, 0, bs); } is.close(); os.close(); } if(bookPhotoFile != null) bo1.setBookPhoto("upload/" + bookPhotoFileName); else bo1.setBookPhoto("upload/NoImage.jpg"); bo1DAO.AddBo1(bo1); ctx.put("message", java.net.URLEncoder.encode("Bo1��ӳɹ�!")); return "add_success"; } catch (Exception e) { e.printStackTrace(); ctx.put("error", java.net.URLEncoder.encode("Bo1���ʧ��!")); return "error"; } } /*��ѯͼ��*/ public String QueryBo1() { if(currentPage == 0) currentPage = 1; if(barcode == null) barcode = ""; if(bookName == null) bookName = ""; if(publishDate == null) publishDate = ""; List<Bo1> bo1List = bo1DAO.QueryBo1Info( barcode, bookName, boT, publishDate, currentPage); /*�����ܵ�ҳ����ܵļ�¼��*/ bo1DAO.CalculateTotalPageAndRecordNumber( barcode, bookName, boT, publishDate); /*��ȡ���ܵ�ҳ����Ŀ*/ totalPage = bo1DAO.getTotalPage(); /*��ǰ��ѯ�������ܼ�¼��*/ recordNumber = bo1DAO.getRecordNumber(); ActionContext ctx = ActionContext.getContext(); ctx.put("bo1List", bo1List); ctx.put("totalPage", totalPage); ctx.put("recordNumber", recordNumber); ctx.put("currentPage", currentPage); ctx.put("barcode", barcode); ctx.put("bookName", bookName); ctx.put("boT", boT); List<BoT> boTList = boTDAO.QueryAllBoTInfo(); ctx.put("boTList", boTList); ctx.put("publishDate", publishDate); return "query_view"; } /*��̨������excel*/ public String QueryBo1OutputToExcel() { if(barcode == null) barcode = ""; if(bookName == null) bookName = ""; if(publishDate == null) publishDate = ""; List<Bo1> bo1List = bo1DAO.QueryBo1Info( barcode, bookName, boT, publishDate, currentPage); ExportExcelUtil ex = new ExportExcelUtil(); String title = "Bo1��Ϣ��¼"; String[] headers = {"ͼ��������","ͼ�����","ͼ���������","ͼ��۸�","���","��������","������","ͼ����","ͼ��ͼƬ"}; List<String[]> dataset = new ArrayList<String[]>(); for(int i=0;i<bo1List.size();i++) { Bo1 bo1 = bo1List.get(i); dataset.add(new String[]{bo1.getBarcode(),bo1.getBookName(),bo1.getBoT().getBookTypeName(),bo1.getPrice() + "",bo1.getCount() + "",bo1.getPublishDate(),bo1.getPublish(),bo1.getIntroduction(),bo1.getBookPhoto()}); } /* OutputStream out = null; try { out = new FileOutputStream("C://output.xls"); ex.exportExcel(title,headers, dataset, out); out.close(); } catch (Exception e) { e.printStackTrace(); } */ HttpServletResponse response = null;//����һ��HttpServletResponse���� OutputStream out = null;//����һ����������� try { response = ServletActionContext.getResponse();//��ʼ��HttpServletResponse���� out = response.getOutputStream();// response.setHeader("Content-disposition","attachment; filename="+"Bo1.xls");//filename�����ص�xls�����������Ӣ�� response.setContentType("application/msexcel;charset=UTF-8");//�������� response.setHeader("Pragma","No-cache");//����ͷ response.setHeader("Cache-Control","no-cache");//����ͷ response.setDateHeader("Expires", 0);//��������ͷ String rootPath = ServletActionContext.getServletContext().getRealPath("/"); ex.exportExcel(rootPath,title,headers, dataset, out); out.flush(); } catch (IOException e) { e.printStackTrace(); }finally{ try{ if(out!=null){ out.close(); } }catch(IOException e){ e.printStackTrace(); } } return null; } /*ǰ̨��ѯͼ��*/ public String FrontQueryBo1() { if(currentPage == 0) currentPage = 1; if(barcode == null) barcode = ""; if(bookName == null) bookName = ""; if(publishDate == null) publishDate = ""; List<Bo1> bo1List = bo1DAO.QueryBo1Info( barcode, bookName, boT, publishDate, currentPage); /*�����ܵ�ҳ����ܵļ�¼��*/ bo1DAO.CalculateTotalPageAndRecordNumber( barcode, bookName, boT, publishDate); /*��ȡ���ܵ�ҳ����Ŀ*/ totalPage = bo1DAO.getTotalPage(); /*��ǰ��ѯ�������ܼ�¼��*/ recordNumber = bo1DAO.getRecordNumber(); ActionContext ctx = ActionContext.getContext(); ctx.put("bo1List", bo1List); ctx.put("totalPage", totalPage); ctx.put("recordNumber", recordNumber); ctx.put("currentPage", currentPage); ctx.put("barcode", barcode); ctx.put("bookName", bookName); ctx.put("boT", boT); List<BoT> boTList = boTDAO.QueryAllBoTInfo(); ctx.put("boTList", boTList); ctx.put("publishDate", publishDate); return "front_query_view"; } /*��ѯҪ�ĵ�Bo1��Ϣ*/ public String ModifyBo1Query() { ActionContext ctx = ActionContext.getContext(); /*�������barcode��ȡBo1����*/ Bo1 bo1 = bo1DAO.GetBo1ByBarcode(barcode); List<BoT> boTList = boTDAO.QueryAllBoTInfo(); ctx.put("boTList", boTList); ctx.put("bo1", bo1); return "modify_view"; } /*��ѯҪ�ĵ�Bo1��Ϣ*/ public String FrontShowBo1Query() { ActionContext ctx = ActionContext.getContext(); /*�������barcode��ȡBo1����*/ Bo1 bo1 = bo1DAO.GetBo1ByBarcode(barcode); List<BoT> boTList = boTDAO.QueryAllBoTInfo(); ctx.put("boTList", boTList); ctx.put("bo1", bo1); return "front_show_view"; } /*������ͼ����Ϣ*/ public String ModifyBo1() { ActionContext ctx = ActionContext.getContext(); try { if(true) { BoT boT = boTDAO.GetBoTByBookTypeId(bo1.getBoT().getBookTypeId()); bo1.setBoT(boT); } String path = ServletActionContext.getServletContext().getRealPath("/upload"); /*����ͼƬ�ϴ�*/ String bookPhotoFileName = ""; if(bookPhotoFile != null) { InputStream is = new FileInputStream(bookPhotoFile); String fileContentType = this.getBookPhotoFileContentType(); if(fileContentType.equals("image/jpeg") || fileContentType.equals("image/pjpeg")) bookPhotoFileName = UUID.randomUUID().toString() + ".jpg"; else if(fileContentType.equals("image/gif")) bookPhotoFileName = UUID.randomUUID().toString() + ".gif"; else { ctx.put("error", java.net.URLEncoder.encode("�ϴ�ͼƬ��ʽ����ȷ!")); return "error"; } File file = new File(path, bookPhotoFileName); OutputStream os = new FileOutputStream(file); byte[] b = new byte[1024]; int bs = 0; while ((bs = is.read(b)) > 0) { os.write(b, 0, bs); } is.close(); os.close(); bo1.setBookPhoto("upload/" + bookPhotoFileName); } bo1DAO.UpdateBo1(bo1); ctx.put("message", java.net.URLEncoder.encode("Bo1��Ϣ���³ɹ�!")); return "modify_success"; } catch (Exception e) { e.printStackTrace(); ctx.put("error", java.net.URLEncoder.encode("Bo1��Ϣ����ʧ��!")); return "error"; } } /*ɾ��ͼ����Ϣ*/ public String DeleteBo1() { ActionContext ctx = ActionContext.getContext(); try { bo1DAO.DeleteBo1(barcode); ctx.put("message", java.net.URLEncoder.encode("Bo1ɾ��ɹ�!")); return "delete_success"; } catch (Exception e) { e.printStackTrace(); ctx.put("error", java.net.URLEncoder.encode("Bo1ɾ��ʧ��!")); return "error"; } } }

AOAO1234 LV2
2024年12月23日
2716804680 LV9
2023年12月6日
ziv5466123 LV7
2023年6月26日
stonerose66 LV1
2023年6月23日
北方菜 LV11
2023年4月16日
2017143155 LV12
2022年11月14日
gch666 LV6
2022年6月8日
hebe灬 LV5
2022年5月21日
isfrand LV4
2022年4月19日
丁春秋 LV2
2022年3月15日

微信网友_7556342730182656
6月16日
暂无贡献等级
XD_futura
5月13日
暂无贡献等级
15515998549 LV1
4月16日
AOAO1234 LV2
2024年12月23日
momomo228 LV2
2024年11月22日
LoveSummer LV6
2024年10月31日
zhangjishao
2024年10月15日
暂无贡献等级
angaochong LV5
2024年10月10日
krispeng LV15
2024年8月25日
cy5201
2024年6月24日
暂无贡献等级