Commit 93823108 by 邓实川 Committed by chenzg

excel读取方式改为直接从OSS读取

parent 7aa4a7ff
......@@ -8,6 +8,8 @@
package cn.timer.api.controller.crm;
import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
......@@ -18,7 +20,6 @@ import java.util.Map;
import java.util.stream.Collectors;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
......@@ -34,7 +35,6 @@ import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.io.resource.ResourceUtil;
import cn.hutool.core.util.StrUtil;
import cn.hutool.poi.excel.ExcelReader;
import cn.hutool.poi.excel.ExcelUtil;
......@@ -52,7 +52,6 @@ import cn.timer.api.bean.crm.CrmSeaRule;
import cn.timer.api.bean.yggl.YgglMainEmp;
import cn.timer.api.config.annotation.CurrentUser;
import cn.timer.api.config.annotation.UserBean;
import cn.timer.api.controller.dzht.cn.tign.hz.comm.FileHelper;
import cn.timer.api.dao.crm.CrmClientContactsMapper;
import cn.timer.api.dao.crm.CrmClientDataMapper;
import cn.timer.api.dto.crm.CrmClientDataImportVo;
......@@ -77,8 +76,8 @@ import io.swagger.annotations.ApiOperation;
@RequestMapping(value = "/crm", produces = { "application/json" })
public class CrmController {
@Value(value = "${config-8timer.crm-excel.realPath}")
private String realPath;
// @Value(value = "${config-8timer.crm-excel.realPath}")
// private String realPath;
@Autowired
private CrmClientDataMapper crmClientDataMapper;
......@@ -104,6 +103,13 @@ public class CrmController {
return getYg(orgCode, empNum).getName();
}
private Integer getQyzxManager(Integer orgCode, Integer empNum) {
return YgglMainEmp.builder().build()
.selectOne(new QueryWrapper<YgglMainEmp>().lambda().eq(YgglMainEmp::getOrgCode, orgCode)
.eq(YgglMainEmp::getEmpNum, empNum).select(YgglMainEmp::getIsManager))
.getIsManager();
}
@GetMapping("getIndustry")
@ApiOperation(value = "获取行业列表", httpMethod = "GET", notes = "接口发布说明")
public Result<List<IndustryClass>> getIndustry(@CurrentUser UserBean userBean) {
......@@ -212,22 +218,30 @@ public class CrmController {
@GetMapping("getBusinessGroup")
@ApiOperation(value = "获取业务组列表", httpMethod = "GET", notes = "接口发布说明")
public Result<Object> getBusinessGroup(@CurrentUser UserBean userBean) {
Integer nowEmpNum = getEmpNum(userBean);
Integer orgCode = getOrgCode(userBean);
Integer isManager = getQyzxManager(orgCode, nowEmpNum);
if (isManager != null && (isManager == 1 || isManager == 2)) {
List<CrmBusinessGroup> list = CrmBusinessGroup.builder().build()
.selectList(new QueryWrapper<CrmBusinessGroup>().lambda()
.eq(CrmBusinessGroup::getOrgCode, getOrgCode(userBean)).select(CrmBusinessGroup::getId,
CrmBusinessGroup::getSort, CrmBusinessGroup::getName, CrmBusinessGroup::getModifyTime));
CrmBusinessGroup::getSort, CrmBusinessGroup::getName,
CrmBusinessGroup::getModifyTime));
for (CrmBusinessGroup crmBusinessGroup : list) {
Integer gid = crmBusinessGroup.getId();
List<CrmBusinessGroupMember> crmBusinessGroupManagers = CrmBusinessGroupMember.builder().build().selectList(
new QueryWrapper<CrmBusinessGroupMember>().lambda().eq(CrmBusinessGroupMember::getGid, gid)
.eq(CrmBusinessGroupMember::getType, 1).select(CrmBusinessGroupMember::getEmpNum));
List<CrmBusinessGroupMember> crmBusinessGroupMembers = CrmBusinessGroupMember.builder().build().selectList(
new QueryWrapper<CrmBusinessGroupMember>().lambda().eq(CrmBusinessGroupMember::getGid, gid)
.eq(CrmBusinessGroupMember::getType, 0).select(CrmBusinessGroupMember::getEmpNum));
List<CrmBusinessGroupMember> crmBusinessGroupManagers = CrmBusinessGroupMember.builder().build()
.selectList(new QueryWrapper<CrmBusinessGroupMember>().lambda()
.eq(CrmBusinessGroupMember::getGid, gid).eq(CrmBusinessGroupMember::getType, 1)
.select(CrmBusinessGroupMember::getEmpNum));
List<CrmBusinessGroupMember> crmBusinessGroupMembers = CrmBusinessGroupMember.builder().build()
.selectList(new QueryWrapper<CrmBusinessGroupMember>().lambda()
.eq(CrmBusinessGroupMember::getGid, gid).eq(CrmBusinessGroupMember::getType, 0)
.select(CrmBusinessGroupMember::getEmpNum));
List<Map<String, Object>> managers = new ArrayList<Map<String, Object>>();
for (CrmBusinessGroupMember crmBusinessGroupManager : crmBusinessGroupManagers) {
Integer empNum = crmBusinessGroupManager.getEmpNum();
String name = getEmpName(getOrgCode(userBean), empNum);
String name = getEmpName(orgCode, empNum);
Map<String, Object> map = new HashMap<String, Object>();
map.put("name", name);
map.put("empNum", empNum);
......@@ -238,7 +252,7 @@ public class CrmController {
List<Map<String, Object>> members = new ArrayList<Map<String, Object>>();
for (CrmBusinessGroupMember crmBusinessGroupManager : crmBusinessGroupMembers) {
Integer empNum = crmBusinessGroupManager.getEmpNum();
String name = getEmpName(getOrgCode(userBean), empNum);
String name = getEmpName(orgCode, empNum);
Map<String, Object> map = new HashMap<String, Object>();
map.put("name", name);
map.put("empNum", empNum);
......@@ -251,6 +265,10 @@ public class CrmController {
crmBusinessGroup.setCrmSeaRules(crmSeaRules);
}
return ResultUtil.data(list, "获取成功");
} else
return ResultUtil.error("暂无查看权限");
}
@GetMapping("getBusinessGroupId")
......@@ -264,7 +282,6 @@ public class CrmController {
.distinct().collect(Collectors.toList());
List<Map<String, Object>> result = new ArrayList<Map<String, Object>>();
for (Integer gid : gids) {
System.err.println(gid);
String name = CrmBusinessGroup.builder().build().selectOne(new LambdaQueryWrapper<CrmBusinessGroup>()
.eq(CrmBusinessGroup::getId, gid).select(CrmBusinessGroup::getName)).getName();
Map<String, Object> map = new HashMap<String, Object>();
......@@ -1063,19 +1080,20 @@ public class CrmController {
Integer empNum = getEmpNum(userBean);
Integer orgCode = getOrgCode(userBean);
String filePath = null;
String time = null;
try {
time = DateUtil.format(new Date(), "yyyyMMddHHmmssSSS");
filePath = FileHelper.downLoadFromUrl(url, time + ".xls", realPath);
System.err.println(filePath);
} catch (IOException e) {
e.printStackTrace();
}
// String filePath = null;
// String time = null;
// try {
// time = DateUtil.format(new Date(), "yyyyMMddHHmmssSSS");
// filePath = FileHelper.downLoadFromUrl(url, time + ".xls", realPath);
// } catch (IOException e) {
// e.printStackTrace();
// }
// 从文件中读取Excel为ExcelReader
ExcelReader reader;
// 从流中读取Excel为ExcelReader(比如从ClassPath中读取Excel文件)
reader = ExcelUtil.getReader(ResourceUtil.getStream(filePath));
// reader = ExcelUtil.getReader(ResourceUtil.getStream(filePath));
// 从网络流OSS中读取excel资源
reader = getReaderByUrl(url);
reader.addHeaderAlias("*客户名称(必填)", "clientName");
reader.addHeaderAlias("*所属分组(必填)", "belongGroupName");
reader.addHeaderAlias("行业", "industryName");
......@@ -1095,7 +1113,6 @@ public class CrmController {
reader.addHeaderAlias("个人地址", "linkAddress");
List<CrmClientDataImportVo> list = reader.read(0, 1, CrmClientDataImportVo.class);
for (CrmClientDataImportVo crmClientDataImportVo : list) {
System.err.println(crmClientDataImportVo);
String clientName = crmClientDataImportVo.getClientName(); // 客户名称(必填)
String belongGroupName = crmClientDataImportVo.getBelongGroupName(); // 分组名(必填)
......@@ -1121,7 +1138,7 @@ public class CrmController {
// 业务组
CrmBusinessGroup crmBusinessGroup = CrmBusinessGroup.builder().build()
.selectOne(new LambdaQueryWrapper<CrmBusinessGroup>()
.eq(CrmBusinessGroup::getOrgCode, userBean.getOrgCode())
.eq(CrmBusinessGroup::getOrgCode, orgCode)
.eq(CrmBusinessGroup::getName, belongGroupName).select(CrmBusinessGroup::getId));
if (crmBusinessGroup == null)
return ResultUtil.error("没有匹配的业务组名称");
......@@ -1188,4 +1205,14 @@ public class CrmController {
}
return ResultUtil.success("导入成功");
}
private ExcelReader getReaderByUrl(String url) {
InputStream is = null;
try {
is = new URL(url).openConnection().getInputStream();
} catch (IOException e) {
e.printStackTrace();
}
return ExcelUtil.getReader(is);
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment