|
@@ -0,0 +1,168 @@
|
|
|
+package com.huimv.manage.service.impl;
|
|
|
+
|
|
|
+import com.alibaba.fastjson.JSONArray;
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
+import com.huimv.manage.dao.entity.EtPackageEntity;
|
|
|
+import com.huimv.manage.dao.repo.PackageRepo;
|
|
|
+import com.huimv.manage.service.IPackageService;
|
|
|
+import com.huimv.manage.util.Const;
|
|
|
+import com.huimv.manage.util.Result;
|
|
|
+import com.huimv.manage.util.ResultCode;
|
|
|
+import com.huimv.manage.webservice.Soap;
|
|
|
+import com.huimv.manage.webservice.task.NewPackage;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.beans.factory.annotation.Value;
|
|
|
+import org.springframework.data.domain.Example;
|
|
|
+import org.springframework.data.domain.ExampleMatcher;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+
|
|
|
+import java.io.UnsupportedEncodingException;
|
|
|
+import java.sql.Timestamp;
|
|
|
+import java.util.Date;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Optional;
|
|
|
+
|
|
|
+/**
|
|
|
+ * @Project : huimv.shiwan
|
|
|
+ * @Package : com.huimv.biosafety.uface.controller
|
|
|
+ * @Description : TODO
|
|
|
+ * @Version : 1.0
|
|
|
+ * @Author : ZhuoNing
|
|
|
+ * @Create : 2020-12-25
|
|
|
+ **/
|
|
|
+@Service
|
|
|
+@Slf4j
|
|
|
+public class PackageServiceImpl implements IPackageService {
|
|
|
+ @Value("${webservice.url}")
|
|
|
+ private String webServiceUrl;
|
|
|
+ @Autowired
|
|
|
+ private PackageRepo packageRepo;
|
|
|
+ @Autowired
|
|
|
+ private NewPackage newPackage;
|
|
|
+ @Autowired
|
|
|
+ private Soap soap;
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Result listPackage(int pageSize) {
|
|
|
+ List<EtPackageEntity> packageEntityList = packageRepo.listPackage(pageSize);
|
|
|
+ return new Result(ResultCode.SUCCESS,packageEntityList);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @Method : getNewPackage
|
|
|
+ * @Description :
|
|
|
+ * @Params : [applyId]
|
|
|
+ * @Return : com.huimv.manage.util.Result
|
|
|
+ *
|
|
|
+ * @Author : ZhuoNing
|
|
|
+ * @Date : 2021/10/29
|
|
|
+ * @Time : 16:08
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public Result getNewPackage(int applyId) throws UnsupportedEncodingException {
|
|
|
+ // Step1.下载新批次数据
|
|
|
+ // Step2.新批次数据入库
|
|
|
+
|
|
|
+ //调用接口获取远程数据
|
|
|
+ String answerXML = soap.callSoap(newPackage.getNewPackageRequestXML(applyId),webServiceUrl);
|
|
|
+ log.info("应答文件="+answerXML);
|
|
|
+
|
|
|
+ //解析应答数据
|
|
|
+ JSONArray downPackageJa = newPackage.parseNewPackageAnswerXML(answerXML);
|
|
|
+ System.out.println("downPackageJa.zie="+downPackageJa.size());
|
|
|
+
|
|
|
+ // 过滤已经存在批次数据
|
|
|
+ JSONArray newPackageJa = filterPackage(downPackageJa);
|
|
|
+ if(newPackageJa.size() == 0){
|
|
|
+ return new Result(Const.CODE_PACKAGE_EXIST, Const.PACKAGE_EXIST,false);
|
|
|
+ }
|
|
|
+
|
|
|
+ //新批次数据入库
|
|
|
+ for(int a=0;a<newPackageJa.size();a++){
|
|
|
+ JSONObject packageJo = newPackageJa.getJSONObject(a);
|
|
|
+ EtPackageEntity newPackageEntity = new EtPackageEntity();
|
|
|
+ newPackageEntity.setPackageId(packageJo.getIntValue("packageId"));
|
|
|
+ newPackageEntity.setPackageNumber(packageJo.getString("packageNumber"));
|
|
|
+ newPackageEntity.setApplyId(packageJo.getIntValue("applyID"));
|
|
|
+ newPackageEntity.setPackageData(packageJo.getString("packageData"));
|
|
|
+ newPackageEntity.setDownloadDate(new Timestamp(new Date().getTime()));
|
|
|
+ packageRepo.saveAndFlush(newPackageEntity);
|
|
|
+ }
|
|
|
+ return new Result(Const.CODE_OK,Const.SAVE_NEW_PACKAGE,true);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @Method : setReturnDownloadState
|
|
|
+ * @Description :
|
|
|
+ * @Params : [packageIds, ids]
|
|
|
+ * @Return : com.huimv.manage.util.Result
|
|
|
+ *
|
|
|
+ * @Author : ZhuoNing
|
|
|
+ * @Date : 2021/10/29
|
|
|
+ * @Time : 19:15
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public Result setReturnDownloadState(String packageIds,String ids) throws UnsupportedEncodingException {
|
|
|
+ String[] packageIdArray = packageIds.split(",");
|
|
|
+ String[] idArray = ids.split(",");
|
|
|
+
|
|
|
+ // 构造请求XML
|
|
|
+ String requestXML = newPackage.getReturnPackageHasDownloadXML(packageIdArray);
|
|
|
+ String answerXML = "";
|
|
|
+ // 提交请求
|
|
|
+ answerXML = soap.callSoap(requestXML,webServiceUrl);
|
|
|
+ // 解析报文
|
|
|
+ String setReturnState = newPackage.parseAnswerXML(answerXML);
|
|
|
+ if(setReturnState.trim().equalsIgnoreCase("false")){
|
|
|
+ return new Result(Const.CODE_UPDATE_PACKAGE_STATE_DOWN_FAIL,Const.UPDATE_PACKAGE_DOWN_STATE_FAIL,false);
|
|
|
+ }
|
|
|
+ // 将返回结果入库
|
|
|
+ for(int a=0;a<idArray.length;a++){
|
|
|
+ System.out.println("idArray["+a+"]>>"+idArray[a]);
|
|
|
+ Optional optional = packageRepo.findById(Integer.parseInt(idArray[a]));
|
|
|
+ if(optional.isPresent()){
|
|
|
+ EtPackageEntity packageEntity = (EtPackageEntity) optional.get();
|
|
|
+ packageEntity.setSetDownState(1);
|
|
|
+ packageEntity.setSetDownStateDate(new Timestamp(new Date().getTime()));
|
|
|
+ packageRepo.saveAndFlush(packageEntity);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return new Result(ResultCode.SUCCESS);
|
|
|
+ }
|
|
|
+
|
|
|
+ //过滤已经存在的批次数据
|
|
|
+ private JSONArray filterPackage(JSONArray downPackageJa) {
|
|
|
+ JSONArray newApplyJa = new JSONArray();
|
|
|
+ // 过滤已经入库的批次数据
|
|
|
+ for(int a=0;a<downPackageJa.size();a++){
|
|
|
+ JSONObject packageJo = downPackageJa.getJSONObject(a);
|
|
|
+ int packageId = packageJo.getIntValue("packageId");
|
|
|
+ String packageNumber = packageJo.getString("packageNumber");
|
|
|
+ EtPackageEntity packageEntity = new EtPackageEntity();
|
|
|
+ packageEntity.setPackageId(packageId);
|
|
|
+ packageEntity.setPackageNumber(packageNumber);
|
|
|
+ ExampleMatcher matcher = ExampleMatcher.matching()
|
|
|
+ .withMatcher("package_id" ,ExampleMatcher.GenericPropertyMatchers.contains())
|
|
|
+ .withMatcher("package_number",ExampleMatcher.GenericPropertyMatchers.contains());
|
|
|
+ Example example = Example.of(packageEntity,matcher);
|
|
|
+ if(!packageRepo.exists(example)){
|
|
|
+ newApplyJa.add(packageJo);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return newApplyJa;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Result setProduceState(String ids, int state) {
|
|
|
+ String[] idArray = ids.split(",");
|
|
|
+ for(int a=0;a<idArray.length;a++){
|
|
|
+ Optional optional = packageRepo.findById(Integer.parseInt(idArray[a]));
|
|
|
+ EtPackageEntity packageEntity = (EtPackageEntity) optional.get();
|
|
|
+ packageEntity.setProduceState(state);
|
|
|
+ packageEntity.setProduceStateDate(new Timestamp(new Date().getTime()));
|
|
|
+ packageRepo.saveAndFlush(packageEntity);
|
|
|
+ }
|
|
|
+ return new Result(ResultCode.SUCCESS);
|
|
|
+ }
|
|
|
+}
|