package com.fs.hisStore;

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.domain.R;
import com.fs.common.core.page.TableDataInfo;
import com.fs.common.enums.BusinessType;
import com.fs.common.utils.ParseUtils;
import com.fs.common.utils.poi.ExcelUtil;
import com.fs.his.domain.FsStore;
import com.fs.his.param.FsStoreAuditParam;
import com.fs.his.service.IFsStoreService;
import com.fs.hisStore.domain.FsStoreScrm;
import com.fs.hisStore.service.IFsStoreScrmService;
import com.fs.hisStore.vo.FsStoreScrmVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

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

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

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

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

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

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

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

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

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

    @GetMapping("/storeList")
    public R storeList(){
        List<FsStoreScrmVO> list = fsStoreService.selectAllStore();
        return R.ok().put("data",list);
    }


}
