FangChao.Qu Blog


  • 首页

  • 归档

  • 标签

基于SSM的商贸平台项目(第七天)

发表于 2017-06-02

1.新的设计方式:打断设计

在表中增加一个字段,这个字段用来存储关联表的主键集合;在报运业务中要查询合同下的货物信息。直接通过这个关联字段,利用in子查询直接去查询货物表,这样查询效率提高很多。而且数据量越大,查询效率越高。这种方式,业务关联层级越多,这种设计方式的性能体现越高。而且通过这种方式可以实现跳跃查询。

2.在jsp页面动态增加表格

##2.1动态表格:
innerHTML 实现往一个区域div增加一段html代码,

table,tr,td都用利用js动态插入

Alt text

/*实现动态增加一行*/
function addTRRecord(objId, id, productNo, cnumber, grossWeight, netWeight, sizeLength, sizeWidth, sizeHeight, exPrice, tax) {

    var _tmpSelect = "";
    var tableObj = document.getElementById(objId);        //得到表格对象
    var rowLength = tableObj.rows.length;                //获取行的长度

    oTR = tableObj.insertRow();                            //新增一行

    oTD = oTR.insertCell(0);                            //新增单元格,下标从0开始
    oTD.style.whiteSpace="nowrap";
    oTD.ondragover = function(){this.className="drag_over" };    //动态加事件, 改变样式类
    oTD.ondragleave = function(){this.className="drag_leave" };
    oTD.onmousedown = function(){ clearTRstyle("result"); this.parentNode.style.background = '#0099cc';};    
    //this.style.background="#0099cc url(../images/arroww.gif) 4px 9px no-repeat";
    oTD.innerHTML = "  ";    
    oTD = oTR.insertCell(1);
    oTD.innerHTML = "<input class=\"input\" type=\"checkbox\" name=\"del\" value=\""+id+"\"><input type=\"hidden\" name=\"mr_id\" value=\""+id+"\"><input class=\"input\" type=\"hidden\" id=\"mr_changed\" name=\"mr_changed\">";
    oTD = oTR.insertCell(2);
    oTD.innerHTML = "<input class=\"input\" type=\"text\" name=\"mr_orderNo\" readonly size=\"3\" value=\"\">";
    oTD = oTR.insertCell(3);
    oTD.innerHTML = "<b><font face='微软雅黑'><font color='blue'>"+productNo;+"</font></font></b> "
    oTD = oTR.insertCell(4);
    oTD.innerHTML = "<input type=\"text\" name=\"mr_cnumber\" maxLength=\"10\" value=\""+cnumber+"\" onBlur=\"setTRUpdateFlag(this);\" size=\"15\">";
    oTD = oTR.insertCell(5);
    oTD.innerHTML = "<input type=\"text\" name=\"mr_grossWeight\" maxLength=\"10\" value=\""+grossWeight+"\" onBlur=\"setTRUpdateFlag(this);\" size=\"15\">";
    oTD = oTR.insertCell(6);
    oTD.innerHTML = "<input type=\"text\" name=\"mr_netWeight\" maxLength=\"10\" value=\""+netWeight+"\" onBlur=\"setTRUpdateFlag(this);\" size=\"15\">";
    oTD = oTR.insertCell(7);
    oTD.innerHTML = "<input type=\"text\" name=\"mr_sizeLength\" maxLength=\"10\" value=\""+sizeLength+"\" onBlur=\"setTRUpdateFlag(this);\" size=\"15\">";
    oTD = oTR.insertCell(8);
    oTD.innerHTML = "<input type=\"text\" name=\"mr_sizeWidth\" maxLength=\"10\" value=\""+sizeWidth+"\" onBlur=\"setTRUpdateFlag(this);\" size=\"15\">";
    oTD = oTR.insertCell(9);
    oTD.innerHTML = "<input type=\"text\" name=\"mr_sizeHeight\" maxLength=\"10\" value=\""+sizeHeight+"\" onBlur=\"setTRUpdateFlag(this);\" size=\"15\">";
    oTD = oTR.insertCell(10);
    oTD.innerHTML = "<input type=\"text\" name=\"mr_exPrice\" maxLength=\"10\" value=\""+exPrice+"\" onBlur=\"setTRUpdateFlag(this);\" size=\"15\">";
    oTD = oTR.insertCell(11);
    oTD.innerHTML = "<input type=\"text\" name=\"mr_tax\" maxLength=\"10\" value=\""+tax+"\" onBlur=\"setTRUpdateFlag(this);\" size=\"15\">";

    dragtableinit();    //拖动表格行
    sortnoTR();            //排序号

}    

##2.2修改新增的字段

  1. 页面上使用同名框,reqest.getParameterValues(),形成一个Sring数组
  2. Struts2框架封装为可以根据它的类型数组,改造ModelDriver
    字符类型,将多个值拼接成一个字符串,之间用逗号+空格隔开
    整形、浮点型、日期等,只保留第一个
  3. Springmvc框架封装为数组,在方法调用参数上声明
    字符类型,将多个值拼接成一个字符串,之间用逗号隔开
    整形、浮点型、日期等,只保留第一个

基于SSM的商贸平台项目(第六天)

发表于 2017-05-27

报表引擎,复杂的报表打印

Alt text

