Browse Source

ocr

recovery
zhizhi wu 4 years ago
parent
commit
1a3a4e99a8
  1. 4
      pom.xml
  2. 84
      tcm/src/main/java/com/ccsens/tcm/bean/po/ReportOcr.java
  3. 571
      tcm/src/main/java/com/ccsens/tcm/bean/po/ReportOcrExample.java
  4. 4
      tcm/src/main/java/com/ccsens/tcm/bean/vo/BiologicalSamplesVo.java
  5. 2
      tcm/src/main/java/com/ccsens/tcm/bean/vo/PatientVo.java
  6. 30
      tcm/src/main/java/com/ccsens/tcm/persist/mapper/ReportOcrMapper.java
  7. 106
      tcm/src/main/java/com/ccsens/tcm/service/OcrService.java
  8. 5
      tcm/src/main/java/com/ccsens/tcm/service/PatientService.java
  9. 4
      tcm/src/main/java/com/ccsens/tcm/uitl/Constant.java
  10. 4
      tcm/src/main/resources/application.yml
  11. 4
      tcm/src/main/resources/mapper_dao/PatientDao.xml
  12. 228
      tcm/src/main/resources/mapper_raw/ReportOcrMapper.xml
  13. 6
      util/pom.xml
  14. 27
      util/src/main/java/com/ccsens/util/ali/AliInstanceUtil.java
  15. 168
      util/src/main/java/com/ccsens/util/ali/Demolyocr_general_advanced.java
  16. 34
      util/src/main/java/com/ccsens/util/ali/HttpApiClientlyocr_general_advanced.java
  17. 50
      util/src/main/java/com/ccsens/util/ali/HttpsApiClientlyocr_general_advanced.java

4
pom.xml

@ -219,13 +219,13 @@
<dependency> <dependency>
<groupId>org.apache.httpcomponents</groupId> <groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId> <artifactId>httpclient</artifactId>
<version>4.3.1</version> <version>4.5.1</version>
</dependency> </dependency>
<!-- https://mvnrepository.com/artifact/org.apache.httpcomponents/httpcore --> <!-- https://mvnrepository.com/artifact/org.apache.httpcomponents/httpcore -->
<dependency> <dependency>
<groupId>org.apache.httpcomponents</groupId> <groupId>org.apache.httpcomponents</groupId>
<artifactId>httpcore</artifactId> <artifactId>httpcore</artifactId>
<version>4.3.1</version> <version>4.4.3</version>
</dependency> </dependency>
<!--腾讯短信--> <!--腾讯短信-->
<dependency> <dependency>

84
tcm/src/main/java/com/ccsens/tcm/bean/po/ReportOcr.java

@ -0,0 +1,84 @@
package com.ccsens.tcm.bean.po;
import java.io.Serializable;
import java.util.Date;
public class ReportOcr implements Serializable {
private Long id;
private String code;
private Byte ocrChannel;
private Date createdAt;
private Date updatedAt;
private Byte recStatus;
private static final long serialVersionUID = 1L;
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public String getCode() {
return code;
}
public void setCode(String code) {
this.code = code == null ? null : code.trim();
}
public Byte getOcrChannel() {
return ocrChannel;
}
public void setOcrChannel(Byte ocrChannel) {
this.ocrChannel = ocrChannel;
}
public Date getCreatedAt() {
return createdAt;
}
public void setCreatedAt(Date createdAt) {
this.createdAt = createdAt;
}
public Date getUpdatedAt() {
return updatedAt;
}
public void setUpdatedAt(Date updatedAt) {
this.updatedAt = updatedAt;
}
public Byte getRecStatus() {
return recStatus;
}
public void setRecStatus(Byte recStatus) {
this.recStatus = recStatus;
}
@Override
public String toString() {
StringBuilder sb = new StringBuilder();
sb.append(getClass().getSimpleName());
sb.append(" [");
sb.append("Hash = ").append(hashCode());
sb.append(", id=").append(id);
sb.append(", code=").append(code);
sb.append(", ocrChannel=").append(ocrChannel);
sb.append(", createdAt=").append(createdAt);
sb.append(", updatedAt=").append(updatedAt);
sb.append(", recStatus=").append(recStatus);
sb.append("]");
return sb.toString();
}
}

571
tcm/src/main/java/com/ccsens/tcm/bean/po/ReportOcrExample.java

