| | |
| | | import org.springframework.data.domain.Sort; |
| | | import org.springframework.data.jpa.domain.Specification; |
| | | import org.springframework.stereotype.Component; |
| | | import sun.misc.BASE64Encoder; |
| | | |
| | | import javax.persistence.criteria.CriteriaBuilder; |
| | | import javax.persistence.criteria.CriteriaQuery; |
| | | import javax.persistence.criteria.Predicate; |
| | | import javax.persistence.criteria.Root; |
| | | import java.io.*; |
| | | import java.util.ArrayList; |
| | | import java.util.Date; |
| | | import java.util.List; |
| | |
| | | predicates.add(predicate2); |
| | | } |
| | | if (null != param.getStart()) { |
| | | Predicate predicate3 = cb.greaterThan(root.<Date>get("qdrq"), ContextUtil.getCurZero(param.getStart())); |
| | | Predicate predicate3 = cb.greaterThan(root.<Date>get("zhgxsj"), ContextUtil.getCurZero(param.getStart())); |
| | | predicates.add(predicate3); |
| | | } |
| | | |
| | | if (null != param.getEnd()) { |
| | | Predicate predicate4 = cb.lessThan(root.<Date>get("qdrq"), ContextUtil.getNextZero(param.getEnd())); |
| | | Predicate predicate4 = cb.lessThan(root.<Date>get("zhgxsj"), ContextUtil.getNextZero(param.getEnd())); |
| | | predicates.add(predicate4); |
| | | } |
| | | return cb.and(predicates.toArray(new Predicate[0])); |
| | |
| | | } |
| | | |
| | | /** |
| | | * |
| | | * |
| | | * 更新删除标记 api1109PR#delUpdate |
| | | * |
| | | * @param entity |
| | |
| | | */ |
| | | @Expose |
| | | public String pushData(List<Api1109> items) { |
| | | ResponseDto responseDto; |
| | | String result = ""; |
| | | Api1109 d; |
| | | |
| | | //获取配置 |
| | | String kqdm = items.get(0).getKqdm(); |
| | | ApiConfs apiConf = apiCommonService.getConf(kqdm); |
| | | |
| | | if (null == apiConf) return "系统没有获取到当前库区配置信息,执行失败"; |
| | | |
| | | //封装参数 |
| | | ApiParam param = new ApiParam(apiConf, Constant.API_CATEGORY_11, Constant.API_CODE_1109); |
| | | |
| | | //获取实现接口 |
| | | ApiRemoteService apiRemoteService = apiPushManager.getApiRemoteService(param.getPushProtocol()); |
| | | ApiRemoteService apiRemoteService = apiPushManager.getApiRemoteService(apiConf.getPushProtocol()); |
| | | if (null == apiRemoteService) return "系统没有当前推送协议配置,执行失败"; |
| | | |
| | | return pushDataSingle(items,apiRemoteService,apiConf); |
| | | } |
| | | |
| | | /** |
| | | * 单条数据json推送 |
| | | * |
| | | * @param items |
| | | * @param apiRemoteService |
| | | * @param apiConf |
| | | * @return |
| | | */ |
| | | private String pushDataSingle(List<Api1109> items, ApiRemoteService apiRemoteService, ApiConfs apiConf) { |
| | | ResponseDto responseDto; |
| | | String result = ""; |
| | | |
| | | //封装参数 |
| | | ApiParam param = new ApiParam(apiConf, Constant.API_CATEGORY_11, Constant.API_CODE_1109); |
| | | Api1109 d; |
| | | for (Api1109 data : items) { |
| | | d = new Api1109(); |
| | | BeanUtils.copyProperties(data, d); |
| | |
| | | return result; |
| | | } |
| | | |
| | | |
| | | /** |
| | | * imgFile 图片本地存储路径 |
| | | * 多条数据json推送 |
| | | * |
| | | * @param items |
| | | * @param apiRemoteService |
| | | * @param apiConf |
| | | * @return |
| | | */ |
| | | public static String getImgFileToBase64(String imgFile) { |
| | | //将图片文件转化为字节数组字符串,并对其进行Base64编码处理 |
| | | InputStream inputStream = null; |
| | | byte[] buffer = null; |
| | | //读取图片字节数组 |
| | | try { |
| | | inputStream = new FileInputStream(imgFile); |
| | | int count = 0; |
| | | while (count == 0) { |
| | | count = inputStream.available(); |
| | | } |
| | | buffer = new byte[count]; |
| | | inputStream.read(buffer); |
| | | } catch (IOException e) { |
| | | log.error(e.getMessage(),e); |
| | | } finally { |
| | | if (inputStream != null) { |
| | | try { |
| | | // 关闭inputStream流 |
| | | inputStream.close(); |
| | | } catch (IOException e) { |
| | | e.printStackTrace(); |
| | | private String pushDataList(List<Api1109> items, ApiRemoteService apiRemoteService, ApiConfs apiConf) { |
| | | |
| | | //封装参数 |
| | | ApiParam param = new ApiParam(apiConf, Constant.API_CATEGORY_11, Constant.API_CODE_1109); |
| | | |
| | | //推送,数据为集合形式 |
| | | ResponseDto responseDto = apiRemoteService.pushData(param, apiConf, items); |
| | | if (responseDto.getSuccess() == 0) { |
| | | //推送成功,更新数据上传状态 |
| | | for (Api1109 data : items) { |
| | | if (Constant.CZBZ_I.equals(data.getCzbz())) { |
| | | //更新状态 |
| | | api1109Rep.updateStatus(data.getId(), Constant.CZBZ_U); |
| | | } |
| | | } |
| | | } |
| | | // 对字节数组Base64编码 |
| | | //return Base64Utils.encodeToString(buffer); |
| | | return new BASE64Encoder().encode(buffer); |
| | | return responseDto.toString(); |
| | | } |
| | | |
| | | /** |
| | | * 获取图片的二进制流 |
| | | * @param imgPath |
| | | * @return |
| | | */ |
| | | @SuppressWarnings("resource") |
| | | public String imgToIo(String imgPath){ |
| | | //图片转化为二进制 |
| | | byte[] imageBytes = null; |
| | | try { |
| | | FileInputStream fileInputStream = new FileInputStream(new File(imgPath)); |
| | | imageBytes = new byte[fileInputStream.available()]; |
| | | fileInputStream.read(imageBytes); |
| | | } catch (IOException e) { |
| | | System.out.println(e); |
| | | return null; |
| | | } |
| | | return UnicodeByteToStr(imageBytes); |
| | | } |
| | | |
| | | private static String UnicodeByteToStr(byte[] b){ |
| | | StringBuilder sb = new StringBuilder(); |
| | | for(int i=0;i<b.length;i++) { |
| | | sb.append(String.format("%02x", b[i])); |
| | | } |
| | | return sb.toString(); |
| | | } |
| | | |
| | | /** |
| | | * 根据文件路径将文件转为二进制数组 |
| | | * @param filePath:文件路径 |
| | | * @return |
| | | */ |
| | | public static byte[] file2byte(String filePath) { |
| | | byte[] buffer = null; |
| | | try { |
| | | File file = new File(filePath); |
| | | FileInputStream fis = new FileInputStream(file); |
| | | ByteArrayOutputStream bos = new ByteArrayOutputStream(); |
| | | byte[] b = new byte[1024]; |
| | | int n; |
| | | while ((n = fis.read(b)) != -1) { |
| | | bos.write(b, 0, n); |
| | | } |
| | | fis.close(); |
| | | bos.close(); |
| | | buffer = bos.toByteArray(); |
| | | } catch (FileNotFoundException e) { |
| | | e.printStackTrace(); |
| | | } catch (IOException e) { |
| | | e.printStackTrace(); |
| | | } |
| | | return buffer; |
| | | } |
| | | |
| | | /** |
| | | * 将二进制数组转为字符串 |
| | | * @param b |
| | | * @return |
| | | */ |
| | | public static String toHexString(byte[] b) { |
| | | StringBuilder sb = new StringBuilder(); |
| | | String stmp=""; |
| | | for (int n=0;n<b.length;n++) { |
| | | stmp=(Integer.toHexString(b[n] & 0XFF)); |
| | | if (stmp.length()==1) sb.append("0"+stmp); |
| | | else sb.append(stmp); |
| | | } |
| | | return sb.toString().toUpperCase(); |
| | | } |
| | | |
| | | |
| | | public static void main(String[] args) { |
| | | String hex = toHexString(file2byte("E://91511424746940066Y001.jpg")); |
| | | System.out.println(hex); |
| | | saveToImgFile(hex,"E://dd.jpg"); |
| | | } |
| | | |
| | | |
| | | public static void saveToImgFile(String src,String output){ |
| | | if(src==null||src.length()==0){ |
| | | return; |
| | | } |
| | | try{ |
| | | FileOutputStream out = new FileOutputStream(new File(output)); |
| | | byte[] bytes = src.getBytes(); |
| | | for(int i=0;i<bytes.length;i+=2){ |
| | | out.write(charToInt(bytes[i])*16+charToInt(bytes[i+1])); |
| | | } |
| | | out.close(); |
| | | }catch(Exception e){ |
| | | e.printStackTrace(); |
| | | } |
| | | } |
| | | private static int charToInt(byte ch){ |
| | | int val = 0; |
| | | if(ch>=0x30&&ch<=0x39){ |
| | | val=ch-0x30; |
| | | }else if(ch>=0x41&&ch<=0x46){ |
| | | val=ch-0x41+10; |
| | | } |
| | | return val; |
| | | } |
| | | } |