package com.docus.server.synchis.controller;

import com.docus.infrastructure.web.api.CommonResult;
import com.docus.server.archive.entity.TBasic;
import com.docus.server.archive.mapper.TBasicMapper;
import com.docus.server.synchis.service.HisService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

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

/**
 * @author YongBin Wen
 * @date 2025/1/16 17:10
 */
@RestController
@Api(tags = "HIS报告视图任务")
@RequestMapping("/ydzyyhistask")
@Slf4j
public class HisTaskController {
    @Resource
    private HisService hisService;
    @Resource
    private TBasicMapper basicMapper;


    @ApiOperation(value = "根据出院日期(yyyy-MM-dd)范围进行his任务检查")
    @GetMapping("/check")
    public CommonResult<String> revisionMzTaskAndFile(String startDate, String endDate) {
        String start = startDate + " 00:00:00";
        String end = endDate + " 23:59:59";
        List<TBasic> tbasics = basicMapper.getByDisDate(start, end);
        log.info(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> 检查HIS任务和文件。出院时间：{} 至 {} 共 {} 条数据！", start, end, tbasics.size());
        for (TBasic tbasic : tbasics) {
            hisService.checkTask(tbasic);
        }
        return CommonResult.success("检查完成！");
    }
}
