package com.docus.server.synclis.controller;

import com.docus.core.util.Func;
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.synclis.service.LisService;
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.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

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

/**
 * @author YongBin Wen
 * @date 2025/1/16 17:10
 */
@RestController
@Api(tags = "LIS检验报告视图任务")
@RequestMapping("/ydzyylistask")
@Slf4j
public class LisTaskController {
    @Resource
    private LisService lisService;
    @Resource
    private TBasicMapper basicMapper;

    @ApiOperation(value = "根据患者主键，同步")
    @GetMapping("/syncFullLisByPatientIds")
    public CommonResult<String> syncFullLisByPatientIds(@RequestBody List<String> patientIds){
        if(Func.isEmpty(patientIds)){
            return CommonResult.failed("请传入正确的患者病案主键！");
        }
        List<TBasic> basicList = basicMapper.getByPatientIds(patientIds);
        for (TBasic basic : basicList) {
            lisService.syncFullTask(basic);
        }

        return CommonResult.success("同步完成！");
    }


    @ApiOperation(value = "修订门诊任务和文件")
    @GetMapping("/revisionMzTaskAndFile")
    public CommonResult<String> revisionMzTaskAndFile() {
        String start = "2022-10-01 00:00:00";
        String end = Func.formatDateTime(new Date());
        List<TBasic> tbasics = basicMapper.getByDisDate(start, end);
        log.info(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> 修订门诊任务和文件。出院时间：{} 至 {} 共 {} 条数据！", start, end, tbasics.size());
        for (TBasic tbasic : tbasics) {
            lisService.revisionMzTaskAndFile(tbasic);
        }
        return CommonResult.success("修订完成！");
    }
}
