package com.chushang.inspection.terminal.controller;

import com.chushang.common.core.exception.utils.AssertUtil;
import com.chushang.common.core.validator.Create;
import com.chushang.common.core.validator.Update;
import com.chushang.common.core.web.AjaxResult;
import com.chushang.common.excel.utils.ExcelUtils;
import com.chushang.common.log.annotation.SysLog;
import com.chushang.common.log.enums.BusinessType;
import com.chushang.common.mybatis.page.CommonParam;
import com.chushang.inspection.project.dto.ContractDTO;
import com.chushang.inspection.project.dto.ProjectDTO;
import com.chushang.inspection.project.dto.TaskExcelDTO;
import com.chushang.inspection.project.service.TbTemplateService;
import com.chushang.inspection.terminal.dto.StoreImportDTO;
import com.chushang.inspection.terminal.po.StoreImport;
import com.chushang.inspection.terminal.query.StoreImportQuery;
import com.chushang.inspection.terminal.query.StoreQuery;
import com.chushang.inspection.terminal.service.StoreImportService;
import com.chushang.inspection.terminal.service.StoreService;
import com.chushang.inspection.utils.BeanCopyUtils;
import com.chushang.security.annotation.RequiresPermissions;
import com.chushang.security.utils.SecurityUtils;
import com.google.common.collect.Lists;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import java.util.Arrays;
import java.util.List;

/**
 * @auther: zhao
 * @date: 2024/7/3 9:56
 */
@RestController
@RequestMapping(value = "/store/import")
public class StoreImportController {

    @Resource
    TbTemplateService tbTemplateService;

    @Resource
    StoreImportService storeImportService;

    /**
     * todo
     * 需要 以下接口
     * 1. 导入列表页查询
     * 2. 导出修改
     * 3. 导入删除
     * 4. 导入预读
     * 5. 导入入库
     * 6. store_import 转 store,template,template_ins 表, 转一条数据之后, 就需要同步清除, 避免数据重复
     * 7. 清除当前数据
     */
    @SysLog(value = "下载模板", businessType = BusinessType.DOWNLOAD)
    @PostMapping("/down/template")
    @RequiresPermissions("store:import:template")
    public AjaxResult downTemplate(@RequestParam(defaultValue = "store_template") String templateAlias)
    {
        return AjaxResult.success(tbTemplateService.getByAlias(templateAlias, null));
    }


    @SysLog(value = "导入预读取", businessType = BusinessType.IMPORT)
    @PostMapping("/read")
    @RequiresPermissions("store:import:read")
    public AjaxResult importRead(@RequestParam(value = "file") MultipartFile file)
    {

        return AjaxResult.success(ExcelUtils.read(file, StoreImportDTO.class));
    }

    @SysLog(value = "导入", businessType = BusinessType.IMPORT)
    @PostMapping("/save")
    @RequiresPermissions("store:import:save")
    public AjaxResult importStore(@RequestBody List<StoreImportDTO> lists)
    {
        return AjaxResult.success(storeImportService.confimImport(lists));
    }









}
