package cn.besteam.modules.medical.controller;
|
|
import cn.besteam.common.api.vo.Result;
|
import cn.besteam.common.aspect.annotation.AutoLog;
|
import cn.besteam.common.constant.ErrorCode;
|
import cn.besteam.common.dto.IdDTO;
|
import cn.besteam.common.exception.BusinessException;
|
import cn.besteam.modules.medical.dto.MwAppVersionDTO;
|
import cn.besteam.modules.medical.dto.MwAppVersionUpdateDTO;
|
import cn.besteam.modules.medical.entity.MwAppVersion;
|
import cn.besteam.modules.medical.service.IMwAppVersionService;
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
import io.swagger.annotations.Api;
|
import io.swagger.annotations.ApiOperation;
|
import lombok.extern.slf4j.Slf4j;
|
import org.apache.commons.collections.CollectionUtils;
|
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.validation.annotation.Validated;
|
import org.springframework.web.bind.annotation.*;
|
|
import java.util.List;
|
|
/**
|
* @Title: Controller
|
* @Description: APP-版本
|
* @author: besteam
|
* @date: 2020-04-25
|
* @version: V1.0
|
*/
|
@RestController
|
@RequestMapping("/medical/mwAppVersion")
|
@Slf4j
|
@Api(description = "APP-版本")
|
public class MwAppVersionController {
|
|
@Autowired
|
private IMwAppVersionService mwAppVersionService;
|
|
/**
|
* 分页列表查询
|
*
|
* @param pageNo
|
* @param pageSize
|
* @return
|
*/
|
@GetMapping(value = "/list")
|
@ApiOperation(value = "获取APP-版本数据列表", notes = "获取所有APP-版本数据列表", produces = "application/json")
|
public Result<IPage<MwAppVersion>> queryPageList(@RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo, @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize) {
|
|
QueryWrapper<MwAppVersion> queryWrapper = new QueryWrapper<MwAppVersion>();
|
queryWrapper.lambda().orderByDesc(MwAppVersion::getVersion);
|
Page<MwAppVersion> page = new Page<MwAppVersion>(pageNo, pageSize);
|
IPage<MwAppVersion> pageList = mwAppVersionService.page(page, queryWrapper);
|
return Result.ok(pageList);
|
}
|
|
// @GetMapping(value = "/getLatest")
|
// @ApiOperation(value = "获取最新版本APK", notes = "获取最新版本APK", produces = "application/json")
|
// public Result<MwAppVersion> getLatest() {
|
//
|
// List<MwAppVersion> list = mwAppVersionService.list(new QueryWrapper<MwAppVersion>().lambda().orderByDesc(MwAppVersion::getVersion));
|
// if (CollectionUtils.isNotEmpty(list)) {
|
// return Result.ok(list.get(0));
|
// } else {
|
// return Result.ok((MwAppVersion) null);
|
// }
|
// }
|
|
/**
|
* 添加
|
*
|
* @return
|
*/
|
@PostMapping(value = "/uploadApk")
|
@ApiOperation(value = "上传APK", notes = "上传APK", produces = "application/json")
|
public Result<Boolean> uploadApk(@Validated MwAppVersionDTO dto) {
|
|
return Result.ok(mwAppVersionService.uploadApk(dto));
|
}
|
|
/**
|
* 编辑
|
*
|
* @param dto
|
* @return
|
*/
|
@PostMapping(value = "/edit")
|
@ApiOperation(value = "编辑APP-版本", notes = "编辑APP-版本", produces = "application/json")
|
public Result<Boolean> edit(@Validated @RequestBody MwAppVersionUpdateDTO dto) {
|
|
MwAppVersion mwAppVersionEntity = mwAppVersionService.getById(dto.getId());
|
if (mwAppVersionEntity == null) {
|
throw new BusinessException(ErrorCode.MW_APK_VERSION_NOT_FOUND);
|
}
|
if (mwAppVersionService.getOne(new QueryWrapper<MwAppVersion>().lambda().eq(MwAppVersion::getVersion, dto.getVersion()).ne(MwAppVersion::getId, dto.getId())) != null) {
|
throw new BusinessException(ErrorCode.MW_APK_VERSION_REPEAT);
|
}
|
mwAppVersionEntity.setDescription(dto.getDescription());
|
mwAppVersionEntity.setVersion(dto.getVersion());
|
mwAppVersionEntity.setVersionName(dto.getVersionName());
|
return Result.ok(mwAppVersionService.updateById(mwAppVersionEntity));
|
}
|
|
/**
|
* 通过id删除
|
*
|
* @param dto
|
* @return
|
*/
|
@PostMapping(value = "/delete")
|
@AutoLog(value = "删除APP-版本")
|
@ApiOperation(value = "删除APP-版本", notes = "删除APP-版本", produces = "application/json")
|
public Result<MwAppVersion> delete(@Validated @RequestBody IdDTO dto) {
|
|
Result<MwAppVersion> result = new Result<MwAppVersion>();
|
MwAppVersion mwAppVersion = mwAppVersionService.getById(dto.getId());
|
if (mwAppVersion == null) {
|
result.error500("未找到对应实体");
|
} else {
|
boolean ok = mwAppVersionService.removeById(dto.getId());
|
if (ok) {
|
result.success("删除成功!");
|
}
|
}
|
return result;
|
}
|
|
}
|