package com.zhongzheng.controller.base;

import java.util.List;
import java.util.Arrays;

import com.zhongzheng.modules.base.bo.ProfileTpAddBo;
import com.zhongzheng.modules.base.bo.ProfileTpEditBo;
import com.zhongzheng.modules.base.bo.ProfileTpQueryBo;
import com.zhongzheng.modules.base.service.IProfileTpService;
import com.zhongzheng.modules.base.vo.ProfileTpVo;
import lombok.RequiredArgsConstructor;
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.zhongzheng.common.annotation.Log;
import com.zhongzheng.common.core.controller.BaseController;
import com.zhongzheng.common.core.domain.AjaxResult;
import com.zhongzheng.common.enums.BusinessType;
import com.zhongzheng.common.utils.poi.ExcelUtil;
import com.zhongzheng.common.core.page.TableDataInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

/**
 * 资料模板Controller
 *
 * @author hjl
 * @date 2021-11-19
 */
@Api(value = "资料模板控制器", tags = {"资料模板管理"})
@RequiredArgsConstructor(onConstructor_ = @Autowired)
@RestController
@RequestMapping("/base/profile/tp")
public class ProfileTpController extends BaseController {

    private final IProfileTpService iProfileTpService;

    /**
     * 查询资料模板列表
     */
    @ApiOperation("查询资料模板列表")
    @PreAuthorize("@ss.hasPermi('system:tp:list')")
    @GetMapping("/list")
    public TableDataInfo<ProfileTpVo> list(ProfileTpQueryBo bo) {
        startPage();
        List<ProfileTpVo> list = iProfileTpService.selectList(bo);
        return getDataTable(list);
    }

    /**
     * 获取所有使用商品ID
     */
    @ApiOperation("获取所有使用商品ID")
    @PreAuthorize("@ss.hasPermi('system:tp:list')")
    @GetMapping("/goods_list")
    public AjaxResult<List<String>> goods_list(ProfileTpQueryBo bo) {
        List<String> list = iProfileTpService.selectAllUseGoods(bo);
        return AjaxResult.success(list);
    }

    /**
     * 导出资料模板列表
     */
   /* @ApiOperation("导出资料模板列表")
    @PreAuthorize("@ss.hasPermi('system:tp:export')")
    @Log(title = "资料模板", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult<ProfileTpVo> export(ProfileTpQueryBo bo) {
        List<ProfileTpVo> list = iProfileTpService.queryList(bo);
        ExcelUtil<ProfileTpVo> util = new ExcelUtil<ProfileTpVo>(ProfileTpVo.class);
        return util.exportExcel(list, "资料模板");
    }*/

    /**
     * 获取资料模板详细信息
     */
    @ApiOperation("获取资料模板详细信息")
    @PreAuthorize("@ss.hasPermi('system:tp:query')")
    @GetMapping("/{profileTpId}")
    public AjaxResult<ProfileTpVo> getInfo(@PathVariable("profileTpId" ) Long profileTpId) {
        return AjaxResult.success(iProfileTpService.queryById(profileTpId));
    }

    /**
     * 新增资料模板
     */
    @ApiOperation("新增资料模板")
    @PreAuthorize("@ss.hasPermi('system:tp:add')")
    @Log(title = "资料模板", businessType = BusinessType.INSERT)
    @PostMapping()
    public AjaxResult<Void> add(@RequestBody ProfileTpAddBo bo) {
        return toAjax(iProfileTpService.insertByAddBo(bo) ? 1 : 0);
    }

    /**
     * 修改资料模板
     */
    @ApiOperation("修改资料模板")
    @PreAuthorize("@ss.hasPermi('system:tp:edit')")
    @Log(title = "资料模板", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    public AjaxResult<Void> edit(@RequestBody ProfileTpEditBo bo) {
        return toAjax(iProfileTpService.updateByEditBo(bo) ? 1 : 0);
    }

    /**
     * 删除资料模板
     */
   /* @ApiOperation("删除资料模板")
    @PreAuthorize("@ss.hasPermi('system:tp:remove')")
    @Log(title = "资料模板" , businessType = BusinessType.DELETE)
    @DeleteMapping("/{profileTpIds}")
    public AjaxResult<Void> remove(@PathVariable Long[] profileTpIds) {
        return toAjax(iProfileTpService.deleteWithValidByIds(Arrays.asList(profileTpIds), true) ? 1 : 0);
    }*/
}
