package com.fs.his.controller;

import java.util.List;

import com.fs.common.utils.ParseUtils;
import com.fs.his.param.FsStoreAuditParam;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.fs.common.annotation.Log;
import com.fs.common.core.controller.BaseController;
import com.fs.common.core.domain.AjaxResult;
import com.fs.common.enums.BusinessType;
import com.fs.his.domain.FsStore;
import com.fs.his.service.IFsStoreService;
import com.fs.common.utils.poi.ExcelUtil;
import com.fs.common.core.page.TableDataInfo;

/**
 * 店铺管理Controller
 *
 * @author fs
 * @date 2023-06-15
 */
@RestController
@RequestMapping("/his/store")
public class FsStoreController extends BaseController
{
    @Autowired
    private IFsStoreService fsStoreService;

    /**
     * 查询店铺管理列表
     */
    @PreAuthorize("@ss.hasPermi('his:store:list')")
    @GetMapping("/list")
    public TableDataInfo list(FsStore fsStore)
    {
        startPage();
        List<FsStore> list = fsStoreService.selectFsStoreList(fsStore);
        for (FsStore store : list) {
            store.setPhone(ParseUtils.parsePhone(store.getPhone()));
        }
        return getDataTable(list);
    }

    /**
     * 导出店铺管理列表
     */
    @PreAuthorize("@ss.hasPermi('his:store:export')")
    @Log(title = "店铺管理", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(FsStore fsStore)
    {
        List<FsStore> list = fsStoreService.selectFsStoreList(fsStore);
        for (FsStore store : list) {
            store.setPhone(ParseUtils.parsePhone(store.getPhone()));
        }
        ExcelUtil<FsStore> util = new ExcelUtil<FsStore>(FsStore.class);
        return util.exportExcel(list, "店铺管理数据");
    }

    /**
     * 获取店铺管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('his:store:query')")
    @GetMapping(value = "/{storeId}")
    public AjaxResult getInfo(@PathVariable("storeId") Long storeId)
    {
        FsStore fsStore = fsStoreService.selectFsStoreByStoreId(storeId);
        fsStore.setPhone(ParseUtils.parsePhone(fsStore.getPhone()));
        return AjaxResult.success(fsStore);
    }

    /**
     * 新增店铺管理
     */
    @PreAuthorize("@ss.hasPermi('his:store:add')")
    @Log(title = "店铺管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody FsStore fsStore)
    {
        return toAjax(fsStoreService.insertFsStore(fsStore));
    }

    /**
     * 修改店铺管理
     */
    @PreAuthorize("@ss.hasPermi('his:store:edit')")
    @Log(title = "店铺管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody FsStore fsStore)
    {

        if (fsStore.getPhone()!=null&&fsStore.getPhone().contains("*")){
            fsStore.setPhone(null);
        }
        return toAjax(fsStoreService.updateFsStore(fsStore));
    }

    /**
     * 删除店铺管理
     */
    @PreAuthorize("@ss.hasPermi('his:store:remove')")
    @Log(title = "店铺管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{storeIds}")
    public AjaxResult remove(@PathVariable Long[] storeIds)
    {
        return toAjax(fsStoreService.deleteFsStoreByStoreIds(storeIds));
    }

    /**
     * 店铺审核
     */
    @PreAuthorize("@ss.hasPermi('his:store:audit')")
    @Log(title = "店铺管理", businessType = BusinessType.UPDATE)
    @PutMapping("/audit")
    public AjaxResult audit(@RequestBody FsStoreAuditParam fsStore)
    {
        return toAjax(fsStoreService.updateFsStoreAudit(fsStore));
    }


}
