package com.eitc.patient.controller;

import com.eitc.common.annotation.Log;
import com.eitc.common.core.controller.BaseController;
import com.eitc.common.core.domain.AjaxResult;
import com.eitc.common.enums.BusinessType;
import com.eitc.common.utils.ShellUtils;
import com.eitc.patient.help.ClinicInfoHelper;
import com.eitc.patient.service.IClinicInfoService;
import com.eitc.patient.vo.ClinicInfoVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.log4j.Log4j2;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
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 javax.servlet.http.HttpServletRequest;
import javax.validation.Valid;
import java.net.UnknownHostException;










/**
 * ClinicInfoController
 *
 * @author mtx
 * @date: 2024/05/17 15:51
 */
@Api(tags = "诊所信息")
@RestController
@Log4j2
@RequestMapping("/clinic-info")
public class ClinicInfoController extends BaseController {

    @Resource
    private IClinicInfoService clinicInfoService;
    @Resource
    private ClinicInfoHelper clinicInfoHelper;


    /**
     * 获取门诊信息详细信息ClinicInfoController.java:140
     */
    @GetMapping(value = "/detail")
    @ApiOperation("获取门诊信息详细信息")
    public AjaxResult detail(HttpServletRequest request) throws Exception {
        // 获取费用信息
        ClinicInfoVO clinicInfo = clinicInfoService.findClinicInfo();
        Boolean fulfillmentInformation = clinicInfoHelper.getFulfillmentInformation(clinicInfo,request);
        if (!fulfillmentInformation) {
            return error("履约信息获取失败，请联系管理员！");
        }
        return success(clinicInfo);
    }

    /**
     * 新增门诊信息
     */
    @Log(title = "新增门诊信息", businessType = BusinessType.INSERT)
    @PostMapping
    @ApiOperation("新增门诊信息")
    public AjaxResult add(@ApiParam(name = "clinicInfo") @Valid @RequestBody ClinicInfoVO clinicInfo) {
        return clinicInfoService.addOrUpdate(clinicInfo);
    }


    /**
     * 下载升级安装包
     */
    @GetMapping(value ="getUpgradePackage")
    @ApiOperation("下载升级安装包")
    public AjaxResult getUpgradePackage(Integer version) {
        clinicInfoHelper.pullTheUpgradePackage(version);
        return success();
    }

    /**
     * 检测版本是否需要升级
     * @return
     */
    @GetMapping(value ="getVersionChanges")
    @ApiOperation("检测版本是否需要升级")
    public AjaxResult getVersionChanges() {
        System.out.println("升级版本v2");

        return success(clinicInfoHelper.getVersionChanges());
    }


    /**
     * 手动升级
     * @return
     */
    @GetMapping(value ="identifyTheUpgrade")
    @ApiOperation("手动升级")
    public AjaxResult identifyTheUpgrade() throws UnknownHostException {
        clinicInfoHelper.identifyTheUpgrade();
        return success();
    }


}
