package com.hys.app.controller.erp.use;

import cn.hutool.core.bean.BeanUtil;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.hys.app.framework.database.BaseQueryParam;
import com.hys.app.framework.database.WebPage;
import com.hys.app.model.erp.dos.GoodsDO;
import com.hys.app.model.erp.dos.PayTypeDO;
import com.hys.app.model.erp.dto.GoodsDTO;
import com.hys.app.model.erp.dto.GoodsQueryParams;
import com.hys.app.model.erp.dto.GoodsSortDto;
import com.hys.app.model.erp.dto.GoodsUpdateDTO;
import com.hys.app.model.erp.vo.GoodsVO;
import com.hys.app.model.erp.vo.ProductStockVO;
import com.hys.app.model.support.LogClient;
import com.hys.app.model.support.validator.annotation.Log;
import com.hys.app.service.erp.GoodsManager;
import com.hys.app.service.erp.PayTypeManager;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

/**
 * 商品档案API
 *
 * @author 张崧
 * 2023-12-26 15:56:58
 */
@RestController
@RequestMapping("/admin/erp/payType")
@Api(tags = "支付方式")
@Validated
public class PayTypeController {

    @Autowired
    private PayTypeManager payTypeManager;

    @ApiOperation(value = "分页列表")
    @GetMapping
    public List<PayTypeDO> list() {
        return payTypeManager.list();
    }

    @ApiOperation(value = "添加")
    @PostMapping
    @Log(client = LogClient.admin, detail = "新增支付方式")
    public void add(@RequestBody @Valid PayTypeDO payTypeDO) {
        payTypeManager.save(payTypeDO);
    }

    @ApiOperation(value = "修改")
    @PostMapping("/update/{id}")
    @Log(client = LogClient.admin, detail = "修改id为[${id}]的支付方式")
    public void update(@RequestBody @Valid PayTypeDO payTypeDO,@PathVariable Long id) {
        PayTypeDO byId = payTypeManager.getById(id);
        BeanUtil.copyProperties(payTypeDO,byId);
        payTypeManager.updateById(byId);
    }

    @ApiOperation(value = "删除")
    @PostMapping("/delete/{id}")
    @Log(client = LogClient.admin, detail = "删除")
    public void delete(@PathVariable Long id) {
        PayTypeDO byId = payTypeManager.getById(id);
        byId.setDeleted(false);
        payTypeManager.updateById(byId);
    }

    @ApiOperation(value = "详情")
    @GetMapping("/{id}")
    public PayTypeDO getById(@PathVariable Long id) {
        return payTypeManager.getById(id);
    }

}