1.技术难点

  1. 插入图片,POI插入图片时,设定区域,自动缩放到这个区域中,图片要设置偏移量
    HSSFPatriarch patriarch = sheet.createDrawingPatriarch(); //add picture
    poiUtil.setPicture(wb, patriarch, path+”make/xlsprint/logo.jpg”, curRow, 2, curRow+4, 2);

  2. 模板,对于购销合同它不能直接做模板。代码中不能做这个功能。Excel支持区域复制。但是目前POI不直接支持区域复制。(合并单元格在sheet对象中、图片、线等)(基于用户使用系统,以及POI不直接支持区域复制,所以它不能直接使用模板)
    A. 只是改变列宽
    B. 画一个sheet,利用poi支持sheet的复制,保留样式。

  3. 插入一根线,设置两个坐标,它直接连线,可以是直线,可以是斜线,可以设置偏移量
    poiUtil.setLine(wb, patriarch, curRow, 2, curRow, 8); //draw line

  4. 合并单元格,特点:合并单元格的边线样式,它实际上是在合并前的单元格上设置的。特殊的地方:在单元格如果有样式,合并单元格的这几个格子都必须设置边线样式。
    CellRangeAddress region = null;
    region = new CellRangeAddress(curRow-1, curRow-1, 1, 3); //纵向合并单元格
    //不需要设置内容,只设置样式,补齐线。

    for(int j=2;j<9;j++){
        nCell = nRow.createCell(j);
        nCell.setCellStyle(poiUtil.notehv10_BorderThin(wb, defaultFont10));
    }
    
  5. 换行
    curStyle.setWrapText(true);

  6. 设置人民币符号(前缀)
    format.getFormat(“\”¥\”#,###,###.00”);
  7. 设置公式,乘法,合计公式
    nCell.setCellType(HSSFCell.CELL_TYPE_FORMULA);
    nCell.setCellFormula(“F”+String.valueOf(curRow)+”*H”+String.valueOf(curRow));
  8. 实现审单人的人名等量空格替换,实现它后面的位置不变(工具类)
    utilFuns.fixSpaceStr(contract.getCheckBy(),26)
  9. 单元格自适应(工具类)
    float height = poiUtil.getCellAutoHeight(printMap.get(“Request”), 12f); //自动高度
  10. 数据和业务分离,一页数据封装到一个map中,以业务字段名称定义KEY,以string定义内容,所有页面封装到一个arraylist。
    Map pageMap = null;
    List pageList = new ArrayList(); //打印页

  11. 插入分页符

    if(p>0){
        sheet.setRowBreak(curRow++);    //在第startRow行设置分页符
    }
    
  12. 公用的工具类PoiUtil poiUtil = new PoiUtil(); 样式,特殊内容封装
  13. return format.getFormat(“\”¥\”#,###,##0.00”); // 设置格式
    0代表,这位值如果不为零,显示原来的内容,直接输出0
    ,#代表,这位值如果存在,就直接显示,不存在,就不显示。
  14. nCell.setCellType(HSSFCell.CELL_TYPE_NUMERIC);

    2.代码整理

import java.io.ByteArrayOutputStream;
import java.io.FileInputStream;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletResponse;

import org.apache.poi.hssf.usermodel.HSSFCell;
import org.apache.poi.hssf.usermodel.HSSFCellStyle;
import org.apache.poi.hssf.usermodel.HSSFFont;
import org.apache.poi.hssf.usermodel.HSSFPatriarch;
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.CellRangeAddress;

import cn.itcast.jk.vo.ContractProductVO;
import cn.itcast.jk.vo.ContractVO;
import cn.itcast.util.DownloadUtil;
import cn.itcast.util.UtilFuns;
import cn.itcast.util.file.PoiUtil;

public class ContractPrint{

public void print(ContractVO contract,String path, HttpServletResponse response) throws Exception{
    //相同厂家的信息一起打印
    List<ContractProductVO> oList = contract.getContractProducts();
    UtilFuns utilFuns = new UtilFuns();
    String tempXlsFile = path + "make/xlsprint/tCONTRACT.xls";        //获取模板文件

    //填写每页的内容,之后在循环每页读取打印
    Map<String,String> pageMap = null;
    List<Map> pageList = new ArrayList();            //打印页

    ContractProductVO oProduct = null;
    String stars = "";
    for(int j=0;j<contract.getImportNum();j++){        //重要程度
        stars += "★";
    }

    String oldFactory = "";
    for(int i=0;i<oList.size();i++){
        oProduct = oList.get(i);    //获得货物
        pageMap = new HashMap();    //每页的内容

        pageMap.put("Offeror", "收 购 方:" + contract.getOfferor());
        pageMap.put("Factory", "生产工厂:" + oProduct.getFactory().getFactoryName());
        pageMap.put("ContractNo", "合 同 号:" + contract.getContractNo());
        pageMap.put("Contractor", "联 系 人:" + oProduct.getFactory().getContacts());
        pageMap.put("SigningDate", "签单日期:"+UtilFuns.formatDateTimeCN(UtilFuns.dateTimeFormat(contract.getSigningDate())));
        pageMap.put("Phone", "电    话:" + oProduct.getFactory().getPhone());
        pageMap.put("InputBy", "制单:" + contract.getInputBy());
        pageMap.put("CheckBy", "审单:"+ utilFuns.fixSpaceStr(contract.getCheckBy(),26)+"验货员:"+utilFuns.convertNull(contract.getInspector()));
        pageMap.put("Remark", "  "+contract.getRemark());
        pageMap.put("Request", "  "+contract.getCrequest());

        pageMap.put("ProductImage", oProduct.getProductImage());
        pageMap.put("ProductDesc", oProduct.getProductDesc());
        pageMap.put("Cnumber", String.valueOf(oProduct.getCnumber().doubleValue()));
        if(oProduct.getPackingUnit().equals("PCS")){
            pageMap.put("PackingUnit", "只");
        }else if(oProduct.getPackingUnit().equals("SETS")){
            pageMap.put("PackingUnit", "套");
        }
        pageMap.put("Price", String.valueOf(oProduct.getPrice().doubleValue()));
        pageMap.put("ProductNo", oProduct.getProductNo());

        oldFactory = oProduct.getFactory().getFactoryName();

        if(contract.getPrintStyle().equals("2")){
            i++;    //读取第二个货物信息
            if(i<oList.size()){
                oProduct = oList.get(i);

                if(oProduct.getFactory().getFactoryName().equals(oldFactory)){    //厂家不同另起新页打印,除去第一次的比较

                    pageMap.put("ProductImage2", oProduct.getProductImage());
                    pageMap.put("ProductDesc2", oProduct.getProductDesc());
                    pageMap.put("Cnumber2", String.valueOf(oProduct.getCnumber().doubleValue()));
                    if(oProduct.getPackingUnit().equals("PCS")){
                        pageMap.put("PackingUnit2", "只");
                    }else if(oProduct.getPackingUnit().equals("SETS")){
                        pageMap.put("PackingUnit2", "套");
                    }                        
                    pageMap.put("Price2", String.valueOf(oProduct.getPrice().doubleValue()));
                    //pageMap.put("Amount2", String.valueOf(oProduct.getAmount().doubleValue()));            //在excel中金额采用公式,所以无需准备数据
                    pageMap.put("ProductNo2", oProduct.getProductNo());
                }else{
                    i--;    //tip:list退回
                }
            }else{
                pageMap.put("ProductNo2", null);    //后面依据此判断是否有第二个货物
            }
        }

        pageMap.put("ContractDesc", stars+" 货物描述");            //重要程度 + 货物描述

        pageList.add(pageMap);
    }

        int cellHeight = 96;    //一个货物的高度            用户需求,一个货物按192高度打印,后来又嫌难看,打印高度和2款高度一样。
//        if(contract.getPrintStyle().equals("2")){
//            cellHeight = 96;    //两个货物的高度
//        }

    PoiUtil poiUtil = new PoiUtil();
    HSSFWorkbook wb = new HSSFWorkbook(new FileInputStream(tempXlsFile));    //打开excel文件
    HSSFFont defaultFont10 = poiUtil.defaultFont10(wb);        //设置字体
    HSSFFont defaultFont12 = poiUtil.defaultFont12(wb);        //设置字体
    HSSFFont blackFont = poiUtil.blackFont12(wb);            //设置字体
    Short rmb2Format = poiUtil.rmb2Format(wb);                //设置格式
    Short rmb4Format = poiUtil.rmb4Format(wb);                //设置格式


    HSSFSheet sheet = wb.getSheetAt(0);                //选择第一个工作簿
    wb.setSheetName(0, "购销合同");                    //设置工作簿的名称


    //sheet.setDefaultColumnWidth((short) 20);         // 设置每列默认宽度

//        POI分页符有BUG,必须在模板文件中插入一个分页符,然后再此处删除预设的分页符;最后在下面重新设置分页符。
//        sheet.setAutobreaks(false);
//        int iRowBreaks[] = sheet.getRowBreaks();
//        sheet.removeRowBreak(3);
//        sheet.removeRowBreak(4);
//        sheet.removeRowBreak(5);
//        sheet.removeRowBreak(6);

    CellRangeAddress region = null;
    HSSFPatriarch patriarch = sheet.createDrawingPatriarch();        //add picture

    HSSFRow nRow = null;
    HSSFCell nCell   = null;
    int curRow = 0;

    //打印每页
    Map<String,String> printMap = null;
    for(int p=0;p<pageList.size();p++){
        printMap = pageList.get(p);

        if(p>0){
            sheet.setRowBreak(curRow++);    //在第startRow行设置分页符
        }


        //设置logo图片
        poiUtil.setPicture(wb, patriarch, path+"make/xlsprint/logo.jpg", curRow, 2, curRow+4, 2);

        //header
        nRow = sheet.createRow(curRow++);
        nRow.setHeightInPoints(21);

        nCell   = nRow.createCell((3));
        nCell.setCellValue("SHAANXI");
        nCell.setCellStyle(headStyle(wb));

        //header
        nRow = sheet.createRow(curRow++);
        nRow.setHeightInPoints(41);

        nCell   = nRow.createCell((3));
        nCell.setCellValue("     JK INTERNATIONAL ");
        nCell.setCellStyle(tipStyle(wb));

        curRow++;

        //header
        nRow = sheet.createRow(curRow++);
        nRow.setHeightInPoints(20);

        nCell   = nRow.createCell((1));
        nCell.setCellValue("                 西经济技术开发区西城一路27号无迪大厦19楼");
        nCell.setCellStyle(addressStyle(wb));

        //header
        nCell   = nRow.createCell((6));
        nCell.setCellValue(" CO., LTD.");
        nCell.setCellStyle(ltdStyle(wb));

        //header
        nRow = sheet.createRow(curRow++);
        nRow.setHeightInPoints(15);

        nCell   = nRow.createCell((1));
        nCell.setCellValue("                   TEL: 0086-29-86339371  FAX: 0086-29-86303310               E-MAIL: ijackix@glass.cn");
        nCell.setCellStyle(telStyle(wb));

        //line
        nRow = sheet.createRow(curRow++);
        nRow.setHeightInPoints(7);

        poiUtil.setLine(wb, patriarch, curRow, 2, curRow, 8);    //draw line

        //header
        nRow = sheet.createRow(curRow++);
        nRow.setHeightInPoints(30);

        nCell   = nRow.createCell((4));
        nCell.setCellValue("    购   销   合   同");
        nCell.setCellStyle(titleStyle(wb));

        //Offeror
        nRow = sheet.createRow(curRow++);
        nRow.setHeightInPoints(20);

        nCell   = nRow.createCell((1));
        nCell.setCellValue(printMap.get("Offeror"));
        nCell.setCellStyle(poiUtil.titlev12(wb, blackFont));

        //Facotry
        nCell   = nRow.createCell((5));
        nCell.setCellValue(printMap.get("Factory"));
        nCell.setCellStyle(poiUtil.titlev12(wb, blackFont));

        //ContractNo
        nRow = sheet.createRow(curRow++);
        nRow.setHeightInPoints(20);

        nCell   = nRow.createCell(1);
        nCell.setCellValue(printMap.get("ContractNo"));
        nCell.setCellStyle(poiUtil.titlev12(wb, blackFont));

        //Contractor
        nCell  = nRow.createCell(5);
        nCell.setCellValue(printMap.get("Contractor"));
        nCell.setCellStyle(poiUtil.titlev12(wb, blackFont));

        //SigningDate
        nRow = sheet.createRow(curRow++);
        nRow.setHeightInPoints(20);

        nCell = nRow.createCell(1);
        nCell.setCellValue(printMap.get("SigningDate"));
        nCell.setCellStyle(poiUtil.titlev12(wb, blackFont));

        //Phone
        nCell = nRow.createCell(5);
        nCell.setCellValue(printMap.get("Phone"));
        nCell.setCellStyle(poiUtil.titlev12(wb, blackFont));

        //importNum
        nRow = sheet.createRow(curRow++);
        nRow.setHeightInPoints(24);

        region = new CellRangeAddress(curRow-1, curRow-1, 1, 3);    //纵向合并单元格 
        sheet.addMergedRegion(region);

        nCell = nRow.createCell(1);
        nCell.setCellValue("产品");
        nCell.setCellStyle(thStyle(wb));        

        nCell = nRow.createCell(2);
        nCell.setCellStyle(poiUtil.notehv10_BorderThin(wb, defaultFont10));

        nCell = nRow.createCell(3);
        nCell.setCellStyle(poiUtil.notehv10_BorderThin(wb, defaultFont10));

        nCell = nRow.createCell(4);
        nCell.setCellValue(printMap.get("ContractDesc"));
        nCell.setCellStyle(thStyle(wb));    

        region = new CellRangeAddress(curRow-1, curRow-1, 5, 6);    //纵向合并单元格 
        sheet.addMergedRegion(region);

        nCell = nRow.createCell(5);
        nCell.setCellValue("数量");
        nCell.setCellStyle(thStyle(wb));    

        nCell = nRow.createCell(6);
        nCell.setCellStyle(poiUtil.notehv10_BorderThin(wb, defaultFont10));            

        nCell = nRow.createCell(7);
        nCell.setCellValue("单价");
        nCell.setCellStyle(thStyle(wb));                        

        nCell = nRow.createCell(8);
        nCell.setCellValue("总金额");
        nCell.setCellStyle(thStyle(wb));                        


        nRow = sheet.createRow(curRow++);
        nRow.setHeightInPoints(96);

        region = new CellRangeAddress(curRow-1, curRow-1, 1, 3);    //纵向合并单元格 
        sheet.addMergedRegion(region);

        //插入产品图片
        if(UtilFuns.isNotEmpty(printMap.get("ProductImage"))){
            System.out.println(printMap.get("ProductImage"));
            poiUtil.setPicture(wb, patriarch, path+"ufiles/jquery/"+printMap.get("ProductImage"), curRow-1, 1, curRow, 3);
        }

        nCell = nRow.createCell(2);
        nCell.setCellStyle(poiUtil.notehv10_BorderThin(wb, defaultFont10));

        nCell = nRow.createCell(3);
        nCell.setCellStyle(poiUtil.notehv10_BorderThin(wb, defaultFont10));

        //ProductDesc
        region = new CellRangeAddress(curRow-1, curRow, 4, 4);    //纵向合并单元格 
        sheet.addMergedRegion(region);

        nCell = nRow.createCell(4);
        nCell.setCellValue(printMap.get("ProductDesc"));
        nCell.setCellStyle(poiUtil.notehv10_BorderThin(wb, defaultFont10));        

        //Cnumber
        region = new CellRangeAddress(curRow-1, curRow, 5, 5);    //纵向合并单元格 
        sheet.addMergedRegion(region);

        nCell = nRow.createCell(5);
        nCell.setCellType(HSSFCell.CELL_TYPE_NUMERIC);
        nCell.setCellValue(Double.parseDouble(printMap.get("Cnumber")));
        nCell.setCellStyle(poiUtil.numberrv10_BorderThin(wb, defaultFont10));    

        //Unit
        region = new CellRangeAddress(curRow-1, curRow, 6, 6);    //纵向合并单元格 
        sheet.addMergedRegion(region);

        nCell = nRow.createCell(6);
        nCell.setCellValue(printMap.get("PackingUnit"));
        nCell.setCellStyle(poiUtil.moneyrv10_BorderThin(wb, defaultFont10, rmb4Format));    

        //Price
        region = new CellRangeAddress(curRow-1, curRow, 7, 7);    //纵向合并单元格 
        sheet.addMergedRegion(region);

        nCell = nRow.createCell(7);
        nCell.setCellType(HSSFCell.CELL_TYPE_NUMERIC);
        nCell.setCellValue(Double.parseDouble(printMap.get("Price")));
        nCell.setCellStyle(poiUtil.moneyrv10_BorderThin(wb, defaultFont10, rmb4Format));


        //Amount
        region = new CellRangeAddress(curRow-1, curRow, 8, 8);    //纵向合并单元格 
        sheet.addMergedRegion(region);

        nCell = nRow.createCell(8);
        if(UtilFuns.isNotEmpty(printMap.get("Cnumber")) && UtilFuns.isNotEmpty(printMap.get("Price"))){
            nCell.setCellType(HSSFCell.CELL_TYPE_FORMULA);
            nCell.setCellFormula("F"+String.valueOf(curRow)+"*H"+String.valueOf(curRow));
        }
        nCell.setCellStyle(poiUtil.moneyrv10_BorderThin(wb, defaultFont10, rmb4Format));            

        curRow++;

        region = new CellRangeAddress(curRow-1, curRow-1, 1, 3);    //纵向合并单元格 
        sheet.addMergedRegion(region);

        //ProductNo
        nRow = sheet.createRow(curRow-1);
        nRow.setHeightInPoints(24);

        nCell = nRow.createCell(1);
        nCell.setCellValue(printMap.get("ProductNo"));
        nCell.setCellStyle(poiUtil.notecv10_BorderThin(wb, defaultFont10));

        for(int j=2;j<9;j++){
            nCell = nRow.createCell(j);
            nCell.setCellStyle(poiUtil.notehv10_BorderThin(wb, defaultFont10));
        }



        if(contract.getPrintStyle().equals("2") && UtilFuns.isNotEmpty(printMap.get("ProductNo2"))){
            nRow = sheet.createRow(curRow++);
            nRow.setHeightInPoints(96);

            region = new CellRangeAddress(curRow-1, curRow-1, 1, 3);    //纵向合并单元格 
            sheet.addMergedRegion(region);

            //插入产品图片
            if(UtilFuns.isNotEmpty(printMap.get("ProductImage2"))){
                System.out.println(printMap.get("ProductImage2"));
                poiUtil.setPicture(wb, patriarch, path+"ufiles/jquery/"+printMap.get("ProductImage2"), curRow-1, 1, curRow, 3);
            }

            //ProductDesc
            region = new CellRangeAddress(curRow-1, curRow, 4, 4);    //纵向合并单元格 
            sheet.addMergedRegion(region);

            nCell = nRow.createCell(4);
            nCell.setCellValue(printMap.get("ProductDesc2"));
            nCell.setCellStyle(poiUtil.notehv10_BorderThin(wb, defaultFont10));        

            //Cnumber
            region = new CellRangeAddress(curRow-1, curRow, 5, 5);    //纵向合并单元格 
            sheet.addMergedRegion(region);

            nCell = nRow.createCell(5);
            nCell.setCellType(HSSFCell.CELL_TYPE_NUMERIC);
            nCell.setCellValue(Double.parseDouble(printMap.get("Cnumber2")));
            nCell.setCellStyle(poiUtil.numberrv10_BorderThin(wb, defaultFont10));    

            //Unit
            region = new CellRangeAddress(curRow-1, curRow, 6, 6);    //纵向合并单元格 
            sheet.addMergedRegion(region);

            nCell = nRow.createCell(6);
            nCell.setCellValue(printMap.get("PackingUnit2"));
            nCell.setCellStyle(poiUtil.moneyrv10_BorderThin(wb, defaultFont10, rmb4Format));    

            //Price
            region = new CellRangeAddress(curRow-1, curRow, 7, 7);    //纵向合并单元格 
            sheet.addMergedRegion(region);

            nCell = nRow.createCell(7);
            nCell.setCellType(HSSFCell.CELL_TYPE_NUMERIC);
            nCell.setCellValue(Double.parseDouble(printMap.get("Price2")));
            nCell.setCellStyle(poiUtil.moneyrv10_BorderThin(wb, defaultFont10, rmb4Format));


            //Amount
            region = new CellRangeAddress(curRow-1, curRow, 8, 8);    //纵向合并单元格 
            sheet.addMergedRegion(region);

            nCell = nRow.createCell(8);
            if(UtilFuns.isNotEmpty(printMap.get("Cnumber2")) && UtilFuns.isNotEmpty(printMap.get("Price2"))){
                nCell.setCellType(HSSFCell.CELL_TYPE_FORMULA);
                nCell.setCellFormula("F"+String.valueOf(curRow)+"*H"+String.valueOf(curRow));
            }
            nCell.setCellStyle(poiUtil.moneyrv10_BorderThin(wb, defaultFont10, rmb4Format));        

            curRow++;

            region = new CellRangeAddress(curRow-1, curRow-1, 1, 3);    //纵向合并单元格
            sheet.addMergedRegion(region);

            nRow = sheet.createRow(curRow-1);
            nRow.setHeightInPoints(24);

            nCell = nRow.createCell(1);
            nCell.setCellValue(printMap.get("ProductNo2"));
            nCell.setCellStyle(poiUtil.notecv10_BorderThin(wb, defaultFont10));            

            //合并单元格画线
            for(int j=2;j<9;j++){
                nCell = nRow.createCell(j);
                nCell.setCellStyle(poiUtil.notehv10_BorderThin(wb, defaultFont10));
            }                
        }


        //InputBy
        nRow = sheet.createRow(curRow++);
        nRow.setHeightInPoints(24);

        nCell = nRow.createCell(1);
        nCell.setCellValue(printMap.get("InputBy"));
        nCell.setCellStyle(poiUtil.bnormalv12(wb,defaultFont12));

        //CheckBy+inspector

        nCell = nRow.createCell(4);
        nCell.setCellValue(printMap.get("CheckBy"));
        nCell.setCellStyle(poiUtil.bnormalv12(wb,defaultFont12));

        //if(contract.getPrintStyle().equals("2") && UtilFuns.isNotEmpty(printMap.get("ProductNo2"))){

            nCell = nRow.createCell(7);
            nCell.setCellValue("总金额:");
            nCell.setCellStyle(bcv12(wb));

            //TotalAmount
            nRow = sheet.createRow(curRow-1);
            nRow.setHeightInPoints(24);
            if(UtilFuns.isNotEmpty(printMap.get("Cnumber"))&&UtilFuns.isNotEmpty(printMap.get("Price"))){
                nCell  = nRow.createCell(8);
                nCell.setCellType(HSSFCell.CELL_TYPE_FORMULA);
                nCell.setCellFormula("SUM(I"+String.valueOf(curRow-4)+":I"+String.valueOf(curRow-1)+")");
                nCell.setCellStyle(poiUtil.moneyrv12_BorderThin(wb,defaultFont12,rmb2Format));        
            }
        //}


        //note
        nRow = sheet.createRow(curRow++);
        nRow.setHeightInPoints(21);

        nCell = nRow.createCell(2);
        nCell.setCellValue(printMap.get("Remark"));
        nCell.setCellStyle(noteStyle(wb));            

        //Request
        region = new CellRangeAddress(curRow, curRow, 1, 8);    //指定合并区域 
        sheet.addMergedRegion(region);

        nRow = sheet.createRow(curRow++);
        float height = poiUtil.getCellAutoHeight(printMap.get("Request"), 12f);        //自动高度
        nRow.setHeightInPoints(height);

        nCell = nRow.createCell(1);
        nCell.setCellValue(printMap.get("Request"));
        nCell.setCellStyle(requestStyle(wb));

        //space line
        nRow = sheet.createRow(curRow++);
        nRow.setHeightInPoints(20);

        //duty
        nRow = sheet.createRow(curRow++);
        nRow.setHeightInPoints(32);

        nCell = nRow.createCell(1);
        nCell.setCellValue("未按以上要求出货而导致客人索赔,由供方承担。");
        nCell.setCellStyle(dutyStyle(wb));    

        //space line
        nRow = sheet.createRow(curRow++);
        nRow.setHeightInPoints(32);

        //buyer
        nRow = sheet.createRow(curRow++);
        nRow.setHeightInPoints(25);

        nCell = nRow.createCell(1);
        nCell.setCellValue("    收购方负责人:");
        nCell.setCellStyle(dutyStyle(wb));                

        //seller
        nCell = nRow.createCell(5);
        nCell.setCellValue("供方负责人:");
        nCell.setCellStyle(dutyStyle(wb));    

        curRow++;

    }

    ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();            //生成流对象
    wb.write(byteArrayOutputStream);                                                    //将excel写入流

    //工具类,封装弹出下载框:        
    String outFile = "购销合同.xls";
    DownloadUtil down = new DownloadUtil();
    down.download(byteArrayOutputStream, response, outFile);

}

private HSSFCellStyle leftStyle(HSSFWorkbook wb){
    HSSFCellStyle curStyle = wb.createCellStyle();
    curStyle.setWrapText(true);                          //换行   
    HSSFFont curFont = wb.createFont();                    //设置字体
    curFont.setCharSet(HSSFFont.DEFAULT_CHARSET);        //设置中文字体,那必须还要再对单元格进行编码设置
    //fTitle.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);    //加粗
    curFont.setFontHeightInPoints((short)10);
    curStyle.setFont(curFont);
    curStyle.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER);        //单元格垂直居中

    curStyle.setBorderLeft(HSSFCellStyle.BORDER_THIN);                //实线右边框
    curStyle.setBorderBottom(HSSFCellStyle.BORDER_THIN);                //实线右边框

    return curStyle;
}  

private HSSFCellStyle headStyle(HSSFWorkbook wb){
    HSSFCellStyle curStyle = wb.createCellStyle();
    HSSFFont curFont = wb.createFont();                    //设置字体
    curFont.setFontName("Comic Sans MS");
    curFont.setCharSet(HSSFFont.DEFAULT_CHARSET);        //设置中文字体,那必须还要再对单元格进行编码设置

    curFont.setItalic(true);
    curFont.setFontHeightInPoints((short)16);
    curStyle.setFont(curFont);
    curStyle.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER);        //单元格垂直居中

    return curStyle;
}  

private HSSFCellStyle tipStyle(HSSFWorkbook wb){
    HSSFCellStyle curStyle = wb.createCellStyle();
    HSSFFont curFont = wb.createFont();                    //设置字体
    curFont.setFontName("Georgia");
    curFont.setCharSet(HSSFFont.DEFAULT_CHARSET);        //设置中文字体,那必须还要再对单元格进行编码设置

    curFont.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);    //加粗
    curFont.setFontHeightInPoints((short)28);
    curStyle.setFont(curFont);
    curStyle.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER);        //单元格垂直居中

    return curStyle;
}  

private HSSFCellStyle addressStyle(HSSFWorkbook wb){
    HSSFCellStyle curStyle = wb.createCellStyle();
    HSSFFont curFont = wb.createFont();                    //设置字体
    curFont.setFontName("宋体");
    curFont.setCharSet(HSSFFont.DEFAULT_CHARSET);        //设置中文字体,那必须还要再对单元格进行编码设置

    //fTitle.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);    //加粗
    curFont.setFontHeightInPoints((short)10);
    curStyle.setFont(curFont);
    curStyle.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER);        //单元格垂直居中

    return curStyle;
}  

private HSSFCellStyle ltdStyle(HSSFWorkbook wb){
    HSSFCellStyle curStyle = wb.createCellStyle();
    HSSFFont curFont = wb.createFont();                    //设置字体
    curFont.setFontName("Times New Roman");
    curFont.setCharSet(HSSFFont.DEFAULT_CHARSET);        //设置中文字体,那必须还要再对单元格进行编码设置

    curFont.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);    //加粗
    curFont.setItalic(true);
    curFont.setFontHeightInPoints((short)16);
    curStyle.setFont(curFont);
    curStyle.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER);        //单元格垂直居中

    return curStyle;
}     

private HSSFCellStyle telStyle(HSSFWorkbook wb){
    HSSFCellStyle curStyle = wb.createCellStyle();
    HSSFFont curFont = wb.createFont();                    //设置字体
    curFont.setFontName("宋体");
    curFont.setCharSet(HSSFFont.DEFAULT_CHARSET);        //设置中文字体,那必须还要再对单元格进行编码设置

    //fTitle.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);    //加粗
    curFont.setFontHeightInPoints((short)9);
    curStyle.setFont(curFont);
    curStyle.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER);        //单元格垂直居中

    return curStyle;
}     

