项目二07

1.游记表

2.后端

回显用户名

@Override
    public IPage<Travel> queryPage(TravelQuery qo) {
        QueryWrapper<Travel> wrapper = new QueryWrapper<>();

        IPage<Travel> page = new Page<>(qo.getCurrentPage(),qo.getPageSize());

        page(page,wrapper);

        List<Travel> records = page.getRecords();
        for (Travel record : records) {
            UserInfo userInfo = userInfoService.getById(record.getAuthorId());
            record.setAuthor(userInfo);
        }

        return page;
    }


查看文章

    @RequestMapping("/getContentById")
    @ResponseBody
    public Object getContentById(Long id){
        TravelContent content = travelService.getContent(id);
        return JsonResult.success(content.getContent());
    }

    //-------这是分割线-----------
    @Override
    public TravelContent getContent(Long id) {
        return travelContentMapper.selectById(id);
    }


审核文章

    @RequestMapping("/audit")
    @ResponseBody
    public Object audit(Long id,Integer state){
        travelService.updateTravel(id,state);
        return JsonResult.success();
    }

    //-----------这是分割线-----------
    @Override
    public void updateTravel(Long id, Integer state) {
        Travel travel = getById(id);
        if(travel == null || state ==Travel.STATE_WAITING){
            throw new LogicException("参数异常");
        }
        //修改状态
        //设置发布时间
        //设置更新时间
        //记录信息
        if(state == Travel.STATE_RELEASE){
            travel.setState(Travel.STATE_RELEASE);
            travel.setReleaseTime(new Date());
            travel.setLastUpdateTime(new Date());

        }else if(state ==Travel.STATE_REJECT){
            travel.setState(Travel.STATE_REJECT);
            travel.setReleaseTime(null);
            travel.setLastUpdateTime(new Date());

        }else{
            throw new LogicException("漏网之鱼");
        }
        updateById(travel);
    }

3.前端

3.1.目的地下的游记分页

@Override
    public IPage<Travel> queryPage(TravelQuery qo) {
        QueryWrapper<Travel> wrapper = new QueryWrapper<>();

        IPage<Travel> page = new Page<>(qo.getCurrentPage(),qo.getPageSize());
        wrapper.eq(qo.getDestId()!=null,"dest_id",qo.getDestId());

        //wrapper.orderByDesc(qo.getOrderBy()!=null,"order_by",qo.getOrderBy());
       

        page(page,wrapper);

        List<Travel> records = page.getRecords();
        for (Travel record : records) {
            UserInfo userInfo = userInfoService.getById(record.getAuthorId());
            record.setAuthor(userInfo);
        }

        return page;
    }

3.2.目的地下的游记过滤

//-----------------封装查询的实体类
@Setter
@Getter
public class TravelQuery extends  QueryObject {
    private Long destId;
    private String orderBy;

    private int travelTimeType=-1;
    private int consumeType=-1;
    private int dayType=-1;
}

//---------------存储的数据结构--------------
@Setter
@Getter
public class TravelCondition {

    // 出行时间
    public static final Map<Integer, TravelCondition> TIMEMAP = new HashMap<>();

    // 旅游天数
    public static final Map<Integer, TravelCondition> DAYMAP = new HashMap<>();

    // 旅游人均
    public static final Map<Integer, TravelCondition> CONSUMEMAP = new HashMap<>();

    static {
        DAYMAP.put(1, new TravelCondition(0, 3));
        DAYMAP.put(2, new TravelCondition(4, 7));
        DAYMAP.put(3, new TravelCondition(8, 14));
        DAYMAP.put(4, new TravelCondition(15, Integer.MAX_VALUE));

        TIMEMAP.put(1, new TravelCondition(1, 2));
        TIMEMAP.put(2, new TravelCondition(3, 4));
        TIMEMAP.put(3, new TravelCondition(5, 6));
        TIMEMAP.put(4, new TravelCondition(7, 8));
        TIMEMAP.put(5, new TravelCondition(9, 10));
        TIMEMAP.put(6, new TravelCondition(11, 12));

        CONSUMEMAP.put(1, new TravelCondition(0, 999));
        CONSUMEMAP.put(2, new TravelCondition(1000, 6000));
        CONSUMEMAP.put(3, new TravelCondition(6001, 20000));
        CONSUMEMAP.put(4, new TravelCondition(20001, Integer.MAX_VALUE));
    }

    private int min;
    private int max;

    public TravelCondition(int min, int max) {
        this.min = min;
        this.max = max;
    }
}

//-------------这是分割线-----------
        wrapper.orderByDesc(StringUtils.hasText(qo.getOrderBy()),qo.getOrderBy());

        Map<Integer, HashMap<Integer,Integer>> map = new HashMap<>();

        TravelCondition day = TravelCondition.DAYMAP.get(qo.getDayType());
        if(day != null){
            wrapper.ge("day",day.getMin()).le("day",day.getMax());
        }

        TravelCondition consume = TravelCondition.CONSUMEMAP.get(qo.getConsumeType());
        if(consume != null){
            wrapper.ge("avg_consume",consume.getMin()).le("avg_consume",consume.getMax());
        }

        TravelCondition time = TravelCondition.TIMEMAP.get(qo.getTravelTimeType());
        if(time != null){
            wrapper.ge("month(travel_time)",time.getMin()).le("month(travel_time)",time.getMax());
        }

3.3.游记明细

前端请求

        //吐司
        ajaxGet("/destinations/toasts", {destId: param.destId}, function (data) {
            vue.dest = data.data.pop();
            vue.toasts = data.data
        })

        //点击量前3的攻略文章
        ajaxGet("/destinations/strategies/viewnumTop3", {destId: param.destId}, function (data) {
            vue.strategies = data.data;
        })

        //游记
        ajaxGet("/travels/detail", {id: param.id}, function (data) {
            _this.detail = data.data;
            _this.content = data.data.content
        })


        //游记点击量前3
        ajaxGet("/destinations/travels/viewnumTop3", {destId: param.destId}, function (data) {
            _this.travels = data.data;
        })

前端接口

    //------------游记文章----------
    @GetMapping("travels/viewnumTop3")
    @ResponseBody
    public Object viewnumTop3xx(Long destId){
        return JsonResult.success(travelService.queryViewTop3(destId));
    }

    @Override
    public List<Travel> queryViewTop3(Long destId) {
        QueryWrapper<Travel> wrapper = new QueryWrapper<>();
        wrapper.eq("dest_id",destId);
        wrapper.orderByDesc("viewnum");
        wrapper.last("limit 3");
        return list(wrapper);
    }

    //-----------明细游记------------
    @GetMapping("/detail")
    public Object detail(Long id){
        Travel travel = travelService.getById(id);

        //这里会报空指针的
        TravelContent content = travelService.getContent(id);

        travel.setAuthor(userInfoService.getById(travel.getAuthorId()));

        travel.setContent(content);
        return JsonResult.success(travel);
    }


返回课程体系

posted @ 2021-07-10 18:54  LinkYup  阅读(36)  评论(0编辑  收藏  举报