package com.chushang.inspection.terminal.controller;

import cn.hutool.core.bean.BeanUtil;
import com.chushang.common.core.web.AjaxResult;
import com.chushang.common.log.annotation.SysLog;
import com.chushang.common.log.enums.BusinessType;
import com.chushang.inspection.project.dto.Delete;
import com.chushang.inspection.project.service.TbTemplateService;
import com.chushang.inspection.terminal.po.Store;
import com.chushang.inspection.terminal.query.StoreQuery;
import com.chushang.inspection.terminal.service.StoreService;
import com.chushang.inspection.terminal.service.TerminalService;
import com.chushang.inspection.terminal.vo.StoreVO;
import com.chushang.security.annotation.RequiresPermissions;
import lombok.extern.java.Log;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import javax.validation.constraints.NotNull;

/**
* 商户信息表(st_store)表控制层
*
* @author xxxxx
*/
@RestController
@RequestMapping("/store")
public class StoreController {

    @Resource
    StoreService storeService;
    /**
     * 1. 终端商户池
     * 2. 我的终端池
     * 3. 分配记录
     * 4. 派单记录
     */

    /**
     * 查询商户
     *
     * @param query 条件
     */
    @SysLog(value = "查询商户", businessType = BusinessType.QUERY)
    @GetMapping("/page")
    @RequiresPermissions("ins:store:page")
    public AjaxResult pageList(@Validated StoreQuery query) {
        return AjaxResult.success(storeService.pageList(query));
    }

    /**
     * 修改商户
     */
    @PostMapping("/update")
    @RequiresPermissions("ins:store:update")
    @SysLog(value = "商户", businessType = BusinessType.UPDATE)
    public AjaxResult update(@RequestBody @Validated Store store) {
        storeService.updateById(store);
        return AjaxResult.success();
    }




    /**
     * 删除商户
     */
    @PostMapping("/delete")
    @RequiresPermissions("ins:store:delete")
    @SysLog(value = "商户", businessType = BusinessType.DELETE)
    public AjaxResult delete(@RequestBody @Validated Delete delete) {
        storeService.removeByIds(delete.getIds());
        return AjaxResult.success();
    }

    /**
     * TODO 上传 商户门头信息
     */
    @SysLog(value = "商户门头信息", businessType = BusinessType.IMPORT)
    @PostMapping("/upload")
    @RequiresPermissions("ins:store:upload")
    public AjaxResult upload(@RequestParam("file") MultipartFile file , @RequestParam("taskId")Long taskId) throws Exception{
        storeService.upload(file,taskId);
        return AjaxResult.success();
    }


    /**
     * 商户详情 --> 查询商户详情
     */
    @SysLog(value = "查询商户", businessType = BusinessType.QUERY)
    @GetMapping("/info/{storeId}")
    //@RequiresPermissions("ins:store:info")
    public AjaxResult info(@PathVariable Long storeId) {
        Store store = storeService.getById(storeId);
        return AjaxResult.success(BeanUtil.copyProperties(store, StoreVO.class));
    }


}