private HSSFCellStyle titleStyle(HSSFWorkbook wb){
    HSSFCellStyle curStyle = wb.createCellStyle();
    HSSFFont curFont = wb.createFont();                    //设置字体
    curFont.setFontName("黑体");
    curFont.setCharSet(HSSFFont.DEFAULT_CHARSET);        //设置中文字体,那必须还要再对单元格进行编码设置

    curFont.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);    //加粗
    curFont.setFontHeightInPoints((short)18);
    curStyle.setFont(curFont);
    curStyle.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER);        //单元格垂直居中

    return curStyle;
}     

private HSSFCellStyle requestStyle(HSSFWorkbook wb){
    HSSFCellStyle curStyle = wb.createCellStyle();
    curStyle.setWrapText(true);                          //换行   
    HSSFFont curFont = wb.createFont();                    //设置字体
    curFont.setFontName("宋体");
    curFont.setCharSet(HSSFFont.DEFAULT_CHARSET);        //设置中文字体,那必须还要再对单元格进行编码设置

    curFont.setFontHeightInPoints((short)10);
    curStyle.setFont(curFont);
    curStyle.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER);        //单元格垂直居中

    return curStyle;
}     

private HSSFCellStyle dutyStyle(HSSFWorkbook wb){
    HSSFCellStyle curStyle = wb.createCellStyle();
    HSSFFont curFont = wb.createFont();                    //设置字体
    curFont.setFontName("黑体");
    curFont.setCharSet(HSSFFont.DEFAULT_CHARSET);        //设置中文字体,那必须还要再对单元格进行编码设置

    curFont.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);    //加粗
    curFont.setFontHeightInPoints((short)16);
    curStyle.setFont(curFont);
    curStyle.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER);        //单元格垂直居中

    return curStyle;
}     

private HSSFCellStyle noteStyle(HSSFWorkbook wb){
    HSSFCellStyle curStyle = wb.createCellStyle();
    HSSFFont curFont = wb.createFont();                    //设置字体
    curFont.setFontName("宋体");
    curFont.setCharSet(HSSFFont.DEFAULT_CHARSET);        //设置中文字体,那必须还要再对单元格进行编码设置

    curFont.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);    //加粗
    curFont.setFontHeightInPoints((short)12);
    curStyle.setFont(curFont);
    curStyle.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER);        //单元格垂直居中

    return curStyle;
} 

public HSSFCellStyle thStyle(HSSFWorkbook wb){
    HSSFCellStyle curStyle = wb.createCellStyle();
    HSSFFont curFont = wb.createFont();                    //设置字体
    curFont.setFontName("宋体");
    curFont.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);    //加粗
    curFont.setFontHeightInPoints((short)12);
    curFont.setCharSet(HSSFFont.DEFAULT_CHARSET);        //设置中文字体,那必须还要再对单元格进行编码设置

    curStyle.setBorderTop(HSSFCellStyle.BORDER_THIN);                //实线右边框
    curStyle.setBorderRight(HSSFCellStyle.BORDER_THIN);                //实线右边框
    curStyle.setBorderBottom(HSSFCellStyle.BORDER_THIN);            //实线右边框
    curStyle.setBorderLeft(HSSFCellStyle.BORDER_THIN);                //实线右边框

    curStyle.setAlignment(HSSFCellStyle.ALIGN_CENTER);
    curStyle.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER);        //单元格垂直居中

    return curStyle;
}  

