package com.hzs.system.config.controller.manage;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.hzs.common.core.annotation.Log;
import com.hzs.common.core.enums.EDelFlag;
import com.hzs.common.core.enums.EOperationBusiness;
import com.hzs.common.core.enums.EOperationMethod;
import com.hzs.common.core.enums.EOperationModule;
import com.hzs.common.core.utils.DateUtils;
import com.hzs.common.core.web.controller.BaseController;
import com.hzs.common.core.web.domain.AjaxResult;
import com.hzs.common.core.web.page.TableDataInfo;
import com.hzs.common.domain.system.config.BdMakerSpaceBonus;
import com.hzs.common.security.utils.SecurityUtils;
import com.hzs.system.config.service.IBdMakerSpaceBonusService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Date;
import java.util.List;

/**
 * 创客空间奖金配置 前端控制器
 */
@RestController
@RequestMapping("/manage/bd-maker-space-bonus")
public class BdMakerSpaceBonusController extends BaseController {

    @Autowired
    private IBdMakerSpaceBonusService iBdMakerSpaceBonusService;

    /**
     * @description: 查询列表
     * @author: zhang jing
     * @date: 2023/7/31 16:03
     * @param: []
     * @return: com.hzs.common.core.web.page.TableDataInfo
     **/
    @Log(module = EOperationModule.BONUS_CONFIG, business = EOperationBusiness.MAKER_SPACE_BONUS, method = EOperationMethod.SELECT)
    @GetMapping("/list")
    public TableDataInfo list() {
        startPage();
        QueryWrapper<BdMakerSpaceBonus> queryWrapper = new QueryWrapper();
        queryWrapper.eq("PK_COUNTRY", SecurityUtils.getPkCountry());
        queryWrapper.orderByAsc("PK_ID");
        List<BdMakerSpaceBonus> list = iBdMakerSpaceBonusService.list(queryWrapper);
        return getDataTable(list);
    }

    /**
     * @description: 新增
     * @author: zhang jing
     * @date: 2023/7/31 16:04
     * @param: [bdMakerSpaceBonus]
     * @return: com.hzs.common.core.web.domain.AjaxResult
     **/
    @Log(module = EOperationModule.BONUS_CONFIG, business = EOperationBusiness.MAKER_SPACE_BONUS, method = EOperationMethod.INSERT)
    @PostMapping("/save")
    public AjaxResult save(@RequestBody BdMakerSpaceBonus bdMakerSpaceBonus) {
        Date date = DateUtils.currentDate();
        bdMakerSpaceBonus.setPkCountry(SecurityUtils.getPkCountry());
        bdMakerSpaceBonus.setPkCreator(SecurityUtils.getUserId());
        bdMakerSpaceBonus.setCreationTime(date);
        return AjaxResult.success(iBdMakerSpaceBonusService.save(bdMakerSpaceBonus));
    }

    /**
     * @description:修改
     * @author: zhang jing
     * @date: 2023/7/31 16:04
     * @param: [bdMakerSpaceBonus]
     * @return: com.hzs.common.core.web.domain.AjaxResult
     **/
    @Log(module = EOperationModule.BONUS_CONFIG, business = EOperationBusiness.MAKER_SPACE_BONUS, method = EOperationMethod.UPDATE)
    @PostMapping("/update")
    public AjaxResult update(@RequestBody BdMakerSpaceBonus bdMakerSpaceBonus) {
        Date date = DateUtils.currentDate();
        bdMakerSpaceBonus.setPkModified(SecurityUtils.getUserId());
        bdMakerSpaceBonus.setModifiedTime(date);
        return AjaxResult.success(iBdMakerSpaceBonusService.updateById(bdMakerSpaceBonus));
    }

    /**
     * @description: 查询单个
     * @author: zhang jing
     * @date: 2023/7/31 16:04
     * @param: [pkId]
     * @return: com.hzs.common.core.web.domain.AjaxResult
     **/
    @Log(module = EOperationModule.BONUS_CONFIG, business = EOperationBusiness.MAKER_SPACE_BONUS, method = EOperationMethod.SELECT)
    @GetMapping("/getOne/{pkId}")
    public AjaxResult getOne(@PathVariable Long pkId) {
        return AjaxResult.success(iBdMakerSpaceBonusService.getById(pkId));
    }

    /**
     * @description: 删除
     * @author: zhang jing
     * @date: 2023/7/31 16:04
     * @param: [pkId]
     * @return: com.hzs.common.core.web.domain.AjaxResult
     **/
    @Log(module = EOperationModule.BONUS_CONFIG, business = EOperationBusiness.MAKER_SPACE_BONUS, method = EOperationMethod.DELETE)
    @DeleteMapping("/{pkId}")
    public AjaxResult delete(@PathVariable Long pkId) {
        UpdateWrapper<BdMakerSpaceBonus> updateWrapper = new UpdateWrapper<>();
        updateWrapper.eq("PK_ID", pkId);
        updateWrapper.set("DEL_FLAG", EDelFlag.DELETE.getValue());
        updateWrapper.set("PK_MODIFIED", SecurityUtils.getUserId());
        updateWrapper.set("MODIFIED_TIME", new Date());
        return toAjax(iBdMakerSpaceBonusService.update(updateWrapper));
    }

}
