zhaowenxuan
2025-06-24 2a9583fd376451ca77a0400af7f3a02d1b80e7f5
ltkj-admin/src/main/java/com/ltkj/web/jmreport/JimuController.java
@@ -1,11 +1,21 @@
package com.ltkj.web.jmreport;
import cn.hutool.http.server.HttpServerRequest;
import cn.hutool.json.JSONObject;
import cn.hutool.json.JSONUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.ltkj.common.core.domain.AjaxResult;
import com.ltkj.common.enums.DataSourceType;
import com.ltkj.db.DataSourceConfig;
import com.ltkj.db.DataSourceContextHolder;
import com.ltkj.hosp.domain.DictCommonHisConfig;
import com.ltkj.hosp.domain.DictHosp;
import com.ltkj.hosp.mapper.TestMapper;
import com.ltkj.hosp.service.DictCommonHisConfigService;
import com.ltkj.hosp.service.IDictHospService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import jodd.util.StringUtil;
import lombok.extern.slf4j.Slf4j;
import org.omg.CORBA.Environment;
import org.springframework.beans.factory.annotation.Autowired;
@@ -16,6 +26,8 @@
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
@@ -33,6 +45,10 @@
@Api(tags = "PC端 积木报表接口集")
@Slf4j
public class JimuController {
    @Autowired
    private DictCommonHisConfigService dictCommonHisConfigService;
//    @Value("${jimu.path}")
    private static  String value;
@@ -41,6 +57,10 @@
    @Autowired
    private TestMapper testMapper;
    @Autowired
    private DataSourceConfig dataSourceConfig;
    @Autowired
    private IDictHospService dictHospService;
    @Value ("${config.properties}")
    public void setConfigPath(String path) {
@@ -91,7 +111,17 @@
    @GetMapping("/view")
    @ApiOperation(value = "view")
    //@PreAuthorize("@ss.hasPermi('report:jimu:view')")
    public String view(){
    public String view(HttpServletRequest request){
//        dataSourceConfig.addDataSource(DataSourceType.MASTER.name());
//        DataSourceContextHolder.setDataSourceKey(DataSourceType.MASTER.name());
//        String hospId = request.getHeader("hospId");
//        LambdaQueryWrapper<DictHosp> wrapper = new LambdaQueryWrapper<>();
//        wrapper.eq(DictHosp::getCode,hospId);
//        DictHosp hosp = dictHospService.getOne(wrapper);
//        if (hosp != null && StringUtil.isNotBlank(hosp.getDbname())) {
//            dataSourceConfig.addDataSource(hosp.getDbname());
//            DataSourceContextHolder.setDataSourceKey(hosp.getDbname());
//        }
        return value+"/jmreport/view";
    }
@@ -109,9 +139,16 @@
//    }
    @GetMapping("/getBingZhong")
    public String getBingZhongInfo(@RequestParam("start") String start, @RequestParam("end") String end){
        JSONObject object = JSONUtil.createObj();
        object.putOpt("data",testMapper.getBingZhongInfo(start,end));
        return JSONUtil.toJsonStr(object);
    public String getBingZhongInfo(@RequestParam("start") String start, @RequestParam("end") String end,@RequestParam(required = true,value = "hospId") String hospId){
        try {
            DictCommonHisConfig hisConfig = dictCommonHisConfigService.getOne(new LambdaQueryWrapper<DictCommonHisConfig>().eq(DictCommonHisConfig::getHospital, hospId));
            dataSourceConfig.addDataSource(hisConfig.getDbName());
            DataSourceContextHolder.setDataSourceKey(hisConfig.getDbName());
            JSONObject object = JSONUtil.createObj();
            object.putOpt("data",testMapper.getBingZhongInfo(start,end));
            return JSONUtil.toJsonStr(object);
        }finally {
            DataSourceContextHolder.setDataSourceKey("default");
        }
    }
}