|
@@ -37,6 +37,7 @@ import javax.servlet.http.HttpServletRequest;
|
|
import javax.servlet.http.HttpServletResponse;
|
|
import javax.servlet.http.HttpServletResponse;
|
|
import java.beans.Transient;
|
|
import java.beans.Transient;
|
|
import java.io.*;
|
|
import java.io.*;
|
|
|
|
+import java.lang.reflect.Field;
|
|
import java.lang.reflect.InvocationTargetException;
|
|
import java.lang.reflect.InvocationTargetException;
|
|
import java.lang.reflect.Method;
|
|
import java.lang.reflect.Method;
|
|
import java.math.BigDecimal;
|
|
import java.math.BigDecimal;
|
|
@@ -398,16 +399,18 @@ public class ClueServiceImpl extends ServiceImpl<ClueMapper, Clue> implements Cl
|
|
@Transactional(rollbackFor = Exception.class)
|
|
@Transactional(rollbackFor = Exception.class)
|
|
public HttpRespMsg importData(MultipartFile multipartFile) {
|
|
public HttpRespMsg importData(MultipartFile multipartFile) {
|
|
HttpRespMsg msg=new HttpRespMsg();
|
|
HttpRespMsg msg=new HttpRespMsg();
|
|
|
|
+ if(!multipartFile.getOriginalFilename().endsWith(".xlsx")){
|
|
|
|
+ msg.setError("文件格式错误,请使用.xlsx格式的Excel文件进行导入");
|
|
|
|
+ return msg;
|
|
|
|
+ }
|
|
String fileName = multipartFile.getOriginalFilename();
|
|
String fileName = multipartFile.getOriginalFilename();
|
|
File file = new File(fileName == null ? "file" : fileName);
|
|
File file = new File(fileName == null ? "file" : fileName);
|
|
User user = userMapper.selectById(request.getHeader("token"));
|
|
User user = userMapper.selectById(request.getHeader("token"));
|
|
Integer companyId = user.getCompanyId();
|
|
Integer companyId = user.getCompanyId();
|
|
WxCorpInfo wxCorpInfo = wxCorpInfoService.getOne(new LambdaQueryWrapper<WxCorpInfo>().eq(WxCorpInfo::getCompanyId, companyId));
|
|
WxCorpInfo wxCorpInfo = wxCorpInfoService.getOne(new LambdaQueryWrapper<WxCorpInfo>().eq(WxCorpInfo::getCompanyId, companyId));
|
|
-// List<Clue> clueList = clueMapper.selectList(new LambdaQueryWrapper<Clue>().eq(Clue::getCompanyId, companyId));
|
|
|
|
List<User> userList = userMapper.selectList(new LambdaQueryWrapper<User>().eq(User::getCompanyId, companyId));
|
|
List<User> userList = userMapper.selectList(new LambdaQueryWrapper<User>().eq(User::getCompanyId, companyId));
|
|
- List<SysDict> sysDictOfClueSources = sysDictMapper.selectList(new LambdaQueryWrapper<SysDict>().eq(SysDict::getCompanyId, companyId).eq(SysDict::getCode, "ClueSources"));
|
|
|
|
- List<SysDict> sysDictOfCustomLevel = sysDictMapper.selectList(new LambdaQueryWrapper<SysDict>().eq(SysDict::getCompanyId, companyId).eq(SysDict::getCode, "CustomLevel"));
|
|
|
|
- List<SysDict> sysDictOfCustomIndustry = sysDictMapper.selectList(new LambdaQueryWrapper<SysDict>().eq(SysDict::getCompanyId, companyId).eq(SysDict::getCode, "CustomIndustry"));
|
|
|
|
|
|
+ List<SysDict> sysDictOfProductType = sysDictMapper.selectList(new LambdaQueryWrapper<SysDict>().eq(SysDict::getCompanyId, companyId).eq(SysDict::getCode, "ClueSources"));
|
|
|
|
+ List<SysDict> sysDictOfProductUnit = sysDictMapper.selectList(new LambdaQueryWrapper<SysDict>().eq(SysDict::getCompanyId, companyId).eq(SysDict::getCode, "ProductUnit"));
|
|
InputStream inputStream = null;
|
|
InputStream inputStream = null;
|
|
OutputStream outputStream = null;
|
|
OutputStream outputStream = null;
|
|
try {
|
|
try {
|
|
@@ -435,10 +438,28 @@ public class ClueServiceImpl extends ServiceImpl<ClueMapper, Clue> implements Cl
|
|
String config = sysForm.getConfig();
|
|
String config = sysForm.getConfig();
|
|
JSONObject configOb = JSON.parseObject(config);
|
|
JSONObject configOb = JSON.parseObject(config);
|
|
JSONArray configObJSONArray = configOb.getJSONArray("list");
|
|
JSONArray configObJSONArray = configOb.getJSONArray("list");
|
|
-// List<Clue> importClueList=new ArrayList<>();
|
|
|
|
|
|
+ //可能存在栅格布局的情况需要特殊处理
|
|
|
|
+ List<String> modelNameList=new ArrayList<>();
|
|
|
|
+ for (int i = 0; i < configObJSONArray.size(); i++) {
|
|
|
|
+ JSONObject jsonObject = configObJSONArray.getJSONObject(i);
|
|
|
|
+ if(jsonObject.getString("type").equals("grid")){
|
|
|
|
+ JSONArray columns = jsonObject.getJSONArray("columns");
|
|
|
|
+ for (int i1 = 0; i1 < columns.size(); i1++) {
|
|
|
|
+ JSONObject columnsJSONObject = columns.getJSONObject(i1);
|
|
|
|
+ JSONArray list = columnsJSONObject.getJSONArray("list");
|
|
|
|
+ for (int i2 = 0; i2 < list.size(); i2++) {
|
|
|
|
+ JSONObject object = list.getJSONObject(i2);
|
|
|
|
+ modelNameList.add(object.getString("model"));
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }else {
|
|
|
|
+ modelNameList.add(jsonObject.getString("model"));
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ List<Clue> importClueList =new ArrayList<>();
|
|
List<String> userNameList=new ArrayList<>();
|
|
List<String> userNameList=new ArrayList<>();
|
|
HttpRespMsg respMsg=new HttpRespMsg();
|
|
HttpRespMsg respMsg=new HttpRespMsg();
|
|
- for (int rowIndex = 0; rowIndex <= rowNum; rowIndex++) {
|
|
|
|
|
|
+ for (int rowIndex = 1; rowIndex <= rowNum; rowIndex++) {
|
|
XSSFRow row = sheet.getRow(rowIndex);
|
|
XSSFRow row = sheet.getRow(rowIndex);
|
|
if (row == null) {
|
|
if (row == null) {
|
|
continue;
|
|
continue;
|
|
@@ -450,20 +471,9 @@ public class ClueServiceImpl extends ServiceImpl<ClueMapper, Clue> implements Cl
|
|
//获取到当前行的列数据
|
|
//获取到当前行的列数据
|
|
int cellNum = row.getLastCellNum();
|
|
int cellNum = row.getLastCellNum();
|
|
for (int i = 0; i < cellNum; i++) {
|
|
for (int i = 0; i < cellNum; i++) {
|
|
- JSONObject item = configObJSONArray.getJSONObject(i);
|
|
|
|
- String modelName = item.getString("model");
|
|
|
|
|
|
+ String modelName = modelNameList.get(i);
|
|
XSSFCell cell = row.getCell(i);
|
|
XSSFCell cell = row.getCell(i);
|
|
- if(cell!=null){
|
|
|
|
- switch (item.getString("type")){
|
|
|
|
-// case "time":cell.setCellType(CellType.NUMERIC);
|
|
|
|
-// break;
|
|
|
|
- default:cell.setCellType(CellType.STRING);
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
if(modelName.equals("inchargerId")){
|
|
if(modelName.equals("inchargerId")){
|
|
- System.out.println("=====");
|
|
|
|
- System.out.println(modelName);
|
|
|
|
- System.out.println(cell.toString());
|
|
|
|
if(!StringUtils.isEmpty(cell.getStringCellValue())){
|
|
if(!StringUtils.isEmpty(cell.getStringCellValue())){
|
|
userNameList.add(cell.getStringCellValue());
|
|
userNameList.add(cell.getStringCellValue());
|
|
}
|
|
}
|
|
@@ -471,7 +481,7 @@ public class ClueServiceImpl extends ServiceImpl<ClueMapper, Clue> implements Cl
|
|
|
|
|
|
}
|
|
}
|
|
}
|
|
}
|
|
- System.out.println("参与搜索的人员列表"+userNameList + userNameList.size());
|
|
|
|
|
|
+ System.out.println("参与搜素的人员列表"+userNameList + userNameList.size());
|
|
if(wxCorpInfo!=null&&wxCorpInfo.getSaasSyncContact()==1&&userNameList.size()>0){
|
|
if(wxCorpInfo!=null&&wxCorpInfo.getSaasSyncContact()==1&&userNameList.size()>0){
|
|
respMsg = wxCorpInfoService.getBatchSearchUserInfo(wxCorpInfo, userNameList,null);
|
|
respMsg = wxCorpInfoService.getBatchSearchUserInfo(wxCorpInfo, userNameList,null);
|
|
if(respMsg.code.equals("0")){
|
|
if(respMsg.code.equals("0")){
|
|
@@ -494,7 +504,6 @@ public class ClueServiceImpl extends ServiceImpl<ClueMapper, Clue> implements Cl
|
|
int cellNum = row.getLastCellNum();
|
|
int cellNum = row.getLastCellNum();
|
|
Clue clue =new Clue();
|
|
Clue clue =new Clue();
|
|
clue.setCompanyId(companyId);
|
|
clue.setCompanyId(companyId);
|
|
- clue.setCreateTime(new Date());
|
|
|
|
clue.setCreateId(user.getId());
|
|
clue.setCreateId(user.getId());
|
|
for (int i = 0; i < cellNum; i++) {
|
|
for (int i = 0; i < cellNum; i++) {
|
|
JSONObject item = configObJSONArray.getJSONObject(i);
|
|
JSONObject item = configObJSONArray.getJSONObject(i);
|
|
@@ -507,6 +516,7 @@ public class ClueServiceImpl extends ServiceImpl<ClueMapper, Clue> implements Cl
|
|
switch (item.getString("type")){
|
|
switch (item.getString("type")){
|
|
// case "time":cell.setCellType(CellType.NUMERIC);
|
|
// case "time":cell.setCellType(CellType.NUMERIC);
|
|
// break;
|
|
// break;
|
|
|
|
+ //默认读取所有数据都是文本格式
|
|
default:cell.setCellType(CellType.STRING);
|
|
default:cell.setCellType(CellType.STRING);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -520,7 +530,7 @@ public class ClueServiceImpl extends ServiceImpl<ClueMapper, Clue> implements Cl
|
|
return msg;
|
|
return msg;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
- if(modelName.equals("inchargerId")){
|
|
|
|
|
|
+ if(modelName.equals("inchargerId")){
|
|
if(!StringUtils.isEmpty(cell.getStringCellValue())){
|
|
if(!StringUtils.isEmpty(cell.getStringCellValue())){
|
|
String userName = cell.getStringCellValue();
|
|
String userName = cell.getStringCellValue();
|
|
Optional<User> first;
|
|
Optional<User> first;
|
|
@@ -537,119 +547,52 @@ public class ClueServiceImpl extends ServiceImpl<ClueMapper, Clue> implements Cl
|
|
return msg;
|
|
return msg;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
- }else if(modelName.equals("customLevelId")){
|
|
|
|
|
|
+ }else if(modelName.equals("clueSourceId")){
|
|
if(!StringUtils.isEmpty(cell.getStringCellValue())){
|
|
if(!StringUtils.isEmpty(cell.getStringCellValue())){
|
|
- Optional<SysDict> first = sysDictOfCustomLevel.stream().filter(s -> s.getName().equals(cell.getStringCellValue())).findFirst();
|
|
|
|
|
|
+ Optional<SysDict> first = sysDictOfProductType.stream().filter(s -> s.getName().equals(cell.getStringCellValue())).findFirst();
|
|
if(first.isPresent()){
|
|
if(first.isPresent()){
|
|
- clue.setCustomerLevelId(first.get().getId());
|
|
|
|
|
|
+ clue.setClueSourceId(first.get().getId());
|
|
}else {
|
|
}else {
|
|
- throw new Exception("客户级别["+cell.getStringCellValue()+"不存在,请在系统字典中增加");
|
|
|
|
|
|
+ msg.setError("线索来源["+cell.getStringCellValue()+"]不存在,请在系统字典中增加");
|
|
|
|
+ return msg;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
- }else if(modelName.equals("clueSourcesId")){
|
|
|
|
- if(!StringUtils.isEmpty(cell.getStringCellValue())){
|
|
|
|
- Optional<SysDict> first = sysDictOfClueSources.stream().filter(s -> s.getName().equals(cell.getStringCellValue())).findFirst();
|
|
|
|
- if(first.isPresent()){
|
|
|
|
- Integer id = first.get().getId();
|
|
|
|
- clue.setClueSourceId(id);
|
|
|
|
- }else {
|
|
|
|
- throw new Exception("线索来源["+cell.getStringCellValue()+"不存在,请在系统字典中增加");
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- }else if(modelName.equals("customIndustryId")){
|
|
|
|
- if(!StringUtils.isEmpty(cell.getStringCellValue())){
|
|
|
|
- Optional<SysDict> first = sysDictOfCustomIndustry.stream().filter(s -> s.getName().equals(cell.getStringCellValue())).findFirst();
|
|
|
|
- if(first.isPresent()){
|
|
|
|
- clue.setCustomerIndustryId(first.get().getId());
|
|
|
|
- }else {
|
|
|
|
- throw new Exception("线索来源["+cell.getStringCellValue()+"不存在,请在系统字典中增加");
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- }else {
|
|
|
|
|
|
+ }else {
|
|
if(!StringUtils.isEmpty(cell.getStringCellValue())){
|
|
if(!StringUtils.isEmpty(cell.getStringCellValue())){
|
|
- Class<Clue> clueClass = Clue.class;
|
|
|
|
- Method method = clueClass.getMethod(setter,String.class);
|
|
|
|
- method.invoke(clue,cell.getStringCellValue());
|
|
|
|
|
|
+ Class<Clue> ClueClass = Clue.class;
|
|
|
|
+ Method method = ClueClass.getMethod(setter,String.class);
|
|
|
|
+ method.invoke(cell,cell.getStringCellValue());
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
}
|
|
}
|
|
- clueMapper.insert(clue);
|
|
|
|
|
|
+ importClueList.add(clue);
|
|
|
|
+ }
|
|
|
|
+ if(importClueList.size()>0){
|
|
|
|
+ if(!saveOrUpdateBatch(importClueList)){
|
|
|
|
+ msg.setError("验证失败,请检验数据格式是否正确");
|
|
|
|
+ return msg;
|
|
|
|
+ }
|
|
}
|
|
}
|
|
} catch (IOException | NoSuchMethodException e) {
|
|
} catch (IOException | NoSuchMethodException e) {
|
|
e.printStackTrace();
|
|
e.printStackTrace();
|
|
|
|
+ msg.setError("验证失败,请检验数据格式是否正确");
|
|
} catch (IllegalAccessException e) {
|
|
} catch (IllegalAccessException e) {
|
|
e.printStackTrace();
|
|
e.printStackTrace();
|
|
} catch (InvocationTargetException e) {
|
|
} catch (InvocationTargetException e) {
|
|
e.printStackTrace();
|
|
e.printStackTrace();
|
|
} catch (Exception e) {
|
|
} catch (Exception e) {
|
|
e.printStackTrace();
|
|
e.printStackTrace();
|
|
- msg.setError("验证失败");
|
|
|
|
|
|
+ msg.setError("验证失败,请检验数据格式是否正确");
|
|
return msg;
|
|
return msg;
|
|
}
|
|
}
|
|
return msg;
|
|
return msg;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+
|
|
@Override
|
|
@Override
|
|
public HttpRespMsg exportData(Clue clue) throws Exception {
|
|
public HttpRespMsg exportData(Clue clue) throws Exception {
|
|
- User user = userMapper.selectById(request.getHeader("token"));
|
|
|
|
- SysForm sysForm = sysFormMapper.selectOne(new LambdaQueryWrapper<SysForm>().eq(SysForm::getCompanyId, user.getCompanyId()).eq(SysForm::getCode, "Thread").eq(SysForm::getIsCurrent, 1));
|
|
|
|
- WxCorpInfo wxCorpInfo = wxCorpInfoService.getOne(new LambdaQueryWrapper<WxCorpInfo>().eq(WxCorpInfo::getCompanyId, user.getCompanyId()));
|
|
|
|
- String config = sysForm.getConfig();
|
|
|
|
- JSONObject configOb = JSON.parseObject(config);
|
|
|
|
- JSONArray configObJSONArray = configOb.getJSONArray("list");
|
|
|
|
- List<List<String>> dataList=new ArrayList<>();
|
|
|
|
- List<String> titleList=new ArrayList<>();
|
|
|
|
- for (int i = 0; i < configObJSONArray.size(); i++) {
|
|
|
|
- JSONObject item = configObJSONArray.getJSONObject(i);
|
|
|
|
- titleList.add(item.getString("label"));
|
|
|
|
- }
|
|
|
|
- dataList.add(titleList);
|
|
|
|
- List<Clue> list1 = getList(clue);
|
|
|
|
- for (Clue clue1 : list1) {
|
|
|
|
- List<String> item=new ArrayList<>();
|
|
|
|
- for (int i = 0; i < configObJSONArray.size(); i++) {
|
|
|
|
- JSONObject target = configObJSONArray.getJSONObject(i);
|
|
|
|
- if(target.getString("type").equals("grid")){
|
|
|
|
- JSONArray columns = target.getJSONArray("columns");
|
|
|
|
- for (int i1 = 0; i1 < columns.size(); i1++) {
|
|
|
|
- JSONObject columnsJSONObject = columns.getJSONObject(i1);
|
|
|
|
- JSONArray list = columnsJSONObject.getJSONArray("list");
|
|
|
|
- for (int i2 = 0; i2 < list.size(); i2++) {
|
|
|
|
- JSONObject object = list.getJSONObject(i2);
|
|
|
|
- String model = object.getString("model");
|
|
|
|
- String targetName = model.substring(0, 1).toUpperCase() + model.substring(1);
|
|
|
|
- Class<? extends Clue> aClass = clue1.getClass();
|
|
|
|
- String value = String.valueOf(aClass.getMethod("get" + targetName).invoke(clue1)==null?"":aClass.getMethod("get" + targetName).invoke(clue1));
|
|
|
|
- if(model.equals("inchargerId")){
|
|
|
|
- if(wxCorpInfo!=null&&wxCorpInfo.getSaasSyncContact()==1){
|
|
|
|
- value = "$userName"+String.valueOf(aClass.getMethod("getInchargerName").invoke(clue1))+"$";
|
|
|
|
- }else {
|
|
|
|
- value = String.valueOf(aClass.getMethod("getInchargerName").invoke(clue1));
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- item.add(value);
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- }else {
|
|
|
|
- String model = target.getString("model");
|
|
|
|
- String targetName = model.substring(0, 1).toUpperCase() + model.substring(1);
|
|
|
|
- Class<? extends Clue> aClass = clue1.getClass();
|
|
|
|
- String value = String.valueOf(aClass.getMethod("get" + targetName).invoke(clue1)==null?"":aClass.getMethod("get" + targetName).invoke(clue1));
|
|
|
|
- if(model.equals("inchargerId")){
|
|
|
|
- if(wxCorpInfo!=null&&wxCorpInfo.getSaasSyncContact()==1){
|
|
|
|
- value = "$userName"+String.valueOf(aClass.getMethod("getInchargerName").invoke(clue1))+"$";
|
|
|
|
- }else {
|
|
|
|
- value = String.valueOf(aClass.getMethod("getInchargerName").invoke(clue1));
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- item.add(value);
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- dataList.add(item);
|
|
|
|
- }
|
|
|
|
- String fileName="线索表导出_"+ System.currentTimeMillis();
|
|
|
|
- return excelExportService.exportGeneralExcelByTitleAndList(wxCorpInfo,fileName,dataList,path);
|
|
|
|
|
|
+ return null;
|
|
}
|
|
}
|
|
|
|
|
|
@Override
|
|
@Override
|