|
@@ -0,0 +1,239 @@
|
|
|
|
+package com.huimv.manage.service.impl;
|
|
|
|
+
|
|
|
|
+import com.alibaba.fastjson.JSONArray;
|
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
|
+import com.huimv.manage.dao.entity.EtApplyEntity;
|
|
|
|
+import com.huimv.manage.dao.entity.EtEarmarkEntity;
|
|
|
|
+import com.huimv.manage.dao.entity.EtPackageEntity;
|
|
|
|
+import com.huimv.manage.dao.repo.EarmarkRepo;
|
|
|
|
+import com.huimv.manage.dao.repo.PackageRepo;
|
|
|
|
+import com.huimv.manage.service.IEarmarkService;
|
|
|
|
+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.EarmarkTask;
|
|
|
|
+import com.huimv.manage.webservice.task.PackageTask;
|
|
|
|
+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
|
|
|
|
+public class EarmarkServiceImpl implements IEarmarkService {
|
|
|
|
+ @Value("${webservice.url}")
|
|
|
|
+ private String webServiceUrl;
|
|
|
|
+ @Autowired
|
|
|
|
+ private EarmarkRepo earmarkRepo;
|
|
|
|
+ @Autowired
|
|
|
|
+ private EarmarkTask earmarkTask;
|
|
|
|
+ @Autowired
|
|
|
|
+ private Soap soap;
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * @Method : listEarmark
|
|
|
|
+ * @Description : 展示列表
|
|
|
|
+ * @Params : [pageSize]
|
|
|
|
+ * @Return : com.huimv.manage.util.Result
|
|
|
|
+ *
|
|
|
|
+ * @Author : ZhuoNing
|
|
|
|
+ * @Date : 2021/10/29
|
|
|
|
+ * @Time : 21:14
|
|
|
|
+ */
|
|
|
|
+ @Override
|
|
|
|
+ public Result listEarmark(int pageSize) {
|
|
|
|
+ //
|
|
|
|
+ List<EtEarmarkEntity> earmarkEntityList = earmarkRepo.listEarmark(pageSize);
|
|
|
|
+ return new Result(ResultCode.SUCCESS,earmarkEntityList);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * @Method : getEarmark
|
|
|
|
+ * @Description : 下载耳标号
|
|
|
|
+ * @Params : [applyId]
|
|
|
|
+ * @Return : com.huimv.manage.util.Result
|
|
|
|
+ *
|
|
|
|
+ * @Author : ZhuoNing
|
|
|
|
+ * @Date : 2021/10/29
|
|
|
|
+ * @Time : 21:14
|
|
|
|
+ */
|
|
|
|
+ @Override
|
|
|
|
+ public Result getEarmark(int applyId) throws UnsupportedEncodingException {
|
|
|
|
+ // 构造请求
|
|
|
|
+ String requestXML = earmarkTask.getRequestEarmarkXML(applyId);
|
|
|
|
+ System.out.println("requestXML="+requestXML);
|
|
|
|
+
|
|
|
|
+ // 调用接口返回结果
|
|
|
|
+ String earMarkReponseXML = soap.callSoap(requestXML,webServiceUrl);
|
|
|
|
+ System.out.println("earMarkReponseXML="+earMarkReponseXML);
|
|
|
|
+
|
|
|
|
+ // 解析结果
|
|
|
|
+ JSONArray downloadEarmarkJa = earmarkTask.parseEarMarkReponseXML(earMarkReponseXML);
|
|
|
|
+ // 耳标入库
|
|
|
|
+ JSONArray newEarmarkJa = filterEarmark(downloadEarmarkJa);
|
|
|
|
+ if(newEarmarkJa.size() == 0){
|
|
|
|
+ return new Result(Const.CODE_NO_NEW_EARMARK,Const.NO_NEW_EARMARK,false);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ for(int a=0;a<newEarmarkJa.size();a++){
|
|
|
|
+ JSONObject earmarkJo = newEarmarkJa.getJSONObject(a);
|
|
|
|
+ EtEarmarkEntity earmarkEntity = new EtEarmarkEntity();
|
|
|
|
+ earmarkEntity.setEarmarkId(earmarkJo.getString("earmarkId"));
|
|
|
|
+ earmarkEntity.setPackageId(earmarkJo.getString("packageId"));
|
|
|
|
+ earmarkEntity.setEarmarkNumber(earmarkJo.getString("earmarkNumber"));
|
|
|
|
+ earmarkEntity.setApplyId(earmarkJo.getString("applyId"));
|
|
|
|
+ earmarkEntity.setEarmarkData(earmarkJo.getString("earmarkData"));
|
|
|
|
+ earmarkRepo.saveAndFlush(earmarkEntity);
|
|
|
|
+ }
|
|
|
|
+ return new Result(Const.CODE_OK,"本次下载"+newEarmarkJa.size()+"个新耳标号数据.",false);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * @Method : setUpdateDownState
|
|
|
|
+ * @Description : 设置耳标已下载状态
|
|
|
|
+ * @Params : [earmarkIDs]
|
|
|
|
+ * @Return : com.huimv.manage.util.Result
|
|
|
|
+ *
|
|
|
|
+ * @Author : ZhuoNing
|
|
|
|
+ * @Date : 2021/10/29
|
|
|
|
+ * @Time : 23:00
|
|
|
|
+ */
|
|
|
|
+ @Override
|
|
|
|
+ public Result setUpdateDownState(String earmarkIDs) throws UnsupportedEncodingException {
|
|
|
|
+ //构造请求字符串
|
|
|
|
+ String requestXML = earmarkTask.getUpdateDownStateRequestXML(earmarkIDs);
|
|
|
|
+ //远程调用返回结果
|
|
|
|
+ String reponseXML = "";
|
|
|
|
+ reponseXML = soap.callSoap(requestXML,webServiceUrl);
|
|
|
|
+ // test
|
|
|
|
+// reponseXML = earmarkTask.TestParseUpdateDownStateXML();
|
|
|
|
+ //解析
|
|
|
|
+ String updateDownState = earmarkTask.parseUpdateDownStateXML(reponseXML);
|
|
|
|
+ // 入库
|
|
|
|
+ if(updateDownState.trim().equalsIgnoreCase("false")){
|
|
|
|
+ return new Result(Const.CODE_UPDATE_EARMARK_DOWN_STATE_FAIL,Const.UPDATE_EARMARK_DOWN_STATE_FAIL,false);
|
|
|
|
+ }else{
|
|
|
|
+ String[] earmarkIDArray = earmarkIDs.split(",");
|
|
|
|
+ for(int a=0;a<earmarkIDArray.length;a++){
|
|
|
|
+ EtEarmarkEntity earmarkEntity = new EtEarmarkEntity();
|
|
|
|
+ earmarkEntity.setEarmarkId(earmarkIDArray[a]);
|
|
|
|
+ ExampleMatcher matcher = ExampleMatcher.matching()
|
|
|
|
+ .withMatcher("earmark_id" ,ExampleMatcher.GenericPropertyMatchers.contains());
|
|
|
|
+ Example example = Example.of(earmarkEntity,matcher);
|
|
|
|
+ Optional optional= earmarkRepo.findOne(example);
|
|
|
|
+ if (optional.isPresent()){
|
|
|
|
+ EtEarmarkEntity earmarkEntity1 = (EtEarmarkEntity) optional.get();
|
|
|
|
+ earmarkEntity1.setSetDownState(1);
|
|
|
|
+ earmarkEntity1.setSetDownDate(new Timestamp(new Date().getTime()));
|
|
|
|
+ earmarkRepo.saveAndFlush(earmarkEntity1);
|
|
|
|
+ }else{
|
|
|
|
+ return new Result(Const.CODE_NO_RECORD,Const.NO_RECORD,false);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ return new Result(ResultCode.SUCCESS);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * @Method : setProduceState
|
|
|
|
+ * @Description : 设置生产状态
|
|
|
|
+ * @Params : [ids]
|
|
|
|
+ * @Return : com.huimv.manage.util.Result
|
|
|
|
+ *
|
|
|
|
+ * @Author : ZhuoNing
|
|
|
|
+ * @Date : 2021/10/29
|
|
|
|
+ * @Time : 23:56
|
|
|
|
+ */
|
|
|
|
+ @Override
|
|
|
|
+ public Result setProduceState(String ids,int state) {
|
|
|
|
+ String[] idArray = ids.split(",");
|
|
|
|
+ for(int a=0;a<idArray.length;a++){
|
|
|
|
+ Optional optional = earmarkRepo.findById(Integer.parseInt(idArray[a]));
|
|
|
|
+ EtEarmarkEntity earmarkEntity = (EtEarmarkEntity) optional.get();
|
|
|
|
+ earmarkEntity.setSetWriteState(state);
|
|
|
|
+ earmarkEntity.setSetWriteDate(new Timestamp(new Date().getTime()));
|
|
|
|
+ earmarkRepo.saveAndFlush(earmarkEntity);
|
|
|
|
+ }
|
|
|
|
+ return new Result(ResultCode.SUCCESS);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * @Method : setWriteState
|
|
|
|
+ * @Description : 设置写入时间
|
|
|
|
+ * @Params : [ids, state]
|
|
|
|
+ * @Return : com.huimv.manage.util.Result
|
|
|
|
+ *
|
|
|
|
+ * @Author : ZhuoNing
|
|
|
|
+ * @Date : 2021/10/30
|
|
|
|
+ * @Time : 0:02
|
|
|
|
+ */
|
|
|
|
+ @Override
|
|
|
|
+ public Result setWriteState(String ids, int state) {
|
|
|
|
+ String[] idArray = ids.split(",");
|
|
|
|
+ for(int a=0;a<idArray.length;a++){
|
|
|
|
+ Optional optional = earmarkRepo.findById(Integer.parseInt(idArray[a]));
|
|
|
|
+ EtEarmarkEntity earmarkEntity = (EtEarmarkEntity) optional.get();
|
|
|
|
+ earmarkEntity.setSetWriteState(state);
|
|
|
|
+ earmarkEntity.setSetWriteDate(new Timestamp(new Date().getTime()));
|
|
|
|
+ earmarkRepo.saveAndFlush(earmarkEntity);
|
|
|
|
+ }
|
|
|
|
+ return new Result(ResultCode.SUCCESS);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * @Method : setPrintState
|
|
|
|
+ * @Description : 设置打码状态
|
|
|
|
+ * @Params : [ids, state]
|
|
|
|
+ * @Return : com.huimv.manage.util.Result
|
|
|
|
+ *
|
|
|
|
+ * @Author : ZhuoNing
|
|
|
|
+ * @Date : 2021/10/30
|
|
|
|
+ * @Time : 0:04
|
|
|
|
+ */
|
|
|
|
+ @Override
|
|
|
|
+ public Result setPrintState(String ids, int state) {
|
|
|
|
+ String[] idArray = ids.split(",");
|
|
|
|
+ for(int a=0;a<idArray.length;a++){
|
|
|
|
+ Optional optional = earmarkRepo.findById(Integer.parseInt(idArray[a]));
|
|
|
|
+ EtEarmarkEntity earmarkEntity = (EtEarmarkEntity) optional.get();
|
|
|
|
+ earmarkEntity.setSetPrintState(state);
|
|
|
|
+ earmarkEntity.setSetPrintDate(new Timestamp(new Date().getTime()));
|
|
|
|
+ earmarkRepo.saveAndFlush(earmarkEntity);
|
|
|
|
+ }
|
|
|
|
+ return new Result(ResultCode.SUCCESS);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ //过滤已经存在的耳标号
|
|
|
|
+ private JSONArray filterEarmark(JSONArray downloadEarmarkJa) {
|
|
|
|
+ JSONArray newEarmarkJa = new JSONArray();
|
|
|
|
+ for(int a=0;a<downloadEarmarkJa.size();a++){
|
|
|
|
+ JSONObject downloadEarmarkJo = downloadEarmarkJa.getJSONObject(a);
|
|
|
|
+ String earmarkId = downloadEarmarkJo.getString("earmarkId");
|
|
|
|
+
|
|
|
|
+ EtEarmarkEntity earmarkEntity = new EtEarmarkEntity();
|
|
|
|
+ earmarkEntity.setEarmarkId(earmarkId);
|
|
|
|
+ ExampleMatcher matcher = ExampleMatcher.matching()
|
|
|
|
+ .withMatcher("earmark_id" ,ExampleMatcher.GenericPropertyMatchers.contains());
|
|
|
|
+ Example example = Example.of(earmarkEntity,matcher);
|
|
|
|
+ if(!earmarkRepo.exists(example)){
|
|
|
|
+ newEarmarkJa.add(downloadEarmarkJo);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ return newEarmarkJa;
|
|
|
|
+ }
|
|
|
|
+}
|