package com.fs.store.controller.store;

import com.fs.common.utils.StringUtils;
import com.fs.his.param.FsStoreAfterSalesParam;
import com.fs.his.vo.FsStoreAfterSalesExcelVO;
import com.fs.his.vo.FsStoreAfterSalesListVO;
import com.fs.store.utils.UserUtil;
import com.fs.common.annotation.Log;
import com.fs.common.core.controller.BaseController;
import com.fs.common.core.domain.AjaxResult;
import com.fs.common.core.page.TableDataInfo;
import com.fs.common.enums.BusinessType;
import com.fs.common.utils.poi.ExcelUtil;
import com.fs.his.domain.FsStoreAfterSales;
import com.fs.his.service.IFsStoreAfterSalesService;
import com.fs.his.vo.FsStoreAfterSalesVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Lazy;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 售后记录Controller
 *
 * @author fs
 * @date 2023-06-13
 */
@RestController
@RequestMapping("/store/storeAfterSales")
public class FsStoreAfterSalesController extends BaseController
{
    @Lazy
    @Autowired
    private IFsStoreAfterSalesService fsStoreAfterSalesService;

    /**
     * 查询售后记录列表
     */

    @GetMapping("/list")
    public TableDataInfo list(FsStoreAfterSalesParam fsStoreAfterSales)
    {
        startPage();
        if(!StringUtils.isEmpty(fsStoreAfterSales.getCreateTimeRange())){
            fsStoreAfterSales.setCreateTimeList(fsStoreAfterSales.getCreateTimeRange().split("--"));
        }
        List<FsStoreAfterSalesListVO> list = fsStoreAfterSalesService.selectFsStoreAfterSalesListVO(fsStoreAfterSales);
        return getDataTable(list);
    }

    /**
     * 导出售后记录列表
     */

    @Log(title = "售后记录", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(FsStoreAfterSalesParam fsStoreAfterSales)
    {
        if(!StringUtils.isEmpty(fsStoreAfterSales.getCreateTimeRange())){
            fsStoreAfterSales.setCreateTimeList(fsStoreAfterSales.getCreateTimeRange().split("--"));
        }
        List<FsStoreAfterSalesExcelVO> list = fsStoreAfterSalesService.selectFsStoreAfterSalesExcelListVO(fsStoreAfterSales);
        ExcelUtil<FsStoreAfterSalesExcelVO> util = new ExcelUtil<>(FsStoreAfterSalesExcelVO.class);
        return util.exportExcel(list, "售后记录数据");
    }


    /**
     * 获取售后记录详细信息
     */

    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(fsStoreAfterSalesService.selectFsStoreAfterSalesVOById(id));
    }

    /**
     * 新增售后记录
     */

    @Log(title = "售后记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody FsStoreAfterSales fsStoreAfterSales)
    {
        return toAjax(fsStoreAfterSalesService.insertFsStoreAfterSales(fsStoreAfterSales));
    }

    /**
     * 修改售后记录
     */

    @Log(title = "售后记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody FsStoreAfterSales fsStoreAfterSales)
    {

        return toAjax(fsStoreAfterSalesService.updateFsStoreAfterSales(fsStoreAfterSales));
    }

    /**
     * 删除售后记录
     */

    @Log(title = "售后记录", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(fsStoreAfterSalesService.deleteFsStoreAfterSalesByIds(ids));
    }

    /**
     * 获取售后记录详细信息
     */

    @GetMapping(value = "itemList/{id}")
    public AjaxResult getItemList(@PathVariable("id") Long id)
    {

        return AjaxResult.success(fsStoreAfterSalesService.selectFsStoreAfterSalesItemById(id));
    }

    /**
     * 获取售后记录详细信息
     */

    @GetMapping(value = "logList/{id}")
    public AjaxResult getLogList(@PathVariable("id") Long id)
    {

        return AjaxResult.success(fsStoreAfterSalesService.selectFsStoreAfterSalesLogById(id));
    }


    /**
     * 获取售后记录详细信息
     */

    @GetMapping(value = "codeId/{id}")
    public AjaxResult getcodeId(@PathVariable("id") Long id)
    {

        Long s = fsStoreAfterSalesService.selectFsOrderIdByCode(id);
        return AjaxResult.success(s);
    }


    /**
     * 修改售后记录
     */


    @PutMapping("/auditing")
    public AjaxResult auditing(@RequestBody FsStoreAfterSales fsStoreAfterSales)
    {
        return toAjax(fsStoreAfterSalesService.auditing(fsStoreAfterSales));
    }
    @PutMapping("/depotAuditing")
    public AjaxResult depotAuditing(@RequestBody FsStoreAfterSales fsStoreAfterSales)
    {
        return toAjax(fsStoreAfterSalesService.depotAuditing(fsStoreAfterSales));
    }

    /**
     * 审核
     */

    @PutMapping("/noAuditing")
    public AjaxResult noAuditing(@RequestBody FsStoreAfterSales fsStoreAfterSales)
    {
        return toAjax(fsStoreAfterSalesService.noAuditing(fsStoreAfterSales));
    }

    /**
     * 财务审核并退款
     */

    @PutMapping("/tuiMoney")
    public AjaxResult tuiMoney(@RequestBody FsStoreAfterSales fsStoreAfterSales)
    {
        return toAjax(fsStoreAfterSalesService.refundMoney(fsStoreAfterSales));
    }



}
