您的位置:首页 > 编程语言 > Java开发

java导入excel数据内容存入数据库

2017-08-29 10:26 771 查看
示例:导入案件,excel

controller方法:

/**
*
* @param file
* @param batch
* @param request
* @param model
* @param attr
* @param response
* @return
* @throws InterruptedException
* @throws InstantiationException
* @throws IllegalAccessException
* @throws IllegalArgumentException
* @throws ParseException
* @throws ClassNotFoundException
*/
@RequestMapping(value = "/caseadd", method = RequestMethod.POST)
public String caseadd(@RequestParam MultipartFile file, Batch batch, HttpServletRequest request, Model model,
RedirectAttributes attr, HttpServletResponse response) throws InterruptedException, InstantiationException,
IllegalAccessException, IllegalArgumentException, ParseException, ClassNotFoundException {
Result result = new Result();
Integer id = batch.getId();
try {
HttpSession session = request.getSession();
Object obj = session.getAttribute("user");
String companyid = SessionUtil.getCompnayCodeFromSessionByCuishouAdminOrUser(session);
if (companyid != null) {
// 通过传入CuishouCode 来判断数据库是否存在此用户的表
templateService.createcuishoutable(companyid, batch.getBankcode());
}
// 查询案件批次完整信息
List<Batch> prebats = batchService.selectByExample(batch);
batch = prebats.get(0);
Integer batchid = batch.getId();

// 导入案件的合同的Id
Integer contractid = batch.getContractid();
String batchcode = batch.getBatchcode();

// 查询已有案件的caseId
CaseHead condition = new CaseHead();
condition.setBatchid(String.valueOf(batchid));
List<CaseHead> preheadlist = caseHeadService.selectByExample(condition, companyid);

String precaseId = null;
if (preheadlist != null && preheadlist.size() > 0) {
int size = preheadlist.size();
precaseId = preheadlist.get(size - 1).getCaseid();
}

String biztype = batch.getBiztype();
String bankcode = batch.getBankcode();
Date wtdate = batch.getWtdate();
Date wtenddate = batch.getWtenddate();

ContractHead contractHead = null;
if (contractid != null) {
contractHead = contractHeadService.selectByPrimaryKey(contractid);
}

// 通过银行code和业务类型 查询模板 ,解析文件存入
Batch batchStatistics = null;
if (batchid != null && biztype != null && companyid != null) {
batchStatistics = excelUploadService.cuishouSaveCaseBatchData(batchcode, wtdate, wtenddate,
String.valueOf(batchid), precaseId, biztype, bankcode, contractHead, companyid, file,
contractLineService, 0);
}

// 检验标记共案和还款
/*excelUploadService.markSameCaseAndRepayment(batchStatistics.getDoccodeList(),
batchStatistics.getDoccodeCompanycode(),batchStatistics.getBiztype(),batchStatistics.getBankcode());
*/
Integer curnum = null;
Double curmoney = null;
if (batchStatistics != null) {
curnum = batchStatistics.getTotalcount();
curmoney = batchStatistics.getTotalbase();
}
// 填充案件数量及金额
if (batchStatistics != null && prebats != null && prebats.size() != 0) {
Batch batch2 = prebats.get(0);
Double totalbase1 = batch2.getTotalbase() == null ? 0d : batch2.getTotalbase();
Integer totalcount1 = batch2.getTotalcount() == null ? 0 : batch2.getTotalcount();
batchStatistics.setTotalbase(batchStatistics.getTotalbase() + totalbase1);
batchStatistics.setTotalcount(batchStatistics.getTotalcount() + totalcount1);
}
// 更新t_batch表数据 总金额
Batch upexample = new Batch();
upexample.setId(batchid);
if (batchStatistics != null) {
batchService.updateByExampleSelective(batchStatistics, upexample);
}
result.setStatus(200);

DecimalFormat df = new DecimalFormat("#.00");
String remoney = df.format(curmoney);
result.setResult("成功导入案件数量:" + curnum + ",案件总金额:" + remoney + "元!");
} catch (Exception e) {
if (e instanceof ContractLineComplicatedException || e instanceof HandCodeMisMatchingException
|| e instanceof NoContractLineException || e instanceof IllegalUploadParamException
|| e instanceof CodeTypeUnMatchException || e instanceof ExcelLineException) {

result.setStatus(500);
result.setResult(e.getMessage());
} else {
result.setStatus(500);
String mes = e.getMessage();
Throwable cause = e.getCause();
while (cause != null) {
mes = cause.getMessage();
cause = cause.getCause();
}
if (mes != null) {
mes = mes.replaceAll("\"", "");
mes = mes.replaceAll("\'", "");
result.setResult(mes.toString());
} else {
result.setResult("数据有误,请重试");
}
}
e.printStackTrace();
}
attr.addFlashAttribute("mes", JSON.toJSONString(result));

return "redirect:/bat/tocaseadd?id=" + id;
}


impl方法:

11d40

@Override
public Batch cuishouSaveCaseBatchData(final String batchcode, final Date wtdate, final Date wtenddate,
final String batchid, final String preCaseId, final String biztype, final String bankcode,
final ContractHead contractHead, final String companyid, MultipartFile file,
ContractLineService contractLineService, final Integer tabletype) throws Exception {
Template templateDate = templateMapper.findtemplateDate(biztype, bankcode);
Batch statistic = null;
final String company = companyid.toLowerCase();

List<String> excelHead = ExcelReader.findExcelHead(file);//解析excel表头

int noEmptyCount = 0;

if (excelHead.size() > 0) {
for (String str : excelHead) {
if (str != null && !"".equals(str.trim())) {
noEmptyCount++;
}

}
if (noEmptyCount != templateDate.getColno()) {
throw new CodeTypeUnMatchException("导入Excel文件第一行非空列数与对应模板列数(模板列为存入数据库的导入模板表头json字符串)不一致,导入文件第一行非空列数: "+noEmptyCount+", 模板列数: "+templateDate.getColno()+", 请检查数据或模板");
}
}

int allCounts = ExcelReader.readExcelRowCounts(file);
if(allCounts == 0){
throw new ExcelLineException("请选择非空的Excel数据表");
} else if(allCounts > 501){
throw new ExcelLineException("导入数据最大行数限制500, 请分多次导入");
}

// 获取excel数据
List<List<String>> datas = ExcelReader.findExcelData(file);

List<Integer> indexls = null;
if (templateDate != null && datas != null) {
String template = templateDate.getTemplate();
List<ColumnTem> list = JSON.parseArray(template, ColumnTem.class);

// 获取CaseContact的List<List<CaseContact>>
int s = list.size();
// 存储CaseContact位置的List
indexls = new ArrayList<>();
for (int i = 0; i < s; i++) {
ColumnTem inColumn = list.get(i);
String word = inColumn.getWord();
if ("contactname".equals(word)) {
indexls.add(i);
}
}

// 生成模板数组
String[] exceltemplate = new String[list.size()];
for (int i = 0; i < list.size(); i++) {
ColumnTem columnTem = list.get(i);
exceltemplate[i] = columnTem.getWord();
}

// 生成回调保存Head实现类
ExcleUtil.AbstractExcleInput<CaseHead> head = new ExcleUtil.AbstractExcleInput<CaseHead>() {
@Override
public void excute(CaseHead t) {
t.setCommdate(wtdate);
t.setTjDate(wtenddate);
t.setBatchid(batchid);
t.setBankid(bankcode);
t.setBiztype(biztype);
t.setCompanycode(companyid);
caseHeadMapper.insertSelective(t, company);
}
};

// 生成回调保存Detail实现类
ExcleUtil.AbstractExcleInput<CaseDetail> detail = new ExcleUtil.AbstractExcleInput<CaseDetail>() {
@Override
public void excute(CaseDetail t) {
if (contractHead != null) {
t.setContractid(contractHead.getId());
}
caseDetailMapper.insertSelective(t, company);
}
};

// 生成回调插入doccode table中间表
ExcleUtil.AbstractExcleInput<CaseTable> table = new ExcleUtil.AbstractExcleInput<CaseTable>() {

@Override
public void excute(CaseTable t) {
t.setCompanycode(companyid);
t.setType(tabletype);
CaseTable example = new CaseTable();
if (t != null) {
example.setDoccode(t.getDoccode());
example.setCompanycode(t.getCompanycode());
}
Integer count = caseTableServiceImpl.queryCountByWhere(example);
if (count == null || count == 0) {
caseTableServiceImpl.saveSelective(t);
}

}

};

// 生成回调保存Contact实现类
ExcleUtil.AbstractExcleInput<CaseContact> contact = new ExcleUtil.AbstractExcleInput<CaseContact>() {
@Override
public void excute(CaseContact t) {
t.setBankcode(bankcode);
CaseContact copy = null;
try {
copy = (CaseContact) t.clone();
} catch (CloneNotSupportedException e) {
throw new RuntimeException("CaseContact失败");
}
copy.setBankcode(null);
copy.setCaseid(null);
Integer count = caseContactService.queryCountByWhere(copy);
if (count == null || count == 0) {
if(t.getInfo() == null || "".equals(t.getInfo())){
//0-未验证   1-无效      2-有效
t.setFake(1);
}
caseContactService.saveSelective(t);
}
}
};

// String bankcode,String preCaseId, Integer contractHeadId
ExcleUtil util = new ExcleUtil(contractLineService, datas, indexls, exceltemplate, head, detail, table,
contact);
statistic = util.CaseStatistic();
List<SameCase> listDoccode=util.excute(batchcode, bankcode, preCaseId, contractHead);
statistic.setDoccodeList(listDoccode);//身份证号码
statistic.setDoccodeCompanycode(companyid);//银行编码
statistic.setBiztype(biztype); //业务类别
statistic.setBankcode(bankcode);//客户bankcode
}
return statistic;

}


解析excel的ExcelReader类

package org.uz.dxt.util;

import java.io.IOException;
import java.io.InputStream;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import org.apache.poi.hssf.usermodel.HSSFCell;
import org.apache.poi.hssf.usermodel.HSSFDateUtil;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.springframework.web.multipart.MultipartFile;

public class ExcelReader {
private Workbook wb;
private Sheet sheet;
private Row row;

/**
* 读取Excel表格表头的内容
*
* @param InputStream
* @return String 表头内容的数组
*/
public String[] readExcelTitle(InputStream is, boolean isXlsx) {
try {
// fs = new POIFSFileSystem(is);
if (isXlsx) {
wb = new XSSFWorkbook(is);
} else {
wb = new HSSFWorkbook(is);
}
} catch (IOException e) {
e.printStackTrace();
}
sheet = wb.getSheetAt(0);
row = sheet.getRow(0);
// 标题总列数
int colNum = row.getPhysicalNumberOfCells();
System.out.println("colNum:" + colNum);
String[] title = new String[colNum];
for (int i = 0; i < colNum; i++) {
title[i] = getCellFormatValue(row.getCell(i));
}
return title;
}

/**
* 读取Excel数据内容
*
* @param InputStream
* @return Map 包含单元格数据内容的Map对象
*/
public List<List<String>> readExcelContent(InputStream is, boolean isXlsx) {
List<List<String>> content = new ArrayList<List<String>>();
Workbook wb = null;
try {
// fs = new POIFSFileSystem(is);
if (isXlsx) {
wb = new XSSFWorkbook(is);
} else {
wb = new HSSFWorkbook(is);
}
} catch (IOException e) {
e.printStackTrace();
}
sheet = wb.getSheetAt(0);
// 得到总行数
int rowNum = sheet.getLastRowNum();
row = sheet.getRow(0);
int colNum = row.getPhysicalNumberOfCells();
// 正文内容应该从第二行开始,第一行为表头的标题
for (int i = 1; i <= rowNum; i++) {
List<String> list = new ArrayList<String>();
row = sheet.getRow(i);
// 判断某一行是否全部为空
if (row == null) {
continue;
}
boolean isNull = true;

for (int k = 0; k < colNum; k++) {
String value = getCellFormatValueNew(row.getCell(k)).trim();
if (!"".equals(value)) {
isNull = false;
break;
}
}
if (isNull) {
continue;
}

for (int j = 0; j < colNum; j++) {
list.add(getCellFormatValueNew(row.getCell(j)).trim());
}
content.add(list);
}
return content;
}

public List<String> readExcelHead(InputStream is, boolean isXlsx) {
List<List<String>> content = new ArrayList<List<String>>();
Workbook wb = null;
try {
// fs = new POIFSFileSystem(is);
if (isXlsx) {
wb = new XSSFWorkbook(is);
} else {
wb = new HSSFWorkbook(is);
}
} catch (IOException e) {
e.printStackTrace();
}
sheet = wb.getSheetAt(0);
// 得到总行数
row = sheet.getRow(0);
int colNum = row.getPhysicalNumberOfCells();
// 正文内容应该从第二行开始,第一行为表头的标题
List<String> list = new ArrayList<String>();
// 判断某一行是否全部为空

for (int j = 0; j < colNum; j++) {
list.add(getCellFormatValueNew(row.getCell(j)).trim());
}
return list;
}

/**
* 读取Excel数据内容
*
* @param InputStream
* @return Map 包含单元格数据内容的Map对象
* @throws IOException
*/
public List<List<String>> readExcelContentNew(InputStream is, boolean isXlsx) throws IOException {
List<List<String>> result = new ArrayList<List<String>>();
Workbook book = new HSSFWorkbook(is);
Sheet sheet = book.getSheetAt(0);
// 遍历行
int rows = sheet.getLastRowNum();
for (int i = 1; i < rows; i++) {
List<String> rowData = new ArrayList<String>();
Row row = sheet.getRow(i);
if (row != null) {
int cols = row.getLastCellNum();
for (int j = 0; j < cols; j++) {
Cell cell = row.getCell(j);
String data = getCellFormatValueNew(cell);
rowData.add(data);
}
}
result.add(rowData);
}
return result;
}

/**
* 获取单元格数据内容为字符串类型的数据
*
* @param cell
* Excel单元格
* @return String 单元格数据内容
*/
private String getStringCellValue(Cell cell) {
String strCell = "";
switch (cell.getCellType()) {
case HSSFCell.CELL_TYPE_STRING:
strCell = cell.getStringCellValue();
break;
case HSSFCell.CELL_TYPE_NUMERIC:
strCell = String.valueOf(cell.getNumericCellValue());
break;
case HSSFCell.CELL_TYPE_BOOLEAN:
strCell = String.valueOf(cell.getBooleanCellValue());
break;
case HSSFCell.CELL_TYPE_BLANK:
strCell = "";
break;
default:
strCell = "";
break;
}
if (strCell.equals("") || strCell == null || cell == null) {
return "";
}
return strCell;
}

/**
* 获取单元格数据内容为日期类型的数据
*
* @param cell
* Excel单元格
* @return String 单元格数据内容
*/
@SuppressWarnings({ "deprecation", "unused" })
private String getDateCellValue(Cell cell) {
String result = "";
try {
int cellType = cell.getCellType();
if (cellType == HSSFCell.CELL_TYPE_NUMERIC) {
Date date = cell.getDateCellValue();
result = (date.getYear() + 1900) + "-" + (date.getMonth() + 1) + "-" + date.getDate();
} else if (cellType == HSSFCell.CELL_TYPE_STRING) {
String date = getStringCellValue(cell);
result = date.replaceAll("[年月]", "-").replace("日", "").trim();
} else if (cellType == HSSFCell.CELL_TYPE_BLANK) {
result = "";
}
} catch (Exception e) {
System.out.println("日期格式不正确!");
e.printStackTrace();
}
return result;
}

/**
* 根据HSSFCell类型设置数据
*
* @param cell
* @return
*/
private String getCellFormatValue(Cell cell) {
String cellvalue = "";
if (cell != null) {
// 判断当前Cell的Type
switch (cell.getCellType()) {
// 如果当前Cell的Type为NUMERIC
case HSSFCell.CELL_TYPE_NUMERIC:
case HSSFCell.CELL_TYPE_FORMULA: {
// 判断当前的cell是否为Date
if (HSSFDateUtil.isCellDateFormatted(cell)) {
// 如果是Date类型则,转化为Data格式

// 方法1:这样子的data格式是带时分秒的:2011-10-12 0:00:00
// cellvalue = cell.getDateCellValue().toLocaleString();

// 方法2:这样子的data格式是不带带时分秒的:2011-10-12
Date date = cell.getDateCellValue();
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
cellvalue = sdf.format(date);

}
// 如果是纯数字
else {
// 取得当前Cell的数值
cellvalue = String.valueOf(cell.getNumericCellValue());
}
break;
}
// 如果当前Cell的Type为STRIN
case HSSFCell.CELL_TYPE_STRING:
// 取得当前的Cell字符串
cellvalue = cell.getRichStringCellValue().getString();
break;
// 默认的Cell值
default:
cellvalue = " ";
}
} else {
cellvalue = "";
}
return cellvalue;
}

private String getCellFormatValueNew(Cell cell) {

if (null != cell) {
switch (cell.getCellType()) {
case HSSFCell.CELL_TYPE_NUMERIC:
case HSSFCell.CELL_TYPE_FORMULA: { // 公式
if (HSSFDateUtil.isCellDateFormatted(cell)) {
// 方法2:这样子的data格式是不带带时分秒的:2011-10-12
Date date = cell.getDateCellValue();
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
return sdf.format(date);
} else {
cell.setCellType(1);
}
}
case HSSFCell.CELL_TYPE_STRING: // 字符串
return String.valueOf(cell.getStringCellValue());
case HSSFCell.CELL_TYPE_BOOLEAN: // Boolean
return String.valueOf(cell.getBooleanCellValue());

case HSSFCell.CELL_TYPE_BLANK: // 空值
return "";
default:
return "";
}
} else {
return "";
}

}

public static List<List<String>> findExcelData(MultipartFile file) {

try {
// 读取
InputStream is = file.getInputStream();
String fileName = file.getOriginalFilename();
ExcelReader excelReader = new ExcelReader();

if (fileName.matches("^.+\\.(?i)((xls)|(xlsx))$")) {
// 对读取Excel表格内容测试
boolean is03Excel = fileName.matches("^.+\\.(?i)(xls)$");
List<List<String>> list = excelReader.readExcelContent(is, !is03Excel);

if (list.size() < 1) {
return null;
}
return list;
}

} catch (Exception e) {
e.printStackTrace();
}
return null;
}

public static List<String> findExcelHead(MultipartFile file) {

try {
// 读取
InputStream is = file.getInputStream();
String fileName = file.getOriginalFilename();
ExcelReader excelReader = new ExcelReader();

if (fileName.matches("^.+\\.(?i)((xls)|(xlsx))$")) {
// 对读取Excel表格内容测试
boolean is03Excel = fileName.matches("^.+\\.(?i)(xls)$");
List<String> list = excelReader.readExcelHead(is, !is03Excel);

if (list.size() < 1) {
return null;
}
return list;
}

} catch (Exception e) {
e.printStackTrace();
}
return null;
}

public static int readExcelRowCounts(MultipartFile file) {

InputStream is = null;
try {
is = file.getInputStream();
} catch (IOException e1) {
e1.printStackTrace();
}
String fileName = file.getOriginalFilename();
ExcelReader excelReader = new ExcelReader();

int rowNum = 0;

if (fileName.matches("^.+\\.(?i)((xls)|(xlsx))$")) {
// 对读取Excel表格内容测试
boolean is03Excel = fileName.matches("^.+\\.(?i)(xls)$");

Workbook wb = null;
try {
// fs = new POIFSFileSystem(is);
if (!is03Excel) {
wb = new XSSFWorkbook(is);
} else {
wb = new HSSFWorkbook(is);
}
} catch (IOException e) {
e.printStackTrace();
}
Sheet sheetAt = wb.getSheetAt(0);
// 得到总行数
rowNum = sheetAt.getLastRowNum();

}

return rowNum;
}

}


util.excute实现插入数据库

//催收公司导入案件
public List<SameCase> excute(String batchcode, String bankcode,String preCaseId, ContractHead contractHead) throws Exception {
List<SameCase> listDoccode=new ArrayList<SameCase>();

String caseId=null;
String handCode =null;
// 遍历数据
for (int i = 0; i < datas.size(); i++) {
SameCase sameCase=new SameCase();
// 一行数据 对应一个对象
List<String> list = datas.get(i);
int listSize = list.size();
//初始化手别、caseid
for(AbstractExcleInput excleInterface: excleInters){
Class preclazz = ReflectionUtils.getSuperClassGenricType(excleInterface.getClass());
Object p = preclazz.newInstance();
Map<Integer, Field> hasFields=map.get(preclazz.getName());
if(p instanceof CaseHead){
for (int j = 0; j < listSize; j++) {
if (hasFields != null && hasFields.containsKey(j)) {
String column = list.get(j);
if("".equals(column.trim()) || column==null){
continue;
}
Field field = hasFields.get(j);
field.setAccessible(true);
field.set(p, changeValueType(column, field));
}
}
//生成手别
handCode = GenerateHandCode((CaseHead)p, contractHead);
if(handCode == null){
throw new RuntimeException("手别未定义");
}
//根据 手别 和 preCaseId 生成CaseId
if(bankcode!= null && handCode!=null){
//caseId = GenerateCaseIdNew(preCaseId,bankcode,i,handCode,batchcode);
caseId = GenerateCaseId(preCaseId,bankcode,i,handCode,batchcode);
}
}

}

List<CaseContact> contacts = new ArrayList<>();
String client = null;//债务人名字
String getdoccode = null;
for(AbstractExcleInput excleInterface: excleInters){
Class clazz = ReflectionUtils.getSuperClassGenricType(excleInterface.getClass());
Object t=clazz.newInstance();
Map<Integer, Field> hasFields=map.get(clazz.getName());

//拿到数据
//                if(hasFields==null) continue;
if(!(t instanceof CaseContact)){
for (int j = 0; j < listSize; j++) {
if(hasFields != null){
if (hasFields.containsKey(j)) {
//一行数据
String column = list.get(j);
Field field = hasFields.get(j);
field.setAccessible(true);
field.set(t, changeValueType(column, field));
if(t instanceof CaseHead){
String fieldname = field.getName();
if("doccode".equals(fieldname)){
String doc = (String) field.get(t);
getdoccode = doc;
}
if("client".equals(fieldname)){
client = (String) field.get(t);
}

}
//private String contacttype;//0-电话   1-邮件   2-QQ 3-Weixin 4-地址
if(t instanceof CaseDetail){
String fieldname = field.getName();
switch (fieldname) {
//电话
case "phoneSelf1":{
if(fieldname.equals("phoneSelf1")){
CaseContact contact = new CaseContact();
contact.setRelation("本人");
contact.setClient(client);
contact.setInfo(list.get(j));
contact.setContacttype("0");
contact.setCaseid(caseId);
contact.setDoccode(getdoccode);
contacts.add(contact);
}
};
case "phoneSelf2":{
if(fieldname.equals("phoneSelf2")){
CaseContact contact = new CaseContact();
contact.setRelation("本人");
contact.setClient(client);
contact.setInfo(list.get(j));
contact.setContacttype("0");
contact.setCaseid(caseId);
contact.setDoccode(getdoccode);
contacts.add(contact);
}
};
case "phoneHome":{
if(fieldname.equals("phoneHome")){
CaseContact contact = new CaseContact();
contact.setRelation("本人家庭");
contact.setClient(client);
contact.setInfo(list.get(j));
contact.setContacttype("0");
contact.setCaseid(caseId);
contact.setDoccode(getdoccode);
contacts.add(contact);
}
};
case "phoneOffice":{
if(fieldname.equals("phoneOffice")){

CaseContact contact = new CaseContact();
contact.setRelation("本人办公");
contact.setClient(client);
contact.setInfo(list.get(j));
contact.setContacttype("0");
contact.setCaseid(caseId);
contact.setDoccode(getdoccode);
contacts.add(contact);
}
};
//地址类
case "addr":{
if(fieldname.equals("addr")){

CaseContact contact = new CaseContact();
contact.setRelation("本人户籍");
contact.setClient(client);
contact.setInfo(list.get(j));
contact.setContacttype("4");
contact.setCaseid(caseId);
contact.setDoccode(getdoccode);
contacts.add(contact);
}
};
case "homeaddr":{
if(fieldname.equals("homeaddr")){

CaseContact contact = new CaseContact();
contact.setRelation("本人居住");
contact.setClient(client);
contact.setInfo(list.get(j));
contact.setContacttype("4");
contact.setCaseid(caseId);
contact.setDoccode(getdoccode);
contacts.add(contact);
}
};
case "unit":{
if(fieldname.equals("unit")){

CaseContact contact = new CaseContact();
contact.setRelation("本人单位");
contact.setClient(client);
contact.setInfo(list.get(j));
contact.setContacttype("4");
contact.setCaseid(caseId);
contact.setDoccode(getdoccode);
contacts.add(contact);
}
};
case "addrUnit":{
if(fieldname.equals("addrUnit")){

CaseContact contact = new CaseContact();
contact.setRelation("本人单位");
contact.setClient(client);
contact.setInfo(list.get(j));
contact.setContacttype("4");
contact.setCaseid(caseId);
contact.setDoccode(getdoccode);
contacts.add(contact);
}
};
//邮箱
case "email":{
if(fieldname.equals("email")){

CaseContact contact = new CaseContact();
contact.setRelation("本人");
contact.setClient(client);
contact.setInfo(list.get(j));
contact.setContacttype("1");
contact.setCaseid(caseId);
contact.setDoccode(getdoccode);
contacts.add(contact);
}
};
//QQ
case "qq":{
if(fieldname.equals("qq")){

CaseContact contact = new CaseContact();
contact.setRelation("本人");
contact.setClient(client);
contact.setInfo(list.get(j));
contact.setContacttype("2");
contact.setCaseid(caseId);
contact.setDoccode(getdoccode);
contacts.add(contact);
}
};
//weixin
case "weixin":{
if(fieldname.equals("weixin")){

CaseContact contact = new CaseContact();
contact.setRelation("本人");
contact.setClient(client);
contact.setInfo(list.get(j));
contact.setContacttype("3");
contact.setCaseid(caseId);
contact.setDoccode(getdoccode);
contacts.add(contact);
}
};

}

}

}
}

}
}

if(t instanceof CaseContact){
//非本人联系方式List<Contact>
if(indexls != null && indexls.size() != 0){
int ms = indexls.size();
Integer target = null;
for (int m = 0; m < ms; m++) {
target = indexls.get(m);
Class contactClazz = Class.forName("org.uz.dxt.model.common.CaseContact");
CaseContact contact = (CaseContact) contactClazz.newInstance();
Field[] fields = contactClazz.getDeclaredFields();

for (int k = 0; k < fields.length; k++) {
Field field = fields[k];
field.setAccessible(true);
//放入CaseContact数据
String name = field.getName();
//联系方式模板字段数量
if("contactname".equals(name)){
field.set(contact, changeValueType(list.get(target), field));
} else if("relation".equals(name)){
field.set(contact, changeValueType(list.get(target+1), field));
} else if("info".equals(name)){
field.set(contact, changeValueType(list.get(target+2), field));
} else if("coofficeaddr".equals(name)){
field.set(contact, changeValueType(list.get(target+3), field));
}
}
//caseId doccode
contact.setCaseid(caseId);
contact.setDoccode(getdoccode);
contacts.add(contact);
}
}
}

if(t instanceof CaseHead){
((CaseHead) t).setHandcode(handCode);
((CaseHead) t).setCaseid(caseId);

//标记共案和还款获取doccode集合

sameCase.setDoccode(((CaseHead) t).getDoccode());
sameCase.setCaseid(((CaseHead) t).getCaseid());

} else if(t instanceof CaseDetail){
((CaseDetail) t).setCaseid(caseId);
//放入卡号合同号
sameCase.setCardcode(((CaseDetail) t).getCardcode());
sameCase.setOriginalcontractid(((CaseDetail) t).getOriginalcontractid());
}
//重置数据
if(!(t instanceof CaseContact)){
excleInterface.excute(t);
}else if(t instanceof CaseContact){
if (contacts != null && contacts.size() != 0) {
for (CaseContact contact : contacts) {
excleInterface.excute(contact);
}
contacts = null;
}
}
}
caseId=null;
handCode =null;
listDoccode.add(sameCase);
}
return listDoccode;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: