Skip to content

Commit

Permalink
设备批量导入、申请
Browse files Browse the repository at this point in the history
  • Loading branch information
leopoldyang committed Mar 6, 2016
1 parent df469a8 commit ec01375
Show file tree
Hide file tree
Showing 97 changed files with 1,427 additions and 264 deletions.
5 changes: 5 additions & 0 deletions resource/spring-web.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,9 @@
<bean class="com.nuc.device.intercepter.LoginInterceptor"/>
</mvc:interceptor>
</mvc:interceptors>
<bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
<property name="maxUploadSize">
<value>5242880</value>
</property>
</bean>
</beans>
49 changes: 25 additions & 24 deletions resource/sql/apply_item_sql.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,20 +22,19 @@
</if>
</select>
<sql id="queryColumn">
select id as id,
item_no as itemNo,
dev_id as devId,
dev_unit as devUnit,
dev_num as devNum,
use_time as useTime,
direc_id as direcId,
dev_lab as devLab,
remark as remark,
create_time as createTime,
modify_time as modifyTime,
create_emp as createEmpId,
modify_time as mofifyEmpId,
apply_id as applyId
select item.id as id,
item.item_no as itemNo,
item.dev_id as devId,
item.dev_num as devNum,
item.apply_id as applyId,
dev.dev_no as devNo,
dev.dev_name as devName,
dev.model_no as modelNo,
dev.standard as standard,
cate.cate_name as cateName,
origin.dev_origin_name as originName,
direc.use_direc_name as direcName,
country.country_name as countryName
</sql>
<select id="queryApplyItemById" parameterType="long" resultType="applyItem">
<include refid="queryColumn"/>
Expand All @@ -46,11 +45,7 @@
INSERT INTO tb_scd_apply_item(
item_no,
dev_id,
dev_unit,
dev_num,
use_time,
direc_id,
dev_lab,
remark,
create_time,
modify_time,
Expand All @@ -59,12 +54,8 @@
apply_id
)VALUE (
#{itemNo},
#{devID},
#{devUnit},
#{devId},
#{devNum},
#{useTime},
#{direcId},
#{devLab},
#{remark},
now(),
now(),
Expand Down Expand Up @@ -100,10 +91,20 @@
where id=#{id}
</update>
<update id="delApplyItem" parameterType="applyItem">
UPDATE tb_scd_apply_itme SET
UPDATE tb_scd_apply_item SET
is_valid=0,
modify_emp=#{modifyEmpId},
modify_time=now()
WHERE id=#{id}
</update>
<select id="queryApplyItemByApplyId" parameterType="long" resultType="applyItem">
<include refid="queryColumn"/>
from tb_scd_apply_item item
LEFT JOIN tb_scd_dev dev ON item.dev_id=dev.id
left JOIN tb_scd_dev_category cate on dev.cate_id=cate.id
LEFT JOIN tb_scd_dev_origin origin on dev.origin_id=origin.id
LEFT JOIN tb_scd_dev_use_direc direc on dev.direc_id=direc.id
LEFT JOIN tb_scd_dev_country country on dev.country_id=country.id
where item.apply_id=#{value}
</select>
</mapper>
34 changes: 19 additions & 15 deletions resource/sql/apply_sql.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@
<if test="applyEmpId!=0">
and apply_emp=#{applyEmpId}
</if>
<if test="status!=0">
<if test="status!=null">
and status=#{status}
</if>
<if test="dealEmpId!=0">
<if test="dealEmpId!=null">
and deal_emp=#{dealEmpId}
</if>
<if test="applyTime!=null">
Expand All @@ -31,33 +31,39 @@
<update id="updateApply" parameterType="apply">
UPDATE tb_scd_apply SET
<if test="status!=null">
status=#{status}
status=#{status},
</if>
<if test="dealEmpId!=null">
deal_emp=#{dealEmpId}
</if>
<if test="backTime!=null">
back_time=#{backTime}
deal_emp=#{dealEmpId},
</if>
<if test="dealTime!=null">
deal_time=#{dealTime}
deal_time=#{dealTime},
</if>
<if test="remark!=null">
remark=#{remark}
<if test="remark!=''">
remark=#{remark},
</if>
</if>
<if test="dealText!=null">
deal_text=#{dealText}
<if test="remark!=''">
deal_text=#{dealText},
</if>
</if>
<if test="applyText!=null">
apply_text=#{applyText}
<if test="remark!=''">
apply_text=#{applyText},
</if>
</if>
<if test="modifyEmpId!=null">
modify_emp=#{modifyEmp}
modify_emp=#{modifyEmpId},
</if>
modify_time=now()
WHERE id=#{id}
</update>
<insert id="insetApply" parameterType="apply">
<selectKey keyProperty="id" resultType="long">
select LAST_INSERT_ID()
</selectKey>
INSERT INTO tb_scd_apply(
apply_no,
apply_emp,
Expand All @@ -66,7 +72,6 @@
remark,
apply_time,
deal_time,
back_time,
create_time,
modify_time,
create_emp,
Expand All @@ -79,9 +84,8 @@
#{status},
#{dealEmpId},
#{remark},
#{applyTime},
now(),
#{dealTime},
#{backTime},
now(),
now(),
#{createEmpId},
Expand Down
4 changes: 0 additions & 4 deletions src/com/nuc/device/base/poi/ExportExcel.java
Original file line number Diff line number Diff line change
@@ -1,16 +1,12 @@
package com.nuc.device.base.poi;

import com.alibaba.fastjson.JSON;
import com.nuc.device.base.poi.bean.ExcelColumnBean;
import com.nuc.device.base.poi.util.PoiCommonUtils;
import org.apache.log4j.Logger;
import org.apache.poi.hssf.usermodel.*;
import org.apache.poi.hssf.util.HSSFColor;

import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.lang.reflect.InvocationTargetException;
import java.util.Collection;
import java.util.List;

/**
Expand Down
82 changes: 82 additions & 0 deletions src/com/nuc/device/base/poi/ImportExcel.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
package com.nuc.device.base.poi;

import com.nuc.device.base.poi.bean.ExcelColumnBean;
import com.nuc.device.base.poi.util.PoiCommonUtils;
import org.apache.poi.hssf.usermodel.HSSFRow;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.poifs.filesystem.POIFSFileSystem;

import java.io.IOException;
import java.io.InputStream;
import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList;
import java.util.List;

/**
* Created by IDEA
* User:Leopold
* Email:[email protected]
* Date:2016/3/6
* Time:5:46
*/
public class ImportExcel<T> {
private HSSFWorkbook workbook;
private List<ExcelColumnBean> list;
private Class beanClass;
public ImportExcel(){}
public ImportExcel(InputStream inputStream,Class beanClass){
try {
this.workbook=new HSSFWorkbook(new POIFSFileSystem(inputStream));
this.list= PoiCommonUtils.getColumnBeanList(beanClass);
this.beanClass=beanClass;
} catch (IOException e) {
e.printStackTrace();
}
}
public String checkExcel(){
String result="success";
if(workbook==null){
return "上传文件为空!";
}
HSSFSheet sheet=workbook.getSheetAt(0);
HSSFRow row=sheet.getRow(0);
for(int i=0;i<list.size();i++){
if(!row.getCell(i).getStringCellValue().equals(list.get(i).getColumnName())){
return "sheet中列名与要求不匹配!";
}
}
return result;
}
public List<T> excelToList(){
List reList=new ArrayList();
try {
HSSFSheet sheet=workbook.getSheetAt(0);
HSSFRow row;
int count=1;
boolean flag=sheet.getRow(count)==null?false:true;
while (flag){
Object obj=beanClass.newInstance();
row=sheet.getRow(count);
if(row!=null){
for(int i=0;i<list.size();i++){
ExcelColumnBean columnBean=list.get(i);
Object value=PoiCommonUtils.parseType(columnBean.getColumnField().getType(), row.getCell(i).getStringCellValue());
columnBean.getSetterMethod().invoke(obj, value);
}
reList.add(obj);
count++;
}else {
flag=false;
}
}
} catch (InstantiationException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
} catch (InvocationTargetException e) {
e.printStackTrace();
}
return reList;
}
}
43 changes: 13 additions & 30 deletions src/com/nuc/device/base/poi/util/PoiCommonUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@
import java.io.IOException;
import java.io.InputStream;
import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.util.Calendar;
import java.util.Date;
import java.util.ArrayList;
import java.util.List;

Expand Down Expand Up @@ -61,36 +64,16 @@ private static String getMethodName(String prefix,Field field){
field.getName().substring(1);
}

/**
* 校验导入的excel
* @param is
* @param beanClass
* @return
*/
public static String checkExcel(InputStream is,Class beanClass){
String result="success";
if(is==null){
return "上传文件为空!";
}
List<ExcelColumnBean> list=getColumnBeanList(beanClass);
try {
HSSFWorkbook workbook=new HSSFWorkbook(new POIFSFileSystem(is));
HSSFSheet sheet=workbook.getSheetAt(0);
if(sheet.getTopRow()<=1){
return "sheet中行数不足!";
}
if(list.size()!=sheet.getFirstRowNum()){
return "标题列数与要求不匹配!";
}
HSSFRow row=sheet.getRow(0);
for(int i=0;i<list.size();i++){
if(!row.getCell(i).getStringCellValue().equals(list.get(i).getColumnName())){
return "sheet中列名与要求不匹配!";
}
}
} catch (IOException e) {
e.printStackTrace();
public static Object parseType(Class type,String value){
if(type.equals(String.class)){
return value;
}else if(type.equals(Double.class)){
return Double.parseDouble(value);
}else if(type.equals(Integer.class)){
return Integer.parseInt(value);
}else if(type.equals(Date.class)){
return new Date(value);
}
return result;
return null;
}
}
21 changes: 6 additions & 15 deletions src/com/nuc/device/bean/Apply.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,27 +19,18 @@ public class Apply extends BaseBean {
public static final String APPLY_LOAN="已借出";
public static final String APPLY_BACK="已归还";
public static final String APPLY_REFUSE="已拒绝";
@ExcelColumnName(value = "申请编号")
private String applyNo;//申请编号
private long applyEmpId;//申请人id
@ExcelColumnName(value = "申请人姓名")
private String applyEmpName;//申请人姓名
@ExcelColumnName(value = "申请状态")
private int status;//申请状态
private long dealEmpId;//处理人id
@ExcelColumnName(value = "处理人姓名")
private Integer status;//申请状态
private Long dealEmpId;//处理人id
private String dealEmpName;//处理人姓名
@ExcelColumnName(value = "备注")
private String remark;//备注
@JSONField(format = "yyyy-MM-dd HH:mm")
@ExcelColumnName(value = "申请时间")
private Date applyTime;//申请时间
@JSONField(format = "yyyy-MM-dd HH:mm")
@ExcelColumnName(value = "处理时间")
private Date dealTime;//处理时间
@ExcelColumnName(value = "申请理由")
private String applyText;//申请理由
@ExcelColumnName(value = "处理意见")
private String dealText;//处理意见
private String statusDesc;//申请状态描述
public String getApplyNo() {
Expand All @@ -66,11 +57,11 @@ public void setApplyEmpName(String applyEmpName) {
this.applyEmpName = applyEmpName;
}

public int getStatus() {
public Integer getStatus() {
return status;
}

public void setStatus(int status) {
public void setStatus(Integer status) {
switch (status){
case 1:this.setStatusDesc(APPLY_ING);
break;
Expand All @@ -87,11 +78,11 @@ public void setStatus(int status) {
this.status = status;
}

public long getDealEmpId() {
public Long getDealEmpId() {
return dealEmpId;
}

public void setDealEmpId(long dealEmpId) {
public void setDealEmpId(Long dealEmpId) {
this.dealEmpId = dealEmpId;
}

Expand Down
Loading

0 comments on commit ec01375

Please sign in to comment.