Pu Zhibing
2025-03-26 7f26677ab7f9b83697370fa142dd1686cdf4082a
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
package com.ruoyi.other.controller;
 
 
import com.alibaba.fastjson2.JSON;
import com.alibaba.fastjson2.JSONObject;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.other.api.domain.SystemConfig;
import com.ruoyi.other.api.dto.IndexConfigSetDto;
import com.ruoyi.other.api.dto.LogisticsSetDto;
import com.ruoyi.other.api.dto.StartPageSetDto;
import com.ruoyi.other.service.SystemConfigService;
import org.springframework.web.bind.annotation.*;
import io.swagger.annotations.ApiOperation;
 
import javax.annotation.Resource;
import java.util.List;
 
/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author luodangjia
 * @since 2024-11-20
 */
@RestController
@RequestMapping("/system-config")
public class SystemConfigController {
    @Resource
    private SystemConfigService systemConfigService;
    @PostMapping("/index/add")
    @ApiOperation(value = "广告管理-首页配置-添加", tags = {"管理后台"})
    public R add(@RequestBody IndexConfigSetDto indexConfigSetDto){
        //先删除type=2的数据
        List<SystemConfig> list = systemConfigService.lambdaQuery().eq(SystemConfig::getType, 2).list();
        systemConfigService.removeBatchByIds(list);
        SystemConfig  systemConfig = new SystemConfig();
        systemConfig.setType(2);
        systemConfig.setContent(JSON.toJSONString(indexConfigSetDto));
        systemConfigService.save(systemConfig);
        return R.ok();
      }
      
      
      
    @GetMapping("/index/detail")
    @ApiOperation(value = "广告管理-首页配置-宣传图片-公司简介", tags = {"管理后台","小程序-首页"})
    public R<IndexConfigSetDto> detail(){
        SystemConfig one = systemConfigService.lambdaQuery().eq(SystemConfig::getType, 2).one();
        if (one==null){
            return R.ok();
        }
        IndexConfigSetDto indexConfigSetDto = JSONObject.parseObject(one.getContent(), IndexConfigSetDto.class);
        return R.ok(indexConfigSetDto);
 
    }
    
    
    /**
     * 根据类型获取系统配置
     * @param type
     * @return
     */
    @ResponseBody
    @PostMapping("/getSystemConfig")
    public R<SystemConfig> getSystemConfig(@RequestParam("type") Integer type){
        SystemConfig one = systemConfigService.lambdaQuery().eq(SystemConfig::getType, type).last("limit 1").one();
        return R.ok(one);
    }
 
    @GetMapping("/index/start")
    @ApiOperation(value = "宣传图片-公司简介", tags = {"小程序-启动页"})
    public R<StartPageSetDto> indexstart(){
        SystemConfig one = systemConfigService.lambdaQuery().eq(SystemConfig::getType, 1).one();
        if (one==null){
            return R.ok();
        }
        StartPageSetDto indexConfigSetDto = JSONObject.parseObject(one.getContent(), StartPageSetDto.class);
        return R.ok(indexConfigSetDto);
 
    }
 
    @PostMapping("/startPage/add")
    @ApiOperation(value = "广告管理-启动页管理-添加", tags = {"管理后台"})
    public R startPageadd(@RequestBody StartPageSetDto startPageSetDto){
        //先删除type=1的数据
        List<SystemConfig> list = systemConfigService.lambdaQuery().eq(SystemConfig::getType, 1).list();
        systemConfigService.removeBatchByIds(list);
        SystemConfig  systemConfig = new SystemConfig();
        systemConfig.setType(1);
        systemConfig.setContent(JSON.toJSONString(startPageSetDto));
        systemConfigService.save(systemConfig);
        return R.ok();
    }
 
    /**
     * 订单包邮设置
     */
    @PostMapping("/logistics/add")
    @ApiOperation(value = "添加", tags = {"管理后台-商品管理-订单包邮设置"})
    public R add(@RequestBody LogisticsSetDto logisticsSetDto){
        List<SystemConfig> list = systemConfigService.lambdaQuery().eq(SystemConfig::getType, 3).list();
        systemConfigService.removeBatchByIds(list);
        SystemConfig  systemConfig = new SystemConfig();
        systemConfig.setType(3);
        systemConfig.setContent(JSON.toJSONString(logisticsSetDto));
        systemConfigService.save(systemConfig);
        return R.ok();
    }
 
    /**
     * 获取订单包邮设置
     */
    @GetMapping("/logistics/detail")
    @ApiOperation(value = "订单包邮设置", tags = {"管理后台-商品管理-订单包邮设置"})
    public R<LogisticsSetDto> logisticsDetail(){
        SystemConfig one = systemConfigService.lambdaQuery().eq(SystemConfig::getType, 3).one();
        if (one==null){
            return R.ok();
        }
        LogisticsSetDto logisticsSetDto = JSONObject.parseObject(one.getContent(), LogisticsSetDto.class);
        return R.ok(logisticsSetDto);
    }
 
 
}