package com.diagbot.facade;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.diagbot.dto.StrAdmissionNoteDTO;
import com.diagbot.entity.*;
import com.diagbot.enums.IsDeleteEnum;
import com.diagbot.service.*;
import com.diagbot.util.*;
import com.diagbot.vo.DataEditVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Component;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @Description:
 * @Author:wangsy
 * @time: 2021/08/14 11:37
 */
@Component
public class DataEditFacade {

    @Autowired
    @Qualifier("strAdmissionNoteServiceImpl")
    StrAdmissionNoteService strAdmissionNoteService;

    /**
     * 数据检索
     */
    public StrAdmissionNoteDTO dataSearch() {
        Long hospitalId = Long.valueOf(SysUserUtils.getCurrentHospitalID());
        StrAdmissionNote strAdmissionNote= strAdmissionNoteService.getBaseMapper().selectOne(new QueryWrapper<StrAdmissionNote>()
                .eq("hospital_id", hospitalId)
                .eq("remark", hospitalId + "N")
                .select("rec_id", "whole_data"));
        StrAdmissionNoteDTO strAdmissionNoteDTO = new StrAdmissionNoteDTO();
        BeanUtil.copyProperties(strAdmissionNote,strAdmissionNoteDTO);
        strAdmissionNoteDTO.setModeId("200");
        return strAdmissionNoteDTO;
    }



    /**
     * 更新数据
     *
     * @param dataEditVO
     * @return
     */
    public Boolean saveDataEditFacade(DataEditVO dataEditVO) {
        return strAdmissionNoteService.update(new UpdateWrapper<StrAdmissionNote>()
                .eq("is_deleted", IsDeleteEnum.N.getKey())
                .eq("hospital_id", SysUserUtils.getCurrentHospitalID())
                .eq("rec_id", dataEditVO.getRecId())
                .set("whole_data", dataEditVO.getWholeData())
                .set("gmt_modified", DateUtil.now())
                .set("modifier", SysUserUtils.getCurrentPrincipleID())
        );
    }

}
