Commit 07259995 authored by AlanGao's avatar AlanGao
Browse files

update

parent 458409b4
package com.jsh.service.materials;
import java.util.List;
import java.util.Map;
import net.sf.json.JSONArray;
import net.sf.json.JSONObject;
import com.jsh.base.BaseService;
import com.jsh.base.Log;
import com.jsh.util.AssetConstants;
import com.jsh.dao.materials.AccountItemIDAO;
import com.jsh.util.JshException;
import com.jsh.model.po.Asset;
import com.jsh.model.po.AccountHead;
import com.jsh.model.po.AccountItem;
import com.jsh.util.PageUtil;
import com.jsh.util.Tools;
public class AccountItemService extends BaseService<AccountItem> implements AccountItemIService
{
public class AccountItemService extends BaseService<AccountItem> implements AccountItemIService {
@SuppressWarnings("unused")
private AccountItemIDAO accoumtItemDao;
......@@ -29,8 +15,7 @@ public class AccountItemService extends BaseService<AccountItem> implements Acco
@Override
protected Class<AccountItem> getEntityClass()
{
protected Class<AccountItem> getEntityClass() {
return AccountItem.class;
}
......
package com.jsh.service.materials;
import com.jsh.base.BaseIService;
import com.jsh.util.JshException;
import com.jsh.model.po.DepotHead;
import com.jsh.model.po.UserBusiness;
import com.jsh.util.JshException;
import com.jsh.util.PageUtil;
public interface DepotHeadIService extends BaseIService<DepotHead>
{
/*
* 获取MaxId
*/
void find(PageUtil<DepotHead> depotHead,String maxid)throws JshException;
void findAllMoney(PageUtil<DepotHead> depotHead, Integer supplierId, String type, String subType, String mode)throws JshException;
public interface DepotHeadIService extends BaseIService<DepotHead> {
/*
* 获取MaxId
*/
void find(PageUtil<DepotHead> depotHead, String maxid) throws JshException;
void findAllMoney(PageUtil<DepotHead> depotHead, Integer supplierId, String type, String subType, String mode) throws JshException;
void batchSetStatus(Boolean status,String depotHeadIDs);
void batchSetStatus(Boolean status, String depotHeadIDs);
void findInDetail(PageUtil pageUtil,String beginTime,String endTime, String type, Long pid,String dids,Long oId)throws JshException;
void findInDetail(PageUtil pageUtil, String beginTime, String endTime, String type, Long pid, String dids, Long oId) throws JshException;
void findInOutMaterialCount(PageUtil pageUtil,String beginTime,String endTime, String type, Long pid,String dids,Long oId)throws JshException;
void findInOutMaterialCount(PageUtil pageUtil, String beginTime, String endTime, String type, Long pid, String dids, Long oId) throws JshException;
void findMaterialsListByHeaderId(PageUtil pageUtil,Long headerId)throws JshException;
void findMaterialsListByHeaderId(PageUtil pageUtil, Long headerId) throws JshException;
void findStatementAccount(PageUtil pageUtil,String beginTime,String endTime, Long organId, String supType)throws JshException;
void findStatementAccount(PageUtil pageUtil, String beginTime, String endTime, Long organId, String supType) throws JshException;
void getHeaderIdByMaterial(PageUtil pageUtil,String materialParam,String depotIds)throws JshException;
void getHeaderIdByMaterial(PageUtil pageUtil, String materialParam, String depotIds) throws JshException;
}
package com.jsh.service.materials;
import java.io.InputStream;
import java.util.List;
import net.sf.json.JSONArray;
import com.jsh.base.BaseIService;
import com.jsh.util.JshException;
import com.jsh.model.po.Asset;
import com.jsh.model.po.DepotHead;
import com.jsh.model.po.DepotItem;
import com.jsh.util.JshException;
import com.jsh.util.PageUtil;
import net.sf.json.JSONArray;
import java.io.InputStream;
public interface DepotItemIService extends BaseIService<DepotItem> {
void findByType(PageUtil<DepotItem> depotItem, String type, Integer ProjectId, Long MId, String MonthTime, Boolean isPrev) throws JshException;
public interface DepotItemIService extends BaseIService<DepotItem>
{
void findByType(PageUtil<DepotItem> depotItem, String type,Integer ProjectId, Long MId, String MonthTime,Boolean isPrev)throws JshException;
void findByTypeAndMaterialId(PageUtil<DepotItem> depotItem, String type, Long MId) throws JshException;
void findByTypeAndMaterialId(PageUtil<DepotItem> depotItem, String type, Long MId)throws JshException;
void findDetailByTypeAndMaterialId(PageUtil<DepotItem> depotItem, Long MId) throws JshException;
void findDetailByTypeAndMaterialId(PageUtil<DepotItem> depotItem, Long MId)throws JshException;
void findPriceByType(PageUtil<DepotItem> depotItem, String type, Integer ProjectId, Long MId, String MonthTime, Boolean isPrev) throws JshException;
void findPriceByType(PageUtil<DepotItem> depotItem, String type,Integer ProjectId, Long MId, String MonthTime,Boolean isPrev)throws JshException;
void buyOrSale(PageUtil<DepotItem> depotItem, String type, String subType, Long MId, String MonthTime, String sumType)throws JshException;
void buyOrSale(PageUtil<DepotItem> depotItem, String type, String subType, Long MId, String MonthTime, String sumType) throws JshException;
void findGiftByType(PageUtil<DepotItem> depotItem, String subType,Integer ProjectId, Long MId, String type)throws JshException;
void findGiftByType(PageUtil<DepotItem> depotItem, String subType, Integer ProjectId, Long MId, String type) throws JshException;
/**
* 导出信息
* @return
*/
InputStream exmportExcel(String isAllPage,JSONArray dataArray)throws JshException;
/**
* 导出信息
*
* @return
*/
InputStream exmportExcel(String isAllPage, JSONArray dataArray) throws JshException;
}
package com.jsh.service.materials;
import com.jsh.base.BaseService;
import com.jsh.base.Log;
import com.jsh.dao.materials.DepotItemIDAO;
import com.jsh.model.po.DepotItem;
import com.jsh.util.JshException;
import com.jsh.util.PageUtil;
import jxl.Workbook;
import jxl.write.Label;
import jxl.write.WritableSheet;
import jxl.write.WritableWorkbook;
import net.sf.json.JSONArray;
import net.sf.json.JSONObject;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.InputStream;
import java.io.OutputStream;
import java.text.DecimalFormat;
import java.util.List;
import java.util.Map;
import net.sf.json.JSONArray;
import net.sf.json.JSONObject;
public class DepotItemService extends BaseService<DepotItem> implements DepotItemIService {
@SuppressWarnings("unused")
private DepotItemIDAO depotItemDao;
import jxl.Workbook;
import jxl.write.Label;
import jxl.write.WritableSheet;
import jxl.write.WritableWorkbook;
import com.jsh.base.BaseService;
import com.jsh.base.Log;
import com.jsh.util.AssetConstants;
import com.jsh.dao.materials.DepotItemIDAO;
import com.jsh.util.JshException;
import com.jsh.model.po.Asset;
import com.jsh.model.po.DepotHead;
import com.jsh.model.po.DepotItem;
import com.jsh.util.PageUtil;
import com.jsh.util.Tools;
public void setDepotItemDao(DepotItemIDAO depotItemDao) {
this.depotItemDao = depotItemDao;
}
public class DepotItemService extends BaseService<DepotItem> implements DepotItemIService
{
@SuppressWarnings("unused")
private DepotItemIDAO depotItemDao;
public void setDepotItemDao(DepotItemIDAO depotItemDao) {
this.depotItemDao = depotItemDao;
}
@Override
protected Class<DepotItem> getEntityClass() {
return DepotItem.class;
}
@Override
public void findByType(PageUtil<DepotItem> pageUtil, String type, Integer ProjectId, Long MId, String MonthTime, Boolean isPrev) throws JshException {
depotItemDao.findByType(pageUtil, type, ProjectId, MId, MonthTime, isPrev);
}
@Override
public void findByTypeAndMaterialId(PageUtil<DepotItem> pageUtil, String type, Long MId) throws JshException {
depotItemDao.findByTypeAndMaterialId(pageUtil, type, MId);
}
@Override
public void findDetailByTypeAndMaterialId(PageUtil<DepotItem> pageUtil, Long MId) throws JshException {
depotItemDao.findDetailByTypeAndMaterialId(pageUtil, MId);
}
@Override
protected Class<DepotItem> getEntityClass()
{
return DepotItem.class;
}
@Override
public void findByType(PageUtil<DepotItem> pageUtil, String type,Integer ProjectId,Long MId, String MonthTime,Boolean isPrev) throws JshException
{
depotItemDao.findByType(pageUtil, type, ProjectId, MId, MonthTime,isPrev);
public void findPriceByType(PageUtil<DepotItem> pageUtil, String type, Integer ProjectId, Long MId, String MonthTime, Boolean isPrev) throws JshException {
depotItemDao.findPriceByType(pageUtil, type, ProjectId, MId, MonthTime, isPrev);
}
@Override
public void findByTypeAndMaterialId(PageUtil<DepotItem> pageUtil, String type,Long MId) throws JshException
{
depotItemDao.findByTypeAndMaterialId(pageUtil, type, MId);
}
@Override
public void buyOrSale(PageUtil<DepotItem> pageUtil, String type, String subType, Long MId, String MonthTime, String sumType) throws JshException {
depotItemDao.buyOrSale(pageUtil, type, subType, MId, MonthTime, sumType);
}
@Override
public void findDetailByTypeAndMaterialId(PageUtil<DepotItem> pageUtil,Long MId) throws JshException
{
depotItemDao.findDetailByTypeAndMaterialId(pageUtil, MId);
}
@Override
public void findGiftByType(PageUtil<DepotItem> pageUtil, String subType, Integer ProjectId, Long MId, String type) throws JshException {
depotItemDao.findGiftByType(pageUtil, subType, ProjectId, MId, type);
}
@Override
public void findPriceByType(PageUtil<DepotItem> pageUtil, String type,Integer ProjectId,Long MId, String MonthTime,Boolean isPrev) throws JshException
{
depotItemDao.findPriceByType(pageUtil, type, ProjectId, MId, MonthTime,isPrev);
}
/**
* 导出Excel表格
*/
@Override
public void buyOrSale(PageUtil<DepotItem> pageUtil, String type,String subType, Long MId, String MonthTime, String sumType) throws JshException
{
depotItemDao.buyOrSale(pageUtil, type, subType, MId, MonthTime, sumType);
public InputStream exmportExcel(String isAllPage, JSONArray dataArray) throws JshException {
try {
//将OutputStream转化为InputStream
ByteArrayOutputStream out = new ByteArrayOutputStream();
putDataOnOutputStream(out, dataArray);
return new ByteArrayInputStream(out.toByteArray());
} catch (Exception e) {
Log.errorFileSync(">>>>>>>>>>>>>>>>>>>>>>>导出信息为excel表格异常", e);
throw new JshException("export asset info to excel exception", e);
}
}
@Override
public void findGiftByType(PageUtil<DepotItem> pageUtil, String subType,Integer ProjectId,Long MId,String type) throws JshException
{
depotItemDao.findGiftByType(pageUtil, subType, ProjectId, MId, type);
}
/**
* 导出Excel表格
*/
@Override
public InputStream exmportExcel(String isAllPage,JSONArray dataArray)throws JshException
{
try
{
//将OutputStream转化为InputStream
ByteArrayOutputStream out = new ByteArrayOutputStream();
putDataOnOutputStream(out,dataArray);
return new ByteArrayInputStream(out.toByteArray());
}
catch (Exception e)
{
Log.errorFileSync(">>>>>>>>>>>>>>>>>>>>>>>导出信息为excel表格异常", e);
throw new JshException("export asset info to excel exception",e);
}
}
/**
* 生成excel表格
* @param os
*/
@SuppressWarnings("deprecation")
private void putDataOnOutputStream(OutputStream os,JSONArray dataArray)
{
WritableWorkbook workbook = null;
try
{
workbook = Workbook.createWorkbook(os);
WritableSheet sheet = workbook.createSheet("进销存报表", 0);
//增加列头
int[] colunmWidth = {10,10,10,10,10,10,15,15,15,15,15};
String[] colunmName = {"名称","型号","规格","颜色","单位","单价","上月结存数量","入库数量","出库数量","本月结存数量","结存金额"};
for(int i = 0 ;i < colunmWidth.length;i ++)
{
sheet.setColumnView(i,colunmWidth[i]);
sheet.addCell(new Label(i, 0, colunmName[i]));
}
if (null != dataArray &&dataArray.size() > 0)
{
for(int j=0; j < dataArray.size(); j++){
JSONObject jo = JSONObject.fromObject(dataArray.get(j));
sheet.addCell(new Label(0, j+1, jo.getString("MaterialName")));
sheet.addCell(new Label(1, j+1, jo.getString("MaterialModel")));
sheet.addCell(new Label(2, j+1, jo.getString("MaterialStandard")));
sheet.addCell(new Label(3, j+1, jo.getString("MaterialColor")));
sheet.addCell(new Label(4, j+1, jo.getString("MaterialUnit")));
sheet.addCell(new Label(5, j+1, jo.getString("UnitPrice")));
sheet.addCell(new Label(6, j+1, jo.getString("prevSum")));
sheet.addCell(new Label(7, j+1, jo.getString("InSum")));
sheet.addCell(new Label(8, j+1, jo.getString("OutSum")));
sheet.addCell(new Label(9, j+1, jo.getString("thisSum")));
double d = Double.parseDouble(jo.getString("thisAllPrice").toString());
String s1 = String.format("%.2f", d);
sheet.addCell(new Label(10, j+1, s1));
}
}
workbook.write();
workbook.close();
}
catch (Exception e)
{
Log.errorFileSync(">>>>>>>>>>>>>>>>>>>>>>>导出资产信息为excel表格异常", e);
}
}
/**
* 生成excel表格
*
* @param os
*/
@SuppressWarnings("deprecation")
private void putDataOnOutputStream(OutputStream os, JSONArray dataArray) {
WritableWorkbook workbook = null;
try {
workbook = Workbook.createWorkbook(os);
WritableSheet sheet = workbook.createSheet("进销存报表", 0);
//增加列头
int[] colunmWidth = {10, 10, 10, 10, 10, 10, 15, 15, 15, 15, 15};
String[] colunmName = {"名称", "型号", "规格", "颜色", "单位", "单价", "上月结存数量", "入库数量", "出库数量", "本月结存数量", "结存金额"};
for (int i = 0; i < colunmWidth.length; i++) {
sheet.setColumnView(i, colunmWidth[i]);
sheet.addCell(new Label(i, 0, colunmName[i]));
}
if (null != dataArray && dataArray.size() > 0) {
for (int j = 0; j < dataArray.size(); j++) {
JSONObject jo = JSONObject.fromObject(dataArray.get(j));
sheet.addCell(new Label(0, j + 1, jo.getString("MaterialName")));
sheet.addCell(new Label(1, j + 1, jo.getString("MaterialModel")));
sheet.addCell(new Label(2, j + 1, jo.getString("MaterialStandard")));
sheet.addCell(new Label(3, j + 1, jo.getString("MaterialColor")));
sheet.addCell(new Label(4, j + 1, jo.getString("MaterialUnit")));
sheet.addCell(new Label(5, j + 1, jo.getString("UnitPrice")));
sheet.addCell(new Label(6, j + 1, jo.getString("prevSum")));
sheet.addCell(new Label(7, j + 1, jo.getString("InSum")));
sheet.addCell(new Label(8, j + 1, jo.getString("OutSum")));
sheet.addCell(new Label(9, j + 1, jo.getString("thisSum")));
double d = Double.parseDouble(jo.getString("thisAllPrice").toString());
String s1 = String.format("%.2f", d);
sheet.addCell(new Label(10, j + 1, s1));
}
}
workbook.write();
workbook.close();
} catch (Exception e) {
Log.errorFileSync(">>>>>>>>>>>>>>>>>>>>>>>导出资产信息为excel表格异常", e);
}
}
}
......@@ -3,7 +3,6 @@ package com.jsh.service.materials;
import com.jsh.base.BaseIService;
import com.jsh.model.po.MaterialCategory;
public interface MaterialCategoryIService extends BaseIService<MaterialCategory>
{
public interface MaterialCategoryIService extends BaseIService<MaterialCategory> {
}
......@@ -4,21 +4,19 @@ import com.jsh.base.BaseService;
import com.jsh.dao.materials.MaterialCategoryIDAO;
import com.jsh.model.po.MaterialCategory;
public class MaterialCategoryService extends BaseService<MaterialCategory> implements MaterialCategoryIService
{
@SuppressWarnings("unused")
private MaterialCategoryIDAO materialCategoryDao;
public class MaterialCategoryService extends BaseService<MaterialCategory> implements MaterialCategoryIService {
@SuppressWarnings("unused")
private MaterialCategoryIDAO materialCategoryDao;
public void setMaterialCategoryDao(MaterialCategoryIDAO materialCategoryDao) {
this.materialCategoryDao = materialCategoryDao;
}
public void setMaterialCategoryDao(MaterialCategoryIDAO materialCategoryDao) {
this.materialCategoryDao = materialCategoryDao;
}
@Override
protected Class<MaterialCategory> getEntityClass() {
return MaterialCategory.class;
}
@Override
protected Class<MaterialCategory> getEntityClass()
{
return MaterialCategory.class;
}
}
......@@ -8,13 +8,12 @@ import com.jsh.util.PageUtil;
import java.io.File;
import java.io.InputStream;
public interface MaterialIService extends BaseIService<Material>
{
public void batchSetEnable(Boolean enable,String supplierIDs);
public interface MaterialIService extends BaseIService<Material> {
public void batchSetEnable(Boolean enable, String supplierIDs);
public void findUnitName(PageUtil<Material> material, Long mId)throws JshException;
public void findUnitName(PageUtil<Material> material, Long mId) throws JshException;
public InputStream exmportExcel(String isAllPage,PageUtil<Material> pageUtil)throws JshException;
public InputStream exmportExcel(String isAllPage, PageUtil<Material> pageUtil) throws JshException;
public InputStream importExcel(File materialFile)throws JshException;
public InputStream importExcel(File materialFile) throws JshException;
}
......@@ -3,7 +3,6 @@ package com.jsh.service.materials;
import com.jsh.base.BaseIService;
import com.jsh.model.po.MaterialProperty;
public interface MaterialPropertyIService extends BaseIService<MaterialProperty>
{
public interface MaterialPropertyIService extends BaseIService<MaterialProperty> {
}
......@@ -4,21 +4,19 @@ import com.jsh.base.BaseService;
import com.jsh.dao.materials.MaterialPropertyIDAO;
import com.jsh.model.po.MaterialProperty;
public class MaterialPropertyService extends BaseService<MaterialProperty> implements MaterialPropertyIService
{
@SuppressWarnings("unused")
private MaterialPropertyIDAO materialPropertyDao;
public class MaterialPropertyService extends BaseService<MaterialProperty> implements MaterialPropertyIService {
@SuppressWarnings("unused")
private MaterialPropertyIDAO materialPropertyDao;
public void setMaterialPropertyDao(MaterialPropertyIDAO materialPropertyDao) {
this.materialPropertyDao = materialPropertyDao;
}
public void setMaterialPropertyDao(MaterialPropertyIDAO materialPropertyDao) {
this.materialPropertyDao = materialPropertyDao;
}
@Override
protected Class<MaterialProperty> getEntityClass() {
return MaterialProperty.class;
}
@Override
protected Class<MaterialProperty> getEntityClass()
{
return MaterialProperty.class;
}
}
......@@ -21,305 +21,284 @@ import java.io.*;
import java.lang.Boolean;
import java.util.*;
public class MaterialService extends BaseService<Material> implements MaterialIService
{
@SuppressWarnings("unused")
private MaterialIDAO materialDao;
public class MaterialService extends BaseService<Material> implements MaterialIService {
/**
* 初始化加载所有系统基础数据
*/
@SuppressWarnings({"rawtypes"})
private static Map<String, List> mapData = new HashMap<String, List>();
/**
* 错误的表格数据
*/
private static List<Material> wrongData = new ArrayList<Material>();
@SuppressWarnings("unused")
private MaterialIDAO materialDao;
public void setMaterialDao(MaterialIDAO materialDao) {
this.materialDao = materialDao;
}
public void setMaterialDao(MaterialIDAO materialDao) {
this.materialDao = materialDao;
}
public void batchSetEnable(Boolean enable,String supplierIDs){
materialDao.batchSetEnable(enable, supplierIDs);
}
public void batchSetEnable(Boolean enable, String supplierIDs) {
materialDao.batchSetEnable(enable, supplierIDs);
}
@Override
public void findUnitName(PageUtil<Material> pageUtil, Long mId) throws JshException {
materialDao.findUnitName(pageUtil, mId);
}
@Override
public void findUnitName(PageUtil<Material> pageUtil, Long mId) throws JshException
{
materialDao.findUnitName(pageUtil, mId);
}
@Override
protected Class<Material> getEntityClass() {
return Material.class;
}
@Override
protected Class<Material> getEntityClass()
{
return Material.class;
}
/**
* 导出Excel表格
*/
@Override
public InputStream exmportExcel(String isAllPage, PageUtil<Material> pageUtil) throws JshException {
try {
//将OutputStream转化为InputStream
ByteArrayOutputStream out = new ByteArrayOutputStream();
putDataOnOutputStream(out, pageUtil.getPageList());
return new ByteArrayInputStream(out.toByteArray());
} catch (Exception e) {
Log.errorFileSync(">>>>>>>>>>>>>>>>>>>>>>>导出信息为excel表格异常", e);
throw new JshException("导出信息为excel表格异常", e);
}
}
/**
* 初始化加载所有系统基础数据
*/
@SuppressWarnings({"rawtypes"})
private static Map<String,List> mapData = new HashMap<String, List>();
/**
* 生成excel表格
*
* @param os
*/
@SuppressWarnings("deprecation")
private void putDataOnOutputStream(OutputStream os, List<Material> dataList) {
WritableWorkbook workbook = null;
try {
workbook = Workbook.createWorkbook(os);
WritableSheet sheet = workbook.createSheet("信息报表", 0);
//增加列头
String[] colunmName = {"品名", "类型", "型号", "安全存量", "单位", "零售价", "最低售价", "预计采购价", "批发价", "备注", "状态"};
for (int i = 0; i < colunmName.length; i++) {
sheet.setColumnView(i, 10);
sheet.addCell(new Label(i, 0, colunmName[i]));
}
if (null != dataList && dataList.size() > 0) {
int i = 1;
for (Material material : dataList) {
int j = 0;
Map<Integer, String> cellInfo = material.getCellInfo();
sheet.addCell(new Label(j++, i, material.getName()));
sheet.addCell(new Label(j++, i, material.getMaterialCategory().getName()));
sheet.addCell(new Label(j++, i, material.getModel() == null ? "" : material.getModel()));
sheet.addCell(getLabelInfo(cellInfo, j++, i, material.getSafetyStock() == null ? "" : material.getSafetyStock().toString(), material));
sheet.addCell(new Label(j++, i, material.getUnit() == null ? "" : material.getUnit()));
sheet.addCell(new Label(j++, i, material.getRetailPrice() == null ? "" : material.getRetailPrice().toString()));
sheet.addCell(new Label(j++, i, material.getLowPrice() == null ? "" : material.getLowPrice().toString()));
sheet.addCell(new Label(j++, i, material.getPresetPriceOne() == null ? "" : material.getPresetPriceOne().toString()));
sheet.addCell(new Label(j++, i, material.getPresetPriceTwo() == null ? "" : material.getPresetPriceTwo().toString()));
sheet.addCell(new Label(j++, i, material.getRemark() == null ? "" : material.getRemark()));
sheet.addCell(new Label(j++, i, material.getEnabled() ? "启用" : "禁用"));
i++;
}
}
workbook.write();
workbook.close();
} catch (Exception e) {
Log.errorFileSync(">>>>>>>>>>>>>>>>>>>>>>>导出信息为excel表格异常", e);
}
}
/**
* 错误的表格数据
*/
private static List<Material> wrongData = new ArrayList<Material>();
/**
* 导出Excel表格
*/
@Override
public InputStream exmportExcel(String isAllPage, PageUtil<Material> pageUtil)throws JshException
{
try
{
//将OutputStream转化为InputStream
ByteArrayOutputStream out = new ByteArrayOutputStream();
putDataOnOutputStream(out, pageUtil.getPageList());
return new ByteArrayInputStream(out.toByteArray());
}
catch (Exception e)
{
Log.errorFileSync(">>>>>>>>>>>>>>>>>>>>>>>导出信息为excel表格异常", e);
throw new JshException("导出信息为excel表格异常",e);
}
}
/**
* 根据错误信息进行提示--excel表格背景设置为红色,表示导入信息有误
*
* @param cellInfo
* @param cellNum
* @param columnNum
* @param value
* @return
*/
private Label getLabelInfo(Map<Integer, String> cellInfo, int cellNum, int columnNum, String value, Material material) {
Label label = null;
/**
* 生成excel表格
* @param os
*/
@SuppressWarnings("deprecation")
private void putDataOnOutputStream(OutputStream os, List<Material> dataList) {
WritableWorkbook workbook = null;
try {
workbook = Workbook.createWorkbook(os);
WritableSheet sheet = workbook.createSheet("信息报表", 0);
//增加列头
String[] colunmName = {"品名","类型","型号","安全存量","单位","零售价","最低售价","预计采购价","批发价","备注","状态"};
for(int i = 0 ;i < colunmName.length;i ++) {
sheet.setColumnView(i, 10);
sheet.addCell(new Label(i, 0, colunmName[i]));
}
if (null != dataList && dataList.size() > 0) {
int i = 1;
for (Material material: dataList){
int j = 0;
Map<Integer,String> cellInfo = material.getCellInfo();
sheet.addCell(new Label(j++,i, material.getName()));
sheet.addCell(new Label(j++,i, material.getMaterialCategory().getName()));
sheet.addCell(new Label(j++,i, material.getModel() == null ?"": material.getModel()));
sheet.addCell(getLabelInfo(cellInfo,j++,i, material.getSafetyStock() == null ?"": material.getSafetyStock().toString(),material));
sheet.addCell(new Label(j++,i, material.getUnit() == null ?"": material.getUnit()));
sheet.addCell(new Label(j++,i, material.getRetailPrice() == null ?"": material.getRetailPrice().toString()));
sheet.addCell(new Label(j++,i, material.getLowPrice() == null ?"": material.getLowPrice().toString()));
sheet.addCell(new Label(j++,i, material.getPresetPriceOne() == null ?"": material.getPresetPriceOne().toString()));
sheet.addCell(new Label(j++,i, material.getPresetPriceTwo() == null ?"": material.getPresetPriceTwo().toString()));
sheet.addCell(new Label(j++,i, material.getRemark() == null ?"": material.getRemark()));
sheet.addCell(new Label(j++,i, material.getEnabled()?"启用":"禁用"));
i++;
}
}
workbook.write();
workbook.close();
}
catch (Exception e) {
Log.errorFileSync(">>>>>>>>>>>>>>>>>>>>>>>导出信息为excel表格异常", e);
}
}
//设置背景颜色
WritableCellFormat cellFormat = new WritableCellFormat();
try {
cellFormat.setBackground(Colour.RED);
} catch (WriteException e) {
Log.errorFileSync(">>>>>>>>>>>>>>>>>>>>>设置单元格背景颜色错误", e);
}
/**
* 根据错误信息进行提示--excel表格背景设置为红色,表示导入信息有误
* @param cellInfo
* @param cellNum
* @param columnNum
* @param value
* @return
*/
private Label getLabelInfo(Map<Integer,String> cellInfo,int cellNum,int columnNum,String value,Material material)
{
Label label = null;
if (null == cellInfo || cellInfo.size() == 0) {
label = new Label(cellNum, columnNum, value);
} else {
//表示此单元格有错误
if (cellInfo.containsKey(cellNum)) {
if (cellNum == MaterialConstants.BusinessForExcel.EXCEL_SAFETY_STOCK) {
label = new Label(cellNum, columnNum, material.getSafetyStockStr(), cellFormat);
}
} else {
label = new Label(cellNum, columnNum, value);
}
}
return label;
}
//设置背景颜色
WritableCellFormat cellFormat = new WritableCellFormat();
try
{
cellFormat.setBackground(Colour.RED);
}
catch (WriteException e)
{
Log.errorFileSync(">>>>>>>>>>>>>>>>>>>>>设置单元格背景颜色错误", e);
}
@Override
public InputStream importExcel(File materialFile) throws JshException {
//全局变量--每次调用前需要清空数据
mapData.clear();
//2、解析文件成资产数据
parseFile(materialFile);
if(null == cellInfo || cellInfo.size() == 0) {
label = new Label(cellNum, columnNum, value);
}
else {
//表示此单元格有错误
if(cellInfo.containsKey(cellNum)) {
if(cellNum == MaterialConstants.BusinessForExcel.EXCEL_SAFETY_STOCK) {
label = new Label(cellNum, columnNum, material.getSafetyStockStr(), cellFormat);
}
}
else{
label = new Label(cellNum, columnNum, value);
}
}
return label;
}
if (null != wrongData && wrongData.size() > 0) {
//将OutputStream转化为InputStream
ByteArrayOutputStream out = new ByteArrayOutputStream();
putDataOnOutputStream(out, wrongData);
return new ByteArrayInputStream(out.toByteArray());
} else {
return null;
}
}
@Override
public InputStream importExcel(File materialFile) throws JshException {
//全局变量--每次调用前需要清空数据
mapData.clear();
//2、解析文件成资产数据
parseFile(materialFile);
if(null != wrongData && wrongData.size()>0) {
//将OutputStream转化为InputStream
ByteArrayOutputStream out = new ByteArrayOutputStream();
putDataOnOutputStream(out,wrongData);
return new ByteArrayInputStream(out.toByteArray());
}
else{
return null;
}
}
/**
* 解析excel表格
*
* @param assetFile
*/
@SuppressWarnings("unchecked")
private void parseFile(File assetFile) {
//每次调用前清空
wrongData.clear();
int totalRow = 0;
try {
//创建对Excel工作簿文件的引用
HSSFWorkbook workbook = new HSSFWorkbook(new FileInputStream(assetFile));
//创建对工作表的引用,获取第一个工作表的内容
HSSFSheet sheet = workbook.getSheetAt(0);
/**
* =====================================
* 1、此处要增加文件的验证,如果不是资产文件需要进行特殊的处理,13列
* 2、文件内容为空处理
* 3、如果是修改过的文件内容
*/
Iterator<Row> itsheet = sheet.rowIterator();
while (itsheet.hasNext()) {
//获取当前行数据
Row row = itsheet.next();
//excel表格第几行数据 从1开始 0 是表头
int rowNum = row.getRowNum();
/**
* 表头跳过不读
*/
if (MaterialConstants.BusinessForExcel.EXCEL_TABLE_HEAD == rowNum)
continue;
/**
* 解析excel表格
* @param assetFile
*/
@SuppressWarnings("unchecked")
private void parseFile(File assetFile) {
//每次调用前清空
wrongData.clear();
int totalRow = 0;
try {
//创建对Excel工作簿文件的引用
HSSFWorkbook workbook = new HSSFWorkbook(new FileInputStream(assetFile));
//创建对工作表的引用,获取第一个工作表的内容
HSSFSheet sheet = workbook.getSheetAt(0);
/**
* =====================================
* 1、此处要增加文件的验证,如果不是资产文件需要进行特殊的处理,13列
* 2、文件内容为空处理
* 3、如果是修改过的文件内容
*/
Iterator<Row> itsheet = sheet.rowIterator();
while(itsheet.hasNext()) {
//获取当前行数据
Row row = itsheet.next();
//开始处理excel表格内容 --每行数据读取,同时统计总共行数
totalRow++;
//excel表格第几行数据 从1开始 0 是表头
int rowNum = row.getRowNum();
/**
* 表头跳过不读
*/
if(MaterialConstants.BusinessForExcel.EXCEL_TABLE_HEAD == rowNum)
continue;
//获取excel表格的每格数据内容
Iterator<Cell> it = row.cellIterator();
//资产子类型--添加了一些excel表格数据
Material material = new Material();
//保存每个单元格错误类型
Map<Integer, String> cellType = new HashMap<Integer, String>();
//设置列号
material.setRowLineNum(rowNum);
//开始处理excel表格内容 --每行数据读取,同时统计总共行数
totalRow ++;
Cell cell = null;
//判断列号--从零开始
int cellIndex = 0;
while (it.hasNext()) {
//获取每个单元格对象
cell = it.next();
//获取列号
cellIndex = cell.getColumnIndex();
//设置此单元格为字符串类型
cell.setCellType(Cell.CELL_TYPE_STRING);
//获取excel表格的每格数据内容
Iterator<Cell> it = row.cellIterator();
//资产子类型--添加了一些excel表格数据
Material material = new Material();
//保存每个单元格错误类型
Map<Integer,String> cellType = new HashMap<Integer,String>();
//设置列号
material.setRowLineNum(rowNum);
Log.infoFileSync("==================excel表格中第" + totalRow + "行的第 " + cellIndex + "列的值为" + cell.getStringCellValue());
Cell cell = null;
//判断列号--从零开始
int cellIndex = 0;
while(it.hasNext()) {
//获取每个单元格对象
cell = it.next();
//获取列号
cellIndex = cell.getColumnIndex();
//设置此单元格为字符串类型
cell.setCellType(Cell.CELL_TYPE_STRING);
//每行中数据顺序 "品名","类型","型号","安全存量","单位","零售价","最低售价","预计采购价","批发价","备注","状态"
switch (cellIndex) {
case MaterialConstants.BusinessForExcel.EXCEL_NAME:
String materialName = cell.getStringCellValue();
if (null == materialName || "".equals(materialName)) {
Log.errorFileSync(">>>>>>>>>>>>>>>>列表没有填写(品名)信息");
break;
}
material.setName(materialName);
break;
case MaterialConstants.BusinessForExcel.EXCEL_CATEGORY:
String category = cell.getStringCellValue();
if (null == category || "".equals(category)) {
Log.errorFileSync(">>>>>>>>>>>>>>>>列表没有填写(类型)信息");
break;
}
material.setMaterialCategory(new MaterialCategory(1l)); //根目录
break;
case MaterialConstants.BusinessForExcel.EXCEL_MODEL:
String model = cell.getStringCellValue();
if (null == model || "".equals(model)) {
Log.errorFileSync(">>>>>>>>>>>>>>>>列表没有填写(型号)信息");
break;
}
material.setModel(model);
break;
case MaterialConstants.BusinessForExcel.EXCEL_SAFETY_STOCK:
String safetyStock = cell.getStringCellValue();
if (null == safetyStock || "".equals(safetyStock)) {
Log.errorFileSync(">>>>>>>>>>>>>>>>列表没有填写(安全存量)信息");
break;
}
if (Tools.checkStrIsNum(safetyStock)) {
material.setSafetyStock(Double.parseDouble(safetyStock));
} else {
Log.errorFileSync(">>>>>>>>>>>>>>>>>(安全存量)不是数字格式");
cellType.put(cellIndex, "wrong");
material.setSafetyStock(0.00d);
material.setSafetyStockStr(safetyStock);
}
break;
case MaterialConstants.BusinessForExcel.EXCEL_UNIT:
String unit = cell.getStringCellValue();
if (null == unit || "".equals(unit)) {
Log.errorFileSync(">>>>>>>>>>>>>>>>列表没有填写(单位)信息");
break;
}
material.setUnit(unit);
break;
case MaterialConstants.BusinessForExcel.EXCEL_REMARK:
String remark = cell.getStringCellValue();
if (null == remark || "".equals(remark)) {
Log.errorFileSync(">>>>>>>>>>>>>>>>列表没有填写(备注)信息");
break;
}
material.setRemark(remark);
break;
}
}
material.setCellInfo(cellType);
Log.infoFileSync("==================excel表格中第" + totalRow + "行的第 " + cellIndex + "列的值为" + cell.getStringCellValue());
Log.infoFileSync(totalRow + "行总共有" + cellIndex + "列");
//每行中数据顺序 "品名","类型","型号","安全存量","单位","零售价","最低售价","预计采购价","批发价","备注","状态"
switch(cellIndex) {
case MaterialConstants.BusinessForExcel.EXCEL_NAME :
String materialName = cell.getStringCellValue();
if(null == materialName || "".equals(materialName)) {
Log.errorFileSync(">>>>>>>>>>>>>>>>列表没有填写(品名)信息");
break;
}
material.setName(materialName);
break;
case MaterialConstants.BusinessForExcel.EXCEL_CATEGORY :
String category = cell.getStringCellValue();
if(null == category || "".equals(category)) {
Log.errorFileSync(">>>>>>>>>>>>>>>>列表没有填写(类型)信息");
break;
}
material.setMaterialCategory(new MaterialCategory(1l)); //根目录
break;
case MaterialConstants.BusinessForExcel.EXCEL_MODEL:
String model = cell.getStringCellValue();
if(null == model || "".equals(model)) {
Log.errorFileSync(">>>>>>>>>>>>>>>>列表没有填写(型号)信息");
break;
}
material.setModel(model);
break;
case MaterialConstants.BusinessForExcel.EXCEL_SAFETY_STOCK :
String safetyStock = cell.getStringCellValue();
if(null == safetyStock || "".equals(safetyStock)) {
Log.errorFileSync(">>>>>>>>>>>>>>>>列表没有填写(安全存量)信息");
break;
}
if(Tools.checkStrIsNum(safetyStock)) {
material.setSafetyStock(Double.parseDouble(safetyStock));
}
else{
Log.errorFileSync(">>>>>>>>>>>>>>>>>(安全存量)不是数字格式");
cellType.put(cellIndex, "wrong");
material.setSafetyStock(0.00d);
material.setSafetyStockStr(safetyStock);
}
break;
case MaterialConstants.BusinessForExcel.EXCEL_UNIT:
String unit = cell.getStringCellValue();
if(null == unit || "".equals(unit)) {
Log.errorFileSync(">>>>>>>>>>>>>>>>列表没有填写(单位)信息");
break;
}
material.setUnit(unit);
break;
case MaterialConstants.BusinessForExcel.EXCEL_REMARK :
String remark = cell.getStringCellValue();
if(null == remark || "".equals(remark)) {
Log.errorFileSync(">>>>>>>>>>>>>>>>列表没有填写(备注)信息");
break;
}
material.setRemark(remark);
break;
}
}
material.setCellInfo(cellType);
Log.infoFileSync(totalRow + "行总共有" + cellIndex + "列");
//判断完成后增加数据
if((null!=cellType && cellType.size() >0) || material.getName() == null) {
wrongData.add(material);
}
else {
material.setEnabled(true);
materialDao.save(material);
}
}
}
catch (FileNotFoundException e)
{
Log.errorFileSync(">>>>>>>>>>>>>>>>>>读取excel文件异常:找不到指定文件!",e);
}
catch (IOException e)
{
Log.errorFileSync(">>>>>>>>>>>>>>>>>>读取excel文件异常,请确认文件格式是否正确 !",e);
}
Log.infoFileSync("===================excel表格总共有 " + totalRow + " 条记录!");
}
//判断完成后增加数据
if ((null != cellType && cellType.size() > 0) || material.getName() == null) {
wrongData.add(material);
} else {
material.setEnabled(true);
materialDao.save(material);
}
}
} catch (FileNotFoundException e) {
Log.errorFileSync(">>>>>>>>>>>>>>>>>>读取excel文件异常:找不到指定文件!", e);
} catch (IOException e) {
Log.errorFileSync(">>>>>>>>>>>>>>>>>>读取excel文件异常,请确认文件格式是否正确 !", e);
}
Log.infoFileSync("===================excel表格总共有 " + totalRow + " 条记录!");
}
}
......@@ -3,7 +3,6 @@ package com.jsh.service.materials;
import com.jsh.base.BaseIService;
import com.jsh.model.po.Person;
public interface PersonIService extends BaseIService<Person>
{
public interface PersonIService extends BaseIService<Person> {
}
......@@ -4,21 +4,19 @@ import com.jsh.base.BaseService;
import com.jsh.dao.materials.PersonIDAO;
import com.jsh.model.po.Person;
public class PersonService extends BaseService<Person> implements PersonIService
{
@SuppressWarnings("unused")
private PersonIDAO personDao;
public class PersonService extends BaseService<Person> implements PersonIService {
@SuppressWarnings("unused")
private PersonIDAO personDao;
public void setPersonDao(PersonIDAO personDao) {
this.personDao = personDao;
}
public void setPersonDao(PersonIDAO personDao) {
this.personDao = personDao;
}
@Override
protected Class<Person> getEntityClass() {
return Person.class;
}
@Override
protected Class<Person> getEntityClass()
{
return Person.class;
}
}
......@@ -2,26 +2,26 @@ package com.jsh.util;
/**
* 定义资产管理常量
*
* @author jishenghua
*/
public interface AssetConstants
{
public interface AssetConstants {
/**
* 公共常量
*
* @author jishenghua
*/
public class Common
{
public class Common {
}
/**
* 资产常量--导入导出excel表格业务相关
*
* @author jishenghua
*/
public class BusinessForExcel
{
public class BusinessForExcel {
/**
* 资产名称常量
*/
......@@ -65,17 +65,17 @@ public interface AssetConstants
/**
* 序列号
*/
public static final int EXCEL_SERIALNO = 8;
public static final int EXCEL_SERIALNO = 8;
/**
* 有效日期
*/
public static final int EXCEL_EXPIRATION_DATE = 9;
public static final int EXCEL_EXPIRATION_DATE = 9;
/**
* 保修日期
*/
public static final int EXCEL_WARRANTY_DATE = 10;
public static final int EXCEL_WARRANTY_DATE = 10;
/**
* 供应商
......@@ -116,6 +116,6 @@ public interface AssetConstants
* action返回excel结果
*/
public static final String EXCEL = "excel";
}
}
package com.jsh.util;
import java.util.HashMap;
import java.util.Map;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.context.support.FileSystemXmlApplicationContext;
import java.util.HashMap;
import java.util.Map;
/**
* 获取spring配置中的bean对象,是单例,只会加载一次,请注意使用
* 注意:此工具类默认处理UI组件WEB-INF目录下的applicationContext.xml配置文件,请注意文件 名和路径
* @author jishenghua
* @qq 7 5 2 7 1 8 9 2 0
*
* @author jishenghua
* @version V1.0
* @qq 7 5 2 7 1 8 9 2 0
*/
public class BeanFactoryUtil
{
public class BeanFactoryUtil {
private static BeanFactoryUtil defaultBeanFactory;
private ApplicationContext defaultAC = null;
//private ApplicationContext autoLoadAC = null;
private static BeanFactoryUtil specialBeanFactory;
private ApplicationContext specialAC = null;
//private ApplicationContext autoLoadAC = null;
private static Map<String, ApplicationContext> beanMap = new HashMap<String, ApplicationContext>();
private ApplicationContext defaultAC = null;
private ApplicationContext specialAC = null;
//private Logger log = Logger.getLogger(BeanFactoryUtil.class);
/**
* 私有构造函数,默认为UI组件WEB-INF目录下的applicationContext.xml配置文件
*/
private BeanFactoryUtil()
{
private BeanFactoryUtil() {
String fileUrl = PathTool.getWebinfPath();
//这里只对UI组件WEB-INF目录下的applicationContext.xml配置文件
defaultAC = new FileSystemXmlApplicationContext( new
String[]{fileUrl
+ "spring/basic-applicationContext.xml",
fileUrl + "spring/dao-applicationContext.xml"});
defaultAC = new FileSystemXmlApplicationContext(new
String[]{fileUrl
+ "spring/basic-applicationContext.xml",
fileUrl + "spring/dao-applicationContext.xml"});
}
/**
* 私有构造函数,带有文件的classpath路径,可能是非applicationContext.xml文件
*/
private BeanFactoryUtil(String fileClassPath)
{
private BeanFactoryUtil(String fileClassPath) {
specialAC = new ClassPathXmlApplicationContext("classpath:"
+ fileClassPath);
}
/**
* 非web.xml方式加载spring配置文件方式的实体实例获取方式
*
* @param fileClassPath
* @param beanName
* @return
* @return
*/
public synchronized static Object getBeanByClassPathAndBeanName(
String fileClassPath, String beanName)
{
String fileClassPath, String beanName) {
ApplicationContext ac = beanMap.get(fileClassPath);
if (null == ac)
{
if (null == ac) {
ac = new ClassPathXmlApplicationContext("classpath:"
+ fileClassPath);
beanMap.put(fileClassPath, ac);
}
return ac.getBean(beanName);
}
/**
* 获取类实例
* 默认加载UI组件WEB-INF目录下的applicationContext.xml配置文件
* @return
*
* @return
*/
public synchronized static BeanFactoryUtil getInstance()
{
if (null == defaultBeanFactory)
{
public synchronized static BeanFactoryUtil getInstance() {
if (null == defaultBeanFactory) {
defaultBeanFactory = new BeanFactoryUtil();
}
return defaultBeanFactory;
}
/**
* 获取类实例,这种情况一定是在依赖其他组件时没有在applicationContext.xml加载器spring文件时使用
* 这种情况请少用
*
* @param fileClassPath
* @return
* @return
*/
@Deprecated
public synchronized static BeanFactoryUtil getInstance(String fileClassPath)
{
if (null == specialBeanFactory)
{
public synchronized static BeanFactoryUtil getInstance(String fileClassPath) {
if (null == specialBeanFactory) {
specialBeanFactory = new BeanFactoryUtil(fileClassPath);
}
return specialBeanFactory;
}
/**
* 获取UI组件WEB-INF目录下的applicationContext.xml配置文件中配置的bean实例
*
* @param beanName
* @return
* @return
*/
public Object getBean(String beanName)
{
public Object getBean(String beanName) {
return defaultAC.getBean(beanName);
}
/**
* 获取没有在applicationContext.xml配置文件中引入的spring配置文件,即没有用容器加载过的配置文件
* 这里为特殊情况下使用,不推荐使用
* 推荐在applicationContext.xml配置文件中引入需要使用的spring配置文件,然后使用BeanFactoryUtil.getInstance().getBean("")方法
*
* @param beanName
* @return
* @return
*/
@Deprecated
public Object getSpecialBean(String beanName)
{
public Object getSpecialBean(String beanName) {
return specialAC.getBean(beanName);
}
}
package com.jsh.util;
public interface ExceptionCodeConstants
{
public interface ExceptionCodeConstants {
/**
* 用户错误码定义
*/
public class UserExceptionCode
{
public class UserExceptionCode {
/**
* 用户不存在
*/
......
package com.jsh.util;
public interface JshConstants
{
public interface JshConstants {
/**
* 定义资产管理公共常量
*
* @author jishenghua
*/
public class Common
{
public class Common {
/**
* Info级别日志前缀
*/
......@@ -19,17 +18,17 @@ public interface JshConstants
public static final String LOG_ERROR_PREFIX = ">>>>>>>>>>";
/**
* debug级别日志前缀
* debug级别日志前缀
*/
public static final String LOG_DEBUG_PREFIX = "-----------";
/**
* fatal级别日志前缀
* fatal级别日志前缀
*/
public static final String LOG_FATAL_PREFIX = "$$$$$$$$$$";
/**
* warn级别日志前缀
* warn级别日志前缀
*/
public static final String LOG_WARN_PREFIX = "##########";
}
......
package com.jsh.util;
/**
* @title: 平台异常基类
* @description: 用于包装一些异常信息,打印日志等服务
* @author jishenghua
* @title: 平台异常基类
* @description: 用于包装一些异常信息,打印日志等服务
* @qq 7 5 2 7 1 8 9 2 0
* @since: 2014-02-24
*/
@SuppressWarnings("serial")
public class JshException extends Exception
{
public class JshException extends Exception {
public long errorCode = -1;
public String message ;
public String message;
public JshException()
{
public JshException() {
super();
}
public JshException(String message)
{
public JshException(String message) {
super(message);
this.message = message;
}
public JshException(String message, Throwable cause)
{
public JshException(String message, Throwable cause) {
super(message, cause);
this.message = message;
}
public JshException(Throwable cause)
{
public JshException(Throwable cause) {
super(cause);
}
public JshException(long errorCode)
{
public JshException(long errorCode) {
super();
this.errorCode = errorCode;
}
public JshException(String message, long errorCode)
{
public JshException(String message, long errorCode) {
super(message);
this.errorCode = errorCode;
this.message = message;
}
public JshException(String message, long errorCode, Throwable cause)
{
public JshException(String message, long errorCode, Throwable cause) {
super(message, cause);
this.errorCode = errorCode;
this.message = message;
}
public JshException(long errorCode, Throwable cause)
{
public JshException(long errorCode, Throwable cause) {
super(cause);
this.errorCode = errorCode;
}
public long getErrorCode()
{
public long getErrorCode() {
return errorCode;
}
public String getMessage()
{
public String getMessage() {
return message;
}
}
......@@ -2,25 +2,25 @@ package com.jsh.util;
/**
* 定义商品信息常量
*
* @author jishenghua
*/
public interface MaterialConstants
{
public interface MaterialConstants {
/**
* 公共常量
*
* @author ji sheng hua
*/
public class Common
{
public class Common {
}
/**
* 常量--导入导出excel表格业务相关
*
* @author jishenghua
*/
public class BusinessForExcel
{
public class BusinessForExcel {
/**
* 名称
*/
......
......@@ -6,19 +6,17 @@ import org.hibernate.SessionFactory;
import org.springframework.dao.DataAccessResourceFailureException;
import org.springframework.orm.hibernate3.support.OpenSessionInViewFilter;
public class OpenSessionInViewFilterExtend extends OpenSessionInViewFilter
{
@Override
protected Session getSession(SessionFactory sessionFactory)
throws DataAccessResourceFailureException
{
this.setFlushMode(FlushMode.AUTO);
return super.getSession(sessionFactory);
}
@Override
protected void closeSession(Session session, SessionFactory sessionFactory)
{
session.flush();
super.closeSession(session, sessionFactory);
}
public class OpenSessionInViewFilterExtend extends OpenSessionInViewFilter {
@Override
protected Session getSession(SessionFactory sessionFactory)
throws DataAccessResourceFailureException {
this.setFlushMode(FlushMode.AUTO);
return super.getSession(sessionFactory);
}
@Override
protected void closeSession(Session session, SessionFactory sessionFactory) {
session.flush();
super.closeSession(session, sessionFactory);
}
}
......@@ -5,195 +5,186 @@ import java.util.ArrayList;
import java.util.Hashtable;
import java.util.List;
import java.util.Map;
/**
* 分页工具类,实现分页功能
* @author jishenghua
*
* @author jishenghua
* @version [版本号version01, 2014-2-21]
* @qq 7 5 2 7 1 8 9 2 0
* @version [版本号version01, 2014-2-21]
*/
@SuppressWarnings("serial")
public class PageUtil<E> implements Serializable
{
/**
* 总页数,根据总数和单页显示个数进行计算
*/
private int totalPage = 0;
/**
* 总个数
*/
private int totalCount = 0 ;
/**
* 当前页码
*/
private int curPage = 1;
/**
* 每页显示个数
*/
private int pageSize = 10;
/**
* 是否为第一页
*/
private boolean isFirstPage = false;
/**
* 是否是最后一页
*/
private boolean isLastPage = false;
/**
* 是否有上一页
*/
private boolean hasPrevious = false;
/**
* 是否有下一页
*/
private boolean hasNext = false;
/**
* 返回页面list数组
*/
private List<E> pageList = new ArrayList<E>();
/**
* 页面搜索条件,用map来实现
*/
private Map<String, Object> advSearch = new Hashtable<String, Object>();
public PageUtil()
{
}
public PageUtil(int totalCount,int pageSize,int curPage,Map<String, Object> adv)
{
init(totalCount,pageSize,curPage,adv);
}
/**
* 初始化页面显示参数
* @param totalCount 总数
* @param pageSize 页面显示个数
* @param curPage 当前页面
*/
public void init(int totalCount,int pageSize,int curPage,Map<String, Object> adv)
{
this.totalCount = totalCount;
this.pageSize = pageSize ;
this.curPage = curPage;
this.advSearch = adv;
//计算总页数
if(pageSize != 0)
{
this.totalPage = (totalCount+pageSize-1)/pageSize;
}
if(curPage <1)
{
this.curPage = 1;
}
if(curPage>this.totalPage)
{
this.curPage = this.totalPage;
}
if(curPage>0&&this.totalPage!=1&&curPage<this.totalPage)
{
this.hasNext = true ;
}
if(curPage>0&&this.totalPage!=1&&curPage>1&&curPage<=this.totalPage)
{
this.hasPrevious = true;
}
if(curPage == 1)
{
this.isFirstPage = true ;
}
if(curPage == this.totalPage)
{
this.isLastPage = true;
}
}
public int getTotalPage()
{
return totalPage;
}
public void setTotalPage(int totalPage)
{
this.totalPage = totalPage;
}
public int getTotalCount()
{
return totalCount;
}
public void setTotalCount(int totalCount)
{
this.totalCount = totalCount;
}
public int getCurPage()
{
return curPage;
}
public void setCurPage(int curPage)
{
this.curPage = curPage;
}
public int getPageSize()
{
return pageSize;
}
public void setPageSize(int pageSize)
{
this.pageSize = pageSize;
}
public boolean isFirstPage()
{
return isFirstPage;
}
public void setFirstPage(boolean isFirstPage)
{
this.isFirstPage = isFirstPage;
}
public boolean isLastPage()
{
return isLastPage;
}
public void setLastPage(boolean isLastPage)
{
this.isLastPage = isLastPage;
}
public boolean isHasPrevious()
{
return hasPrevious;
}
public void setHasPrevious(boolean hasPrevious)
{
this.hasPrevious = hasPrevious;
}
public boolean isHasNext()
{
return hasNext;
}
public void setHasNext(boolean hasNext)
{
this.hasNext = hasNext;
}
public List<E> getPageList()
{
return pageList;
}
public void setPageList(List<E> pageList)
{
this.pageList = pageList;
}
public Map<String, Object> getAdvSearch()
{
return advSearch;
}
public void setAdvSearch(Map<String, Object> advSearch)
{
this.advSearch = advSearch;
}
public class PageUtil<E> implements Serializable {
/**
* 总页数,根据总数和单页显示个数进行计算
*/
private int totalPage = 0;
/**
* 总个数
*/
private int totalCount = 0;
/**
* 当前页码
*/
private int curPage = 1;
/**
* 每页显示个数
*/
private int pageSize = 10;
/**
* 是否为第一页
*/
private boolean isFirstPage = false;
/**
* 是否是最后一页
*/
private boolean isLastPage = false;
/**
* 是否有上一页
*/
private boolean hasPrevious = false;
/**
* 是否有下一页
*/
private boolean hasNext = false;
/**
* 返回页面list数组
*/
private List<E> pageList = new ArrayList<E>();
/**
* 页面搜索条件,用map来实现
*/
private Map<String, Object> advSearch = new Hashtable<String, Object>();
public PageUtil() {
}
public PageUtil(int totalCount, int pageSize, int curPage, Map<String, Object> adv) {
init(totalCount, pageSize, curPage, adv);
}
/**
* 初始化页面显示参数
*
* @param totalCount 总数
* @param pageSize 页面显示个数
* @param curPage 当前页面
*/
public void init(int totalCount, int pageSize, int curPage, Map<String, Object> adv) {
this.totalCount = totalCount;
this.pageSize = pageSize;
this.curPage = curPage;
this.advSearch = adv;
//计算总页数
if (pageSize != 0) {
this.totalPage = (totalCount + pageSize - 1) / pageSize;
}
if (curPage < 1) {
this.curPage = 1;
}
if (curPage > this.totalPage) {
this.curPage = this.totalPage;
}
if (curPage > 0 && this.totalPage != 1 && curPage < this.totalPage) {
this.hasNext = true;
}
if (curPage > 0 && this.totalPage != 1 && curPage > 1 && curPage <= this.totalPage) {
this.hasPrevious = true;
}
if (curPage == 1) {
this.isFirstPage = true;
}
if (curPage == this.totalPage) {
this.isLastPage = true;
}
}
public int getTotalPage() {
return totalPage;
}
public void setTotalPage(int totalPage) {
this.totalPage = totalPage;
}
public int getTotalCount() {
return totalCount;
}
public void setTotalCount(int totalCount) {
this.totalCount = totalCount;
}
public int getCurPage() {
return curPage;
}
public void setCurPage(int curPage) {
this.curPage = curPage;
}
public int getPageSize() {
return pageSize;
}
public void setPageSize(int pageSize) {
this.pageSize = pageSize;
}
public boolean isFirstPage() {
return isFirstPage;
}
public void setFirstPage(boolean isFirstPage) {
this.isFirstPage = isFirstPage;
}
public boolean isLastPage() {
return isLastPage;
}
public void setLastPage(boolean isLastPage) {
this.isLastPage = isLastPage;
}
public boolean isHasPrevious() {
return hasPrevious;
}
public void setHasPrevious(boolean hasPrevious) {
this.hasPrevious = hasPrevious;
}
public boolean isHasNext() {
return hasNext;
}
public void setHasNext(boolean hasNext) {
this.hasNext = hasNext;
}
public List<E> getPageList() {
return pageList;
}
public void setPageList(List<E> pageList) {
this.pageList = pageList;
}
public Map<String, Object> getAdvSearch() {
return advSearch;
}
public void setAdvSearch(Map<String, Object> advSearch) {
this.advSearch = advSearch;
}
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment