Commit 55135aca authored by 季圣华's avatar 季圣华
Browse files

整理代码

parent 46b75fec
package com.jsh.base; package com.jsh.base;
import java.io.Serializable; import java.io.Serializable;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import org.springframework.dao.DataAccessException; import org.springframework.dao.DataAccessException;
import com.jsh.util.common.PageUtil; import com.jsh.util.common.PageUtil;
/** /**
* 常用增删改查操作 * 常用增删改查操作
* @author andy * @author jishenghua
* @param <T> * @param <T>
*/ */
public interface BaseIDAO<T> public interface BaseIDAO<T>
{ {
/** /**
* 设置操作类对象 * 设置操作类对象
* @param paramClass * @param paramClass
*/ */
void setPoJoClass(Class<T> paramClass); void setPoJoClass(Class<T> paramClass);
/** /**
* 增加 * 增加
* @param t 对象 * @param t 对象
* @throws DataAccessException * @throws DataAccessException
*/ */
Serializable create(T t)throws DataAccessException; Serializable create(T t)throws DataAccessException;
/** /**
* 增加 * 增加
* @param t 对象 * @param t 对象
* @throws DataAccessException * @throws DataAccessException
*/ */
void save(T t)throws DataAccessException; void save(T t)throws DataAccessException;
/** /**
* 删除 * 删除
* @param t 对象 * @param t 对象
* @throws DataAccessException * @throws DataAccessException
*/ */
void delete(T t)throws DataAccessException; void delete(T t)throws DataAccessException;
/** /**
* 获取 * 获取
* @param objID ID * @param objID ID
* @return 对象 * @return 对象
* @throws DataAccessException * @throws DataAccessException
*/ */
T get(Long objID)throws DataAccessException; T get(Long objID)throws DataAccessException;
/** /**
* 修改信息 * 修改信息
* @param t 要修改的对象 * @param t 要修改的对象
* @throws DataAccessException * @throws DataAccessException
*/ */
void update(T t)throws DataAccessException; void update(T t)throws DataAccessException;
/** /**
* 批量删除信息 * 批量删除信息
* @param 以逗号分割的ID * @param 以逗号分割的ID
* @throws DataAccessException * @throws DataAccessException
*/ */
void batchDelete(String objIDs)throws DataAccessException; void batchDelete(String objIDs)throws DataAccessException;
/** /**
* 查找列表 * 查找列表
* @param pageUtil 分页工具类 * @param pageUtil 分页工具类
* @throws DataAccessException * @throws DataAccessException
*/ */
void find(PageUtil<T> pageUtil)throws DataAccessException; void find(PageUtil<T> pageUtil)throws DataAccessException;
/** /**
* 根据条件查询列表--没有分页信息 * 根据条件查询列表--没有分页信息
* @param conditon 查询条件 * @param conditon 查询条件
* @return 查询列表数据 * @return 查询列表数据
*/ */
List<T> find(Map<String,Object> conditon)throws DataAccessException; List<T> find(Map<String,Object> conditon)throws DataAccessException;
/** /**
* 根据hql查询 --没有分页信息 * 根据hql查询 --没有分页信息
* @param hql hibernate查询 * @param hql hibernate查询
* @return 查询列表数据 * @return 查询列表数据
*/ */
List<T> find(String hql)throws DataAccessException; List<T> find(String hql)throws DataAccessException;
/** /**
* 根据搜索条件查询--分页 * 根据搜索条件查询--分页
* @param conditon 查询条件 * @param conditon 查询条件
* @param pageSize 每页个数 * @param pageSize 每页个数
* @param pageNo 页码 * @param pageNo 页码
* @return 查询列表数据 * @return 查询列表数据
* @throws DataAccessException * @throws DataAccessException
*/ */
List<T> find(Map<String,Object> conditon,int pageSize,int pageNo)throws DataAccessException; List<T> find(Map<String,Object> conditon,int pageSize,int pageNo)throws DataAccessException;
/** /**
* 根据hql查询--分页 * 根据hql查询--分页
* @param hql hibernate查询语句 * @param hql hibernate查询语句
* @param pageSize 每页个数 * @param pageSize 每页个数
* @param pageNo 页码 * @param pageNo 页码
* @return 查询列表数据 * @return 查询列表数据
* @throws DataAccessException * @throws DataAccessException
*/ */
List<T> find(String hql,int pageSize,int pageNo)throws DataAccessException; List<T> find(String hql,int pageSize,int pageNo)throws DataAccessException;
/** /**
* 查找符合条件的总数 * 查找符合条件的总数
* @param conditon * @param conditon
* @return * @return
* @throws DataAccessException * @throws DataAccessException
*/ */
Integer countSum(Map<String,Object> conditon)throws DataAccessException; Integer countSum(Map<String,Object> conditon)throws DataAccessException;
/** /**
* 查找符合条件的总数 * 查找符合条件的总数
* @param hql * @param hql
* @return * @return
* @throws DataAccessException * @throws DataAccessException
*/ */
Integer countSum(String hql)throws DataAccessException; Integer countSum(String hql)throws DataAccessException;
} }
package com.jsh.base; package com.jsh.base;
import java.io.Serializable; import java.io.Serializable;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import org.springframework.dao.DataAccessException; import org.springframework.dao.DataAccessException;
import com.jsh.exception.AmsException; import com.jsh.exception.JshException;
import com.jsh.model.po.Basicuser; import com.jsh.model.po.Basicuser;
import com.jsh.util.common.PageUtil; import com.jsh.util.common.PageUtil;
public abstract class BaseService<T> implements BaseIService<T> public abstract class BaseService<T> implements BaseIService<T>
{ {
/** /**
* Dao对象 * Dao对象
*/ */
private BaseIDAO<T> baseDao; private BaseIDAO<T> baseDao;
protected Class<T> entityClass; protected Class<T> entityClass;
public void setBaseDao(BaseIDAO<T> baseDao) public void setBaseDao(BaseIDAO<T> baseDao)
{ {
this.baseDao = baseDao; this.baseDao = baseDao;
setPoJoClass(getEntityClass()); setPoJoClass(getEntityClass());
} }
protected BaseIDAO<T> getBaseDao() protected BaseIDAO<T> getBaseDao()
{ {
return this.baseDao; return this.baseDao;
} }
private void setPoJoClass(Class<T> c) private void setPoJoClass(Class<T> c)
{ {
this.baseDao.setPoJoClass(c); this.baseDao.setPoJoClass(c);
} }
protected abstract Class<T> getEntityClass(); protected abstract Class<T> getEntityClass();
@Override @Override
public Serializable create(T t) throws DataAccessException public Serializable create(T t) throws DataAccessException
{ {
return baseDao.create(t); return baseDao.create(t);
} }
@Override @Override
public void save(T t) throws DataAccessException public void save(T t) throws DataAccessException
{ {
baseDao.save(t); baseDao.save(t);
} }
@Override @Override
public void delete(T t) throws DataAccessException public void delete(T t) throws DataAccessException
{ {
baseDao.delete(t); baseDao.delete(t);
} }
@Override @Override
public void delete(Long id) throws DataAccessException public void delete(Long id) throws DataAccessException
{ {
baseDao.batchDelete(id.toString()); baseDao.batchDelete(id.toString());
} }
@Override @Override
public T get(Long objID) throws DataAccessException public T get(Long objID) throws DataAccessException
{ {
return baseDao.get(objID); return baseDao.get(objID);
} }
@Override @Override
public void update(T t) throws DataAccessException public void update(T t) throws DataAccessException
{ {
baseDao.update(t); baseDao.update(t);
} }
@Override @Override
public void batchDelete(String objIDs) throws DataAccessException public void batchDelete(String objIDs) throws DataAccessException
{ {
baseDao.batchDelete(objIDs); baseDao.batchDelete(objIDs);
} }
@Override @Override
public void find(PageUtil<T> pageUtil) throws DataAccessException public void find(PageUtil<T> pageUtil) throws DataAccessException
{ {
baseDao.find(pageUtil); baseDao.find(pageUtil);
} }
@Override @Override
public Boolean checkIsNameExist(String filedName, String filedVale,String idFiled,Long objectID) throws DataAccessException public Boolean checkIsNameExist(String filedName, String filedVale,String idFiled,Long objectID) throws DataAccessException
{ {
PageUtil<T> pageUtil = new PageUtil<T>(); PageUtil<T> pageUtil = new PageUtil<T>();
Map<String,Object> condition = new HashMap<String,Object>(); Map<String,Object> condition = new HashMap<String,Object>();
condition.put(filedName + "_s_eq", filedVale); condition.put(filedName + "_s_eq", filedVale);
condition.put(idFiled + "_n_neq", objectID); condition.put(idFiled + "_n_neq", objectID);
pageUtil.setAdvSearch(condition); pageUtil.setAdvSearch(condition);
baseDao.find(pageUtil); baseDao.find(pageUtil);
List<T> dataList = pageUtil.getPageList(); List<T> dataList = pageUtil.getPageList();
if(null != dataList && dataList.size() > 0) if(null != dataList && dataList.size() > 0)
return true; return true;
return false; return false;
} }
@Override @Override
public Boolean checkIsUserBusinessExist(String TypeName,String TypeVale,String KeyIdName,String KeyIdValue,String UBName,String UBValue) throws DataAccessException public Boolean checkIsUserBusinessExist(String TypeName,String TypeVale,String KeyIdName,String KeyIdValue,String UBName,String UBValue) throws DataAccessException
{ {
PageUtil<T> pageUtil = new PageUtil<T>(); PageUtil<T> pageUtil = new PageUtil<T>();
Map<String,Object> condition = new HashMap<String,Object>(); Map<String,Object> condition = new HashMap<String,Object>();
condition.put(TypeName + "_s_eq", TypeVale); condition.put(TypeName + "_s_eq", TypeVale);
condition.put(KeyIdName + "_s_eq", KeyIdValue); condition.put(KeyIdName + "_s_eq", KeyIdValue);
condition.put(UBName + "_s_like", UBValue); condition.put(UBName + "_s_like", UBValue);
pageUtil.setAdvSearch(condition); pageUtil.setAdvSearch(condition);
baseDao.find(pageUtil); baseDao.find(pageUtil);
List<T> dataList = pageUtil.getPageList(); List<T> dataList = pageUtil.getPageList();
if(null != dataList && dataList.size() > 0) if(null != dataList && dataList.size() > 0)
return true; return true;
return false; return false;
} }
@Override @Override
public Boolean checkIsValueExist(String TypeName, String TypeVale, String KeyIdName, String KeyIdValue) throws DataAccessException public Boolean checkIsValueExist(String TypeName, String TypeVale, String KeyIdName, String KeyIdValue) throws DataAccessException
{ {
PageUtil<T> pageUtil = new PageUtil<T>(); PageUtil<T> pageUtil = new PageUtil<T>();
Map<String,Object> condition = new HashMap<String,Object>(); Map<String,Object> condition = new HashMap<String,Object>();
condition.put(TypeName + "_s_eq", TypeVale); condition.put(TypeName + "_s_eq", TypeVale);
condition.put(KeyIdName + "_s_eq", KeyIdValue); condition.put(KeyIdName + "_s_eq", KeyIdValue);
pageUtil.setAdvSearch(condition); pageUtil.setAdvSearch(condition);
baseDao.find(pageUtil); baseDao.find(pageUtil);
List<T> dataList = pageUtil.getPageList(); List<T> dataList = pageUtil.getPageList();
if(null != dataList && dataList.size() > 0) if(null != dataList && dataList.size() > 0)
return true; return true;
return false; return false;
} }
} }
package com.jsh.base; package com.jsh.base;
import org.apache.log4j.Logger; import org.apache.log4j.Logger;
/** /**
* 封装log4j日志信息,打印日志信息类 * 封装log4j日志信息,打印日志信息类
* @author andy * @author jishenghua
* @since 2014-01-22 * @since 2014-01-22
*/ */
public class Log public class Log
{ {
/** /**
* 根据异常信息获取调用类的信息 * 根据异常信息获取调用类的信息
*/ */
private static final Exception ex = new Exception(); private static final Exception ex = new Exception();
/** /**
* 获取Log4j实例 * 获取Log4j实例
*/ */
private static final Logger log = Logger.getLogger("ams"); private static final Logger log = Logger.getLogger("ams");
/** /**
* Info级别日志前缀 * Info级别日志前缀
*/ */
public static final String LOG_INFO_PREFIX = "=========="; public static final String LOG_INFO_PREFIX = "==========";
/** /**
* error级别日志前缀 * error级别日志前缀
*/ */
public static final String LOG_ERROR_PREFIX = ">>>>>>>>>>"; public static final String LOG_ERROR_PREFIX = ">>>>>>>>>>";
/** /**
* debug级别日志前缀 * debug级别日志前缀
*/ */
public static final String LOG_DEBUG_PREFIX = "-----------"; public static final String LOG_DEBUG_PREFIX = "-----------";
/** /**
* fatal级别日志前缀 * fatal级别日志前缀
*/ */
public static final String LOG_FATAL_PREFIX = "$$$$$$$$$$"; public static final String LOG_FATAL_PREFIX = "$$$$$$$$$$";
/** /**
* warn级别日志前缀 * warn级别日志前缀
*/ */
public static final String LOG_WARN_PREFIX = "##########"; public static final String LOG_WARN_PREFIX = "##########";
/** /**
* 打印deug日期信息 * 打印deug日期信息
* @param msg 日志信息 * @param msg 日志信息
*/ */
public static void debugFileSync(Object msg) public static void debugFileSync(Object msg)
{ {
log.debug(getLogDetail(msg)); log.debug(getLogDetail(msg));
} }
/** /**
* 打印debug异常信息 * 打印debug异常信息
* @param msg 日志信息 * @param msg 日志信息
* @param e 异常堆栈 * @param e 异常堆栈
*/ */
public static void debugFileSync(Object msg, Throwable e) public static void debugFileSync(Object msg, Throwable e)
{ {
log.debug(getLogDetail(msg), e); log.debug(getLogDetail(msg), e);
} }
/** /**
* 打印info日志信息 * 打印info日志信息
* @param msg 日志信息 * @param msg 日志信息
*/ */
public static void infoFileSync(Object msg) public static void infoFileSync(Object msg)
{ {
log.info(getLogDetail(msg)); log.info(getLogDetail(msg));
} }
/** /**
* 打印 info日志带异常信息 * 打印 info日志带异常信息
* @param msg 日志信息 * @param msg 日志信息
* @param e 异常堆栈 * @param e 异常堆栈
*/ */
public static void infoFileSync(Object msg, Throwable e) public static void infoFileSync(Object msg, Throwable e)
{ {
log.info(getLogDetail(msg), e); log.info(getLogDetail(msg), e);
} }
/** /**
* 打印warn日期信息 * 打印warn日期信息
* @param msg 日志信息 * @param msg 日志信息
*/ */
public static void warnFileSync(Object msg) public static void warnFileSync(Object msg)
{ {
log.warn(getLogDetail(msg)); log.warn(getLogDetail(msg));
} }
/** /**
* 打印warn日志信息带异常 * 打印warn日志信息带异常
* @param msg日志信息 * @param msg日志信息
* @param e 异常堆栈 * @param e 异常堆栈
*/ */
public static void warnFileSync(Object msg, Throwable e) public static void warnFileSync(Object msg, Throwable e)
{ {
log.warn(getLogDetail(msg), e); log.warn(getLogDetail(msg), e);
} }
/** /**
* 打印error日志信息 * 打印error日志信息
* @param msg 日志信息 * @param msg 日志信息
*/ */
public static void errorFileSync(Object msg) public static void errorFileSync(Object msg)
{ {
log.error(getLogDetail(msg)); log.error(getLogDetail(msg));
} }
/** /**
* 打印error日志信息带异常 * 打印error日志信息带异常
* @param msg 日志信息 * @param msg 日志信息
* @param e 异常堆栈 * @param e 异常堆栈
*/ */
public static void errorFileSync(Object msg, Throwable e) public static void errorFileSync(Object msg, Throwable e)
{ {
log.error(getLogDetail(msg), e); log.error(getLogDetail(msg), e);
} }
/** /**
* 打印fatal日志信息 * 打印fatal日志信息
* @param msg 日志信息 * @param msg 日志信息
*/ */
public static void fatalFileSync(Object msg) public static void fatalFileSync(Object msg)
{ {
log.fatal(getLogDetail(msg)); log.fatal(getLogDetail(msg));
} }
/** /**
* 打印fatal日志信息带异常 * 打印fatal日志信息带异常
* @param msg 日志信息 * @param msg 日志信息
* @param e 异常堆栈 * @param e 异常堆栈
*/ */
public static void fatalFileSync(Object msg, Throwable e) public static void fatalFileSync(Object msg, Throwable e)
{ {
log.fatal(getLogDetail(msg), e); log.fatal(getLogDetail(msg), e);
} }
/** /**
* 拼装日志详细信息 * 拼装日志详细信息
* @param message 要打印的日志信息 * @param message 要打印的日志信息
* @return 封装后的日志详细信息 * @return 封装后的日志详细信息
*/ */
private static synchronized String getLogDetail(Object message) private static synchronized String getLogDetail(Object message)
{ {
String msg = ""; String msg = "";
if (null != message) if (null != message)
msg = message.toString(); msg = message.toString();
StringBuffer bf = new StringBuffer(); StringBuffer bf = new StringBuffer();
try try
{ {
ex.fillInStackTrace(); ex.fillInStackTrace();
throw ex; throw ex;
} }
catch (Exception ex) catch (Exception ex)
{ {
StackTraceElement[] trace = ex.getStackTrace(); StackTraceElement[] trace = ex.getStackTrace();
//获取异常堆栈中的调用类信息 //获取异常堆栈中的调用类信息
final int pos = 2; final int pos = 2;
bf.append(msg); bf.append(msg);
bf.append(" [class:"); bf.append(" [class:");
bf.append(trace[pos].getClassName()); bf.append(trace[pos].getClassName());
bf.append(" method:"); bf.append(" method:");
bf.append(trace[pos].getMethodName()); bf.append(trace[pos].getMethodName());
bf.append(" line:"); bf.append(" line:");
bf.append(trace[pos].getLineNumber()); bf.append(trace[pos].getLineNumber());
bf.append("]"); bf.append("]");
} }
return bf.toString(); return bf.toString();
} }
} }
\ No newline at end of file
package com.jsh.constants.asset; package com.jsh.constants.asset;
/** /**
* 定义资产管理常量 * 定义资产管理常量
* @author andy * @author jishenghua
*/ */
public interface AssetConstants public interface AssetConstants
{ {
/** /**
* 公共常量 * 公共常量
* @author andy * @author jishenghua
*/ */
public class Common public class Common
{ {
} }
/** /**
* 资产常量--导入导出excel表格业务相关 * 资产常量--导入导出excel表格业务相关
* @author andy * @author jishenghua
*/ */
public class BusinessForExcel public class BusinessForExcel
{ {
/** /**
* 资产名称常量 * 资产名称常量
*/ */
public static final int EXCEL_ASSETNAME = 0; public static final int EXCEL_ASSETNAME = 0;
/** /**
* 资产类型常量 * 资产类型常量
*/ */
public static final int EXCEL_CATEGORY = 1; public static final int EXCEL_CATEGORY = 1;
/** /**
* 资产单价 * 资产单价
*/ */
public static final int EXCEL_PRICE = 2; public static final int EXCEL_PRICE = 2;
/** /**
* 用户 * 用户
*/ */
public static final int EXCEL_USER = 3; public static final int EXCEL_USER = 3;
/** /**
* 购买日期 * 购买日期
*/ */
public static final int EXCEL_PURCHASE_DATE = 4; public static final int EXCEL_PURCHASE_DATE = 4;
/** /**
* 资产状态 * 资产状态
*/ */
public static final int EXCEL_STATUS = 5; public static final int EXCEL_STATUS = 5;
/** /**
* 位置 * 位置
*/ */
public static final int EXCEL_LOCATION = 6; public static final int EXCEL_LOCATION = 6;
/** /**
* 资产编号 * 资产编号
*/ */
public static final int EXCEL_NUM = 7; public static final int EXCEL_NUM = 7;
/** /**
* 序列号 * 序列号
*/ */
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;
/** /**
* 供应商 * 供应商
*/ */
public static final int EXCEL_SUPPLIER = 11; public static final int EXCEL_SUPPLIER = 11;
/** /**
* 标签 * 标签
*/ */
public static final int EXCEL_LABLE = 12; public static final int EXCEL_LABLE = 12;
/** /**
* 描述 * 描述
*/ */
public static final int EXCEL_DESC = 13; public static final int EXCEL_DESC = 13;
/** /**
* 表头 * 表头
*/ */
public static final int EXCEL_TABLE_HEAD = 0; public static final int EXCEL_TABLE_HEAD = 0;
/** /**
* 状态 --在库 * 状态 --在库
*/ */
public static final int EXCEl_STATUS_ZAIKU = 0; public static final int EXCEl_STATUS_ZAIKU = 0;
/** /**
* 状态 --在用 * 状态 --在用
*/ */
public static final int EXCEl_STATUS_INUSE = 1; public static final int EXCEl_STATUS_INUSE = 1;
/** /**
* 状态 -- 消费 * 状态 -- 消费
*/ */
public static final int EXCEl_STATUS_CONSUME = 2; public static final int EXCEl_STATUS_CONSUME = 2;
/** /**
* action返回excel结果 * action返回excel结果
*/ */
public static final String EXCEL = "excel"; public static final String EXCEL = "excel";
} }
} }
package com.jsh.constants.common; package com.jsh.constants.common;
public interface AmsConstants public interface AmsConstants
{ {
/** /**
* 定义资产管理公共常量 * 定义资产管理公共常量
* @author andy * @author jishenghua
*/ */
public class Common public class Common
{ {
/** /**
* Info级别日志前缀 * Info级别日志前缀
*/ */
public static final String LOG_INFO_PREFIX = "=========="; public static final String LOG_INFO_PREFIX = "==========";
/** /**
* error级别日志前缀 * error级别日志前缀
*/ */
public static final String LOG_ERROR_PREFIX = ">>>>>>>>>>"; public static final String LOG_ERROR_PREFIX = ">>>>>>>>>>";
/** /**
* debug级别日志前缀 * debug级别日志前缀
*/ */
public static final String LOG_DEBUG_PREFIX = "-----------"; public static final String LOG_DEBUG_PREFIX = "-----------";
/** /**
* fatal级别日志前缀 * fatal级别日志前缀
*/ */
public static final String LOG_FATAL_PREFIX = "$$$$$$$$$$"; public static final String LOG_FATAL_PREFIX = "$$$$$$$$$$";
/** /**
* warn级别日志前缀 * warn级别日志前缀
*/ */
public static final String LOG_WARN_PREFIX = "##########"; public static final String LOG_WARN_PREFIX = "##########";
} }
} }
package com.jsh.constants.common; package com.jsh.constants.common;
public interface LogModuleConstants public interface LogModuleConstants
{ {
/** /**
* 系统管理模块名称定义 * 系统管理模块名称定义
* @author andy * @author jishenghua
*/ */
public class ManageModuleNameCode public class ManageModuleNameCode
{ {
/** /**
* 管理模块资产名称 * 管理模块资产名称
*/ */
public static final String MODULE_MANAGE_ASSETNAME = "资产名称"; public static final String MODULE_MANAGE_ASSETNAME = "资产名称";
/** /**
* 管理模块供应商 * 管理模块供应商
*/ */
public static final String MODULE_MANAGE_SUPPLIER = "供应商"; public static final String MODULE_MANAGE_SUPPLIER = "供应商";
/** /**
* 管理模块资产类型 * 管理模块资产类型
*/ */
public static final String MODULE_MANAGE_CATEGORY = "资产类型"; public static final String MODULE_MANAGE_CATEGORY = "资产类型";
/** /**
* 管理模块用户管理 * 管理模块用户管理
*/ */
public static final String MODULE_MANAGE_USER = "用户管理"; public static final String MODULE_MANAGE_USER = "用户管理";
} }
/** /**
* 资产管理模块名称定义 * 资产管理模块名称定义
* @author andy * @author jishenghua
*/ */
public class AssetModuleNameCode public class AssetModuleNameCode
{ {
/** /**
* 资产管理模块资产管理 * 资产管理模块资产管理
*/ */
public static final String MODULE_ASSET_MANAGE = "资产管理"; public static final String MODULE_ASSET_MANAGE = "资产管理";
/** /**
* 资产管理模块资产报表 * 资产管理模块资产报表
*/ */
public static final String MODULE_ASSET_REPORT = "资产报表"; public static final String MODULE_ASSET_REPORT = "资产报表";
/** /**
* 资产管理模块资产概况 * 资产管理模块资产概况
*/ */
public static final String MODULE_ASSET_GENERAL = "资产概况"; public static final String MODULE_ASSET_GENERAL = "资产概况";
} }
/** /**
* 日志管理模块名称定义 * 日志管理模块名称定义
* @author andy * @author jishenghua
*/ */
public class LogModuleNameCode public class LogModuleNameCode
{ {
/** /**
* 日志管理模块日志管理 * 日志管理模块日志管理
*/ */
public static final String MODULE_LOG_MANAGE = "日志管理"; public static final String MODULE_LOG_MANAGE = "日志管理";
} }
} }
\ No newline at end of file
package com.jsh.dao.asset; package com.jsh.dao.asset;
import org.hibernate.Query; import org.hibernate.Query;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport; import org.springframework.orm.hibernate3.support.HibernateDaoSupport;
import com.jsh.exception.AmsException; import com.jsh.exception.JshException;
import com.jsh.model.po.Asset; import com.jsh.model.po.Asset;
import com.jsh.util.common.PageUtil; import com.jsh.util.common.PageUtil;
import com.jsh.util.common.SearchConditionUtil; import com.jsh.util.common.SearchConditionUtil;
public class ReportDAO extends HibernateDaoSupport implements ReportIDAO public class ReportDAO extends HibernateDaoSupport implements ReportIDAO
{ {
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
@Override @Override
public void find(PageUtil<Asset> pageUtil,String reportType,String reportName) throws AmsException public void find(PageUtil<Asset> pageUtil,String reportType,String reportName) throws JshException
{ {
Query query = this.getHibernateTemplate().getSessionFactory().getCurrentSession().createQuery("select count(" + reportType +") as dataSum, " + reportName + " from Asset asset where 1=1 " + SearchConditionUtil.getCondition(pageUtil.getAdvSearch())); Query query = this.getHibernateTemplate().getSessionFactory().getCurrentSession().createQuery("select count(" + reportType +") as dataSum, " + reportName + " from Asset asset where 1=1 " + SearchConditionUtil.getCondition(pageUtil.getAdvSearch()));
pageUtil.setTotalCount(query.list().size()); pageUtil.setTotalCount(query.list().size());
pageUtil.setPageList(query.list()); pageUtil.setPageList(query.list());
} }
} }
package com.jsh.dao.asset; package com.jsh.dao.asset;
import com.jsh.exception.AmsException; import com.jsh.exception.JshException;
import com.jsh.model.po.Asset; import com.jsh.model.po.Asset;
import com.jsh.util.common.PageUtil; import com.jsh.util.common.PageUtil;
public interface ReportIDAO public interface ReportIDAO
{ {
/** /**
* 查找资产列表 * 查找资产列表
* @param pageUtil 分页工具类 * @param pageUtil 分页工具类
* @param reportType 报表统计字段 * @param reportType 报表统计字段
* @throws AmsException * @throws JshException
*/ */
void find(PageUtil<Asset> pageUtil,String reportType,String reportName) throws AmsException; void find(PageUtil<Asset> pageUtil,String reportType,String reportName) throws JshException;
} }
package com.jsh.dao.basic; package com.jsh.dao.basic;
import org.hibernate.Query; import org.hibernate.Query;
import com.jsh.base.BaseDAO; import com.jsh.base.BaseDAO;
import com.jsh.exception.AmsException; import com.jsh.exception.JshException;
import com.jsh.model.po.Asset; import com.jsh.model.po.Asset;
import com.jsh.model.po.UserBusiness; import com.jsh.model.po.UserBusiness;
import com.jsh.util.common.PageUtil; import com.jsh.util.common.PageUtil;
import com.jsh.util.common.SearchConditionUtil; import com.jsh.util.common.SearchConditionUtil;
public class UserBusinessDAO extends BaseDAO<UserBusiness> implements UserBusinessIDAO public class UserBusinessDAO extends BaseDAO<UserBusiness> implements UserBusinessIDAO
{ {
/** /**
* 设置dao映射基类 * 设置dao映射基类
* @return * @return
*/ */
@Override @Override
public Class<UserBusiness> getEntityClass() public Class<UserBusiness> getEntityClass()
{ {
return UserBusiness.class; return UserBusiness.class;
} }
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
@Override @Override
public void find(PageUtil<UserBusiness> pageUtil,String ceshi) throws AmsException public void find(PageUtil<UserBusiness> pageUtil,String ceshi) throws JshException
{ {
Query query = this.getHibernateTemplate().getSessionFactory().getCurrentSession().createQuery("select count(id),sum(id) from UserBusiness userBusiness where 1=1 " + SearchConditionUtil.getCondition(pageUtil.getAdvSearch())); Query query = this.getHibernateTemplate().getSessionFactory().getCurrentSession().createQuery("select count(id),sum(id) from UserBusiness userBusiness where 1=1 " + SearchConditionUtil.getCondition(pageUtil.getAdvSearch()));
pageUtil.setTotalCount(query.list().size()); pageUtil.setTotalCount(query.list().size());
pageUtil.setPageList(query.list()); pageUtil.setPageList(query.list());
} }
} }
package com.jsh.dao.basic; package com.jsh.dao.basic;
import com.jsh.base.BaseIDAO; import com.jsh.base.BaseIDAO;
import com.jsh.exception.AmsException; import com.jsh.exception.JshException;
import com.jsh.model.po.UserBusiness; import com.jsh.model.po.UserBusiness;
import com.jsh.util.common.PageUtil; import com.jsh.util.common.PageUtil;
public interface UserBusinessIDAO extends BaseIDAO<UserBusiness> public interface UserBusinessIDAO extends BaseIDAO<UserBusiness>
{ {
/* /*
* 测试hql语句 * 测试hql语句
*/ */
void find(PageUtil<UserBusiness> pageUtil,String ceshi) throws AmsException; void find(PageUtil<UserBusiness> pageUtil,String ceshi) throws JshException;
} }
package com.jsh.dao.materials; package com.jsh.dao.materials;
import org.hibernate.Query; import org.hibernate.Query;
import com.jsh.base.BaseDAO; import com.jsh.base.BaseDAO;
import com.jsh.exception.AmsException; import com.jsh.exception.JshException;
import com.jsh.model.po.DepotHead; import com.jsh.model.po.DepotHead;
import com.jsh.model.po.UserBusiness; import com.jsh.model.po.UserBusiness;
import com.jsh.util.common.PageUtil; import com.jsh.util.common.PageUtil;
import com.jsh.util.common.SearchConditionUtil; import com.jsh.util.common.SearchConditionUtil;
public class DepotHeadDAO extends BaseDAO<DepotHead> implements DepotHeadIDAO public class DepotHeadDAO extends BaseDAO<DepotHead> implements DepotHeadIDAO
{ {
/** /**
* 设置dao映射基类 * 设置dao映射基类
* @return * @return
*/ */
@Override @Override
public Class<DepotHead> getEntityClass() public Class<DepotHead> getEntityClass()
{ {
return DepotHead.class; return DepotHead.class;
} }
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
@Override @Override
public void find(PageUtil<DepotHead> pageUtil,String maxid) throws AmsException public void find(PageUtil<DepotHead> pageUtil,String maxid) throws JshException
{ {
Query query = this.getHibernateTemplate().getSessionFactory().getCurrentSession().createQuery("select max(Id) as Id from DepotHead depotHead where 1=1 " + SearchConditionUtil.getCondition(pageUtil.getAdvSearch())); Query query = this.getHibernateTemplate().getSessionFactory().getCurrentSession().createQuery("select max(Id) as Id from DepotHead depotHead where 1=1 " + SearchConditionUtil.getCondition(pageUtil.getAdvSearch()));
pageUtil.setTotalCount(query.list().size()); pageUtil.setTotalCount(query.list().size());
pageUtil.setPageList(query.list()); pageUtil.setPageList(query.list());
} }
} }
package com.jsh.dao.materials; package com.jsh.dao.materials;
import com.jsh.base.BaseIDAO; import com.jsh.base.BaseIDAO;
import com.jsh.exception.AmsException; import com.jsh.exception.JshException;
import com.jsh.model.po.DepotHead; import com.jsh.model.po.DepotHead;
import com.jsh.model.po.UserBusiness; import com.jsh.model.po.UserBusiness;
import com.jsh.util.common.PageUtil; import com.jsh.util.common.PageUtil;
public interface DepotHeadIDAO extends BaseIDAO<DepotHead> public interface DepotHeadIDAO extends BaseIDAO<DepotHead>
{ {
/* /*
* 获取MaxId * 获取MaxId
*/ */
void find(PageUtil<DepotHead> pageUtil,String maxid) throws AmsException; void find(PageUtil<DepotHead> pageUtil,String maxid) throws JshException;
} }
package com.jsh.dao.materials; package com.jsh.dao.materials;
import org.hibernate.Query; import org.hibernate.Query;
import com.jsh.base.BaseDAO; import com.jsh.base.BaseDAO;
import com.jsh.exception.AmsException; import com.jsh.exception.JshException;
import com.jsh.model.po.DepotHead; import com.jsh.model.po.DepotHead;
import com.jsh.model.po.DepotItem; import com.jsh.model.po.DepotItem;
import com.jsh.util.common.PageUtil; import com.jsh.util.common.PageUtil;
import com.jsh.util.common.SearchConditionUtil; import com.jsh.util.common.SearchConditionUtil;
public class DepotItemDAO extends BaseDAO<DepotItem> implements DepotItemIDAO public class DepotItemDAO extends BaseDAO<DepotItem> implements DepotItemIDAO
{ {
/** /**
* 设置dao映射基类 * 设置dao映射基类
* @return * @return
*/ */
@Override @Override
public Class<DepotItem> getEntityClass() public Class<DepotItem> getEntityClass()
{ {
return DepotItem.class; return DepotItem.class;
} }
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
@Override @Override
public void findByType(PageUtil<DepotItem> pageUtil,String type,Long MId,String MonthTime,Boolean isPrev) throws AmsException public void findByType(PageUtil<DepotItem> pageUtil,String type,Long MId,String MonthTime,Boolean isPrev) throws JshException
{ {
//多表联查,多表连查,此处用到了createSQLQuery,可以随便写sql语句,很方便 //多表联查,多表连查,此处用到了createSQLQuery,可以随便写sql语句,很方便
Query query; Query query;
if(isPrev) { if(isPrev) {
query = this.getHibernateTemplate().getSessionFactory().getCurrentSession().createSQLQuery("select sum(OperNumber) as OperNumber from jsh_depotitem,jsh_depothead where jsh_depotitem.HeaderId = jsh_depothead.id and type='" + type +"' and MaterialId ="+ MId + " and jsh_depothead.OperTime <'"+ MonthTime +"-01 00:00:00' " + SearchConditionUtil.getCondition(pageUtil.getAdvSearch())); query = this.getHibernateTemplate().getSessionFactory().getCurrentSession().createSQLQuery("select sum(OperNumber) as OperNumber from jsh_depotitem,jsh_depothead where jsh_depotitem.HeaderId = jsh_depothead.id and type='" + type +"' and MaterialId ="+ MId + " and jsh_depothead.OperTime <'"+ MonthTime +"-01 00:00:00' " + SearchConditionUtil.getCondition(pageUtil.getAdvSearch()));
} }
else { else {
query = this.getHibernateTemplate().getSessionFactory().getCurrentSession().createSQLQuery("select sum(OperNumber) as OperNumber from jsh_depotitem,jsh_depothead where jsh_depotitem.HeaderId = jsh_depothead.id and type='" + type +"' and MaterialId ="+ MId + " and jsh_depothead.OperTime >='"+ MonthTime +"-01 00:00:00' and jsh_depothead.OperTime <='"+ MonthTime +"-31 00:00:00' " + SearchConditionUtil.getCondition(pageUtil.getAdvSearch())); query = this.getHibernateTemplate().getSessionFactory().getCurrentSession().createSQLQuery("select sum(OperNumber) as OperNumber from jsh_depotitem,jsh_depothead where jsh_depotitem.HeaderId = jsh_depothead.id and type='" + type +"' and MaterialId ="+ MId + " and jsh_depothead.OperTime >='"+ MonthTime +"-01 00:00:00' and jsh_depothead.OperTime <='"+ MonthTime +"-31 00:00:00' " + SearchConditionUtil.getCondition(pageUtil.getAdvSearch()));
} }
pageUtil.setTotalCount(query.list().size()); pageUtil.setTotalCount(query.list().size());
pageUtil.setPageList(query.list()); pageUtil.setPageList(query.list());
} }
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
@Override @Override
public void findOrderByMaterial(PageUtil<DepotItem> pageUtil) throws AmsException public void findOrderByMaterial(PageUtil<DepotItem> pageUtil) throws JshException
{ {
//多表联查,多表连查,此处用到了createSQLQuery,可以随便写sql语句,很方便 //多表联查,多表连查,此处用到了createSQLQuery,可以随便写sql语句,很方便
Query query = this.getHibernateTemplate().getSessionFactory().getCurrentSession().createSQLQuery("select * from jsh_depotitem where 1=1 " + SearchConditionUtil.getCondition(pageUtil.getAdvSearch())); Query query = this.getHibernateTemplate().getSessionFactory().getCurrentSession().createSQLQuery("select * from jsh_depotitem where 1=1 " + SearchConditionUtil.getCondition(pageUtil.getAdvSearch()));
pageUtil.setTotalCount(query.list().size()); pageUtil.setTotalCount(query.list().size());
// 分页查询 // 分页查询
int pageNo = pageUtil.getCurPage(); int pageNo = pageUtil.getCurPage();
int pageSize = pageUtil.getPageSize(); int pageSize = pageUtil.getPageSize();
if (0 != pageNo && 0 != pageSize) if (0 != pageNo && 0 != pageSize)
{ {
query.setFirstResult((pageNo - 1) * pageSize); query.setFirstResult((pageNo - 1) * pageSize);
query.setMaxResults(pageSize); query.setMaxResults(pageSize);
} }
pageUtil.setPageList(query.list()); pageUtil.setPageList(query.list());
} }
} }
package com.jsh.dao.materials; package com.jsh.dao.materials;
import com.jsh.base.BaseIDAO; import com.jsh.base.BaseIDAO;
import com.jsh.exception.AmsException; import com.jsh.exception.JshException;
import com.jsh.model.po.DepotHead; import com.jsh.model.po.DepotHead;
import com.jsh.model.po.DepotItem; import com.jsh.model.po.DepotItem;
import com.jsh.util.common.PageUtil; import com.jsh.util.common.PageUtil;
public interface DepotItemIDAO extends BaseIDAO<DepotItem> public interface DepotItemIDAO extends BaseIDAO<DepotItem>
{ {
void findByType(PageUtil<DepotItem> pageUtil,String type,Long MId, String MonthTime,Boolean isPrev) throws AmsException; void findByType(PageUtil<DepotItem> pageUtil,String type,Long MId, String MonthTime,Boolean isPrev) throws JshException;
void findOrderByMaterial(PageUtil<DepotItem> pageUtil) throws AmsException; void findOrderByMaterial(PageUtil<DepotItem> pageUtil) throws JshException;
} }
package com.jsh.exception; package com.jsh.exception;
/** /**
* @title: 平台异常基类 * @title: 平台异常基类
* @description: 用于包装一些异常信息,打印日志等服务 * @description: 用于包装一些异常信息,打印日志等服务
* @author andy * @author jishenghua
* @since: 2014-01-24 * @since: 2014-01-24
*/ */
@SuppressWarnings("serial") @SuppressWarnings("serial")
public class AmsException extends Exception public class JshException extends Exception
{ {
public long errorCode = -1; public long errorCode = -1;
public String message ; public String message ;
public AmsException() public JshException()
{ {
super(); super();
} }
public AmsException(String message) public JshException(String message)
{ {
super(message); super(message);
this.message = message; this.message = message;
} }
public AmsException(String message, Throwable cause) public JshException(String message, Throwable cause)
{ {
super(message, cause); super(message, cause);
this.message = message; this.message = message;
} }
public AmsException(Throwable cause) public JshException(Throwable cause)
{ {
super(cause); super(cause);
} }
public AmsException(long errorCode) public JshException(long errorCode)
{ {
super(); super();
this.errorCode = errorCode; this.errorCode = errorCode;
} }
public AmsException(String message, long errorCode) public JshException(String message, long errorCode)
{ {
super(message); super(message);
this.errorCode = errorCode; this.errorCode = errorCode;
this.message = message; this.message = message;
} }
public AmsException(String message, long errorCode, Throwable cause) public JshException(String message, long errorCode, Throwable cause)
{ {
super(message, cause); super(message, cause);
this.errorCode = errorCode; this.errorCode = errorCode;
this.message = message; this.message = message;
} }
public AmsException(long errorCode, Throwable cause) public JshException(long errorCode, Throwable cause)
{ {
super(cause); super(cause);
this.errorCode = errorCode; this.errorCode = errorCode;
} }
public long getErrorCode() public long getErrorCode()
{ {
return errorCode; return errorCode;
} }
public String getMessage() public String getMessage()
{ {
return message; return message;
} }
} }
package com.jsh.filter.user; package com.jsh.filter.user;
import java.io.IOException; import java.io.IOException;
import java.io.PrintWriter; import java.io.PrintWriter;
import javax.servlet.Filter; import javax.servlet.Filter;
import javax.servlet.FilterChain; import javax.servlet.FilterChain;
import javax.servlet.FilterConfig; import javax.servlet.FilterConfig;
import javax.servlet.ServletException; import javax.servlet.ServletException;
import javax.servlet.ServletRequest; import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse; import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession; import javax.servlet.http.HttpSession;
/** /**
* 用户登录session处理类 * 用户登录session处理类
* 过滤session是否超时 * 过滤session是否超时
* @author andy * @author jishenghua
* @version [版本号, 2012-3-6] * @version [版本号, 2012-3-6]
* @see [相关类/方法] * @see [相关类/方法]
* @since * @since
*/ */
public class UserFilter implements Filter public class UserFilter implements Filter
{ {
/** /**
* 初始化过滤器 暂不处理 * 初始化过滤器 暂不处理
* 重载方法 * 重载方法
* @param arg0 * @param arg0
* @throws ServletException * @throws ServletException
*/ */
public void init(FilterConfig arg0) public void init(FilterConfig arg0)
throws ServletException throws ServletException
{ {
} }
/** /**
* 判断用户session是否存在 不存在则跳转到登录页面 * 判断用户session是否存在 不存在则跳转到登录页面
* 重载方法 * 重载方法
* @param srequest * @param srequest
* @param sresponse * @param sresponse
* @param chain * @param chain
* @throws IOException * @throws IOException
* @throws ServletException * @throws ServletException
*/ */
public void doFilter(ServletRequest srequest, ServletResponse sresponse, FilterChain chain) public void doFilter(ServletRequest srequest, ServletResponse sresponse, FilterChain chain)
throws IOException, ServletException throws IOException, ServletException
{ {
HttpServletRequest request = (HttpServletRequest) srequest; HttpServletRequest request = (HttpServletRequest) srequest;
HttpServletResponse response = (HttpServletResponse) sresponse; HttpServletResponse response = (HttpServletResponse) sresponse;
HttpSession session = request.getSession(); HttpSession session = request.getSession();
// //定义登录页面不被过滤===后续考虑 // //定义登录页面不被过滤===后续考虑
// List<String> notFilterFile = new ArrayList<String>(); // List<String> notFilterFile = new ArrayList<String>();
// notFilterFile.add("/login.jsp"); // notFilterFile.add("/login.jsp");
// notFilterFile.add("/logout.jsp"); // notFilterFile.add("/logout.jsp");
// notFilterFile.add("/css/*"); // notFilterFile.add("/css/*");
// notFilterFile.add("/css/zTreeStyle/*"); // notFilterFile.add("/css/zTreeStyle/*");
// notFilterFile.add("/css/zTreeStyle/img/*"); // notFilterFile.add("/css/zTreeStyle/img/*");
// notFilterFile.add("/css/zTreeStyle/img/diy/*"); // notFilterFile.add("/css/zTreeStyle/img/diy/*");
//获取工程路径 //获取工程路径
String path = request.getContextPath(); String path = request.getContextPath();
String requestURl = request.getRequestURI(); String requestURl = request.getRequestURI();
//提示用户没有权限操作 //提示用户没有权限操作
// response.setCharacterEncoding("utf-8"); // response.setCharacterEncoding("utf-8");
// PrintWriter pw=response.getWriter(); // PrintWriter pw=response.getWriter();
// pw.write("<script language='javascript'>alert('您没有权限进行此项操作!')</script>"); // pw.write("<script language='javascript'>alert('您没有权限进行此项操作!')</script>");
//session中有值则不进行处理 //session中有值则不进行处理
if(requestURl.contains("/pages") &&null != session.getAttribute("user")) if(requestURl.contains("/pages") &&null != session.getAttribute("user"))
chain.doFilter(request, response); chain.doFilter(request, response);
else else
response.sendRedirect(path + "/logout.jsp"); response.sendRedirect(path + "/logout.jsp");
} }
/** /**
* 销毁过滤器 * 销毁过滤器
*/ */
public void destroy() public void destroy()
{ {
} }
} }
\ No newline at end of file
...@@ -18,7 +18,7 @@ ...@@ -18,7 +18,7 @@
</column> </column>
</property> </property>
<property name="password" type="java.lang.String"> <property name="password" type="java.lang.String">
<column name="password" length="30" not-null="true"> <column name="password" length="50" not-null="true">
<comment>登陆密码</comment> <comment>登陆密码</comment>
</column> </column>
</property> </property>
......
package com.jsh.model.vo.materials; package com.jsh.model.vo.materials;
import java.io.Serializable; import java.io.Serializable;
import com.sun.jmx.snmp.Timestamp;
@SuppressWarnings("serial")
@SuppressWarnings("serial") public class DepotHeadModel implements Serializable
public class DepotHeadModel implements Serializable {
{ private DepotHeadShowModel showModel = new DepotHeadShowModel();
private DepotHeadShowModel showModel = new DepotHeadShowModel();
/**======开始接受页面参数=================**/
/**======开始接受页面参数=================**/ private String Type = "";
private String Type = ""; private String SubType = "";
private String SubType = ""; private Long ProjectId;
private Long ProjectId; private String Number = "";
private String Number = ""; private String OperPersonName = "";
private String OperPersonName = ""; private String OperTime;
private String OperTime; private Long OrganId;
private Long OrganId; private Long HandsPersonId;
private Long HandsPersonId; private Long WareHousePersonId;
private Long WareHousePersonId; private String SettlementWay = "";
private String SettlementWay = ""; private Long BuildingId;
private Long BuildingId; private Long AllocationProjectId;
private Long AllocationProjectId; private String Remark = "";
private String Remark = ""; private String State = "";
private String State = ""; private String ReAuditPersonName = "";
private String ReAuditPersonName = ""; private String Reason = "";
private String Reason = "";
private String BeginTime; //查询开始时间
private String BeginTime; //查询开始时间 private String EndTime; //查询结束时间
private String EndTime; //查询结束时间 private String MonthTime; //查询月份
private String MonthTime; //查询月份 /**
/** * 分类ID
* 分类ID */
*/ private Long depotHeadID = 0l;
private Long depotHeadID = 0l;
/**
/** * 分类IDs 批量操作使用
* 分类IDs 批量操作使用 */
*/ private String depotHeadIDs = "";
private String depotHeadIDs = "";
/**
/** * 每页显示的个数
* 每页显示的个数 */
*/ private int pageSize = 10;
private int pageSize = 10;
/**
/** * 当前页码
* 当前页码 */
*/ private int pageNo = 1;
private int pageNo = 1;
/**
/** * 用户IP,用户记录操作日志
* 用户IP,用户记录操作日志 */
*/ private String clientIp = "";
private String clientIp = "";
public DepotHeadShowModel getShowModel() {
public DepotHeadShowModel getShowModel() { return showModel;
return showModel; }
}
public void setShowModel(DepotHeadShowModel showModel) {
public void setShowModel(DepotHeadShowModel showModel) { this.showModel = showModel;
this.showModel = showModel; }
}
public String getType() {
public String getType() { return Type;
return Type; }
}
public void setType(String type) {
public void setType(String type) { Type = type;
Type = type; }
}
public String getSubType() {
public String getSubType() { return SubType;
return SubType; }
}
public void setSubType(String subType) {
public void setSubType(String subType) { SubType = subType;
SubType = subType; }
}
public Long getProjectId() {
public Long getProjectId() { return ProjectId;
return ProjectId; }
}
public void setProjectId(Long projectId) {
public void setProjectId(Long projectId) { ProjectId = projectId;
ProjectId = projectId; }
}
public String getNumber() {
public String getNumber() { return Number;
return Number; }
}
public void setNumber(String number) {
public void setNumber(String number) { Number = number;
Number = number; }
}
public String getOperPersonName() {
public String getOperPersonName() { return OperPersonName;
return OperPersonName; }
}
public void setOperPersonName(String operPersonName) {
public void setOperPersonName(String operPersonName) { OperPersonName = operPersonName;
OperPersonName = operPersonName; }
}
public Long getOrganId() {
public Long getOrganId() { return OrganId;
return OrganId; }
}
public void setOrganId(Long organId) {
public void setOrganId(Long organId) { OrganId = organId;
OrganId = organId; }
}
public Long getHandsPersonId() {
public Long getHandsPersonId() { return HandsPersonId;
return HandsPersonId; }
}
public void setHandsPersonId(Long handsPersonId) {
public void setHandsPersonId(Long handsPersonId) { HandsPersonId = handsPersonId;
HandsPersonId = handsPersonId; }
}
public Long getWareHousePersonId() {
public Long getWareHousePersonId() { return WareHousePersonId;
return WareHousePersonId; }
}
public void setWareHousePersonId(Long wareHousePersonId) {
public void setWareHousePersonId(Long wareHousePersonId) { WareHousePersonId = wareHousePersonId;
WareHousePersonId = wareHousePersonId; }
}
public String getSettlementWay() {
public String getSettlementWay() { return SettlementWay;
return SettlementWay; }
}
public void setSettlementWay(String settlementWay) {
public void setSettlementWay(String settlementWay) { SettlementWay = settlementWay;
SettlementWay = settlementWay; }
}
public Long getBuildingId() {
public Long getBuildingId() { return BuildingId;
return BuildingId; }
}
public void setBuildingId(Long buildingId) {
public void setBuildingId(Long buildingId) { BuildingId = buildingId;
BuildingId = buildingId; }
}
public Long getAllocationProjectId() {
public Long getAllocationProjectId() { return AllocationProjectId;
return AllocationProjectId; }
}
public void setAllocationProjectId(Long allocationProjectId) {
public void setAllocationProjectId(Long allocationProjectId) { AllocationProjectId = allocationProjectId;
AllocationProjectId = allocationProjectId; }
}
public String getRemark() {
public String getRemark() { return Remark;
return Remark; }
}
public void setRemark(String remark) {
public void setRemark(String remark) { Remark = remark;
Remark = remark; }
}
public String getState() {
public String getState() { return State;
return State; }
}
public void setState(String state) {
public void setState(String state) { State = state;
State = state; }
}
public String getReAuditPersonName() {
public String getReAuditPersonName() { return ReAuditPersonName;
return ReAuditPersonName; }
}
public void setReAuditPersonName(String reAuditPersonName) {
public void setReAuditPersonName(String reAuditPersonName) { ReAuditPersonName = reAuditPersonName;
ReAuditPersonName = reAuditPersonName; }
}
public String getReason() {
public String getReason() { return Reason;
return Reason; }
}
public void setReason(String reason) {
public void setReason(String reason) { Reason = reason;
Reason = reason; }
}
public Long getDepotHeadID() {
public Long getDepotHeadID() { return depotHeadID;
return depotHeadID; }
}
public void setDepotHeadID(Long depotHeadID) {
public void setDepotHeadID(Long depotHeadID) { this.depotHeadID = depotHeadID;
this.depotHeadID = depotHeadID; }
}
public String getDepotHeadIDs() {
public String getDepotHeadIDs() { return depotHeadIDs;
return depotHeadIDs; }
}
public void setDepotHeadIDs(String depotHeadIDs) {
public void setDepotHeadIDs(String depotHeadIDs) { this.depotHeadIDs = depotHeadIDs;
this.depotHeadIDs = depotHeadIDs; }
}
public int getPageSize() {
public int getPageSize() { return pageSize;
return pageSize; }
}
public void setPageSize(int pageSize) {
public void setPageSize(int pageSize) { this.pageSize = pageSize;
this.pageSize = pageSize; }
}
public int getPageNo() {
public int getPageNo() { return pageNo;
return pageNo; }
}
public void setPageNo(int pageNo) {
public void setPageNo(int pageNo) { this.pageNo = pageNo;
this.pageNo = pageNo; }
}
public String getClientIp() {
public String getClientIp() { return clientIp;
return clientIp; }
}
public void setClientIp(String clientIp) {
public void setClientIp(String clientIp) { this.clientIp = clientIp;
this.clientIp = clientIp; }
}
public String getBeginTime() {
public String getBeginTime() { return BeginTime;
return BeginTime; }
}
public void setBeginTime(String beginTime) {
public void setBeginTime(String beginTime) { BeginTime = beginTime;
BeginTime = beginTime; }
}
public String getEndTime() {
public String getEndTime() { return EndTime;
return EndTime; }
}
public void setEndTime(String endTime) {
public void setEndTime(String endTime) { EndTime = endTime;
EndTime = endTime; }
}
public String getOperTime() {
public String getOperTime() { return OperTime;
return OperTime; }
}
public void setOperTime(String operTime) {
public void setOperTime(String operTime) { OperTime = operTime;
OperTime = operTime; }
}
public String getMonthTime() {
public String getMonthTime() { return MonthTime;
return MonthTime; }
}
public void setMonthTime(String monthTime) {
public void setMonthTime(String monthTime) { MonthTime = monthTime;
MonthTime = monthTime; }
}
}
}
package com.jsh.service.asset; package com.jsh.service.asset;
import java.io.File; import java.io.File;
import java.io.InputStream; import java.io.InputStream;
import com.jsh.base.BaseIService; import com.jsh.base.BaseIService;
import com.jsh.exception.AmsException; import com.jsh.exception.JshException;
import com.jsh.model.po.Asset; import com.jsh.model.po.Asset;
import com.jsh.util.common.PageUtil; import com.jsh.util.common.PageUtil;
public interface AssetIService extends BaseIService<Asset> public interface AssetIService extends BaseIService<Asset>
{ {
/** /**
* 导出信息 * 导出信息
* @return * @return
*/ */
InputStream exmportExcel(String isAllPage,PageUtil<Asset> pageUtil)throws AmsException; InputStream exmportExcel(String isAllPage,PageUtil<Asset> pageUtil)throws JshException;
/** /**
* 导入资产excel文件--表格格式 同 媒资列表 || 资产名称-资产类型-单价-用户-购买时间-状态-位置-资产编号-序列号-有效日期-保修日期-供应商-标签-描述 * 导入资产excel文件--表格格式 同 媒资列表 || 资产名称-资产类型-单价-用户-购买时间-状态-位置-资产编号-序列号-有效日期-保修日期-供应商-标签-描述
* 业务规则:导入时,检查资产名称是否存在,如存在就不考虑表格中资产类型。如资产名不存在,就新建资产名,类型用表格中的,但类型必须是系统中存在的,不存在的不能导入。 * 业务规则:导入时,检查资产名称是否存在,如存在就不考虑表格中资产类型。如资产名不存在,就新建资产名,类型用表格中的,但类型必须是系统中存在的,不存在的不能导入。
* 资产名称,用户可以添加,其他的应该不能填 * 资产名称,用户可以添加,其他的应该不能填
* *
* @param assetFile excel表格文件 * @param assetFile excel表格文件
* @param isCheck 是否检查 0--手工确定 1--直接导入数据库中 * @param isCheck 是否检查 0--手工确定 1--直接导入数据库中
* @return 错误的表格数据 * @return 错误的表格数据
* @throws AmsException * @throws JshException
*/ */
InputStream importExcel(File assetFile,int isCheck)throws AmsException; InputStream importExcel(File assetFile,int isCheck)throws JshException;
} }
package com.jsh.service.asset; package com.jsh.service.asset;
import java.io.ByteArrayInputStream; import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream; import java.io.ByteArrayOutputStream;
import java.io.File; import java.io.File;
import java.io.FileInputStream; import java.io.FileInputStream;
import java.io.FileNotFoundException; import java.io.FileNotFoundException;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.io.OutputStream; import java.io.OutputStream;
import java.sql.Timestamp; import java.sql.Timestamp;
import java.text.ParseException; import java.text.ParseException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Calendar; import java.util.Calendar;
import java.util.HashMap; import java.util.HashMap;
import java.util.Iterator; import java.util.Iterator;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import jxl.Workbook; import jxl.Workbook;
import jxl.format.Colour; import jxl.format.Colour;
import jxl.write.Label; import jxl.write.Label;
import jxl.write.WritableCellFormat; import jxl.write.WritableCellFormat;
import jxl.write.WritableSheet; import jxl.write.WritableSheet;
import jxl.write.WritableWorkbook; import jxl.write.WritableWorkbook;
import jxl.write.WriteException; import jxl.write.WriteException;
import org.apache.poi.hssf.usermodel.HSSFSheet; import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook; import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.ss.usermodel.Cell; import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.DateUtil; import org.apache.poi.ss.usermodel.DateUtil;
import org.apache.poi.ss.usermodel.Row; import org.apache.poi.ss.usermodel.Row;
import com.jsh.base.BaseService; import com.jsh.base.BaseService;
import com.jsh.base.Log; import com.jsh.base.Log;
import com.jsh.constants.asset.AssetConstants; import com.jsh.constants.asset.AssetConstants;
import com.jsh.dao.asset.AssetIDAO; import com.jsh.dao.asset.AssetIDAO;
import com.jsh.dao.basic.AssetNameIDAO; import com.jsh.dao.basic.AssetNameIDAO;
import com.jsh.dao.basic.CategoryIDAO; import com.jsh.dao.basic.CategoryIDAO;
import com.jsh.dao.basic.SupplierIDAO; import com.jsh.dao.basic.SupplierIDAO;
import com.jsh.dao.basic.UserIDAO; import com.jsh.dao.basic.UserIDAO;
import com.jsh.exception.AmsException; import com.jsh.exception.JshException;
import com.jsh.model.po.Asset; import com.jsh.model.po.Asset;
import com.jsh.model.po.Assetname; import com.jsh.model.po.Assetname;
import com.jsh.model.po.Category; import com.jsh.model.po.Category;
import com.jsh.model.po.Supplier; import com.jsh.model.po.Supplier;
import com.jsh.util.common.PageUtil; import com.jsh.util.common.PageUtil;
import com.jsh.util.common.Tools; import com.jsh.util.common.Tools;
public class AssetService extends BaseService<Asset> implements AssetIService public class AssetService extends BaseService<Asset> implements AssetIService
{ {
private AssetIDAO assetDao; private AssetIDAO assetDao;
private AssetNameIDAO assetNameDao; private AssetNameIDAO assetNameDao;
private CategoryIDAO categoryDao; private CategoryIDAO categoryDao;
private SupplierIDAO supplierDao; private SupplierIDAO supplierDao;
private UserIDAO userDao; private UserIDAO userDao;
/** /**
* 初始化加载所有系统基础数据 * 初始化加载所有系统基础数据
*/ */
@SuppressWarnings({"rawtypes"}) @SuppressWarnings({"rawtypes"})
private static Map<String,List> mapData = new HashMap<String, List>(); private static Map<String,List> mapData = new HashMap<String, List>();
/** /**
* 错误的表格数据 * 错误的表格数据
*/ */
private static List<Asset> wrongData = new ArrayList<Asset>(); private static List<Asset> wrongData = new ArrayList<Asset>();
/** /**
* 导出Excel表格 * 导出Excel表格
*/ */
@Override @Override
public InputStream exmportExcel(String isAllPage,PageUtil<Asset> pageUtil)throws AmsException public InputStream exmportExcel(String isAllPage,PageUtil<Asset> pageUtil)throws JshException
{ {
try try
{ {
if("currentPage".equals(isAllPage)) if("currentPage".equals(isAllPage))
{ {
assetDao.find(pageUtil); assetDao.find(pageUtil);
} }
else else
{ {
pageUtil.setCurPage(0); pageUtil.setCurPage(0);
pageUtil.setPageSize(0); pageUtil.setPageSize(0);
assetDao.find(pageUtil); assetDao.find(pageUtil);
} }
//将OutputStream转化为InputStream //将OutputStream转化为InputStream
ByteArrayOutputStream out = new ByteArrayOutputStream(); ByteArrayOutputStream out = new ByteArrayOutputStream();
putDataOnOutputStream(out,pageUtil.getPageList()); putDataOnOutputStream(out,pageUtil.getPageList());
return new ByteArrayInputStream(out.toByteArray()); return new ByteArrayInputStream(out.toByteArray());
} }
catch (Exception e) catch (Exception e)
{ {
Log.errorFileSync(">>>>>>>>>>>>>>>>>>>>>>>导出资产信息为excel表格异常", e); Log.errorFileSync(">>>>>>>>>>>>>>>>>>>>>>>导出资产信息为excel表格异常", e);
throw new AmsException("export asset info to excel exception",e); throw new JshException("export asset info to excel exception",e);
} }
} }
@Override @Override
public InputStream importExcel(File assetFile,int isCheck) throws AmsException public InputStream importExcel(File assetFile,int isCheck) throws JshException
{ {
//全局变量--每次调用前需要清空数据 //全局变量--每次调用前需要清空数据
mapData.clear(); mapData.clear();
//1、加载系统基础数据 //1、加载系统基础数据
loadSystemData(); loadSystemData();
//2、解析文件成资产数据 //2、解析文件成资产数据
parseFile(assetFile); parseFile(assetFile);
if(null != wrongData && wrongData.size()>0) if(null != wrongData && wrongData.size()>0)
{ {
//将OutputStream转化为InputStream //将OutputStream转化为InputStream
ByteArrayOutputStream out = new ByteArrayOutputStream(); ByteArrayOutputStream out = new ByteArrayOutputStream();
putDataOnOutputStream(out,wrongData); putDataOnOutputStream(out,wrongData);
return new ByteArrayInputStream(out.toByteArray()); return new ByteArrayInputStream(out.toByteArray());
} }
else else
return null; return null;
//2、是否直接插入数据库中 //2、是否直接插入数据库中
// if(0 == isCheck) // if(0 == isCheck)
// System.out.println("手动检查"); // System.out.println("手动检查");
// else // else
// System.out.println("自动检查插入"); // System.out.println("自动检查插入");
} }
/** /**
* 初始加载系统基础数据--导入过程中,不用频繁查询数据库内容,影响系统性能。 * 初始加载系统基础数据--导入过程中,不用频繁查询数据库内容,影响系统性能。
* @throws AmsException * @throws JshException
*/ */
@SuppressWarnings({ "unchecked", "rawtypes" }) @SuppressWarnings({ "unchecked", "rawtypes" })
private void loadSystemData()throws AmsException private void loadSystemData()throws JshException
{ {
PageUtil pageUtil = new PageUtil(); PageUtil pageUtil = new PageUtil();
pageUtil.setPageSize(0); pageUtil.setPageSize(0);
pageUtil.setCurPage(0); pageUtil.setCurPage(0);
try try
{ {
Map<String,Object> condition = pageUtil.getAdvSearch(); Map<String,Object> condition = pageUtil.getAdvSearch();
condition.put("id_s_order", "desc"); condition.put("id_s_order", "desc");
categoryDao.find(pageUtil); categoryDao.find(pageUtil);
mapData.put("categoryList", pageUtil.getPageList()); mapData.put("categoryList", pageUtil.getPageList());
supplierDao.find(pageUtil); supplierDao.find(pageUtil);
mapData.put("supplierList", pageUtil.getPageList()); mapData.put("supplierList", pageUtil.getPageList());
condition.put("isystem_n_eq", 1); condition.put("isystem_n_eq", 1);
condition.put("id_s_order", "desc"); condition.put("id_s_order", "desc");
userDao.find(pageUtil); userDao.find(pageUtil);
mapData.put("userList", pageUtil.getPageList()); mapData.put("userList", pageUtil.getPageList());
//清除搜索条件 防止对查询有影响 //清除搜索条件 防止对查询有影响
condition.remove("isystem_n_eq"); condition.remove("isystem_n_eq");
assetNameDao.find(pageUtil); assetNameDao.find(pageUtil);
mapData.put("assetnameList", pageUtil.getPageList()); mapData.put("assetnameList", pageUtil.getPageList());
} }
catch (Exception e) catch (Exception e)
{ {
Log.errorFileSync(">>>>>>>>>>>>>查找系统基础数据信息异常", e); Log.errorFileSync(">>>>>>>>>>>>>查找系统基础数据信息异常", e);
} }
} }
/** /**
* 解析excel表格 * 解析excel表格
* @param assetFile * @param assetFile
*/ */
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
private void parseFile(File assetFile) private void parseFile(File assetFile)
{ {
//每次调用前清空 //每次调用前清空
wrongData.clear(); wrongData.clear();
int totalRow = 0; int totalRow = 0;
try try
{ {
//创建对Excel工作簿文件的引用 //创建对Excel工作簿文件的引用
HSSFWorkbook workbook = new HSSFWorkbook(new FileInputStream(assetFile)); HSSFWorkbook workbook = new HSSFWorkbook(new FileInputStream(assetFile));
//创建对工作表的引用,获取第一个工作表的内容 //创建对工作表的引用,获取第一个工作表的内容
HSSFSheet sheet = workbook.getSheetAt(0); HSSFSheet sheet = workbook.getSheetAt(0);
/** /**
* ===================================== * =====================================
* 1、此处要增加文件的验证,如果不是资产文件需要进行特殊的处理,13列 * 1、此处要增加文件的验证,如果不是资产文件需要进行特殊的处理,13列
* 2、文件内容为空处理 * 2、文件内容为空处理
* 3、如果是修改过的文件内容 * 3、如果是修改过的文件内容
*/ */
Iterator<Row> itsheet = sheet.rowIterator(); Iterator<Row> itsheet = sheet.rowIterator();
while(itsheet.hasNext()) while(itsheet.hasNext())
{ {
//获取当前行数据 //获取当前行数据
Row row = itsheet.next(); Row row = itsheet.next();
//获取一行有多少单元格 //获取一行有多少单元格
// System.out.println(row.getLastCellNum()); // System.out.println(row.getLastCellNum());
//excel表格第几行数据 从1开始 0 是表头 //excel表格第几行数据 从1开始 0 是表头
int rowNum = row.getRowNum(); int rowNum = row.getRowNum();
/** /**
* 表头跳过不读 * 表头跳过不读
*/ */
if(AssetConstants.BusinessForExcel.EXCEL_TABLE_HEAD == rowNum) if(AssetConstants.BusinessForExcel.EXCEL_TABLE_HEAD == rowNum)
continue; continue;
//开始处理excel表格内容 --每行数据读取,同时统计总共行数 //开始处理excel表格内容 --每行数据读取,同时统计总共行数
totalRow ++; totalRow ++;
//获取excel表格的每格数据内容 //获取excel表格的每格数据内容
Iterator<Cell> it = row.cellIterator(); Iterator<Cell> it = row.cellIterator();
//资产子类型--添加了一些excel表格数据 //资产子类型--添加了一些excel表格数据
Asset asset = new Asset(); Asset asset = new Asset();
//保存每个单元格错误类型 //保存每个单元格错误类型
Map<Integer,String> cellType = new HashMap<Integer,String>(); Map<Integer,String> cellType = new HashMap<Integer,String>();
//名称需要类型字段 //名称需要类型字段
Assetname nameModel = null; Assetname nameModel = null;
//资产名称 //资产名称
@SuppressWarnings("unused") @SuppressWarnings("unused")
String assetname = ""; String assetname = "";
//资产类型 //资产类型
String categoryStr = ""; String categoryStr = "";
//设置列号 //设置列号
asset.setRowLineNum(rowNum); asset.setRowLineNum(rowNum);
Cell cell = null; Cell cell = null;
//判断列号--从零开始 //判断列号--从零开始
int cellIndex = 0; int cellIndex = 0;
while(it.hasNext()) while(it.hasNext())
{ {
//获取每个单元格对象 //获取每个单元格对象
cell = it.next(); cell = it.next();
//获取列号 //获取列号
cellIndex = cell.getColumnIndex(); cellIndex = cell.getColumnIndex();
//设置此单元格为字符串类型 //设置此单元格为字符串类型
cell.setCellType(Cell.CELL_TYPE_STRING); cell.setCellType(Cell.CELL_TYPE_STRING);
Log.infoFileSync("==================excel表格中第" + totalRow + "行的第 " + cellIndex + "列的值为" + cell.getStringCellValue()); Log.infoFileSync("==================excel表格中第" + totalRow + "行的第 " + cellIndex + "列的值为" + cell.getStringCellValue());
//每行中数据顺序 资产名称-资产类型-单价-用户-购买时间-状态-位置-资产编号-序列号-有效日期-保修日期-供应商-标签-描述 //每行中数据顺序 资产名称-资产类型-单价-用户-购买时间-状态-位置-资产编号-序列号-有效日期-保修日期-供应商-标签-描述
switch(cellIndex) switch(cellIndex)
{ {
case AssetConstants.BusinessForExcel.EXCEL_ASSETNAME : case AssetConstants.BusinessForExcel.EXCEL_ASSETNAME :
//资产名称是否存在 //资产名称是否存在
boolean isAssetnameExist = false; boolean isAssetnameExist = false;
//此处添加资产名称处理 //此处添加资产名称处理
String nameValue = cell.getStringCellValue(); String nameValue = cell.getStringCellValue();
if(null == nameValue || "".equals(nameValue)) if(null == nameValue || "".equals(nameValue))
{ {
Log.errorFileSync(">>>>>>>>>>>>>>>>资产名称没有填写"); Log.errorFileSync(">>>>>>>>>>>>>>>>资产名称没有填写");
cellType.put(cellIndex, "wrong"); cellType.put(cellIndex, "wrong");
break; break;
} }
assetname = nameValue; assetname = nameValue;
List<Assetname> nameList = mapData.get("assetnameList"); List<Assetname> nameList = mapData.get("assetnameList");
for(Assetname name:nameList) for(Assetname name:nameList)
{ {
//表示名称存在--直接进行保存,不需要判断类型字段 //表示名称存在--直接进行保存,不需要判断类型字段
if(nameValue.equals(name.getAssetname())) if(nameValue.equals(name.getAssetname()))
{ {
isAssetnameExist = true; isAssetnameExist = true;
//直接进行设置 //直接进行设置
asset.setAssetname(name); asset.setAssetname(name);
break; break;
} }
} }
//名称不存在 重新创建 //名称不存在 重新创建
if(!isAssetnameExist) if(!isAssetnameExist)
{ {
isAssetnameExist = false; isAssetnameExist = false;
nameModel = new Assetname(); nameModel = new Assetname();
nameModel.setAssetname(nameValue); nameModel.setAssetname(nameValue);
nameModel.setIsconsumables((short)0); nameModel.setIsconsumables((short)0);
nameModel.setIsystem((short)1); nameModel.setIsystem((short)1);
nameModel.setDescription(""); nameModel.setDescription("");
asset.setAssetnameStr(nameValue); asset.setAssetnameStr(nameValue);
} }
break; break;
case AssetConstants.BusinessForExcel.EXCEL_CATEGORY : case AssetConstants.BusinessForExcel.EXCEL_CATEGORY :
//此处添加资产类型处理 //此处添加资产类型处理
//类型信息是否存在 //类型信息是否存在
boolean isCategoryExist = false; boolean isCategoryExist = false;
String categoryValue = cell.getStringCellValue(); String categoryValue = cell.getStringCellValue();
if((null == categoryValue || "".equals(categoryValue)) && null != nameModel) if((null == categoryValue || "".equals(categoryValue)) && null != nameModel)
{ {
Log.errorFileSync(">>>>>>>>>>>>>>>>资产名称没有指定类型"); Log.errorFileSync(">>>>>>>>>>>>>>>>资产名称没有指定类型");
cellType.put(cellIndex, "wrong"); cellType.put(cellIndex, "wrong");
break; break;
} }
categoryStr = categoryValue; categoryStr = categoryValue;
List<Category> categoryList = mapData.get("categoryList"); List<Category> categoryList = mapData.get("categoryList");
for(Category category:categoryList) for(Category category:categoryList)
{ {
//表示新创建 --名称设置过 不需要再进行处理 //表示新创建 --名称设置过 不需要再进行处理
if(category.getAssetname().equals(categoryValue) && null != nameModel) if(category.getAssetname().equals(categoryValue) && null != nameModel)
{ {
isCategoryExist = true; isCategoryExist = true;
nameModel.setCategory(category); nameModel.setCategory(category);
asset.setAssetname(nameModel); asset.setAssetname(nameModel);
assetNameDao.create(nameModel); assetNameDao.create(nameModel);
break; break;
} }
} }
//重新创建 //重新创建
if(null != nameModel && !isCategoryExist) if(null != nameModel && !isCategoryExist)
{ {
//首先创建类型信息 //首先创建类型信息
Category canew = new Category(); Category canew = new Category();
canew.setAssetname(categoryValue); canew.setAssetname(categoryValue);
canew.setIsystem((short)1); canew.setIsystem((short)1);
canew.setDescription(""); canew.setDescription("");
categoryDao.create(canew); categoryDao.create(canew);
nameModel.setCategory(canew); nameModel.setCategory(canew);
assetNameDao.create(nameModel); assetNameDao.create(nameModel);
asset.setAssetname(nameModel); asset.setAssetname(nameModel);
} }
//nameModel为空表示 已经处理过类型信息 --此处不需要进行处理 //nameModel为空表示 已经处理过类型信息 --此处不需要进行处理
else else
{ {
asset.setCategory(categoryStr); asset.setCategory(categoryStr);
} }
break; break;
case AssetConstants.BusinessForExcel.EXCEL_PRICE: case AssetConstants.BusinessForExcel.EXCEL_PRICE:
//此处添加单价处理 //此处添加单价处理
String priceValue = cell.getStringCellValue(); String priceValue = cell.getStringCellValue();
//String priceValue = getCellFormatValue(cell); //String priceValue = getCellFormatValue(cell);
if(null == priceValue || "".equals(priceValue)) if(null == priceValue || "".equals(priceValue))
{ {
Log.errorFileSync(">>>>>>>>>>>>>>>>资产没有填写单价"); Log.errorFileSync(">>>>>>>>>>>>>>>>资产没有填写单价");
break; break;
} }
//解析价格 //解析价格
if(Tools.checkStrIsNum(priceValue)) if(Tools.checkStrIsNum(priceValue))
asset.setPrice(Double.parseDouble(priceValue)); asset.setPrice(Double.parseDouble(priceValue));
else else
{ {
Log.errorFileSync(">>>>>>>>>>>>>>>>>资产价格不是数字格式"); Log.errorFileSync(">>>>>>>>>>>>>>>>>资产价格不是数字格式");
cellType.put(cellIndex, "wrong"); cellType.put(cellIndex, "wrong");
asset.setPrice(0.00d); asset.setPrice(0.00d);
asset.setPriceStr(priceValue); asset.setPriceStr(priceValue);
} }
break; break;
case AssetConstants.BusinessForExcel.EXCEL_USER : case AssetConstants.BusinessForExcel.EXCEL_USER :
//此处添加用户处理--用户信息不需要进行处理 //此处添加用户处理--用户信息不需要进行处理
break; break;
case AssetConstants.BusinessForExcel.EXCEL_PURCHASE_DATE : case AssetConstants.BusinessForExcel.EXCEL_PURCHASE_DATE :
//此处添加购买时间处理--时间不需要处理 //此处添加购买时间处理--时间不需要处理
String purchaseValue = cell.getStringCellValue(); String purchaseValue = cell.getStringCellValue();
if(null == purchaseValue || "".equals(purchaseValue)) if(null == purchaseValue || "".equals(purchaseValue))
{ {
Log.errorFileSync(">>>>>>>>>>>>>>>>资产没有填写购买日期"); Log.errorFileSync(">>>>>>>>>>>>>>>>资产没有填写购买日期");
break; break;
} }
try try
{ {
asset.setPurchasedate(new Timestamp(Tools.parse(purchaseValue, "yyyy-MM-dd").getTime())); asset.setPurchasedate(new Timestamp(Tools.parse(purchaseValue, "yyyy-MM-dd").getTime()));
} }
catch (ParseException e) catch (ParseException e)
{ {
Log.errorFileSync(">>>>>>>>>>>>>>>>>解析购买日期异常", e); Log.errorFileSync(">>>>>>>>>>>>>>>>>解析购买日期异常", e);
try try
{ {
asset.setPurchasedate(new Timestamp(DateUtil.getJavaDate(Double.parseDouble(purchaseValue)).getTime())); asset.setPurchasedate(new Timestamp(DateUtil.getJavaDate(Double.parseDouble(purchaseValue)).getTime()));
} }
catch (Exception t) catch (Exception t)
{ {
asset.setPurchasedateStr(purchaseValue); asset.setPurchasedateStr(purchaseValue);
cellType.put(cellIndex, "wrong"); cellType.put(cellIndex, "wrong");
} }
} }
break; break;
case AssetConstants.BusinessForExcel.EXCEL_STATUS : case AssetConstants.BusinessForExcel.EXCEL_STATUS :
//此处添加状态处理--默认为在库状态 //此处添加状态处理--默认为在库状态
asset.setStatus((short)0); asset.setStatus((short)0);
break; break;
case AssetConstants.BusinessForExcel.EXCEL_LOCATION : case AssetConstants.BusinessForExcel.EXCEL_LOCATION :
//此处添加位置处理--不需要进行处理 //此处添加位置处理--不需要进行处理
String locationValue = cell.getStringCellValue(); String locationValue = cell.getStringCellValue();
if(null == locationValue || "".equals(locationValue)) if(null == locationValue || "".equals(locationValue))
{ {
Log.errorFileSync(">>>>>>>>>>>>>>>>资产没有填写位置信息"); Log.errorFileSync(">>>>>>>>>>>>>>>>资产没有填写位置信息");
break; break;
} }
asset.setLocation(locationValue); asset.setLocation(locationValue);
break; break;
case AssetConstants.BusinessForExcel.EXCEL_NUM : case AssetConstants.BusinessForExcel.EXCEL_NUM :
//此处添加资产编号处理 //此处添加资产编号处理
String assetnumValue = cell.getStringCellValue(); String assetnumValue = cell.getStringCellValue();
if(null == assetnumValue || "".equals(assetnumValue)) if(null == assetnumValue || "".equals(assetnumValue))
{ {
Log.errorFileSync(">>>>>>>>>>>>>>>>资产没有填写资产编号"); Log.errorFileSync(">>>>>>>>>>>>>>>>资产没有填写资产编号");
break; break;
} }
//设置资产编号 //设置资产编号
asset.setAssetnum(assetnumValue); asset.setAssetnum(assetnumValue);
break; break;
case AssetConstants.BusinessForExcel.EXCEL_SERIALNO : case AssetConstants.BusinessForExcel.EXCEL_SERIALNO :
//此处添加序列号处理 //此处添加序列号处理
String assetseriValue = cell.getStringCellValue(); String assetseriValue = cell.getStringCellValue();
if(null == assetseriValue || "".equals(assetseriValue)) if(null == assetseriValue || "".equals(assetseriValue))
{ {
Log.errorFileSync(">>>>>>>>>>>>>>>>资产没有填写序列号"); Log.errorFileSync(">>>>>>>>>>>>>>>>资产没有填写序列号");
break; break;
} }
//设置资产编号 //设置资产编号
asset.setSerialnum(assetseriValue); asset.setSerialnum(assetseriValue);
break; break;
case AssetConstants.BusinessForExcel.EXCEL_EXPIRATION_DATE : case AssetConstants.BusinessForExcel.EXCEL_EXPIRATION_DATE :
//此处添加有效日期处理--不需要处理 //此处添加有效日期处理--不需要处理
String expirationValue = cell.getStringCellValue(); String expirationValue = cell.getStringCellValue();
if(null == expirationValue || "".equals(expirationValue)) if(null == expirationValue || "".equals(expirationValue))
{ {
Log.errorFileSync(">>>>>>>>>>>>>>>>资产没有有效日期"); Log.errorFileSync(">>>>>>>>>>>>>>>>资产没有有效日期");
break; break;
} }
try try
{ {
asset.setPeriodofvalidity(new Timestamp(Tools.parse(expirationValue, "yyyy-MM-dd").getTime())); asset.setPeriodofvalidity(new Timestamp(Tools.parse(expirationValue, "yyyy-MM-dd").getTime()));
} }
catch (ParseException e) catch (ParseException e)
{ {
try try
{ {
asset.setPeriodofvalidity(new Timestamp(DateUtil.getJavaDate(Double.parseDouble(expirationValue)).getTime())); asset.setPeriodofvalidity(new Timestamp(DateUtil.getJavaDate(Double.parseDouble(expirationValue)).getTime()));
} }
catch (Exception t) catch (Exception t)
{ {
Log.errorFileSync(">>>>>>>>>>>>>>>>>解析有效日期异常", t); Log.errorFileSync(">>>>>>>>>>>>>>>>>解析有效日期异常", t);
asset.setPeriodofvalidityStr(expirationValue); asset.setPeriodofvalidityStr(expirationValue);
cellType.put(cellIndex, "wrong"); cellType.put(cellIndex, "wrong");
} }
} }
break; break;
case AssetConstants.BusinessForExcel.EXCEL_WARRANTY_DATE : case AssetConstants.BusinessForExcel.EXCEL_WARRANTY_DATE :
//此处添加保修日期处理--不需要处理 //此处添加保修日期处理--不需要处理
String warrantyValue = cell.getStringCellValue(); String warrantyValue = cell.getStringCellValue();
if(null == warrantyValue || "".equals(warrantyValue)) if(null == warrantyValue || "".equals(warrantyValue))
{ {
Log.errorFileSync(">>>>>>>>>>>>>>>>资产没有保修日期"); Log.errorFileSync(">>>>>>>>>>>>>>>>资产没有保修日期");
break; break;
} }
try try
{ {
asset.setWarrantydate(new Timestamp(Tools.parse(warrantyValue, "yyyy-MM-dd").getTime())); asset.setWarrantydate(new Timestamp(Tools.parse(warrantyValue, "yyyy-MM-dd").getTime()));
} }
catch (ParseException e) catch (ParseException e)
{ {
try try
{ {
asset.setWarrantydate(new Timestamp(DateUtil.getJavaDate(Double.parseDouble(warrantyValue)).getTime())); asset.setWarrantydate(new Timestamp(DateUtil.getJavaDate(Double.parseDouble(warrantyValue)).getTime()));
} }
catch (Exception t) catch (Exception t)
{ {
Log.errorFileSync(">>>>>>>>>>>>>>>>>解析保修日期异常", t); Log.errorFileSync(">>>>>>>>>>>>>>>>>解析保修日期异常", t);
asset.setWarrantydateStr(warrantyValue); asset.setWarrantydateStr(warrantyValue);
cellType.put(cellIndex, "wrong"); cellType.put(cellIndex, "wrong");
} }
} }
break; break;
case AssetConstants.BusinessForExcel.EXCEL_SUPPLIER : case AssetConstants.BusinessForExcel.EXCEL_SUPPLIER :
//此处添加供应商处理 //此处添加供应商处理
String supplierValue = cell.getStringCellValue(); String supplierValue = cell.getStringCellValue();
if(null == supplierValue || "".equals(supplierValue)) if(null == supplierValue || "".equals(supplierValue))
{ {
Log.errorFileSync(">>>>>>>>>>>>>>>>资产没有填写供应商"); Log.errorFileSync(">>>>>>>>>>>>>>>>资产没有填写供应商");
cellType.put(cellIndex, "wrong"); cellType.put(cellIndex, "wrong");
break; break;
} }
//供应商 //供应商
List<Supplier> supplierList = mapData.get("supplierList"); List<Supplier> supplierList = mapData.get("supplierList");
boolean isSupplerExist =false; boolean isSupplerExist =false;
for(Supplier supplier:supplierList) for(Supplier supplier:supplierList)
{ {
if(supplierValue.equals(supplier.getSupplier())) if(supplierValue.equals(supplier.getSupplier()))
{ {
isSupplerExist =true; isSupplerExist =true;
asset.setSupplier(supplier); asset.setSupplier(supplier);
break; break;
} }
} }
if(!isSupplerExist) if(!isSupplerExist)
{ {
Supplier sup = new Supplier(); Supplier sup = new Supplier();
sup.setIsystem((short)1); sup.setIsystem((short)1);
sup.setSupplier(supplierValue); sup.setSupplier(supplierValue);
sup.setDescription(""); sup.setDescription("");
supplierDao.create(sup); supplierDao.create(sup);
//保存供应商信息 //保存供应商信息
asset.setSupplier(sup); asset.setSupplier(sup);
} }
break; break;
case AssetConstants.BusinessForExcel.EXCEL_LABLE : case AssetConstants.BusinessForExcel.EXCEL_LABLE :
//此处添加标签处理 //此处添加标签处理
String lableValue = cell.getStringCellValue(); String lableValue = cell.getStringCellValue();
if(null == lableValue || "".equals(lableValue)) if(null == lableValue || "".equals(lableValue))
{ {
Log.errorFileSync(">>>>>>>>>>>>>>>>资产没有填写标签信息"); Log.errorFileSync(">>>>>>>>>>>>>>>>资产没有填写标签信息");
break; break;
} }
asset.setLabels(lableValue); asset.setLabels(lableValue);
break; break;
case AssetConstants.BusinessForExcel.EXCEL_DESC : case AssetConstants.BusinessForExcel.EXCEL_DESC :
//此处添加描述信息处理 //此处添加描述信息处理
String descValue = cell.getStringCellValue(); String descValue = cell.getStringCellValue();
if(null == descValue || "".equals(descValue)) if(null == descValue || "".equals(descValue))
{ {
Log.errorFileSync(">>>>>>>>>>>>>>>>资产没有填写描述信息"); Log.errorFileSync(">>>>>>>>>>>>>>>>资产没有填写描述信息");
break; break;
} }
asset.setDescription(descValue); asset.setDescription(descValue);
break; break;
} }
} }
asset.setCreatetime(new Timestamp(Calendar.getInstance().getTime().getTime())); asset.setCreatetime(new Timestamp(Calendar.getInstance().getTime().getTime()));
asset.setUpdatetime(new Timestamp(Calendar.getInstance().getTime().getTime())); asset.setUpdatetime(new Timestamp(Calendar.getInstance().getTime().getTime()));
asset.setCellInfo(cellType); asset.setCellInfo(cellType);
Log.infoFileSync(totalRow + "行总共有" + cellIndex + "列"); Log.infoFileSync(totalRow + "行总共有" + cellIndex + "列");
//资产文件为13列,否则不是资产模板文件--不输入的时候 判断会有问题 暂时去掉 //资产文件为13列,否则不是资产模板文件--不输入的时候 判断会有问题 暂时去掉
// if(cellIndex != 13) // if(cellIndex != 13)
// { // {
// Log.errorFileSync(">>>>>>>>>>>>>>>>>>>>>>导入文件格式不合法,请重新选择文件进行操作!"); // Log.errorFileSync(">>>>>>>>>>>>>>>>>>>>>>导入文件格式不合法,请重新选择文件进行操作!");
// return; // return;
// } // }
//判断完成后增加数据 //判断完成后增加数据
if((null!=cellType && cellType.size() >0) if((null!=cellType && cellType.size() >0)
|| asset.getAssetname() == null || asset.getAssetname().getCategory() == null) || asset.getAssetname() == null || asset.getAssetname().getCategory() == null)
wrongData.add(asset); wrongData.add(asset);
else else
{ {
if(null == asset.getStatus()) if(null == asset.getStatus())
asset.setStatus((short)0); asset.setStatus((short)0);
assetDao.save(asset); assetDao.save(asset);
} }
} }
} }
catch (FileNotFoundException e) catch (FileNotFoundException e)
{ {
Log.errorFileSync(">>>>>>>>>>>>>>>>>>读取excel文件异常:找不到指定文件!",e); Log.errorFileSync(">>>>>>>>>>>>>>>>>>读取excel文件异常:找不到指定文件!",e);
} }
catch (IOException e) catch (IOException e)
{ {
Log.errorFileSync(">>>>>>>>>>>>>>>>>>读取excel文件异常,请确认文件格式是否正确 !",e); Log.errorFileSync(">>>>>>>>>>>>>>>>>>读取excel文件异常,请确认文件格式是否正确 !",e);
} }
Log.infoFileSync("===================excel表格总共有 " + totalRow + " 条记录!"); Log.infoFileSync("===================excel表格总共有 " + totalRow + " 条记录!");
} }
/** /**
* 生成excel表格 * 生成excel表格
* @param os * @param os
*/ */
private void putDataOnOutputStream(OutputStream os,List<Asset> dataList) private void putDataOnOutputStream(OutputStream os,List<Asset> dataList)
{ {
WritableWorkbook workbook = null; WritableWorkbook workbook = null;
try try
{ {
workbook = Workbook.createWorkbook(os); workbook = Workbook.createWorkbook(os);
WritableSheet sheet = workbook.createSheet("资产详细信息", 0); WritableSheet sheet = workbook.createSheet("资产详细信息", 0);
//增加列头 //增加列头
int[] colunmWidth = {30,30,10,15,20,10,30,30,30,20,20,20,30,80}; int[] colunmWidth = {30,30,10,15,20,10,30,30,30,20,20,20,30,80};
String[] colunmName = {"资产名称","资产类型","单价","用户","购买时间","状态","位置","资产编号","序列号","有效日期","保修日期","供应商","标签","描述"}; String[] colunmName = {"资产名称","资产类型","单价","用户","购买时间","状态","位置","资产编号","序列号","有效日期","保修日期","供应商","标签","描述"};
for(int i = 0 ;i < colunmWidth.length;i ++) for(int i = 0 ;i < colunmWidth.length;i ++)
{ {
sheet.setColumnView(i,colunmWidth[i]); sheet.setColumnView(i,colunmWidth[i]);
sheet.addCell(new Label(i, 0, colunmName[i])); sheet.addCell(new Label(i, 0, colunmName[i]));
} }
if (null != dataList &&dataList.size() > 0) if (null != dataList &&dataList.size() > 0)
{ {
int i = 1; int i = 1;
for (Asset asset: dataList) for (Asset asset: dataList)
{ {
int j = 0; int j = 0;
Map<Integer,String> cellInfo = asset.getCellInfo(); Map<Integer,String> cellInfo = asset.getCellInfo();
//第一列,填充 数据, Label(列,行,值) //第一列,填充 数据, Label(列,行,值)
sheet.addCell(getLabelInfo(cellInfo,j++,i,asset.getAssetname() == null ?"":asset.getAssetname().getAssetname(),asset)); sheet.addCell(getLabelInfo(cellInfo,j++,i,asset.getAssetname() == null ?"":asset.getAssetname().getAssetname(),asset));
sheet.addCell(getLabelInfo(cellInfo,j++,i,asset.getAssetname() == null || asset.getAssetname().getCategory() == null ?"":asset.getAssetname().getCategory().getAssetname(),asset)); sheet.addCell(getLabelInfo(cellInfo,j++,i,asset.getAssetname() == null || asset.getAssetname().getCategory() == null ?"":asset.getAssetname().getCategory().getAssetname(),asset));
sheet.addCell(getLabelInfo(cellInfo,j++,i,asset.getPrice() == null?"":asset.getPrice().toString(),asset)); sheet.addCell(getLabelInfo(cellInfo,j++,i,asset.getPrice() == null?"":asset.getPrice().toString(),asset));
sheet.addCell(new Label(j++, i, asset.getUser()==null?"":asset.getUser().getUsername())); sheet.addCell(new Label(j++, i, asset.getUser()==null?"":asset.getUser().getUsername()));
sheet.addCell(getLabelInfo(cellInfo,j++,i,asset.getPurchasedate() == null ?"":Tools.getCurrentMonth(asset.getPurchasedate()),asset)); sheet.addCell(getLabelInfo(cellInfo,j++,i,asset.getPurchasedate() == null ?"":Tools.getCurrentMonth(asset.getPurchasedate()),asset));
Short status = asset.getStatus(); Short status = asset.getStatus();
if(null == status) if(null == status)
status = 0 ; status = 0 ;
if(AssetConstants.BusinessForExcel.EXCEl_STATUS_ZAIKU == status) if(AssetConstants.BusinessForExcel.EXCEl_STATUS_ZAIKU == status)
sheet.addCell(new Label(j++, i, "在库")); sheet.addCell(new Label(j++, i, "在库"));
else if(AssetConstants.BusinessForExcel.EXCEl_STATUS_INUSE == status) else if(AssetConstants.BusinessForExcel.EXCEl_STATUS_INUSE == status)
sheet.addCell(new Label(j++, i, "在用")); sheet.addCell(new Label(j++, i, "在用"));
else if(AssetConstants.BusinessForExcel.EXCEl_STATUS_CONSUME == status) else if(AssetConstants.BusinessForExcel.EXCEl_STATUS_CONSUME == status)
sheet.addCell(new Label(j++, i, "消费")); sheet.addCell(new Label(j++, i, "消费"));
sheet.addCell(new Label(j++, i, asset.getLocation())); sheet.addCell(new Label(j++, i, asset.getLocation()));
sheet.addCell(new Label(j++, i, asset.getAssetnum())); sheet.addCell(new Label(j++, i, asset.getAssetnum()));
sheet.addCell(new Label(j++, i, asset.getSerialnum())); sheet.addCell(new Label(j++, i, asset.getSerialnum()));
sheet.addCell(getLabelInfo(cellInfo,j++,i, asset.getPeriodofvalidity() == null ?"":Tools.getCurrentMonth(asset.getPeriodofvalidity()),asset)); sheet.addCell(getLabelInfo(cellInfo,j++,i, asset.getPeriodofvalidity() == null ?"":Tools.getCurrentMonth(asset.getPeriodofvalidity()),asset));
sheet.addCell(getLabelInfo(cellInfo,j++,i,asset.getWarrantydate() == null ?"":Tools.getCurrentMonth(asset.getWarrantydate()),asset)); sheet.addCell(getLabelInfo(cellInfo,j++,i,asset.getWarrantydate() == null ?"":Tools.getCurrentMonth(asset.getWarrantydate()),asset));
sheet.addCell(new Label(j++, i, asset.getSupplier()==null?"":asset.getSupplier().getSupplier())); sheet.addCell(new Label(j++, i, asset.getSupplier()==null?"":asset.getSupplier().getSupplier()));
sheet.addCell(new Label(j++, i, asset.getLabels())); sheet.addCell(new Label(j++, i, asset.getLabels()));
sheet.addCell(new Label(j++, i, asset.getDescription())); sheet.addCell(new Label(j++, i, asset.getDescription()));
i++; i++;
} }
} }
workbook.write(); workbook.write();
workbook.close(); workbook.close();
} }
catch (Exception e) catch (Exception e)
{ {
Log.errorFileSync(">>>>>>>>>>>>>>>>>>>>>>>导出资产信息为excel表格异常", e); Log.errorFileSync(">>>>>>>>>>>>>>>>>>>>>>>导出资产信息为excel表格异常", e);
} }
} }
/** /**
* 根据错误信息进行提示--execel表格背景设置为红色,表示导入信息有误 * 根据错误信息进行提示--execel表格背景设置为红色,表示导入信息有误
* @param cellInfo * @param cellInfo
* @param cellNum * @param cellNum
* @param columnNum * @param columnNum
* @param value * @param value
* @return * @return
*/ */
private Label getLabelInfo(Map<Integer,String> cellInfo,int cellNum,int columnNum,String value,Asset asset) private Label getLabelInfo(Map<Integer,String> cellInfo,int cellNum,int columnNum,String value,Asset asset)
{ {
Label label = null; Label label = null;
//设置背景颜色 //设置背景颜色
WritableCellFormat cellFormat = new WritableCellFormat(); WritableCellFormat cellFormat = new WritableCellFormat();
try try
{ {
cellFormat.setBackground(Colour.RED); cellFormat.setBackground(Colour.RED);
} }
catch (WriteException e) catch (WriteException e)
{ {
Log.errorFileSync(">>>>>>>>>>>>>>>>>>>>>设置单元格背景颜色错误", e); Log.errorFileSync(">>>>>>>>>>>>>>>>>>>>>设置单元格背景颜色错误", e);
} }
if(null == cellInfo || cellInfo.size() == 0) if(null == cellInfo || cellInfo.size() == 0)
{ {
if(cellNum == AssetConstants.BusinessForExcel.EXCEL_ASSETNAME) if(cellNum == AssetConstants.BusinessForExcel.EXCEL_ASSETNAME)
{ {
if(null == asset.getAssetname() && null != asset.getAssetnameStr()) if(null == asset.getAssetname() && null != asset.getAssetnameStr())
label = new Label(cellNum, columnNum,asset.getAssetnameStr()); label = new Label(cellNum, columnNum,asset.getAssetnameStr());
else if(null != asset.getAssetname()) else if(null != asset.getAssetname())
label = new Label(cellNum, columnNum, value); label = new Label(cellNum, columnNum, value);
else else
label = new Label(cellNum, columnNum, null,cellFormat); label = new Label(cellNum, columnNum, null,cellFormat);
} }
else if(cellNum == AssetConstants.BusinessForExcel.EXCEL_CATEGORY) else if(cellNum == AssetConstants.BusinessForExcel.EXCEL_CATEGORY)
{ {
if(null != asset.getAssetnameStr() && null == asset.getAssetname()) if(null != asset.getAssetnameStr() && null == asset.getAssetname())
label = new Label(cellNum, columnNum, null,cellFormat); label = new Label(cellNum, columnNum, null,cellFormat);
else if(null == asset.getAssetnameStr() && null == asset.getAssetname() else if(null == asset.getAssetnameStr() && null == asset.getAssetname()
&& asset.getCategory() != null &&asset.getCategory().length()>0) && asset.getCategory() != null &&asset.getCategory().length()>0)
label = new Label(cellNum, columnNum, asset.getCategory()); label = new Label(cellNum, columnNum, asset.getCategory());
else else
label = new Label(cellNum, columnNum, value); label = new Label(cellNum, columnNum, value);
} }
else else
label = new Label(cellNum, columnNum, value); label = new Label(cellNum, columnNum, value);
} }
else else
{ {
//表示此单元格有错误 //表示此单元格有错误
if(cellInfo.containsKey(cellNum)) if(cellInfo.containsKey(cellNum))
{ {
if(cellNum == AssetConstants.BusinessForExcel.EXCEL_ASSETNAME) if(cellNum == AssetConstants.BusinessForExcel.EXCEL_ASSETNAME)
{ {
if(null == asset.getAssetname() && null != asset.getAssetnameStr()) if(null == asset.getAssetname() && null != asset.getAssetnameStr())
label = new Label(cellNum, columnNum,asset.getAssetnameStr()); label = new Label(cellNum, columnNum,asset.getAssetnameStr());
if(null != asset.getAssetname()) if(null != asset.getAssetname())
label = new Label(cellNum, columnNum,asset.getAssetname().getAssetname()); label = new Label(cellNum, columnNum,asset.getAssetname().getAssetname());
else else
label = new Label(cellNum, columnNum, value,cellFormat); label = new Label(cellNum, columnNum, value,cellFormat);
} }
else if(cellNum == AssetConstants.BusinessForExcel.EXCEL_CATEGORY) else if(cellNum == AssetConstants.BusinessForExcel.EXCEL_CATEGORY)
{ {
if(null != asset.getAssetnameStr() && null == asset.getAssetname()) if(null != asset.getAssetnameStr() && null == asset.getAssetname())
label = new Label(cellNum, columnNum, null,cellFormat); label = new Label(cellNum, columnNum, null,cellFormat);
else if(null == asset.getAssetnameStr() && null == asset.getAssetname() else if(null == asset.getAssetnameStr() && null == asset.getAssetname()
&& asset.getCategory() != null &&asset.getCategory().length()>0) && asset.getCategory() != null &&asset.getCategory().length()>0)
label = new Label(cellNum, columnNum, asset.getCategory()); label = new Label(cellNum, columnNum, asset.getCategory());
} }
else if(cellNum == AssetConstants.BusinessForExcel.EXCEL_PRICE) else if(cellNum == AssetConstants.BusinessForExcel.EXCEL_PRICE)
label = new Label(cellNum, columnNum,asset.getPriceStr(),cellFormat); label = new Label(cellNum, columnNum,asset.getPriceStr(),cellFormat);
else if(cellNum == AssetConstants.BusinessForExcel.EXCEL_PURCHASE_DATE) else if(cellNum == AssetConstants.BusinessForExcel.EXCEL_PURCHASE_DATE)
label = new Label(cellNum, columnNum,asset.getPurchasedateStr(),cellFormat); label = new Label(cellNum, columnNum,asset.getPurchasedateStr(),cellFormat);
else if(cellNum == AssetConstants.BusinessForExcel.EXCEL_WARRANTY_DATE) else if(cellNum == AssetConstants.BusinessForExcel.EXCEL_WARRANTY_DATE)
label = new Label(cellNum, columnNum,asset.getWarrantydateStr(),cellFormat); label = new Label(cellNum, columnNum,asset.getWarrantydateStr(),cellFormat);
else if(cellNum == AssetConstants.BusinessForExcel.EXCEL_EXPIRATION_DATE) else if(cellNum == AssetConstants.BusinessForExcel.EXCEL_EXPIRATION_DATE)
label = new Label(cellNum, columnNum,asset.getPeriodofvalidityStr(),cellFormat); label = new Label(cellNum, columnNum,asset.getPeriodofvalidityStr(),cellFormat);
else else
label = new Label(cellNum, columnNum, value,cellFormat); label = new Label(cellNum, columnNum, value,cellFormat);
} }
else else
{ {
if(null == asset.getAssetname() && null != asset.getAssetnameStr()&& cellNum == 0) if(null == asset.getAssetname() && null != asset.getAssetnameStr()&& cellNum == 0)
label = new Label(cellNum, columnNum,asset.getAssetnameStr()); label = new Label(cellNum, columnNum,asset.getAssetnameStr());
else if(null == asset.getAssetnameStr() && null == asset.getAssetname() else if(null == asset.getAssetnameStr() && null == asset.getAssetname()
&& asset.getCategory() != null &&asset.getCategory().length()>0&& cellNum == 1) && asset.getCategory() != null &&asset.getCategory().length()>0&& cellNum == 1)
label = new Label(cellNum, columnNum, asset.getCategory()); label = new Label(cellNum, columnNum, asset.getCategory());
else else
label = new Label(cellNum, columnNum, value); label = new Label(cellNum, columnNum, value);
} }
} }
return label; return label;
} }
/*=====================以下处理与业务无关的共用方法=================================*/ /*=====================以下处理与业务无关的共用方法=================================*/
public void setAssetDao(AssetIDAO assetDao) public void setAssetDao(AssetIDAO assetDao)
{ {
this.assetDao = assetDao; this.assetDao = assetDao;
} }
public void setAssetNameDao(AssetNameIDAO assetNameDao) public void setAssetNameDao(AssetNameIDAO assetNameDao)
{ {
this.assetNameDao = assetNameDao; this.assetNameDao = assetNameDao;
} }
public void setCategoryDao(CategoryIDAO categoryDao) public void setCategoryDao(CategoryIDAO categoryDao)
{ {
this.categoryDao = categoryDao; this.categoryDao = categoryDao;
} }
public void setSupplierDao(SupplierIDAO supplierDao) public void setSupplierDao(SupplierIDAO supplierDao)
{ {
this.supplierDao = supplierDao; this.supplierDao = supplierDao;
} }
public void setUserDao(UserIDAO userDao) public void setUserDao(UserIDAO userDao)
{ {
this.userDao = userDao; this.userDao = userDao;
} }
@Override @Override
protected Class<Asset> getEntityClass() protected Class<Asset> getEntityClass()
{ {
return Asset.class; return Asset.class;
} }
} }
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