|
@@ -3,6 +3,7 @@ package com.management.platform.service.impl;
|
|
|
import com.alibaba.fastjson.JSON;
|
|
|
import com.alibaba.fastjson.JSONArray;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
+import com.baomidou.mybatisplus.core.conditions.Wrapper;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
|
|
@@ -377,7 +378,6 @@ public class ContactsServiceImpl extends ServiceImpl<ContactsMapper, Contacts> i
|
|
|
User user = userMapper.selectById(request.getHeader("token"));
|
|
|
Integer companyId = user.getCompanyId();
|
|
|
WxCorpInfo wxCorpInfo = wxCorpInfoService.getOne(new LambdaQueryWrapper<WxCorpInfo>().eq(WxCorpInfo::getCompanyId, companyId));
|
|
|
- List<Contacts> contactsList = contactsMapper.selectList(new LambdaQueryWrapper<Contacts>().eq(Contacts::getCompanyId, companyId));
|
|
|
List<User> userList = userMapper.selectList(new LambdaQueryWrapper<User>().eq(User::getCompanyId, companyId));
|
|
|
InputStream inputStream = null;
|
|
|
OutputStream outputStream = null;
|
|
@@ -412,6 +412,10 @@ public class ContactsServiceImpl extends ServiceImpl<ContactsMapper, Contacts> i
|
|
|
|
|
|
//可能存在栅格布局的情况需要特殊处理
|
|
|
List<String> modelNameList=new ArrayList<>();
|
|
|
+ List<String> typeList=new ArrayList<>();
|
|
|
+ List<String> labelList=new ArrayList<>();
|
|
|
+ List<Boolean> requiredList=new ArrayList<>();
|
|
|
+
|
|
|
for (int i = 0; i < configObJSONArray.size(); i++) {
|
|
|
JSONObject jsonObject = configObJSONArray.getJSONObject(i);
|
|
|
if(jsonObject.getString("type").equals("grid")){
|
|
@@ -422,10 +426,18 @@ public class ContactsServiceImpl extends ServiceImpl<ContactsMapper, Contacts> i
|
|
|
for (int i2 = 0; i2 < list.size(); i2++) {
|
|
|
JSONObject object = list.getJSONObject(i2);
|
|
|
modelNameList.add(object.getString("model"));
|
|
|
+ typeList.add(object.getString("type"));
|
|
|
+ labelList.add(object.getString("label"));
|
|
|
+ Boolean required = object.getJSONObject("options").getJSONObject("rules").getBoolean("required");
|
|
|
+ requiredList.add(required);
|
|
|
}
|
|
|
}
|
|
|
}else {
|
|
|
modelNameList.add(jsonObject.getString("model"));
|
|
|
+ typeList.add(jsonObject.getString("type"));
|
|
|
+ labelList.add(jsonObject.getString("label"));
|
|
|
+ Boolean required = jsonObject.getJSONObject("options").getJSONObject("rules").getBoolean("required");
|
|
|
+ requiredList.add(required);
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -497,18 +509,13 @@ public class ContactsServiceImpl extends ServiceImpl<ContactsMapper, Contacts> i
|
|
|
contacts.setCompanyId(companyId);
|
|
|
contacts.setCreatorId(user.getId());
|
|
|
for (int i = 0; i < cellNum; i++) {
|
|
|
- JSONObject item = configObJSONArray.getJSONObject(i);
|
|
|
- String modelName = item.getString("model");
|
|
|
+ String modelName = modelNameList.get(i);
|
|
|
String className = modelName.substring(0, 1).toUpperCase() + modelName.substring(1);
|
|
|
String getter="get"+className;
|
|
|
String setter="set"+className;
|
|
|
XSSFCell cell = row.getCell(i);
|
|
|
if(cell!=null){
|
|
|
- switch (item.getString("type")){
|
|
|
- case "time":cell.setCellType(CellType.NUMERIC);
|
|
|
- break;
|
|
|
- case "int":cell.setCellType(CellType.NUMERIC);
|
|
|
- break;
|
|
|
+ switch (typeList.get(i)){
|
|
|
default:cell.setCellType(CellType.STRING);
|
|
|
}
|
|
|
}
|
|
@@ -517,25 +524,36 @@ public class ContactsServiceImpl extends ServiceImpl<ContactsMapper, Contacts> i
|
|
|
Class<?> type = field.getType();
|
|
|
Method method = contactsClass.getMethod(setter, type);
|
|
|
//校验当前列是否为必填
|
|
|
- JSONObject options = item.getJSONObject("options");
|
|
|
- JSONObject rules = options.getJSONObject("rules");
|
|
|
- Boolean required = rules.getBoolean("required");
|
|
|
- if(required){
|
|
|
+ if(requiredList.get(i)){
|
|
|
if(StringUtils.isEmpty(cell.getStringCellValue())){
|
|
|
- msg.setError(item.getString("label")+"值不能为空值");
|
|
|
+ msg.setError(labelList.get(i)+"值不能为空值");
|
|
|
return msg;
|
|
|
}
|
|
|
}
|
|
|
- /*if(modelName.equals("contactsCode")){
|
|
|
- if(!org.springframework.util.StringUtils.isEmpty(cell.getStringCellValue())){
|
|
|
- //系统中同公司已存在的产品编码 更新
|
|
|
- Optional<Contacts> first = contactsList.stream().filter(p ->p.getContactsCode()!=null&& p.getContactsCode().equals(cell.getStringCellValue())).findFirst();
|
|
|
- if(first.isPresent()){
|
|
|
- contacts.setId(first.get().getId());
|
|
|
+ if(modelName.equals("customId")){
|
|
|
+ if(!StringUtils.isEmpty(cell.getStringCellValue())){
|
|
|
+ String customerName = cell.getStringCellValue();
|
|
|
+ List<Custom> customList = customMapper.selectList(new QueryWrapper<Custom>().eq("custom_name", customerName));
|
|
|
+ if (customList!=null&&!customList.isEmpty()){
|
|
|
+ Custom custom = customList.get(0);
|
|
|
+ contacts.setCustomId(custom.getId());
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ msg.setError("负责人["+customerName+"]在系统中不存在");
|
|
|
+ return msg;
|
|
|
}
|
|
|
}
|
|
|
- }*/
|
|
|
- if(modelName.equals("inchargerId")){
|
|
|
+ }else if(modelName.equals("sex")){
|
|
|
+ if(!StringUtils.isEmpty(cell.getStringCellValue())){
|
|
|
+ String stringCellValue = cell.getStringCellValue();
|
|
|
+ if (stringCellValue.equals("男")){
|
|
|
+ contacts.setSex(1);
|
|
|
+ } else if (stringCellValue.equals("女")) {
|
|
|
+ contacts.setSex(0);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else if(modelName.equals("ownerId")){
|
|
|
if(!StringUtils.isEmpty(cell.getStringCellValue())){
|
|
|
String userName = cell.getStringCellValue();
|
|
|
Optional<User> first;
|
|
@@ -551,30 +569,12 @@ public class ContactsServiceImpl extends ServiceImpl<ContactsMapper, Contacts> i
|
|
|
throw new Exception("["+userName+"]在系统中不存在");
|
|
|
}
|
|
|
}
|
|
|
- }
|
|
|
- /*if(cell.getCellType()==CellType.STRING.getCode()&&!StringUtils.isEmpty(cell.getStringCellValue())){
|
|
|
- method.invoke(contacts,cell.getStringCellValue());
|
|
|
- } else if (cell.getCellType()==CellType.NUMERIC.getCode()) {
|
|
|
-
|
|
|
-
|
|
|
- }*/
|
|
|
- if (cell != null && cell.getCellTypeEnum() != CellType.BLANK) {
|
|
|
- if (cell.getCellTypeEnum() == CellType.STRING && cell.getStringCellValue() != null && !cell.getStringCellValue().isEmpty()) {
|
|
|
- // 字符串类型不为空
|
|
|
+ }else{
|
|
|
+ if(!StringUtils.isEmpty(cell.getStringCellValue())){
|
|
|
+ System.out.println(cell.getStringCellValue());
|
|
|
method.invoke(contacts,cell.getStringCellValue());
|
|
|
- } else if (cell.getCellTypeEnum() == CellType.NUMERIC) {
|
|
|
- // 数值类型不为空
|
|
|
- double numericCellValue = cell.getNumericCellValue();
|
|
|
- if (type.getSimpleName().equals("Integer")){
|
|
|
- int intValue = (int) numericCellValue;
|
|
|
- method.invoke(contacts,intValue);
|
|
|
- }
|
|
|
- else {
|
|
|
- method.invoke(contacts, numericCellValue);
|
|
|
- }
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
}
|
|
|
importContactsList.add(contacts);
|
|
|
}
|