|
|
|
@@ -4,6 +4,7 @@ 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.ErrorCode; |
|
|
|
import com.simple.common.IdWorker; |
|
|
|
import com.simple.common.Result; |
|
|
|
import com.simple.common.ResultData; |
|
|
|
@@ -16,6 +17,7 @@ import com.simple.mapper.WxCUserBasicInfoMapper; |
|
|
|
import com.simple.mapper.WxCUserMapper; |
|
|
|
import com.simple.service.WxCUserBasicInfoService; |
|
|
|
import org.apache.commons.io.FileUtils; |
|
|
|
import org.apache.commons.lang3.StringUtils; |
|
|
|
import org.apache.poi.ss.usermodel.Cell; |
|
|
|
import org.apache.poi.ss.usermodel.Row; |
|
|
|
import org.apache.poi.xssf.usermodel.XSSFSheet; |
|
|
|
@@ -27,17 +29,15 @@ import org.springframework.web.multipart.MultipartFile; |
|
|
|
import javax.servlet.http.HttpServletRequest; |
|
|
|
import javax.servlet.http.HttpServletResponse; |
|
|
|
import java.io.*; |
|
|
|
import java.util.Date; |
|
|
|
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 { |
|
|
|
|
|
|
|
@Autowired |
|
|
|
|
|
|
|
@Autowired |
|
|
|
WxCUserBasicInfoMapper wxCUserBasicInfoMapper; |
|
|
|
|
|
|
|
@Autowired |
|
|
|
@@ -47,13 +47,13 @@ public class WxCUserBasicInfoServiceImpl implements WxCUserBasicInfoService { |
|
|
|
public PageInfo<WxCUserBasicInfo> listAsPage(WxCUserBasicInfo record, Integer pageIndex, Integer pageSize) { |
|
|
|
return PageHelper.startPage(pageIndex, pageSize).doSelectPageInfo(() -> wxCUserBasicInfoMapper.findList(record)); |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
|
|
|
|
@Override |
|
|
|
public List<WxCUserBasicInfo> findByPhone(String tenantId, String phone) { |
|
|
|
WxCUserBasicInfo basicQ = new WxCUserBasicInfo(); |
|
|
|
basicQ.setTenantId(tenantId); |
|
|
|
basicQ.setPhone(phone); |
|
|
|
return wxCUserBasicInfoMapper.select(basicQ); |
|
|
|
return wxCUserBasicInfoMapper.select(basicQ); |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
@@ -71,7 +71,7 @@ public class WxCUserBasicInfoServiceImpl implements WxCUserBasicInfoService { |
|
|
|
if (record.getId() == null) { |
|
|
|
//record.setId(UUID.randomUUID().toString().replaceAll("-", "")); |
|
|
|
final IdWorker idWorker = IdWorker.get(); |
|
|
|
record.setId(idWorker.nextId()); |
|
|
|
record.setId(idWorker.nextId()); |
|
|
|
wxCUserBasicInfoMapper.insertSelective(record); |
|
|
|
} else { |
|
|
|
wxCUserBasicInfoMapper.updateByPrimaryKeySelective(record); |
|
|
|
@@ -92,25 +92,23 @@ public class WxCUserBasicInfoServiceImpl implements WxCUserBasicInfoService { |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
public long findCountBySex(WxCUserBasicInfoDto dto) { |
|
|
|
return wxCUserBasicInfoMapper.findCountBySex(dto); |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public long findCountBySex(WxCUserBasicInfoDto dto) { |
|
|
|
return wxCUserBasicInfoMapper.findCountBySex(dto); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
public long findCountByAge(WxCUserBasicInfoDto dto) { |
|
|
|
return wxCUserBasicInfoMapper.findCountByAge(dto); |
|
|
|
} |
|
|
|
@Override |
|
|
|
public long findCountByAge(WxCUserBasicInfoDto dto) { |
|
|
|
return wxCUserBasicInfoMapper.findCountByAge(dto); |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public PageInfo<Map<String, Object>> queryListMap(WxCUserBasicInfoDto record, Integer pageNum, Integer pageSize) { |
|
|
|
return PageHelper.startPage(pageNum, pageSize).doSelectPageInfo(() -> wxCUserBasicInfoMapper.findListMap(record)); |
|
|
|
} |
|
|
|
|
|
|
|
/*@Override |
|
|
|
@Override |
|
|
|
public void exportData(HttpServletRequest request, HttpServletResponse response, String tenantId) { |
|
|
|
|
|
|
|
|
|
|
|
@@ -124,16 +122,16 @@ public class WxCUserBasicInfoServiceImpl implements WxCUserBasicInfoService { |
|
|
|
|
|
|
|
|
|
|
|
XSSFWorkbook workbook; |
|
|
|
String filepath="./uploads/"; |
|
|
|
String filepath = "./uploads/"; |
|
|
|
File savefile = new File(filepath); |
|
|
|
if (!savefile.exists()) { |
|
|
|
savefile.mkdirs(); |
|
|
|
} |
|
|
|
String filename=UUID.randomUUID()+".xlsx"; |
|
|
|
filepath=filepath+filename; |
|
|
|
String filename = UUID.randomUUID() + ".xlsx"; |
|
|
|
filepath = filepath + filename; |
|
|
|
try { |
|
|
|
File file=new File(filepath); |
|
|
|
workbook=new XSSFWorkbook(); |
|
|
|
File file = new File(filepath); |
|
|
|
workbook = new XSSFWorkbook(); |
|
|
|
XSSFSheet sheetOne = workbook.createSheet("微信关注用户"); |
|
|
|
Row row = sheetOne.createRow(0); |
|
|
|
Cell openIdCell = row.createCell(0); |
|
|
|
@@ -159,9 +157,9 @@ public class WxCUserBasicInfoServiceImpl implements WxCUserBasicInfoService { |
|
|
|
sceneadressCell.setCellValue("场景值"); |
|
|
|
|
|
|
|
|
|
|
|
for(int i=0;i<userlist.size();i++){ |
|
|
|
for (int i = 0; i < userlist.size(); i++) { |
|
|
|
|
|
|
|
row = sheetOne.createRow(i+1); |
|
|
|
row = sheetOne.createRow(i + 1); |
|
|
|
openIdCell = row.createCell(0); |
|
|
|
nickNameCell = row.createCell(1); |
|
|
|
phoneCell = row.createCell(2); |
|
|
|
@@ -192,138 +190,41 @@ public class WxCUserBasicInfoServiceImpl implements WxCUserBasicInfoService { |
|
|
|
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); |
|
|
|
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("学历"); |
|
|
|
|
|
|
|
|
|
|
|
for(int i=0;i<memberlist.size();i++){ |
|
|
|
rowtwo = sheetTwo.createRow(i+1); |
|
|
|
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); |
|
|
|
sexCellTwo = rowtwo.createCell(2); |
|
|
|
birthdateCellTwo = rowtwo.createCell(3); |
|
|
|
educationCellTwo = rowtwo.createCell(4); |
|
|
|
|
|
|
|
WxCUserBasicInfo entity = memberlist.get(i); |
|
|
|
|
|
|
|
nameCellTwo.setCellValue(entity.getName()); |
|
|
|
phoneCellTwo.setCellValue(entity.getPhone()); |
|
|
|
String sexStr = "保密"; |
|
|
|
if (entity.getSex() == 1) |
|
|
|
sexStr = "男"; |
|
|
|
else if (entity.getSex() == 2) |
|
|
|
sexStr = "女"; |
|
|
|
sexCellTwo.setCellValue(sexStr); |
|
|
|
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 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(); |
|
|
|
@@ -335,8 +236,8 @@ public class WxCUserBasicInfoServiceImpl implements WxCUserBasicInfoService { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
public void downFile(String filePath,String filename, HttpServletResponse response, |
|
|
|
HttpServletRequest req) throws IOException { |
|
|
|
public void downFile(String filePath, String filename, HttpServletResponse response, |
|
|
|
HttpServletRequest req) throws IOException { |
|
|
|
try { |
|
|
|
response.reset(); |
|
|
|
response.setContentType("bin"); |
|
|
|
@@ -369,16 +270,16 @@ public class WxCUserBasicInfoServiceImpl implements WxCUserBasicInfoService { |
|
|
|
public void exportTemplate(HttpServletRequest request, HttpServletResponse response, String tenantId) { |
|
|
|
|
|
|
|
XSSFWorkbook workbook; |
|
|
|
String filepath="./uploads/"; |
|
|
|
String filepath = "./uploads/"; |
|
|
|
File savefile = new File(filepath); |
|
|
|
if (!savefile.exists()) { |
|
|
|
savefile.mkdirs(); |
|
|
|
} |
|
|
|
String filename=UUID.randomUUID()+".xlsx"; |
|
|
|
filepath=filepath+filename; |
|
|
|
String filename = UUID.randomUUID() + ".xlsx"; |
|
|
|
filepath = filepath + filename; |
|
|
|
try { |
|
|
|
File file=new File(filepath); |
|
|
|
workbook=new XSSFWorkbook(); |
|
|
|
File file = new File(filepath); |
|
|
|
workbook = new XSSFWorkbook(); |
|
|
|
|
|
|
|
XSSFSheet sheetTwo = workbook.createSheet("会员信息"); |
|
|
|
Row rowtwo = sheetTwo.createRow(0); |
|
|
|
@@ -398,7 +299,7 @@ public class WxCUserBasicInfoServiceImpl implements WxCUserBasicInfoService { |
|
|
|
workbook.write(fileOut); |
|
|
|
fileOut.close(); |
|
|
|
workbook.close(); |
|
|
|
downFile(filepath,filename,response,request); |
|
|
|
downFile(filepath, filename, response, request); |
|
|
|
FileUtils.forceDelete(file); |
|
|
|
} catch (Exception e) { |
|
|
|
e.printStackTrace(); |
|
|
|
@@ -411,43 +312,67 @@ public class WxCUserBasicInfoServiceImpl implements WxCUserBasicInfoService { |
|
|
|
public ResultData importTemplate(MultipartFile file, String tenantId) { |
|
|
|
|
|
|
|
try { |
|
|
|
|
|
|
|
ImportParams params = new ImportParams(); |
|
|
|
List<WxCUserBasicInfo> datalist = ExcelImportUtil.importExcel(file.getInputStream(), WxCUserBasicInfo.class, params); |
|
|
|
|
|
|
|
|
|
|
|
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){ |
|
|
|
if(user.getPhone()!=null){ |
|
|
|
WxCUserBasicInfo tempuser=null; |
|
|
|
if(list.size()>0){ |
|
|
|
tempuser = list.stream().filter(u -> u.getPhone().equals(user.getPhone())).findFirst().get(); |
|
|
|
} |
|
|
|
if(tempuser!=null){ |
|
|
|
tempuser.setTenantId(tenantId); |
|
|
|
tempuser.setSex(user.getSex()); |
|
|
|
tempuser.setEducation(user.getEducation()); |
|
|
|
tempuser.setBirthdate(user.getBirthdate()); |
|
|
|
tempuser.setName(user.getName()); |
|
|
|
wxCUserBasicInfoMapper.updateByPrimaryKeySelective(tempuser); |
|
|
|
} else { |
|
|
|
user.setId(idWorker.nextId()); |
|
|
|
user.setTenantId(tenantId); |
|
|
|
wxCUserBasicInfoMapper.insertSelective(user); |
|
|
|
for (WxCUserBasicInfo userBase : datalist) { |
|
|
|
Date curDate = new Date(); |
|
|
|
if (StringUtils.isBlank(userBase.getPhone())) |
|
|
|
continue; |
|
|
|
WxCUserBasicInfo oldUserBase = null; |
|
|
|
WxCUserBasicInfo userBaseQ = new WxCUserBasicInfo(); |
|
|
|
userBaseQ.setTenantId(tenantId); |
|
|
|
userBaseQ.setPhone(userBase.getPhone()); |
|
|
|
List<WxCUserBasicInfo> userBList = wxCUserBasicInfoMapper.select(userBaseQ); |
|
|
|
if (userBList.size() > 0) { |
|
|
|
oldUserBase = userBList.get(0); |
|
|
|
} |
|
|
|
|
|
|
|
if (oldUserBase != null) { |
|
|
|
oldUserBase.setTenantId(tenantId); |
|
|
|
oldUserBase.setSex(userBase.getSex()); |
|
|
|
oldUserBase.setEducation(userBase.getEducation()); |
|
|
|
oldUserBase.setBirthdate(userBase.getBirthdate()); |
|
|
|
oldUserBase.setName(userBase.getName()); |
|
|
|
oldUserBase.setUpdateDate(curDate); |
|
|
|
} else { |
|
|
|
userBase.setId(idWorker.nextId()); |
|
|
|
userBase.setTenantId(tenantId); |
|
|
|
userBase.setCreateDate(curDate); |
|
|
|
userBase.setUpdateDate(curDate); |
|
|
|
} |
|
|
|
|
|
|
|
// update 昵称 |
|
|
|
WxCUser cUserQ = new WxCUser(); |
|
|
|
cUserQ.setTenantId(tenantId); |
|
|
|
cUserQ.setPhone(userBase.getPhone()); |
|
|
|
List<WxCUser> userList = wxCUserMapper.select(cUserQ); |
|
|
|
if (userList.size() > 0) { |
|
|
|
WxCUser user = userList.get(0); |
|
|
|
if (user != null) { |
|
|
|
if (user.getNickName() != null) { |
|
|
|
if (oldUserBase != null) { |
|
|
|
oldUserBase.setNickName(user.getNickName()); |
|
|
|
} else { |
|
|
|
userBase.setNickName(user.getNickName()); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
if (oldUserBase != null) { |
|
|
|
wxCUserBasicInfoMapper.updateByPrimaryKeySelective(oldUserBase); |
|
|
|
} else { |
|
|
|
wxCUserBasicInfoMapper.insertSelective(userBase); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
} catch (Exception e) { |
|
|
|
throw new MallinkException(500,"模板导入失败"+e); |
|
|
|
throw new MallinkException(ErrorCode.MEM_IMPORT_ERR.getCode(), e.getMessage()); |
|
|
|
} |
|
|
|
|
|
|
|
return new ResultData(Result.SUCCESS,"导入成功"); |
|
|
|
return new ResultData(Result.SUCCESS, "导入成功"); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |