package cn.gov.customs.wxjy.task.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import cn.gov.customs.cacp.sdks.core.result.Result;
import cn.gov.customs.cacp.sdks.core.user.trans.CacpTransUser;
import cn.gov.customs.cacp.sdks.core.user.trans.UserContextHolder;
import cn.gov.customs.wxjy.common.utils.StringUtils;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;
import cn.gov.customs.wxjy.common.core.controller.BaseController;
import org.springframework.web.multipart.MultipartFile;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import cn.gov.customs.wxjy.task.pojo.SyncDataStatus;
import cn.gov.customs.wxjy.task.pojo.SyncDataStatusQuery;
import cn.gov.customs.wxjy.task.service.ISyncDataStatusService;
import cn.gov.customs.wxjy.common.utils.poi.ExcelUtil;
import cn.gov.customs.wxjy.common.core.page.TableDataInfo;

/**
 * 数据同步状态记录Controller
 *
 * @author xiong
 * @date 2025-12-19
 */
@RestController
@RequestMapping("/task/SyncDataStatus")
@RequiredArgsConstructor
public class SyncDataStatusController extends BaseController {

    private final ISyncDataStatusService syncDataStatusService;

    /**
     * 查询数据同步状态记录列表
     */
    @PostMapping("/get-list")
    public Result<PageInfo<SyncDataStatus>> list(@RequestBody SyncDataStatusQuery query) {
        PageHelper.startPage(query.getPageIndex(), query.getPageSize());
        PageInfo<SyncDataStatus> list = syncDataStatusService.selectPageList(query);
        return Result.success(list);
    }

    /**
     * 获取数据同步状态记录详细信息
     */
    @GetMapping(value = "/get-detail")
    public Result<SyncDataStatus> getInfo(@RequestParam String ID) {
        return Result.success(syncDataStatusService.selectByID(ID));
    }

    /**
     * 新增数据同步状态记录
     */
    @PostMapping("/insert-syncDataStatus")
    public Result<Integer> add(@RequestBody SyncDataStatus syncDataStatus) {
        return Result.success(syncDataStatusService.insert(syncDataStatus));
    }

    /**
     * 修改数据同步状态记录
     */
    @PostMapping("/update-syncDataStatus")
    public Result<Integer> edit(@RequestBody SyncDataStatus syncDataStatus) {
        return Result.success(syncDataStatusService.update(syncDataStatus));
    }

    /**
     * 删除数据同步状态记录
     */
    @PostMapping("/delete-syncDataStatus")
    public Result<Integer> remove(@RequestBody String[] ids) {
        return Result.success(syncDataStatusService.deleteByIDs(ids));
    }

    /**
    * 导入 数据同步状态记录
    * @param file
    * @param updateSupport
    * @return
    * @throws Exception
    */
    @PostMapping("/import-syncDataStatus")
    public Result<String> importData(MultipartFile file, boolean updateSupport) throws Exception
    {
        CacpTransUser user = UserContextHolder.currentUser();
        ExcelUtil<SyncDataStatus> util = new ExcelUtil<SyncDataStatus>(SyncDataStatus.class);
        List<SyncDataStatus> syncDataStatusList = util.importExcel(file.getInputStream());
        String message = syncDataStatusService.importSyncDataStatus(syncDataStatusList, updateSupport, user);
        return Result.success(message);
    }

    /**
     * 导出数据同步状态记录列表
     */
    @PostMapping("/get-syncDataStatus-export")
    public void export(HttpServletResponse response, @RequestBody SyncDataStatusQuery query) {
        List<SyncDataStatus> list = syncDataStatusService.selectList(query);
        ExcelUtil<SyncDataStatus> util = new ExcelUtil<SyncDataStatus>(SyncDataStatus. class);
        util.exportExcel(response, list, "数据同步状态记录数据");
    }

    /**
    * 获取导入模板
    * @param response
    */
    @PostMapping("/template-syncDataStatus")
    public void importTemplate(HttpServletResponse response)
    {
        ExcelUtil<SyncDataStatus> util = new ExcelUtil<SyncDataStatus>(SyncDataStatus.class);
        util.importTemplateExcel(response, "数据同步状态记录");
    }
}
