package com.fs.hisStore.controller.store;

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.poi.ExcelUtil;
import com.fs.hisStore.domain.StoreLoginUserScrm;
import com.fs.hisStore.domain.FsMaterialGroupScrm;
import com.fs.hisStore.service.IFsMaterialGroupScrmStoreService;
import com.fs.hisStore.utils.UserUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 素材分组Controller
 *
 * @author fs
 * @date 2022-03-15
 */
@RestController
@RequestMapping("/store/store/materialGroup")
public class FsMaterialGroupScrmController extends BaseController
{
    @Autowired
    private IFsMaterialGroupScrmStoreService fsMaterialGroupService;

    /**
     * 查询素材分组列表
     */
    @GetMapping("/list")
    public TableDataInfo list(FsMaterialGroupScrm fsMaterialGroup)
    {

        startPage();
        List<FsMaterialGroupScrm> list = fsMaterialGroupService.selectFsMaterialGroupList(fsMaterialGroup);
        return getDataTable(list);
    }

    /**
     * 导出素材分组列表
     */
    @Log(title = "素材分组", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(FsMaterialGroupScrm fsMaterialGroup)
    {
        List<FsMaterialGroupScrm> list = fsMaterialGroupService.selectFsMaterialGroupList(fsMaterialGroup);
        ExcelUtil<FsMaterialGroupScrm> util = new ExcelUtil<FsMaterialGroupScrm>(FsMaterialGroupScrm.class);
        return util.exportExcel(list, "materialGroup");
    }

    /**
     * 获取素材分组详细信息
     */
    @GetMapping(value = "/{groupId}")
    public AjaxResult getInfo(@PathVariable("groupId") Long groupId)
    {
        return AjaxResult.success(fsMaterialGroupService.selectFsMaterialGroupByGroupId(groupId));
    }

    /**
     * 新增素材分组
     */
    @Log(title = "素材分组", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody FsMaterialGroupScrm fsMaterialGroup)
    {
        StoreLoginUserScrm loginUser = UserUtil.getLoginUser();
        fsMaterialGroup.setStoreId(loginUser.getFsStore().getStoreId());
        return toAjax(fsMaterialGroupService.insertFsMaterialGroup(fsMaterialGroup));
    }

    /**
     * 修改素材分组
     */
    @Log(title = "素材分组", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody FsMaterialGroupScrm fsMaterialGroup)
    {
        return toAjax(fsMaterialGroupService.updateFsMaterialGroup(fsMaterialGroup));
    }

    /**
     * 删除素材分组
     */
    @Log(title = "素材分组", businessType = BusinessType.DELETE)
	@DeleteMapping("/{groupIds}")
    public AjaxResult remove(@PathVariable Long[] groupIds)
    {
        return toAjax(fsMaterialGroupService.deleteFsMaterialGroupByGroupIds(groupIds));
    }

    @GetMapping("/getAllList")
    public R getAllList(FsMaterialGroupScrm fsMaterialGroup)
    {
        StoreLoginUserScrm loginUser = UserUtil.getLoginUser();
        fsMaterialGroup.setStoreId(loginUser.getFsStore().getStoreId());
        List<FsMaterialGroupScrm> list = fsMaterialGroupService.selectFsMaterialGroupList(fsMaterialGroup);
        return R.ok().put("data",list);
    }
}