public HSSFCellStyle bcv12(HSSFWorkbook wb){
    HSSFCellStyle curStyle = wb.createCellStyle();
    HSSFFont curFont = wb.createFont();                        //设置字体
    curFont.setFontName("Times New Roman");
    curFont.setCharSet(HSSFFont.DEFAULT_CHARSET);            //设置中文字体,那必须还要再对单元格进行编码设置

    curFont.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);        //加粗
    curFont.setFontHeightInPoints((short)12);
    curStyle.setFont(curFont);

    curStyle.setBorderTop(HSSFCellStyle.BORDER_THIN);                //实线
    curStyle.setBorderRight(HSSFCellStyle.BORDER_THIN);            //粗实线
    curStyle.setBorderBottom(HSSFCellStyle.BORDER_THIN);            //实线
    curStyle.setBorderLeft(HSSFCellStyle.BORDER_THIN);                //实线

    curStyle.setAlignment(HSSFCellStyle.ALIGN_RIGHT);
    curStyle.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER);        //单元格垂直居中

    return curStyle;
}        

}

基于SSM的商贸平台项目(第五天)

发表于 2017-05-25

1.POI解决什么问题

JXL,POI都是操作excel
Excel一些企业小的应用都直接用excel来实现,例如:工资报表,人员名单,进销存
作为数据的备份和恢复(导入、导出)

Jxl 它只能操作excel 2003版本,它导入导出数据量小时性能很高
POI 它可以操作office系列软件word、excel、ppt、visio(画网络布局、家装),在早期版本中它在导出海量数据时,容易崩溃。在新版本中它解决了这个海量数据时,进行了优化,解决了这个问题。

2.POI初体验

@Test
public void testHSSF_base() throws IOException{
    /*
     * 开发步骤:
     * 1、创建一个工作簿
     * 2、创建一个工作表
     * 3、创建一个行对象
     * 4、创建一个单元格对象,指定它的列
     * 5、给单元格设置内容
     * 6、样式进行修饰(跳过)
     * 7、保存,写文件
     * 8、关闭对象
     */

    Workbook wb = new HSSFWorkbook();
    Sheet sheet = wb.createSheet();
    Row nRow = sheet.createRow(7);            //第八行
    Cell nCell = nRow.createCell(4);        //第五列

    nCell.setCellValue("传智播客万年长!");

    OutputStream os = new FileOutputStream("c:\\testpoi.xls");    //excel 2003
    wb.write(os);

    os.flush();
    os.close();
}

2.1小结

Poi本身操作极其简单,只要记住使用的api即可。
但是它在处理单元格时
1) 不能直接看中间结果,必须运行完才可以看到
2) HSSF构造的对象都在内存中,创建非常多的对象,当对象量越来越多时,容易造成堆溢出。

3.POI模板开发

Alt text

InputStream is = new FileInputStream(new File("c:\\tOUTPRODUCT.xls"));
Workbook wb = new HSSFWorkbook(is);        //打开一个模板文件,工作簿
Sheet sheet = wb.getSheetAt(0);            //获取到第一个工作表

Row nRow = null;
Cell nCell = null;
int rowNo = 0;                            //行号
int colNo = 1;                            //列号

//获取模板上的单元格样式
nRow = sheet.getRow(2);

//客户的样式
nCell = nRow.getCell(1);
CellStyle customStyle = nCell.getCellStyle();    

4.POI百万数据打印

  1. 从数据库读取数据,LIST在构造时十分耗费内存,还占用CPU资源
  2. Xlsx一个单sheet可以支持1048576条数据。它加工这些数据时,都是暂时放在内存中。报内存堆溢出。
  3. POI意识到这个问题,它在高版本解决了海量数据导出时性能问题。可以实现非常平滑的导出。

4.1解决方法

4.1.1 POI ooxml SXSSF对象

<dependency>
    <groupId>org.apache.poi</groupId>
    <artifactId>poi</artifactId>
    <version>3.9</version>
</dependency>
<dependency>
    <groupId>org.apache.poi</groupId>
    <artifactId>poi-ooxml</artifactId>
    <version>3.9</version>
</dependency>

4.1.2 它解决思路:

在打印过程中,已经加工完的对象,临时存到一个临时文件中,它采用xml临时文件。最终处理完时,将这些临时内容写入到最终的xlsx文件中。

Workbook wb = new SXSSFWorkbook(100);    //创建excel文件,内存只有100条记录【关键语句】
public SXSSFWorkbook(int rowAccessWindowSize){
this(null /*workbook*/, rowAccessWindowSize);

}
每rowAccessWindowSize条对象时,写一次缓存。

!!!! 这个对象不能使用模板。只能用于到数据量的导出。(没有格式)

5. CSV文件,导入到数据库中

CSV是一个标准的导入导出文件格式,实际是一个txt文件

基于SSM的商贸平台项目(第四天)

发表于 2017-05-21

1.数据字典

1.1一般它由编号+名称构成。

  1. 性别:0101男,0102女
  2. 包装单位:0201 PCS,0202 SETS
  3. 区县:02901西安市 02902宝鸡市
    通用的数据字典,它可以存放多个分类,结构必须是ID+NAME
    TYPE+ID+NAME

1.2数据字典都在哪里使用?

单选的组合;下拉框

2.表的业务后缀

_c 业务表 customer
_b 基础表 base
_p 权限表 privilege

3.级联删除

  1. Mybatis多层关联关系时,级联删除必须一级一级的删除。多级时要专门写mapper方法。

  2. 在mybatis在service,删除货物时,先调用附件的service删除方法

  3. 通过sql,高速删除(批量删除)每层都要实现一个删除

业务:要求直接显示合同下的货物数和附件数
select count(*) from contract_product_c
where contract_id=’928eb2ae-23ba-46e0-9ad0-054354f66af8’

select count(*) from ext_cproduct_c
where contract_product_id in (select contract_product_id from contract_product_c where contract_id=’928eb2ae-23ba-46e0-9ad0-054354f66af8’)

3.1获取货物数和附件数

select
(select count() from contract_product_c
where contract_id=c.contract_id) as cpnum,
(select count(
) from ext_cproduct_c
where contract_product_id in (select contract_product_id from contract_product_c where contract_id=c.contract_id)
) as extnum,

c.*

from contract_c c

3.2 PO、VO、BO有什么区别?

  1. PO 持久化对象,一般就直接对象数据库表
  2. VO 视图对象,一般对应页面jsp
  3. BO 业务对象,一般对应复杂业务

4.合同总金额业务【sql的强大】

4.1 货物的总金额

select cnumber*price as cptotal from contract_product_c
where contract_id =’471e562b-bfa5-4ba7-a2b5-17e9b0d40179’

4.2 附件的总金额

select sum(cnumber*price) as exttotal from ext_cproduct_c
where contract_product_id in (select contract_product_id from contract_product_c where contract_id=c.contract_id)

4.3最终

select
(select count() from contract_product_c
where contract_id=c.contract_id) as cpnum,
(select count(
) from ext_cproduct_c
where contract_product_id in (select contract_product_id from contract_product_c where contract_id=c.contract_id)
) as extnum,
(
nvl((select sum(cnumberprice) as cptotal from contract_product_c
where contract_id =c.contract_id),0)
+
nvl(
(select sum(cnumber
price) as exttotal from ext_cproduct_c
where contract_product_id in (select contract_product_id from contract_product_c where contract_id=c.contract_id))
,0)
) as total_amount,
c.CONTRACT_ID,c.OFFEROR,c.CONTRACT_NO,c.SIGNING_DATE,c.INPUT_BY,c.CHECK_BY,c.INSPECTOR,c.IMPORT_NUM,c.CREQUEST,c.CUSTOM_NAME,c.DELIVERY_PERIOD,c.SHIP_TIME,c.TRADE_TERMS,c.REMARK,c.PRINT_STYLE,c.OLD_STATE,c.STATE,c.OUT_STATE

