|
@@ -1,5 +1,9 @@
|
|
|
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.query.LambdaQueryWrapper;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
|
|
|
import com.management.platform.entity.*;
|
|
@@ -8,20 +12,30 @@ import com.management.platform.mapper.*;
|
|
|
import com.management.platform.service.CustomService;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
import com.management.platform.service.SysFunctionService;
|
|
|
+import com.management.platform.service.WxCorpInfoService;
|
|
|
+import com.management.platform.util.ExcelUtil;
|
|
|
import com.management.platform.util.FileUtil;
|
|
|
import com.management.platform.util.HttpRespMsg;
|
|
|
import com.management.platform.util.MessageUtils;
|
|
|
+import org.apache.poi.ss.usermodel.CellType;
|
|
|
+import org.apache.poi.xssf.usermodel.XSSFCell;
|
|
|
+import org.apache.poi.xssf.usermodel.XSSFRow;
|
|
|
+import org.apache.poi.xssf.usermodel.XSSFSheet;
|
|
|
+import org.apache.poi.xssf.usermodel.XSSFWorkbook;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
+import org.springframework.util.StringUtils;
|
|
|
import org.springframework.web.multipart.MultipartFile;
|
|
|
|
|
|
+import javax.annotation.Resource;
|
|
|
import javax.servlet.ServletOutputStream;
|
|
|
import javax.servlet.http.HttpServletRequest;
|
|
|
import javax.servlet.http.HttpServletResponse;
|
|
|
-import java.io.File;
|
|
|
-import java.io.IOException;
|
|
|
+import java.io.*;
|
|
|
+import java.lang.reflect.InvocationTargetException;
|
|
|
+import java.lang.reflect.Method;
|
|
|
import java.net.URLEncoder;
|
|
|
import java.util.*;
|
|
|
|
|
@@ -43,12 +57,25 @@ public class CustomServiceImpl extends ServiceImpl<CustomMapper, Custom> impleme
|
|
|
private BusinessItemCustomMapper businessItemCustomMapper;
|
|
|
@Autowired
|
|
|
private CustomItemContactsMapper customItemContactsMapper;
|
|
|
+ @Resource
|
|
|
+ private ExcelExportServiceImpl excelExportService;
|
|
|
+ @Resource
|
|
|
+ private SysFormMapper sysFormMapper;
|
|
|
+ @Autowired
|
|
|
+ private WxCorpInfoService wxCorpInfoService;
|
|
|
@Autowired
|
|
|
private ActionLogMapper actionLogMapper;
|
|
|
|
|
|
@Autowired
|
|
|
private UploadFileMapper uploadFileMapper;
|
|
|
|
|
|
+
|
|
|
+ @Resource
|
|
|
+ private HttpServletRequest request;
|
|
|
+
|
|
|
+ @Resource
|
|
|
+ private SysDictMapper sysDictMapper;
|
|
|
+
|
|
|
@Autowired
|
|
|
private BusinessOpportunityMapper businessOpportunityMapper;
|
|
|
@Autowired
|
|
@@ -99,6 +126,13 @@ public class CustomServiceImpl extends ServiceImpl<CustomMapper, Custom> impleme
|
|
|
// msg.setError("电话号码重复了");
|
|
|
return msg;
|
|
|
}
|
|
|
+
|
|
|
+ if (custom.getCustomName() != null && contactsMapper.selectCount(new QueryWrapper<Contacts>()
|
|
|
+ .eq("name", custom.getContactsName())
|
|
|
+ ) == 0) {
|
|
|
+ msg.setError("此联系人不存在");
|
|
|
+ return msg;
|
|
|
+ }
|
|
|
custom.setCreateTime(new Date());
|
|
|
custom.setCreatorId(user.getId());
|
|
|
custom.setIsDelete(0);
|
|
@@ -110,6 +144,13 @@ public class CustomServiceImpl extends ServiceImpl<CustomMapper, Custom> impleme
|
|
|
actionLog.setItemId(custom.getId());
|
|
|
actionLogMapper.insert(actionLog);
|
|
|
customMapper.insert(custom);
|
|
|
+ if (custom.getCustomName() != null && custom.getCustomName()!="" &&custom.getTelPhone() !="" &&custom.getTelPhone()!=null){
|
|
|
+ Contacts contacts = contactsMapper.selectOne(new QueryWrapper<Contacts>().eq("name", custom.getCustomName()).eq("phone", custom.getTelPhone()));
|
|
|
+ if (contacts != null){
|
|
|
+ contacts.setCustomId(custom.getId());
|
|
|
+ contactsMapper.update(contacts,new UpdateWrapper<Contacts>().eq("id",contacts.getId()));
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
msg.setMsg("操作成功");
|
|
|
return msg;
|
|
@@ -170,6 +211,8 @@ public class CustomServiceImpl extends ServiceImpl<CustomMapper, Custom> impleme
|
|
|
customMapper.update(custom, updateWrapper);
|
|
|
}
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private SalesOrderMapper salesOrderMapper;
|
|
|
@Override
|
|
|
public HttpRespMsg getInfo(Custom custom, HttpServletRequest request) {
|
|
|
Custom custom1 = customMapper.getInfo(custom.getId());
|
|
@@ -180,15 +223,19 @@ public class CustomServiceImpl extends ServiceImpl<CustomMapper, Custom> impleme
|
|
|
custom1.setBusinessOpportunitys(businessOpportunityMapper.selectList(new QueryWrapper<BusinessOpportunity>().eq("customer_id",custom1.getId())));
|
|
|
//操作记录
|
|
|
custom1.setActionLogs(actionLogMapper.selectList(new QueryWrapper<ActionLog>().eq("code","custom").eq("item_id",custom1.getId())));
|
|
|
- List<CustomItemContacts> contacts = customItemContactsMapper.selectList(new QueryWrapper<CustomItemContacts>().eq("contacts_id", custom1.getId()));
|
|
|
- List<Integer> ids = new ArrayList<>();
|
|
|
- for (CustomItemContacts contact : contacts) {
|
|
|
- ids.add(contact.getCustomId());
|
|
|
- }
|
|
|
- if (ids.size() > 0){
|
|
|
- List<Contacts> cs = contactsMapper.selectListByIds(ids);
|
|
|
- custom1.setContactsList(cs);
|
|
|
- }
|
|
|
+// List<CustomItemContacts> contacts = customItemContactsMapper.selectList(new QueryWrapper<CustomItemContacts>().eq("contacts_id", custom1.getId()));
|
|
|
+// List<Integer> ids = new ArrayList<>();
|
|
|
+// for (CustomItemContacts contact : contacts) {
|
|
|
+// ids.add(contact.getCustomId());
|
|
|
+// }
|
|
|
+// if (ids.size() > 0){
|
|
|
+// List<Contacts> cs = contactsMapper.selectListByIds(ids);
|
|
|
+// custom1.setContactsList(cs);
|
|
|
+// }
|
|
|
+ //联系人
|
|
|
+ custom1.setContacts(contactsMapper.selectList((new QueryWrapper<Contacts>().eq("custom_id",custom1.getId()))));
|
|
|
+ //订单
|
|
|
+ custom1.setSalesOrders(salesOrderMapper.selectList((new QueryWrapper<SalesOrder>().eq("custom_id",custom1.getId()))));
|
|
|
HttpRespMsg httpRespMsg = new HttpRespMsg();
|
|
|
httpRespMsg.setData(custom1);
|
|
|
return httpRespMsg;
|
|
@@ -432,6 +479,168 @@ public class CustomServiceImpl extends ServiceImpl<CustomMapper, Custom> impleme
|
|
|
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
+ public HttpRespMsg importData(MultipartFile multipartFile) {
|
|
|
+ HttpRespMsg msg=new HttpRespMsg();
|
|
|
+ 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"));
|
|
|
+ InputStream inputStream = null;
|
|
|
+ OutputStream outputStream = null;
|
|
|
+ try {
|
|
|
+ inputStream = multipartFile.getInputStream();
|
|
|
+ outputStream = new FileOutputStream(file);
|
|
|
+ byte[] buffer = new byte[4096];
|
|
|
+ int temp = 0;
|
|
|
+ while ((temp = inputStream.read(buffer, 0, 4096)) != -1) {
|
|
|
+ outputStream.write(buffer, 0, temp);
|
|
|
+ }
|
|
|
+ inputStream.close();
|
|
|
+ outputStream.close();
|
|
|
+ //解析表格
|
|
|
+ XSSFWorkbook workbook = new XSSFWorkbook(file);
|
|
|
+ //我们只需要第一个sheet
|
|
|
+ XSSFSheet sheet = workbook.getSheetAt(0);
|
|
|
+ //由于第一行需要指明列对应的标题
|
|
|
+ int rowNum = sheet.getLastRowNum();
|
|
|
+ //获取当前表单模板 校验规则
|
|
|
+ SysForm sysForm = sysFormMapper.selectOne(new LambdaQueryWrapper<SysForm>().eq(SysForm::getCode, "Customer").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++) {
|
|
|
+ XSSFRow row = sheet.getRow(rowIndex);
|
|
|
+ if (row == null) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ //跳过空行
|
|
|
+ if (ExcelUtil.isRowEmpty(row)) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ //获取到当前行的列数据
|
|
|
+ int cellNum = row.getLastCellNum();
|
|
|
+ for (int i = 0; i < cellNum; i++) {
|
|
|
+ JSONObject item = configObJSONArray.getJSONObject(i);
|
|
|
+ String modelName = item.getString("model");
|
|
|
+ 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())){
|
|
|
+ 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)+"]的人员存在重复,请使用工号!");
|
|
|
+ return msg;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ List<User> targetUserList= (List<User>) respMsg.data;
|
|
|
+ //直接忽略空行 从row1开始
|
|
|
+ for (int rowIndex = 1; rowIndex <= rowNum; rowIndex++) {
|
|
|
+ XSSFRow row = sheet.getRow(rowIndex);
|
|
|
+ if (row == null) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ //跳过空行
|
|
|
+ if (ExcelUtil.isRowEmpty(row)) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ //获取到当前行的列数据
|
|
|
+ int cellNum = row.getLastCellNum();
|
|
|
+ Custom custom =new Custom();
|
|
|
+ custom.setCompanyId(companyId);
|
|
|
+ custom.setCreateTime(new Date());
|
|
|
+ custom.setCreatorId(user.getId());
|
|
|
+ for (int i = 0; i < cellNum; i++) {
|
|
|
+ JSONObject item = configObJSONArray.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;
|
|
|
+ XSSFCell cell = row.getCell(i);
|
|
|
+ if(cell!=null){
|
|
|
+ switch (item.getString("type")){
|
|
|
+
|
|
|
+ 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())){
|
|
|
+ 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()) {
|
|
|
+ custom.setInchargerId(first.get().getId());
|
|
|
+ } else {
|
|
|
+ msg.setError("负责人["+userName+"]在系统中不存在");
|
|
|
+ return msg;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }else {
|
|
|
+ if(!StringUtils.isEmpty(cell.getStringCellValue())){
|
|
|
+ Class<Clue> clueClass = Clue.class;
|
|
|
+ Method method = clueClass.getMethod(setter,String.class);
|
|
|
+ method.invoke(custom,cell.getStringCellValue());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ customMapper.insert(custom);
|
|
|
+ }
|
|
|
+ } catch (IOException | NoSuchMethodException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ } catch (IllegalAccessException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ } catch (InvocationTargetException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ msg.setError("验证失败");
|
|
|
+ return msg;
|
|
|
+ }
|
|
|
+ return msg;
|
|
|
+ }
|
|
|
+
|
|
|
|
|
|
private Custom setNull(Custom clue) {
|
|
|
if (clue.getPlate1() == "") {
|