huanghongfa
2021-08-30 15fa9d64f49b8d1ae7d75a535ed45bb359e26024
springcloud_k8s_panzhihuazhihuishequ/service_community/src/main/java/com/panzhihua/service_community/service/impl/ComActReserveServiceImpl.java
@@ -26,6 +26,7 @@
import com.panzhihua.service_community.dao.*;
import com.panzhihua.service_community.model.dos.*;
import com.panzhihua.service_community.service.ComActReserveAnswerContentService;
import com.panzhihua.service_community.service.ComActReserveRecordService;
import com.panzhihua.service_community.service.ComActReserveService;
import com.panzhihua.service_community.service.ComActReserveSubSelectionService;
import lombok.extern.slf4j.Slf4j;
@@ -68,6 +69,8 @@
    private ComActReserveOperationRecordMapper comActReserveOperationRecordMapper;
    @Resource
    private ComActReserveSubSelectionService comActReserveSubSelectionService;
    @Resource
    private ComActReserveRecordService comActReserveRecordService;
    private final static String COMMIT="用户已提交";
    @Override
@@ -80,8 +83,16 @@
            ComActReserveDO comActReserveDO=comActReserveMapper.selectById(comActReserveCommitVO.getId());
            if(comActReserveDO!=null){
                //查询当前用户是否已预约并判断是否能继续预约
                if(comActReserveDO.getJoinAllCount()!=0){
                    Integer count=comActReserveRecordMapper.selectCount(new QueryWrapper<ComActReserveRecordDO>().eq("reserve_id",comActReserveCommitVO.getId()));
                    if(count>=comActReserveDO.getJoinAllCount()){
                        return R.fail("预约已上限");
                    }
                }
                List<ComActReserveRecordDO> list=comActReserveRecordMapper.selectList(new QueryWrapper<ComActReserveRecordDO>().eq("reserve_id",comActReserveCommitVO.getId()).eq("user_id",comActReserveCommitVO.getUserId()).in("status",1,2,3));
                if(!list.isEmpty()&&comActReserveDO.getIsRepeat()==ComActReserveDO.isRepeat.no){
                if(!list.isEmpty()&&list.size()>1&&comActReserveDO.getIsRepeat()==ComActReserveDO.isRepeat.no){
                    return R.fail("提交失败,不可重复预约");
                }
                else {
@@ -144,7 +155,7 @@
                                    answerContentDO.setAnswerContent(subSelectionDO.getContent());
                                    answerContentList.add(answerContentDO);
                                }
                            }else if(questnaiteSub.getType().equals(QuestnaiteSubVO.type.wenda)){
                            }else{
                                //问答题处理
                                String values = questnaiteSub.getValues();
                                ComActReserveAnswerContentDO answerContentDO = new ComActReserveAnswerContentDO();
@@ -158,17 +169,16 @@
                            }
                        }
                        if(!answerContentList.isEmpty()){
                            comActReserveAnswerContentService.saveBatch(answerContentList);
                            //更新回答用户数量
                            Integer joinCount = comActReserveDO.getJoinCount();
                            comActReserveDO.setJoinCount(joinCount != null ? joinCount + 1 : 1);
                            comActReserveMapper.updateById(comActReserveDO);
                            //新增用户答题记录
                            ComActReserveRecordDO userAnswerDO = new ComActReserveRecordDO();
                            userAnswerDO.setCommunityId(comActReserveCommitVO.getCommunityId());
                            userAnswerDO.setPhone(comActReserveCommitVO.getPhone());
                            userAnswerDO.setReserveId(questId);
                            userAnswerDO.setReserveTime(comActReserveCommitVO.getReserveTime());
                            userAnswerDO.setUserId(userId);
                            userAnswerDO.setType(comActReserveCommitVO.getType());
                            userAnswerDO.setCreateAt(nowDate);
@@ -179,18 +189,26 @@
                            else {
                                userAnswerDO.setStatus(ComActReserveRecordDO.status.cg);
                            }
                            comActReserveRecordMapper.insert(userAnswerDO);
                            comActReserveRecordService.saveOrUpdate(userAnswerDO);
                            //给答题记录赋值预约登记记录id
                            answerContentList.forEach(answerContent -> {
                                answerContent.setReserveRecordId(userAnswerDO.getId());
                            });
                            comActReserveAnswerContentService.saveBatch(answerContentList);
                            //新增用户操作记录
                            ComActReserveOperationRecordDO comActReserveOperationRecordDO=new ComActReserveOperationRecordDO();
                            comActReserveOperationRecordDO.setReserveId(comActReserveCommitVO.getId());
                            comActReserveOperationRecordDO.setReserveRecordId(userAnswerDO.getId());
                            comActReserveOperationRecordDO.setType(ComActReserveOperationRecordDO.type.br);
                            comActReserveOperationRecordDO.setReserveTime(DateUtil.date());
                            comActReserveOperationRecordDO.setCreateAt(DateUtil.date());
                            comActReserveOperationRecordDO.setReserveTime(comActReserveCommitVO.getReserveTime());
                            comActReserveOperationRecordDO.setReserveContent(COMMIT);
                            comActReserveOperationRecordDO.setPhone(comActReserveCommitVO.getPhone());
                            comActReserveOperationRecordDO.setStatus(ComActReserveOperationRecordDO.status.ytj);
                            comActReserveOperationRecordDO.setUserId(comActReserveCommitVO.getUserId());
                            comActReserveOperationRecordMapper.insert(comActReserveOperationRecordDO);
                        return R.ok("提交成功");
                        }
                    }
                }
