luo
2023-12-25 23c4967b4cb8dbce8277f830f7152d315c5a4a57
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
package com.stylefeng.guns.modular.code.controller;
 
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.stylefeng.guns.core.shiro.ShiroKit;
import com.stylefeng.guns.modular.system.dto.BannerVo;
import com.stylefeng.guns.modular.system.dto.THouseResource;
import com.stylefeng.guns.modular.system.model.Banner;
import com.stylefeng.guns.modular.system.model.HouseType;
import com.stylefeng.guns.modular.system.service.IBannerService;
import com.stylefeng.guns.modular.system.util.ResultUtil;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
 
import javax.print.attribute.IntegerSyntax;
import java.util.Date;
import java.util.List;
import java.util.Objects;
 
@Controller
@RequestMapping("/base/banner")
public class SysBannerController {
 
    @Autowired
    private IBannerService bannerService;
    @ResponseBody
    @GetMapping("/list")
    @ApiOperation(value = "列表", tags = {"后台-轮播图管理"},response = BannerVo.class)
    public Object list(int pageNum,int pageSize,Integer position,Integer sort){
        PageHelper.startPage(pageNum,pageSize);
        List<BannerVo>  list =  bannerService.list(position,sort);
        PageInfo<BannerVo> info=new PageInfo<>(list);
        System.err.println(info);
        return  info;
    }
 
    @ResponseBody
    @PostMapping ("/add")
    @ApiOperation(value = "添加", tags = {"后台-轮播图管理"})
    public ResultUtil add(@RequestBody BannerVo bannerVo){
        List<Banner> position = bannerService.selectList(new EntityWrapper<Banner>().eq("position", bannerVo.getPosition()));
        if (!position.isEmpty()){
            return ResultUtil.error("当前模块已经上传");
        }
        Banner banner = new Banner();
        BeanUtils.copyProperties(bannerVo,banner);
        banner.setInsertUserId(Objects.requireNonNull(ShiroKit.getUser()).id);
        banner.setInsertTime(new Date());
        bannerService.insertOrUpdate(banner);
        return  ResultUtil.success("操作成功");
    }
 
 
    @ResponseBody
    @DeleteMapping("/delete")
    @ApiOperation(value = "批量删除", tags = {"后台-轮播图管理"})
    public ResultUtil add(String ids){
        String[] split = ids.split(",");
        for (String s : split) {
            bannerService.deleteById(Integer.valueOf(s));
        }
 
        return  ResultUtil.success("删除成功");
    }
}