|
|
@ -401,80 +401,94 @@ public class StoreEmployeeService {
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* @param response
|
|
|
|
* @param response
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
public void exportStoreExcel(HttpServletResponse response) throws Exception {
|
|
|
|
public void exportStoreExcel(HttpServletResponse response, Long userId, Long regionId, Long companyId, Long storeId, String code) throws Exception {
|
|
|
|
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
|
|
|
|
List<StoreUserDTO> results = new ArrayList<>();
|
|
|
|
|
|
|
|
List<Long> shopIds = new ArrayList<>();
|
|
|
|
|
|
|
|
if (storeId != null) {
|
|
|
|
|
|
|
|
shopIds.add(storeId);
|
|
|
|
|
|
|
|
} else if (StringUtils.isNotBlank(code)) {
|
|
|
|
|
|
|
|
List<PoiStore> store = poiStoreDOMapper.selectShopByNameOrCode(code);
|
|
|
|
|
|
|
|
shopIds = store.stream().map(i -> i.getId()).collect(Collectors.toList());
|
|
|
|
|
|
|
|
List<Long> userAllShops = privilageDomainService.listUserDatePermission(userId);
|
|
|
|
|
|
|
|
shopIds.retainAll(userAllShops);
|
|
|
|
|
|
|
|
} else if (companyId != null) {
|
|
|
|
|
|
|
|
shopIds = new ArrayList<>(customerViewService.getCompanyShop(companyId, userId));
|
|
|
|
|
|
|
|
List<Long> userAllShops = privilageDomainService.listUserDatePermission(userId);
|
|
|
|
|
|
|
|
shopIds.retainAll(userAllShops);
|
|
|
|
|
|
|
|
} else if (regionId != null) {
|
|
|
|
|
|
|
|
shopIds = new ArrayList<>(customerViewService.getCompanyShop(regionId, userId));
|
|
|
|
|
|
|
|
List<Long> userAllShops = privilageDomainService.listUserDatePermission(userId);
|
|
|
|
|
|
|
|
shopIds.retainAll(userAllShops);
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
//查询用户权限店铺
|
|
|
|
|
|
|
|
shopIds = new ArrayList<>(privilageDomainService.listUserDatePermission(userId));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
List<StoreUserDTO> cpUserStoreDO = privilageCpUserStoreDOMapper.selectCpUserByShops(shopIds);
|
|
|
|
|
|
|
|
if (CollectionUtils.isNotEmpty(cpUserStoreDO)) {
|
|
|
|
|
|
|
|
int orderNum = 0;
|
|
|
|
|
|
|
|
for (StoreUserDTO cpUserStore : cpUserStoreDO) {
|
|
|
|
|
|
|
|
//设置序号
|
|
|
|
|
|
|
|
cpUserStore.setOrderNum(++orderNum);
|
|
|
|
|
|
|
|
//查询店铺绑定的企业微信
|
|
|
|
|
|
|
|
PoiStore poiStore = poiStoreDOMapper.selectById(cpUserStore.getId());
|
|
|
|
|
|
|
|
if (null != poiStore) {
|
|
|
|
|
|
|
|
cpUserStore.setName(poiStore.getName());
|
|
|
|
|
|
|
|
cpUserStore.setCode(poiStore.getCode());
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
//客户orgId
|
|
|
|
|
|
|
|
Long customerId = privilageDomainEntityDOMapper.selectDomainIdByShopEntity(cpUserStore.getId());
|
|
|
|
|
|
|
|
|
|
|
|
List<CpUserExcelDTO> results = new ArrayList<>();
|
|
|
|
if (customerId != null){
|
|
|
|
|
|
|
|
PrivilageOrganizational customer = retailCompanyMapper.selectById(customerId);
|
|
|
|
|
|
|
|
PrivilageOrganizational company = retailCompanyMapper.selectById(customer.getParentId());
|
|
|
|
|
|
|
|
PrivilageOrganizational region = retailCompanyMapper.selectById(company.getParentId());
|
|
|
|
|
|
|
|
|
|
|
|
//查询大区
|
|
|
|
cpUserStore.setCompanyName(company.getName());
|
|
|
|
QueryWrapper<PrivilageOrganizational> regionWrapper = new QueryWrapper<>();
|
|
|
|
cpUserStore.setCompanyCode(company.getCode());
|
|
|
|
regionWrapper.eq("status", 1).eq("type", 2).eq("level", 1);
|
|
|
|
cpUserStore.setRegionName(region.getName());
|
|
|
|
List<PrivilageOrganizational> regions = retailCompanyMapper.selectList(regionWrapper);
|
|
|
|
|
|
|
|
if (CollectionUtils.isNotEmpty(regions)){
|
|
|
|
|
|
|
|
for (PrivilageOrganizational region:regions){
|
|
|
|
|
|
|
|
if (region == null || region.getId() == null) {
|
|
|
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
//查询所有公司
|
|
|
|
|
|
|
|
QueryWrapper<PrivilageOrganizational> queryWrapper = new QueryWrapper<>();
|
|
|
|
String qrCodeAction = cpUserStore.getQrCodeAction();
|
|
|
|
queryWrapper.eq("status", 1).eq("type", 2).eq("level", 2).eq("parent_id",region.getId());
|
|
|
|
if (StringUtils.isBlank(qrCodeAction)){
|
|
|
|
List<PrivilageOrganizational> privilageOrganizationals = retailCompanyMapper.selectList(queryWrapper);
|
|
|
|
qrCodeAction = getQrCodeFromBSD(cpUserStore.getCpUserId(),BSD_REQ_QRCODE_TYPE_STORE,"0",cpUserStore.getCode());
|
|
|
|
if (CollectionUtils.isNotEmpty(privilageOrganizationals)) {
|
|
|
|
cpUserStore.setQrCodeAction(qrCodeAction);
|
|
|
|
//遍历零售公司
|
|
|
|
PrivilageCpUserDO update = new PrivilageCpUserDO();
|
|
|
|
for (PrivilageOrganizational privilageOrganizational : privilageOrganizationals) {
|
|
|
|
update.setId(cpUserStore.getUserId());
|
|
|
|
if (privilageOrganizational == null || privilageOrganizational.getId() == null) {
|
|
|
|
update.setQrCode(qrCodeAction);
|
|
|
|
continue;
|
|
|
|
privilageCpUserDOMapper.updateById(update);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
//查询客户
|
|
|
|
|
|
|
|
QueryWrapper<PrivilageOrganizational> customerWrap = new QueryWrapper<>();
|
|
|
|
//查询导购数目
|
|
|
|
customerWrap.eq("status", 1).eq("type", 2).eq("level", 3).eq("parent_id", privilageOrganizational.getId());
|
|
|
|
List<Long> shops = Arrays.asList(cpUserStore.getId());
|
|
|
|
List<PrivilageOrganizational> customerList = retailCompanyMapper.selectList(customerWrap);
|
|
|
|
List<PoiStoreStaffDTO> sellerList = poiStoreStaffDOMapper.selectSellersByShopIds(shops);
|
|
|
|
if (CollectionUtils.isNotEmpty(customerList)) {
|
|
|
|
int staffNum = 0;
|
|
|
|
List<Long> customerIds = customerList.stream().map(i -> i.getId()).collect(Collectors.toList());
|
|
|
|
if (null != sellerList && sellerList.size() > 0) {
|
|
|
|
//查询店铺
|
|
|
|
staffNum = sellerList.size();
|
|
|
|
List<PoiStore> poiStores = poiStoreDOMapper.selectShopByCustomerIds(customerIds);
|
|
|
|
|
|
|
|
if (CollectionUtils.isNotEmpty(poiStores)) {
|
|
|
|
|
|
|
|
//遍历店铺查询门店码url
|
|
|
|
|
|
|
|
for (PoiStore poiStore : poiStores) {
|
|
|
|
|
|
|
|
String cpUserId = privilageCpUserStoreDOMapper.selectCpUserIdByStoreId(poiStore.getId());
|
|
|
|
|
|
|
|
if (StringUtils.isBlank(cpUserId)) {
|
|
|
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
QueryWrapper<PrivilageCpUserDO> userQw = new QueryWrapper<>();
|
|
|
|
|
|
|
|
userQw.eq("cp_user_id",cpUserId).last("limit 1");
|
|
|
|
|
|
|
|
PrivilageCpUserDO privilageCpUserDO = privilageCpUserDOMapper.selectOne(userQw);
|
|
|
|
|
|
|
|
if (privilageCpUserDO == null) {
|
|
|
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
CpUserExcelDTO excelDTO = new CpUserExcelDTO(region.getName(),privilageOrganizational.getName(),
|
|
|
|
|
|
|
|
privilageOrganizational.getCode(),poiStore.getName(),poiStore.getCode(),
|
|
|
|
|
|
|
|
privilageCpUserDO.getCpUserId(),privilageCpUserDO.getName(),privilageCpUserDO.getAlias());
|
|
|
|
|
|
|
|
results.add(excelDTO);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
cpUserStore.setStaffNum(staffNum);
|
|
|
|
|
|
|
|
//客户数
|
|
|
|
|
|
|
|
QueryWrapper<OpSellerCustomerRelation> wrapper2 = new QueryWrapper<>();
|
|
|
|
|
|
|
|
wrapper2.eq("store_id", cpUserStore.getId());
|
|
|
|
|
|
|
|
List<OpSellerCustomerRelation> opRelations = opSellerCustomerRelationDOMapper.selectList(wrapper2);
|
|
|
|
|
|
|
|
long count = opRelations.stream().map(OpSellerCustomerRelation::getCustomerId).distinct().count();
|
|
|
|
|
|
|
|
cpUserStore.setCustomerNum((int) count);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
results.add(cpUserStore);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (CollectionUtils.isNotEmpty(results)){
|
|
|
|
if (CollectionUtils.isNotEmpty(results)){
|
|
|
|
createStoreUserExcel(results,response);
|
|
|
|
createStoreUserExcel(results,response);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void createStoreUserExcel(List<CpUserExcelDTO> results,HttpServletResponse response) throws IOException {
|
|
|
|
public void createStoreUserExcel(List<StoreUserDTO> results,HttpServletResponse response) throws IOException {
|
|
|
|
String[] headNames = new String[]{"序号","大区名","零售公司","零售公司编号","店铺名","店铺编号"," 企业微信号","企业微信号名称","企业微信号别名"};
|
|
|
|
String[] headNames = new String[]{"序号","店铺名","店铺编号","门店企业号","大区名","零售公司","零售公司编号","员工数","客户数"};
|
|
|
|
HSSFWorkbook ws = new HSSFWorkbook();
|
|
|
|
HSSFWorkbook ws = new HSSFWorkbook();
|
|
|
|
Sheet hssfSheet = ws.createSheet("门店号信息");
|
|
|
|
Sheet hssfSheet = ws.createSheet("推广管理");
|
|
|
|
|
|
|
|
|
|
|
|
HSSFCellStyle cellStyle = ws.createCellStyle();
|
|
|
|
HSSFCellStyle cellStyle = ws.createCellStyle();
|
|
|
|
cellStyle.setWrapText(true);//设置自动换行
|
|
|
|
cellStyle.setWrapText(true);//设置自动换行
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int isAdd = 0;
|
|
|
|
int isAdd = 0;
|
|
|
|
|
|
|
|
|
|
|
|
//设置列名
|
|
|
|
//设置列名
|
|
|
|
if (null != headNames && headNames.length > 0) {
|
|
|
|
if (null != headNames && headNames.length > 0) {
|
|
|
|
|
|
|
|
|
|
|
@ -489,29 +503,27 @@ public class StoreEmployeeService {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
for (int i = 0; i < results.size(); i++) {
|
|
|
|
for (int i = 0; i < results.size(); i++) {
|
|
|
|
|
|
|
|
|
|
|
|
//创造行
|
|
|
|
//创造行
|
|
|
|
Row row = hssfSheet.createRow(isAdd++);
|
|
|
|
Row row = hssfSheet.createRow(isAdd++);
|
|
|
|
|
|
|
|
StoreUserDTO cpUserExcelDTO = results.get(i);
|
|
|
|
CpUserExcelDTO cpUserExcelDTO = results.get(i);
|
|
|
|
|
|
|
|
Cell orderCell = row.createCell(0);
|
|
|
|
Cell orderCell = row.createCell(0);
|
|
|
|
orderCell.setCellValue(i + 1 +"");
|
|
|
|
orderCell.setCellValue(i + 1 +"");
|
|
|
|
Cell reginCell = row.createCell(1);
|
|
|
|
Cell reginCell = row.createCell(1);
|
|
|
|
reginCell.setCellValue(cpUserExcelDTO.getRegionName());
|
|
|
|
reginCell.setCellValue(cpUserExcelDTO.getName());
|
|
|
|
Cell companyNameCell = row.createCell(2);
|
|
|
|
Cell companyNameCell = row.createCell(2);
|
|
|
|
companyNameCell.setCellValue(cpUserExcelDTO.getCompanyName());
|
|
|
|
companyNameCell.setCellValue(cpUserExcelDTO.getCode());
|
|
|
|
Cell companyCodeCell = row.createCell(3);
|
|
|
|
Cell companyCodeCell = row.createCell(3);
|
|
|
|
companyCodeCell.setCellValue(cpUserExcelDTO.getCompanyCode());
|
|
|
|
companyCodeCell.setCellValue(cpUserExcelDTO.getCpUserId());
|
|
|
|
Cell storeNameCell = row.createCell(4);
|
|
|
|
Cell storeNameCell = row.createCell(4);
|
|
|
|
storeNameCell.setCellValue(cpUserExcelDTO.getStoreName());
|
|
|
|
storeNameCell.setCellValue(cpUserExcelDTO.getRegionName());
|
|
|
|
Cell storeCodeCell = row.createCell(5);
|
|
|
|
Cell storeCodeCell = row.createCell(5);
|
|
|
|
storeCodeCell.setCellValue(cpUserExcelDTO.getStoreCode());
|
|
|
|
storeCodeCell.setCellValue(cpUserExcelDTO.getCompanyName());
|
|
|
|
Cell cpUserIdCell = row.createCell(6);
|
|
|
|
Cell cpUserIdCell = row.createCell(6);
|
|
|
|
cpUserIdCell.setCellValue(cpUserExcelDTO.getCpUserId());
|
|
|
|
cpUserIdCell.setCellValue(cpUserExcelDTO.getCompanyCode());
|
|
|
|
Cell nameCell = row.createCell(7);
|
|
|
|
Cell nameCell = row.createCell(7);
|
|
|
|
nameCell.setCellValue(cpUserExcelDTO.getName());
|
|
|
|
nameCell.setCellValue(cpUserExcelDTO.getStaffNum());
|
|
|
|
Cell aliasCell = row.createCell(8);
|
|
|
|
Cell aliasCell = row.createCell(8);
|
|
|
|
aliasCell.setCellValue(cpUserExcelDTO.getAlias());
|
|
|
|
aliasCell.setCellValue(cpUserExcelDTO.getCustomerNum());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
OutputStream output = response.getOutputStream();
|
|
|
|
OutputStream output = response.getOutputStream();
|
|
|
|
response.reset();
|
|
|
|
response.reset();
|
|
|
|