com.pureinfo.srm.reports.table.data.weight.WeightStatistic.java Source code

Java tutorial

Introduction

Here is the source code for com.pureinfo.srm.reports.table.data.weight.WeightStatistic.java

Source

/**
 * PureInfo Command2
 * @(#)WeightStatistic.java   1.0 2007-11-11
 * 
 * Copyright(c) 2004-2005, PureInfo Information Technology Corp. Ltd. 
 * All rights reserved, see the license file.
 * 
 * www.pureinfo.com.cn
 */

package com.pureinfo.srm.reports.table.data.weight;

import java.text.DecimalFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.TreeMap;

import org.apache.commons.lang.StringUtils;
import org.apache.log4j.Logger;

import com.pureinfo.ark.content.ArkContentHelper;
import com.pureinfo.ark.content.domain.IContentMgr;
import com.pureinfo.dolphin.model.DolphinObject;
import com.pureinfo.dolphin.model.IObjects;
import com.pureinfo.dolphin.persister.IStatement;
import com.pureinfo.force.exception.PureException;
import com.pureinfo.srm.SRMConstants;
import com.pureinfo.srm.SRMTypes;
import com.pureinfo.srm.org.domain.IOrganizationMgr;
import com.pureinfo.srm.org.model.Organization;
import com.pureinfo.srm.product.domain.IProductMgr;
import com.pureinfo.srm.product.model.Product;
import com.pureinfo.srm.project.model.OutlayUnit;
import com.pureinfo.srm.reports.table.ITableDatabuilder;

/**
 * <P>
 * Created on 2007-12-28 09:51:07<BR>
 * Last modified on 2007-12-28
 * </P>
 * TODO describe WeightStatistic here ... 
 * 
 * 
 * departmentcollege
 * 
 * @author opensky.ma
 * @version 1.0, 2007-12-28
 * @since Command2 1.0
 */
public class WeightStatistic implements ITableDatabuilder {

    private Logger logger = Logger.getLogger(this.getClass());

    private Object[][] m_datas;

    private final int TITLE_HEIGHT = 2;

    private final int LABEL_WIDTH = 2;

    private final int OUTLAY_WIDTH = 3;

    private final int BIG_PRJ_WIDTH = 3;

    private final int PRODUCT_WIDTH = 7;

    private final int SUM_ALL_WIDHT = 1;

    private final int OTHER_HEIGHT = 1;

    private final int SUM_HEIGHT = 1;

    private Map m_codeLabelMap = new TreeMap();

    private Map m_codeCellMap = new TreeMap();

    private static Map m_hHospitals = new TreeMap();

    private static Map m_others = new TreeMap();

    private final String HOSPITAL_CODE = "19";

    private final String OTHER_CODE = "88";

    private Map m_codeRowIndexMap = new TreeMap();

    private IOrganizationMgr m_OrgMgr;

    private List m_dataOutlay = new ArrayList();

    private IObjects m_dataProduct;

    private List m_dataBigPrj = new ArrayList();

    private List m_dataBigPrjOther = new ArrayList();

    private IObjects m_dataAll;

    private IObjects m_dataCitePaper;

    private IObjects m_dataPatent;

    private IObjects m_data3Index;

    private IObjects m_dataProductAbs;

    private final String ARRIVE_OUTLAY = "_OUT";

    private final String OUTLAY_PROB_WEIGHT = "_OUTPROBWEIGHT";

    private final String OUTLAY_ABS_WEIGHT = "_OUTABSWEIGHT";

    private final String PRJ_TOTAL_NUM = "_PRJSUM";

    private final String PRJ_PROB_WEIGHT = "_PRJPROBWEIGHT";

    private final String PRJ_ABS_WEIGHT = "_PRJABSWEIGHT";

    private final String PRD_PATENT_WEIGHT = "_PRJPATENTWEIGHT";

    private final String PRD_HONOR_WEIGHT = "_PRJHONORWEIGHT";

    private final String PRD_INDEX_WEIGHT = "_PRJINDEXWEIGHT";

    private final String PRD_CITEPAPER_WEIGHT = "_PRJCITEPAPERWEIGHT";

    private final String PRD_ZHUZUO_WEIGHT = "_PRJZHUZUOWEIGHT";

    private final String PRD_SUM_WEIGHT = "_PRJSUMWEIGHT";

    private final String PRD_ABS_WEIGHT = "_PRJABSWEIGHT";

    private final String ALL_ABS_WEIGHT = "_SUMALL";

    private final String DEPARTMENT = "_DEPARTMENT";

    private final String PRODUCT_FORM = "_FORM";

    private int m_nWeightYear;

    private final SimpleDateFormat DATE_FORMATTER = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");

    private final DecimalFormat NUM_FORMATTER = new DecimalFormat("#.###");

    /*
     * deparment
     * 
     */
    static {
        m_hHospitals.put("91010", "");
        m_hHospitals.put("91020", "");
        m_hHospitals.put("91030", "");
        m_hHospitals.put("91050", "");
        m_hHospitals.put("91040", "");
        m_hHospitals.put("91060", "");

        m_others.put("88040", "");
        m_others.put("88730", "");
        m_others.put("88740", "");
        m_others.put("88750", "");
    }

    public Object[][] buildDatas(boolean _bAscOrder, boolean _bOrderByValue) throws PureException {
        //label
        initLabelOrgArea();
        m_datas = new Object[TITLE_HEIGHT + m_codeRowIndexMap.size() + OTHER_HEIGHT + SUM_HEIGHT][LABEL_WIDTH
                + OUTLAY_WIDTH + BIG_PRJ_WIDTH + PRODUCT_WIDTH + SUM_ALL_WIDHT];
        //titlelabelIndex3SCIStatistic
        renderTitleAndLabel();

        logger.debug("it's outlay time now is" + DATE_FORMATTER.format(new Date()));
        //
        setUpData(doOutlayQuery(), new String[] { ARRIVE_OUTLAY, OUTLAY_PROB_WEIGHT, OUTLAY_ABS_WEIGHT },
                new int[] { 2, 3, 4 });
        if (m_dataOutlay != null)
            m_dataOutlay.clear();

        logger.debug("outlay time is over" + DATE_FORMATTER.format(new Date()));
        //
        doBigPrjQuery();
        //
        setUpData(m_dataBigPrj, new String[] { PRJ_TOTAL_NUM }, new int[] { 5 });
        if (m_dataBigPrj != null)
            m_dataBigPrj.clear();

        logger.debug("doBigPrjQuery time is over" + DATE_FORMATTER.format(new Date()));
        //
        doBigPrjQueryOther();
        //
        setUpData(m_dataBigPrjOther, new String[] { PRJ_PROB_WEIGHT, PRJ_ABS_WEIGHT }, new int[] { 6, 7 });
        if (m_dataBigPrjOther != null)
            m_dataBigPrjOther.clear();
        logger.debug("doBigPrjQueryOther time is over" + DATE_FORMATTER.format(new Date()));

        doProductQuery();

        setUpProductData(m_dataProduct);
        setUpData(m_dataPatent, new String[] { PRD_PATENT_WEIGHT }, new int[] { 8 });
        setUpData(m_dataCitePaper, new String[] { PRD_CITEPAPER_WEIGHT }, new int[] { 11 });
        setUpData(m_data3Index, new String[] { PRD_ABS_WEIGHT }, new int[] { 10 });
        setUpProductWeight();
        setUpData(m_dataProductAbs, new String[] { PRD_ABS_WEIGHT }, new int[14]);
        setUpAllData();
        //
        formatDatas();

        clear();
        return m_datas;
    }

    private void changeOutlay() {
        for (int i = 2; i < m_datas.length; i++) {
            m_datas[i][3] = new Double(doSubtration(m_datas[i][3], m_datas[i][6]));
        }
    }

    private void formatDatas() {
        for (int i = TITLE_HEIGHT; i < m_datas.length; i++) {
            for (int j = LABEL_WIDTH; j < m_datas[i].length; j++) {
                if (m_datas[i][j] != null) {
                    Double d = new Double((m_datas[i][j]).toString());
                    m_datas[i][j] = NUM_FORMATTER.format(d);
                }
            }
        }
    }

    private void setUpAllData() {
        for (int i = 2; i < m_datas.length; i++) {
            double sum = (m_datas[i][4] != null
                    ? Double.parseDouble(
                            StringUtils.isNotEmpty(m_datas[i][4].toString()) ? m_datas[i][4].toString() : "0")
                    : 0.0)
                    + (m_datas[i][7] != null ? Double.parseDouble(
                            StringUtils.isNotEmpty(m_datas[i][7].toString()) ? m_datas[i][7].toString() : "0")
                            : 0.0)
                    + (m_datas[i][14] != null ? Double.parseDouble(
                            StringUtils.isNotEmpty(m_datas[i][14].toString()) ? m_datas[i][14].toString() : "0")
                            : 0.0);
            m_datas[i][15] = StringUtils.isNotEmpty(String.valueOf(sum)) ? "0.0" : String.valueOf(sum);
        }
    }

    private void setUpProductWeight() {
        for (int i = 2; i < m_datas.length; i++) {
            double dblSumValue = 0.0;
            for (int j = 8; j <= 12; j++) {
                double dblValue = m_datas[i][j] != null
                        ? Double.parseDouble(
                                StringUtils.isNotEmpty(m_datas[i][j].toString()) ? m_datas[i][j].toString() : "0")
                        : 0.0;
                dblSumValue += dblValue;
                m_datas[i][13] = String.valueOf(dblSumValue);
            }
        }
    }

    private void setUpProductData(IObjects _products) throws PureException {
        DolphinObject obj = null;
        for (Iterator iter = _products.iterator(); iter.hasNext();) {
            obj = (DolphinObject) iter.next();
            String sForm = obj.getStrProperty(PRODUCT_FORM);
            int nForm = StringUtils.isNotEmpty(sForm) ? Integer.parseInt(sForm) : 0;
            switch (nForm) {
            // 
            case 1: {
                addProductValue(obj, 12);
                break;
            }
            // 
            case 2: {
                addProductValue(obj, 9);
                break;
            }
            default:
                break;
            }
        }
    }

    private void addProductValue(DolphinObject _obj, int _nColIndex) throws PureException {
        int nDept = _obj.getIntProperty(DEPARTMENT, 0);
        int nRowIndex = putDataToCell(nDept);
        double dblValue = _obj.getDoubleProperty(PRD_ABS_WEIGHT, 0.0);
        addValueToCell(_nColIndex, nRowIndex, dblValue);
    }

    private void doProductQuery() throws PureException {
        logger.debug("...now it's productTime" + System.currentTimeMillis());
        executeProductQuery();
        execute3IndexQuery();
        executeCitePaperQuery();
        executePatentQuery();
        executeSumProductAll();
        logger.debug("...now it's productTime over" + System.currentTimeMillis());
    }

    private void execute3IndexQuery() throws PureException {
        String sSql = "select map.dept_id,map.obj_id AS _ID from srm_prj_obj_dept_mapping map inner join srm_prj_product prd on (obj_type = "
                + SRMTypes.PRODUCT + " and obj_id = prd.product_id) where map.weight_year = " + m_nWeightYear
                + " and map.is_temp = 0 and map.obj_type = " + SRMTypes.PRODUCT + " and l_product_form = '3'";
        IStatement query = null;
        IObjects objs = null;
        try {
            IProductMgr mgr = (IProductMgr) ArkContentHelper.getContentMgrOf(Product.class);
            query = mgr.createQuery(sSql, 0);
            objs = query.executeQuery(false);

            DolphinObject obj = null;
            String sID = "''";
            while ((obj = objs.next()) != null) {
                Product product = (Product) mgr.lookupById(obj.getIntProperty("_ID", 0));
                double dblWeight = mgr.getTrueProbWeight(product);
                if (dblWeight <= 0.00000001) {
                    sID += "," + "'" + product.getId() + "'";
                }
            }
            String sIDs = "(" + sID + ")";
            query.clear(false);
            String sSql2 = "select sum(map.PROB_WEIGHT) AS " + PRD_ABS_WEIGHT + ",prd.L_Product_form AS "
                    + PRODUCT_FORM + ",map.dept_id AS " + DEPARTMENT
                    + " from srm_prj_obj_dept_mapping map inner join srm_prj_product prd on  (obj_type = "
                    + SRMTypes.PRODUCT + " and obj_id = prd.product_id) where map.weight_year = " + m_nWeightYear
                    + " and map.obj_type = " + SRMTypes.PRODUCT
                    + " and map.is_temp = 0 and prd.l_product_form = '3' and map.is_temp = 0 and map.obj_id not in "
                    + sIDs + "  group by prd.L_Product_form,map.dept_id";
            query = mgr.createQuery(sSql2, 0);
            m_data3Index = query.executeQuery(false);
        } finally {
            if (query != null)
                query.clear();
            if (objs != null)
                objs.clear();
        }

    }

    private void executeSumProductAll() throws PureException {
        String sSql = "select sum(map.ABS_WEIGHT) as " + PRD_ABS_WEIGHT + ",map.dept_id as " + DEPARTMENT
                + " from srm_prj_obj_dept_mapping map inner join srm_prj_product prd on (obj_type = "
                + SRMTypes.PRODUCT + " and obj_id = prd.product_id) where map.weight_year = " + m_nWeightYear
                + " and map.is_temp = 0 and map.obj_type = " + SRMTypes.PRODUCT + " group by map.dept_id";
        IStatement query = null;
        try {
            IContentMgr mgr = ArkContentHelper.getContentMgrOf(OutlayUnit.class);
            query = mgr.createQuery(sSql, 0);
            m_dataProductAbs = query.executeQuery(false);
        } finally {
            if (query != null)
                query.clear();
        }
    }

    private void executePatentQuery() throws PureException {
        String sSql = "select sum(map.PROB_WEIGHT) AS " + PRD_PATENT_WEIGHT + ",map.dept_id AS " + DEPARTMENT
                + " from srm_prj_obj_dept_mapping map inner join srm_prj_patent patent on (obj_type = "
                + SRMTypes.PATENT + " and obj_id = patent.product_id) where map.weight_year = " + m_nWeightYear
                + " and map.is_temp = 0 and map.obj_type = " + SRMTypes.PATENT + " group by map.dept_id";
        IStatement query = null;
        try {
            IContentMgr mgr = ArkContentHelper.getContentMgrOf(OutlayUnit.class);
            query = mgr.createQuery(sSql, 0);
            m_dataPatent = query.executeQuery(false);
        } finally {
            if (query != null)
                query.clear();
        }
    }

    private void executeCitePaperQuery() throws PureException {
        String sSql = "select sum(map.PROB_WEIGHT) AS " + PRD_CITEPAPER_WEIGHT + ",map.dept_id AS " + DEPARTMENT
                + " from srm_prj_obj_dept_mapping map inner join srm_product_cite_paper cite on (obj_type = "
                + SRMTypes.CITE_PAPER + " and obj_id = cite.cite_paper_id) where map.weight_year = " + m_nWeightYear
                + " and map.is_temp = 0 and map.obj_type = " + SRMTypes.CITE_PAPER + " group by map.dept_id";
        IStatement query = null;
        try {
            IContentMgr mgr = ArkContentHelper.getContentMgrOf(OutlayUnit.class);
            query = mgr.createQuery(sSql, 0);
            m_dataCitePaper = query.executeQuery(false);
        } finally {
            if (query != null)
                query.clear();
        }
    }

    private void executeProductQuery() throws PureException {
        String sSql = "select sum(map.PROB_WEIGHT) AS " + PRD_ABS_WEIGHT + ",prd.L_Product_form AS " + PRODUCT_FORM
                + ",map.dept_id AS " + DEPARTMENT
                + " from srm_prj_obj_dept_mapping map inner join srm_prj_product prd on  (obj_type = "
                + SRMTypes.PRODUCT + " and obj_id = prd.product_id) where map.weight_year = " + m_nWeightYear
                + " and map.is_temp = 0 and map.obj_type = " + SRMTypes.PRODUCT
                + "  group by prd.L_Product_form,map.dept_id";
        IStatement query = null;
        try {
            IContentMgr mgr = ArkContentHelper.getContentMgrOf(OutlayUnit.class);
            query = mgr.createQuery(sSql, 0);
            m_dataProduct = query.executeQuery(false);
        } finally {
            if (query != null)
                query.clear();
        }
    }

    private void doBigPrjQuery() throws PureException {
        IObjects objs = null;
        String sSql = "select sum(TAB.total_num) as " + PRJ_TOTAL_NUM + ",TAB.department_id AS " + DEPARTMENT
                + ",TAB.outlayunit_id as _ID"
                + " from ((select outlayunit_id, unit0.PROB_WEIGHT,unit0.project_id,unit0.department_id,total_num, STATUS,DEDUCT_RATIO,arrived_date, 1 as _temp  from srm_prj_outlay_unit0 unit0 inner join srm_prj_project prj on prj.project_id = unit0.project_id where year(unit0.arrived_date) = "
                + m_nWeightYear
                + "  and unit0.status<>2  and prj.is_big = 1 and prj.is_big_checked = 1 and unit0.DEDUCT_RATIO = '100') union (select outlayunit_id, unit.PROB_WEIGHT, unit.project_id, unit.department_id, total_num, STATUS, DEDUCT_RATIO,arrived_date,0 AS _TEMP  from srm_prj_outlay_unit unit inner join srm_prj_project prj on prj.project_id = unit.project_id where year(unit.arrived_date) =  "
                + m_nWeightYear
                + " and unit.status<>2 and prj.is_big = 1 and prj.is_big_checked = 1 and unit.DEDUCT_RATIO = '100')) AS TAB group by TAB.department_id,TAB.outlayunit_id";

        IStatement query = null;
        try {
            IContentMgr mgr = ArkContentHelper.getContentMgrOf(OutlayUnit.class);
            query = mgr.createQuery(sSql, 0);
            objs = query.executeQuery(false);
            for (Iterator iter = objs.iterator(); iter.hasNext();) {
                OutlayUnit unit = (OutlayUnit) iter.next();
                DolphinObject obj = prepareObject(unit, true);
                m_dataBigPrj.add(obj);
            }
        } finally {
            if (query != null)
                query.clear();
            if (objs != null)
                objs.clear();
        }
    }

    private void doBigPrjQueryOther() throws PureException {
        IObjects objs = null;
        String sSql = "select " + " sum(TAB.PROB_WEIGHT) AS " + PRJ_PROB_WEIGHT + ", 0 AS " + PRJ_ABS_WEIGHT
                + ",TAB.department_id AS " + DEPARTMENT + ",TAB.outlayunit_id as _ID"
                + " from ((select outlayunit_id, unit0.PROB_WEIGHT,unit0.project_id,unit0.department_id,total_num, STATUS,DEDUCT_RATIO,arrived_date, 1 as _temp  from srm_prj_outlay_unit0 unit0 inner join srm_prj_project prj on prj.project_id = unit0.project_id where year(unit0.arrived_date) = "
                + m_nWeightYear
                + "  and unit0.status<>2 and prj.is_big = 1 and prj.is_big_checked = 1) union (select outlayunit_id, unit.PROB_WEIGHT, unit.project_id, unit.department_id, total_num, STATUS, DEDUCT_RATIO,arrived_date,0 AS _TEMP  from srm_prj_outlay_unit unit inner join srm_prj_project prj on prj.project_id = unit.project_id where year(unit.arrived_date) =  "
                + m_nWeightYear
                + " and unit.status<>2 and prj.is_big = 1 and prj.is_big_checked = 1)) AS TAB group by TAB.department_id,TAB.outlayunit_id";
        IStatement query = null;
        try {
            IContentMgr mgr = ArkContentHelper.getContentMgrOf(OutlayUnit.class);
            query = mgr.createQuery(sSql, 0);
            objs = query.executeQuery(false);
            int i = 0;
            for (Iterator iter = objs.iterator(); iter.hasNext(); i++) {
                OutlayUnit unit = (OutlayUnit) iter.next();
                DolphinObject obj = prepareObject(unit, true);
                m_dataBigPrjOther.add(obj);
            }
            System.out.println("size2 is = " + i);
        } finally {
            if (query != null)
                query.clear();
            if (objs != null)
                objs.clear();
        }
    }

