无关风月
20 小时以前 cfa7d0a90e7da9b52606ab8fca364fa5bddddcd4
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
package com.dsh.guns.modular.system.controller.code;
 
 
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.dsh.guns.config.UserExt;
import com.dsh.guns.core.util.ToolUtil;
import com.dsh.guns.modular.system.model.HomeModule;
import com.dsh.guns.modular.system.service.IHomeModuleService;
import com.dsh.guns.modular.system.service.IStoreService;
import com.dsh.guns.modular.system.util.ImageUtils;
import com.dsh.guns.modular.system.util.ResultUtil;
import org.springframework.beans.BeanUtils;
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.io.IOException;
import java.util.List;
import java.util.Map;
 
@Controller
@RequestMapping("/tHomeModule")
public class HomeModuleController {
 
    @Autowired
    private IHomeModuleService homeModuleService;
    @Autowired
    private IStoreService storeService;
 
    private String PREFIX = "/system/tHomeModule/";
 
 
    @RequestMapping("/tHomeModule_platformSet/{id}")
    public String tHomeModulePlatformSet(@PathVariable Integer id, Model model) {
        HomeModule data = homeModuleService.getOne(new LambdaQueryWrapper<HomeModule>().eq(HomeModule::getStoreId, id));
        if(data==null){
            data =homeModuleService.getById(1);
        }
        List<Map<String, Object>> pages = storeService.typeChange(data.getModel());
        List<Map<String, Object>> types = storeService.typeChangeOne(data.getJumpPage());
        // type=1 查看详情 type=2 编辑
        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);
        model.addAttribute("id",id);
        return PREFIX + "tHomeModule.html";
    }
 
    @ResponseBody
    @RequestMapping("/updateHomeModule")
    public ResultUtil updateAdvertisement(@RequestBody HomeModule homeModule) {
        HomeModule one = homeModuleService.getOne(new LambdaQueryWrapper<HomeModule>().eq(HomeModule::getStoreId, homeModule.getStoreId()));
        if(one==null){
            one = new HomeModule();
            BeanUtils.copyProperties(homeModule,one);
            one.setId(null);
            if (homeModule.getType().equals("请选择")){
                one.setType(null);
            }
            if (homeModule.getPage().equals("请选择")){
                one.setPage(null);
            }
            if (ToolUtil.isNotEmpty(homeModule.getBackgroundImage())) {
                try {
                    one.setDisplayType(ImageUtils.getImageDimensions(homeModule.getBackgroundImage()).getDisplayType());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return ResultUtil.success(homeModuleService.saveOrUpdate(one));
 
        }else {
            if (homeModule.getType().equals("请选择")){
                homeModule.setType(null);
            }
            if (homeModule.getPage().equals("请选择")){
                homeModule.setPage(null);
            }
            if (ToolUtil.isNotEmpty(homeModule.getBackgroundImage())) {
                try {
                    homeModule.setDisplayType(ImageUtils.getImageDimensions(homeModule.getBackgroundImage()).getDisplayType());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return ResultUtil.success(homeModuleService.updateById(homeModule));
        }
 
    }
 
}