@@ -539,6 +557,48 @@
    }
    @Override
    public R getById(Long id,Long userId,Long recordId,Integer isBack) {
        ComActReserveDO comActReserveDO=comActReserveMapper.selectById(id);
        if(comActReserveDO!=null){
            ComActReserveDetailVO comActReserveDetailVO=new ComActReserveDetailVO();
            if(isBack!=1){
                comActReserveDO.setViewNum(comActReserveDO.getViewNum()+1);
                BeanUtils.copyProperties(comActReserveDO,comActReserveDetailVO);
                List<ComActReserveRecordDO> list=comActReserveRecordMapper.selectList(new QueryWrapper<ComActReserveRecordDO>().eq("user_id",userId).eq("reserve_id",id).in("status",1,2).orderByDesc("reserve_time"));
                List<ComActReserveRecordDO> secondlist=comActReserveRecordMapper.selectList(new QueryWrapper<ComActReserveRecordDO>().eq("user_id",userId).eq("reserve_id",id).orderByDesc("reserve_time"));
                //判断当前数据是否可重复提交
                if(comActReserveDO.getIsRepeat()==ComActReserveDetailVO.isOk.y||list.isEmpty()){
                    comActReserveDetailVO.setIsOk(ComActReserveDetailVO.isOk.n);
                }else {
                    comActReserveDetailVO.setIsOk(ComActReserveDetailVO.isOk.y);
                }
                //如果用户已提交返回最新一条记录 列表时间倒序排列
                if(!list.isEmpty()){
                    comActReserveDetailVO.setJsonObject(list.get(0).getJsonObject());
                    comActReserveDetailVO.setReserveTime(list.get(0).getReserveTime());
                }
                if(!secondlist.isEmpty()&&recordId!=null){
                    secondlist.forEach(comActReserveRecordDO -> {
                        if(comActReserveRecordDO.getId().equals(recordId)){
                            comActReserveDetailVO.setRecordStatus(comActReserveRecordDO.getStatus());
                        }
                    });
                }
                //更新浏览量
                comActReserveMapper.updateById(comActReserveDO);
                return R.ok(comActReserveDetailVO);
            }
            ComActReserveRecordDO comActReserveRecordDO =comActReserveRecordMapper.selectById(recordId);
            if(comActReserveRecordDO!=null){
                BeanUtils.copyProperties(comActReserveRecordDO,comActReserveDetailVO);
            }
            return R.ok(comActReserveDetailVO);
        }
        return R.fail("未查询到数据");
    }
    @Override
    public R pageReserveList(PageUserReserveDTO pageUserReserveDTO) {
        return R.ok(comActReserveRecordMapper.pageReserveList(new Page<ComActReserveDO>(pageUserReserveDTO.getPageNum(), pageUserReserveDTO.getPageSize()),pageUserReserveDTO));
    }