|
@@ -38,6 +38,9 @@ import java.lang.reflect.InvocationTargetException;
|
|
|
import java.lang.reflect.Method;
|
|
|
import java.math.BigDecimal;
|
|
|
import java.net.URLEncoder;
|
|
|
+import java.text.SimpleDateFormat;
|
|
|
+import java.time.LocalDate;
|
|
|
+import java.time.ZoneId;
|
|
|
import java.util.*;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
@@ -82,6 +85,9 @@ public class BusinessOpportunityServiceImpl extends ServiceImpl<BusinessOpportun
|
|
|
@Resource
|
|
|
private SysDictMapper sysDictMapper;
|
|
|
|
|
|
+ @Resource
|
|
|
+ private StageMapper stageMapper;
|
|
|
+
|
|
|
@Override
|
|
|
public List<BusinessOpportunity> getAll(BusinessOpportunity bo) {
|
|
|
return bOMapper.selectAllList(bo);
|
|
@@ -432,16 +438,28 @@ public class BusinessOpportunityServiceImpl extends ServiceImpl<BusinessOpportun
|
|
|
bOMapper.deleteBatchIds(ids);
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private ContactsMapper contactsMapper;
|
|
|
+ @Autowired
|
|
|
+ private CustomMapper customMapper;
|
|
|
@Override
|
|
|
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();
|
|
|
File file = new File(fileName == null ? "file" : fileName);
|
|
|
User user = userMapper.selectById(request.getHeader("token"));
|
|
|
Integer companyId = user.getCompanyId();
|
|
|
WxCorpInfo wxCorpInfo = wxCorpInfoService.getOne(new LambdaQueryWrapper<WxCorpInfo>().eq(WxCorpInfo::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<Stage> stage = stageMapper.selectList(null);
|
|
|
+ List<Contacts> contacts = contactsMapper.selectList(new LambdaQueryWrapper<Contacts>().eq(Contacts::getCompanyId, user.getCompanyId()).eq(Contacts::getIsDelete, 0).orderByDesc(Contacts::getId));
|
|
|
+ List<Custom> customs = customMapper.selectList(new LambdaQueryWrapper<Custom>().eq(Custom::getCompanyId, user.getCompanyId()).eq(Custom::getIsDelete, 0).orderByDesc(Custom::getId));
|
|
|
+
|
|
|
InputStream inputStream = null;
|
|
|
OutputStream outputStream = null;
|
|
|
try {
|
|
@@ -461,17 +479,36 @@ public class BusinessOpportunityServiceImpl extends ServiceImpl<BusinessOpportun
|
|
|
//由于第一行需要指明列对应的标题
|
|
|
int rowNum = sheet.getLastRowNum();
|
|
|
//获取当前表单模板 校验规则
|
|
|
- SysForm sysForm = sysFormMapper.selectOne(new LambdaQueryWrapper<SysForm>().eq(SysForm::getCode, "Thread").eq(SysForm::getCompanyId, companyId).eq(SysForm::getIsCurrent, 1));
|
|
|
- if (sysForm == null) {
|
|
|
+ SysForm sysForm = sysFormMapper.selectOne(new LambdaQueryWrapper<SysForm>().eq(SysForm::getCode, "business").eq(SysForm::getCompanyId, companyId).eq(SysForm::getIsCurrent, 1));
|
|
|
+ if(sysForm==null){
|
|
|
msg.setError("当前模块未配置自定义模板,需先完成配置");
|
|
|
return msg;
|
|
|
}
|
|
|
String config = sysForm.getConfig();
|
|
|
JSONObject configOb = JSON.parseObject(config);
|
|
|
JSONArray configObJSONArray = configOb.getJSONArray("list");
|
|
|
- List<String> userNameList = new ArrayList<>();
|
|
|
- HttpRespMsg respMsg = new HttpRespMsg();
|
|
|
- for (int rowIndex = 0; rowIndex <= rowNum; rowIndex++) {
|
|
|
+ //可能存在栅格布局的情况需要特殊处理
|
|
|
+ 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<BusinessOpportunity> importProductList = new ArrayList<>();
|
|
|
+ List<String> userNameList=new ArrayList<>();
|
|
|
+ HttpRespMsg respMsg=new HttpRespMsg();
|
|
|
+ for (int rowIndex = 1; rowIndex <= rowNum; rowIndex++) {
|
|
|
XSSFRow row = sheet.getRow(rowIndex);
|
|
|
if (row == null) {
|
|
|
continue;
|
|
@@ -483,37 +520,25 @@ public class BusinessOpportunityServiceImpl extends ServiceImpl<BusinessOpportun
|
|
|
//获取到当前行的列数据
|
|
|
int cellNum = row.getLastCellNum();
|
|
|
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);
|
|
|
- if (cell != null) {
|
|
|
- switch (item.getString("type")) {
|
|
|
-// case "time":cell.setCellType(CellType.NUMERIC);
|
|
|
-// break;
|
|
|
- default:
|
|
|
- cell.setCellType(CellType.STRING);
|
|
|
- }
|
|
|
- }
|
|
|
- if (modelName.equals("inchargerId")) {
|
|
|
- System.out.println("=====");
|
|
|
- System.out.println(modelName);
|
|
|
- System.out.println(cell.toString());
|
|
|
- if (!StringUtils.isEmpty(cell.getStringCellValue())) {
|
|
|
+ if(modelName.equals("inchargerId")){
|
|
|
+ if(!org.springframework.util.StringUtils.isEmpty(cell.getStringCellValue())){
|
|
|
userNameList.add(cell.getStringCellValue());
|
|
|
}
|
|
|
}
|
|
|
|
|
|
}
|
|
|
}
|
|
|
- System.out.println("参与搜索的人员列表" + userNameList + userNameList.size());
|
|
|
- if (wxCorpInfo != null && wxCorpInfo.getSaasSyncContact() == 1 && userNameList.size() > 0) {
|
|
|
- respMsg = wxCorpInfoService.getBatchSearchUserInfo(wxCorpInfo, userNameList, null);
|
|
|
- if (respMsg.code.equals("0")) {
|
|
|
- msg.setError("姓名为[" + String.valueOf(respMsg.data) + "]的人员存在重复,请使用工号!");
|
|
|
+ System.out.println("参与搜素的人员列表"+userNameList + userNameList.size());
|
|
|
+ if(wxCorpInfo!=null&&wxCorpInfo.getSaasSyncContact()==1&&userNameList.size()>0){
|
|
|
+ respMsg = wxCorpInfoService.getBatchSearchUserInfo(wxCorpInfo, userNameList,null);
|
|
|
+ if(respMsg.code.equals("0")){
|
|
|
+ msg.setError("姓名为["+String.valueOf(respMsg.data)+"]的人员存在重复,请使用工号!");
|
|
|
return msg;
|
|
|
}
|
|
|
}
|
|
|
- List<User> targetUserList = (List<User>) respMsg.data;
|
|
|
+ List<User> targetUserList= (List<User>) respMsg.data;
|
|
|
//直接忽略空行 从row1开始
|
|
|
for (int rowIndex = 1; rowIndex <= rowNum; rowIndex++) {
|
|
|
XSSFRow row = sheet.getRow(rowIndex);
|
|
@@ -526,89 +551,134 @@ public class BusinessOpportunityServiceImpl extends ServiceImpl<BusinessOpportun
|
|
|
}
|
|
|
//获取到当前行的列数据
|
|
|
int cellNum = row.getLastCellNum();
|
|
|
- BusinessOpportunity bo = new BusinessOpportunity();
|
|
|
- bo.setCompanyId(companyId);
|
|
|
- bo.setCreateTime(new Date());
|
|
|
- bo.setCreatorId(user.getId());
|
|
|
+ BusinessOpportunity product=new BusinessOpportunity();
|
|
|
+ product.setCompanyId(companyId);
|
|
|
+ product.setCreatorId(user.getId());
|
|
|
+ product.setCreateTime(new Date());
|
|
|
+ JSONArray objects=new JSONArray();
|
|
|
+ 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 jsonObject1 = columns.getJSONObject(i1).getJSONArray("list").getJSONObject(0);
|
|
|
+ objects.add(jsonObject1);
|
|
|
+ }
|
|
|
+ }else {
|
|
|
+ objects.add(jsonObject);
|
|
|
+ }
|
|
|
+ }
|
|
|
for (int i = 0; i < cellNum; i++) {
|
|
|
- JSONObject item = configObJSONArray.getJSONObject(i);
|
|
|
+ JSONObject item = objects.getJSONObject(i);
|
|
|
String modelName = item.getString("model");
|
|
|
String className = modelName.substring(0, 1).toUpperCase() + modelName.substring(1);
|
|
|
- String getter = "get" + className;
|
|
|
- String setter = "set" + className;
|
|
|
+ String getter="get"+className;
|
|
|
+ String setter="set"+className;
|
|
|
XSSFCell cell = row.getCell(i);
|
|
|
- if (cell != null) {
|
|
|
- switch (item.getString("type")) {
|
|
|
+ if(cell!=null){
|
|
|
+ switch (item.getString("type")){
|
|
|
// case "time":cell.setCellType(CellType.NUMERIC);
|
|
|
// break;
|
|
|
- default:
|
|
|
- cell.setCellType(CellType.STRING);
|
|
|
+ //默认读取所有数据都是文本格式
|
|
|
+ default:cell.setCellType(CellType.STRING);
|
|
|
}
|
|
|
}
|
|
|
- //校验当前列是否为必填
|
|
|
- JSONObject options = item.getJSONObject("options");
|
|
|
- JSONObject rules = options.getJSONObject("rules");
|
|
|
- Boolean required = rules.getBoolean("required");
|
|
|
- if (required) {
|
|
|
- if (StringUtils.isEmpty(cell.getStringCellValue())) {
|
|
|
- msg.setError(item.getString("label") + "值不能为空值");
|
|
|
- return msg;
|
|
|
- }
|
|
|
- }
|
|
|
- if (modelName.equals("inchargerId")) {
|
|
|
- if (!StringUtils.isEmpty(cell.getStringCellValue())) {
|
|
|
+ if(modelName.equals("inchargerId")){
|
|
|
+ if(!org.springframework.util.StringUtils.isEmpty(cell.getStringCellValue())){
|
|
|
String userName = cell.getStringCellValue();
|
|
|
Optional<User> first;
|
|
|
- if (wxCorpInfo != null && wxCorpInfo.getSaasSyncContact() == 1) {
|
|
|
+ if(wxCorpInfo!=null&&wxCorpInfo.getSaasSyncContact()==1){
|
|
|
Optional<User> optional = targetUserList.stream().filter(tl -> tl.getName().equals(userName)).findFirst();
|
|
|
- first = userList.stream().filter(u -> (u.getJobNumber() != null && u.getJobNumber().equals(userName)) || (optional.isPresent() && u.getCorpwxUserid() != null && u.getCorpwxUserid().equals(optional.get().getCorpwxUserid()))).findFirst();
|
|
|
- } else {
|
|
|
- first = userList.stream().filter(u -> u.getName().equals(userName) || (u.getJobNumber() != null && u.getJobNumber().equals(userName))).findFirst();
|
|
|
+ first= userList.stream().filter(u ->(u.getJobNumber()!=null&&u.getJobNumber().equals(userName))||(optional.isPresent()&&u.getCorpwxUserid()!=null&&u.getCorpwxUserid().equals(optional.get().getCorpwxUserid()))).findFirst();
|
|
|
+ }else {
|
|
|
+ first= userList.stream().filter(u -> u.getName().equals(userName)||(u.getJobNumber()!=null&&u.getJobNumber().equals(userName))).findFirst();
|
|
|
}
|
|
|
if (first.isPresent()) {
|
|
|
- bo.setInchargerId(first.get().getId());
|
|
|
+ product.setInchargerId(first.get().getId());
|
|
|
} else {
|
|
|
- msg.setError("负责人[" + userName + "]在系统中不存在");
|
|
|
+ msg.setError("负责人["+userName+"]在系统中不存在");
|
|
|
return msg;
|
|
|
}
|
|
|
}
|
|
|
- } else if (modelName.equals("contactsId")) {
|
|
|
- if (!StringUtils.isEmpty(cell.getStringCellValue())) {
|
|
|
- String userName = cell.getStringCellValue();
|
|
|
- Optional<User> first;
|
|
|
- if (wxCorpInfo != null && wxCorpInfo.getSaasSyncContact() == 1) {
|
|
|
- Optional<User> optional = targetUserList.stream().filter(tl -> tl.getName().equals(userName)).findFirst();
|
|
|
- first = userList.stream().filter(u -> (u.getJobNumber() != null && u.getJobNumber().equals(userName)) || (optional.isPresent() && u.getCorpwxUserid() != null && u.getCorpwxUserid().equals(optional.get().getCorpwxUserid()))).findFirst();
|
|
|
- } else {
|
|
|
- first = userList.stream().filter(u -> u.getName().equals(userName) || (u.getJobNumber() != null && u.getJobNumber().equals(userName))).findFirst();
|
|
|
- }
|
|
|
- if (first.isPresent()) {
|
|
|
- bo.setContactsId(Integer.parseInt(first.get().getId()));
|
|
|
- } else {
|
|
|
- msg.setError("负责人[" + userName + "]在系统中不存在");
|
|
|
+ }else if(modelName.equals("stageId")){
|
|
|
+ if(!StringUtils.isEmpty(cell.getStringCellValue())){
|
|
|
+ Optional<Stage> first = stage.stream().filter(s -> s.getName().equals(cell.getStringCellValue())).findFirst();
|
|
|
+ if(first.isPresent()){
|
|
|
+ product.setStageId(first.get().getId());
|
|
|
+ }else {
|
|
|
+ msg.setError("阶段["+cell.getStringCellValue()+"]不存在,请在阶段设置中增加");
|
|
|
return msg;
|
|
|
}
|
|
|
}
|
|
|
- } else {
|
|
|
- if (!StringUtils.isEmpty(cell.getStringCellValue())) {
|
|
|
- Class<Clue> clueClass = Clue.class;
|
|
|
- Method method = clueClass.getMethod(setter, String.class);
|
|
|
- method.invoke(bo, cell.getStringCellValue());
|
|
|
+ }else if(modelName.equals("contactsId")){
|
|
|
+ if(!StringUtils.isEmpty(cell.getStringCellValue())){
|
|
|
+ Optional<Contacts> first = contacts.stream().filter(s -> s.getName().equals(cell.getStringCellValue())).findFirst();
|
|
|
+ product.setContactsId(first.get().getId());
|
|
|
+ }
|
|
|
+ }else if(modelName.equals("customerId")){
|
|
|
+ if(!StringUtils.isEmpty(cell.getStringCellValue())){
|
|
|
+ Optional<Custom> first = customs.stream().filter(s -> s.getCustomName().equals(cell.getStringCellValue())).findFirst();
|
|
|
+ product.setCustomerId(first.get().getId());
|
|
|
+ }
|
|
|
+ }else if(modelName.equals("expectedTransactionDate")){
|
|
|
+ if(cell != null && cell.getCellTypeEnum() != CellType.BLANK){
|
|
|
+ if(!org.apache.commons.lang3.StringUtils.isEmpty(cell.getStringCellValue())){
|
|
|
+ try {
|
|
|
+ // 假设 cell 是一个代表 Excel 单元格的对象
|
|
|
+ String dateString = cell.getStringCellValue();
|
|
|
+
|
|
|
+ // 定义日期格式
|
|
|
+ SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd");
|
|
|
+
|
|
|
+ // 解析字符串为 Date 类型
|
|
|
+ Date parsedDate = dateFormat.parse(dateString);
|
|
|
+
|
|
|
+ // 设置到对象中
|
|
|
+ product.setExpectedTransactionDate(parsedDate);
|
|
|
+
|
|
|
+ } catch (Exception e) {
|
|
|
+ System.out.println("日期时间格式不正确, 应该是yyyy/MM/dd");
|
|
|
+ msg.setError("日期时间格式不正确, 应该是yyyy/MM/dd");
|
|
|
+ return msg;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }else {
|
|
|
+ if(!StringUtils.isEmpty(cell.getStringCellValue())){
|
|
|
+ Class<BusinessOpportunity> productClass = BusinessOpportunity.class;
|
|
|
+ Method method = productClass.getMethod(setter,String.class);
|
|
|
+ method.invoke(product,cell.getStringCellValue());
|
|
|
}
|
|
|
}
|
|
|
|
|
|
}
|
|
|
- bOMapper.insert(bo);
|
|
|
+ importProductList.add(product);
|
|
|
+ }
|
|
|
+ if(importProductList.size()>0){
|
|
|
+ if(!saveOrUpdateBatch(importProductList)){
|
|
|
+ msg.setError("验证失败,请检验数据格式是否正确");
|
|
|
+ return msg;
|
|
|
+ }
|
|
|
+// List<ActionLog> ads = new ArrayList<>();
|
|
|
+ for (BusinessOpportunity bo : importProductList) {
|
|
|
+ ActionLog actionLog = new ActionLog();
|
|
|
+ actionLog.setName("新增了商机");
|
|
|
+ actionLog.setItemId(bo.getId());
|
|
|
+ actionLog.setCode("business");
|
|
|
+ actionLog.setUserId(user.getId());
|
|
|
+ actionLogMapper.insert(actionLog);
|
|
|
+ }
|
|
|
}
|
|
|
} catch (IOException | NoSuchMethodException e) {
|
|
|
e.printStackTrace();
|
|
|
+ msg.setError("验证失败,请检验数据格式是否正确");
|
|
|
} catch (IllegalAccessException e) {
|
|
|
e.printStackTrace();
|
|
|
} catch (InvocationTargetException e) {
|
|
|
e.printStackTrace();
|
|
|
} catch (Exception e) {
|
|
|
e.printStackTrace();
|
|
|
- msg.setError("验证失败");
|
|
|
+ msg.setError("验证失败,请检验数据格式是否正确");
|
|
|
return msg;
|
|
|
}
|
|
|
return msg;
|