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.springblade.core.tool.utils.ObjectUtil; 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 pageList = appManageService.page(Condition.getPage(query), Condition.getQueryWrapper(appManage).orderByDesc("create_time")); 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 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", "/subPackage/user/historical/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"); Integer errCode = resultObj.getInteger("errcode"); String errMsg = resultObj.getString("errmsg"); if (errCode.equals(0)) { return R.data(openLink); } else { return R.fail(errMsg); } } }