44323
2023-09-23 753145b81710f934c28b29a1feb376ce79d4a965
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
package com.dsh.guns.modular.system.controller.code;
 
import com.dsh.course.feignClient.account.CityManagerClient;
import com.dsh.course.feignClient.account.model.CityManager;
import com.dsh.course.feignClient.account.model.Coach;
import com.dsh.course.feignClient.account.model.CoachSerchVO;
import com.dsh.course.feignClient.other.BannerClient;
import com.dsh.course.feignClient.other.model.Banner;
import com.dsh.guns.config.UserExt;
import com.dsh.guns.core.base.controller.BaseController;
import com.dsh.guns.modular.system.model.*;
import com.dsh.guns.modular.system.service.ICityService;
import com.dsh.guns.modular.system.service.IStoreService;
import com.dsh.guns.modular.system.util.ResultUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
 
import java.util.*;
 
/**
 * 广告管理控制器
 *
 */
@Controller
@RequestMapping("/advertisement")
public class AdvertisementController extends BaseController {
    private String PREFIX = "/system/advertisement/";
    @Autowired
    private ICityService cityService;
    @Autowired
    private CityManagerClient cityManagerClient;
    @Autowired
    private BannerClient bannerClient;
    @Autowired
    private IStoreService storeService;
    /**
     * 跳转到广告页面
     */
    @RequestMapping("")
    public String index(Model model) {
 
        List<TTurn> pages = storeService.pageList();
        List<Integer> ids = new ArrayList<>();
        for (TTurn page : pages) {
            ids.add(page.getId());
        }
        List<TTurn> res = storeService.getPage(ids);
        model.addAttribute("pages",res);
        model.addAttribute("models",1);
        return PREFIX + "advertisement.html";
    }
    /**
     * 跳转到广告添加页面
     */
    @RequestMapping("/add")
    public String operator(Model model) {
        Integer roleType = UserExt.getUser().getObjectType();
        model.addAttribute("roleType",roleType);
        return PREFIX + "advertisement_add.html";
    }
 
    /**
     * 跳转到广告编辑页面
     */
    @RequestMapping("/update/{id}/{type}")
    public String store(Model model, @PathVariable("id") Integer id,@PathVariable("type")Integer type) {
        Banner data = bannerClient.getById(id);
        List<Map<String, Object>> pages = storeService.typeChange(data.getModel());
        List<Map<String, Object>> types = storeService.typeChangeOne(data.getJumpPage());
        // type=1 查看详情 type=2 编辑
        if (type == 1){
            model.addAttribute("type",1);
        }else{
            model.addAttribute("type",2);
        }
        Integer roleType = UserExt.getUser().getObjectType();
        model.addAttribute("roleType",roleType);
        model.addAttribute("data",data);
        model.addAttribute("pages",pages);
        model.addAttribute("types",types);
        return PREFIX + "advertisement_edit.html";
    }
 
    /**
     * 广告上下架
     */
    @RequestMapping("/changeState")
    @ResponseBody
    public Object changeState(@RequestBody AdvertisementChangeStateDTO dto) {
        bannerClient.changeState(dto);
        return ResultUtil.success();
    }
    /**
     *  添加广告
     */
    @ResponseBody
    @RequestMapping(value = "/addAdvertisement")
    public ResultUtil addAdvertisement(@RequestBody Banner banner) {
        banner.setInsertTime(new Date());
        bannerClient.addAdvertisement(banner);
        return ResultUtil.success("添加成功");
    }
    /**
     *  编辑广告
     */
    @ResponseBody
    @RequestMapping(value = "/updateAdvertisement")
    public ResultUtil updateAdvertisement(@RequestBody Banner banner) {
        Banner byId = bannerClient.getById(banner.getId());
        // 如果为空 则没有改变图片
        if (banner.getImg().equals("")||banner==null){
            banner.setImg(byId.getImg());
        }
        bannerClient.updateAdvertisement(banner);
        return ResultUtil.success("添加成功");
    }
    /**
     * 通过id 获取广告管理 数据
     */
    @ResponseBody
    @RequestMapping(value = "/getById")
    public Banner getById(Integer bannerId) {
 
        return bannerClient.getById(bannerId);
    }
 
    /**
     * 获取教练列表
     */
    @RequestMapping(value = "/listAll")
    @ResponseBody
    public List<Banner> listAll(AdvertisementQuery query) {
        return bannerClient.listAll(query);
    }
 
}