导出excel

This commit is contained in:
cyk
2023-12-22 19:49:24 +08:00
parent b30162391d
commit cc5276705d
8 changed files with 270 additions and 13 deletions

View File

@@ -1,5 +1,6 @@
package com.lovenav.service;
import com.alibaba.fastjson2.JSONArray;
import com.lovenav.entity.UrlCateList;
import java.util.List;
@@ -9,4 +10,8 @@ public interface UrlCateListService {
public int selectAndInsertUrlCate(String email , String cateName , String parent);
public List<UrlCateList> selectUrListByUserId(Integer userId);
public String countCateContainUrlNumber(String userId);
public JSONArray getUrl(String userId);
}

View File

@@ -1,16 +1,19 @@
package com.lovenav.service.serviceImpl;
import com.alibaba.fastjson2.JSONArray;
import com.alibaba.fastjson2.JSONObject;
import com.lovenav.dao.UrlCateListDao;
import com.lovenav.dao.UrlListDao;
import com.lovenav.dao.UserDao;
import com.lovenav.entity.UrlCateList;
import com.lovenav.entity.UrlList;
import com.lovenav.entity.User;
import com.lovenav.service.UrlCateListService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.Date;
import java.util.List;
import java.util.*;
@Transactional
@Service("urlCateListService")
@@ -20,7 +23,8 @@ public class UrlCateListServiceImpl implements UrlCateListService {
@Autowired
UrlCateListDao urlCateListDao;
@Autowired
UrlListDao urlListDao;
@Autowired
UserDao userDao;
public int selectAndInsertUrlCate(String email , String cateName , String parent )
@@ -53,4 +57,75 @@ public class UrlCateListServiceImpl implements UrlCateListService {
public List<UrlCateList> selectUrListByUserId(Integer userId){
return urlCateListDao.selectUrListByUserId(userId);
}
public String countCateContainUrlNumber(String email){
User user = userDao.selectByEmail(email);
int userId = user.getId();
List<UrlCateList> urlCateLists =urlCateListDao.selectUrListByUserId(userId);
List<UrlList> urlLists = urlListDao.selectUrList();
HashMap<String,Integer> CateNumber = new HashMap<>();
for(UrlCateList urlCateList :urlCateLists)
{
CateNumber.put(urlCateList.getName(),0);
}
for(UrlList urlList : urlLists){
Long id = Long.valueOf(urlList.getCateId());
while(id!= 0)
{
for(UrlCateList urlCateList :urlCateLists)
{
if(id == Long.valueOf(urlCateList.getId())){
int cateNum = CateNumber.get(urlCateList.getName())+1;
CateNumber.put(urlCateList.getName(),cateNum);
id=Long.valueOf(urlCateList.getRootCateId());
break;
}
}
}
}
Iterator iterator = CateNumber.entrySet().iterator();
while(iterator.hasNext()) {
Map.Entry<String, Integer> entry=(Map.Entry<String, Integer>) iterator.next();
for(int i = 0; i<urlCateLists.size();i++)
{
UrlCateList urlCateList = urlCateLists.get(i);
if(urlCateList.getName().equals(entry.getKey()))
{
urlCateList.setUrlNumber(Long.valueOf(entry.getValue()));
urlCateListDao.updateByPrimaryKeySelective(urlCateList);
break;
}
}
}
return CateNumber.toString();
}
public JSONArray getUrl(String userId)
{
List<UrlCateList> urlCateLists =urlCateListDao.selectUrListByUserId(Integer.valueOf(userId));
List<UrlList> urlLists = urlListDao.selectUrList();
JSONArray jsonArray = new JSONArray();
for(UrlCateList urlCateList : urlCateLists)
{
int parentId = urlCateList.getId();
for(UrlList urlList : urlLists)
{
if(urlList.getCateId() == parentId)
{
JSONObject jsonObject = new JSONObject();
jsonObject.put(urlList.getName(),urlList.getUrl());
jsonArray.add(jsonObject);
break;
}
}
}
return jsonArray;
}
}