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

import com.baomidou.mybatisplus.core.metadata.IPage;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.apache.shiro.authz.annotation.RequiresPermissions;
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.system.app.dto.AppSiteDTO;
import org.jeecg.modules.system.app.dto.AppSitePageDTO;
import org.jeecg.modules.system.app.dto.EditSitePayInfoDTO;
import org.jeecg.modules.system.app.entity.AppSite;
import org.jeecg.modules.system.app.service.IAppSitePriceRulesService;
import org.jeecg.modules.system.app.service.IAppSiteService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;


/**
 * @Description: 场地表
 * @Author: jeecg-boot
 * @Date:   2025-07-03
 * @Version: V1.0
 */
@Tag(name="商户信息补充")
@RestController
@RequestMapping("/appSite")
@Slf4j
public class AppSiteController extends JeecgController<AppSite, IAppSiteService> {
	@Autowired
	private IAppSiteService appSiteService;
	@Autowired
	private IAppSitePriceRulesService sitePriceRulesService;

	/**
	 * 分页列表查询
	 *
	 * @param dto
	 * @return
	 */
	//@AutoLog(value = "场地表-分页列表查询")
	@Operation(summary="商户信息补充-分页列表查询")
	@GetMapping(value = "/list")
	public Result<IPage<AppSiteDTO>> queryPageList(AppSitePageDTO dto) {
		return Result.OK(appSiteService.querySitePage(dto));
	}

	/**
	 *   添加
	 *
	 * @param appSiteDTO
	 * @return
	 */
	@AutoLog(value = "商户信息补充-添加")
	@Operation(summary="商户信息补充-添加")
//	@RequiresPermissions("org.jeecg.modules.app:nm_site:add")
	@PostMapping(value = "/add")
	public Result<String> add(@RequestBody AppSiteDTO appSiteDTO) {
		return appSiteService.saveSite(appSiteDTO)?Result.OK("添加成功！"):Result.error("添加失败！");
	}

	/**
	 *  编辑
	 *
	 * @param appSiteDTO
	 * @return
	 */
	@AutoLog(value = "商户信息补充-编辑")
	@Operation(summary="商户信息补充-编辑")
//	@RequiresPermissions("org.jeecg.modules.app:nm_site:edit")
	@RequestMapping(value = "/edit", method = {RequestMethod.PUT,RequestMethod.POST})
	public Result<String> edit(@RequestBody AppSiteDTO appSiteDTO) {
		return appSiteService.editSite(appSiteDTO)?Result.OK("操作成功！"):Result.error("操作失败！");
	}

	/**
	 *   通过id删除
	 *
	 * @param id
	 * @return
	 */
	@AutoLog(value = "商户信息补充-通过id删除")
	@Operation(summary="商户信息补充-通过id删除")
//	@RequiresPermissions("org.jeecg.modules.app:nm_site:delete")
	@DeleteMapping(value = "/delete")
	public Result<String> delete(@RequestParam(name="id",required=true) String id) {

		return appSiteService.deleteSiteById(id)? Result.OK("删除成功!"):Result.error("删除失败！");
	}

//	/**
//	 *  批量删除
//	 *
//	 * @param ids
//	 * @return
//	 */
//	@AutoLog(value = "场地表-批量删除")
//	@Operation(summary="场地表-批量删除")
//	@RequiresPermissions("org.jeecg.modules.app:nm_site:deleteBatch")
//	@DeleteMapping(value = "/deleteBatch")
//	public Result<String> deleteBatch(@RequestParam(name="ids",required=true) String ids) {
//		this.appSiteService.removeByIds(Arrays.asList(ids.split(",")));
//		return Result.OK("批量删除成功!");
//	}

	/**
	 * 通过id查询
	 *
	 * @param id
	 * @return
	 */
	//@AutoLog(value = "场地表-通过id查询")
	@Operation(summary="商户信息补充-通过id查询")
	@GetMapping(value = "/queryById")
	public Result<AppSiteDTO> queryById(@RequestParam(name="id",required=true) String id) {
			return Result.ok(appSiteService.querySiteById(id));
	}

	/**
	 * 通过orgCode查询
	 *
	 * @param orgCode
	 * @return
	 */
	//@AutoLog(value = "场地表-通过orgCode查询")
	@Operation(summary="商户信息补充-通过orgCode查询")
	@GetMapping(value = "/querySiteListByOrgCode")
	public Result<AppSiteDTO> querySiteByOrgCode(@RequestParam(name="orgCode",required=true) String orgCode) {
		return Result.ok(appSiteService.querySiteByOrgCode(orgCode));
	}

    /**
    * 导出excel
    *
    * @param request
    * @param appSite
    */
    @RequiresPermissions("org.jeecg.modules.app:nm_site:exportXls")
    @RequestMapping(value = "/exportXls")
    public ModelAndView exportXls(HttpServletRequest request, AppSite appSite) {
        return super.exportXls(request, appSite, AppSite.class, "场地表");
    }

    /**
      * 通过excel导入数据
    *
    * @param request
    * @param response
    * @return
    */
    @RequiresPermissions("org.jeecg.modules.app:nm_site:importExcel")
    @RequestMapping(value = "/importExcel", method = RequestMethod.POST)
    public Result<?> importExcel(HttpServletRequest request, HttpServletResponse response) {
        return super.importExcel(request, response, AppSite.class);
    }

	/**
	 * 通过tenantId查询
	 *
	 * @param tenantId
	 * @return
	 */
	@AutoLog(value = "门店信息补充-通过tenantId查询")
	@Operation(summary="门店信息补充-通过tenantId查询")
	@GetMapping(value = "/queryByTenantId")
	public Result<AppSiteDTO> queryByTenantId(@RequestParam(name="tenantId",required=true) String tenantId) {
		return Result.ok(appSiteService.queryByTenantId(tenantId));
	}

	/**
	 *  编辑
	 *
	 * @param appSiteDTO
	 * @return
	 */
	@AutoLog(value = "门店信息补充-编辑")
	@Operation(summary="门店信息补充-编辑")
	@RequestMapping(value = "/editSite", method = {RequestMethod.PUT,RequestMethod.POST})
	public Result<String> editSite(@RequestBody AppSiteDTO appSiteDTO) {
		return appSiteService.editSite(appSiteDTO)?Result.OK("操作成功！"):Result.error("操作失败！");
	}

    /**
     * <p>根据部门信息ID修改支付信息</p>
     * @author SheepHy
     * @param editSitePayInfoDTO，参数为类则包含{@link EditSitePayInfoDTO}
     * @return 返回值描述，如无返回值则为void 返回值为类则包含{@link Boolean}
     *
     */
    @Operation(summary="根据门店信息ID修改支付信息")
    @RequestMapping(value = "/editSitePayInfo", method = {RequestMethod.PUT,RequestMethod.POST})
    public Result<Boolean> editSitePayInfo(@RequestBody EditSitePayInfoDTO editSitePayInfoDTO){
        return appSiteService.editSitePayInfo(editSitePayInfoDTO)?Result.OK("操作成功！"):Result.error("操作失败！");
    }

    /**
     * <p>根据部门信息ID修改支付信息</p>
     * @author SheepHy
     * @param id，参数为类则包含
     * @return 返回值描述，如无返回值则为void 返回值为类则包含{@link EditSitePayInfoDTO}
     *
     */
    @Operation(summary="根据门店信息ID修改支付信息")
    @GetMapping(value = "/querySitePayInfoById")
    public Result<EditSitePayInfoDTO> querySitePayInfoById(@RequestParam(name="id",required=true) String id){
        return Result.ok(appSiteService.querySitePayInfoById(id));
    }
}