    private List doOutlayQuery() throws PureException {
        List list = new ArrayList();
        System.out.println("query to start::::" + new Date());
        String sSql = "select sum(TAB.total_num) as " + ARRIVE_OUTLAY + ", sum(TAB.PROB_WEIGHT) as "
                + OUTLAY_PROB_WEIGHT + ", TAB.department_id as " + DEPARTMENT + ", TAB.outlayunit_id as _ID "
                + " from ((select outlayunit_id, unit0.PROB_WEIGHT,unit0.project_id,unit0.department_id,total_num, STATUS,DEDUCT_RATIO,arrived_date, 1 as _temp  from srm_prj_outlay_unit0 unit0 inner join srm_prj_project prj on prj.project_id = unit0.project_id where year(unit0.arrived_date) = "
                + m_nWeightYear
                + "  and unit0.status<>2) union (select outlayunit_id, unit.PROB_WEIGHT, unit.project_id, unit.department_id, total_num, STATUS, DEDUCT_RATIO,arrived_date,0 AS _TEMP  from srm_prj_outlay_unit unit inner join srm_prj_project prj on prj.project_id = unit.project_id where year(unit.arrived_date) =  "
                + m_nWeightYear + " and unit.status<>2)) AS TAB group by TAB.department_id,TAB.outlayunit_id";
        IObjects objs = null;
        IStatement query = null;
        try {
            IContentMgr mgr = ArkContentHelper.getContentMgrOf(OutlayUnit.class);
            query = mgr.createQuery(sSql, 0);
            objs = query.executeQuery(false);
            int i = 0;
            System.out.println("query end::::" + new Date());
            OutlayUnit unit = null;
            while ((unit = (OutlayUnit) objs.next()) != null) {
                //                System.out.println("--------> " + unit.display());
                list.add(prepareObject(unit, true));
            }
            System.out.println("size1 is = " + list.size());
            return list;
        } finally {
            if (query != null)
                query.clear();
            if (objs != null)
                objs.clear();
        }
    }

    /**
     * render
     * @param _unit
     * @param _bNeedBigWeight
     * @return
     * @throws PureException
     */
    private DolphinObject prepareObject(OutlayUnit _unit, boolean _bNeedBigWeight) throws PureException {
        String sId = _unit.getPropertyAsString("_ID");
        int nId = StringUtils.isNotEmpty(sId) ? Integer.parseInt(sId) : 0;
        OutlayUnit unit = (OutlayUnit) ArkContentHelper.lookupById4Edit(OutlayUnit.class, nId);
        DolphinObject object = new DolphinObject();
        if (unit != null) {
            String sArrivedOutlay = _unit.getPropertyAsString(ARRIVE_OUTLAY);
            String sProbWeight = _unit.getPropertyAsString(OUTLAY_PROB_WEIGHT);
            String sAbsWeight = _unit.getPropertyAsString(OUTLAY_ABS_WEIGHT);

            String sDepartmentId = _unit.getPropertyAsString(DEPARTMENT);

            String sPrjProbWeight = _unit.getPropertyAsString(PRJ_PROB_WEIGHT);
            String sPrjTotalNum = _unit.getPropertyAsString(PRJ_TOTAL_NUM);
            String sPrjAbsWeight = _unit.getPropertyAsString(PRJ_ABS_WEIGHT);

            double dblArrivedOutlay = StringUtils.isNotEmpty(sArrivedOutlay) ? Double.parseDouble(sArrivedOutlay)
                    : 0.0;
            double dblProbWeight = StringUtils.isNotEmpty(sProbWeight) ? Double.parseDouble(sProbWeight) : 0.0;
            int nDepartmentId = StringUtils.isNotEmpty(sDepartmentId) ? Integer.parseInt(sDepartmentId) : 0;
            double dblPrjProbWeight = StringUtils.isNotEmpty(sPrjProbWeight) ? Double.parseDouble(sPrjProbWeight)
                    : 0.0;
            double dblPrjTotalNum = StringUtils.isNotEmpty(sPrjTotalNum) ? Double.parseDouble(sPrjTotalNum) : 0.0;
            double dblPrjAbsWeight = StringUtils.isNotEmpty(sPrjAbsWeight) ? Double.parseDouble(sPrjAbsWeight)
                    : 0.0;
            double dblAbsWeight = StringUtils.isNotEmpty(sAbsWeight) ? Double.parseDouble(sAbsWeight) : 0.0;

            double dblBigProbWeight = unit.getBigProbWeight();

            object.setProperty(ARRIVE_OUTLAY, dblArrivedOutlay);
            object.setProperty(OUTLAY_PROB_WEIGHT, dblProbWeight - dblBigProbWeight);
            object.setProperty(DEPARTMENT, nDepartmentId);

            object.setProperty(PRJ_PROB_WEIGHT, dblPrjProbWeight);
            object.setProperty(PRJ_ABS_WEIGHT, dblBigProbWeight);
            object.setProperty(PRJ_TOTAL_NUM, dblPrjTotalNum);

        }
        return object;
    }

