package com.panzhihua.service_community.service.impl;
|
|
import java.math.BigDecimal;
|
import java.math.RoundingMode;
|
import java.util.*;
|
|
import javax.annotation.Resource;
|
|
import cn.hutool.core.util.NumberUtil;
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
import com.panzhihua.common.model.vos.DateVO;
|
import com.panzhihua.common.model.vos.community.building.admin.BuildingListHeaderStatisticsAdminVo;
|
import com.panzhihua.common.model.vos.community.building.admin.PageBuildingListAdminVo;
|
import com.panzhihua.common.model.vos.puda.BasicDataVO;
|
import com.panzhihua.common.model.vos.puda.CitizenInfoVO;
|
import com.panzhihua.common.model.vos.puda.DynamicVO;
|
import com.panzhihua.common.model.vos.puda.SpecialPeopleVO;
|
import com.panzhihua.common.service.community.CommunityService;
|
import com.panzhihua.service_community.service.ComActBuildingService;
|
import org.springframework.stereotype.Service;
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
import com.panzhihua.common.model.vos.R;
|
import com.panzhihua.common.model.vos.screen.*;
|
import com.panzhihua.common.utlis.DateUtils;
|
import com.panzhihua.common.utlis.StringUtils;
|
import com.panzhihua.service_community.dao.*;
|
import com.panzhihua.service_community.model.dos.ComActDO;
|
import com.panzhihua.service_community.model.dos.ComActDynDO;
|
import com.panzhihua.service_community.service.ScreenWorkService;
|
|
import cn.hutool.core.date.DateTime;
|
import cn.hutool.core.date.DateUtil;
|
|
/**
|
* @author xyh
|
* @date 2021/6/15 15:14
|
*/
|
@Service
|
public class ScreenWorkServiceImpl implements ScreenWorkService {
|
|
private static final Integer pageSize = 200;
|
private final String moth_format_str = "yyyy-MM";
|
private final String[] monthStr = new String[] {"一", "二", "三", "四", "五", "六", "七", "八", "九", "十", "十一", "十二"};
|
@Resource
|
private ComActDAO comActDAO;
|
@Resource
|
private ComActNeighborCircleDAO comActNeighborCircleDAO;
|
@Resource
|
private ComActDynDAO comActDynDAO;
|
@Resource
|
private ComActMicroWishDAO comActMicroWishDAO;
|
@Resource
|
private ComActActivityDAO actActivityDAO;
|
@Resource
|
private ComActDiscussDAO comActDiscussDAO;
|
@Resource
|
private ComPbDynDAO comPbDynDAO;
|
@Resource
|
private ComActEasyPhotoDAO comActEasyPhotoDAO;
|
@Resource
|
private ComScreenDao comScreenDao;
|
@Resource
|
private ComActBuildingService comActBuildingService;
|
|
@Override
|
public R statisticNeighborCircle(Long communityId) {
|
|
ComActNeighborCircleScreenVO comActNeighborCircleScreenVO = new ComActNeighborCircleScreenVO();
|
String date = DateUtils.getDateFormatString(new Date(), moth_format_str);
|
Map<String, Long> countMap = comActNeighborCircleDAO.countByCommunityId(communityId, date);
|
comActNeighborCircleScreenVO.setCurrentNum(countMap.get("currentNum"));
|
comActNeighborCircleScreenVO.setTotalNum(countMap.get("totalNum"));
|
Map<String, Object> sumMap = comActNeighborCircleDAO.sumScreenNum(communityId);
|
comActNeighborCircleScreenVO.setFabulousNum(
|
sumMap.get("fabulousNum") == null ? 0L : Long.valueOf(sumMap.get("fabulousNum").toString()));
|
comActNeighborCircleScreenVO
|
.setCommentNum(sumMap.get("commentNum") == null ? 0L : Long.valueOf(sumMap.get("commentNum").toString()));
|
comActNeighborCircleScreenVO
|
.setSharedNum(sumMap.get("forwardNum") == null ? 0L : Long.valueOf(sumMap.get("forwardNum").toString()));
|
// 查询最近发布的邻里圈
|
comActNeighborCircleScreenVO.setList(comActNeighborCircleDAO.screenNeighborCircle(communityId, pageSize));
|
// 查询最近发布的邻里圈图片
|
comActNeighborCircleScreenVO
|
.setImgs(convertStringList(comActNeighborCircleDAO.screenNeighborCircleImgs(communityId, pageSize)));
|
return R.ok(comActNeighborCircleScreenVO);
|
}
|
|
@Override
|
public R wish(Long communityId) {
|
ComActMicroWishScreenVO wishScreenVO = new ComActMicroWishScreenVO();
|
String date = DateUtils.getDateFormatString(new Date(), moth_format_str);
|
// 统计本月新增,累计实现,待实现
|
Map<String, Long> countMap = comActMicroWishDAO.countByCommunityId(communityId, date);
|
wishScreenVO.setCompletedNum(countMap.get("completedNum") == null ? 0L : countMap.get("completedNum"));
|
wishScreenVO.setWillNum(countMap.get("willNum") == null ? 0L : countMap.get("willNum"));
|
wishScreenVO.setCurrentNum(countMap.get("currentNum") == null ? 0L : countMap.get("currentNum"));
|
// 微心愿轮播图片
|
wishScreenVO.setImgs(convertStringList(comActMicroWishDAO.getAllImgs(communityId, pageSize)));
|
return R.ok(wishScreenVO);
|
}
|
|
private List<String> convertStringList(List<String> imgList) {
|
List<String> imgs = new ArrayList<>();
|
for (String img : imgList) {
|
if (StringUtils.isEmpty(img)) {
|
continue;
|
}
|
String[] arrs = img.split(",");
|
if (arrs.length > 1) {
|
for (String arr : arrs) {
|
imgs.add(arr);
|
}
|
} else {
|
imgs.add(img);
|
}
|
}
|
return imgs;
|
}
|
|
@Override
|
public R activity(Long communityId) {
|
ComActActivityScreenVO comActActivityScreenVO = new ComActActivityScreenVO();
|
|
comActActivityScreenVO.setImgs(convertStringList(actActivityDAO.listImg(communityId)));
|
// 统计本月新增、居民活动,志愿者活动
|
String date = DateUtils.getDateFormatString(new Date(), moth_format_str);
|
Map<String, Long> countMap = actActivityDAO.countByCommunityId(communityId, date);
|
comActActivityScreenVO.setTotalNum(countMap.get("totalNum") == null ? 0L : countMap.get("totalNum"));
|
comActActivityScreenVO.setCurrentNum(countMap.get("currentNum") == null ? 0L : countMap.get("currentNum"));
|
comActActivityScreenVO.setCommonNum(countMap.get("commonNum") == null ? 0L : countMap.get("commonNum"));
|
comActActivityScreenVO
|
.setCommonPeopleNum(countMap.get("commonPeopleNum") == null ? 0L : countMap.get("commonPeopleNum"));
|
comActActivityScreenVO
|
.setVolunteerNum(countMap.get("volunteerNum") == null ? 0L : countMap.get("volunteerNum"));
|
comActActivityScreenVO.setVolunteerPeopleNum(
|
countMap.get("volunteerPeopleNum") == null ? 0L : countMap.get("volunteerPeopleNum"));
|
// 最近活动
|
comActActivityScreenVO.setList(actActivityDAO.screenActivity(communityId, pageSize));
|
return R.ok(comActActivityScreenVO);
|
}
|
|
@Override
|
public R discuss(Long communityId) {
|
ComActDiscussScreenVO discussScreenVO = new ComActDiscussScreenVO();
|
// 统计本月新增,总共,图文,投票
|
String date = DateUtils.getDateFormatString(new Date(), moth_format_str);
|
Map<String, Long> countMap = comActDiscussDAO.countByCommunityId(communityId, date);
|
discussScreenVO.setCurrentNum(countMap.get("currentNum") == null ? 0L : countMap.get("currentNum"));
|
discussScreenVO.setTotalNum(countMap.get("totalNum") == null ? 0L : countMap.get("totalNum"));
|
discussScreenVO.setImgNum(countMap.get("imgNum") == null ? 0L : countMap.get("imgNum"));
|
discussScreenVO.setImgPeopleNum(countMap.get("imgPeopleNum") == null ? 0L : countMap.get("imgPeopleNum"));
|
discussScreenVO.setVoteNum(discussScreenVO.getTotalNum() - discussScreenVO.getImgNum());
|
discussScreenVO.setVotePeopleNum(countMap.get("votePeopleNum") == null ? 0L : countMap.get("votePeopleNum"));
|
discussScreenVO.setList(comActDiscussDAO.screenDiscuss(communityId, pageSize));
|
return R.ok(discussScreenVO);
|
}
|
|
@Override
|
public R pbWork(Long communityId) {
|
ComPbWorkScreenVO pbWorkScreenVO = new ComPbWorkScreenVO();
|
String date = DateUtils.getDateFormatString(new Date(), moth_format_str);
|
Map<String, Long> countMap = comPbDynDAO.countByCommunityId(communityId, date);
|
pbWorkScreenVO.setActivityNum(countMap.get("activityNum") == null ? 0L : countMap.get("activityNum"));
|
pbWorkScreenVO.setDynNum(countMap.get("dynNum") == null ? 0L : countMap.get("dynNum"));
|
pbWorkScreenVO.setTotalNum(pbWorkScreenVO.getActivityNum() + pbWorkScreenVO.getDynNum());
|
pbWorkScreenVO.setCurrentNum(countMap.get("currentNum") == null ? 0L : countMap.get("currentNum"));
|
// 统计近半年数据
|
List<PbWorkVO> list = new ArrayList<>();
|
for (PbWorkVO workVO : listHalfYear()) {
|
PbWorkVO result = comPbDynDAO.countByTime(workVO.getStart(), workVO.getEnd(), communityId);
|
result.setMonth(workVO.getMonth());
|
list.add(result);
|
}
|
pbWorkScreenVO.setList(list);
|
return R.ok(pbWorkScreenVO);
|
}
|
|
private List<PbWorkVO> listHalfYear() {
|
List<PbWorkVO> dateList = new ArrayList<>();
|
Date now = new Date();
|
for (int i = 6; i >= 1; i--) {
|
Date date = DateUtils.getDateM(now, -i);
|
DateTime endDay = DateUtil.endOfMonth(date);
|
|
int m = DateUtil.month(endDay);
|
if (m == 0) {
|
m = 12;
|
}
|
m--;
|
int day = DateUtil.dayOfMonth(endDay);
|
int half = day / 2;
|
String month = DateUtil.format(date, moth_format_str);
|
PbWorkVO pbWorkVO = new PbWorkVO();
|
pbWorkVO.setMonth(monthStr[m] + "月上旬");
|
pbWorkVO.setStart(month + "-01 00:00:00");
|
pbWorkVO.setEnd(month + "-" + half + " 23:59:58");
|
dateList.add(pbWorkVO);
|
PbWorkVO pbWorkVO2 = new PbWorkVO();
|
pbWorkVO2.setMonth(monthStr[m] + "月下旬");
|
pbWorkVO2.setStart(month + "-" + half + " 23:59:58");
|
pbWorkVO2.setEnd(DateUtils.getDateFormatString(endDay, "yyyy-MM-dd HH:mm:ss"));
|
dateList.add(pbWorkVO2);
|
}
|
return dateList;
|
|
}
|
|
@Override
|
public R easyPhoto(Long communityId) {
|
ComActEasyPhotoScreenVO comActEasyPhotoScreenVO = new ComActEasyPhotoScreenVO();
|
comActEasyPhotoScreenVO.setDeal(comActEasyPhotoDAO.countDeal(communityId));
|
comActEasyPhotoScreenVO.setPub(comActEasyPhotoDAO.countPub(communityId));
|
comActEasyPhotoScreenVO.setApproved(comActEasyPhotoDAO.countApproved(communityId));
|
String date = DateUtils.getDateFormatString(new Date(), moth_format_str);
|
Map<String, Object> countMap = comActEasyPhotoDAO.countByCommunityId(communityId, date);
|
comActEasyPhotoScreenVO.setCurrentNum(
|
countMap.get("currentNum") == null ? 0L : Long.valueOf(countMap.get("currentNum").toString()));
|
comActEasyPhotoScreenVO
|
.setNoneDeal(countMap.get("noneDeal") == null ? 0L : Long.valueOf(countMap.get("noneDeal").toString()));
|
comActEasyPhotoScreenVO
|
.setPubPoint(countMap.get("pubPoint") == null ? 0 : Integer.valueOf(countMap.get("pubPoint").toString()));
|
comActEasyPhotoScreenVO.setDealTime(
|
countMap.get("dealTime") == null ? 0 : Double.valueOf(countMap.get("dealTime").toString()).intValue());
|
List<EastPhotoVO> list = new ArrayList<>();
|
for (PbWorkVO workVO : listHalfYear()) {
|
String nowDate = DateUtils.getDateFormatString(DateUtil.parseDate(workVO.getStart()), moth_format_str);
|
EastPhotoVO result =
|
comActEasyPhotoDAO.countByTime(workVO.getStart(), workVO.getEnd(), nowDate, communityId);
|
result.setMonth(workVO.getMonth());
|
list.add(result);
|
}
|
comActEasyPhotoScreenVO.setList(list);
|
return R.ok(comActEasyPhotoScreenVO);
|
}
|
|
private List<EasyPhotoPointVO> getList(Map<String, Long> dealMap) {
|
Set<Map.Entry<String, Long>> entrySet = dealMap.entrySet();
|
|
List<EasyPhotoPointVO> list = new ArrayList<>();
|
for (Map.Entry<String, Long> en : entrySet) {
|
EasyPhotoPointVO easyPhotoPointVO = new EasyPhotoPointVO();
|
easyPhotoPointVO.setTypeName(en.getKey());
|
easyPhotoPointVO.setPoint(en.getValue().intValue());
|
list.add(easyPhotoPointVO);
|
}
|
return list;
|
|
}
|
|
@Override
|
public R workCount(Long communityId) {
|
ComActWorkScreenVO comActWorkScreenVO = new ComActWorkScreenVO();
|
// 已完成
|
comActWorkScreenVO.setCompletetList(comActNeighborCircleDAO.countAllCompletedWorkByCommunityId(communityId));
|
|
// 未完成
|
comActWorkScreenVO.setNoneList(comActNeighborCircleDAO.countAllNoneCompletedWorkByCommunityId(communityId));
|
comActWorkScreenVO
|
.setTotalCompleted(comActWorkScreenVO.getCompletetList().stream().mapToInt(PieElementVO::getNum).sum());
|
comActWorkScreenVO
|
.setTotalNoneCompleted(comActWorkScreenVO.getNoneList().stream().mapToInt(PieElementVO::getNum).sum());
|
|
// 统计平均耗时、平均每天完成个数
|
Map<String, Object> avgMap = comActNeighborCircleDAO.countAvgByCommunityId(communityId);
|
comActWorkScreenVO.setAvgTime(avgMap.get("avgTime") == null ? "0h"
|
: convertTimeStr(Double.valueOf(avgMap.get("avgTime").toString()).intValue()));
|
|
ComActDO comActDO = comActDAO.selectById(communityId);
|
BigDecimal days = new BigDecimal(DateUtil.betweenDay(comActDO.getCreateAt(), new Date(), false));
|
BigDecimal num = new BigDecimal(comActWorkScreenVO.getTotalCompleted());
|
BigDecimal rt = num.divide(days, 1, RoundingMode.HALF_UP);
|
comActWorkScreenVO.setEveryDayNum(rt.toString());
|
return R.ok(comActWorkScreenVO);
|
}
|
|
private String convertTimeStr(int minute) {
|
int hour = minute / 60;
|
int min = minute % 60;
|
StringBuilder timestr = new StringBuilder();
|
if (hour > 0) {
|
timestr.append(hour).append("h");
|
}
|
if (min > 0) {
|
timestr.append(min).append("min");
|
}
|
return timestr.toString();
|
}
|
|
@Override
|
public R dynamicWork(Long communityId) {
|
ComDynamicWorkScreenVO workScreenVO = new ComDynamicWorkScreenVO();
|
String date = DateUtils.getDateFormatString(new Date(), moth_format_str);
|
Map<String, Long> countMap = comActDynDAO.countByCommunityId(communityId, date);
|
if (!countMap.isEmpty()) {
|
workScreenVO
|
.setTotalNum(countMap.get("dynTotal") == null ? 0L : Long.valueOf(countMap.get("dynTotal").toString()));
|
workScreenVO.setCurrentNum(
|
countMap.get("currentNum") == null ? 0L : Long.valueOf(countMap.get("currentNum").toString()));
|
}
|
|
// 计算平均每天动态
|
DateScreenVO countAvg = comActDynDAO.countByAvgCommunityId(communityId);
|
if (countAvg != null) {
|
int day = DateUtils.differentDays(countAvg.getStartTime(), countAvg.getEndTime());
|
if (day > 0) {
|
workScreenVO.setCurrentAvgNum(workScreenVO.getTotalNum().intValue() / day);
|
}
|
}
|
|
// 查询最新的10条社区动态
|
List<String> dynList = new ArrayList<>();
|
List<ComActDynDO> actDynDOList = comActDynDAO.selectList(new QueryWrapper<ComActDynDO>().lambda()
|
.eq(ComActDynDO::getCommunityId, communityId).orderByDesc(ComActDynDO::getCreateAt).last("limit 10"));
|
if (!actDynDOList.isEmpty()) {
|
actDynDOList.forEach(actDyn -> {
|
dynList.add(actDyn.getTitle());
|
});
|
}
|
workScreenVO.setDynList(dynList);
|
|
// 统计近半年数据
|
List<DynamicWorkVO> list = new ArrayList<>();
|
for (DynamicWorkVO dynamicWorkVO : listHalfYearByDyn()) {
|
DynamicWorkVO result =
|
comActDynDAO.countByTime(dynamicWorkVO.getStart(), dynamicWorkVO.getEnd(), communityId);
|
result.setMonth(dynamicWorkVO.getMonth());
|
list.add(result);
|
}
|
workScreenVO.setList(list);
|
|
return R.ok(workScreenVO);
|
}
|
|
@Override
|
public R autonomyDynamic(Long communityId) {
|
DynamicVO dynamicVO =comScreenDao.autonomyDynamic(communityId);
|
return R.ok(dynamicVO);
|
}
|
|
@Override
|
public R property(Long communityId) {
|
return R.ok(comScreenDao.propertyData(communityId));
|
}
|
|
@Override
|
public R partyData(Long communityId) {
|
return R.ok(comScreenDao.partyData(communityId));
|
}
|
|
@Override
|
public R yard(Long communityId) {
|
return R.ok(comScreenDao.yard(communityId));
|
}
|
|
@Override
|
public R citizenInfo(Long communityId) {
|
DateVO vo=new DateVO();
|
vo.setCommunityId(communityId);
|
//当前日期
|
vo.setNow(DateUtil.now());
|
//16年前
|
vo.setOffset16(DateUtil.offsetMonth(DateUtil.date(), -192).toDateStr());
|
//27年前
|
vo.setOffset27(DateUtil.offsetMonth(DateUtil.date(), -324).toDateStr());
|
//35年前
|
vo.setOffset35(DateUtil.offsetMonth(DateUtil.date(), -420).toDateStr());
|
//45年前
|
vo.setOffset45(DateUtil.offsetMonth(DateUtil.date(), -540).toDateStr());
|
//55年前
|
vo.setOffset55(DateUtil.offsetMonth(DateUtil.date(), -660).toDateStr());
|
CitizenInfoVO citizenInfoVO = comScreenDao.ageRange(vo);
|
citizenInfoVO.setTotal(comScreenDao.buildingListHeaderStatisticsAdmin(communityId).getPopulationNum());
|
citizenInfoVO.setMaleRate(NumberUtil.div(citizenInfoVO.getMaleNum(), citizenInfoVO.getTotal(), 2));
|
citizenInfoVO.setFemaleRate(NumberUtil.div(citizenInfoVO.getFemaleNum(), citizenInfoVO.getTotal(), 2));
|
//男性占比
|
return R.ok(citizenInfoVO);
|
}
|
|
@Override
|
public R specialPeople(Long communityId) {
|
SpecialPeopleVO vo=new SpecialPeopleVO();
|
vo.setTotal(0);
|
List<SpecialPeopleVO> specialPeopleVOS = comScreenDao.specialPeople(communityId);
|
//求和
|
for (SpecialPeopleVO specialPeopleVO : specialPeopleVOS) {
|
vo.setTotal(vo.getTotal()+specialPeopleVO.getCount());
|
}
|
//计算占比
|
for (SpecialPeopleVO specialPeopleVO : specialPeopleVOS) {
|
specialPeopleVO.setRate(NumberUtil.div(specialPeopleVO.getCount(),vo.getTotal() ,2 ));
|
}
|
vo.setChildList(specialPeopleVOS);
|
return R.ok(vo);
|
}
|
|
@Override
|
public R basicData(Long communityId) {
|
BuildingListHeaderStatisticsAdminVo buildingListHeaderStatisticsAdminVo=comScreenDao.buildingListHeaderStatisticsAdmin(communityId);
|
BasicDataVO vo=new BasicDataVO();
|
vo.setVillage(buildingListHeaderStatisticsAdminVo.getBuildNum());
|
vo.setPeople(buildingListHeaderStatisticsAdminVo.getPopulationNum());
|
vo.setBuildings(buildingListHeaderStatisticsAdminVo.getHouseNum());
|
// vo.setBuildings(comScreenDao.assetAnalysis(communityId));
|
return R.ok(vo);
|
}
|
|
private List<DynamicWorkVO> listHalfYearByDyn() {
|
List<DynamicWorkVO> dateList = new ArrayList<>();
|
Date now = new Date();
|
for (int i = 5; i >= 0; i--) {
|
Date date = DateUtils.getDateM(now, -i);
|
DateTime endDay = DateUtil.endOfMonth(date);
|
|
int m = DateUtil.month(endDay);
|
m++;
|
int day = DateUtil.dayOfMonth(endDay);
|
int half = day / 2;
|
String month = DateUtil.format(date, moth_format_str);
|
DynamicWorkVO dynamicWorkVO = new DynamicWorkVO();
|
dynamicWorkVO.setMonth(monthStr[m-1] + "月上旬");
|
dynamicWorkVO.setStart(month + "-01 00:00:00");
|
dynamicWorkVO.setEnd(month + "-" + half + " 23:59:58");
|
dateList.add(dynamicWorkVO);
|
DynamicWorkVO dynamicWorkVO1 = new DynamicWorkVO();
|
dynamicWorkVO1.setMonth(monthStr[m-1] + "月下旬");
|
dynamicWorkVO1.setStart(month + "-" + half + " 23:59:58");
|
dynamicWorkVO1.setEnd(DateUtils.getDateFormatString(endDay, "yyyy-MM-dd HH:mm:ss"));
|
dateList.add(dynamicWorkVO1);
|
}
|
return dateList;
|
}
|
|
|
}
|