Excel 导入问题i

package com.sunline.ermas.ui.server.postloanserver;

import java.io.IOException;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.fileupload.FileItem;
import org.apache.commons.fileupload.FileItemFactory;
import org.apache.commons.fileupload.FileUploadException;
import org.apache.commons.fileupload.disk.DiskFileItemFactory;
import org.apache.commons.fileupload.servlet.ServletFileUpload;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.transaction.annotation.Transactional;

import com.mysema.query.jpa.impl.JPAQuery;
import com.sunline.ark.support.OrganizationContextHolder;
import com.sunline.ermas.ui.server.security.HostSecurityUtils;
import com.sunline.ermas.facility.utils.Constants;
import com.sunline.ermas.facility.utils.JXLExcelUtils;
import com.sunline.ermas.infrastructure.server.repos.RErmasRiskList;
import com.sunline.ermas.infrastructure.shared.model.ErmasCaseMain;
import com.sunline.ermas.infrastructure.shared.model.ErmasLoanMain;
import com.sunline.ermas.infrastructure.shared.model.ErmasRiskList;
import com.sunline.ermas.infrastructure.shared.model.QErmasCaseMain;
import com.sunline.ermas.infrastructure.shared.model.QErmasLoanMain;
import com.sunline.ermas.infrastructure.shared.model.QErmasRiskList;
import com.sunline.ermas.param.def.enums.Indicator;
import com.sunline.kylin.web.ark.client.utils.StringUtils;
import com.sunline.kylin.web.code.infrastructure.shared.model.QTmAdpCode;
import com.sunline.kylin.web.code.infrastructure.shared.model.TmAdpCode;
import com.sunline.kylin.web.code.server.code.CodeService;
import com.sunline.kylin.web.core.client.exception.FlatException;

@Controller
@Transactional
public class RiskListImportServlet extends HttpServlet{

private static final long serialVersionUID = 1L;

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

@PersistenceContext
private EntityManager em;

@Autowired
private RErmasRiskList rErmasRiskList;
@Autowired
private JXLExcelUtils jXLExcelUtils;

@Autowired
private CodeService codeService;

@Autowired
private HostSecurityUtils hostSecurityUtils;

private DateFormat formater = new SimpleDateFormat("yyyy-MM-dd");


@SuppressWarnings("rawtypes")
@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html");
response.setCharacterEncoding("utf-8");
FileItemFactory factory = new DiskFileItemFactory();
ServletFileUpload upload = new ServletFileUpload(factory);
//String productNo="fep";
//request.getParameter("productNo");//产品类型:Fep快易花 Fef快易融 Sel专享贷

List items = null;    
try {   
items = upload.parseRequest(request);    
} catch (FileUploadException ex) {    
ex.printStackTrace();    
}   

Iterator iter = items.iterator();    
if(items.size() == 0){
response.getWriter().write("error");
}else{
while (iter.hasNext()) {    
FileItem item = (FileItem) iter.next();

try {
List<List<String>> list = jXLExcelUtils.readExcel(item, 0);//获取excel表中数据
if (list == null && list.size()==0) {
throw new FlatException("无数据!");
}
List<String> titleList=list.get(0);//获取表头
//判断excel表头是否合法
boolean flagTitle=this.isLegalTitle(titleList);
if (flagTitle) {//如果合法
List<List<String>> bodyList=new ArrayList<List<String>>();
if(list.size()>1){
bodyList=list.subList(1, list.size());//获取表中出去表头以外的数据
//翻译名单类型
LinkedHashMap<String, String> resultTypeMap=new LinkedHashMap<String, String>();
List<TmAdpCode> productList=codeService.getCodes(Constants.RESULT);
if (productList!=null) {
for(TmAdpCode tmAdpProductType:productList){
resultTypeMap.put(tmAdpProductType.getNameCn(),tmAdpProductType.getCode());
}
}

//翻译风险等级
String riskType="";
riskType=Constants.RISKTYPE;

Map<String, String> riskTypeMap=new HashMap<String, String>();
QTmAdpCode qTmAdpCode=QTmAdpCode.tmAdpCode;
List<TmAdpCode> codeList=new JPAQuery(em).from(qTmAdpCode)
.where(qTmAdpCode.codeType.eq(riskType))
.list(qTmAdpCode);
for (TmAdpCode tmAdpCode : codeList) {
riskTypeMap.put(tmAdpCode.getNameCn(),tmAdpCode.getCode());
}

//翻译警报员员所在的类型
LinkedHashMap<String, String> handlerTypeMap=new LinkedHashMap<String, String>();
List<TmAdpCode> handlerTypeList=codeService.getCodes(Constants.COLLORG_TYPE);
if (productList!=null) {
for(TmAdpCode tmAdpProductType:handlerTypeList){
handlerTypeMap.put(tmAdpProductType.getNameCn(),tmAdpProductType.getCode());
}
}
//保存黑/灰名单数据
saveRiskInfo(bodyList,handlerTypeMap,riskTypeMap,resultTypeMap);
}
}
}catch (FlatException e) {
response.getWriter().write(e.getMessage());
logger.info(e.getMessage());
} catch (Exception e) {
response.getWriter().write("上传的黑灰名单数据有误.");
logger.info(e.getMessage());
}
}
}
}

