Просмотр исходного кода

[会员管理][会员详情][导入导出]

release_toaliyun_real
gongbiao 7 лет назад
Родитель
Сommit
b1e16bf50b
2 измененных файлов: 112 добавлений и 10 удалений
  1. +107
    -2
      mallinkService/src/main/java/com/simple/service/impl/WxCUserBasicInfoServiceImpl.java
  2. +5
    -8
      mallinkService/src/main/resources/mapper/WxCUserBasicInfoMapper.xml

+ 107
- 2
mallinkService/src/main/java/com/simple/service/impl/WxCUserBasicInfoServiceImpl.java Просмотреть файл

@@ -28,8 +28,11 @@ import javax.servlet.http.HttpServletResponse;
import java.io.*;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.UUID;

import static java.util.stream.Collectors.toList;

@Service
public class WxCUserBasicInfoServiceImpl implements WxCUserBasicInfoService {
@@ -101,7 +104,7 @@ public class WxCUserBasicInfoServiceImpl implements WxCUserBasicInfoService {
return PageHelper.startPage(pageNum, pageSize).doSelectPageInfo(() -> wxCUserBasicInfoMapper.findListMap(record));
}

@Override
/*@Override
public void exportData(HttpServletRequest request, HttpServletResponse response, String tenantId) {


@@ -221,8 +224,110 @@ public class WxCUserBasicInfoServiceImpl implements WxCUserBasicInfoService {
}


}
}*/

public void exportData(HttpServletRequest request, HttpServletResponse response, String tenantId) {


WxCUser wxCUser = new WxCUser();
wxCUser.setTenantId(tenantId);
List<WxCUser> userlist = wxCUserMapper.findList(wxCUser);

WxCUserBasicInfo basicInfo = new WxCUserBasicInfo();
basicInfo.setTenantId(tenantId);
List<WxCUserBasicInfo> memberlist = wxCUserBasicInfoMapper.findList(basicInfo);

XSSFWorkbook workbook;
String filepath = "./uploads/";
File savefile = new File(filepath);
if (!savefile.exists()) {
savefile.mkdirs();
}
String filename = UUID.randomUUID() + ".xlsx";
filepath = filepath + filename;
try {
File file = new File(filepath);
workbook = new XSSFWorkbook();

XSSFSheet sheetOne = workbook.createSheet("会员");
Row row = sheetOne.createRow(0);
Cell nameCell = row.createCell(0);
Cell phoneCell = row.createCell(1);
Cell nickNameCell = row.createCell(2);
Cell cityCell = row.createCell(3);
Cell provinceCell = row.createCell(4);
Cell countryCodeCell = row.createCell(5);
Cell registerIpCell = row.createCell(6);
Cell emailCell = row.createCell(7);
Cell educationCell = row.createCell(8);
Cell addressCell = row.createCell(9);
Cell activeTimeCell = row.createCell(10);
Cell registerTimeCell = row.createCell(11);

nameCell.setCellValue("姓名");
phoneCell.setCellValue("手机号");
nickNameCell.setCellValue("微信名称");
cityCell.setCellValue("城市");
provinceCell.setCellValue("省份");
countryCodeCell.setCellValue("国家代码");
registerIpCell.setCellValue("注册IP");
emailCell.setCellValue("邮箱");
educationCell.setCellValue("学历");
addressCell.setCellValue("地址");
activeTimeCell.setCellValue("上次活跃时间");
registerTimeCell.setCellValue("注册时间");

for (int i = 0; i < memberlist.size(); i++) {
row = sheetOne.createRow(i + 1);
nameCell = row.createCell(0);
phoneCell = row.createCell(1);
nickNameCell = row.createCell(2);
cityCell = row.createCell(3);
provinceCell = row.createCell(4);
countryCodeCell = row.createCell(5);
registerIpCell = row.createCell(6);
emailCell = row.createCell(7);
educationCell = row.createCell(8);
addressCell = row.createCell(9);
activeTimeCell = row.createCell(10);
registerTimeCell = row.createCell(11);

WxCUserBasicInfo wxCUserBasicInfo = memberlist.get(0);
nameCell.setCellValue(wxCUserBasicInfo.getName());
String phone = wxCUserBasicInfo.getPhone();
phoneCell.setCellValue(phone);
emailCell.setCellValue(wxCUserBasicInfo.getEmail());
educationCell.setCellValue(wxCUserBasicInfo.getEducation());
addressCell.setCellValue(wxCUserBasicInfo.getAddress());
Optional<WxCUser> first = userlist.stream().filter(m -> {
if(m.getPhone() != null){
return m.getPhone().equals(phone);
}
return false;
}).findFirst();
if(first.isPresent()){
WxCUser cUser = first.get();
nickNameCell.setCellValue(cUser.getNickName());
countryCodeCell.setCellValue(cUser.getCountryCode());
cityCell.setCellValue(cUser.getCity());
provinceCell.setCellValue(cUser.getProvince());
registerIpCell.setCellValue(cUser.getRegisterIp());
activeTimeCell.setCellValue(cUser.getUpdateDate());
registerTimeCell.setCellValue(cUser.getCreateDate());
}

}

FileOutputStream fileOut = new FileOutputStream(file);
workbook.write(fileOut);
fileOut.close();
workbook.close();
downFile(filepath, filename, response, request);
FileUtils.forceDelete(file);
} catch (Exception e) {
e.printStackTrace();
}
}

public void downFile(String filePath,String filename, HttpServletResponse response,
HttpServletRequest req) throws IOException {


+ 5
- 8
mallinkService/src/main/resources/mapper/WxCUserBasicInfoMapper.xml Просмотреть файл

@@ -163,24 +163,21 @@

<select id="findListMap" parameterType="com.simple.domain.dto.WxCUserBasicInfoDto" resultType="hashmap">
select cu.id,cu.tenant_id tenantId,cu.open_id openId,cu.union_id unionId,
cu.nick_name nickName,cu.gender,cu.avatar_url avatarUrl,cu.phone,
cu.nick_name nickName,cu.gender,cu.avatar_url avatarUrl,cubi.phone,
cu.pure_phone purePhone,cu.city,cu.province,cu.`language`,cu.country_code countryCode,
cu.register_ip registerIp,cu.verify_code_phone verifyCodePhone,cu.qrcode_source qrcodeSource,
cu.scene,cu.scene_address sceneAddress,cu.score,cu.update_date updateDate,
cu.create_date createDate,cu.app_id appId,cu.session_key sessionKey,cu.token,
cu.expire_time expireTime,cu.latitude,cu.longitude,cubi.birthdate,cubi.education,
cubi.sex,cubi.email,cubi.address,cubi.poins,cubi.`name`,cubi.`level`,cubi.id cubiid
from wx_c_user cu left join wx_c_user_basic_info cubi
from wx_c_user cu right join wx_c_user_basic_info cubi
on cu.phone=cubi.phone and cu.tenant_id=cubi.tenant_id
where 1=1
<if test=" null != tenantId ">
and cu.`tenant_id` = #{tenantId}
and cubi.`tenant_id` = #{tenantId}
</if>
<if test=" null != phone and phone !='' ">
and cu.`phone` = #{phone}
</if>
<if test=" null == phone or phone =='' ">
and cu.`phone` is not null
and cubi.`phone` = #{phone}
</if>
<if test=" null != startTime ">
and cubi.create_date &gt;= #{startTime}
@@ -190,7 +187,7 @@
and cubi.update_date &lt;= #{endTime}
</if>
<if test=" null != name and name != '' ">
and cb.`name` like concat('%', #{name},'%')
and cubi.`name` like concat('%', #{name},'%')
</if>
</select>


Загрузка…
Отмена
Сохранить