| | |
| | | package com.panzhihua.service_community.service.impl; |
| | | |
| | | import com.alibaba.fastjson.JSON; |
| | | import com.baomidou.mybatisplus.core.metadata.IPage; |
| | | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | | import com.google.common.collect.Lists; |
| | | import com.panzhihua.common.model.dtos.community.reserve.*; |
| | | import com.panzhihua.common.model.vos.R; |
| | | import com.panzhihua.common.model.vos.community.questnaire.QuestnaiteSubSelectionVO; |
| | | import com.panzhihua.common.model.vos.community.questnaire.QuestnaiteSubVO; |
| | | import com.panzhihua.common.model.vos.community.reserve.*; |
| | | import com.panzhihua.common.utlis.StringUtils; |
| | | import com.panzhihua.service_community.dao.ComActReserveMapper; |
| | | import com.panzhihua.service_community.model.dos.ComActReserveDO; |
| | | import com.panzhihua.service_community.dao.ComActReserveSubMapper; |
| | | import com.panzhihua.service_community.model.dos.*; |
| | | import com.panzhihua.service_community.service.ComActReserveService; |
| | | import com.panzhihua.service_community.service.ComActReserveSubSelectionService; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.springframework.beans.BeanUtils; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | |
| | | import javax.annotation.Resource; |
| | | import java.math.BigDecimal; |
| | | import java.math.RoundingMode; |
| | | import java.util.ArrayList; |
| | | import java.util.Date; |
| | | import java.util.List; |
| | | |
| | | /** |
| | | * @auther lyq |
| | |
| | | @Service |
| | | public class ComActReserveServiceImpl extends ServiceImpl<ComActReserveMapper, ComActReserveDO> implements ComActReserveService { |
| | | |
| | | @Resource |
| | | private ComActReserveSubMapper comActReserveSubMapper; |
| | | @Resource |
| | | private ComActReserveSubSelectionService comActReserveSubSelectionService; |
| | | |
| | | /** |
| | | * 社区后台-分页查询预约登记列表 |
| | | * @param pageReserveDTO 请求参数 |
| | | * @return 预约登记列表 |
| | | */ |
| | | @Override |
| | | public R pageReserveAdmin(PageReserveAdminDTO pageReserveDTO){ |
| | | IPage<ComActReserveListAdminVO> reservePage = this.baseMapper.pageReserveAdmin(new Page(pageReserveDTO.getPageNum(),pageReserveDTO.getPageSize()),pageReserveDTO); |
| | | reservePage.getRecords().forEach(reserve -> { |
| | | //判断广告位置 |
| | | StringBuilder sb = new StringBuilder(); |
| | | if(reserve.getAdverPositionTop().equals(ComActQuestnaireDO.isOk.yes)){ |
| | | sb.append("首页顶部,"); |
| | | } |
| | | if(reserve.getAdverPositionApplication().equals(ComActQuestnaireDO.isOk.yes)){ |
| | | sb.append("首页应用,"); |
| | | } |
| | | String advertPosition = sb.toString(); |
| | | if(advertPosition.length() > 0){ |
| | | reserve.setAdvertPosition(advertPosition.substring(0,advertPosition.length()-1)); |
| | | }else{ |
| | | reserve.setAdvertPosition("无"); |
| | | } |
| | | }); |
| | | return R.ok(reservePage); |
| | | } |
| | | |
| | | /** |
| | | * 社区后台-新增预约登记信息 |
| | | * @param addReserveDTO 请求参数 |
| | | * @return 新增结果 |
| | | */ |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public R addReserveAdmin(AddReserveAdminDTO addReserveDTO){ |
| | | Date nowDate = new Date(); |
| | | Long userId = addReserveDTO.getUserId(); |
| | | //新增预约登记信息 |
| | | ComActReserveDO reserveDO = new ComActReserveDO(); |
| | | BeanUtils.copyProperties(addReserveDTO,reserveDO); |
| | | reserveDO.setStatus(ComActReserveDO.status.dfb); |
| | | reserveDO.setCreateAt(nowDate); |
| | | reserveDO.setCreateBy(userId); |
| | | |
| | | if(addReserveDTO.getIsPublish().equals(ComActReserveDO.isOk.yes)){ |
| | | reserveDO.setStatus(ComActReserveDO.status.jxz); |
| | | reserveDO.setPublishTime(nowDate); |
| | | } |
| | | this.baseMapper.insert(reserveDO); |
| | | |
| | | //根据上传的json数据录入选项以及题目到数据库 |
| | | if(StringUtils.isEmpty(addReserveDTO.getJsonObject())){ |
| | | return R.fail("组件json数据为空,录入失败"); |
| | | } |
| | | List<QuestnaiteSubVO> reserveSubVOS = JSON.parseArray(addReserveDTO.getJsonObject(),QuestnaiteSubVO.class); |
| | | reserveSubVOS.forEach(reserveSub -> { |
| | | ComActReserveSubDO comActReserveSubDO = new ComActReserveSubDO(); |
| | | comActReserveSubDO.setType(reserveSub.getType()); |
| | | comActReserveSubDO.setContent(reserveSub.getLabel()); |
| | | comActReserveSubDO.setSort(reserveSub.getSort()); |
| | | comActReserveSubDO.setReserveId(reserveDO.getId()); |
| | | comActReserveSubDO.setCreateBy(userId); |
| | | comActReserveSubDO.setCreateAt(nowDate); |
| | | comActReserveSubDO.setKey(reserveSub.getKey()); |
| | | comActReserveSubMapper.insert(comActReserveSubDO); |
| | | |
| | | ArrayList<ComActReserveSubSelectionDO> subSelectionList = Lists.newArrayList(); |
| | | if(reserveSub.getOptions() != null && !reserveSub.getOptions().isEmpty()) { |
| | | List<QuestnaiteSubSelectionVO> subOptions = reserveSub.getOptions(); |
| | | for(int i=0; i<subOptions.size(); i++){ |
| | | QuestnaiteSubSelectionVO subSelect = subOptions.get(i); |
| | | ComActReserveSubSelectionDO subSelectionDO = new ComActReserveSubSelectionDO(); |
| | | subSelectionDO.setReserveSubId(comActReserveSubDO.getId()); |
| | | if(subSelect.getType().equals(1)){ |
| | | //添加选项名称 |
| | | subSelectionDO.setOptionName(subSelect.getOptionName()); |
| | | }else { |
| | | subSelectionDO.setOptionName(String.valueOf(Character.toChars('A' + i))); |
| | | } |
| | | subSelectionDO.setContent(subSelect.getLabel()); |
| | | subSelectionDO.setReserveId(reserveDO.getId()); |
| | | subSelectionDO.setCreateBy(userId); |
| | | subSelectionDO.setCreateAt(nowDate); |
| | | subSelectionDO.setType(subSelect.getType()); |
| | | subSelectionDO.setKey(subSelect.getKey()); |
| | | subSelectionList.add(subSelectionDO); |
| | | } |
| | | } |
| | | comActReserveSubSelectionService.saveBatch(subSelectionList); |
| | | }); |
| | | |
| | | return R.ok(); |
| | | } |
| | | |
| | | /** |
| | | * 社区后台-编辑预约登记信息 |
| | | * @param editReserveDTO 请求参数 |
| | | * @return 新增结果 |
| | | */ |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public R editReserveAdmin(EditReserveAdminDTO editReserveDTO){ |
| | | Date nowDate = new Date(); |
| | | Long userId = editReserveDTO.getUserId(); |
| | | Long reserveId = editReserveDTO.getId(); |
| | | //查询预约登记信息 |
| | | ComActReserveDO reserveDO = this.baseMapper.selectById(reserveId); |
| | | if(reserveDO == null){ |
| | | return R.fail("未查询到预约登记记录"); |
| | | } |
| | | if(!reserveDO.getStatus().equals(ComActReserveDO.status.dfb)){ |
| | | return R.fail("不可修改不是待发布状态的预约登记记录"); |
| | | } |
| | | BeanUtils.copyProperties(editReserveDTO,reserveDO); |
| | | reserveDO.setStatus(ComActReserveDO.status.dfb); |
| | | reserveDO.setUpdateAt(nowDate); |
| | | reserveDO.setUpdateBy(userId); |
| | | if(editReserveDTO.getIsPublish().equals(ComActReserveDO.isOk.yes)){ |
| | | reserveDO.setStatus(ComActReserveDO.status.jxz); |
| | | reserveDO.setPublishTime(nowDate); |
| | | } |
| | | this.baseMapper.updateById(reserveDO); |
| | | |
| | | //根据上传的json数据录入选项以及题目到数据库 |
| | | if(StringUtils.isEmpty(editReserveDTO.getJsonObject())){ |
| | | return R.fail("组件json数据为空,录入失败"); |
| | | } |
| | | |
| | | //清除原来预约登记题目以及题目选项 |
| | | this.baseMapper.deleteReserveSubAll(reserveId); |
| | | //清除原有的,添加更新的 |
| | | List<QuestnaiteSubVO> reserveSubVOS = JSON.parseArray(editReserveDTO.getJsonObject(),QuestnaiteSubVO.class); |
| | | if(reserveSubVOS.isEmpty()){ |
| | | return R.fail("组件json数据为空,录入失败"); |
| | | } |
| | | reserveSubVOS.forEach(reserveSub -> { |
| | | ComActReserveSubDO comActReserveSubDO = new ComActReserveSubDO(); |
| | | comActReserveSubDO.setType(reserveSub.getType()); |
| | | comActReserveSubDO.setContent(reserveSub.getLabel()); |
| | | comActReserveSubDO.setSort(reserveSub.getSort()); |
| | | comActReserveSubDO.setReserveId(reserveDO.getId()); |
| | | comActReserveSubDO.setCreateBy(userId); |
| | | comActReserveSubDO.setCreateAt(nowDate); |
| | | comActReserveSubDO.setKey(reserveSub.getKey()); |
| | | comActReserveSubMapper.insert(comActReserveSubDO); |
| | | |
| | | ArrayList<ComActReserveSubSelectionDO> subSelectionList = Lists.newArrayList(); |
| | | if(reserveSub.getOptions() != null && !reserveSub.getOptions().isEmpty()) { |
| | | List<QuestnaiteSubSelectionVO> subOptions = reserveSub.getOptions(); |
| | | for(int i=0; i<subOptions.size(); i++){ |
| | | QuestnaiteSubSelectionVO subSelect = subOptions.get(i); |
| | | ComActReserveSubSelectionDO subSelectionDO = new ComActReserveSubSelectionDO(); |
| | | subSelectionDO.setReserveSubId(comActReserveSubDO.getId()); |
| | | if(subSelect.getType().equals(1)){ |
| | | //添加选项名称 |
| | | subSelectionDO.setOptionName(subSelect.getOptionName()); |
| | | }else { |
| | | subSelectionDO.setOptionName(String.valueOf(Character.toChars('A' + i))); |
| | | } |
| | | subSelectionDO.setContent(subSelect.getLabel()); |
| | | subSelectionDO.setReserveId(reserveDO.getId()); |
| | | subSelectionDO.setCreateBy(userId); |
| | | subSelectionDO.setCreateAt(nowDate); |
| | | subSelectionDO.setType(subSelect.getType()); |
| | | subSelectionDO.setKey(subSelect.getKey()); |
| | | subSelectionList.add(subSelectionDO); |
| | | } |
| | | } |
| | | comActReserveSubSelectionService.saveBatch(subSelectionList); |
| | | }); |
| | | return R.ok(); |
| | | } |
| | | |
| | | /** |
| | | * 社区后台-修改预约登记状态 |
| | | * @param editReserveDTO 请求参数 |
| | | * @return 修改结果 |
| | | */ |
| | | @Override |
| | | public R editReserveStatusAdmin(EditComActReserveStatusDTO editReserveDTO){ |
| | | Date nowDate = new Date(); |
| | | Long userId = editReserveDTO.getUserId(); |
| | | Long reserveId = editReserveDTO.getId(); |
| | | //查询预约登记信息 |
| | | ComActReserveDO reserveDO = this.baseMapper.selectById(reserveId); |
| | | if(reserveDO == null){ |
| | | return R.fail("未查询到预约登记记录"); |
| | | } |
| | | |
| | | if(editReserveDTO.getType().equals(EditComActReserveStatusDTO.type.tz)){ |
| | | reserveDO.setStatus(ComActReserveDO.status.ytz); |
| | | reserveDO.setEndTime(nowDate); |
| | | }else if(editReserveDTO.getType().equals(EditComActReserveStatusDTO.type.fb)){ |
| | | reserveDO.setStatus(ComActReserveDO.status.jxz); |
| | | reserveDO.setPublishTime(nowDate); |
| | | } |
| | | reserveDO.setUpdateBy(userId); |
| | | reserveDO.setUpdateAt(nowDate); |
| | | if(this.baseMapper.updateById(reserveDO) > 0){ |
| | | return R.ok(); |
| | | }else{ |
| | | return R.fail(); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 社区后台-继续预约登记 |
| | | * @param editReserveDTO 请求参数 |
| | | * @return 修改结果 |
| | | */ |
| | | @Override |
| | | public R editReserveInfoAdmin(EditComActReserveInfoDTO editReserveDTO){ |
| | | Date nowDate = new Date(); |
| | | Long userId = editReserveDTO.getUserId(); |
| | | Long reserveId = editReserveDTO.getId(); |
| | | //查询预约登记信息 |
| | | ComActReserveDO reserveDO = this.baseMapper.selectById(reserveId); |
| | | if(reserveDO == null){ |
| | | return R.fail("未查询到预约登记记录"); |
| | | } |
| | | BeanUtils.copyProperties(editReserveDTO,reserveDO); |
| | | reserveDO.setStatus(ComActReserveDO.status.jxz); |
| | | reserveDO.setUpdateAt(nowDate); |
| | | reserveDO.setUpdateBy(userId); |
| | | reserveDO.setEndTime(null); |
| | | if(this.baseMapper.updateById(reserveDO) > 0){ |
| | | return R.ok(); |
| | | }else{ |
| | | return R.fail(); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 社区后台-根据预约登记id查询详情 |
| | | * @param reserveId 预约登记id |
| | | * @return 预约登记详情 |
| | | */ |
| | | @Override |
| | | public R detailReserveAdmin(Long reserveId){ |
| | | ComActReserveDetailAdminVO reserveDetailAdminVO = new ComActReserveDetailAdminVO(); |
| | | //查询预约登记信息 |
| | | ComActReserveDO reserveDO = this.baseMapper.selectById(reserveId); |
| | | BeanUtils.copyProperties(reserveDO,reserveDetailAdminVO); |
| | | return R.ok(reserveDetailAdminVO); |
| | | } |
| | | |
| | | /** |
| | | * 社区后台-根据社区id统计预约类数据 |
| | | * @param makeStatisticsDTO 请求参数 |
| | | * @return 统计预约类数据 |
| | | */ |
| | | @Override |
| | | public R makeStatisticsAdmin(ComActReserveMakeStatisticsDTO makeStatisticsDTO){ |
| | | Long communityId = makeStatisticsDTO.getCommunityId(); |
| | | ComActReserveMakeStatisticsAdminVO makeStatisticsAdminVO = new ComActReserveMakeStatisticsAdminVO(); |
| | | //查询预约登记统计汇总左边数据 |
| | | List<ComActReserveMakeLeftStatisticsAdminVO> leftStatisticsList = this.baseMapper.getReserveMakeLeftStatistics(communityId); |
| | | if(!leftStatisticsList.isEmpty()){ |
| | | makeStatisticsAdminVO.setLeftStatisticsList(leftStatisticsList); |
| | | } |
| | | |
| | | //查询预约登记统计汇总右边数据 |
| | | List<ComActReserveMakeRightStatisticsAdminVO> rightStatisticsList = getRightStatisticsList(makeStatisticsDTO); |
| | | if(!rightStatisticsList.isEmpty()){ |
| | | makeStatisticsAdminVO.setRightStatisticsList(rightStatisticsList); |
| | | } |
| | | return R.ok(makeStatisticsAdminVO); |
| | | } |
| | | |
| | | /** |
| | | * 社区后台-查询预约统计汇总右边数据 |
| | | * @param makeStatisticsDTO 请求参数 |
| | | * @return 预约统计汇总右边数据 |
| | | */ |
| | | private List<ComActReserveMakeRightStatisticsAdminVO> getRightStatisticsList(ComActReserveMakeStatisticsDTO makeStatisticsDTO){ |
| | | Long communityId = makeStatisticsDTO.getCommunityId(); |
| | | //查询预约登记统计汇总右边数据 |
| | | List<ComActReserveMakeRightStatisticsAdminVO> rightStatisticsList = this.baseMapper.getReserveMakeRightStatistics(makeStatisticsDTO); |
| | | if(!rightStatisticsList.isEmpty()){ |
| | | rightStatisticsList.forEach(rightStatistics -> { |
| | | String date = rightStatistics.getReserveTime(); |
| | | Integer count = this.baseMapper.getReserveRecordCount(communityId,date + " 00:00:00",date + " 23:59:59"); |
| | | rightStatistics.setAllCount(count); |
| | | |
| | | //计算百分比 |
| | | BigDecimal tag = BigDecimal.ZERO; |
| | | if(count >= 0){ |
| | | tag = BigDecimal.valueOf(rightStatistics.getCount()).divide(BigDecimal.valueOf(count),2, RoundingMode.HALF_UP).multiply(BigDecimal.valueOf(100)); |
| | | } |
| | | rightStatistics.setTag(tag); |
| | | }); |
| | | } |
| | | return rightStatisticsList; |
| | | } |
| | | |
| | | /** |
| | | * 社区后台-查询导出预约统计汇总数据 |
| | | * @param makeStatisticsDTO 请求参数 |
| | | * @return 统计预约类数据 |
| | | */ |
| | | @Override |
| | | public R makeStatisticsExportAdmin(ComActReserveMakeStatisticsDTO makeStatisticsDTO){ |
| | | return R.ok(getRightStatisticsList(makeStatisticsDTO)); |
| | | } |
| | | |
| | | /** |
| | | * 删除预约登记信息 |
| | | * @param reserveId 预约登记id |
| | | * @return 删除结果 |
| | | */ |
| | | @Override |
| | | public R deleteReserveAdmin(Long reserveId){ |
| | | //查询预约登记信息 |
| | | ComActReserveDO reserveDO = this.baseMapper.selectById(reserveId); |
| | | if(reserveDO == null){ |
| | | return R.fail("未查询到预约登记信息"); |
| | | } |
| | | reserveDO.setIsDel(ComActReserveDO.isOk.yes); |
| | | reserveDO.setUpdateAt(new Date()); |
| | | |
| | | if(this.baseMapper.updateById(reserveDO) > 0){ |
| | | return R.ok(); |
| | | }else{ |
| | | return R.fail(); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 查询社区所有预约信息列表 |
| | | * @param communityId 社区id |
| | | * @return 预约信息列表 |
| | | */ |
| | | @Override |
| | | public R listReserveAdmin(Long communityId){ |
| | | return R.ok(this.baseMapper.listReserveAdmin(communityId)); |
| | | } |
| | | |
| | | } |