|
|
|
@@ -1,18 +1,34 @@ |
|
|
|
package com.simple.service.impl; |
|
|
|
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
|
import org.springframework.stereotype.Service; |
|
|
|
|
|
|
|
import cn.afterturn.easypoi.excel.ExcelImportUtil; |
|
|
|
import cn.afterturn.easypoi.excel.entity.ImportParams; |
|
|
|
import com.github.pagehelper.PageHelper; |
|
|
|
import com.github.pagehelper.PageInfo; |
|
|
|
import com.simple.common.IdWorker; |
|
|
|
import com.simple.common.Result; |
|
|
|
import com.simple.common.ResultData; |
|
|
|
import com.simple.domain.dto.WxCUserBasicInfoDto; |
|
|
|
import com.simple.domain.po.WxCUser; |
|
|
|
import com.simple.domain.po.WxCUserBasicInfo; |
|
|
|
import com.simple.exception.MallinkException; |
|
|
|
import com.simple.mapper.WxCUserBasicInfoMapper; |
|
|
|
import com.simple.mapper.WxCUserMapper; |
|
|
|
import com.simple.service.WxCUserBasicInfoService; |
|
|
|
import org.apache.commons.io.FileUtils; |
|
|
|
import org.apache.poi.ss.usermodel.Cell; |
|
|
|
import org.apache.poi.ss.usermodel.Row; |
|
|
|
import org.apache.poi.xssf.usermodel.XSSFSheet; |
|
|
|
import org.apache.poi.xssf.usermodel.XSSFWorkbook; |
|
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
|
import org.springframework.stereotype.Service; |
|
|
|
import org.springframework.web.multipart.MultipartFile; |
|
|
|
|
|
|
|
import javax.servlet.http.HttpServletRequest; |
|
|
|
import javax.servlet.http.HttpServletResponse; |
|
|
|
import java.io.*; |
|
|
|
import java.util.List; |
|
|
|
import java.util.Map; |
|
|
|
import java.util.UUID; |
|
|
|
|
|
|
|
@Service |
|
|
|
public class WxCUserBasicInfoServiceImpl implements WxCUserBasicInfoService { |
|
|
|
@@ -20,6 +36,8 @@ public class WxCUserBasicInfoServiceImpl implements WxCUserBasicInfoService { |
|
|
|
@Autowired |
|
|
|
WxCUserBasicInfoMapper wxCUserBasicInfoMapper; |
|
|
|
|
|
|
|
@Autowired |
|
|
|
WxCUserMapper wxCUserMapper; |
|
|
|
|
|
|
|
@Override |
|
|
|
public PageInfo<WxCUserBasicInfo> listAsPage(WxCUserBasicInfo record, Integer pageIndex, Integer pageSize) { |
|
|
|
@@ -83,5 +101,235 @@ public class WxCUserBasicInfoServiceImpl implements WxCUserBasicInfoService { |
|
|
|
return PageHelper.startPage(pageNum, pageSize).doSelectPageInfo(() -> wxCUserBasicInfoMapper.findListMap(record)); |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public void exportData(HttpServletRequest request, HttpServletResponse response, String tenantId) { |
|
|
|
|
|
|
|
|
|
|
|
WxCUser wxCUser = new WxCUser(); |
|
|
|
wxCUser.setTenantId(tenantId); |
|
|
|
List<WxCUser> userlist = wxCUserMapper.findList(wxCUser); |
|
|
|
|
|
|
|
WxCUserBasicInfoDto basicInfoDto = new WxCUserBasicInfoDto(); |
|
|
|
basicInfoDto.setTenantId(tenantId); |
|
|
|
List<WxCUserBasicInfo> memberlist = wxCUserBasicInfoMapper.list(basicInfoDto); |
|
|
|
|
|
|
|
|
|
|
|
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 openIdCell = row.createCell(0); |
|
|
|
Cell nickNameCell = row.createCell(1); |
|
|
|
Cell phoneCell = row.createCell(2); |
|
|
|
Cell genderCell = row.createCell(3); |
|
|
|
Cell cityCell = row.createCell(4); |
|
|
|
Cell provinceCell = row.createCell(5); |
|
|
|
Cell languageCell = row.createCell(6); |
|
|
|
Cell countryCodeCell = row.createCell(7); |
|
|
|
Cell registerIpCell = row.createCell(8); |
|
|
|
Cell sceneadressCell = row.createCell(9); |
|
|
|
|
|
|
|
openIdCell.setCellValue("openId"); |
|
|
|
nickNameCell.setCellValue("昵称"); |
|
|
|
phoneCell.setCellValue("手机"); |
|
|
|
genderCell.setCellValue("性别"); |
|
|
|
cityCell.setCellValue("城市"); |
|
|
|
provinceCell.setCellValue("省份"); |
|
|
|
languageCell.setCellValue("语言"); |
|
|
|
countryCodeCell.setCellValue("国家代码"); |
|
|
|
registerIpCell.setCellValue("注册IP"); |
|
|
|
sceneadressCell.setCellValue("场景值"); |
|
|
|
|
|
|
|
|
|
|
|
for(int i=0;i<userlist.size();i++){ |
|
|
|
|
|
|
|
row = sheetOne.createRow(i+1); |
|
|
|
openIdCell = row.createCell(0); |
|
|
|
nickNameCell = row.createCell(1); |
|
|
|
phoneCell = row.createCell(2); |
|
|
|
genderCell = row.createCell(3); |
|
|
|
cityCell = row.createCell(4); |
|
|
|
provinceCell = row.createCell(5); |
|
|
|
languageCell = row.createCell(6); |
|
|
|
countryCodeCell = row.createCell(7); |
|
|
|
registerIpCell = row.createCell(8); |
|
|
|
sceneadressCell = row.createCell(9); |
|
|
|
|
|
|
|
WxCUser entity = userlist.get(i); |
|
|
|
openIdCell.setCellValue(entity.getOpenId()); |
|
|
|
nickNameCell.setCellValue(entity.getNickName()); |
|
|
|
phoneCell.setCellValue(entity.getPhone()); |
|
|
|
genderCell.setCellValue(entity.getGender()); |
|
|
|
cityCell.setCellValue(entity.getCity()); |
|
|
|
provinceCell.setCellValue(entity.getProvince()); |
|
|
|
languageCell.setCellValue(entity.getLanguage()); |
|
|
|
countryCodeCell.setCellValue(entity.getCountryCode()); |
|
|
|
registerIpCell.setCellValue(entity.getRegisterIp()); |
|
|
|
sceneadressCell.setCellValue(entity.getSceneAddress()); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
XSSFSheet sheetTwo = workbook.createSheet("会员信息"); |
|
|
|
Row rowtwo = sheetTwo.createRow(0); |
|
|
|
Cell nameCellTwo = rowtwo.createCell(0); |
|
|
|
Cell phoneCellTwo = rowtwo.createCell(1); |
|
|
|
Cell birthdateCellTwo = rowtwo.createCell(2); |
|
|
|
Cell educationCellTwo = rowtwo.createCell(3); |
|
|
|
|
|
|
|
|
|
|
|
nameCellTwo.setCellValue("姓名"); |
|
|
|
phoneCellTwo.setCellValue("手机"); |
|
|
|
birthdateCellTwo.setCellValue("生日"); |
|
|
|
educationCellTwo.setCellValue("学历"); |
|
|
|
|
|
|
|
|
|
|
|
for(int i=0;i<memberlist.size();i++){ |
|
|
|
rowtwo = sheetTwo.createRow(i+1); |
|
|
|
nameCellTwo = rowtwo.createCell(0); |
|
|
|
phoneCellTwo = rowtwo.createCell(1); |
|
|
|
birthdateCellTwo = rowtwo.createCell(2); |
|
|
|
educationCellTwo = rowtwo.createCell(3); |
|
|
|
|
|
|
|
WxCUserBasicInfo entity = memberlist.get(i); |
|
|
|
|
|
|
|
nameCellTwo.setCellValue(entity.getName()); |
|
|
|
phoneCellTwo.setCellValue(entity.getPhone()); |
|
|
|
birthdateCellTwo.setCellValue(entity.getBirthdate()); |
|
|
|
educationCellTwo.setCellValue(entity.getEducation()); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
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 { |
|
|
|
try { |
|
|
|
response.reset(); |
|
|
|
response.setContentType("bin"); |
|
|
|
String agent = req.getHeader("user-agent"); |
|
|
|
if (agent.contains("Firefox")) { |
|
|
|
response.setHeader("Content-disposition", |
|
|
|
"attachment; filename=" |
|
|
|
+ new String(filename.getBytes("GB2312"), |
|
|
|
"ISO-8859-1")); |
|
|
|
} else { |
|
|
|
response |
|
|
|
.setHeader("Content-disposition", |
|
|
|
"attachment; filename=" |
|
|
|
+ java.net.URLEncoder.encode(filename, |
|
|
|
"UTF-8")); |
|
|
|
} |
|
|
|
// 循环取出流中的数据 |
|
|
|
byte[] b = new byte[1024]; |
|
|
|
int len; |
|
|
|
InputStream inStream = new FileInputStream(filePath); |
|
|
|
while ((len = inStream.read(b)) > 0) |
|
|
|
response.getOutputStream().write(b, 0, len); |
|
|
|
inStream.close(); |
|
|
|
} catch (Exception e) { |
|
|
|
e.printStackTrace(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public void exportTemplate(HttpServletRequest request, HttpServletResponse response, String tenantId) { |
|
|
|
|
|
|
|
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 sheetTwo = workbook.createSheet("会员信息"); |
|
|
|
Row rowtwo = sheetTwo.createRow(0); |
|
|
|
Cell nameCellTwo = rowtwo.createCell(0); |
|
|
|
Cell phoneCellTwo = rowtwo.createCell(1); |
|
|
|
Cell sexCellTwo = rowtwo.createCell(2); |
|
|
|
Cell birthdateCellTwo = rowtwo.createCell(3); |
|
|
|
Cell educationCellTwo = rowtwo.createCell(4); |
|
|
|
|
|
|
|
nameCellTwo.setCellValue("姓名"); |
|
|
|
phoneCellTwo.setCellValue("手机"); |
|
|
|
sexCellTwo.setCellValue("性别"); |
|
|
|
birthdateCellTwo.setCellValue("生日"); |
|
|
|
educationCellTwo.setCellValue("学历"); |
|
|
|
|
|
|
|
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(); |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
public ResultData importTemplate(MultipartFile file, String tenantId) { |
|
|
|
|
|
|
|
try { |
|
|
|
|
|
|
|
ImportParams params = new ImportParams(); |
|
|
|
params.setTitleRows(1); |
|
|
|
params.setHeadRows(1); |
|
|
|
List<WxCUserBasicInfo> datalist = ExcelImportUtil.importExcel(file.getInputStream(),WxCUserBasicInfo.class, params); |
|
|
|
WxCUserBasicInfo wxCUserBasicInfo = new WxCUserBasicInfo(); |
|
|
|
wxCUserBasicInfo.setTenantId(tenantId); |
|
|
|
List<WxCUserBasicInfo> list = wxCUserBasicInfoMapper.findList(wxCUserBasicInfo); |
|
|
|
final IdWorker idWorker = IdWorker.get(); |
|
|
|
for(WxCUserBasicInfo user:datalist){ |
|
|
|
WxCUserBasicInfo tempuser = list.stream().filter(u -> u.getPhone().equals(user.getPhone())).findFirst().get(); |
|
|
|
if(tempuser!=null){ |
|
|
|
tempuser.setSex(user.getSex()); |
|
|
|
tempuser.setEducation(user.getEducation()); |
|
|
|
tempuser.setBirthdate(user.getBirthdate()); |
|
|
|
tempuser.setName(user.getName()); |
|
|
|
wxCUserBasicInfoMapper.updateByPrimaryKeySelective(tempuser); |
|
|
|
} else { |
|
|
|
user.setId(idWorker.nextId()); |
|
|
|
wxCUserBasicInfoMapper.insertSelective(user); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
} catch (Exception e) { |
|
|
|
throw new MallinkException(500,"模板导入失败"); |
|
|
|
} |
|
|
|
|
|
|
|
return new ResultData(Result.SUCCESS,"导入成功"); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |