package org.jeecg.modules.system.app.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.jeecg.common.api.vo.Result;
import org.jeecg.common.aspect.annotation.AutoLog;
import org.jeecg.common.system.base.controller.JeecgController;
import org.jeecg.modules.app.form.QueryByOrgCodeForm;
import org.jeecg.modules.jmreport.common.annotation.RequiresPermissions;
import org.jeecg.modules.system.app.dto.*;
import org.jeecg.modules.system.app.entity.AppSite;
import org.jeecg.modules.system.app.entity.AppSitePlace;
import org.jeecg.modules.system.app.service.IAppSitePlaceService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Description: 商户场所表
 * @Author: jeecg-boot
 * @Date: 2025-07-09
 * @Version: V1.0
 */
@Tag(name = "商户场所表")
@RestController
@RequestMapping("/app/appSitePlace")
@Slf4j
public class AppSitePlaceController extends JeecgController<AppSitePlace, IAppSitePlaceService> {
    @Autowired
    private IAppSitePlaceService appSitePlaceService;

    /**
     * 分页列表查询
     *
     * @param appSitePlace
     * @return
     */
    //@AutoLog(value = "商户场所表-分页列表查询")
    @Operation(summary = "商户场所学校、体育馆包场-分页列表查询")
    @GetMapping(value = "/list")
    public Result<IPage<AppSitePlaceCuDTO>> queryPageList(AppSitePlacePageDTO appSitePlace) {
        return Result.OK(appSitePlaceService.querySchoolPage(appSitePlace));
    }

    /**
     * 分页列表查询
     *
     * @param appSitePlace
     * @return
     */
    //@AutoLog(value = "商户场所表-分页列表查询")
    @Operation(summary = "商户场所无固定场-分页列表查询")
    @GetMapping(value = "/queryUnfixedPageList")
    public Result<IPage<AppSitePlaceUnfixedDTO>> queryUnfixedPageList(AppSitePlaceUnfixedPageDTO appSitePlace) {
        return Result.OK(appSitePlaceService.queryUnfixedPage(appSitePlace));
    }

    /**
     * 添加
     *
     * @param appSitePlace
     * @return
     */
    @AutoLog(value = "商户场所学校-添加")
    @Operation(summary = "商户场所学校-添加")
//	@RequiresPermissions("org.jeecg.modules.system.app:nm_site_place:add")
    @PostMapping(value = "/add")
    public Result<String> add(@RequestBody AppSitePlaceSchoolDTO appSitePlace) {
        Boolean b = appSitePlaceService.saveSchool(appSitePlace);
        return b ? Result.OK("添加成功！") : Result.error("添加失败！");
    }

    /**
     * 添加
     *
     * @param unfixedDTO
     * @return
     */
    @AutoLog(value = "商户无固定场所-添加")
    @Operation(summary = "商户无固定场所-添加")
	@RequiresPermissions("app:appSitePlace:addUnfixed")
    @PostMapping(value = "/addUnfixed")
    public Result<String> addUnfixed(@RequestBody
                                     AppSitePlaceUnfixedDTO unfixedDTO) {
        Boolean b = appSitePlaceService.addUnfixed(unfixedDTO);
        return b ? Result.OK("添加成功！") : Result.error("添加失败！");
    }

//    @AutoLog(value = "商户包场-添加")
//    @Operation(summary = "商户包场-添加")
//    @RequiresPermissions("org.jeecg.modules.system.app:nm_site_place:add")
//    @PostMapping(value = "/savePack")
//    public Result<String> savePack(@RequestBody AppSitePlaceDTO unfixedDTO) {
//        Boolean b = appSitePlaceService.savePack(unfixedDTO);
//        return b ? Result.OK("添加成功！") : Result.error("添加失败！");
//    }
    /**
     * 添加
     *
     * @param appSitePlaceParkDTO
     * @return
     */
    @AutoLog(value = "商户包场-添加")
    @Operation(summary = "商户包场-添加")
    @RequiresPermissions("org.jeecg.modules.system.app:nm_site_place:add")
    @PostMapping(value = "/savePack")
    public Result<String> savePack(@RequestBody AppSitePlaceParkDTO appSitePlaceParkDTO) {
        Boolean b = appSitePlaceService.savePack(appSitePlaceParkDTO);
        return b ? Result.OK("添加成功！") : Result.error("添加失败！");
    }

