/*
 *    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.baomidou.mybatisplus.core.metadata.OrderItem;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.qunzhixinxi.hnqz.common.core.util.R;
import com.qunzhixinxi.hnqz.common.log.annotation.SysLog;
import com.qunzhixinxi.hnqz.admin.entity.WmTaskContentConfig;
import com.qunzhixinxi.hnqz.admin.service.WmTaskContentConfigService;
import org.springframework.security.access.prepost.PreAuthorize;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDateTime;


/**
 * 任务内容字段配置
 *
 * @author gaoyanng
 * @date 2020-06-25 23:35:25
 */
@RestController
@AllArgsConstructor
@RequestMapping("/wmtaskcontentconfig" )
@Api(value = "wmtaskcontentconfig", tags = "任务内容字段配置管理")
public class WmTaskContentConfigController {

    private final  WmTaskContentConfigService wmTaskContentConfigService;

    /**
     * 分页查询
     * @param page 分页对象
     * @param wmTaskContentConfig 任务内容字段配置
     * @return
     */
    @ApiOperation(value = "分页查询", notes = "分页查询")
    @GetMapping("/page" )
    //@PreAuthorize("@pms.hasPermission('admin_wmtaskcontentconfig_view')" )
    public R getWmTaskContentConfigPage(Page page, WmTaskContentConfig wmTaskContentConfig) {
		OrderItem orderItem=new OrderItem();
		orderItem.setColumn("create_time");
		orderItem.setAsc(false);
		page.addOrder(orderItem);

        return R.ok(wmTaskContentConfigService.page(page, Wrappers.query(wmTaskContentConfig)));
    }


    /**
     * 通过id查询任务内容字段配置
     * @param id id
     * @return R
     */
    @ApiOperation(value = "通过id查询", notes = "通过id查询")
    @GetMapping("/{id}" )
	//@PreAuthorize("@pms.hasPermission('admin_wmtaskcontentconfig_view')" )
    public R getById(@PathVariable("id" ) Integer id) {
        return R.ok(wmTaskContentConfigService.getById(id));
    }

    /**
     * 新增任务内容字段配置
     * @param wmTaskContentConfig 任务内容字段配置
     * @return R
     */
    @ApiOperation(value = "新增任务内容字段配置", notes = "新增任务内容字段配置")
    @SysLog("新增任务内容字段配置" )
    @PostMapping
	//@PreAuthorize("@pms.hasPermission('admin_wmtaskcontentconfig_add')" )
    public R save(@RequestBody WmTaskContentConfig wmTaskContentConfig) {
		wmTaskContentConfig.setCreateTime(LocalDateTime.now());
        return R.ok(wmTaskContentConfigService.save(wmTaskContentConfig));
    }

    /**
     * 修改任务内容字段配置
     * @param wmTaskContentConfig 任务内容字段配置
     * @return R
     */
    @ApiOperation(value = "修改任务内容字段配置", notes = "修改任务内容字段配置")
    @SysLog("修改任务内容字段配置" )
    @PutMapping
	//@PreAuthorize("@pms.hasPermission('admin_wmtaskcontentconfig_edit')" )
    public R updateById(@RequestBody WmTaskContentConfig wmTaskContentConfig) {
        return R.ok(wmTaskContentConfigService.updateById(wmTaskContentConfig));
    }

    /**
     * 通过id删除任务内容字段配置
     * @param id id
     * @return R
     */
    @ApiOperation(value = "通过id删除任务内容字段配置", notes = "通过id删除任务内容字段配置")
    @SysLog("通过id删除任务内容字段配置" )
    @DeleteMapping("/{id}" )
	//@PreAuthorize("@pms.hasPermission('admin_wmtaskcontentconfig_del')" )
    public R removeById(@PathVariable Integer id) {
        return R.ok(wmTaskContentConfigService.removeById(id));
    }

}
