package com.luowei.app_sb.controller;
import com.luowei.app_sb.entity.Person_805Entity;
import com.luowei.app_sb.entity.Person_health_805Entity;
import com.luowei.app_sb.service.Person_805Service;
import com.luowei.app_sb.vo.PersonHealthVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;
import java.util.UUID;

@RestController
@RequestMapping("emr")
public class EmrController {
    @Autowired
    Person_805Entity person_805Entity;
    @Autowired
    Person_health_805Entity person_health_805Entity;
    @Autowired
    Person_805Service person_805Service;

    //提交的表单对应vo层
    @RequestMapping("ehrSet_805")
    public String ehrSet_805(PersonHealthVo personHealthVo){
        String id= UUID.randomUUID().toString().replace("_","").toLowerCase();//生成混杂数字英文的字符串，类似于php中的uniquID
        //时间戳
        long now = new Date().getTime()/1000;
        person_805Entity.setSfz_id(personHealthVo.getSfz_id());
        person_805Entity.setName(personHealthVo.getName());
        person_805Entity.setGender(personHealthVo.getGender());
        person_805Entity.setEmr(personHealthVo.getEmr());
        if (person_805Service.selectPerson_805(personHealthVo.getSfz_id())==null){
            //新增
            person_805Entity.setCreate_time(now);
            person_805Entity.setUpdate_time(now);
            person_805Entity.setId(id);
            person_805Service.insertPerson_805(person_805Entity);
        }else {
            //编辑
            person_805Entity.setUpdate_time(now);
            person_805Service.updatePerson_805(person_805Entity);
        }
        person_health_805Entity.setId(id);
        person_health_805Entity.setSfz_id(personHealthVo.getSfz_id());
        person_health_805Entity.setSbp(personHealthVo.getSbp());
        person_health_805Entity.setDbp(personHealthVo.getDbp());
        person_health_805Entity.setCreate_time(now);
        person_health_805Entity.setUpdate_time(now);
        person_805Service.insertPerson_health_805Entity(person_health_805Entity);

        return person_805Entity.getName();
    }
    @RequestMapping("ehrGet_805")
    public PersonHealthVo ehrGet_805(String sfz_id){
        return person_805Service.selectPersonHealthVo(sfz_id);
    }
}
