package com.unis.base.server.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;
import com.github.pagehelper.PageInfo;
import com.unis.base.common.vo.DYpxxHisVO;
import com.unis.base.common.vo.DYpxxQueryHisVO;
import com.unis.base.server.service.DYpxxHisService;
import com.unis.common.utils.ResponseWrapper;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;

/**
 * @author 张琪
 * @date 2019年9月22日 下午3:11:32
 * @description
 */
@RestController
@Api(value = "药剂信息历史记录 ", tags = "药剂信息历史记录 维护")
@Slf4j
public class MedicineinfoHisController {
	@Autowired
	private DYpxxHisService dYpxxHisService;

	@ApiOperation(value = "药剂信息历史记录列表 根据条件【分页查询】",notes = "参数：方案编号/作业单编号")
	@PostMapping(value = "/medicineinfoHisPageList/{pageNum}/{pageSize}")
	public ResponseWrapper getMedicineinfoHisList(@PathVariable(value = "pageNum") Integer pageNum,
			  @PathVariable(value = "pageSize") Integer pageSize,@RequestBody DYpxxQueryHisVO dYpxxQueryHisVO){
		try {
			PageInfo<DYpxxHisVO> pageInfos = dYpxxHisService.getDYpxxHisList(dYpxxQueryHisVO,pageNum,pageSize);
			return ResponseWrapper.success(HttpStatus.OK.value(), HttpStatus.OK.getReasonPhrase(), pageInfos);
		} catch (Exception e) {
			log.error(e.getMessage());
			return ResponseWrapper.error(HttpStatus.INTERNAL_SERVER_ERROR.value(), HttpStatus.INTERNAL_SERVER_ERROR.getReasonPhrase(),"服务错误，请联系管理员");
		}
	}

	/**
	 * @author 张琪
	 * @Description 根据主键ID获取药剂信息历史信息
	 * @return 药剂信息信息
	 */
	@ApiOperation(value = "根据主键编码获取药剂历史信息", notes = "参数：主键ID")
	@GetMapping(value = "/medicineinfoHisInfo/{lsId}")
	public ResponseWrapper getMedicineinfoHisInfoByLsId(@PathVariable("lsId")String lsId) {
		try {
			DYpxxHisVO medicineinfoHisVO=dYpxxHisService.getDYpxxHisInfoByLsId(lsId);
			if(medicineinfoHisVO == null) {
				return ResponseWrapper.success(HttpStatus.BAD_REQUEST.value(), "获取失败", null);
			}
            return ResponseWrapper.success(HttpStatus.OK.value(), HttpStatus.OK.getReasonPhrase(), medicineinfoHisVO);
        } catch (Exception e) {
            e.printStackTrace();
            log.error(e.getMessage());
        }
        return ResponseWrapper.error(HttpStatus.INTERNAL_SERVER_ERROR.value(), HttpStatus.INTERNAL_SERVER_ERROR.getReasonPhrase(),"服务错误，请联系管理员");
	}

	/**
	 * @author 张琪
	 * @Description 新增药剂信息信息
	 * @param 药剂信息信息对象 models
	 * @return 新增状态
	 */
	@ApiOperation(value = "新增药剂日志信息", notes = "参数：备案类型【0_未备案，1_待提交，2_待审核，3_已驳回，4_已备案】")
	@PostMapping(value = "/medicineinfoHisInfoSave")
    public ResponseWrapper insert(@RequestBody DYpxxHisVO dYpxxHisVO) {
		try{
			if(dYpxxHisVO.getSfba()==null) {
				return ResponseWrapper.success(HttpStatus.BAD_REQUEST.value(), "有必传参数为空", null);
			}
			int vo = dYpxxHisService.insert(dYpxxHisVO);
			if(vo!=0) {
	            return ResponseWrapper.success(HttpStatus.OK.value(), "添加成功",vo);
			} else {
	            return ResponseWrapper.success(HttpStatus.BAD_REQUEST.value(), "添加失败", null);
			}
        } catch (Exception e) {
            e.printStackTrace();
            log.error(e.getMessage());
        }
        return ResponseWrapper.error(HttpStatus.INTERNAL_SERVER_ERROR.value(), HttpStatus.INTERNAL_SERVER_ERROR.getReasonPhrase(),"服务错误，请联系管理员");
	}

}
