AppUpdateController.java 13.7 KB
/*
package com.brframework.webapppatch.web;

import com.brframework.commoncms.annatotion.AdminMenu;
import com.brframework.commoncms.annatotion.layout.EditAlertLayout;
import com.brframework.commoncms.annatotion.layout.EditLayout;
import com.brframework.commoncms.annatotion.layout.PageLayout;
import com.brframework.commoncms.annatotion.layout.ViewLayout;
import com.brframework.commoncms.annatotion.option.CmsOption;
import com.brframework.commoncms.core.Icons;
import com.brframework.commonweb.json.JSONResult;
import com.brframework.commonweb.json.Page;
import com.brframework.commonweb.json.PageParam;
import com.brframework.commonwebadmin.aop.annotation.AOLog;
import com.brframework.webapppatch.domain.AppPatchConfig;
import com.brframework.webapppatch.entity.AppVersion;
import com.brframework.webapppatch.entity.PatchBranch;
import com.brframework.webapppatch.entity.PatchGrayUser;
import com.brframework.webapppatch.entity.PatchVersion;
import com.brframework.webapppatch.json.*;
import com.brframework.webapppatch.service.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

import java.time.LocalDateTime;

import static com.brframework.commondb.core.ControllerPageHandle.jpaPageConvertToPage;
import static com.brframework.commondb.core.ControllerPageHandle.jpaPageToPage;

*/
/**
 * APP热更新
 *
 * @author xu
 * @date 2019/11/14 10:36
 *//*

@RestController
@Api(tags = "APP更新")
@RequestMapping("/admin/access")
@AdminMenu(menuName = "APP更新", icon = Icons.DEVELOPMENT_FIX, order = Integer.MIN_VALUE + 200)
public class AppUpdateController {

    @Autowired
    AppVersionService appVersionService;
    @Autowired
    PatchBranchService patchBranchService;
    @Autowired
    PatchGrayUserService patchGrayUserService;
    @Autowired
    PatchVersionService patchVersionService;
    @Autowired
    PatchConfigService patchConfigService;

    @ApiOperation(value = "APP版本列表", notes = "APP版本列表")
    @GetMapping("v1/app/version/list")
    @PageLayout(
            options = {
                    @CmsOption(name = "发布", uriMappingMethod = "appVersionCreate")
            },
            columnOptions = {
                    @CmsOption(name = "查看", uriMappingMethod = "appVersionGet"),
                    @CmsOption(name = "灰度", condition = "{updateStatus}==1", uriMappingMethod = "appVersionGray", alert = "您确定要进行灰度发布吗?"),
                    @CmsOption(name = "发布", condition = "{updateStatus}==2", uriMappingMethod = "appVersionRelease", alert = "您确定要正式发布吗?"),
                    @CmsOption(name = "失败", condition = "{updateStatus}==2", uriMappingMethod = "appVersionDefeated", alert = "您确定要失败吗?")
            }
    )
    @PreAuthorize("hasRole('app-version-list')")
    @AdminMenu(menuName = "APP版本管理", order = 5)
    @AOLog
    public JSONResult<Page<AppVersionListSimpleResult>> appVersionList(@Valid PageParam page, AppVersionListParam param) {
        return JSONResult.ok(jpaPageConvertToPage(
                appVersionService.page(page, param),
                page, AppVersionListSimpleResult.class
        ));
    }

    @ApiOperation(value = "发布版本", notes = "新增版本")
    @PutMapping("v1/app/version")
    @EditAlertLayout
    @PreAuthorize("hasRole('app-version-create')")
    @AOLog
    public JSONResult appVersionCreate(
            @Valid @RequestBody AppVersionUpdateParam param) {
        appVersionService.createVersion(param.getOs(), param.getVersion(), param.getVersionName(), param.getVersionMessage(),
                param.getVersionUrl(), param.getUpdateType());
        return JSONResult.ok();
    }

    @ApiOperation(value = "查看版本信息", notes = "查看版本信息")
    @GetMapping("v1/app/version/{id}")
    @ViewLayout(
            paddingMappingMethod = "appVersionGet"
    )
    @PreAuthorize("hasRole('app-version-get')")
    @AOLog
    public JSONResult<AppVersion> appVersionGet(@PathVariable Long id) {
        return JSONResult.ok(appVersionService.accessObject(id));
    }

    @ApiOperation(value = "版本进入灰度", notes = "版本进入灰度")
    @PostMapping("v1/app/version/gray/{id}")
    @PreAuthorize("hasRole('app-version-gray')")
    @AOLog
    public JSONResult appVersionGray(@PathVariable Long id) {
        appVersionService.setVersionGray(id);
        return JSONResult.ok();
    }

    @ApiOperation(value = "版本发布", notes = "版本发布")
    @PostMapping("v1/app/version/release/{id}")
    @PreAuthorize("hasRole('app-version-release')")
    @AOLog
    public JSONResult appVersionRelease(@PathVariable Long id) {
        appVersionService.setVersionRelease(id);
        return JSONResult.ok();
    }

    @ApiOperation(value = "版本失败", notes = "版本失败")
    @DeleteMapping("v1/app/version/defeated/{id}")
    @PreAuthorize("hasRole('app-version-defeated')")
    @AOLog
    public JSONResult appVersionDefeated(@PathVariable Long id) {
        appVersionService.setVersionDefeated(id);
        return JSONResult.ok();
    }


    @ApiOperation(value = "热更新分支列表", notes = "热更新分支列表")
    @GetMapping("v1/app-patch/branch/list")
    @PageLayout(
            options = {
                    @CmsOption(name = "添加分支", uriMappingMethod = "appPatchBranchCreate")
            },
            columnOptions = {
                    @CmsOption(name = "查看", uriMappingMethod = "appPatchBranchGet"),
                    //@CmsOption(name = "修改信息", uriMappingMethod = "appPatchBranchEdit"),
                    @CmsOption(name = "删除", uriMappingMethod = "appPatchBranchDel", alert = "您确定要删除该数据吗?"),
                    @CmsOption(name = "清除分支版本", uriMappingMethod = "appPatchBranchVersion", alert = "您确定清除该分支下的所有版本吗?这是一个危险并不可逆的操作,如果您对该功能不了解或不完全了解不要进行该操作!")
            }
    )
    @PreAuthorize("hasRole('app-patch-branch-list')")
    @AdminMenu(menuName = "热更新分支管理", order = 20)
    @AOLog
    public JSONResult<Page<AppPatchBranchSimpleResult>> appPatchBranchList(@Valid PageParam page) {
        return JSONResult.ok(jpaPageConvertToPage(
                patchBranchService.page(page, null),
                page, AppPatchBranchSimpleResult.class
        ));
    }

    @ApiOperation(value = "分支信息", notes = "分支信息")
    @GetMapping("v1/app-patch/branch/{id}")
    @ViewLayout(paddingMappingMethod = "appPatchBranchGet")
    @PreAuthorize("hasRole('app-patch-branch-list')")
    @AOLog
    public JSONResult<PatchBranch> appPatchBranchGet(@PathVariable Long id) {

        return JSONResult.ok(
                patchBranchService.accessObject(id)
        );
    }

    @ApiOperation(value = "更新分支", notes = "更新分支")
    @PostMapping("v1/app-patch/branch/{id}")
    @EditAlertLayout(
            paddingMappingMethod = "appPatchBranchGet"
    )
    @PreAuthorize("hasRole('app-patch-branch-edit')")
    @AOLog
    public JSONResult appPatchBranchEdit(
            @PathVariable Long id,
            @Valid @RequestBody AppPatchBranchUpdateParam param) {

        patchBranchService.updateBranch(id, param.getOs(), param.getBranchName(), param.getBranchDetail());
        return JSONResult.ok();
    }

    @ApiOperation(value = "清除分支版本", notes = "清除分支版本")
    @DeleteMapping("v1/app-patch/branch/version/{id}")
    @PreAuthorize("hasRole('app-patch-branch-version')")
    public JSONResult appPatchBranchVersion(@PathVariable Long id) {

        PatchBranch patchBranch = patchBranchService.accessObject(id);
        patchVersionService.removeByBranch(patchBranch.getBranchName());

        return JSONResult.ok();
    }

    @ApiOperation(value = "添加分支", notes = "添加分支")
    @PutMapping("v1/app-patch/branch")
    @EditAlertLayout
    @PreAuthorize("hasRole('app-patch-branch-create')")
    @AOLog
    public JSONResult appPatchBranchCreate(
            @Valid @RequestBody AppPatchBranchUpdateParam param) {
        patchBranchService.createBranch(param.getOs(), param.getBranchName(), param.getBranchDetail());
        return JSONResult.ok();
    }

    @ApiOperation(value = "删除分支", notes = "删除分支")
    @DeleteMapping("v1/app-patch/branch/{id}")
    @PreAuthorize("hasRole('app-patch-branch-del')")
    public JSONResult appPatchBranchDel(@PathVariable Long id) {
        patchBranchService.removeById(id);
        return JSONResult.ok();
    }


    @ApiOperation(value = "灰度用户列表", notes = "灰度用户列表")
    @GetMapping("v1/app-patch/gray-user/list")
    @PageLayout(
            options = {
                    @CmsOption(name = "添加灰度用户", uriMappingMethod = "appPatchGrayUserCreate")
            },
            columnOptions = {
                    @CmsOption(name = "删除", uriMappingMethod = "appPatchGrayUserDel", alert = "您确定要删除该数据吗?")
            }
    )
    @PreAuthorize("hasRole('app-patch-gray-user-list')")
    @AdminMenu(menuName = "灰度用户管理", order = 30)
    @AOLog
    public JSONResult<Page<PatchGrayUser>> appPatchGrayUserList(@Valid PageParam page,
                                                                AppPatchGrayUserListQueryParam param) {
        return JSONResult.ok(jpaPageToPage(
                patchGrayUserService.page(page, param),
                page
        ));
    }

    @ApiOperation(value = "添加灰度用户", notes = "添加灰度用户")
    @PutMapping("v1/app-patch/gray-user")
    @EditAlertLayout
    @PreAuthorize("hasRole('app-patch-gray-user-create')")
    @AOLog
    public JSONResult appPatchGrayUserCreate(
            @Valid @RequestBody AppPatchGrayUserUpdateParam param) {

        patchGrayUserService.createGrayUser(param.getUsername());
        return JSONResult.ok();
    }

    @ApiOperation(value = "删除灰度用户", notes = "删除灰度用户")
    @DeleteMapping("v1/app-patch/gray-user/{id}")
    @PreAuthorize("hasRole('app-patch-gray-user-del')")
    @AOLog
    public JSONResult appPatchGrayUserDel(@PathVariable Long id) {
        patchGrayUserService.removeById(id);
        return JSONResult.ok();
    }


    @ApiOperation(value = "热更新版本列表", notes = "热更新版本列表")
    @GetMapping("v1/app-patch/version/list")
    @PageLayout(
            columnOptions = {
                    @CmsOption(name = "查看", uriMappingMethod = "appPatchVersionGet"),
                    @CmsOption(name = "灰度", condition = "{updateStatus}==1", uriMappingMethod = "appPatchVersionGray", alert = "您确定要进行灰度发布吗?"),
                    @CmsOption(name = "发布", condition = "{updateStatus}==2", uriMappingMethod = "appPatchVersionRelease", alert = "您确定要正式发布吗?"),
                    @CmsOption(name = "失败", condition = "{updateStatus}==2", uriMappingMethod = "appPatchVersionDefeated", alert = "您确定要失败吗?")
            }
    )
    @PreAuthorize("hasRole('app-patch-version-list')")
    @AdminMenu(menuName = "热更新版本管理", order = 10)
    @AOLog
    public JSONResult<Page<AppPatchVersionListSimpleResult>> appPatchVersionList(@Valid PageParam page, AppPatchVersionListParam param) {
        return JSONResult.ok(jpaPageConvertToPage(
                patchVersionService.page(page, param),
                page, AppPatchVersionListSimpleResult.class
        ));
    }

    @ApiOperation(value = "查看版本信息", notes = "查看版本信息")
    @GetMapping("v1/app-patch/version/{id}")
    @ViewLayout(
            paddingMappingMethod = "appPatchVersionGet"
    )
    @PreAuthorize("hasRole('app-patch-version-get')")
    @AOLog
    public JSONResult<PatchVersion> appPatchVersionGet(@PathVariable Long id) {
        return JSONResult.ok(patchVersionService.accessObject(id));
    }

    @ApiOperation(value = "版本进入灰度", notes = "版本进入灰度")
    @PostMapping("v1/app-patch/version/gray/{id}")
    @PreAuthorize("hasRole('app-patch-version-gray')")
    @AOLog
    public JSONResult appPatchVersionGray(@PathVariable Long id) {
        patchVersionService.setVersionGray(id);
        return JSONResult.ok();
    }

    @ApiOperation(value = "版本发布", notes = "版本发布")
    @PostMapping("v1/app-patch/version/release/{id}")
    @PreAuthorize("hasRole('app-patch-version-release')")
    @AOLog
    public JSONResult appPatchVersionRelease(@PathVariable Long id) {
        patchVersionService.setVersionRelease(id);
        return JSONResult.ok();
    }

    @ApiOperation(value = "版本失败", notes = "版本失败")
    @DeleteMapping("v1/app-patch/version/defeated/{id}")
    @PreAuthorize("hasRole('app-patch-version-defeated')")
    @AOLog
    public JSONResult appPatchVersionDefeated(@PathVariable Long id) {
        patchVersionService.setVersionDefeated(id);
        return JSONResult.ok();
    }


    @ApiOperation(value = "热更新配置", notes = "热更新配置")
    @PostMapping("/v1/app-patch/config")
    @EditLayout(paddingMappingMethod = "appPatchConfigGet")
    @PreAuthorize("hasRole('app-patch-config')")
    @AdminMenu(menuName = "热更新配置", order = 50)
    @AOLog
    public JSONResult appPatchConfigSet(@RequestBody AppPatchConfig param) {
        patchConfigService.set(param);
        return JSONResult.ok();
    }

    @ApiOperation(value = "获取热更新配置", notes = "获取热更新配置")
    @GetMapping("/v1/app-patch/config")
    @PreAuthorize("hasRole('app-patch-config')")
    @AOLog
    public JSONResult<AppPatchConfig> appPatchConfigGet() {
        return JSONResult.ok(patchConfigService.get());
    }

}
*/