package com.emr.controller.emrLock;

import com.alibaba.fastjson.JSON;
import com.emr.entity.recordLock.Emr_Lock;
import com.emr.service.emrLock.EmrLockServiceImpl;
import com.emr.util.ExceptionPrintUtil;
import com.emr.vo.EmrLockVo;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

/**
 * @ProjectName:EmrLockController
 * @Description:锁定病案
 * @Param 传输参数
 * @Return
 * @Author: 曾文和
 * @CreateDate: 2019/6/3 17:49
 * @UpdateUser: 曾文和
 * @UpdateDate: 2019/6/3 17:49
 * @UpdateRemark: 更新说明
 * @Version: 1.0
 */
@Controller
@RequestMapping("emrLock/")
public class EmrLockController {
    @Autowired
    private EmrLockServiceImpl emrLockService;
    /**
     * @MethodName lockList
     * @Description: 跳转到锁定管理页面
     * @Param 无
     * @Returnt
     * @Author: 曾文和
     * @CreateDate: 2020-04-14
     * @UpdateUser: 曾文和
     * @UpdateDate: 2020-04-14
     * @UpdateRemark: 更新说明
     * @Version: 1.0
     */
    @RequestMapping("lockList")
    public String lockList(){
        return "otherManage/lockList";
    }

    /**
     * @ProjectName:getLockList
     * @Description:查询锁定记录
     * @Param
     * @Return
     * @Author: 曾文和
     * @CreateDate: 2020-04-14
     * @UpdateUser: 曾文和
     * @UpdateDate: 2020-04-14
     * @UpdateRemark: 更新说明
     * @Version: 1.0
     */
    @RequiresPermissions("/emrLock/select")
    @RequestMapping("getLockList")
    @ResponseBody
    public String getLockList(Integer page, Integer limit, EmrLockVo lockVo){
        if(null != page && null != limit){
            PageHelper.startPage(page, limit);
        }
        try{
            //查询
            List<EmrLockVo> list = emrLockService.getLockList(lockVo);
            PageInfo pageInfo = new PageInfo<>(list);
            return JSON.toJSONString(pageInfo);
        }catch (Exception e){
            ExceptionPrintUtil.printException(e);
            e.printStackTrace();
            return null;
        }
    }

    /**
     * @MethodName getLoctPatientIds
     * @Description: 获取被锁定了的patientId集合
     * @Param 无
     * @Returnt
     * @Author: 曾文和
     * @CreateDate: 2019-06-03
     * @UpdateUser: 曾文和
     * @UpdateDate: 2019-06-03
     * @UpdateRemark: 更新说明
     * @Version: 1.0
     */
    @RequestMapping("getLoctPatientIds")
    @ResponseBody
    public String getLoctPatientIds(){
        //锁定的集合
        try {
            int status = 1;
            List<Emr_Lock> emr_locks = emrLockService.selectLockListByStatus(status);
            if(null != emr_locks && !emr_locks.isEmpty()){
                StringBuilder locks = new StringBuilder();
                for (Emr_Lock emr_lock : emr_locks) {
                    locks.append("'").append(emr_lock.getPatientId()).append("',");
                }
                return JSON.toJSONString(locks);
            }else{
                return "";
            }
        }catch (Exception e){
            ExceptionPrintUtil.printException(e);
            e.printStackTrace();
            return null;
        }
    }
}
