导出Excel优化。

master
kevin jiang 6 years ago
parent d98ab38f6f
commit f6f69b890d

@ -32,6 +32,13 @@ public interface PoiStoreStaffDOMapper extends BaseMapper<PoiStoreStaff> {
*/ */
List<PoiStoreStaffDTO> selectSellersByShopIds(@Param("shopId") List<Long> shopId); List<PoiStoreStaffDTO> selectSellersByShopIds(@Param("shopId") List<Long> shopId);
/**
*
* @param shopId
* @return
*/
Integer selectSellersByShopIdsCount(@Param("shopId") List<Long> shopId);
/** /**
* *
*/ */

@ -427,6 +427,8 @@ public class StoreEmployeeService {
//查询用户权限店铺 //查询用户权限店铺
shopIds = new ArrayList<>(privilageDomainService.listUserDatePermission(userId)); shopIds = new ArrayList<>(privilageDomainService.listUserDatePermission(userId));
} }
long s = System.currentTimeMillis();
System.out.println(s);
List<StoreUserDTO> cpUserStoreDO = privilageCpUserStoreDOMapper.selectCpUserByShops(shopIds); List<StoreUserDTO> cpUserStoreDO = privilageCpUserStoreDOMapper.selectCpUserByShops(shopIds);
if (CollectionUtils.isNotEmpty(cpUserStoreDO)) { if (CollectionUtils.isNotEmpty(cpUserStoreDO)) {
int orderNum = 0; int orderNum = 0;
@ -434,11 +436,11 @@ public class StoreEmployeeService {
//设置序号 //设置序号
cpUserStore.setOrderNum(++orderNum); cpUserStore.setOrderNum(++orderNum);
//查询店铺绑定的企业微信 //查询店铺绑定的企业微信
PoiStore poiStore = poiStoreDOMapper.selectById(cpUserStore.getId()); // PoiStore poiStore = poiStoreDOMapper.selectById(cpUserStore.getId());
if (null != poiStore) { // if (null != poiStore) {
cpUserStore.setName(poiStore.getName()); // cpUserStore.setName(poiStore.getName());
cpUserStore.setCode(poiStore.getCode()); // cpUserStore.setCode(poiStore.getCode());
} // }
//客户orgId //客户orgId
Long customerId = privilageDomainEntityDOMapper.selectDomainIdByShopEntity(cpUserStore.getId()); Long customerId = privilageDomainEntityDOMapper.selectDomainIdByShopEntity(cpUserStore.getId());
@ -452,38 +454,43 @@ public class StoreEmployeeService {
cpUserStore.setRegionName(region.getName()); cpUserStore.setRegionName(region.getName());
} }
String qrCodeAction = cpUserStore.getQrCodeAction(); // String qrCodeAction = cpUserStore.getQrCodeAction();
if (StringUtils.isBlank(qrCodeAction)){ // if (StringUtils.isBlank(qrCodeAction)){
qrCodeAction = getQrCodeFromBSD(cpUserStore.getCpUserId(),BSD_REQ_QRCODE_TYPE_STORE,"0",cpUserStore.getCode()); // qrCodeAction = getQrCodeFromBSD(cpUserStore.getCpUserId(),BSD_REQ_QRCODE_TYPE_STORE,"0",cpUserStore.getCode());
cpUserStore.setQrCodeAction(qrCodeAction); // cpUserStore.setQrCodeAction(qrCodeAction);
PrivilageCpUserDO update = new PrivilageCpUserDO(); // PrivilageCpUserDO update = new PrivilageCpUserDO();
update.setId(cpUserStore.getUserId()); // update.setId(cpUserStore.getUserId());
update.setQrCode(qrCodeAction); // update.setQrCode(qrCodeAction);
privilageCpUserDOMapper.updateById(update); // privilageCpUserDOMapper.updateById(update);
} // }
//查询导购数目 //查询导购数目
List<Long> shops = Arrays.asList(cpUserStore.getId()); List<Long> shops = Arrays.asList(cpUserStore.getId());
List<PoiStoreStaffDTO> sellerList = poiStoreStaffDOMapper.selectSellersByShopIds(shops); Integer staffNum = poiStoreStaffDOMapper.selectSellersByShopIdsCount(shops);
int staffNum = 0; // int staffNum = 0;
if (null != sellerList && sellerList.size() > 0) { // if (null != sellerList && sellerList.size() > 0) {
staffNum = sellerList.size(); // staffNum = sellerList.size();
} // }
cpUserStore.setStaffNum(staffNum); cpUserStore.setStaffNum(staffNum);
//客户数 //客户数
QueryWrapper<OpSellerCustomerRelation> wrapper2 = new QueryWrapper<>(); QueryWrapper<OpSellerCustomerRelation> wrapper2 = new QueryWrapper<>();
wrapper2.eq("store_id", cpUserStore.getId()); wrapper2.eq("store_id", cpUserStore.getId());
List<OpSellerCustomerRelation> opRelations = opSellerCustomerRelationDOMapper.selectList(wrapper2); Integer opRelations = opSellerCustomerRelationDOMapper.selectCount(wrapper2);
long count = opRelations.stream().map(OpSellerCustomerRelation::getCustomerId).distinct().count(); // long count = opRelations.stream().map(OpSellerCustomerRelation::getCustomerId).distinct().count();
cpUserStore.setCustomerNum((int) count); cpUserStore.setCustomerNum(opRelations);
results.add(cpUserStore); results.add(cpUserStore);
} }
} }
System.out.println(s - System.currentTimeMillis());
if (CollectionUtils.isNotEmpty(results)){ if (CollectionUtils.isNotEmpty(results)){
createStoreUserExcel(results,response); createStoreUserExcel(results,response);
} }
System.out.println(s - System.currentTimeMillis());
} }
public void createStoreUserExcel(List<StoreUserDTO> results,HttpServletResponse response) throws IOException { public void createStoreUserExcel(List<StoreUserDTO> results,HttpServletResponse response) throws IOException {
@ -530,10 +537,10 @@ public class StoreEmployeeService {
aliasCell.setCellValue(cpUserExcelDTO.getCustomerNum()); aliasCell.setCellValue(cpUserExcelDTO.getCustomerNum());
} }
OutputStream output = response.getOutputStream(); OutputStream output = response.getOutputStream();
response.reset();
response.setHeader("Content-disposition", "attachment; filename=store.xls"); response.setHeader("Content-disposition", "attachment; filename=store.xls");
response.setContentType("application/msexcel"); response.setContentType("application/vnd.ms-excel");
ws.write(output); ws.write(output);
ws.close();
} }
/** /**

@ -4,7 +4,8 @@
<select id="selectCpUserByShops" resultType="com.kiisoo.ic.store.entity.StoreUserDTO"> <select id="selectCpUserByShops" resultType="com.kiisoo.ic.store.entity.StoreUserDTO">
select distinct pcu.cp_user_id as cpUserId,pcu.qr_code as qrCodeAction,pcus.store_id as id,pcu.id as userId from poi_store t join privilage_domain_entity t2 on t.id = t2.entity_id and t2.type = 3 select distinct pcu.cp_user_id as cpUserId,pcu.qr_code as qrCodeAction,pcus.store_id as id,pcu.id as userId ,t.name,t.code
from poi_store t join privilage_domain_entity t2 on t.id = t2.entity_id and t2.type = 3
left join privilage_cp_user_store pcus on t.id = pcus.store_id left join privilage_cp_user_store pcus on t.id = pcus.store_id
left join privilage_cp_user pcu on pcus.cp_user_id = pcu.id and pcu.status in (1,4) left join privilage_cp_user pcu on pcus.cp_user_id = pcu.id and pcu.status in (1,4)
<where> <where>

@ -27,6 +27,19 @@
</choose> </choose>
group by t1.staff_code group by t1.staff_code
</select> </select>
<select id="selectSellersByShopIdsCount" resultType="Integer">
select
count(1)
from poi_store_staff t1, privilage_user t2
where t1.user_id = t2.id
<if test="shopId != null and shopId.size > 0">
and t1.store_id in
<foreach collection="shopId" index="index" item="item" open="(" separator="," close=")">
#{item}
</foreach>
</if>
</select>
<select id="selectShopManagerByShop" resultType="java.lang.String"> <select id="selectShopManagerByShop" resultType="java.lang.String">
select staff_code from poi_store_staff where store_id = #{shopId} and status = 1 and type = 1 and user_id != 0 select staff_code from poi_store_staff where store_id = #{shopId} and status = 1 and type = 1 and user_id != 0
limit 1 limit 1

Loading…
Cancel
Save