    /**
     * 编辑
     *
     * @param appSitePlace
     * @return
     */
    @AutoLog(value = "商户场所学校-编辑")
    @Operation(summary = "商户场所学校-编辑")
//	@RequiresPermissions("org.jeecg.modules.system.app:nm_site_place:edit")
    @RequestMapping(value = "/edit", method = {RequestMethod.PUT, RequestMethod.POST})
    public Result<String> edit(@RequestBody AppSitePlaceSchoolDTO appSitePlace) {
        Boolean b = appSitePlaceService.editSchool(appSitePlace);
        return b ? Result.OK("编辑成功!") : Result.error("编辑失败!");
    }
    /**
     * 编辑
     *
     * @param appSitePlaceParkDTO
     * @return
     */
    @AutoLog(value = "商户包场-编辑")
    @Operation(summary = "商户包场-编辑")
//	@RequiresPermissions("org.jeecg.modules.system.app:nm_site_place:edit")
    @RequestMapping(value = "/editPack", method = {RequestMethod.PUT, RequestMethod.POST})
    public Result<String> editPack(@RequestBody
                                   AppSitePlaceParkDTO appSitePlaceParkDTO) {
        Boolean b = appSitePlaceService.editPack(appSitePlaceParkDTO);
        return b ? Result.OK("编辑成功!") : Result.error("编辑失败!");
    }

    /**
     * 编辑
     *
     * @param siteId
     * @return
     */
    @AutoLog(value = "商户包场-查询")
    @Operation(summary = "商户包场-查询")
    @GetMapping(value = "/queryPack")
    public Result<AppSitePlaceParkDTO> queryPack(@RequestParam(name = "siteId", required = true) String siteId) {
        AppSitePlaceParkDTO appSitePlaceParkDTO= appSitePlaceService.queryPack(siteId);
        return Result.OK(appSitePlaceParkDTO);
    }

    /**
     * 根据orgCode查询site列表
     *
     * @param orgCode
     * @param type
     * @return
     */
    @AutoLog(value = "根据orgCode查询商户信息列表")
    @Operation(summary = "根据orgCode查询site列表")
    @PostMapping(value = "/queryByOrgCode")
    public Result<List<AppSite>> queryByOrgCode(@RequestBody QueryByOrgCodeForm queryByOrgCodeForm) {
        List<AppSite> appSites = appSitePlaceService.queryByOrgCode(queryByOrgCodeForm);
        return Result.OK(appSites);
    }

    /**
     * 编辑
     *
     * @param unfixedDTO
     * @return
     */
    @AutoLog(value = "c-编辑")
    @Operation(summary = "商户无固定场所-编辑")
	@RequiresPermissions("app:appSitePlace:updateUnfixed")
    @RequestMapping(value = "/updateUnfixed", method = {RequestMethod.PUT, RequestMethod.POST})
    public Result<String> updateUnfixed(@RequestBody AppSitePlaceUnfixedDTO unfixedDTO) {
        Boolean b = appSitePlaceService.updateUnfixed(unfixedDTO);
        return b ? Result.OK("编辑成功!") : Result.error("编辑失败!");
    }

    /**
     * 通过id删除
     *
     * @param id
     * @return
     */
    @AutoLog(value = "商户场所学校-通过id删除")
    @Operation(summary = "商户场所学校-通过id删除")
//	@RequiresPermissions("org.jeecg.modules.system.app:nm_site_place:delete")
    @DeleteMapping(value = "/delete")
    public Result<String> delete(@RequestParam(name = "id", required = true) String id) {
        appSitePlaceService.removeById(id);
        return Result.OK("删除成功!");
    }

    /**
     * 通过id删除
     *
     * @param id
     * @return
     */
    @AutoLog(value = "商户无固定场所-通过id删除")
    @Operation(summary = "商户无固定场所-通过id删除")
	@RequiresPermissions("app:appSitePlace:deleteUnfixed")
    @DeleteMapping(value = "/deleteUnfixed")
    public Result<String> deleteUnfixed(@RequestParam(name = "id", required = true) String id) {
        appSitePlaceService.deleteUnfixed(id);
        return Result.OK("删除成功!");
    }

