/*
 *    Copyright (c) 2018-2025, hnqz All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are met:
 *
 * Redistributions of source code must retain the above copyright notice,
 * this list of conditions and the following disclaimer.
 * Redistributions in binary form must reproduce the above copyright
 * notice, this list of conditions and the following disclaimer in the
 * documentation and/or other materials provided with the distribution.
 * Neither the name of the pig4cloud.com developer nor the names of its
 * contributors may be used to endorse or promote products derived from
 * this software without specific prior written permission.
 * Author: hnqz
 */

package com.qunzhixinxi.hnqz.admin.controller;

import com.alibaba.csp.sentinel.util.StringUtil;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.qunzhixinxi.hnqz.admin.entity.WmScorePackage;
import com.qunzhixinxi.hnqz.admin.entity.WmScoreTaskType;
import com.qunzhixinxi.hnqz.admin.service.WmScoreTaskTypeService;
import com.qunzhixinxi.hnqz.common.core.util.R;
import com.qunzhixinxi.hnqz.common.log.annotation.SysLog;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import org.apache.commons.lang.StringUtils;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;


/**
 * 积分包任务类型表
 *
 * @author pigx code generator
 * @date 2021-01-06 17:30:30
 */
@RestController
@AllArgsConstructor
@RequestMapping("/wmscoretasktype" )
@Api(value = "wmscoretasktype", tags = "积分包任务类型表管理")
public class WmScoreTaskTypeController {

    private final WmScoreTaskTypeService wmScoreTaskTypeService;

    /**
     * 分页查询
     * @param page 分页对象
     * @param wmScoreTaskType 积分包任务类型表
     * @return
     */
    @ApiOperation(value = "分页查询", notes = "分页查询")
    @GetMapping("/page" )
    @PreAuthorize("@pms.hasPermission('admin_wmscoretasktype_view')" )
    public R getWmScoreTaskTypePage(Page page, WmScoreTaskType wmScoreTaskType) {
        return R.ok(wmScoreTaskTypeService.page(page, Wrappers.query(wmScoreTaskType)));
    }


    /**
     * 通过id查询积分包任务类型表
     * @param id id
     * @return R
     */
    @ApiOperation(value = "通过id查询", notes = "通过id查询")
    @GetMapping("/{id}" )
    @PreAuthorize("@pms.hasPermission('admin_wmscoretasktype_view')" )
    public R getById(@PathVariable("id" ) Long id) {
        return R.ok(wmScoreTaskTypeService.getById(id));
    }

    /**
     * 新增积分包任务类型表
     * @param wmScoreTaskType 积分包任务类型表
     * @return R
     */
    @ApiOperation(value = "新增积分包任务类型表", notes = "新增积分包任务类型表")
    @SysLog("新增积分包任务类型表" )
    @PostMapping
    @PreAuthorize("@pms.hasPermission('admin_wmscoretasktype_add')" )
    public R save(@RequestBody WmScoreTaskType wmScoreTaskType) {
        return R.ok(wmScoreTaskTypeService.save(wmScoreTaskType));
    }

    /**
     * 修改积分包任务类型表
     * @param wmScoreTaskType 积分包任务类型表
     * @return R
     */
    @ApiOperation(value = "修改积分包任务类型表", notes = "修改积分包任务类型表")
    @SysLog("修改积分包任务类型表" )
    @PutMapping
    @PreAuthorize("@pms.hasPermission('admin_wmscoretasktype_edit')" )
    public R updateById(@RequestBody WmScoreTaskType wmScoreTaskType) {
        return R.ok(wmScoreTaskTypeService.updateById(wmScoreTaskType));
    }

    /**
     * 通过id删除积分包任务类型表
     * @param id id
     * @return R
     */
    @ApiOperation(value = "通过id删除积分包任务类型表", notes = "通过id删除积分包任务类型表")
    @SysLog("通过id删除积分包任务类型表" )
    @DeleteMapping("/{id}" )
    @PreAuthorize("@pms.hasPermission('admin_wmscoretasktype_del')" )
    public R removeById(@PathVariable Long id) {
        return R.ok(wmScoreTaskTypeService.removeById(id));
    }


	/**
	 * 通过关联积分包id查询积分包任务类型表
	 * @param wmScoreTaskType
	 * @return R
	 */
	@ApiOperation(value = "通过关联积分包id查询积分包任务类型表", notes = "通过关联积分包id查询积分包任务类型表")
	@GetMapping("/getListByScoreId" )
	public R getListByScoreId(WmScoreTaskType wmScoreTaskType) {
		if(StringUtil.isEmpty(wmScoreTaskType.getScoreId())){
			return R.failed("关联积分包id不能为空");
		}


		return R.ok(wmScoreTaskTypeService.getListByScoreId(wmScoreTaskType));
	}

	/**
	 * 通过积分包id查询积分包有效任务类型
	 * @param wmScorePackage
	 * @return R
	 */
	@ApiOperation(value = "通过积分包id查询积分包有效任务类型", notes = "通过积分包id查询积分包有效任务类型")
	@GetMapping("/selectByScoreId")
	public R selectByScoreId(WmScorePackage wmScorePackage) {
		return R.ok(wmScoreTaskTypeService.selectByScoreId(wmScorePackage));
	}

	/**
	 * 通过积分包id查询积分包有效任务类型
	 * @param wmScorePackage
	 * @return R
	 */
	@ApiOperation(value = "通过积分包id查询积分包有效任务类型", notes = "通过积分包id查询积分包有效任务类型")
	@GetMapping("/selectByScorePackageId")
	public R selectByScorePackageId(WmScorePackage wmScorePackage) {
		if(StringUtils.isEmpty(wmScorePackage.getId())){
			return R.failed("参数异常");
		}
		return wmScoreTaskTypeService.selectByScorePackageId(wmScorePackage);
	}
}