/**
* 上传黑灰名单(快易融)
* @param rows
* @return
* @throws Exception
*/
@Transactional
private String updateFef(List<String> rows,Map<String, String> resultTypeMap,Map<String, String> riskTypeMap,Map<String, String> handlerTypeMap){
ErmasRiskList riskList=new ErmasRiskList();
//保存黑灰名单列表
try {
riskList.setDealDate(formater.parse(rows.get(0)));
} catch (ParseException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
riskList.setAlarmId(rows.get(1));  //处理人
riskList.setIdNo(rows.get(2)); //身份证
//riskList.setReferees(rows.get(2));
//riskList.setMerchantName(rows.get(3));
riskList.setCustName(rows.get(3));    //客户姓名

riskList.setMobilePhone(rows.get(4)); //手机
riskList.setContactName(rows.get(5));  //联系人姓名
riskList.setContactMobile(rows.get(6));  //联系人手机
//riskList.setContactIdNo(hostSecurityUtils.encryptMessage(rows.get(9)));
riskList.setCustNo(rows.get(7));  //客户号
riskList.setAddress(rows.get(8));   //地址
riskList.setHandlerType(handlerTypeMap.get(rows.get(9)));
riskList.setRiskType(riskTypeMap.get(rows.get(10))); 
riskList.setResult(resultTypeMap.get(rows.get(11)));
riskList.setResources(rows.get(12));
// riskList.setProductNo(productNo);
riskList.setOrg(OrganizationContextHolder.getCurrentOrg());
rErmasRiskList.save(riskList);

//修改案件状态
updatePostCaseStatus(riskList.getIdNo(),  riskList.getResult());
return null;
}

/**
* 上传黑灰名单(快易花)
* @param rows 身份证号
* @return
* @throws Exception
*/
@Transactional
private String updateFep(List<String> rows,  Map<String, String> resultTypeMap,Map<String, String> riskTypeMap,Map<String, String> handlerTypeMap){
ErmasRiskList riskList=new ErmasRiskList();
try {
riskList.setDealDate(formater.parse(rows.get(0)));
} catch (ParseException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
riskList.setAlarmId(rows.get(1));
riskList.setIdNo(hostSecurityUtils.encryptMessage(rows.get(2)));
riskList.setCustName(rows.get(3));
riskList.setMobilePhone(hostSecurityUtils.encryptMessage(rows.get(4)));
riskList.setContactName(rows.get(5));
riskList.setContactMobile(hostSecurityUtils.encryptMessage(rows.get(6)));
riskList.setCustNo(rows.get(7));
riskList.setAddress(rows.get(8));

riskList.setHandlerType(handlerTypeMap.get(rows.get(11)));
riskList.setRiskType(riskTypeMap.get(rows.get(12)));
riskList.setResult(resultTypeMap.get(rows.get(13)));
riskList.setResources(rows.get(14));
// riskList.setProductNo(productNo);
riskList.setOrg(OrganizationContextHolder.getCurrentOrg());
rErmasRiskList.save(riskList);

//修改案件状态
updatePostCaseStatus(riskList.getIdNo(),  riskList.getResult());

return null;
}



/**
* 上传黑灰名单(专享贷)
* @param rows
* @return
* @throws Exception
*/
/*@Transactional
private String updateSel(List<String> rows, Map<String, String> resultTypeMap,Map<String, String> riskTypeMap,Map<String, String> handlerTypeMap){
ErmasRiskList riskList=new ErmasRiskList();
try {
riskList.setDealDate(formater.parse(rows.get(0)));
} catch (ParseException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
riskList.setAlarmId(rows.get(1));
riskList.setIdNo(hostSecurityUtils.encryptMessage(rows.get(2)));
riskList.setCustName(rows.get(3));
riskList.setMobilePhone(hostSecurityUtils.encryptMessage(rows.get(4)));
riskList.setMerchantName(rows.get(5));
riskList.setReferees(rows.get(6));
riskList.setContactName(rows.get(7));
riskList.setContactMobile(hostSecurityUtils.encryptMessage(rows.get(8)));
riskList.setCustNo(rows.get(9));
riskList.setAddress(rows.get(10));

riskList.setHandlerType(handlerTypeMap.get(rows.get(13)));
riskList.setRiskType(riskTypeMap.get(rows.get(14)));
riskList.setResult(resultTypeMap.get(rows.get(15)));
//riskList.setProductNo(productNo);
riskList.setOrg(OrganizationContextHolder.getCurrentOrg());
rErmasRiskList.save(riskList);

//修改案件状态
updatePostCaseStatus(riskList.getIdNo(), riskList.getResult());
return null;
}*/

/**
* 判断表头是否正确
* @param titleList 表头
* @param productNo 产品类型
* @return
*/
private boolean isLegalTitle(List<String> titleList/*,String productNo*/){


//快易花

if(!"日期".equals(titleList.get(0))){
throw new FlatException("第1列:日期,请上传正确的模板!");
};

if(!"处理人".equals(titleList.get(1))){
throw new FlatException("第2列:处理人,请上传正确的模板!");
};

if(!"身份证号".equals(titleList.get(2))){
throw new FlatException("第3列:身份证号,请上传正确的模板!");
};

if(!"姓名".equals(titleList.get(3))){
throw new FlatException("第4列:姓名,请上传正确的模板!");
};

if(!"手机".equals(titleList.get(4))){
throw new FlatException("第5列:手机,请上传正确的模板!");
};

if(!"联系人姓名".equals(titleList.get(5))){
throw new FlatException("第6列:联系人姓名,请上传正确的模板!");
};

if(!"联系人手机".equals(titleList.get(6))){
throw new FlatException("第7列:联系人手机,请上传正确的模板!");
};

if(!"客户号".equals(titleList.get(7))){
throw new FlatException("第8列:客户号,请上传正确的模板!");
};

if(!"地址".equals(titleList.get(8))){
throw new FlatException("第9列:地址,请上传正确的模板!");
};


if(!"判定人员".equals(titleList.get(9))){
throw new FlatException("第10列:判定人员,请上传正确的模板!");
};

if(!"风险类型".equals(titleList.get(10))){
throw new FlatException("第11列:风险类型,请上传正确的模板!");
};

if(!"最终结果".equals(titleList.get(11))){
throw new FlatException("第12列:最终结果,请上传正确的模板!");
};

if(!"来源".equals(titleList.get(12))){
throw new FlatException("第13列:来源,请上传正确的模板!");
};

return true;
}

/**
* 保存黑名单数据
* @param bodyList  excel中除去表头以外的数据
* @param productNo 产品类型
* @param handlerTypeMap 人员类型Map
* @param riskTypeMap 风险等级Map
* @param resultTypeMap 黑/灰名单
* @return
*/
private String saveRiskInfo(List<List<String>> bodyList,Map<String, String> handlerTypeMap,Map<String, String> riskTypeMap,Map<String, String> resultTypeMap){
//保存数据
String result="";
for (List<String> rows : bodyList) {
if(isFepBodyLegal(rows, handlerTypeMap, riskTypeMap, resultTypeMap)
&&isRiskInfoLegal(rows, handlerTypeMap, riskTypeMap, resultTypeMap)){
//如果表里面的数据合法,并且允许插入,则新增黑/灰名单数据
result = updateFef(rows,resultTypeMap,riskTypeMap,handlerTypeMap);
if(result != null){
throw new FlatException("导入失败(快易融),存在无效身份证号["+result+"]");
}
}



}
return result;
}


/**
* 判断快易融数据是否合法
* @param rows 导入数据
* @param handlerTypeMap 人员类型Map
* @param riskTypeMap 风险等级Map
* @param resultTypeMap 黑/灰名单
* @return
*/
/*private boolean isFefBodyLegal(List<String> rows,Map<String, String> handlerTypeMap,Map<String, String> riskTypeMap,Map<String, String> resultTypeMap){
if(StringUtils.isBlank( rows.get(0))){
throw new FlatException("姓名["+rows.get(4)+"],日期不能为空");
}else{
if(!rows.get(0).trim().matches("^(\\d{4})-(\\d{2})-(\\d{2})$")){
throw new FlatException("姓名["+rows.get(4)+"],日期格式不正确,日期格式应该为YYYY-MM-DD");
}else{
try {
formater.setLenient(false);
formater.parse(rows.get(0));
} catch (Exception e) {
logger.debug("导入数据信息[{}]",rows.toString());
logger.debug(e.getMessage());
throw new FlatException("姓名["+rows.get(4)+"],日期不合法");
}
}
}
if(StringUtils.isBlank( rows.get(1))){

throw new FlatException("姓名["+rows.get(4)+"],处理人不能为空");
}else {
boolean isMatch=rows.get(1).matches("^[\u4e00-\u9fa5a-zA-Z]+$");
if(isMatch==false){
throw new FlatException("姓名["+rows.get(4)+"]:处理人,只能输入中文和英文字符!");
}
}

if(StringUtils.isBlank( rows.get(2))){
throw new FlatException("姓名["+rows.get(4)+"],代理商不能为空");
}

if(StringUtils.isBlank( rows.get(3))){
throw new FlatException("姓名["+rows.get(4)+"],商户名不能为空");
}

if(StringUtils.isBlank( rows.get(4))){
throw new FlatException("姓名["+rows.get(4)+"],法人代表不能为空");
}else {
boolean isMatch=rows.get(4).matches("^[\u4e00-\u9fa5a-zA-Z]+$");
if(isMatch==false){
throw new FlatException("姓名["+rows.get(4)+"]:法人代表,只能输入中文和英文字符!");
}
}
if(StringUtils.isBlank( rows.get(5))){
throw new FlatException("姓名["+rows.get(4)+"],身份证号不能为空");
}else {
boolean isMatch=rows.get(5).matches("^\\d{17}[\\d|X]$");
if(isMatch==false){
throw new FlatException("姓名["+rows.get(4)+"],平输入正确的身份证号!");
}
}
if(StringUtils.isNotBlank( rows.get(6))){
boolean isMatch=rows.get(6).matches("^[1]\\d{10}");
if(isMatch==false){
throw new FlatException("姓名["+rows.get(4)+"],请输入正确的法人手机号!");
}
}
if(StringUtils.isBlank( rows.get(7))){
throw new FlatException("姓名["+rows.get(4)+"],关联人不能为空");
}else {
boolean isMatch=rows.get(7).matches("^[\u4e00-\u9fa5a-zA-Z]+$");
if(isMatch==false){
throw new FlatException("姓名["+rows.get(4)+"]:关联人,只能输入中文和英文字符!");
}
}

if(StringUtils.isNotBlank(rows.get(8))){
boolean isMatch=rows.get(8).matches("^[1]\\d{10}");
if(isMatch==false){
throw new FlatException("姓名["+rows.get(4)+"],请输入正确的关联人手机号!");
}
}

if(StringUtils.isBlank( rows.get(9))){
throw new FlatException("姓名["+rows.get(4)+"],关联人身份证不能为空");
}else {
boolean isMatch=rows.get(9).matches("^\\d{17}[\\d|X]$");
if(isMatch==false){
throw new FlatException("姓名["+rows.get(4)+"],请输入正确的关联人身份证!");
}
}
if(StringUtils.isBlank( rows.get(10))){
throw new FlatException("姓名["+rows.get(4)+"],判定人员不能为空");
}else if(handlerTypeMap.get(rows.get(10))==null){
throw new FlatException("姓名["+rows.get(4)+"],判定人员有误!");
}
if(StringUtils.isBlank( rows.get(11))){
throw new FlatException("姓名["+rows.get(4)+"],风险等级不能为空");
}else if(riskTypeMap.get(rows.get(11))==null){
throw new FlatException("姓名["+rows.get(4)+"],风险等级有误!");
}
if(StringUtils.isBlank( rows.get(12))){
throw new FlatException("姓名["+rows.get(4)+"],最终结果不能为空");
}else if(resultTypeMap.get(rows.get(12))==null){
throw new FlatException("姓名["+rows.get(4)+"],最终结果有误!");
}

if(StringUtils.isBlank( rows.get(13))){
throw new FlatException("姓名["+rows.get(4)+"],备注不能为空");
}

return true;
}
*/
/**
* 判断快易花数据是否合法
* @param rows 导入数据
* @param handlerTypeMap 人员类型Map
* @param riskTypeMap 风险等级Map
* @param resultTypeMap 黑/灰名单
* @return
*/
private boolean isFepBodyLegal(List<String> rows,Map<String, String> handlerTypeMap,Map<String, String> riskTypeMap,Map<String, String> resultTypeMap){
if(StringUtils.isBlank( rows.get(0))){
throw new FlatException("姓名["+rows.get(3)+"],日期不能为空");
}else{
if(!rows.get(0).trim().matches("^(\\d{4})-(\\d{2})-(\\d{2})$")){
throw new FlatException("姓名["+rows.get(3)+"],日期格式不正确,日期格式应该为YYYY-MM-DD");
}else{
try {
formater.setLenient(false);
formater.parse(rows.get(0));
} catch (Exception e) {
logger.debug("导入数据信息[{}]",rows.toString());
logger.debug(e.getMessage());
throw new FlatException("姓名["+rows.get(3)+"],日期不合法");
}
}
}
if(StringUtils.isBlank( rows.get(1))){
throw new FlatException("姓名["+rows.get(3)+"],处理人不能为空");
}else {
boolean isMatch=rows.get(1).matches("^[\u4e00-\u9fa5a-zA-Z]+$");
if(isMatch==false){
throw new FlatException("姓名["+rows.get(3)+"]:处理人,只能输入中文和英文字符!");
}
}
if(StringUtils.isBlank( rows.get(2))){
throw new FlatException("姓名["+rows.get(3)+"],身份证号不能为空");
}else {
boolean isMatch=rows.get(2).matches("^\\d{17}[\\d|X]$");
if(isMatch==false){
throw new FlatException("姓名["+rows.get(3)+"],请输入正确的身份证号!");
}
}
if(StringUtils.isBlank( rows.get(3))){
throw new FlatException("姓名["+rows.get(3)+"],姓名不能为空");
}else {
boolean isMatch=rows.get(3).matches("^[\u4e00-\u9fa5a-zA-Z]+$");
if(isMatch==false){
throw new FlatException("姓名["+rows.get(3)+"]:姓名,只能输入中文和英文字符!");
}
}
if(StringUtils.isBlank( rows.get(4))){
throw new FlatException("姓名["+rows.get(3)+"],手机不能为空");
}else {
boolean isMatch=rows.get(4).matches("^[1]\\d{10}");
if(isMatch==false){
throw new FlatException("姓名["+rows.get(3)+"],请输入正确的手机号!");
}
}
if(StringUtils.isNotBlank( rows.get(5))){
boolean isMatch=rows.get(5).matches("^[\u4e00-\u9fa5a-zA-Z]+$");
if(isMatch==false){
throw new FlatException("姓名["+rows.get(3)+"]:联人姓名,只能输入中文和英文字符!");
}
}
if(StringUtils.isNotBlank( rows.get(6))){
boolean isMatch=rows.get(6).matches("^[1]\\d{10}");
if(isMatch==false){
throw new FlatException("姓名["+rows.get(3)+"],请输入正确的联系人手机号!");
}
}
if(StringUtils.isBlank( rows.get(7))){
throw new FlatException("姓名["+rows.get(3)+"],客户号不能为空");
}
if(StringUtils.isBlank( rows.get(8))){
throw new FlatException("姓名["+rows.get(3)+"],地址不能为空");
}
/*if(StringUtils.isBlank( rows.get(9))){
throw new FlatException("姓名["+rows.get(3)+"],Device ID不能为空");
}*/
/*if(StringUtils.isBlank( rows.get(10))){
throw new FlatException("姓名["+rows.get(3)+"],IP不能为空");
}else {
boolean isMatch=rows.get(10).matches("^[0-9]{3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}$");
if(isMatch==false){
throw new FlatException("姓名["+rows.get(3)+"],请输入正确的IP!");
}
}*/
if(StringUtils.isBlank( rows.get(9))){
throw new FlatException("姓名["+rows.get(3)+"],判定人员不能为空");
}else if(handlerTypeMap.get(rows.get(9))==null){
throw new FlatException("姓名["+rows.get(3)+"],判定人员有误!");
}

if(StringUtils.isBlank( rows.get(10))){
throw new FlatException("姓名["+rows.get(3)+"],风险等级不能为空");
}else if(riskTypeMap.get(rows.get(10))==null){
throw new FlatException("姓名["+rows.get(3)+"],风险等级有误!");
}
if(StringUtils.isBlank( rows.get(11))){
throw new FlatException("姓名["+rows.get(3)+"],最终结果不能为空");
}else if(resultTypeMap.get(rows.get(11))==null){
throw new FlatException("姓名["+rows.get(3)+"],名单类型有误!");
}
if(StringUtils.isBlank( rows.get(12))){
throw new FlatException("姓名["+rows.get(3)+"],来源不能为空");
}
return true;
}

/**
* 判断专享贷数据是否合法
* @param rows 导入数据
* @param handlerTypeMap 人员类型Map
* @param riskTypeMap 风险等级Map
* @param resultTypeMap 黑/灰名单
* @return
*/
/*private boolean isSelBodyLegal(List<String> rows,Map<String, String> handlerTypeMap,Map<String, String> riskTypeMap,Map<String, String> resultTypeMap){
if(StringUtils.isBlank( rows.get(0))){
throw new FlatException("姓名["+rows.get(3)+"],日期不能为空");
}else{
try {
formater.setLenient(false);
formater.parse(rows.get(0));
} catch (Exception e) {
logger.debug("导入数据信息[{}]",rows.toString());
logger.debug(e.getMessage());
throw new FlatException("姓名["+rows.get(3)+"],日期格式不正确,日期格式应该为YYYY-MM-DD");
}
}
if(StringUtils.isBlank( rows.get(1))){
throw new FlatException("姓名["+rows.get(3)+"],处理人不能为空");
}else {
boolean isMatch=rows.get(1).matches("^[\u4e00-\u9fa5a-zA-Z]+$");
if(isMatch==false){
throw new FlatException("姓名["+rows.get(3)+"]:处理人,只能输入中文和英文字符!");
}
}
if(StringUtils.isBlank( rows.get(2))){
throw new FlatException("姓名["+rows.get(3)+"],身份证号不能为空");
}else {
boolean isMatch=rows.get(2).matches("^\\d{17}[\\d|X]$");
if(isMatch==false){
throw new FlatException("姓名["+rows.get(3)+"],请输入正确的身份证号!");
}
}
if(StringUtils.isBlank( rows.get(3))){
throw new FlatException("姓名["+rows.get(3)+"],姓名不能为空");
}else {
boolean isMatch=rows.get(3).matches("^[\u4e00-\u9fa5a-zA-Z]+$");
if(isMatch==false){
throw new FlatException("姓名["+rows.get(3)+"]:姓名,只能输入中文和英文字符!");
}
}
if(StringUtils.isBlank( rows.get(4))){
throw new FlatException("姓名["+rows.get(3)+"],手机不能为空");
}else {
boolean isMatch=rows.get(4).matches("^[1]\\d{10}");
if(isMatch==false){
throw new FlatException("姓名["+rows.get(3)+"],请输入正确的手机号!");
}
}
if(StringUtils.isBlank( rows.get(5))){
throw new FlatException("姓名["+rows.get(3)+"],合作商户不能为空");
}

if(StringUtils.isBlank( rows.get(6))){
throw new FlatException("姓名["+rows.get(3)+"],销售人员不能为空");
}else {
boolean isMatch=rows.get(6).matches("^[\u4e00-\u9fa5a-zA-Z]+$");
if(isMatch==false){
throw new FlatException("姓名["+rows.get(3)+"]:销售人员,只能输入中文和英文字符!");
}
}
if(StringUtils.isNotBlank( rows.get(7))){
boolean isMatch=rows.get(7).matches("^[\u4e00-\u9fa5a-zA-Z]+$");
if(isMatch==false){
throw new FlatException("姓名["+rows.get(3)+"]:关联人姓名,只能输入中文和英文字符!");
}
}
if(StringUtils.isNotBlank( rows.get(8))){
boolean isMatch=rows.get(8).matches("^[1]\\d{10}");
if(isMatch==false){
throw new FlatException("姓名["+rows.get(3)+"],请输入正确的手机号!");
}
}
if(StringUtils.isBlank( rows.get(9))){
throw new FlatException("姓名["+rows.get(3)+"],客户号不能为空");
}
if(StringUtils.isBlank( rows.get(10))){
throw new FlatException("姓名["+rows.get(3)+"],地址不能为空");
}
if(StringUtils.isBlank( rows.get(11))){
throw new FlatException("姓名["+rows.get(3)+"],Device ID不能为空");
}
if(StringUtils.isBlank( rows.get(12))){
throw new FlatException("姓名["+rows.get(3)+"],IP不能为空");
}else {
boolean isMatch=rows.get(12).matches("^[0-9]{3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}$");
if(isMatch==false){
throw new FlatException("姓名["+rows.get(3)+"],请输入正确的IP!");
}
}
if(StringUtils.isBlank( rows.get(13))){
throw new FlatException("姓名["+rows.get(3)+"],判定人员不能为空");
}else if(handlerTypeMap.get(rows.get(13))==null){
throw new FlatException("姓名["+rows.get(3)+"],判定人员有误!");
}

if(StringUtils.isBlank( rows.get(14))){
throw new FlatException("姓名["+rows.get(3)+"],风险等级不能为空");
}else if(riskTypeMap.get(rows.get(14))==null){
throw new FlatException("姓名["+rows.get(3)+"],风险等级有误!");
}

if(StringUtils.isBlank( rows.get(15))){
throw new FlatException("姓名["+rows.get(3)+"],最终结果不能为空");
}else if(resultTypeMap.get(rows.get(15))==null){
throw new FlatException("姓名["+rows.get(3)+"],名单类型有误!");
}
return true;
}*/

private boolean isRiskInfoLegal(List<String> rows,Map<String, String> handlerTypeMap,Map<String, String> riskTypeMap,Map<String, String> resultTypeMap){
QErmasCaseMain qErmasCaseMain=QErmasCaseMain.ermasCaseMain;
//判断身份证是否在案件中存在
String idNo="";
String custName="";
String result="";

idNo=rows.get(2);
custName=rows.get(3);
result=resultTypeMap.get(rows.get(11));
List<ErmasCaseMain> caseMainList =new JPAQuery(em).from(qErmasCaseMain).where(qErmasCaseMain.idNo.eq(idNo)).list(qErmasCaseMain);
if (caseMainList==null||caseMainList.size()==0) {
throw new FlatException("客户【"+custName+"】,身份证号码不存在!");
}

//查询该身份证的所有黑/灰名单数据
QErmasRiskList qErmasRiskList=QErmasRiskList.ermasRiskList;
List<ErmasRiskList> riskList=new JPAQuery(em).from(qErmasRiskList)
.where(qErmasRiskList.idNo.eq(idNo)).list(qErmasRiskList);
boolean flag=true;
if(riskList==null||riskList.size()==0){
return flag;//如果之前没有黑/灰名单数据,则允许查询
}
//判断案件中是否存在黑/灰名单
for (ErmasRiskList ermasRiskList : riskList) {
if (Constants.BLACK.equals(result)) {//如果要新增黑名单
//如果该客户已经存在黑名单,则提示
if(Constants.BLACK.equals(ermasRiskList.getResult())){
flag=false;
throw new FlatException("客户【"+custName+"】,在黑名单中已存在!!");
}else{
//判断其他产品中是否存在灰名单,如果有将所有灰名单删除
rErmasRiskList.delete(new JPAQuery(em).from(qErmasRiskList)
.where(qErmasRiskList.result.eq(Constants.GRAY)
.and(qErmasRiskList.idNo.eq(idNo)))
.list(qErmasRiskList));
}
}else{//要新增灰名单
if(Constants.BLACK.equals(ermasRiskList.getResult())){
//如果该客户已经存在黑名单,则提示
flag=false;
throw new FlatException("客户【"+custName+"】,在黑名单中已存在!!");
}else {
throw new FlatException("客户【"+custName+"】,在灰名单中已存在!!");
}
}

}
return flag;
}

/**
* 插入黑灰名单时,同时修改全部贷后案件“是否灰名单”、“是否灰名单”
* @param idNo
*/
private void updatePostCaseStatus(String idNo,String result){
if(Constants.BLACK.equals(result)){
//查询该客户是否有警报案件,如果有警报案件,则全部修改案件“是否黑名单”为是
QErmasLoanMain qErmasLoanMain=QErmasLoanMain.ermasLoanMain;
List<ErmasLoanMain> loanMainList=new JPAQuery(em).from(qErmasLoanMain)
.where(qErmasLoanMain.idNo.eq(idNo)).list(qErmasLoanMain);
for (ErmasLoanMain ermasLoanMain : loanMainList) {
ermasLoanMain.setIsBlack(Indicator.Y);
ermasLoanMain.setIsGray(Indicator.N);
}
}else{
//查询该客户对应的产品是否有警报案件,如果有警报案件,则全部修改案件“是否灰名单”为是
QErmasLoanMain qErmasLoanMain=QErmasLoanMain.ermasLoanMain;
List<ErmasLoanMain> loanMainList=new JPAQuery(em).from(qErmasLoanMain)
.where(qErmasLoanMain.idNo.eq(idNo))
.list(qErmasLoanMain);
for (ErmasLoanMain ermasLoanMain : loanMainList) {
ermasLoanMain.setIsBlack(Indicator.N);
ermasLoanMain.setIsGray(Indicator.Y);
}
}
}
}

猜你喜欢

转载自2513312341.iteye.com/blog/2394008