|
@@ -13,21 +13,29 @@ import com.management.platform.mapper.*;
|
|
|
import com.management.platform.service.BusinessOpportunityService;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
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.math.BigDecimal;
|
|
|
import java.net.URLEncoder;
|
|
|
import java.util.*;
|
|
@@ -61,7 +69,11 @@ public class BusinessOpportunityServiceImpl extends ServiceImpl<BusinessOpportun
|
|
|
private SysFormMapper sysFormMapper;
|
|
|
@Autowired
|
|
|
private UploadFileMapper uploadFileMapper;
|
|
|
+ @Resource
|
|
|
+ private HttpServletRequest request;
|
|
|
|
|
|
+ @Resource
|
|
|
+ private SysDictMapper sysDictMapper;
|
|
|
@Override
|
|
|
public List<BusinessOpportunity> getAll(BusinessOpportunity bo) {
|
|
|
return bOMapper.selectAllList(bo);
|
|
@@ -192,28 +204,7 @@ public class BusinessOpportunityServiceImpl extends ServiceImpl<BusinessOpportun
|
|
|
@Value(value = "${upload.file}")
|
|
|
private String path;
|
|
|
|
|
|
- @Override
|
|
|
- public Object exportData(BusinessOpportunity bo, HttpServletRequest request) throws Exception {
|
|
|
- User user = userMapper.selectById(request.getHeader("token"));
|
|
|
- SysForm sysForm = sysFormMapper.selectOne(new LambdaQueryWrapper<SysForm>().eq(SysForm::getCompanyId, user.getCompanyId()).eq(SysForm::getCode, "Clue").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);//设置表头
|
|
|
-
|
|
|
-
|
|
|
- bo.setCompanyId(user.getCompanyId());
|
|
|
|
|
|
- String fileName = "商机表导出_" + System.currentTimeMillis();
|
|
|
- return excelExportService.exportGeneralExcelByTitleAndList(wxCorpInfo, fileName, dataList, path);
|
|
|
- }
|
|
|
|
|
|
@Override
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
@@ -380,6 +371,191 @@ public class BusinessOpportunityServiceImpl extends ServiceImpl<BusinessOpportun
|
|
|
bOMapper.deleteBatchIds(ids);
|
|
|
}
|
|
|
|
|
|
+ @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, "Thread").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();
|
|
|
+ BusinessOpportunity bo =new BusinessOpportunity();
|
|
|
+ bo.setCompanyId(companyId);
|
|
|
+ bo.setCreateTime(new Date());
|
|
|
+ bo.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")){
|
|
|
+// case "time":cell.setCellType(CellType.NUMERIC);
|
|
|
+// break;
|
|
|
+ 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()) {
|
|
|
+ bo.setInchargerId(first.get().getId());
|
|
|
+ } else {
|
|
|
+ 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+"]在系统中不存在");
|
|
|
+ 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());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ bOMapper.insert(bo);
|
|
|
+ }
|
|
|
+ } 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;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public HttpRespMsg exportData(BusinessOpportunity bo) {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
private BusinessOpportunity setNull(BusinessOpportunity bo) {
|
|
|
if (bo.getPlate1() == "") {
|
|
|
bo.setPlate1(null);
|