    private void setUpData(IObjects _objs, String[] params, int[] colIndex) throws PureException {
        DolphinObject obj = null;
        for (Iterator iter = _objs.iterator(); iter.hasNext();) {
            obj = (DolphinObject) iter.next();
            int nDept = obj.getIntProperty(DEPARTMENT, -1);
            int rowIndex = putDataToCell(nDept);
            for (int i = 0; i < params.length; i++) {
                double dblValue = obj.getDoubleProperty(params[i], 0.0);
                addValueToCell(colIndex[i], rowIndex, dblValue);
            }
        }
    }

    private void setUpData(List _objs, String[] params, int[] colIndex) throws PureException {
        DolphinObject obj = null;
        System.out.println("to start set up data::::" + new Date());
        for (Iterator iter = _objs.iterator(); iter.hasNext();) {
            obj = (DolphinObject) iter.next();
            int nDept = obj.getIntProperty(DEPARTMENT, -1);
            int rowIndex = putDataToCell(nDept);
            for (int i = 0; i < params.length; i++) {
                double dblValue = obj.getDoubleProperty(params[i], 0.0);
                addValueToCell(colIndex[i], rowIndex, dblValue);
            }
            obj.clear();
        }
        System.out.println("end set up data::::" + new Date());
    }

    private void addValueToCell(int _nCol, int _nRowIndex, double _dblValue) {
        Object cellValue = m_datas[_nRowIndex][_nCol];
        if (cellValue == null) {
            m_datas[_nRowIndex][_nCol] = String.valueOf(_dblValue);
        } else {
            String sTemp = (String) m_datas[_nRowIndex][_nCol];
            double dblValue = StringUtils.isNotEmpty(sTemp) ? Double.parseDouble(sTemp) : 0.0;
            dblValue += _dblValue;
            m_datas[_nRowIndex][_nCol] = String.valueOf(dblValue);
        }
    }

    private int putDataToCell(int _nDept) throws PureException {
        Organization org = null;
        Integer row = null;
        try {
            org = getCollege(_nDept);
            if (org != null) {
                String sCode = org.getCode();
                if (m_codeRowIndexMap.containsKey(sCode)) {
                    row = (Integer) m_codeRowIndexMap.get(sCode);
                    if (row != null)
                        return row.intValue() - 1;
                }
            }
            return TITLE_HEIGHT + m_codeRowIndexMap.size() + OTHER_HEIGHT - 1;
        } finally {
            if (org != null)
                org = null;
            if (row != null)
                row = null;
        }
    }

    private Organization getCollege(int _nDept) throws PureException {
        IOrganizationMgr mgr = getOrgMgr();

        Organization org = (Organization) mgr.lookupById(_nDept);

        if (org != null) {
            if (m_hHospitals.containsKey(org.getCode()))
                return org;
            if (m_others.containsKey(org.getCode()))
                return org;

            int nParentId = org.getParentId();
            if (nParentId > 0 && !SRMConstants.ORG_TYPE.INSTITUTE.equals(org.getOrgType())) {
                org = (Organization) mgr.lookupById(nParentId);
            }
        }

        return org;
    }

    private void renderTitleAndLabel() {
        renderTitle();
        renderLabel();
    }

    private void renderLabel() {
        for (Iterator iter = m_codeRowIndexMap.entrySet().iterator(); iter.hasNext();) {
            Map.Entry en = (Map.Entry) iter.next();
            String sCode = (String) en.getKey();
            Integer rowIndex = (Integer) en.getValue();
            // 1
            int nRowIndex = rowIndex != null ? rowIndex.intValue() - 1 : 0;
            if (nRowIndex == 0)
                continue;
            m_datas[nRowIndex][0] = sCode;
            m_datas[nRowIndex][1] = m_codeLabelMap.get(sCode);
        }
        m_datas[TITLE_HEIGHT + m_codeRowIndexMap.size() + OTHER_HEIGHT - 1][1] = "";
        m_datas[TITLE_HEIGHT + m_codeRowIndexMap.size() + OTHER_HEIGHT + SUM_HEIGHT - 1][1] = "";
    }

