mitao
2024-04-30 ab4ea7b8f10c9b66aed9c2ea161a08b25c3851a7
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
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
package com.sinata.modular.system.controller;
 
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.mapper.Wrapper;
import com.google.common.collect.Lists;
import com.sinata.common.enums.EnumAppSetKey;
import com.sinata.core.base.controller.BaseController;
import com.sinata.core.log.LogObjectHolder;
import com.sinata.core.util.ToolUtil;
import com.sinata.modular.system.model.TAppSet;
import com.sinata.modular.system.service.ITAppSetService;
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.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
 
import java.util.HashMap;
import java.util.List;
import java.util.Map;
 
/**
 * APP设置控制器
 */
@Controller
@RequestMapping("/tAppSet")
public class TAppSetController extends BaseController {
 
    private String PREFIX = "/system/tAppSet/";
 
    @Autowired
    private ITAppSetService tAppSetService;
 
    /**
     * 跳转到APP设置首页
     */
    @RequestMapping("html")
    public String html(Model model) {
        List<Integer> ids = Lists.newArrayList(
                EnumAppSetKey.REGISTER_AGREEMENT_H5.index,
                EnumAppSetKey.USER_AGREEMENT_H5.index,
                EnumAppSetKey.TEAM_US_H5.index,
                EnumAppSetKey.DAILY_TASK_H5.index,
                EnumAppSetKey.ABOUT_US_H5.index,
                EnumAppSetKey.SERVICE_TEL_NUMBER.index,
                EnumAppSetKey.MEMBER_GRADE_H5.index,
                EnumAppSetKey.RICE_GRAINS_H5.index,
                EnumAppSetKey.CONTRIBUTION_SCORE_H5.index,
                EnumAppSetKey.EXCHANGE_AGREEMENT_H5.index,
                EnumAppSetKey.SERVICE_H5.index,
                EnumAppSetKey.MERCHANT_H5.index,
                EnumAppSetKey.HELP_H5.index,
                EnumAppSetKey.USER_INFO_HANDLE_RULE_H5.index,
                EnumAppSetKey.JOIN_COMPANY_AGREEMENT_H5.index
        );
        List<TAppSet> appSetList = tAppSetService.selectList(null);
 
        List<Map<String, String>> contents = Lists.newArrayList();
        for (TAppSet obj : appSetList) {
            if ( !ids.contains( obj.getId())) { continue; }
            contents.add( new HashMap<String, String>(){{
                put( "key", obj.getId().toString());
                put( "content", obj.getValueStr());
            }});
        }
 
        model.addAttribute( "keys", ids);
        model.addAttribute( "contents", contents);
        return PREFIX + "html.html";
    }
    @RequestMapping("/updateHtml")
    @ResponseBody
    public Object updateHtml(Integer id, String content) {
        // H5页面代码包装(判断加上自适应代码)
        if (ToolUtil.isNotEmpty(content)) {
            content = ToolUtil.h5Warpper(content);
        }
 
        TAppSet appSet = tAppSetService.selectById(id);
        if (appSet != null) {
            appSet.setValueStr(content);
            tAppSetService.updateById(appSet);
        } else {
            appSet = new TAppSet();
            appSet.setValueStr(content);
            tAppSetService.insert(appSet);
        }
        return SUCCESS_TIP;
    }
 
    /**
     * 跳转到APP设置首页
     */
    @RequestMapping("")
    public String index() {
        return PREFIX + "tAppSet.html";
    }
 
    /**
     * 跳转到添加APP设置
     */
    @RequestMapping("/tAppSet_add")
    public String tAppSetAdd() {
        return PREFIX + "tAppSet_add.html";
    }
 
    /**
     * 跳转到修改APP设置
     */
    @RequestMapping("/tAppSet_update/{tAppSetId}")
    public String tAppSetUpdate(@PathVariable Integer tAppSetId, Model model) {
        TAppSet tAppSet = tAppSetService.selectById(tAppSetId);
        model.addAttribute("item",tAppSet);
        LogObjectHolder.me().set(tAppSet);
        return PREFIX + "tAppSet_edit.html";
    }
 
    /**
     * 获取APP设置列表
     */
    @RequestMapping(value = "/list")
    @ResponseBody
    public Object list(String condition) {
        Wrapper wrapper = new EntityWrapper<TAppSet>();
        return tAppSetService.selectList(wrapper);
    }
 
    /**
     * 新增APP设置
     */
    @RequestMapping(value = "/add")
    @ResponseBody
    public Object add(TAppSet tAppSet) {
        tAppSetService.insert(tAppSet);
        return SUCCESS_TIP;
    }
 
    /**
     * 删除APP设置
     */
    @RequestMapping(value = "/delete")
    @ResponseBody
    public Object delete(@RequestParam Integer tAppSetId) {
        tAppSetService.deleteById(tAppSetId);
//        tAppSetService.updateById(new TAppSet(tAppSetId, 1));
        return SUCCESS_TIP;
    }
 
    /**
     * 修改APP设置
     */
    @RequestMapping(value = "/update")
    @ResponseBody
    public Object update(TAppSet tAppSet) {
        tAppSetService.updateById(tAppSet);
        return SUCCESS_TIP;
    }
 
    /**
     * 修改APP设置状态
     */
    @RequestMapping(value = "/updateState")
    @ResponseBody
    public Object updateState(@RequestParam Integer tAppSetId) {
//        TAppSet obj = tAppSetService.selectById(tAppSetId);
//        if (obj != null) {
//            if(obj.getState() == 0) {
//                obj.setState(1);
//            } else {
//                obj.setState(0);
//            }
//            tAppSetService.updateById(obj);
//        }
        return SUCCESS_TIP;
    }
 
 
    /**
     * APP设置详情
     */
    @RequestMapping(value = "/detail/{tAppSetId}")
    @ResponseBody
    public Object detail(@PathVariable("tAppSetId") Integer tAppSetId) {
        return tAppSetService.selectById(tAppSetId);
    }
}