| | |
| | | package com.xinquan.system.controller; |
| | | |
| | | |
| | | import org.springframework.web.bind.annotation.RequestMapping; |
| | | import com.alibaba.nacos.shaded.org.checkerframework.checker.units.qual.A; |
| | | import com.alibaba.nacos.shaded.org.checkerframework.checker.units.qual.C; |
| | | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
| | | import com.xinquan.common.core.domain.R; |
| | | import com.xinquan.common.core.utils.page.PageDTO; |
| | | import com.xinquan.common.core.web.domain.BaseModel; |
| | | import com.xinquan.common.security.service.TokenService; |
| | | import com.xinquan.common.security.utils.SecurityUtils; |
| | | import com.xinquan.system.api.domain.AppUser; |
| | | import com.xinquan.system.api.domain.NoticeRecord; |
| | | import com.xinquan.system.domain.Version; |
| | | import com.xinquan.system.service.VersionService; |
| | | import com.xinquan.user.api.feign.RemoteAppUserService; |
| | | import io.swagger.annotations.ApiImplicitParam; |
| | | import io.swagger.annotations.ApiImplicitParams; |
| | | import io.swagger.annotations.ApiOperation; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.web.bind.annotation.*; |
| | | |
| | | import org.springframework.web.bind.annotation.RestController; |
| | | import java.time.LocalDateTime; |
| | | import java.util.Arrays; |
| | | import java.util.List; |
| | | import java.util.stream.Collectors; |
| | | |
| | | /** |
| | | * <p> |
| | |
| | | @RestController |
| | | @RequestMapping("/system/version") |
| | | public class VersionController { |
| | | |
| | | @Autowired |
| | | private VersionService versionService; |
| | | @Autowired |
| | | private TokenService tokenService; |
| | | @Autowired |
| | | private RemoteAppUserService remoteAppUserService; |
| | | @GetMapping("/detailVersionApp") |
| | | @ApiOperation(value = "查看详情版本管理", tags = "安卓版本管理") |
| | | public R<Version> detailVersionApp() { |
| | | List<Version> list = versionService.lambdaQuery().orderByDesc(BaseModel::getCreateTime).list(); |
| | | if (!list.isEmpty()){ |
| | | return R.ok(list.get(0)); |
| | | } |
| | | return R.ok(); |
| | | } |
| | | @GetMapping("/versionList") |
| | | @ApiOperation(value = "版本管理列表-分页", tags = {"管理后台-版本管理"}) |
| | | @ApiImplicitParams({ |
| | | @ApiImplicitParam(value = "分页参数,当前页码", name = "pageCurr", required = true, dataType = "Integer"), |
| | | @ApiImplicitParam(value = "分页参数,每页数量", name = "pageSize", required = true, dataType = "Integer") |
| | | }) |
| | | public R<PageDTO<Version>> versionList( |
| | | @RequestParam(value = "pageCurr", defaultValue = "1") Integer pageCurr, |
| | | @RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize) { |
| | | Long userId = SecurityUtils.getUserId(); |
| | | if(userId ==null || userId == 0)return R.tokenError("登录失效"); |
| | | Page<Version> page = versionService.lambdaQuery() |
| | | .orderByDesc(Version::getCreateTime) |
| | | .page(new Page<>(pageCurr, pageSize)); |
| | | if (page.getRecords().isEmpty()){ |
| | | return R.ok(PageDTO.empty(page)); |
| | | } |
| | | for (Version record : page.getRecords()) { |
| | | record.setUid(record.getId() + ""); |
| | | } |
| | | return R.ok(PageDTO.of(page, Version.class)); |
| | | } |
| | | @PostMapping("/addVersion") |
| | | @ApiOperation(value = "新增版本管理", tags = "管理后台-版本管理") |
| | | public R addVersion(@RequestBody Version homeBackgroundMusic) { |
| | | homeBackgroundMusic.setCreateBy(SecurityUtils.getUsername()); |
| | | homeBackgroundMusic.setCreateTime(LocalDateTime.now()); |
| | | List<AppUser> data = remoteAppUserService.getAllUserList().getData(); |
| | | for (AppUser datum : data) { |
| | | // 给用户添加一条系统消息 |
| | | NoticeRecord noticeRecord = new NoticeRecord(); |
| | | noticeRecord.setAppUserId(datum.getId()); |
| | | noticeRecord.setReadStatus(1); |
| | | noticeRecord.setNoticeType(1); |
| | | noticeRecord.setTitle("APP版本升级通知"); |
| | | noticeRecord.setContent("APP已更新至【"+homeBackgroundMusic.getVersionNo()+"】版本,请及时更新!"); |
| | | remoteAppUserService.addNoticeReplay(noticeRecord); |
| | | } |
| | | return R.ok(versionService.save(homeBackgroundMusic)); |
| | | } |
| | | @GetMapping("/detailVersion") |
| | | @ApiOperation(value = "查看详情版本管理", tags = "管理后台-版本管理") |
| | | public R<Version> detailVersion(String uid) { |
| | | return R.ok(versionService.getById(uid)); |
| | | } |
| | | @PostMapping("/updateVersion") |
| | | @ApiOperation(value = "修改版本管理", tags = "管理后台-版本管理") |
| | | public R updateVersion(@RequestBody Version homeBackgroundMusic) { |
| | | homeBackgroundMusic.setUpdateBy(SecurityUtils.getUsername()); |
| | | homeBackgroundMusic.setUpdateTime(LocalDateTime.now()); |
| | | return R.ok(versionService.updateById(homeBackgroundMusic)); |
| | | } |
| | | @PostMapping("/deleteVersion") |
| | | @ApiOperation(value = "批量删除", tags = "管理后台-版本管理") |
| | | public R deleteVersion(String ids) { |
| | | return R.ok(versionService.removeBatchByIds(Arrays.asList(ids.split(",")).stream().map(Long::valueOf).collect(Collectors.toList()))); |
| | | } |
| | | } |
| | | |