|
|
@@ -0,0 +1,359 @@
|
|
|
+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.conditions.update.LambdaUpdateWrapper;
|
|
|
+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.common.annotation.RepeatSubmit;
|
|
|
+import org.springblade.core.secure.utils.AuthUtil;
|
|
|
+import org.springblade.core.tool.api.R;
|
|
|
+import org.springblade.los.Util.BigDecimalUtils;
|
|
|
+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.los.gmy.entity.GmyDeclHead;
|
|
|
+import org.springblade.system.feign.ISysClient;
|
|
|
+import org.springframework.transaction.annotation.Transactional;
|
|
|
+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.math.RoundingMode;
|
|
|
+import java.net.HttpURLConnection;
|
|
|
+import java.net.URL;
|
|
|
+import java.rmi.RemoteException;
|
|
|
+import java.util.ArrayList;
|
|
|
+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 && mblNo.compareTo(e.getMblno())==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")
|
|
|
+ @RepeatSubmit
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
+ public R submit(@RequestParam("mode") Boolean mode, @RequestParam("id") String id, @Valid @RequestBody String data) 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,
|
|
|
+ Bills::getBranchId, Bills::getCreateUser, Bills::getCreateUserName, Bills::getHblno,
|
|
|
+ Bills::getPackingUnitId, Bills::getPackingUnit)
|
|
|
+ .eq(Bills::getId, id)
|
|
|
+ .eq(Bills::getTenantId, AuthUtil.getTenantId())
|
|
|
+ .eq(Bills::getIsDeleted, 0));
|
|
|
+ if(ObjectUtils.isNull(bill)){
|
|
|
+ throw new RemoteException("id " + id + " 不存在,无法查询箱封号!");
|
|
|
+ }
|
|
|
+
|
|
|
+ JSONArray ja = JSON.parseArray(data);
|
|
|
+ if(ObjectUtils.isNull(ja) && ja.isEmpty()){
|
|
|
+ return R.fail("没有选择箱号!");
|
|
|
+ }
|
|
|
+
|
|
|
+ String mblNo = ObjectUtils.isNotNull(bill.getMblno()) ? bill.getMblno().trim() : "";
|
|
|
+ Boolean bImportPWV = mode; // && bill.getCarrierId()!=18;
|
|
|
+ BigDecimal sumQty = new BigDecimal(0L);
|
|
|
+ BigDecimal sumGw = new BigDecimal(0L);
|
|
|
+ BigDecimal sumVol = BigDecimal.ZERO;
|
|
|
+
|
|
|
+ List<Containers> containersList = new ArrayList<>();
|
|
|
+ //
|
|
|
+ for (Object jaCntr : ja) {
|
|
|
+ JSONObject jc = (JSONObject) jaCntr;
|
|
|
+
|
|
|
+ if(mblNo.compareTo(jc.getString("mblNo"))==0) {
|
|
|
+ Containers containers = new Containers();
|
|
|
+ containers.setId(null);
|
|
|
+ containers.setPid(bill.getId());
|
|
|
+ containers.setBranchId(bill.getBranchId());
|
|
|
+ containers.setBillNo(bill.getBillNo());
|
|
|
+ containers.setCreateUser(bill.getCreateUser());
|
|
|
+ containers.setCreateUserName(bill.getCreateUserName());
|
|
|
+ containers.setTenantId(AuthUtil.getTenantId());
|
|
|
+ containers.setMblno(bill.getMblno());
|
|
|
+ containers.setHblno(mblNo);
|
|
|
+
|
|
|
+ containers.setCntrTypeCode(jc.getString("cntrType"));
|
|
|
+ containers.setCntrNo(jc.getString("cntrNo"));
|
|
|
+ containers.setSealNo(jc.getString("sealNo"));
|
|
|
+
|
|
|
+ if (bImportPWV) {
|
|
|
+ double q1 = jc.getDouble("qty");
|
|
|
+ containers.setQuantity(BigDecimal.valueOf(q1));
|
|
|
+ sumQty = sumQty.add(new BigDecimal(q1));
|
|
|
+ double w1 = jc.getDouble("gwt");
|
|
|
+ containers.setGrossWeight(BigDecimal.valueOf(w1));
|
|
|
+ sumGw = sumGw.add(new BigDecimal(w1));
|
|
|
+ double v1 = jc.getDouble("vol");
|
|
|
+ containers.setMeasurement(BigDecimal.valueOf(v1));
|
|
|
+ sumVol = sumVol.add(new BigDecimal(v1));
|
|
|
+ }
|
|
|
+ containers.setPackingUnitId(bill.getPackingUnitId());
|
|
|
+ containers.setPackingUnit(bill.getPackingUnit());
|
|
|
+ containersList.add(containers);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 删除
|
|
|
+ if (containersList.size() > 0) {
|
|
|
+ containersService.deleteByPid(bill.getId());
|
|
|
+ // 保存配箱箱号明细
|
|
|
+ containersService.submitList(containersList);
|
|
|
+ }else{
|
|
|
+ throw new RemoteException("没有该提单号下的箱号!");
|
|
|
+ }
|
|
|
+ if(bImportPWV) {
|
|
|
+ // 修改主表件重尺
|
|
|
+ sumQty.setScale(0, BigDecimal.ROUND_HALF_UP);
|
|
|
+ bill.setQuantity(sumQty);
|
|
|
+ bill.setQuantityPackingDescr("SAY " + BigDecimalUtils.convertToEnglish(bill.getQuantity()) + " " + bill.getPackingUnit() + " ONLY.");
|
|
|
+ bill.setCfsQuantity(sumQty);
|
|
|
+ sumGw.setScale(3, BigDecimal.ROUND_HALF_UP);
|
|
|
+ bill.setGrossWeight(sumGw);
|
|
|
+ bill.setCfsGrossWeight(sumGw);
|
|
|
+ sumVol.setScale(3, BigDecimal.ROUND_HALF_UP);
|
|
|
+ bill.setMeasurement(containersList.stream().map(Containers::getMeasurement).reduce(BigDecimal.ZERO, BigDecimal::add).setScale(2, RoundingMode.HALF_UP));
|
|
|
+ bill.setCfsMeasurement(bill.getMeasurement());
|
|
|
+
|
|
|
+ billsService.update(null, new LambdaUpdateWrapper<Bills>()
|
|
|
+ .set(Bills::getQuantity, bill.getQuantity())
|
|
|
+ .set(Bills::getQuantityPackingDescr, bill.getQuantityPackingDescr())
|
|
|
+ .set(Bills::getCfsQuantity, bill.getCfsQuantity())
|
|
|
+ .set(Bills::getGrossWeight, bill.getGrossWeight())
|
|
|
+ .set(Bills::getCfsGrossWeight, bill.getCfsGrossWeight())
|
|
|
+ .set(Bills::getMeasurement, bill.getMeasurement())
|
|
|
+ .set(Bills::getCfsMeasurement, bill.getCfsMeasurement())
|
|
|
+ .eq(Bills::getId, bill.getId())
|
|
|
+ );
|
|
|
+ }
|
|
|
+
|
|
|
+ return R.success("ok");
|
|
|
+ }
|
|
|
+}
|