guoshilong
2023-06-20 e95a5d39eabc286c574e39dea14377fcd159051b
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
package cn.gistack.sm.appmanage.controller;
 
import cn.gistack.common.utils.WxUtils;
import cn.gistack.sm.appmanage.entity.AppManage;
import cn.gistack.sm.appmanage.service.IAppManageService;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.metadata.IPage;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springblade.core.mp.support.Condition;
import org.springblade.core.mp.support.Query;
import org.springblade.core.tool.api.R;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.client.RestTemplate;
 
import java.util.LinkedHashMap;
import java.util.Map;
 
/**
 * @ClassName app管理
 * @Description TODO
 * @Author aix
 * @Date 2023/4/26 20:55
 * @Version 1.0
 */
@Slf4j
@Api(tags="app管理")
@RestController
@RequestMapping("/app/manage")
@AllArgsConstructor
public class AppManageController {
 
    private IAppManageService appManageService;
 
    /**
     * 分页列表查询
     *
     * @param appManage
     * @return
     */
    @ApiOperation(value = "app管理-分页列表查询", notes = "app管理-分页列表查询")
    @GetMapping(value = "/list")
    public R queryPageList(AppManage appManage, Query query) {
        IPage<AppManage> pageList = appManageService.page(Condition.getPage(query), Condition.getQueryWrapper(appManage));
        return R.data(pageList);
    }
 
    /**
     * 添加
     *
     * @param appManage
     * @return
     */
    @ApiOperation(value = "app管理-添加", notes = "app管理-添加")
    @PostMapping(value = "/add")
    public R add(@RequestBody AppManage appManage) {
        return R.data(appManageService.save(appManage));
    }
 
    /**
     * 编辑
     *
     * @param appManage
     * @return
     */
    @ApiOperation(value = "app管理-编辑", notes = "app管理-编辑")
    @RequestMapping(value = "/edit", method = {RequestMethod.PUT, RequestMethod.POST})
    public R edit(@RequestBody AppManage appManage) {
        return R.data(appManageService.updateById(appManage));
    }
 
    /**
     * 通过id删除
     *
     * @param id
     * @return
     */
    @ApiOperation(value = "app管理-通过id删除", notes = "app管理-通过id删除")
    @PostMapping(value = "/delete")
    public R<?> delete(@RequestParam(name = "id", required = true) String id) {
        return R.data(appManageService.removeById(id));
    }
 
    /**
     * 查询最新一条的数据
     *
     * @return
     */
    @ApiOperation(value = "app管理-查询最新一条的数据", notes = "app管理-查询最新一条的数据")
    @GetMapping(value = "/getLastInfo")
    public R getLastInfo() {
        AppManage appManage = appManageService.getLastInfo();
        return R.data(appManage);
    }
 
    /**
     * 获取微信小程序跳转链接
     *
     * @return
     */
    @ApiOperation(value = "app管理-获取微信小程序跳转链接", notes = "app管理-获取微信小程序跳转链接")
    @GetMapping(value = "/getMiniProgramPath")
    public R getMiniProgramPath(){
        String wxAccessToken = WxUtils.getWxAccessToken();
 
        String url = WxUtils.WX_GET_GENERATESCHEME+"?access_token="+wxAccessToken;
 
        RestTemplate template = new RestTemplate();
        Map<String, Object> params = new LinkedHashMap<>();
 
        /**
         * {
         *     "jump_wxa":
         *     {
         *         "path": "/pages/publishHomework/publishHomework",
         *         "query": "",
         *         "env_version": "release"
         *     },
         *     "is_expire":true,
         *     "expire_type":1,
         *     "expire_interval":1
         * }
         */
        JSONObject jump_wxa = new JSONObject();
 
        jump_wxa.put("path","/pages/home/index");
        jump_wxa.put("query","");
        jump_wxa.put("env_version","release");
 
        params.put("jump_wxa",jump_wxa);
        params.put("is_expire",true);
        params.put("expire_type",1);
        params.put("expire_interval",1);
 
        String result = template.postForObject(url, params, String.class);
        JSONObject resultObj = (JSONObject)JSONObject.parse(result);
        String openLink = resultObj.getString("openlink");
 
        return R.data(openLink);
    }
 
}