package cn.ey.biz.module.system.controller.engagement.scope;

import cn.ey.biz.common.pojo.R;
import cn.ey.biz.module.system.controller.engagement.scope.vo.OpprScopeConfigReqVO;
import cn.ey.biz.module.system.controller.engagement.scope.vo.OpprScopeConfigRespVO;
import cn.ey.biz.module.system.controller.engagement.scope.vo.OpprScopeConfigUpdateReqVO;
import cn.ey.biz.module.system.convert.engagement.scope.OpprScopeConfigConvert;
import cn.ey.biz.module.system.dal.dataobject.engagement.scope.SystemOpprScopeConfigDO;
import cn.ey.biz.module.system.service.engagement.scope.OpprScopeConfigService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import java.util.List;
import static cn.ey.biz.common.pojo.R.success;

@Api(tags = "商机公开范围")
@RestController
@RequestMapping("/system/opportunity/scope/config")
public class OpprScopeConfigController {

    @Resource
    private OpprScopeConfigService opprScopeConfigService;

    @GetMapping("/list")
    @ApiOperation("查询商机公开范围")
    @PreAuthorize("@ss.hasPermission('system:opportunity-scope:query')")
    public R<List<OpprScopeConfigRespVO>> getOpprScopeList(OpprScopeConfigReqVO reqVO) {
        List<SystemOpprScopeConfigDO> taskRule =opprScopeConfigService. getOpprScopeConfigList(reqVO);
        return success(OpprScopeConfigConvert.INSTANCE.doConvertListVo(taskRule));
    }

    @PostMapping("/update")
    @ApiOperation("修改商机公开范围")
    @PreAuthorize("@ss.hasPermission('system:opportunity-scope:update')")
    public R<Boolean> updateOpprScopeList(@RequestBody List<OpprScopeConfigUpdateReqVO> reqListVO) {
        opprScopeConfigService. updateOpprScopeList(reqListVO);
        return success(true);
    }

}