    /**
     * 通过id删除
     *
     * @param id
     * @return
     */
    @AutoLog(value = "商户包场-通过id删除")
    @Operation(summary = "商户包场-通过id删除")
//	@RequiresPermissions("org.jeecg.modules.system.app:nm_site_place:delete")
    @DeleteMapping(value = "/deletePackById")
    public Result<String> deletePackById(@RequestParam(name = "id", required = true) String id) {
        appSitePlaceService.deletePackById(id);
        return Result.OK("删除成功!");
    }

    /**
     * 通过id删除
     *
     * @param siteId
     * @return
     */
    @Operation(summary = "查询商户门店列表")
    @GetMapping(value = "/querySitePlaceList")
    public Result<List<AppSitePlace>> querySitePlaceList(@RequestParam(name = "id", required = true) String siteId) {
        List<AppSitePlace> list = appSitePlaceService.list(Wrappers.<AppSitePlace>lambdaQuery().eq(AppSitePlace::getSiteId, siteId));
        return Result.OK(list);
    }

    /**
     * 通过id查询
     *
     * @param id
     * @return
     */
    //@AutoLog(value = "商户场所表-通过id查询")
    @Operation(summary = "商户场所学校通过id查询")
    @GetMapping(value = "/queryById")
    public Result<AppSitePlaceSchoolDTO> queryById(@RequestParam(name = "id", required = true) String id) {
        return Result.OK(appSitePlaceService.querySchoolById(id));
    }

    /**
     * 通过id查询
     *
     * @param id
     * @return
     */
    //@AutoLog(value = "商户场所表-通过id查询")
    @Operation(summary = "商户场所学校通过id查询")
    @GetMapping(value = "/queryUnfixedById")
    public Result<AppSitePlaceUnfixedDTO> queryUnfixedById(@RequestParam(name = "id", required = true) String id) {
        return Result.OK(appSitePlaceService.queryUnfixedById(id));
    }

    /**
     * 学校场地开放添加
     *
     * @param schoolPlaceAddDTO
     * @return
     */
    @RequiresPermissions("org.jeecg.modules.system.app:nm_site_place:addSchoolPlace")
    @AutoLog(value = "商户无固定场所-学校场地开放添加")
    @Operation(summary = "商户无固定场所-学校场地开放添加")
    @PostMapping(value = "/addSchoolPlace")
    public Result<String> addSchoolPlace(@RequestBody SchoolPlaceAddDTO schoolPlaceAddDTO) {
        Boolean b =  appSitePlaceService.addSchoolPlace(schoolPlaceAddDTO);
        return b ? Result.OK("添加成功！") : Result.error("添加失败！");
    }

    /**
     * 学校场地开放查询
     *
     * @param orgCode
     * @return
     */
    @AutoLog(value = "商户无固定场所-学校场地开放查询")
    @Operation(summary = "商户无固定场所-学校场地开放查询")
    @GetMapping(value = "/querySchoolPlace")
    public Result<SchoolPlaceAddDTO> querySchoolPlace(@RequestParam(name = "orgCode", required = true) String orgCode) {
        return Result.OK(appSitePlaceService.querySchoolPlace(orgCode));
    }

//    /**
//    * 导出excel
//    *
//    * @param request
//    * @param appSitePlace
//    */
//    @RequiresPermissions("org.jeecg.modules.system.app:nm_site_place:exportXls")
//    @RequestMapping(value = "/exportXls")
//    public ModelAndView exportXls(HttpServletRequest request, AppSitePlace appSitePlace) {
//        return super.exportXls(request, appSitePlace, AppSitePlace.class, "商户场所表");
//    }
//
//    /**
//      * 通过excel导入数据
//    *
//    * @param request
//    * @param response
//    * @return
//    */
//    @RequiresPermissions("org.jeecg.modules.system.app:nm_site_place:importExcel")
//    @RequestMapping(value = "/importExcel", method = RequestMethod.POST)
//    public Result<?> importExcel(HttpServletRequest request, HttpServletResponse response) {
//        return super.importExcel(request, response, AppSitePlace.class);
//    }

}
