导出推广管理列表。

master
kevin jiang 6 years ago
parent 7bd6a80bb6
commit a6c6865584

@ -110,9 +110,9 @@ public class StoreEmployeeController extends BaseController {
*/
@RequestMapping(value = "download/store/excel/bsd",method = RequestMethod.GET)
@ResponseBody
public void downloadStoreCpUserExcelForBSD(HttpServletResponse response) {
public void downloadStoreCpUserExcelForBSD(HttpServletResponse response,@RequestParam("userId") Long userId, Long regionId, Long companyId, Long storeId, String code) {
try {
storeEmployeeService.exportStoreExcel(response);
storeEmployeeService.exportStoreExcel(response,userId,regionId,companyId,storeId,code);
} catch (Exception e) {
log.error("批量下载店铺excel", e);
}

@ -52,4 +52,7 @@ public interface PoiStoreDOMapper extends BaseMapper<PoiStore> {
*/
List<CompanyStoreDO> selectAllCompanyStore();
List<PoiStore> selectShopByCustomerIdAndStore(@Param("customerIds")List<Long> customerIds, @Param("storeId") Long storeId, @Param("code") String code);
}

@ -401,80 +401,94 @@ public class StoreEmployeeService {
*
* @param response
*/
public void exportStoreExcel(HttpServletResponse response) throws Exception {
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
public void exportStoreExcel(HttpServletResponse response, Long userId, Long regionId, Long companyId, Long storeId, String code) throws Exception {
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());
//查询大区
QueryWrapper<PrivilageOrganizational> regionWrapper = new QueryWrapper<>();
regionWrapper.eq("status", 1).eq("type", 2).eq("level", 1);
List<PrivilageOrganizational> regions = retailCompanyMapper.selectList(regionWrapper);
if (CollectionUtils.isNotEmpty(regions)){
for (PrivilageOrganizational region:regions){
if (region == null || region.getId() == null) {
continue;
cpUserStore.setCompanyName(company.getName());
cpUserStore.setCompanyCode(company.getCode());
cpUserStore.setRegionName(region.getName());
}
//查询所有公司
QueryWrapper<PrivilageOrganizational> queryWrapper = new QueryWrapper<>();
queryWrapper.eq("status", 1).eq("type", 2).eq("level", 2).eq("parent_id",region.getId());
List<PrivilageOrganizational> privilageOrganizationals = retailCompanyMapper.selectList(queryWrapper);
if (CollectionUtils.isNotEmpty(privilageOrganizationals)) {
//遍历零售公司
for (PrivilageOrganizational privilageOrganizational : privilageOrganizationals) {
if (privilageOrganizational == null || privilageOrganizational.getId() == null) {
continue;
}
//查询客户
QueryWrapper<PrivilageOrganizational> customerWrap = new QueryWrapper<>();
customerWrap.eq("status", 1).eq("type", 2).eq("level", 3).eq("parent_id", privilageOrganizational.getId());
List<PrivilageOrganizational> customerList = retailCompanyMapper.selectList(customerWrap);
if (CollectionUtils.isNotEmpty(customerList)) {
List<Long> customerIds = customerList.stream().map(i -> i.getId()).collect(Collectors.toList());
//查询店铺
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);
}
}
}
}
String qrCodeAction = cpUserStore.getQrCodeAction();
if (StringUtils.isBlank(qrCodeAction)){
qrCodeAction = getQrCodeFromBSD(cpUserStore.getCpUserId(),BSD_REQ_QRCODE_TYPE_STORE,"0",cpUserStore.getCode());
cpUserStore.setQrCodeAction(qrCodeAction);
PrivilageCpUserDO update = new PrivilageCpUserDO();
update.setId(cpUserStore.getUserId());
update.setQrCode(qrCodeAction);
privilageCpUserDOMapper.updateById(update);
}
//查询导购数目
List<Long> shops = Arrays.asList(cpUserStore.getId());
List<PoiStoreStaffDTO> sellerList = poiStoreStaffDOMapper.selectSellersByShopIds(shops);
int staffNum = 0;
if (null != sellerList && sellerList.size() > 0) {
staffNum = sellerList.size();
}
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)){
createStoreUserExcel(results,response);
}
}
public void createStoreUserExcel(List<CpUserExcelDTO> results,HttpServletResponse response) throws IOException {
String[] headNames = new String[]{"序号","大区名","零售公司","零售公司编号","店铺名","店铺编号"," 企业微信号","企业微信号名称","企业微信号别名"};
public void createStoreUserExcel(List<StoreUserDTO> results,HttpServletResponse response) throws IOException {
String[] headNames = new String[]{"序号","店铺名","店铺编号","门店企业号","大区名","零售公司","零售公司编号","员工数","客户数"};
HSSFWorkbook ws = new HSSFWorkbook();
Sheet hssfSheet = ws.createSheet("门店号信息");
Sheet hssfSheet = ws.createSheet("推广管理");
HSSFCellStyle cellStyle = ws.createCellStyle();
cellStyle.setWrapText(true);//设置自动换行
int isAdd = 0;
//设置列名
if (null != headNames && headNames.length > 0) {
@ -489,29 +503,27 @@ public class StoreEmployeeService {
}
for (int i = 0; i < results.size(); i++) {
//创造行
Row row = hssfSheet.createRow(isAdd++);
CpUserExcelDTO cpUserExcelDTO = results.get(i);
StoreUserDTO cpUserExcelDTO = results.get(i);
Cell orderCell = row.createCell(0);
orderCell.setCellValue(i + 1 +"");
Cell reginCell = row.createCell(1);
reginCell.setCellValue(cpUserExcelDTO.getRegionName());
reginCell.setCellValue(cpUserExcelDTO.getName());
Cell companyNameCell = row.createCell(2);
companyNameCell.setCellValue(cpUserExcelDTO.getCompanyName());
companyNameCell.setCellValue(cpUserExcelDTO.getCode());
Cell companyCodeCell = row.createCell(3);
companyCodeCell.setCellValue(cpUserExcelDTO.getCompanyCode());
companyCodeCell.setCellValue(cpUserExcelDTO.getCpUserId());
Cell storeNameCell = row.createCell(4);
storeNameCell.setCellValue(cpUserExcelDTO.getStoreName());
storeNameCell.setCellValue(cpUserExcelDTO.getRegionName());
Cell storeCodeCell = row.createCell(5);
storeCodeCell.setCellValue(cpUserExcelDTO.getStoreCode());
storeCodeCell.setCellValue(cpUserExcelDTO.getCompanyName());
Cell cpUserIdCell = row.createCell(6);
cpUserIdCell.setCellValue(cpUserExcelDTO.getCpUserId());
cpUserIdCell.setCellValue(cpUserExcelDTO.getCompanyCode());
Cell nameCell = row.createCell(7);
nameCell.setCellValue(cpUserExcelDTO.getName());
nameCell.setCellValue(cpUserExcelDTO.getStaffNum());
Cell aliasCell = row.createCell(8);
aliasCell.setCellValue(cpUserExcelDTO.getAlias());
aliasCell.setCellValue(cpUserExcelDTO.getCustomerNum());
}
OutputStream output = response.getOutputStream();
response.reset();

@ -124,4 +124,49 @@
and t4.type = 3
and t1.store_id = t4.entity_id
</select>
<select id="selectShopByCustomerIdAndStore" resultType="com.kiisoo.ic.store.entity.PoiStore">
select t3.id,t3.name,t3.code
from privilage_organizational_domain t1 join privilage_domain_entity t2 on t1.domain_id = t2.domain_id and t2.type = 3
join poi_store t3 on t2.entity_id = t3.id
<where>
<if test="null != storeId and storeId != 0">
and t2.entity_id = #{storeId}
</if>
<if test="null != code and code != ''">
and (t3.name LIKE CONCAT('%',#{code},'%') OR t3.code LIKE
CONCAT('%',#{code},'%'))
</if>
<if test="customerIds != null and customerIds.size > 0">
and t1.org_id in
<foreach collection="customerIds" index="index" item="item" open="(" separator="," close=")">
#{item}
</foreach>
</if>
</where>
<!-- <choose>-->
<!-- <when test="customerIds != null and customerIds.size > 0">-->
<!-- and t1.org_id in-->
<!-- <foreach collection="customerIds" index="index" item="item" open="(" separator="," close=")">-->
<!-- #{item}-->
<!-- </foreach>-->
<!-- </when>-->
<!-- <otherwise>-->
<!-- and 0 = 0-->
<!-- </otherwise>-->
<!-- </choose>-->
<!-- <if test="customerIds != null and customerIds.size > 0">-->
<!-- and t1.org_id in-->
<!-- <foreach collection="customerIds" index="index" item="item" open="(" separator="," close=")">-->
<!-- #{item}-->
<!-- </foreach>-->
<!-- </if>-->
</select>
</mapper>

@ -99,16 +99,28 @@ public class OrganizationInitCompany {
parentId = parent.getId();
}
PrivilageOrganizational param = new PrivilageOrganizational();
param.setName(v.getName());
param.setLevel(regionLevel);
param.setParentId(parentId);
param.setType(2l);
param.setStatus(1l);
param.setCreateTime(new Date());
param.setUpdateTime(new Date());
Map<String, Object> map = new HashMap<>();
map.put("name", v.getName());
map.put("level", regionLevel);
map.put("parent_id", parentId);
map.put("type", 2L);
map.put("status", 1L);
List<PrivilageOrganizational> list = retailCompanyMapper.selectByMap(map);
if(list.size() == 0){
PrivilageOrganizational param = new PrivilageOrganizational();
param.setName(v.getName());
param.setLevel(regionLevel);
param.setParentId(parentId);
param.setType(2l);
param.setStatus(1l);
param.setCreateTime(new Date());
param.setUpdateTime(new Date());
retailCompanyMapper.insert(param);
}else{
}
retailCompanyMapper.insert(param);
});
}
public long getType(String position){

Loading…
Cancel
Save