@ -0,0 +1,571 @@
package com.ccsens.tcm.bean.po;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
public class ReportOcrExample {
protected String orderByClause;
protected boolean distinct;
protected List<Criteria> oredCriteria;
public ReportOcrExample() {
oredCriteria = new ArrayList<Criteria>();
}
public void setOrderByClause(String orderByClause) {
this.orderByClause = orderByClause;
}
public String getOrderByClause() {
return orderByClause;
}
public void setDistinct(boolean distinct) {
this.distinct = distinct;
}
public boolean isDistinct() {
return distinct;
}
public List<Criteria> getOredCriteria() {
return oredCriteria;
}
public void or(Criteria criteria) {
oredCriteria.add(criteria);
}
public Criteria or() {
Criteria criteria = createCriteriaInternal();
oredCriteria.add(criteria);
return criteria;
}
public Criteria createCriteria() {
Criteria criteria = createCriteriaInternal();
if (oredCriteria.size() == 0) {
oredCriteria.add(criteria);
}
return criteria;
}
protected Criteria createCriteriaInternal() {
Criteria criteria = new Criteria();
return criteria;
}
public void clear() {
oredCriteria.clear();
orderByClause = null;
distinct = false;
}
protected abstract static class GeneratedCriteria {
protected List<Criterion> criteria;
protected GeneratedCriteria() {
super();
criteria = new ArrayList<Criterion>();
}
public boolean isValid() {
return criteria.size() > 0;
}
public List<Criterion> getAllCriteria() {
return criteria;
}
public List<Criterion> getCriteria() {
return criteria;
}
protected void addCriterion(String condition) {
if (condition == null) {
throw new RuntimeException("Value for condition cannot be null");
}
criteria.add(new Criterion(condition));
}
protected void addCriterion(String condition, Object value, String property) {
if (value == null) {
throw new RuntimeException("Value for " + property + " cannot be null");
}
criteria.add(new Criterion(condition, value));
}
protected void addCriterion(String condition, Object value1, Object value2, String property) {
if (value1 == null || value2 == null) {
throw new RuntimeException("Between values for " + property + " cannot be null");
}
criteria.add(new Criterion(condition, value1, value2));
}
public Criteria andIdIsNull() {
addCriterion("id is null");
return (Criteria) this;
}
public Criteria andIdIsNotNull() {
addCriterion("id is not null");
return (Criteria) this;
}
public Criteria andIdEqualTo(Long value) {
addCriterion("id =", value, "id");
return (Criteria) this;
}
public Criteria andIdNotEqualTo(Long value) {
addCriterion("id <>", value, "id");
return (Criteria) this;
}
public Criteria andIdGreaterThan(Long value) {
addCriterion("id >", value, "id");
return (Criteria) this;
}
public Criteria andIdGreaterThanOrEqualTo(Long value) {
addCriterion("id >=", value, "id");
return (Criteria) this;
}
public Criteria andIdLessThan(Long value) {
addCriterion("id <", value, "id");
return (Criteria) this;
}
public Criteria andIdLessThanOrEqualTo(Long value) {
addCriterion("id <=", value, "id");
return (Criteria) this;
}
public Criteria andIdIn(List<Long> values) {
addCriterion("id in", values, "id");
return (Criteria) this;
}
public Criteria andIdNotIn(List<Long> values) {
addCriterion("id not in", values, "id");
return (Criteria) this;
}
public Criteria andIdBetween(Long value1, Long value2) {
addCriterion("id between", value1, value2, "id");
return (Criteria) this;
}
public Criteria andIdNotBetween(Long value1, Long value2) {
addCriterion("id not between", value1, value2, "id");
return (Criteria) this;
}
public Criteria andCodeIsNull() {
addCriterion("code is null");
return (Criteria) this;
}
public Criteria andCodeIsNotNull() {
addCriterion("code is not null");
return (Criteria) this;
}
public Criteria andCodeEqualTo(String value) {
addCriterion("code =", value, "code");
return (Criteria) this;
}
public Criteria andCodeNotEqualTo(String value) {
addCriterion("code <>", value, "code");
return (Criteria) this;
}
public Criteria andCodeGreaterThan(String value) {
addCriterion("code >", value, "code");
return (Criteria) this;
}
public Criteria andCodeGreaterThanOrEqualTo(String value) {
addCriterion("code >=", value, "code");
return (Criteria) this;
}
public Criteria andCodeLessThan(String value) {
addCriterion("code <", value, "code");
return (Criteria) this;
}
public Criteria andCodeLessThanOrEqualTo(String value) {
addCriterion("code <=", value, "code");
return (Criteria) this;
}
public Criteria andCodeLike(String value) {
addCriterion("code like", value, "code");
return (Criteria) this;
}
public Criteria andCodeNotLike(String value) {
addCriterion("code not like", value, "code");
return (Criteria) this;
}
public Criteria andCodeIn(List<String> values) {
addCriterion("code in", values, "code");
return (Criteria) this;
}
public Criteria andCodeNotIn(List<String> values) {
addCriterion("code not in", values, "code");
return (Criteria) this;
}
public Criteria andCodeBetween(String value1, String value2) {
addCriterion("code between", value1, value2, "code");
return (Criteria) this;
}
public Criteria andCodeNotBetween(String value1, String value2) {
addCriterion("code not between", value1, value2, "code");
return (Criteria) this;
}
public Criteria andOcrChannelIsNull() {
addCriterion("ocr_channel is null");
return (Criteria) this;
}
public Criteria andOcrChannelIsNotNull() {
addCriterion("ocr_channel is not null");
return (Criteria) this;
}
public Criteria andOcrChannelEqualTo(Byte value) {
addCriterion("ocr_channel =", value, "ocrChannel");
return (Criteria) this;
}
public Criteria andOcrChannelNotEqualTo(Byte value) {
addCriterion("ocr_channel <>", value, "ocrChannel");
return (Criteria) this;
}
public Criteria andOcrChannelGreaterThan(Byte value) {
addCriterion("ocr_channel >", value, "ocrChannel");
return (Criteria) this;
}
public Criteria andOcrChannelGreaterThanOrEqualTo(Byte value) {
addCriterion("ocr_channel >=", value, "ocrChannel");
return (Criteria) this;
}
public Criteria andOcrChannelLessThan(Byte value) {
addCriterion("ocr_channel <", value, "ocrChannel");
return (Criteria) this;
}
public Criteria andOcrChannelLessThanOrEqualTo(Byte value) {
addCriterion("ocr_channel <=", value, "ocrChannel");
return (Criteria) this;
}
public Criteria andOcrChannelIn(List<Byte> values) {
addCriterion("ocr_channel in", values, "ocrChannel");
return (Criteria) this;
}
public Criteria andOcrChannelNotIn(List<Byte> values) {
addCriterion("ocr_channel not in", values, "ocrChannel");
return (Criteria) this;
}
public Criteria andOcrChannelBetween(Byte value1, Byte value2) {
addCriterion("ocr_channel between", value1, value2, "ocrChannel");
return (Criteria) this;
}
public Criteria andOcrChannelNotBetween(Byte value1, Byte value2) {
addCriterion("ocr_channel not between", value1, value2, "ocrChannel");
return (Criteria) this;
}
public Criteria andCreatedAtIsNull() {
addCriterion("created_at is null");
return (Criteria) this;
}
public Criteria andCreatedAtIsNotNull() {
addCriterion("created_at is not null");
return (Criteria) this;
}
public Criteria andCreatedAtEqualTo(Date value) {
addCriterion("created_at =", value, "createdAt");
return (Criteria) this;
}
public Criteria andCreatedAtNotEqualTo(Date value) {
addCriterion("created_at <>", value, "createdAt");
return (Criteria) this;
}
public Criteria andCreatedAtGreaterThan(Date value) {
addCriterion("created_at >", value, "createdAt");
return (Criteria) this;
}
public Criteria andCreatedAtGreaterThanOrEqualTo(Date value) {
addCriterion("created_at >=", value, "createdAt");
return (Criteria) this;
}
public Criteria andCreatedAtLessThan(Date value) {
addCriterion("created_at <", value, "createdAt");
return (Criteria) this;
}
public Criteria andCreatedAtLessThanOrEqualTo(Date value) {
addCriterion("created_at <=", value, "createdAt");
return (Criteria) this;
}
public Criteria andCreatedAtIn(List<Date> values) {
addCriterion("created_at in", values, "createdAt");
return (Criteria) this;
}
public Criteria andCreatedAtNotIn(List<Date> values) {
addCriterion("created_at not in", values, "createdAt");
return (Criteria) this;
}
public Criteria andCreatedAtBetween(Date value1, Date value2) {
addCriterion("created_at between", value1, value2, "createdAt");
return (Criteria) this;
}
public Criteria andCreatedAtNotBetween(Date value1, Date value2) {
addCriterion("created_at not between", value1, value2, "createdAt");
return (Criteria) this;
}
public Criteria andUpdatedAtIsNull() {
addCriterion("updated_at is null");
return (Criteria) this;
}
public Criteria andUpdatedAtIsNotNull() {
addCriterion("updated_at is not null");
return (Criteria) this;
}
public Criteria andUpdatedAtEqualTo(Date value) {
addCriterion("updated_at =", value, "updatedAt");
return (Criteria) this;
}
public Criteria andUpdatedAtNotEqualTo(Date value) {
addCriterion("updated_at <>", value, "updatedAt");
return (Criteria) this;
}
public Criteria andUpdatedAtGreaterThan(Date value) {
addCriterion("updated_at >", value, "updatedAt");
return (Criteria) this;
}
public Criteria andUpdatedAtGreaterThanOrEqualTo(Date value) {
addCriterion("updated_at >=", value, "updatedAt");
return (Criteria) this;
}
public Criteria andUpdatedAtLessThan(Date value) {
addCriterion("updated_at <", value, "updatedAt");
return (Criteria) this;
}
public Criteria andUpdatedAtLessThanOrEqualTo(Date value) {
addCriterion("updated_at <=", value, "updatedAt");
return (Criteria) this;
}
public Criteria andUpdatedAtIn(List<Date> values) {
addCriterion("updated_at in", values, "updatedAt");
return (Criteria) this;
}
public Criteria andUpdatedAtNotIn(List<Date> values) {
addCriterion("updated_at not in", values, "updatedAt");
return (Criteria) this;
}
public Criteria andUpdatedAtBetween(Date value1, Date value2) {
addCriterion("updated_at between", value1, value2, "updatedAt");
return (Criteria) this;
}
public Criteria andUpdatedAtNotBetween(Date value1, Date value2) {
addCriterion("updated_at not between", value1, value2, "updatedAt");
return (Criteria) this;
}
public Criteria andRecStatusIsNull() {
addCriterion("rec_status is null");
return (Criteria) this;
}
public Criteria andRecStatusIsNotNull() {
addCriterion("rec_status is not null");
return (Criteria) this;
}
public Criteria andRecStatusEqualTo(Byte value) {
addCriterion("rec_status =", value, "recStatus");
return (Criteria) this;
}
public Criteria andRecStatusNotEqualTo(Byte value) {
addCriterion("rec_status <>", value, "recStatus");
return (Criteria) this;
}
public Criteria andRecStatusGreaterThan(Byte value) {
addCriterion("rec_status >", value, "recStatus");
return (Criteria) this;
}
public Criteria andRecStatusGreaterThanOrEqualTo(Byte value) {
addCriterion("rec_status >=", value, "recStatus");
return (Criteria) this;
}
public Criteria andRecStatusLessThan(Byte value) {
addCriterion("rec_status <", value, "recStatus");
return (Criteria) this;
}
public Criteria andRecStatusLessThanOrEqualTo(Byte value) {
addCriterion("rec_status <=", value, "recStatus");
return (Criteria) this;
}
public Criteria andRecStatusIn(List<Byte> values) {
addCriterion("rec_status in", values, "recStatus");
return (Criteria) this;
}
public Criteria andRecStatusNotIn(List<Byte> values) {
addCriterion("rec_status not in", values, "recStatus");
return (Criteria) this;
}
public Criteria andRecStatusBetween(Byte value1, Byte value2) {
addCriterion("rec_status between", value1, value2, "recStatus");
return (Criteria) this;
}
public Criteria andRecStatusNotBetween(Byte value1, Byte value2) {
addCriterion("rec_status not between", value1, value2, "recStatus");
return (Criteria) this;
}
}
public static class Criteria extends GeneratedCriteria {
protected Criteria() {
super();
}
}
public static class Criterion {
private String condition;
private Object value;
private Object secondValue;
private boolean noValue;
private boolean singleValue;
private boolean betweenValue;
private boolean listValue;
private String typeHandler;
public String getCondition() {
return condition;
}
public Object getValue() {
return value;
}
public Object getSecondValue() {
return secondValue;
}
public boolean isNoValue() {
return noValue;
}
public boolean isSingleValue() {
return singleValue;
}
public boolean isBetweenValue() {
return betweenValue;
}
public boolean isListValue() {
return listValue;
}
public String getTypeHandler() {
return typeHandler;
}
protected Criterion(String condition) {
super();
this.condition = condition;
this.typeHandler = null;
this.noValue = true;
}
protected Criterion(String condition, Object value, String typeHandler) {
super();
this.condition = condition;
this.value = value;
this.typeHandler = typeHandler;
if (value instanceof List<?>) {
this.listValue = true;
} else {
this.singleValue = true;
}
}
protected Criterion(String condition, Object value) {
this(condition, value, null);
}
protected Criterion(String condition, Object value, Object secondValue, String typeHandler) {
super();
this.condition = condition;
this.value = value;
this.secondValue = secondValue;
this.typeHandler = typeHandler;
this.betweenValue = true;
}
protected Criterion(String condition, Object value, Object secondValue) {
this(condition, value, secondValue, null);
}
}
}

4
tcm/src/main/java/com/ccsens/tcm/bean/vo/BiologicalSamplesVo.java

@ -14,8 +14,10 @@ public class BiologicalSamplesVo {
public static class selBiolog { public static class selBiolog {
@ApiModelProperty("医院名称") @ApiModelProperty("医院名称")
private String name; private String name;
@ApiModelProperty("患者号") @ApiModelProperty("患者住院号")
private String hospitalization; private String hospitalization;
@ApiModelProperty("患者研究编号")
private String patientCode;
@ApiModelProperty("生物样本编号") @ApiModelProperty("生物样本编号")
private String code; private String code;
@ApiModelProperty("样本类型 0:抗血凝10ml 1:促凝血5ml 2:晨尿10ml 3:24小时尿10ml") @ApiModelProperty("样本类型 0:抗血凝10ml 1:促凝血5ml 2:晨尿10ml 3:24小时尿10ml")

2
tcm/src/main/java/com/ccsens/tcm/bean/vo/PatientVo.java

@ -21,6 +21,8 @@ public class PatientVo {
private Long id; private Long id;
@ApiModelProperty("住院号") @ApiModelProperty("住院号")
private String hospitalization; private String hospitalization;
@ApiModelProperty("研究编号")
private String code;
@ApiModelProperty("对照组id") @ApiModelProperty("对照组id")
private Long inpatientId; private Long inpatientId;
@ApiModelProperty("录入状态:0:新建 1:数据搜集中 2数据搜集完成 3数据搜集超时 4:废弃") @ApiModelProperty("录入状态:0:新建 1:数据搜集中 2数据搜集完成 3数据搜集超时 4:废弃")

30
tcm/src/main/java/com/ccsens/tcm/persist/mapper/ReportOcrMapper.java

@ -0,0 +1,30 @@
package com.ccsens.tcm.persist.mapper;
import com.ccsens.tcm.bean.po.ReportOcr;
import com.ccsens.tcm.bean.po.ReportOcrExample;
import java.util.List;
import org.apache.ibatis.annotations.Param;
public interface ReportOcrMapper {
long countByExample(ReportOcrExample example);
int deleteByExample(ReportOcrExample example);
int deleteByPrimaryKey(Long id);
int insert(ReportOcr record);
int insertSelective(ReportOcr record);
List<ReportOcr> selectByExample(ReportOcrExample example);
ReportOcr selectByPrimaryKey(Long id);
int updateByExampleSelective(@Param("record") ReportOcr record, @Param("example") ReportOcrExample example);
int updateByExample(@Param("record") ReportOcr record, @Param("example") ReportOcrExample example);
int updateByPrimaryKeySelective(ReportOcr record);
int updateByPrimaryKey(ReportOcr record);
}

106
tcm/src/main/java/com/ccsens/tcm/service/OcrService.java

@ -2,14 +2,22 @@ package com.ccsens.tcm.service;
import cn.hutool.core.collection.CollectionUtil; import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.util.StrUtil; import cn.hutool.core.util.StrUtil;
import com.alibaba.cloudapi.sdk.model.ApiResponse;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import com.ccsens.tcm.bean.dto.QuestionOcrDto; import com.ccsens.tcm.bean.dto.QuestionOcrDto;
import com.ccsens.tcm.bean.po.ReportOcr;
import com.ccsens.tcm.bean.po.ReportOcrExample;
import com.ccsens.tcm.bean.vo.QuestionOcrVo; import com.ccsens.tcm.bean.vo.QuestionOcrVo;
import com.ccsens.tcm.persist.dao.QuestionOcrDao; import com.ccsens.tcm.persist.dao.QuestionOcrDao;
import com.ccsens.tcm.persist.mapper.ReportOcrMapper;
import com.ccsens.tcm.uitl.Constant; import com.ccsens.tcm.uitl.Constant;
import com.ccsens.util.CodeEnum;
import com.ccsens.util.ali.AliInstanceUtil;
import com.ccsens.util.baidu.BaiDuDto; import com.ccsens.util.baidu.BaiDuDto;
import com.ccsens.util.baidu.BaiDuUtil; import com.ccsens.util.baidu.BaiDuUtil;
import com.ccsens.util.baidu.BaiDuVo; import com.ccsens.util.baidu.BaiDuVo;
import com.ccsens.util.exception.BaseException;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation; import org.springframework.transaction.annotation.Propagation;
@ -33,35 +41,83 @@ public class OcrService implements IOcrService {
@Resource @Resource
private QuestionOcrDao questionOcrDao; private QuestionOcrDao questionOcrDao;
@Resource
private ReportOcrMapper reportOcrMapper;
@Override @Override
public List<QuestionOcrVo.GeneralBasic> identifyWords(QuestionOcrDto.GeneralBasic generalBasic, Long userId) { public List<QuestionOcrVo.GeneralBasic> identifyWords(QuestionOcrDto.GeneralBasic generalBasic, Long userId) {
long time1 = System.currentTimeMillis();
List<QuestionOcrVo.GeneralBasic> vos = new ArrayList<>(); List<QuestionOcrVo.GeneralBasic> vos = new ArrayList<>();
// 类型测评规则
List<QuestionOcrVo.OcrRule> rules = questionOcrDao.queryRules(generalBasic.getHospitalId(), generalBasic.getCode());
log.info("规则:{}", rules);
if (CollectionUtil.isEmpty(rules)) {
return vos;
}
long time2 = System.currentTimeMillis();
log.info("查询规则时间:{}", time2 - time1);
ReportOcrExample ocrExample = new ReportOcrExample();
ocrExample.createCriteria().andCodeEqualTo(generalBasic.getCode());
List<ReportOcr> reportOcrList = reportOcrMapper.selectByExample(ocrExample);
long time3 = System.currentTimeMillis();
log.info("查询reportOrc:{}", time3 - time2);
boolean baidu = CollectionUtil.isEmpty(reportOcrList) || reportOcrList.get(0).getOcrChannel() != 1;
// 识别字符串
List<String> contents = new ArrayList<>();
long time4 = 0;
if (baidu) {
BaiDuDto.GeneralBasic basic = new BaiDuDto.GeneralBasic(); BaiDuDto.GeneralBasic basic = new BaiDuDto.GeneralBasic();
basic.setUrl(generalBasic.getUrl()); basic.setUrl(generalBasic.getUrl());
BaiDuVo.GeneralBasic words = BaiDuUtil.accurateBasic(Constant.BaiDu.APP_KEY, Constant.BaiDu.SECRET_KEY, basic); BaiDuVo.GeneralBasic words = BaiDuUtil.accurateBasic(Constant.BaiDu.APP_KEY, Constant.BaiDu.SECRET_KEY, basic);
log.info("文字识别:{}", words); log.info("文字识别:{}", words);
if (words == null || words.getWordsResultNum() <= 0) { if (words == null || CollectionUtil.isEmpty(words.getWordsResult())) {
return vos; return vos;
} }
List<QuestionOcrVo.OcrRule> rules = questionOcrDao.queryRules(generalBasic.getHospitalId(), generalBasic.getCode()); words.getWordsResult().forEach(word -> contents.add(word.getWords()));
log.info("规则:{}", rules); } else {
if (CollectionUtil.isEmpty(rules)) { // 阿里
return vos; String body = "{\"img\":\"\",\"url\":\""+generalBasic.getUrl()+"\",\"prob\":false,\"charInfo\":false,\"rotate\":false,\"table\":false}";
ApiResponse response = AliInstanceUtil.getGeneralAdvancedHttps().ocrAdvancedSyncMode(body.getBytes());
time4 = System.currentTimeMillis();
log.info("阿里接口调用:{}", time4 -time3);
log.info("调用阿里的通用识别接口,请求:{}, 返回:{}", body, response);
int code = response.getCode();
int curCode = 200;
if (code != curCode) {
CodeEnum thirdError = CodeEnum.THIRD_ERROR;
thirdError.setMsg(response.getEx().getMessage());
throw new BaseException(thirdError);
} }
Map<String, Integer> keyMap = new HashMap<>(); String result = new String(response.getBody());
log.info("result:{}", result);
JSONObject json = JSONObject.parseObject(result);
JSONArray infos = json.getJSONArray("prism_wordsInfo");
for (Object obj: infos) {
JSONObject info = (JSONObject)obj;
contents.add(info.getString("word").replaceAll("\\s+",""));
}
}
Map<String, Integer> keyMap = new HashMap<>(16);
rules.forEach(rule -> { rules.forEach(rule -> {
JSONObject start = StrUtil.isEmpty(rule.getStart()) ? null : JSONObject.parseObject(rule.getStart()); JSONObject start = StrUtil.isEmpty(rule.getStart()) ? null : JSONObject.parseObject(rule.getStart());
JSONObject end = StrUtil.isEmpty(rule.getEnd()) ? null : JSONObject.parseObject(rule.getEnd()); JSONObject end = StrUtil.isEmpty(rule.getEnd()) ? null : JSONObject.parseObject(rule.getEnd());
StringBuilder builder = new StringBuilder(); StringBuilder builder;
if (start == null) { if (start == null) {
// 不知道这种场景 // 不知道这种场景
return;
} else if (start.containsKey(Constant.BaiDu.NUM)) { } else if (start.containsKey(Constant.BaiDu.NUM)) {
// 包含读取第几个 // 包含读取第几个
builder = getContent(words, keyMap, start); builder = getContent(contents, keyMap, start);
} else { } else {
builder = getContent(words, start, end); builder = getContent(contents, start, end);
} }
QuestionOcrVo.GeneralBasic vo = new QuestionOcrVo.GeneralBasic(); QuestionOcrVo.GeneralBasic vo = new QuestionOcrVo.GeneralBasic();
@ -71,24 +127,24 @@ public class OcrService implements IOcrService {
vo.setContent(builder.toString()); vo.setContent(builder.toString());
vos.add(vo); vos.add(vo);
}); });
long time5 = System.currentTimeMillis();
log.info("数据处理时间:{}", time5 - time4);
return vos; return vos;
} }
private StringBuilder getContent(BaiDuVo.GeneralBasic words, Map<String, Integer> keyMap, JSONObject start) { private StringBuilder getContent(List<String> contents, Map<String, Integer> keyMap, JSONObject start) {
StringBuilder builder = new StringBuilder(); StringBuilder builder = new StringBuilder();
String key = start.getString(Constant.BaiDu.KEY); String key = start.getString(Constant.BaiDu.KEY);
int index = start.getIntValue(Constant.BaiDu.NUM); int index = start.getIntValue(Constant.BaiDu.NUM);
if (keyMap.containsKey(key) ) { if (keyMap.containsKey(key) ) {
if (keyMap.get(key) >= 0) { if (keyMap.get(key) >= 0) {
builder.append( words.getWordsResult().get(keyMap.get(key) + index).getWords()); builder.append( contents.get(keyMap.get(key) + index));
} }
} else { } else {
for (int i = 0; i < words.getWordsResultNum(); i++) { for (int i = 0; i < contents.size(); i++) {
BaiDuVo.GeneralWord word = words.getWordsResult().get(i); if (contents.get(i).contains(key)) {
if (word.getWords().contains(key)) { keyMap.put(key.trim(), i);
keyMap.put(key, i); builder.append(contents.get(i + index));
builder.append(words.getWordsResult().get(i + index).getWords());
return builder; return builder;
} }
} }
@ -96,20 +152,18 @@ public class OcrService implements IOcrService {
return builder; return builder;
} }
private StringBuilder getContent(BaiDuVo.GeneralBasic words, JSONObject start, JSONObject end) { private StringBuilder getContent(List<String> contents, JSONObject start, JSONObject end) {
StringBuilder builder = new StringBuilder(); StringBuilder builder = new StringBuilder();
for (int i = 0; i < words.getWordsResult().size(); i++) { for (String content : contents) {
BaiDuVo.GeneralWord word = words.getWordsResult().get(i); String word = content.trim();
String wordStr = word.getWords(); if (start != null && word.startsWith(start.getString(Constant.BaiDu.KEY))) {
if (start != null && wordStr.startsWith(start.getString(Constant.BaiDu.KEY))) {
builder.delete(0, builder.length()); builder.delete(0, builder.length());
builder.append(wordStr); builder.append(word);
} else if (end != null && wordStr.startsWith(end.getString(Constant.BaiDu.KEY))) { } else if (end != null && word.startsWith(end.getString(Constant.BaiDu.KEY))) {
break; break;
} else { } else {
builder.append(wordStr); builder.append(word);
} }
} }
return builder; return builder;
} }

5
tcm/src/main/java/com/ccsens/tcm/service/PatientService.java

@ -3,6 +3,7 @@ package com.ccsens.tcm.service;
import cn.hutool.core.collection.CollectionUtil; import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.lang.Snowflake; import cn.hutool.core.lang.Snowflake;
import cn.hutool.core.util.ObjectUtil; import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import com.ccsens.tcm.bean.dto.BiologicalSamplesDto; import com.ccsens.tcm.bean.dto.BiologicalSamplesDto;
import com.ccsens.tcm.bean.dto.ConRecDto; import com.ccsens.tcm.bean.dto.ConRecDto;
import com.ccsens.tcm.bean.dto.PatientDto; import com.ccsens.tcm.bean.dto.PatientDto;
@ -94,7 +95,7 @@ public class PatientService implements IPatientService {
patientInformation.setId(snowflake.nextId()); patientInformation.setId(snowflake.nextId());
patientInformation.setHospitalId(hospital.getId()); patientInformation.setHospitalId(hospital.getId());
// 生成编号 // 生成编号
long incr = redisUtil.incr(Constant.Redis.HOSPITAL_NUM + hospital.getCode(), 1) + 1; long incr = redisUtil.incr(StrUtil.format(Constant.Redis.HOSPITAL_NUM, hospital.getCode(), inpatient.getCode()) , 1);
DecimalFormat df=new DecimalFormat("000"); DecimalFormat df=new DecimalFormat("000");
String num = hospital.getCode() + inpatient.getCode() + df.format(incr); String num = hospital.getCode() + inpatient.getCode() + df.format(incr);
log.info("编号:{}", num); log.info("编号:{}", num);
@ -357,7 +358,7 @@ public class PatientService implements IPatientService {
biologicalSamples.setId(snowflake.nextId()); biologicalSamples.setId(snowflake.nextId());
biologicalSamples.setPatientInformationId(patientInformations.get(0).getId()); biologicalSamples.setPatientInformationId(patientInformations.get(0).getId());
BeanUtils.copyProperties(param,biologicalSamples); BeanUtils.copyProperties(param,biologicalSamples);
biologicalSamples.setCode(param.getHospitalization() + Constant.SPLIT_STRIKE + Constant.Biological.getByType(param.getSampleType()).getCode() + Constant.SPLIT_STRIKE + param.getCollectTime()); biologicalSamples.setCode(patientInformations.get(0).getCode() + Constant.SPLIT_STRIKE + Constant.Biological.getByType(param.getSampleType()).getCode() + Constant.SPLIT_STRIKE + param.getCollectTime());
biologicalSamplesMapper.insertSelective(biologicalSamples); biologicalSamplesMapper.insertSelective(biologicalSamples);
} }

4
tcm/src/main/java/com/ccsens/tcm/uitl/Constant.java

@ -102,8 +102,8 @@ public class Constant {
public final static String DISEASE_TIME = "disease_time"; public final static String DISEASE_TIME = "disease_time";
/**所有题目按code分类*/ /**所有题目按code分类*/
public final static String CODE_QUESTION = "code_question"; public final static String CODE_QUESTION = "code_question";
/**医院排序*/ /**医院_组别排序*/
public final static String HOSPITAL_NUM = "hospital_num_"; public final static String HOSPITAL_NUM = "hospital_num_{}_{}";
} }
public static class File{ public static class File{

4
tcm/src/main/resources/application.yml

@ -1,5 +1,5 @@
spring: spring:
profiles: profiles:
active: green active: dev
include: common, util-green include: common, util-dev

4
tcm/src/main/resources/mapper_dao/PatientDao.xml

@ -41,6 +41,7 @@
SELECT SELECT
tpi.id, tpi.id,
tpi.hospitalization, tpi.hospitalization,
tpi.code,
tpi.inpatient_id AS inpatientId, tpi.inpatient_id AS inpatientId,
tpi.input_status AS inputStatus, tpi.input_status AS inputStatus,
tpi.hospital_id AS hospitalId, tpi.hospital_id AS hospitalId,
@ -148,6 +149,7 @@
SELECT SELECT
tpi.id, tpi.id,
tpi.hospitalization, tpi.hospitalization,
tpi.code,
tpi.inpatient_id AS inpatientId, tpi.inpatient_id AS inpatientId,
tpi.input_status AS inputStatus, tpi.input_status AS inputStatus,
tpi.hospital_id AS hospitalId, tpi.hospital_id AS hospitalId,
@ -391,7 +393,7 @@
t.user_id t.user_id
</select> </select>
<select id="selBiologicalSamples" resultType="com.ccsens.tcm.bean.vo.BiologicalSamplesVo$selBiolog"> <select id="selBiologicalSamples" resultType="com.ccsens.tcm.bean.vo.BiologicalSamplesVo$selBiolog">
select th.name,tbs.sample_type as sampleType, tpi.hospitalization, tbs.code, tbs.collect_time as collectTime,tbs.update_at as updateAt select th.name,tbs.sample_type as sampleType, tpi.hospitalization, tpi.code as patientCode, tbs.code, tbs.collect_time as collectTime,tbs.update_at as updateAt
from t_biological_samples tbs from t_biological_samples tbs
left join t_patient_information tpi on tpi.id=tbs.patient_information_id and tpi.rec_status=0 left join t_patient_information tpi on tpi.id=tbs.patient_information_id and tpi.rec_status=0
left join t_hospital th on th.id=tpi.hospital_id and th.rec_status=0 left join t_hospital th on th.id=tpi.hospital_id and th.rec_status=0

228
tcm/src/main/resources/mapper_raw/ReportOcrMapper.xml

@ -0,0 +1,228 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.ccsens.tcm.persist.mapper.ReportOcrMapper">
<resultMap id="BaseResultMap" type="com.ccsens.tcm.bean.po.ReportOcr">
<id column="id" jdbcType="BIGINT" property="id" />
<result column="code" jdbcType="VARCHAR" property="code" />
<result column="ocr_channel" jdbcType="TINYINT" property="ocrChannel" />
<result column="created_at" jdbcType="TIMESTAMP" property="createdAt" />
<result column="updated_at" jdbcType="TIMESTAMP" property="updatedAt" />
<result column="rec_status" jdbcType="TINYINT" property="recStatus" />
</resultMap>
<sql id="Example_Where_Clause">
<where>
<foreach collection="oredCriteria" item="criteria" separator="or">
<if test="criteria.valid">
<trim prefix="(" prefixOverrides="and" suffix=")">
<foreach collection="criteria.criteria" item="criterion">
<choose>
<when test="criterion.noValue">
and ${criterion.condition}
</when>
<when test="criterion.singleValue">
and ${criterion.condition} #{criterion.value}
</when>
<when test="criterion.betweenValue">
and ${criterion.condition} #{criterion.value} and #{criterion.secondValue}
</when>
<when test="criterion.listValue">
and ${criterion.condition}
<foreach close=")" collection="criterion.value" item="listItem" open="(" separator=",">
#{listItem}
</foreach>
</when>
</choose>
</foreach>
</trim>
</if>
</foreach>
</where>
</sql>
<sql id="Update_By_Example_Where_Clause">
<where>
<foreach collection="example.oredCriteria" item="criteria" separator="or">
<if test="criteria.valid">
<trim prefix="(" prefixOverrides="and" suffix=")">
<foreach collection="criteria.criteria" item="criterion">
<choose>
<when test="criterion.noValue">
and ${criterion.condition}
</when>
<when test="criterion.singleValue">
and ${criterion.condition} #{criterion.value}
</when>
<when test="criterion.betweenValue">
and ${criterion.condition} #{criterion.value} and #{criterion.secondValue}
</when>
<when test="criterion.listValue">
and ${criterion.condition}
<foreach close=")" collection="criterion.value" item="listItem" open="(" separator=",">
#{listItem}
</foreach>
</when>
</choose>
</foreach>
</trim>
</if>
</foreach>
</where>
</sql>
<sql id="Base_Column_List">
id, code, ocr_channel, created_at, updated_at, rec_status
</sql>
<select id="selectByExample" parameterType="com.ccsens.tcm.bean.po.ReportOcrExample" resultMap="BaseResultMap">
select
<if test="distinct">
distinct
</if>
<include refid="Base_Column_List" />
from t_report_ocr
<if test="_parameter != null">
<include refid="Example_Where_Clause" />
</if>
<if test="orderByClause != null">
order by ${orderByClause}
</if>
</select>
<select id="selectByPrimaryKey" parameterType="java.lang.Long" resultMap="BaseResultMap">
select
<include refid="Base_Column_List" />
from t_report_ocr
where id = #{id,jdbcType=BIGINT}
</select>
<delete id="deleteByPrimaryKey" parameterType="java.lang.Long">
delete from t_report_ocr
where id = #{id,jdbcType=BIGINT}
</delete>
<delete id="deleteByExample" parameterType="com.ccsens.tcm.bean.po.ReportOcrExample">
delete from t_report_ocr
<if test="_parameter != null">
<include refid="Example_Where_Clause" />
</if>
</delete>
<insert id="insert" parameterType="com.ccsens.tcm.bean.po.ReportOcr">
insert into t_report_ocr (id, code, ocr_channel,
created_at, updated_at, rec_status
)
values (#{id,jdbcType=BIGINT}, #{code,jdbcType=VARCHAR}, #{ocrChannel,jdbcType=TINYINT},
#{createdAt,jdbcType=TIMESTAMP}, #{updatedAt,jdbcType=TIMESTAMP}, #{recStatus,jdbcType=TINYINT}
)
</insert>
<insert id="insertSelective" parameterType="com.ccsens.tcm.bean.po.ReportOcr">
insert into t_report_ocr
<trim prefix="(" suffix=")" suffixOverrides=",">
<if test="id != null">
id,
</if>
<if test="code != null">
code,
</if>
<if test="ocrChannel != null">
ocr_channel,
</if>
<if test="createdAt != null">
created_at,
</if>
<if test="updatedAt != null">
updated_at,
</if>
<if test="recStatus != null">
rec_status,
</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="id != null">
#{id,jdbcType=BIGINT},
</if>
<if test="code != null">
#{code,jdbcType=VARCHAR},
</if>
<if test="ocrChannel != null">
#{ocrChannel,jdbcType=TINYINT},
</if>
<if test="createdAt != null">
#{createdAt,jdbcType=TIMESTAMP},
</if>
<if test="updatedAt != null">
#{updatedAt,jdbcType=TIMESTAMP},
</if>
<if test="recStatus != null">
#{recStatus,jdbcType=TINYINT},
</if>
</trim>
</insert>
<select id="countByExample" parameterType="com.ccsens.tcm.bean.po.ReportOcrExample" resultType="java.lang.Long">
select count(*) from t_report_ocr
<if test="_parameter != null">
<include refid="Example_Where_Clause" />
</if>
</select>
<update id="updateByExampleSelective" parameterType="map">
update t_report_ocr
<set>
<if test="record.id != null">
id = #{record.id,jdbcType=BIGINT},
</if>
<if test="record.code != null">
code = #{record.code,jdbcType=VARCHAR},
</if>
<if test="record.ocrChannel != null">
ocr_channel = #{record.ocrChannel,jdbcType=TINYINT},
</if>
<if test="record.createdAt != null">
created_at = #{record.createdAt,jdbcType=TIMESTAMP},
</if>
<if test="record.updatedAt != null">
updated_at = #{record.updatedAt,jdbcType=TIMESTAMP},
</if>
<if test="record.recStatus != null">
rec_status = #{record.recStatus,jdbcType=TINYINT},
</if>
</set>
<if test="_parameter != null">
<include refid="Update_By_Example_Where_Clause" />
</if>
</update>
<update id="updateByExample" parameterType="map">
update t_report_ocr
set id = #{record.id,jdbcType=BIGINT},
code = #{record.code,jdbcType=VARCHAR},
ocr_channel = #{record.ocrChannel,jdbcType=TINYINT},
created_at = #{record.createdAt,jdbcType=TIMESTAMP},
updated_at = #{record.updatedAt,jdbcType=TIMESTAMP},
rec_status = #{record.recStatus,jdbcType=TINYINT}
<if test="_parameter != null">
<include refid="Update_By_Example_Where_Clause" />
</if>
</update>
<update id="updateByPrimaryKeySelective" parameterType="com.ccsens.tcm.bean.po.ReportOcr">
update t_report_ocr
<set>
<if test="code != null">
code = #{code,jdbcType=VARCHAR},
</if>
<if test="ocrChannel != null">
ocr_channel = #{ocrChannel,jdbcType=TINYINT},
</if>
<if test="createdAt != null">
created_at = #{createdAt,jdbcType=TIMESTAMP},
</if>
<if test="updatedAt != null">
updated_at = #{updatedAt,jdbcType=TIMESTAMP},
</if>
<if test="recStatus != null">
rec_status = #{recStatus,jdbcType=TINYINT},
</if>
</set>
where id = #{id,jdbcType=BIGINT}
</update>
<update id="updateByPrimaryKey" parameterType="com.ccsens.tcm.bean.po.ReportOcr">
update t_report_ocr
set code = #{code,jdbcType=VARCHAR},
ocr_channel = #{ocrChannel,jdbcType=TINYINT},
created_at = #{createdAt,jdbcType=TIMESTAMP},
updated_at = #{updatedAt,jdbcType=TIMESTAMP},
rec_status = #{recStatus,jdbcType=TINYINT}
where id = #{id,jdbcType=BIGINT}
</update>
</mapper>

6
util/pom.xml

@ -38,6 +38,12 @@
<artifactId>javase</artifactId> <artifactId>javase</artifactId>
<version>2.0</version> <version>2.0</version>
</dependency> </dependency>
<!--阿里图像识别-->
<dependency>
<groupId>com.aliyun.api.gateway</groupId>
<artifactId>sdk-core-java</artifactId>
<version>1.1.6</version>
</dependency>
</dependencies> </dependencies>

27
util/src/main/java/com/ccsens/util/ali/AliInstanceUtil.java

@ -0,0 +1,27 @@
package com.ccsens.util.ali;
import com.alibaba.cloudapi.sdk.model.HttpClientBuilderParams;
/**
* @description:
* @author: whj
* @time: 2021/4/25 16:53
*/
public class AliInstanceUtil {
private static String appKey = "203933478";
private static String appSecret = "KrDev8GlVu6DyMOhjGSudngDZ8RsslYE";
/**
*
* @return
*/
public static HttpsApiClientlyocr_general_advanced getGeneralAdvancedHttps(){
HttpClientBuilderParams httpsParam = new HttpClientBuilderParams();
httpsParam.setAppKey(appKey);
httpsParam.setAppSecret(appSecret);
HttpsApiClientlyocr_general_advanced instance = HttpsApiClientlyocr_general_advanced.getInstance();
instance.init(httpsParam);
return instance;
}
}

168
util/src/main/java/com/ccsens/util/ali/Demolyocr_general_advanced.java

@ -0,0 +1,168 @@
//
// Created by fred on 2016/10/26.
// Copyright © 2016年 Alibaba. All rights reserved.
//
package com.ccsens.util.ali;
import com.alibaba.cloudapi.sdk.constant.SdkConstant;
import com.alibaba.cloudapi.sdk.model.ApiCallback;
import com.alibaba.cloudapi.sdk.model.ApiRequest;
import com.alibaba.cloudapi.sdk.model.ApiResponse;
import com.alibaba.cloudapi.sdk.model.HttpClientBuilderParams;
import java.io.IOException;
import org.apache.http.config.Registry;
import org.apache.http.config.RegistryBuilder;
import org.apache.http.conn.socket.ConnectionSocketFactory;
import org.apache.http.conn.socket.PlainConnectionSocketFactory;
import org.apache.http.conn.ssl.SSLConnectionSocketFactory;
import org.apache.http.ssl.SSLContextBuilder;
import org.apache.http.ssl.TrustStrategy;
import javax.net.ssl.*;
import java.security.KeyStore;
import java.security.cert.CertificateException;
import java.security.cert.X509Certificate;
public class Demolyocr_general_advanced {
static{
//HTTP Client init
HttpClientBuilderParams httpParam = new HttpClientBuilderParams();
httpParam.setAppKey("203933478");
httpParam.setAppSecret("KrDev8GlVu6DyMOhjGSudngDZ8RsslYE");
HttpApiClientlyocr_general_advanced.getInstance().init(httpParam);
//HTTPS Client init
HttpClientBuilderParams httpsParam = new HttpClientBuilderParams();
httpsParam.setAppKey("203933478");
httpsParam.setAppSecret("KrDev8GlVu6DyMOhjGSudngDZ8RsslYE");
/**
* HTTPS request use DO_NOT_VERIFY mode only for demo
* Suggest verify for security
*/
//httpsParam.setRegistry(getNoVerifyRegistry());
HttpsApiClientlyocr_general_advanced.getInstance().init(httpsParam);
}
public static void ocrAdvancedHttpsTest(){
HttpsApiClientlyocr_general_advanced.getInstance().ocrAdvanced("default".getBytes(SdkConstant.CLOUDAPI_ENCODING) , new ApiCallback() {
@Override
public void onFailure(ApiRequest request, Exception e) {
e.printStackTrace();
}
@Override
public void onResponse(ApiRequest request, ApiResponse response) {
try {
System.out.println(getResultString(response));
}catch (Exception ex){
ex.printStackTrace();
}
}
});
}
public static void ocrAdvancedHttpsSyncTest(){
ApiResponse response = HttpsApiClientlyocr_general_advanced.getInstance().ocrAdvancedSyncMode("default".getBytes(SdkConstant.CLOUDAPI_ENCODING));
try {
System.out.println(getResultString(response));
}catch (Exception ex){
ex.printStackTrace();
}
}
private static String getResultString(ApiResponse response) throws IOException {
StringBuilder result = new StringBuilder();
result.append("Response from backend server").append(SdkConstant.CLOUDAPI_LF).append(SdkConstant.CLOUDAPI_LF);
result.append("ResultCode:").append(SdkConstant.CLOUDAPI_LF).append(response.getCode()).append(SdkConstant.CLOUDAPI_LF).append(SdkConstant.CLOUDAPI_LF);
if(response.getCode() != 200){
result.append("Error description:").append(response.getHeaders().get("X-Ca-Error-Message")).append(SdkConstant.CLOUDAPI_LF).append(SdkConstant.CLOUDAPI_LF);
}
result.append("ResultBody:").append(SdkConstant.CLOUDAPI_LF).append(new String(response.getBody() , SdkConstant.CLOUDAPI_ENCODING));
return result.toString();
}
private static Registry<ConnectionSocketFactory> getNoVerifyRegistry() {
RegistryBuilder<ConnectionSocketFactory> registryBuilder = RegistryBuilder.create();
try {
registryBuilder.register("http", PlainConnectionSocketFactory.INSTANCE).build();
registryBuilder.register(
"https",
new SSLConnectionSocketFactory(new SSLContextBuilder().loadTrustMaterial(
KeyStore.getInstance(KeyStore.getDefaultType()), new TrustStrategy() {
@Override
public boolean isTrusted(X509Certificate[] x509Certificates, String s) throws CertificateException {
return true;
}
}).build(),
new HostnameVerifier() {
@Override
public boolean verify(String paramString, SSLSession paramSSLSession) {
return true;
}
}));
} catch (Exception e) {
throw new RuntimeException("HttpClientUtil init failure !", e);
}
return registryBuilder.build();
}
private static void trustAllHttpsCertificates() throws Exception {
javax.net.ssl.TrustManager[] trustAllCerts = new javax.net.ssl.TrustManager[1];
javax.net.ssl.TrustManager tm = new miTM();
trustAllCerts[0] = tm;
javax.net.ssl.SSLContext sc = javax.net.ssl.SSLContext
.getInstance("SSL");
sc.init(null, trustAllCerts, null);
javax.net.ssl.HttpsURLConnection.setDefaultSSLSocketFactory(sc
.getSocketFactory());
}
static class miTM implements javax.net.ssl.TrustManager,
javax.net.ssl.X509TrustManager {
@Override
public java.security.cert.X509Certificate[] getAcceptedIssuers() {
return null;
}
public boolean isServerTrusted(
java.security.cert.X509Certificate[] certs) {
return true;
}
public boolean isClientTrusted(
java.security.cert.X509Certificate[] certs) {
return true;
}
@Override
public void checkServerTrusted(
java.security.cert.X509Certificate[] certs, String authType)
throws java.security.cert.CertificateException {
return;
}
@Override
public void checkClientTrusted(
java.security.cert.X509Certificate[] certs, String authType)
throws java.security.cert.CertificateException {
return;
}
}
}

34
util/src/main/java/com/ccsens/util/ali/HttpApiClientlyocr_general_advanced.java

@ -0,0 +1,34 @@
//
// Created by fred on 2017/1/12.
// Copyright © 2016年 Alibaba. All rights reserved.
//
package com.ccsens.util.ali;
import com.alibaba.cloudapi.sdk.client.ApacheHttpClient;
import com.alibaba.cloudapi.sdk.enums.Scheme;
import com.alibaba.cloudapi.sdk.enums.HttpMethod;
import com.alibaba.cloudapi.sdk.model.ApiRequest;
import com.alibaba.cloudapi.sdk.model.ApiResponse;
import com.alibaba.cloudapi.sdk.model.ApiCallback;
import com.alibaba.cloudapi.sdk.model.HttpClientBuilderParams;
import com.alibaba.cloudapi.sdk.enums.ParamPosition;
import com.alibaba.cloudapi.sdk.enums.WebSocketApiType;
import com.alibaba.fastjson.JSONObject;
public class HttpApiClientlyocr_general_advanced extends ApacheHttpClient{
public final static String HOST = "ocrapi-advanced.taobao.com";
static HttpApiClientlyocr_general_advanced instance = new HttpApiClientlyocr_general_advanced();
public static HttpApiClientlyocr_general_advanced getInstance(){return instance;}
public void init(HttpClientBuilderParams httpClientBuilderParams){
httpClientBuilderParams.setScheme(Scheme.HTTP);
httpClientBuilderParams.setHost(HOST);
super.init(httpClientBuilderParams);
}
}

50
util/src/main/java/com/ccsens/util/ali/HttpsApiClientlyocr_general_advanced.java

@ -0,0 +1,50 @@
//
// Created by fred on 2017/1/12.
// Copyright © 2016年 Alibaba. All rights reserved.
//
package com.ccsens.util.ali;
import com.alibaba.cloudapi.sdk.client.ApacheHttpClient;
import com.alibaba.cloudapi.sdk.enums.HttpMethod;
import com.alibaba.cloudapi.sdk.enums.ParamPosition;
import com.alibaba.cloudapi.sdk.enums.Scheme;
import com.alibaba.cloudapi.sdk.model.ApiCallback;
import com.alibaba.cloudapi.sdk.model.ApiRequest;
import com.alibaba.cloudapi.sdk.model.ApiResponse;
import com.alibaba.cloudapi.sdk.model.HttpClientBuilderParams;
import com.alibaba.cloudapi.sdk.enums.WebSocketApiType;
import com.alibaba.fastjson.JSONObject;
public class HttpsApiClientlyocr_general_advanced extends ApacheHttpClient{
public final static String HOST = "ocrapi-advanced.taobao.com";
static HttpsApiClientlyocr_general_advanced instance = new HttpsApiClientlyocr_general_advanced();
public static HttpsApiClientlyocr_general_advanced getInstance(){return instance;}
public void init(HttpClientBuilderParams httpClientBuilderParams){
httpClientBuilderParams.setScheme(Scheme.HTTPS);
httpClientBuilderParams.setHost(HOST);
super.init(httpClientBuilderParams);
}
public void ocrAdvanced(byte[] body , ApiCallback callback) {
String path = "/ocrservice/advanced";
ApiRequest request = new ApiRequest(HttpMethod.POST_BODY , path, body);
sendAsyncRequest(request , callback);
}
public ApiResponse ocrAdvancedSyncMode(byte[] body) {
String path = "/ocrservice/advanced";
ApiRequest request = new ApiRequest(HttpMethod.POST_BODY , path, body);
return sendSyncRequest(request);
}
}
Loading…
Cancel
Save