    private void renderTitle() {
        m_datas[0] = new String[] { " ", " ", "", " ", " ", "", " ", " ", "", " ", " ", " ", " ",
                " ", "", "" };
        m_datas[1] = new String[] { " ", "", "", "", "",
                "()", "", "", "", "",
                "", "", "", "", "", "" };
    }

    private void initLabelOrgArea() throws PureException {
        IOrganizationMgr mgr = getOrgMgr();
        List colleges = mgr.findAllByType(SRMConstants.ORG_TYPE.COLLEGE, true);
        int nRowNumber = TITLE_HEIGHT + 1;
        for (Iterator iter = colleges.iterator(); iter.hasNext();) {
            Organization org = (Organization) iter.next();
            String sCode = org.getCode();
            m_codeLabelMap.put(sCode, org.getName());
            m_codeRowIndexMap.put(sCode, new Integer(nRowNumber++));
        }
        // other
        for (Iterator iter = m_others.entrySet().iterator(); iter.hasNext();) {
            Map.Entry en = (Map.Entry) iter.next();
            String sCode = (String) en.getKey();
            String sOrgName = (String) en.getValue();
            m_codeLabelMap.put(sCode, sOrgName);
            m_codeRowIndexMap.put(sCode, new Integer(nRowNumber++));
        }
        // hosptial
        for (Iterator iter = m_hHospitals.entrySet().iterator(); iter.hasNext();) {
            Map.Entry en = (Map.Entry) iter.next();
            String sCode = (String) en.getKey();
            String sOrgName = (String) en.getValue();
            m_codeLabelMap.put(sCode, sOrgName);
            m_codeRowIndexMap.put(sCode, new Integer(nRowNumber++));
        }
    }

    public void setParameters(Map _sParams) throws ParseException {
        String[] sYear = (String[]) _sParams.get("year");
        m_nWeightYear = StringUtils.isNotEmpty(sYear[0]) ? Integer.parseInt(sYear[0]) : 0;
        // m_nWeightYear = Integer.parseInt(((String) _sParams.get("year")));
    }

    private IOrganizationMgr getOrgMgr() throws PureException {
        if (m_OrgMgr != null)
            return m_OrgMgr;
        return m_OrgMgr = (IOrganizationMgr) ArkContentHelper.getContentMgrOf(Organization.class);
    }

    private void clear() {
        if (m_codeCellMap != null)
            m_codeCellMap.clear();
        if (m_codeLabelMap != null)
            m_codeLabelMap.clear();
        if (m_codeRowIndexMap != null)
            m_codeRowIndexMap.clear();
        if (m_hHospitals != null)
            m_hHospitals.clear();
        if (m_others != null)
            m_others.clear();
        if (m_dataAll != null)
            m_dataAll.clear();
        if (m_dataBigPrj != null)
            m_dataBigPrj.clear();
        if (m_dataOutlay != null)
            m_dataOutlay.clear();
        if (m_dataProduct != null)
            m_dataProduct.clear();
        if (m_dataProductAbs != null)
            m_dataProductAbs.clear();
        if (m_data3Index != null)
            m_data3Index.clear();
        if (m_dataPatent != null)
            m_dataPatent.clear();
    }

    private double doSubtration(Object obj1, Object obj2) {
        double objValue1 = 0.0;
        double objValue2 = 0.0;

        if (obj1 != null) {
            objValue1 = Double.parseDouble(obj1.toString());
        }
        if (obj2 != null) {
            objValue2 = Double.parseDouble(obj2.toString());
        }

        return objValue1 - objValue2;
    }

    public static void main(String[] args) {
        try {

            WeightStatistic s = new WeightStatistic();
            Map m = new HashMap();
            String[] year = { "2007" };
            m.put("year", year);
            s.setParameters(m);
            //            s.doOutlayQuery();
            Object[][] o = s.buildDatas(false, false);
            for (int i = 0; i < o.length; i++) {
                for (int j = 0; j < o[i].length; j++) {
                    System.out.print("\t" + "\t" + "\t" + o[i][j]);
                }
                System.out.println();
            }
        } catch (Exception ex) {
            // TODO Auto-generated catch block
            ex.printStackTrace(System.err);
        } finally {
        }
    }
}