LAPTOP-KB9HII50\70708 vor 10 Monaten
Ursprung
Commit
45a980add9

+ 58 - 0
svr/svr-visit-behind/src/main/java/com/yihu/jw/hospital/module/common/CommonItemController.java

@ -6,12 +6,21 @@ import com.yihu.jw.restmodel.web.endpoint.EnvelopRestEndpoint;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;
import java.io.File;
import java.io.IOException;
import java.util.List;
/**
 * Created by yeshijie on 2023/11/3.
@ -21,8 +30,13 @@ import org.springframework.web.bind.annotation.RestController;
@Api(value = "通用项目接口")
public class CommonItemController extends EnvelopRestEndpoint {
    private static Logger logger = LoggerFactory.getLogger(CommonItemController.class);
    @Autowired
    private DoorOrderService doorOrderService;
    @Autowired
    private JdbcTemplate jdbcTemplate;
    /**
     * 这个接口没用了
@ -43,4 +57,48 @@ public class CommonItemController extends EnvelopRestEndpoint {
            return Envelop.getError("查询失败",-1);
        }
    }
    @RequestMapping("/open/exportExcel/fileUpload")
    @ApiOperation("文件上传")
    public String handleFileUpload(@RequestParam("file") MultipartFile file
            ,@RequestParam("token") String token) {
        if (file.isEmpty()) {
            return "文件为空";
        }
        if(StringUtils.isBlank(token)){
            return error(-1,"非法请求");
        }
        String sql = "select dict_code from wlyy_hospital_sys_dict where dict_name ='fileUpload_token'  ";
        List<String> urls = jdbcTemplate.queryForList(sql,String.class);
        if(urls.size()==0){
            return error(-1,"非法请求");
        }
        if(!token.equals(urls.get(0))){
            return error(-1,"非法请求");
        }
        // 获取文件名
        String fileName = file.getOriginalFilename();
        logger.info("上传的文件名为:" + fileName);
        // 获取文件的后缀名
        String suffixName = fileName.substring(fileName.lastIndexOf("."));
        logger.info("上传的后缀名为:" + suffixName);
        // 文件上传后的路径
        String filePath = "/data/";
        File dest = new File(filePath + fileName);
        // 检测是否存在目录
        if (!dest.getParentFile().exists()) {
            dest.getParentFile().mkdirs();
        }
        try {
            file.transferTo(dest);
            return "上传成功";
        } catch (IllegalStateException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return "上传失败";
    }
}