package com.huijy.web.controller.management;

import java.util.Date;
import java.util.List;
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.huijy.common.annotation.Log;
import com.huijy.common.core.controller.BaseController;
import com.huijy.common.core.domain.AjaxResult;
import com.huijy.common.enums.BusinessType;
import com.huijy.management.domain.Shop;
import com.huijy.management.service.IShopService;
import com.huijy.common.utils.poi.ExcelUtil;
import com.huijy.common.core.page.TableDataInfo;

/**
 * 商铺管理Controller
 *
 * @author luobo
 * @date 2021-09-12
 */
@RestController
@RequestMapping("/management/shop")
public class ShopController extends BaseController
{
    @Autowired
    private IShopService shopService;

    /**
     * 查询商铺管理列表
     */
    @PreAuthorize("@ss.hasPermi('management:shop:list')")
    @GetMapping("/list")
    public TableDataInfo list(Shop shop)
    {
        startPage();
        List<Shop> list = shopService.selectShopList(shop);
        return getDataTable(list);
    }

    /**
     * 查询商铺管理列表
     */
    @GetMapping("/select")
    public TableDataInfo select()
    {
        Shop shop = new Shop();
        shop.setAuditFlag("1");
        List<Shop> list = shopService.selectShopList(shop);
        return getDataTable(list);
    }


    /**
     * 导出商铺管理列表
     */
    @PreAuthorize("@ss.hasPermi('management:shop:export')")
    @Log(title = "商铺管理", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(Shop shop)
    {
        List<Shop> list = shopService.selectShopList(shop);
        ExcelUtil<Shop> util = new ExcelUtil<Shop>(Shop.class);
        return util.exportExcel(list, "商铺管理数据");
    }

    /**
     * 获取商铺管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('management:shop:query')")
    @GetMapping(value = "/{shopId}")
    public AjaxResult getInfo(@PathVariable("shopId") Long shopId)
    {
        return AjaxResult.success(shopService.selectShopByShopId(shopId));
    }

    /**
     * 新增商铺管理
     */
    @PreAuthorize("@ss.hasPermi('management:shop:add')")
    @Log(title = "商铺管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Shop shop)
    {
        return toAjax(shopService.insertShop(shop));
    }

    /**
     * 修改商铺管理
     */
    @PreAuthorize("@ss.hasPermi('management:shop:edit')")
    @Log(title = "商铺管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Shop shop)
    {
        if (shop.getAuditFlag().equalsIgnoreCase("1") ){
            shop.setAuditAt(getUserId());
            shop.setAuditTime(new Date());
        }

        return toAjax(shopService.updateShop(shop));
    }

    /**
     * 删除商铺管理
     */
    @PreAuthorize("@ss.hasPermi('management:shop:remove')")
    @Log(title = "商铺管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{shopIds}")
    public AjaxResult remove(@PathVariable Long[] shopIds)
    {
        return toAjax(shopService.deleteShopByShopIds(shopIds));
    }
}
