|
|
@@ -0,0 +1,256 @@
|
|
|
+package org.springblade.los.sldc;
|
|
|
+
|
|
|
+import com.alibaba.fastjson.JSON;
|
|
|
+import com.alibaba.fastjson.JSONArray;
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
+import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
|
|
|
+import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
|
|
|
+import io.swagger.annotations.Api;
|
|
|
+import io.swagger.annotations.ApiOperation;
|
|
|
+import lombok.AllArgsConstructor;
|
|
|
+import org.springblade.core.secure.utils.AuthUtil;
|
|
|
+import org.springblade.core.tool.api.R;
|
|
|
+import org.springblade.los.basic.corps.service.IBCorpsService;
|
|
|
+import org.springblade.los.business.sea.entity.*;
|
|
|
+import org.springblade.los.business.sea.service.IBillsService;
|
|
|
+import org.springblade.los.business.sea.service.IContainersService;
|
|
|
+import org.springblade.los.business.sea.service.IPreContainersService;
|
|
|
+import org.springblade.los.external.Luhaitong.ApiController;
|
|
|
+import org.springblade.system.feign.ISysClient;
|
|
|
+import org.springframework.web.bind.annotation.*;
|
|
|
+
|
|
|
+import org.springblade.los.basic.corps.entity.BCorps;
|
|
|
+
|
|
|
+import javax.validation.Valid;
|
|
|
+import java.io.BufferedReader;
|
|
|
+import java.io.IOException;
|
|
|
+import java.io.InputStreamReader;
|
|
|
+import java.math.BigDecimal;
|
|
|
+import java.net.HttpURLConnection;
|
|
|
+import java.net.URL;
|
|
|
+import java.rmi.RemoteException;
|
|
|
+import java.util.List;
|
|
|
+
|
|
|
+@RestController
|
|
|
+@AllArgsConstructor
|
|
|
+@RequestMapping("/sldcApi")
|
|
|
+@Api(value = "海运出口场站箱封号接口", tags = "海运出口场站箱封号接口")
|
|
|
+public class sldcApiController {
|
|
|
+ private final ISysClient sysClient;
|
|
|
+
|
|
|
+ private final IBillsService billsService;
|
|
|
+ private final IPreContainersService preContainersService;
|
|
|
+ private final IContainersService containersService;
|
|
|
+
|
|
|
+ private final IBCorpsService corpsService;
|
|
|
+
|
|
|
+ private final ApiController lht;
|
|
|
+
|
|
|
+ @GetMapping("/detail")
|
|
|
+ public R detail(@RequestParam("id") String id ) throws IOException {
|
|
|
+ Bills bill = billsService.getOne(new LambdaQueryWrapper<Bills>()
|
|
|
+ .select(Bills::getId, Bills::getBillNo, Bills::getCarrierId, Bills::getCarrierShortName,
|
|
|
+ Bills::getBookingNo, Bills::getMblno, Bills::getCyId, Bills::getCyCode)
|
|
|
+ .eq(Bills::getId, id)
|
|
|
+ .eq(Bills::getTenantId, AuthUtil.getTenantId())
|
|
|
+ .eq(Bills::getIsDeleted, 0));
|
|
|
+ if(ObjectUtils.isNull(bill)){
|
|
|
+ throw new RemoteException("id " + id + " 不存在,无法查询箱封号!");
|
|
|
+ }
|
|
|
+
|
|
|
+ // CarrierId==10 QDCMA
|
|
|
+ // CarrierId==18 QDPIL
|
|
|
+ // CarrierId==19 QDHAPAG
|
|
|
+ // CarrierId==11207 QDONE
|
|
|
+ // CarrierId==8,MSC,地中海航运
|
|
|
+ Long carrierId = bill.getCarrierId();
|
|
|
+ String mblNo = carrierId==8 ? bill.getBookingNo() : bill.getMblno();
|
|
|
+ if(ObjectUtils.isNull(mblNo) || mblNo.isEmpty()){
|
|
|
+ throw new RemoteException("该业务没有录入提单号,无法查询箱封号!");
|
|
|
+ }
|
|
|
+
|
|
|
+ Long cyId = ObjectUtils.isNotNull(bill.getCyId()) ? bill.getCyId() : 0;
|
|
|
+ String cyCode = "";
|
|
|
+ if(cyId>0){
|
|
|
+ BCorps cyCorp = corpsService.getOne(new LambdaQueryWrapper<BCorps>()
|
|
|
+ .select(BCorps::getId, BCorps::getUnCode)
|
|
|
+ .eq(BCorps::getId, cyId)
|
|
|
+ .eq(BCorps::getTenantId, AuthUtil.getTenantId())
|
|
|
+ .eq(BCorps::getIsDeleted, 0));
|
|
|
+ if(ObjectUtils.isNotNull(cyCorp)){
|
|
|
+ cyCode = (ObjectUtils.isNotNull(cyCorp.getUnCode()) ? cyCorp.getUnCode() : "").toLowerCase();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (cyCode.isEmpty()){
|
|
|
+ throw new RemoteException("场站没有录入或场站代码没有维护,不能查询!");
|
|
|
+ }
|
|
|
+
|
|
|
+ if(cyCode.compareTo("cygj")==0) cyCode = "glj";
|
|
|
+ if(cyCode.compareTo("cygf")==0) cyCode = "gjf";
|
|
|
+ if (",glr,glj,glx,glhai,glhua,gjf,".contains("," + cyCode + ",")){
|
|
|
+ R r = lht.detail(mblNo, cyCode);
|
|
|
+ return r;
|
|
|
+ }
|
|
|
+
|
|
|
+ String url = "http://112.6.239.197:8096/sldc/ContainerTracking/json?";
|
|
|
+ url += "mblNo=" + mblNo;
|
|
|
+ url += "&containerNo=";
|
|
|
+ url += "&bookingNo=";
|
|
|
+ url += "&customerCode=" + cyCode;
|
|
|
+
|
|
|
+ URL Url = new URL(url); // 把字符串转换为URL请求地址
|
|
|
+ HttpURLConnection connection = (HttpURLConnection) Url.openConnection();// 打开连接
|
|
|
+ connection.setRequestMethod("GET");
|
|
|
+ // 添加自定义的Header信息
|
|
|
+ connection.addRequestProperty("Host", "112.6.239.197");
|
|
|
+ connection.connect();// 连接会话
|
|
|
+
|
|
|
+ // 获取输入流
|
|
|
+ BufferedReader br = new BufferedReader(new InputStreamReader(connection.getInputStream()));
|
|
|
+ String line;
|
|
|
+ StringBuilder sb = new StringBuilder();
|
|
|
+ while ((line = br.readLine()) != null) {// 循环读取流
|
|
|
+ sb.append(line);
|
|
|
+ }
|
|
|
+ br.close();// 关闭流
|
|
|
+ connection.disconnect();// 断开连接
|
|
|
+
|
|
|
+ JSONObject js = JSON.parseObject(sb.toString());
|
|
|
+ JSONArray jaCntrs = null;
|
|
|
+ if(ObjectUtils.isNotNull(js) && js.containsKey("main")){
|
|
|
+ JSONObject main = js.getJSONObject("main");
|
|
|
+ if(main.containsKey("data")){
|
|
|
+ JSONObject jsData = main.getJSONObject("data");
|
|
|
+ if(jsData.containsKey("containers")){
|
|
|
+ jaCntrs = jsData.getJSONArray("containers");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ JSONArray cntrs = JSON.parseArray("[]");
|
|
|
+
|
|
|
+ if(ObjectUtils.isNotNull(jaCntrs) && jaCntrs.size()>0){
|
|
|
+ // 根据船公司查询箱型
|
|
|
+ // CarrierId==10 QDCMA
|
|
|
+ // CarrierId==18 QDPIL
|
|
|
+ // CarrierId==19 QDHAPAG
|
|
|
+ // CarrierId==11207 QDONE
|
|
|
+ Boolean flag = false;
|
|
|
+ if(carrierId==10 || carrierId==18 || carrierId==19 || carrierId==11207){
|
|
|
+ LambdaQueryWrapper<PreContainers> qry = new LambdaQueryWrapper<PreContainers>();
|
|
|
+ qry.eq(PreContainers::getTenantId, AuthUtil.getTenantId())
|
|
|
+ .eq(PreContainers::getIsDeleted, 0)
|
|
|
+ .eq(PreContainers::getPid, bill.getId());
|
|
|
+ if(carrierId==19 || carrierId==11207){
|
|
|
+ qry.eq(PreContainers::getCntrTypeCode, "40NOR");
|
|
|
+ }
|
|
|
+ if(carrierId==10){
|
|
|
+ qry.and(q->q.eq(PreContainers::getCntrTypeCode, "40NOR").or().eq(PreContainers::getCntrTypeCode, "40HQ"));
|
|
|
+ }
|
|
|
+ if(carrierId==18){
|
|
|
+ qry.eq(PreContainers::getCntrTypeCode, "40HQ");
|
|
|
+ }
|
|
|
+
|
|
|
+ int pc = preContainersService.count(qry);
|
|
|
+ flag = pc>0;
|
|
|
+ }
|
|
|
+
|
|
|
+ List<PreContainers> preContainersList = preContainersService.list(new LambdaQueryWrapper<PreContainers>()
|
|
|
+ .eq(PreContainers::getIsDeleted, 0)
|
|
|
+ .eq(PreContainers::getTenantId, AuthUtil.getTenantId())
|
|
|
+ .eq(PreContainers::getPid, bill.getId()));
|
|
|
+
|
|
|
+ List<Containers> containersList = containersService.list(new LambdaQueryWrapper<Containers>()
|
|
|
+ .eq(Containers::getIsDeleted, 0)
|
|
|
+ .eq(Containers::getTenantId, AuthUtil.getTenantId())
|
|
|
+ .eq(Containers::getPid, bill.getId()));
|
|
|
+
|
|
|
+ for (Object jaCntr : jaCntrs) {
|
|
|
+ JSONObject jc = (JSONObject) jaCntr;
|
|
|
+ JSONObject jo = new JSONObject();
|
|
|
+ jo.put("index", cntrs.size() + 1);
|
|
|
+ jo.put("mblNo", jc.getString("mblno"));
|
|
|
+
|
|
|
+ String cntrNo = jc.getString("containerno").trim();
|
|
|
+ String ct = jc.getString("containertype").trim();
|
|
|
+
|
|
|
+ jo.put("cntrNo", cntrNo);
|
|
|
+ jo.put("sealNo", jc.getString("containersealno"));
|
|
|
+ if(flag && (carrierId==19 || carrierId==11207)) {
|
|
|
+ ct = ct.replace("RH", "NOR");
|
|
|
+ }
|
|
|
+ if(flag && (carrierId==10)) {
|
|
|
+ ct = ct.replace("HC", "HQ");
|
|
|
+ }
|
|
|
+ if(flag && (carrierId==18)) {
|
|
|
+ if("40HC".equals(ct)) {
|
|
|
+ ct = ct.replace("HC", "HQ");
|
|
|
+ }
|
|
|
+ if("40RH".equals(ct)) {
|
|
|
+ ct = ct.replace("RH", "NOR");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ jo.put("cntrType", ct);
|
|
|
+ String cntrType = ct;
|
|
|
+
|
|
|
+ PreContainers preCntr = null;
|
|
|
+ if(ObjectUtils.isNotNull(preContainersList)) {
|
|
|
+ preCntr = preContainersList.stream().filter(e->cntrType.compareTo(e.getCntrTypeCode()) == 0).findFirst().orElse(null);
|
|
|
+ }
|
|
|
+
|
|
|
+ jo.put("cntrTypeExists", ObjectUtils.isNotNull(preCntr));
|
|
|
+ jo.put("qty", jc.getInteger("quantity"));
|
|
|
+ jo.put("gwt", jc.getDouble("grossweight"));
|
|
|
+ jo.put("vol", jc.getDouble("volume"));
|
|
|
+
|
|
|
+ Containers cntr = null;
|
|
|
+ if(ObjectUtils.isNotNull(containersList)){
|
|
|
+ cntr = containersList.stream().filter(e->cntrNo.compareTo(e.getCntrNo()) == 0).findFirst().orElse(null);
|
|
|
+ }
|
|
|
+
|
|
|
+ if(ObjectUtils.isNotNull(cntr)){
|
|
|
+ jo.put("oldCntrType", cntr.getCntrTypeCode());
|
|
|
+ jo.put("oldSealNo", cntr.getSealNo());
|
|
|
+ jo.put("oldQty", cntr.getQuantity().doubleValue());
|
|
|
+ jo.put("oldGwt", cntr.getGrossWeight().doubleValue());
|
|
|
+ jo.put("oldVol", cntr.getMeasurement().doubleValue());
|
|
|
+ // 是否最新数据
|
|
|
+ Boolean isNewest = cntr.getCntrTypeCode().compareTo(ct)!=0
|
|
|
+ || cntr.getSealNo().compareTo(jc.getString("containersealno"))!=0
|
|
|
+ || cntr.getQuantity().compareTo(new BigDecimal(jc.getInteger("quantity").toString()))!=0
|
|
|
+ || cntr.getQuantity().compareTo(jc.getBigDecimal("grossweight"))!=0
|
|
|
+ || cntr.getQuantity().compareTo(jc.getBigDecimal("volume"))!=0;
|
|
|
+ jo.put("isNewest", isNewest);
|
|
|
+ // status: 是否已配箱
|
|
|
+ jo.put("status", "已配箱");
|
|
|
+ }else {
|
|
|
+ jo.put("oldCntrType", "");
|
|
|
+ jo.put("oldSealNo", "");
|
|
|
+ jo.put("oldQty", 0L);
|
|
|
+ jo.put("oldGwt", 0F);
|
|
|
+ jo.put("oldVol", 0F);
|
|
|
+ // 是否最新数据
|
|
|
+ jo.put("isNewest", true);
|
|
|
+ // status: 是否已配箱
|
|
|
+ jo.put("status", "");
|
|
|
+ }
|
|
|
+ jo.put("selected", true);
|
|
|
+ cntrs.add(jo);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return R.data(cntrs);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 提交 sldc, pil 始终不导件重尺
|
|
|
+ *
|
|
|
+ * @param mode true 导入箱封号、件重尺,false 只导入箱封号,不导入件重尺
|
|
|
+ * @param data 箱数据
|
|
|
+ */
|
|
|
+ @PostMapping("/submit")
|
|
|
+ public R submit(@RequestParam("mode") Boolean mode, @Valid @RequestBody String data) throws IOException {
|
|
|
+ return R.success(data);
|
|
|
+ }
|
|
|
+}
|