springcloud_k8s_panzhihuazhihuishequ/common/src/main/java/com/panzhihua/common/model/vos/TreeListVO.java
@@ -7,8 +7,6 @@ @Data public class TreeListVO { private String fatherName; private String orgName; private String name; springcloud_k8s_panzhihuazhihuishequ/common/src/main/java/com/panzhihua/common/model/vos/neighbor/ActivityAnalysisVO.java
@@ -31,4 +31,7 @@ @ApiModelProperty("党员服务总时长") private Integer partyMemberServiceTotalTime; @ApiModelProperty("累计总积分") private Long awardSumCount; } springcloud_k8s_panzhihuazhihuishequ/common/src/main/java/com/panzhihua/common/service/community/CommunityService.java
@@ -256,6 +256,7 @@ import org.springframework.web.multipart.MultipartFile; import javax.annotation.Resource; import javax.servlet.http.HttpServletResponse; /** * @program: springcloud_k8s_panzhihuazhihuishequ @@ -9959,6 +9960,10 @@ @RequestParam(value = "size",required = false) Integer size, @RequestParam(value = "belongTo",required = false) String belongTo, @RequestParam(value = "unitId",required = false) Long unitId,@RequestParam(value = "loginAccount",required = false) String loginAccount); @GetMapping("/neighbor/export") public R export(@RequestParam("year") Integer year, @RequestParam("belongTo") String belongTo, @RequestParam("communityId") Long communityId, HttpServletResponse response); /** * 批量删除活动 * @param ids springcloud_k8s_panzhihuazhihuishequ/community_backstage/pom.xml
@@ -84,6 +84,12 @@ <artifactId>kaptcha</artifactId> <version>2.3.2</version> </dependency> <dependency> <groupId>com.alibaba</groupId> <artifactId>easyexcel</artifactId> <version>3.1.3</version> </dependency> </dependencies> <build> springcloud_k8s_panzhihuazhihuishequ/community_backstage/src/main/java/com/panzhihua/community_backstage/api/CommunityActivityApi.java
@@ -1,7 +1,6 @@ package com.panzhihua.community_backstage.api; import static java.util.Objects.isNull; import static java.util.Objects.nonNull; import java.io.BufferedWriter; import java.io.File; @@ -18,6 +17,7 @@ import java.util.Map; import javax.annotation.Resource; import javax.servlet.http.HttpServletResponse; import javax.validation.Valid; import com.panzhihua.common.model.dtos.partybuilding.NewFightIntegral; @@ -27,6 +27,7 @@ import com.panzhihua.common.model.vos.neighbor.ActivityAnalysisVO; import com.panzhihua.common.model.vos.user.SysTemplateConfigVO; import com.panzhihua.common.service.partybuilding.NewStriveForFeign; import com.panzhihua.common.utlis.*; import io.swagger.annotations.*; import org.springframework.beans.factory.annotation.Value; import org.springframework.util.ObjectUtils; @@ -60,12 +61,6 @@ import com.panzhihua.common.model.vos.user.SysUserNoticeVO; import com.panzhihua.common.service.community.CommunityService; import com.panzhihua.common.service.user.UserService; import com.panzhihua.common.utlis.DateUtils; import com.panzhihua.common.utlis.QRCodeUtils; import com.panzhihua.common.utlis.SFTPUtil; import com.panzhihua.common.utlis.StringUtils; import com.panzhihua.common.utlis.WxUtil; import com.panzhihua.common.utlis.WxXCXTempSend; import com.panzhihua.common.validated.AddGroup; import com.panzhihua.community_backstage.excel.CustomSheetWriteHandler; @@ -1386,4 +1381,14 @@ @RequestParam(value = "unitId",required = false) Long unitId){ return communityService.institutionalUnitServiceAnalysis(year,type,range,communityId,page,size,belongTo,unitId,this.getLoginUserInfo().getAccount()); } @GetMapping("/exportExcel") public R exportExcel(@RequestParam(value = "year",required = false) Integer year, @RequestParam(value = "type",required = false) Integer type, @RequestParam(value = "communityId",required = false) Long communityId, @RequestParam(value = "belongTo",required = false) String belongTo, HttpServletResponse response){ communityService.export(year,belongTo,communityId,response); return R.ok(); } } springcloud_k8s_panzhihuazhihuishequ/community_backstage/src/main/java/com/panzhihua/community_backstage/util/ExcelUtils.java
New file @@ -0,0 +1,84 @@ package com.panzhihua.community_backstage.util; import com.alibaba.excel.EasyExcel; import com.alibaba.excel.support.ExcelTypeEnum; import com.google.api.client.util.IOUtils; import lombok.extern.slf4j.Slf4j; import javax.servlet.ServletOutputStream; import javax.servlet.http.HttpServletResponse; import java.io.File; import java.io.FileInputStream; import java.io.UnsupportedEncodingException; import java.net.URLEncoder; import java.util.List; @Slf4j public class ExcelUtils { /** * 导出Excel(07版.xlsx)到指定路径下 * * @param path 路径 * @param excelName Excel名称 * @param sheetName sheet页名称 * @param clazz Excel要转换的类型 * @param data 要导出的数据 */ public static void export2File(String path, String excelName, String sheetName, Class clazz, List data) { String fileName = path.concat(excelName).concat(ExcelTypeEnum.XLSX.getValue()); EasyExcel.write(fileName, clazz).sheet(sheetName).doWrite(data); } /** * 导出Excel(07版.xlsx)到web * * @param response 响应 * @param excelName Excel名称 * @param sheetName sheet页名称 * @param clazz Excel要转换的类型 * @param data 要导出的数据 * @throws Exception */ public static void export2Web(HttpServletResponse response, String excelName, String sheetName, Class clazz, List data) throws Exception { response.setContentType("application/vnd.ms-excel"); response.setCharacterEncoding("utf-8"); // 这里URLEncoder.encode可以防止中文乱码 excelName = URLEncoder.encode(excelName, "UTF-8"); response.setHeader("Content-disposition", "attachment;filename=" + excelName + ExcelTypeEnum.XLSX.getValue()); EasyExcel.write(response.getOutputStream(), clazz).sheet(sheetName).doWrite(data); } /** * 将指定位置指定名称的Excel导出到web * * @param response 响应 * @param path 文件路径 * @param excelName 文件名称 * @return * @throws UnsupportedEncodingException */ public static String export2Web4File(HttpServletResponse response, String path, String excelName) throws UnsupportedEncodingException { File file = new File(path.concat(excelName).concat(ExcelTypeEnum.XLSX.getValue())); if (!file.exists()) { return "文件不存在!"; } response.setContentType("application/vnd.ms-excel"); response.setCharacterEncoding("utf-8"); // 这里URLEncoder.encode可以防止中文乱码 excelName = URLEncoder.encode(excelName, "UTF-8"); response.setHeader("Content-disposition", "attachment;filename=" + excelName + ExcelTypeEnum.XLSX.getValue()); try ( FileInputStream in = new FileInputStream(file); ServletOutputStream out = response.getOutputStream(); ) { IOUtils.copy(in, out); return "导出成功!"; } catch (Exception e) { log.error("导出文件异常:", e); } return "导出失败!"; } } springcloud_k8s_panzhihuazhihuishequ/service_community/src/main/java/com/panzhihua/service_community/api/NeighborApi.java
@@ -1,6 +1,7 @@ package com.panzhihua.service_community.api; import javax.annotation.Resource; import javax.servlet.http.HttpServletResponse; import com.panzhihua.service_community.model.dos.ComActNeighborCircleDO; import org.springframework.beans.BeanUtils; @@ -429,6 +430,14 @@ } /** * 导出 */ @GetMapping("/export") public R export(@RequestParam("year") Integer year, @RequestParam("belongTo") String belongTo, @RequestParam("communityId") Long communityId, HttpServletResponse response) throws Exception { return this.comActNeighborCircleService.export(year,belongTo,communityId,response); } /** * 小程序服务统计 * @param serviceStaticDTO * @return springcloud_k8s_panzhihuazhihuishequ/service_community/src/main/java/com/panzhihua/service_community/dao/NewFightNeedProblemInventoryMapper.java
@@ -4,7 +4,12 @@ import com.baomidou.mybatisplus.core.mapper.BaseMapper; import com.panzhihua.service_community.entity.NewFightNeedProblemInventory; import org.apache.ibatis.annotations.Mapper; import org.apache.ibatis.annotations.Select; import java.util.List; @Mapper public interface NewFightNeedProblemInventoryMapper extends BaseMapper<NewFightNeedProblemInventory> { @Select("select * from new_fight_need_problem_inventory") List<NewFightNeedProblemInventory> selectAll(); } springcloud_k8s_panzhihuazhihuishequ/service_community/src/main/java/com/panzhihua/service_community/entity/NewFightNeedProblemInventory.java
@@ -2,10 +2,56 @@ import lombok.Data; import java.util.Date; @Data public class NewFightNeedProblemInventory { private Long id; private String title; private String classifyId; private String claimNum; private String address; private String lat; private String lon; private Date claimStartTime; private Date claimEndTime; private Date needStartTime; private Date needEndTime; private String linkman; private String phone; private String signInScope; private String signOutScope; private String award; private String content; private String imgsUrl; private Date creationTime; private Date updateTime; private String kind; private String userId; private String communityId; private String status; } springcloud_k8s_panzhihuazhihuishequ/service_community/src/main/java/com/panzhihua/service_community/model/dos/ExcelDO.java
New file @@ -0,0 +1,37 @@ package com.panzhihua.service_community.model.dos; import com.alibaba.excel.annotation.ExcelProperty; import com.alibaba.excel.annotation.write.style.ColumnWidth; import lombok.Data; @Data public class ExcelDO { @ColumnWidth(10) // 定义列宽 @ExcelProperty(value = {"单位归属"}, index = 0) private String belongTo; @ColumnWidth(20) // 定义列宽 @ExcelProperty(value = {"所属党组织"}, index = 1) private String orgName; @ColumnWidth(26) // 定义列宽 @ExcelProperty(value = {"单位名称"}, index = 2) private String unitName; @ColumnWidth(20) // 定义列宽 @ExcelProperty(value = {"报道社区名称"}, index = 3) private String communityName; @ColumnWidth(20) // 定义列宽 @ExcelProperty(value = {"服务次数"}, index = 4) private Integer serviceTimes; @ColumnWidth(20) // 定义列宽 @ExcelProperty(value = {"服务时长"}, index = 5) private Integer serviceTime; @ColumnWidth(20) // 定义列宽 @ExcelProperty(value = {"累计积分"}, index = 6) private Long awardSum; } springcloud_k8s_panzhihuazhihuishequ/service_community/src/main/java/com/panzhihua/service_community/service/ComActNeighborCircleService.java
@@ -10,6 +10,8 @@ import com.panzhihua.service_community.model.dos.ComActNeighborCircleDO; import org.springframework.web.bind.annotation.RequestParam; import javax.servlet.http.HttpServletResponse; /** * @auther lyq * @create 2021-04-28 09:20:49 @@ -257,6 +259,11 @@ R institutionalUnitServiceAnalysis(Integer year, Integer type, Integer range,Long communityId,Integer page,Integer size,String belongTo,Long unitId); /** * 导出 */ R export(Integer year,String belongTo,Long communityId, HttpServletResponse response) throws Exception; /** * 后台服务统计 * @param serviceStaticDTO * @return springcloud_k8s_panzhihuazhihuishequ/service_community/src/main/java/com/panzhihua/service_community/service/impl/ComActNeighborCircleServiceImpl.java
@@ -25,6 +25,7 @@ import com.panzhihua.service_community.service.ComActNeighborCircleBrowseService; import com.panzhihua.service_community.service.ComActNeighborCircleService; import com.panzhihua.service_community.service.ComActNeighborCircleTopicService; import com.panzhihua.service_community.util.ExcelUtils; import lombok.extern.slf4j.Slf4j; import org.apache.commons.lang3.ObjectUtils; import org.springframework.beans.BeanUtils; @@ -33,6 +34,7 @@ import org.springframework.transaction.annotation.Transactional; import javax.annotation.Resource; import javax.servlet.http.HttpServletResponse; import java.util.*; import java.util.stream.Collectors; @@ -1228,6 +1230,8 @@ } } //统计积分 List<NewFightNeedProblemInventory> allList = newFightNeedProblemInventoryMapper.selectAll(); Map<Long, String> awardMap = allList.stream().filter(Objects::nonNull).collect(Collectors.toMap(NewFightNeedProblemInventory::getId, NewFightNeedProblemInventory::getAward)); for (UnitActivityAnalysisVO unitVO : unitActivityAnalysisVOS) { Long unitId1 = unitVO.getUnitId(); @@ -1240,8 +1244,9 @@ //任务id集合 List<String> taskIds = inventories.stream().map(NewFightNeedProblemClaim::getTaskId).distinct().collect(Collectors.toList()); for (String taskId : taskIds) { NewFightNeedProblemInventory newFightNeedProblemInventory = newFightNeedProblemInventoryMapper.selectById(taskId); String award = newFightNeedProblemInventory.getAward(); // NewFightNeedProblemInventory newFightNeedProblemInventory = newFightNeedProblemInventoryMapper.selectById(taskId); // String award = newFightNeedProblemInventory.getAward(); String award = awardMap.get(Long.parseLong(taskId)); Long count = collectMap.get(taskId); long i = Long.parseLong(award) * count; sum = sum + i; @@ -1254,6 +1259,7 @@ Integer unitServiceTotalTime=0; Integer memberServiceCount=0; Integer memberServiceTotalTome=0; long awardSumCount=0L; for (UnitActivityAnalysisVO vo : unitActivityAnalysisVOS) { //避免空指针 if (ObjectUtils.isNotEmpty(vo)){ @@ -1276,22 +1282,34 @@ } } } for (UnitActivityAnalysisVO vo : unitActivityAnalysisVOS) { if(ObjectUtils.isNotEmpty(vo)){ if(ObjectUtils.isNotEmpty(vo.getAwardSum())){ awardSumCount += vo.getAwardSum(); } } } activityVO.setAwardSumCount(awardSumCount); activityVO.setUnitServiceTotalCount(unitServiceCount); activityVO.setUnitServiceTotalTime(unitServiceTotalTime); activityVO.setPartyMemberServiceTotalCount(memberServiceCount); activityVO.setPartyMemberServiceTotalTime(memberServiceTotalTome); //处理排序 // if (null != type){ // if (type.equals(1)){ // //按时长排序 // ListUtil.sortByProperty(unitActivityAnalysisVOS, "serviceTime"); // ListUtil.sortByProperty(partyMemberAnalysisVOS, "serviceTime"); // }else if (type.equals(2)){ // //按次数排序 // ListUtil.sortByProperty(unitActivityAnalysisVOS, "serviceTimes"); // ListUtil.sortByProperty(partyMemberAnalysisVOS, "serviceTimes"); // } // } if (null != type){ if (type.equals(1)){ //按时长排序 ListUtil.sortByProperty(unitActivityAnalysisVOS, "serviceTime"); ListUtil.sortByProperty(partyMemberAnalysisVOS, "serviceTime"); }else if (type.equals(2)){ //按次数排序 ListUtil.sortByProperty(unitActivityAnalysisVOS, "serviceTimes"); ListUtil.sortByProperty(partyMemberAnalysisVOS, "serviceTimes"); }else if(type.equals(3)){ //按积分排序 ListUtil.sortByProperty(unitActivityAnalysisVOS,"awardSum"); // ListUtil.sortByProperty(unitActivityAnalysisVOS,""); } } //处理分页 PageVO<List<UnitActivityAnalysisVO>> unitPage=new PageVO<>(); PageVO<List<PartyMemberAnalysisVO>> memberPage=new PageVO<>(); @@ -1317,6 +1335,101 @@ } @Override public R export(Integer year,String belongTo,Long communityId, HttpServletResponse response) throws Exception { List<ExcelDO> excelDOList = new ArrayList<>(); String beginTime=null; String endTime=null; if (null != year){ //设置开始,截止时间 beginTime=year.toString().concat("-01-01"); endTime=year.toString().concat("-12-31"); } //获取单位活动统计数据(邻里圈) List<UnitActivityAnalysisVO> unitActivityAnalysisVOS = comActNeighborCircleDAO.institutionalUnitServiceAnalysis(beginTime, endTime, belongTo,communityId); //获取单位活动统计数据(活动) List<UnitActivityAnalysisVO> unitActivityAnalysisVOS1 = comActNeighborCircleDAO.institutionalUnitActivityAnalysis(beginTime, endTime, belongTo,communityId); if (!unitActivityAnalysisVOS.isEmpty()){ for (UnitActivityAnalysisVO unitActivityAnalysisVO : unitActivityAnalysisVOS){ if (ObjectUtils.isNotEmpty(unitActivityAnalysisVO)){ if (ObjectUtils.isNotEmpty(unitActivityAnalysisVO.getUnitId())){ //设置单位名称 unitActivityAnalysisVO.setUnitName(comActDAO.selectUnitName(unitActivityAnalysisVO.getUnitId())); //统计活动表中的活动信息 } if (ObjectUtils.isNotEmpty(unitActivityAnalysisVO.getCommunityId())){ unitActivityAnalysisVO.setCommunityName(comActDAO.selectById(unitActivityAnalysisVO.getCommunityId()).getName()); } } } } //活动表数据处理 if (!unitActivityAnalysisVOS1.isEmpty()){ for (UnitActivityAnalysisVO vo : unitActivityAnalysisVOS1) { if(ObjectUtils.isNotEmpty(vo)){ if (ObjectUtils.isNotEmpty(vo.getUnitId())){ //判断邻里圈统计中是否已有该单位数据 Map<String, Integer> param = alreadyAnalysis(vo.getUnitId(), unitActivityAnalysisVOS); if (param.get("flag")==1){ //已有数据,将时长,次数相加 Integer serviceTime = vo.getServiceTime(); Integer serviceTimes = vo.getServiceTimes(); unitActivityAnalysisVOS.get(param.get("index")).setServiceTime(unitActivityAnalysisVOS.get(param.get("index")).getServiceTime()+serviceTime); unitActivityAnalysisVOS.get(param.get("index")).setServiceTimes(unitActivityAnalysisVOS.get(param.get("index")).getServiceTimes()+serviceTimes); }else { //新数据,获取单位,社区名 vo.setUnitName(comActDAO.selectUnitName(vo.getUnitId())); if (ObjectUtils.isNotEmpty(vo.getCommunityId())) { ComActDO actDO=comActDAO.selectById(vo.getCommunityId()); if(actDO!=null && !StringUtils.isEmpty(actDO.getName())) { vo.setCommunityName(actDO.getName()); } } unitActivityAnalysisVOS.add(vo); } } } } } List<NewFightNeedProblemInventory> allList = newFightNeedProblemInventoryMapper.selectAll(); Map<Long, String> awardMap = allList.stream().filter(Objects::nonNull).collect(Collectors.toMap(NewFightNeedProblemInventory::getId, NewFightNeedProblemInventory::getAward)); for (UnitActivityAnalysisVO unitVO : unitActivityAnalysisVOS) { Long unitId1 = unitVO.getUnitId(); LambdaQueryWrapper<NewFightNeedProblemClaim> wrapper = new LambdaQueryWrapper<>(); wrapper.eq(NewFightNeedProblemClaim::getUnitId,String.valueOf(unitId1)); List<NewFightNeedProblemClaim> inventories = newFightNeedProblemClaimMapper.selectList(wrapper); Map<String, Long> collectMap = inventories.stream() .collect(Collectors.groupingBy(NewFightNeedProblemClaim::getTaskId, Collectors.counting())); long sum = 0L; //任务id集合 List<String> taskIds = inventories.stream().map(NewFightNeedProblemClaim::getTaskId).distinct().collect(Collectors.toList()); for (String taskId : taskIds) { // NewFightNeedProblemInventory newFightNeedProblemInventory = newFightNeedProblemInventoryMapper.selectById(taskId); // String award = newFightNeedProblemInventory.getAward(); String award = awardMap.get(Long.parseLong(taskId)); Long count = collectMap.get(taskId); long i = Long.parseLong(award) * count; sum = sum + i; } unitVO.setAwardSum(sum); } for (UnitActivityAnalysisVO vo : unitActivityAnalysisVOS) { ExcelDO excelDO = new ExcelDO(); excelDO.setBelongTo(vo.getBelongTo()); excelDO.setOrgName(vo.getOrgName()); excelDO.setUnitName(vo.getUnitName()); excelDO.setCommunityName(vo.getCommunityName()); excelDO.setServiceTime(vo.getServiceTime()); excelDO.setAwardSum(vo.getAwardSum()); excelDOList.add(excelDO); } ExcelUtils.export2Web(response,"双争双评","sheet",ExcelDO.class,excelDOList); return R.ok(); } @Override public R serviceStaticBackstage(ServiceStaticBackstageDTO serviceStaticDTO) { springcloud_k8s_panzhihuazhihuishequ/service_community/src/main/java/com/panzhihua/service_community/util/ExcelUtils.java
New file @@ -0,0 +1,85 @@ package com.panzhihua.service_community.util; import com.alibaba.excel.EasyExcel; import com.alibaba.excel.support.ExcelTypeEnum; import lombok.extern.slf4j.Slf4j; import org.apache.commons.io.IOUtils; import javax.servlet.ServletOutputStream; import javax.servlet.http.HttpServletResponse; import java.io.File; import java.io.FileInputStream; import java.io.UnsupportedEncodingException; import java.net.URLEncoder; import java.util.List; @Slf4j public class ExcelUtils { /** * 导出Excel(07版.xlsx)到指定路径下 * * @param path 路径 * @param excelName Excel名称 * @param sheetName sheet页名称 * @param clazz Excel要转换的类型 * @param data 要导出的数据 */ public static void export2File(String path, String excelName, String sheetName, Class clazz, List data) { String fileName = path.concat(excelName).concat(ExcelTypeEnum.XLSX.getValue()); EasyExcel.write(fileName, clazz).sheet(sheetName).doWrite(data); } /** * 导出Excel(07版.xlsx)到web * * @param response 响应 * @param excelName Excel名称 * @param sheetName sheet页名称 * @param clazz Excel要转换的类型 * @param data 要导出的数据 * @throws Exception */ public static void export2Web(HttpServletResponse response, String excelName, String sheetName, Class clazz, List data) throws Exception { response.setContentType("application/vnd.ms-excel"); response.setCharacterEncoding("utf-8"); // 这里URLEncoder.encode可以防止中文乱码 excelName = URLEncoder.encode(excelName, "UTF-8"); response.setHeader("Content-disposition", "attachment;filename=" + excelName + ExcelTypeEnum.XLSX.getValue()); EasyExcel.write(response.getOutputStream(), clazz).sheet(sheetName).doWrite(data); } /** * 将指定位置指定名称的Excel导出到web * * @param response 响应 * @param path 文件路径 * @param excelName 文件名称 * @return * @throws UnsupportedEncodingException */ public static String export2Web4File(HttpServletResponse response, String path, String excelName) throws UnsupportedEncodingException { File file = new File(path.concat(excelName).concat(ExcelTypeEnum.XLSX.getValue())); if (!file.exists()) { return "文件不存在!"; } response.setContentType("application/vnd.ms-excel"); response.setCharacterEncoding("utf-8"); // 这里URLEncoder.encode可以防止中文乱码 excelName = URLEncoder.encode(excelName, "UTF-8"); response.setHeader("Content-disposition", "attachment;filename=" + excelName + ExcelTypeEnum.XLSX.getValue()); try ( FileInputStream in = new FileInputStream(file); ServletOutputStream out = response.getOutputStream(); ) { IOUtils.copy(in, out); return "导出成功!"; } catch (Exception e) { log.error("导出文件异常:", e); } return "导出失败!"; } }