from contract_c c

5.业务:购销合同查看【sql的强大】

  1. 查看合同的主信息,查看合同下的货物信息,还要查看附件信息,货物和附件的信息要显示出它们的关联关系。

  2. 利用面对对象的关联关系来实现上面的需求非常简单。

  3. 合同、货物、附件、生产厂家构建复杂多级关联的SQL时原则
    1) 挑选最小的结果集
    2) 滚雪球(左连接),逐步往上加内容
    3) 重复字段,需要起别名(mybatis)

!在实际业务中几乎没有内连接的情况,直接就用左连接即可。

最终实现业务的超长sql

select 
c.contract_id,c.offeror,c.contract_no,c.signing_date,c.input_by,c.check_by,c.inspector,c.total_amount,c.import_n    um,c.crequest,c.custom_name,c.delivery_period,c.ship_time,c.trade_terms,c.remark,c.print_style,c.old_state,c.sta    te,c.out_state,c.create_by,c.create_dept,c.create_time, 
t.contract_product_id,t.product_no,t.product_image,t.product_desc,t.cnumber,t.out_number,t.loading_rate,t.box_num,t.packing_unit,t.price,t.amount,t.finished,t.exts,t.order_no,t.factory_id,t.full_name,t.factory_name,t.contacts,t.phone, t.ext_cproduct_id,     t.ctype,t.ext_product_no,t.ext_product_image,t.ext_product_desc,t.ext_cnumber,t.ext_packing_         unit,t.ext_price,t.ext_amount,t.product_request,
 t.ext_order_no,
 t.ext_factory_id,t.ext_full_name,t.ext_factory_name,t.ext_contacts,t.ext_phone

from
(
  select 
      contract_id,offeror,contract_no,signing_date,input_by,check_by,inspector,total_amount,import_num,crequest,custom_name,delivery_period,ship_time,trade_terms,remark,print_style,old_state,state,out_state,create_by,create_dept,create_time
   from contract_c ) c left join (
   select
          cp.contract_product_id,cp.contract_id,
          cp.product_no,cp.product_image,cp.product_desc,cp.cnumber,cp.out_number,cp.loading_rate,cp.box_num,cp.packing_unit,cp.price,cp.amount,cp.finished,cp.exts,cp.order_no,
          cp.factory_id,cp.full_name,cp.factory_name,cp.contacts,cp.phone,

          ext.ext_cproduct_id,
          ext.ctype,ext.product_no as ext_product_no,ext.product_image as ext_product_image,ext.product_desc as ext_product_desc,
          ext.cnumber as ext_cnumber,ext.packing_unit as ext_packing_unit,ext.price as ext_price,ext.amount as ext_amount,
          ext.product_request,ext.order_no as ext_order_no,
          ext.factory_id as ext_factory_id,ext.full_name as ext_full_name,ext.factory_name as ext_factory_name,ext.contacts as ext_contacts,ext.phone as ext_phone

    from
    (
        select
          cp.contract_product_id,cp.contract_id,
          cp.product_no,cp.product_image,cp.product_desc,cp.cnumber,cp.out_number,cp.loading_rate,cp.box_num,cp.packing_unit,cp.price,cp.amount,cp.finished,cp.exts,cp.order_no,
          f.factory_id,f.full_name,f.factory_name,f.contacts,f.phone
        from
        (select 
        contract_product_id,contract_id,factory_id,
        product_no,product_image,product_desc,cnumber,out_number,loading_rate,box_num,packing_unit,price,amount,finished,exts,order_no
         from contract_product_c) cp
        left join 
        (select factory_id,full_name,factory_name,contacts,phone from factory_c) f
        on cp.factory_id=f.factory_id
    ) cp
    left join
    (
        select
          ext.ext_cproduct_id,ext.contract_product_id,
          ext.ctype,ext.product_no,ext.product_image,ext.product_desc,ext.cnumber,ext.packing_unit,ext.price,ext.amount,ext.product_request,ext.order_no,
          f.factory_id,f.full_name,f.factory_name,f.contacts,f.phone
        from
        (
        select 
            ext_cproduct_id,contract_product_id,factory_id,
            ctype,product_no,product_image,product_desc,cnumber,packing_unit,price,amount,product_request,order_no
         from ext_cproduct_c 
        ) ext
        left join 
        (select factory_id,full_name,factory_name,contacts,phone from factory_c) f
        on ext.factory_id=f.factory_id
    ) ext
    on cp.contract_product_id=ext.contract_product_id) t on c.contract_id=t.contract_id where c.contract_id=#{contractId} 

基于SSM的商贸平台项目(第三天)

发表于 2017-05-20

细粒度权限

1.日常权限框架:

基于角色权限,用户、角色、权限(URL、主菜单、左侧菜单、按钮)–

2.数据权限:

纵向的数据权限过滤:对数据进行过滤

2.1本人(专责):登录后只能看到自己的信息

Where条件 create_by = #{当前登录者id}

2.2部门(集团公司):登录后登录人是经理级别

A.只能看本部门

Where条件 create_dept=#{当前登录者所在的部门}

B.只能看到本部门和直属下属的数据 总经理-财务部-社保组

Where条件 create_dept=#{当前登录者所在的部门}
And create_dept like #{当前登录者所在部门}???

C.看到所有下属的数据 财务副总-财务部-社保组

Where条件 create_dept like #{当前登录者所在部门id}%

3.部门表的编码有业务规则

001总部
001004 财务部
001005 软件部
001004001 社保组
001004002 工资组
001005001 杰信组
编码3位为一层

4.跨部门跨人员权限控制(特殊的情况,大型企业)

举例:副总(分管),分管领导业务交叉

Alt text

单独加表实现
Where条件 create_dept in (当前登录者配置的管理的部门集合)
Or
Create_by in (当前登录者配置的管理的人员集合)

基于SSM的商贸平台项目(第二天)

发表于 2017-05-19

1.开发规范

1.1数据库设计的规范

  1. 数据库设计的规范
  2. 数据库表和字段都大写
  3. 表都要加业务后缀,例如_C客户表 _B基础表 _P权限表
  4. 必须有主键,主键是表名去掉业务后缀,加_ID,大多表的主键使用UUID
  5. 字段多个单词时,全大写,用下划线隔开
  6. 类型INT/LONG/DOUBLE/TIMESTAMP/CHAR/VARCHAR2 尽量化在这几个类型中,这样数据库设计相当简单
  7. 排序号定死名称ORDER_NO
  8. 权限两个字段CREATE_BY创建人,CREATE_DEPT创建部门
  9. 记录创建时间CREATE_TIME

    1.2代码的开发规范

  10. 将静态资源之间放在webapps下;将动态资源需要验证权限放在WEB-INF/pages(安全)
  11. 类文件放在src/main/java下;资源文件src/main/resources;web文件放在src/main/webapp下
  12. cn.itcast.jk.domain 存放所有实体文件PO
  13. cn.itcast.jk.dao 存放所有dao的接口和实现类,业务接口必须继承BaseDao接口,业务的实现类必须继承BaseDaoImpl实现类。
  14. cn.itcast.jk.dao 存放所有的service接口和实现类,无需继承。
  15. cn.itcast.jk.controller 存放所有springmvc 的controller,它不必须继承BaseController;它创建两层目录结构,一层是大模块名称,第二层是小模块名称,业务内容都放在下面。
  16. jsp,它放在WEB-INF/pages目录下,也创建两级目录,第一层就是大模块名称,第二层是小模块名称。
  17. webapp/components它第三方组件的目录,例如jQuery
  18. webapp/js/common.js 它是整个项目公用的js
  19. webapp/mak/xlsprint excel报表的模板文件

1.3数据库设计

数据库设计基础原则:三范式

  1. 表必须有主键
  2. 字段内容不能是其他的字段加工而成
  3. 行数据不能相同

现今业界主流数据库设计原则:反三范式

  1. 表不是必须有主键
  2. 字段存一些加工后的中间的结果,冗余设计
  3. 记录冗余

三范式追求的目标存储空间尽量小;反三范式追求的目标是查询速度。
创建数据库设计时首先按三范式设计,然后局部优化。

画图的目的:为了开发人员了解整个系统的概貌,当画很多细节时,就会干扰我们对图的了解。

2.Oracle数据库备份和恢复

1.备份

Alt text

2.恢复

Alt text

3.SQL形式备份,备份不能含有大字段,在导入时,不直接用工具,直接拷贝sql语句,进行执行

Alt text

基于SSM的商贸平台项目(第一天)

发表于 2017-05-19

1.用例图

  1. 角色:代表系统中的一类用户
  2. 用例:代表业务功能
  3. 连线关系:哪个角色操作哪些用例

Alt text

画图的目的:为了开发人员了解整个系统的概貌,当画很多细节时,就会干扰我们对图的了解。

2.PowerDesign数据库建模,Oracle 设置

2.1创建一个账号

Alt text

2.2授权

Alt text

2.3使用自己创建的账号登陆

Alt text

2.4PD建模

Alt text

3.系统功能结构图

  1. 功能点(分层,主次)演化成主菜单,左侧菜单,功能点
  2. 了解系统的所有功能
  3. 按功能点分配工作
  4. 用户报价的依据(按模块报价)

Alt text

4.系统架构

springmvc+spring3.2.6+mybatis+oracle11g/mysql+maven

Alt text

经验总结

  1. 首先感谢网上的学习资料
  2. 学会项目开发前的前期工作

基于opencv自带SVM的图像块分类及标定

发表于 2017-04-25

#1.基于opencv 3.1 自带的SVM的训练检测无人机

##1.1处理正负样本(负样本为正样本数的3倍)

要求64*128的训练集 ,为了是的训练之后的得到的模型有3780个特征向量,setSVMDetector函数要求输入
的检测器的响亮就是3780+rho 总共3781个向量

##1.2 训练

训练后得到 SVM_HOG.xml模型,该模型得到3781个向量作为detector

##1.3 测试

  1. 测试时,只需加载detector所在的txt文件,将他传给vector去检测即可。
  2. 注意detectMultiScale函数耗时时间很长,hog_test.detectMultiScale(src, found, 0, Size(8, 8), Size(32, 32), 1.05, 2);注意调整其参数

#2. 经验总结

1:学会了sourceTree的基本用法
克隆/新建:创建一个新仓库,或者从服务器克隆,或者加载本地已经有的
提交:git命令的commit,上传到本地仓库
检出:checkout,其实就是切换,切换不同分支,切换一个分支的不同版本
丢弃:回到最近一次add或者commit的状态。
暂存:git stash,手头工作没有完成的时候,保存一下现场
添加:add,把工作区的修改添加到暂缓区
获取和拉取:git fetch和git pull,获取是从远端获取最新版本到本地,但是不会自动合并,而拉取是会自动合并。fetch更安全一些,可以查看更新情况,然后决定是否合并。
推送:push,本地数据库的更新上传到远端。
分支:创建或者删除分支。
合并:分支的合并
标签:给每个版本定义个标签
Git工作流:一般master是总的主枝,每个人开发的时候都自己定义一个dev分支是自己的主枝,当没有问题的时候提交到master,然后每个人自己开发新功能的时候创建一个feature功能分支,修改BUG时要单独拿出一个BUG分支。
命令行模式:可以输入git命令
2:对于opencv的HOG+SVM的整体技术路线清楚了,可以进行单帧目标识别

基于libSVM的图像块分类及标定

发表于 2017-04-10

#基于libSVN的图像块分类及标定

##1.安装opencv

下载opencv.exe,安装,配置环境变量:OPENCV_HOME,Path

##2.在VS2013配置opencv环境

VC++directories,Linker中的input

##3.vs2013集成QT5

(转载自 http://blog.csdn.net/u013360881/article/details/50629876)
在Windows Host下,下载Qt 5.5.1 for Windows 64-bit (VS 2013, 823 MB) ;在Other downloads下,下载Visual Studio Add-in 1.2.4 for Qt5 (156 MB) ,当然具体版本还需根据自己的实际情况来定,这里是以我的安装版本为例进行介绍的。

安装顺序:最好先安装第一个,然后在安装后一个。

配置:1、在VS中新建项目,命名为test,选择第一个应用平台,然后直接next即可;
2、在菜单栏上有个Qt5,在其下拉菜单中找到Qt options->添加name和path,
name这里为VS2013_QT5.5.1,这个最好与安装的VS和QT版本一致;path为QT安装后的路径,路径末端一直到msvc2013_64即可;
3、点击test项目右键找到Qt project setting后双击,选择最后一项版本,点击下拉菜单找到相应版本;
4、项目属性 -> 链接器 -> 高级 -> 目标计算机 -> 将其值改为MachineX86;
配置管理器 -> 平台 -> 改为活动(X64);
5、项目属性 -> VC++目录 -> 包含目录 -> 添加QT安装目录下include路径;

Node.js+Hexo+Git搭建个人博客心路历程

发表于 2017-03-07

Node.js+Hexo+Git搭建个人博客心路历程(感谢小勇哥)

##1. 安装git

  • 从https://git-for-windows.github.io下载,然后按默认选项安装即可。
    安装完成后,在开始菜单里找到“Git”->“Git Bash”,蹦出一个类似命令行窗口的东西,就说明Git安装成功!

##2. 安装Node.js

http://www.runoob.com/nodejs/nodejs-install-setup.html详细步骤

##3.安装 Hexo

在git bush 里面操作

  1. $ cd d:/hexo
  2. $ npm install hexo-cli -g
  3. $ hexo init blog
  4. $ cd blog
  5. $ npm install
  6. $ hexo g # 或者hexo generate
  7. $ hexo s # 或者hexo server,可以在http://localhost:4000/ 查看
    -这里有必要提下Hexo常用的几个命令:
    hexo generate (hexo g) 生成静态文件,会在当前目录下生成一个新的叫做public的文件夹
    hexo server (hexo s) 启动本地web服务,用于博客的预览
    hexo deploy (hexo d) 部署播客到远端(比如github, heroku等平台)

##4.配置到GitHub

创建本地ssh:

  1. 在git bush 下输入 ssh-keygen -t rsa -C “1151958516@qq.com”,然后一路回车下去;
  2. windows应该是(C:\Documents and Settings\Administrator.ssh (或者 C:\Users\自己电脑用户名.ssh)中)。
  3. 在github中的settings 中打开ssh选项 ,添加ssh ,然后用记事本打开id_rsa.pub,将里面的全部代码复制到github的SSH中;
12
FangChao.Qu

FangChao.Qu

所有人都在努力,并不是只有你满腹委屈

20 日志
6 标签
GitHub 微博
© 2017 FangChao.Qu
由 Hexo 强力驱动
主题 - NexT.Muse