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

import cn.hutool.core.bean.BeanUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.hzs.common.core.annotation.Log;
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.BdSpecialCurrency;
import com.hzs.common.domain.system.config.ext.BdSpecialCurrencyExt;
import com.hzs.common.security.utils.SecurityUtils;
import com.hzs.system.config.service.IBdSpecialCurrencyService;
import com.hzs.system.config.param.SpecialCurrencyParam;
import com.hzs.system.config.vo.SpecialCurrencyVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 特殊消费配置 前端控制器
 *
 * @author hzs
 * @since 2023-07-18
 */
@RestController
@RequestMapping("/manage/special-currency")
public class BdSpecialCurrencyController extends BaseController {

    @Autowired
    private IBdSpecialCurrencyService specialCurrencyService;

    /*
     * @description: 新增特殊消费配置
     * @author: sui q
     * @date: 2023/7/18 20:35
     * @param: null null
     **/
    @Log(module = EOperationModule.SPECIAL_CURRENCY_DETAIL, business = EOperationBusiness.SPECIAL_CURRENCY_DETAIL, method = EOperationMethod.SELECT)
    @GetMapping("/list")
    public TableDataInfo list(SpecialCurrencyParam specialCurrencyParam) {
        specialCurrencyParam.setPkCountry(SecurityUtils.getPkCountry());
        List<BdSpecialCurrencyExt> specialCurrencyExtList = specialCurrencyService.querySpecialCurrencyList(specialCurrencyParam);
        List<SpecialCurrencyVO> specialCurrencyVOList = BeanUtil.copyToList(specialCurrencyExtList, SpecialCurrencyVO.class);
        return getDataTable(specialCurrencyVOList);
    }

    /*
     * @description: 保存特殊消费配置
     * @author: sui q
     * @date: 2023/7/18 20:37
     * @param: null null
     **/
    @Log(module = EOperationModule.SPECIAL_CURRENCY_DETAIL, business = EOperationBusiness.SPECIAL_CURRENCY_DETAIL, method = EOperationMethod.INSERT)
    @PostMapping("/save")
    public AjaxResult save(@RequestBody SpecialCurrencyParam specialCurrencyParam) {
        specialCurrencyParam.setPkCountry(SecurityUtils.getPkCountry());
        specialCurrencyParam.setUserId(SecurityUtils.getUserId());
        specialCurrencyParam.setCurrentTime(DateUtils.currentDateTime());
        return AjaxResult.success(specialCurrencyService.saveSpecialCurrency(specialCurrencyParam));
    }

    /*
     * @description: 删除特殊消费配置
     * @author: sui q
     * @date: 2023/7/18 20:37
     * @param: null null
     **/
    @Log(module = EOperationModule.SPECIAL_CURRENCY_DETAIL, business = EOperationBusiness.SPECIAL_CURRENCY_DETAIL, method = EOperationMethod.DELETE)
    @PostMapping("/delete")
    public AjaxResult delete(@RequestBody SpecialCurrencyParam specialCurrencyParam) {
        specialCurrencyParam.setPkCountry(SecurityUtils.getPkCountry());
        specialCurrencyParam.setUserId(SecurityUtils.getUserId());
        specialCurrencyParam.setCurrentTime(DateUtils.currentDateTime());
        return AjaxResult.success(specialCurrencyService.deleteSpecialCurrency(specialCurrencyParam));
    }

    /*
     * @description: 新增特殊消费配置
     * @author: sui q
     * @date: 2023/7/18 20:35
     * @param: null null
     **/
    @Log(module = EOperationModule.SPECIAL_CURRENCY_DETAIL, business = EOperationBusiness.SPECIAL_CURRENCY_DETAIL, method = EOperationMethod.SELECT)
    @GetMapping("/findAll")
    public AjaxResult findAll() {
        QueryWrapper<BdSpecialCurrency> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("PK_COUNTRY", SecurityUtils.getPkCountry());
        return AjaxResult.success(specialCurrencyService.list(queryWrapper));
    }

}
