RightsOperationController.java 2.4 KB
package com.topdraw.business.process.rest;

import com.topdraw.business.basicdata.rights.history.domain.RightsHistory;
import com.topdraw.business.basicdata.rights.history.service.RightsHistoryService;
import com.topdraw.business.basicdata.rights.history.service.dto.RightsHistoryQueryCriteria;
import com.topdraw.business.basicdata.rights.history.service.dto.RightsHistoryQueryType;
import com.topdraw.business.process.service.RightsOperationService;
import com.topdraw.common.ResultInfo;
import com.topdraw.annotation.Log;
import com.topdraw.business.basicdata.rights.domain.Rights;
import com.topdraw.business.basicdata.rights.service.RightsService;
import com.topdraw.util.TimestampUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Pageable;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import io.swagger.annotations.*;

import java.util.Arrays;
import java.util.List;


/**
 * @author XiangHan
 * @date 2021-10-22
 */
@Api(tags = "Rights管理")
@RestController
@RequestMapping("/api/RightsOperation")
public class RightsOperationController {

    @Autowired
    private RightsOperationService rightsOperationService;
    @Autowired
    private RightsHistoryService rightsHistoryService;
    @Autowired
    private RightsService rightsService;

    @GetMapping
    @ApiOperation("查询RightsHistory")
    public ResultInfo queryRightsHistory(RightsHistoryQueryCriteria criteria, Pageable pageable) {
        RightsHistoryQueryType queryType = criteria.getQueryType();
        if (queryType == RightsHistoryQueryType.AVAILABLE_ONLY) {
            criteria.setExpireTime(TimestampUtil.now());
        }
        return ResultInfo.successPage(rightsHistoryService.queryAll(criteria,pageable));
    }

    @GetMapping(value = "/findRightsHistoryById/{id}")
    @ApiOperation("查询RightsHistory")
    public ResultInfo findRightsHistoryById(@PathVariable Long id) {
        return ResultInfo.success(rightsHistoryService.findById(id));
    }


    @PostMapping(value = "/grantRightsByManual")
    @ApiOperation("查询RightsHistory")
    public ResultInfo grantRightsByManual(@Validated @RequestBody RightsHistory rightsHistory) {
        List<RightsHistory> rightsHistories = Arrays.asList(rightsHistory);
        this.rightsOperationService.grantRightsByManual(rightsHistories);
        return ResultInfo.success();
    }


}