| | |
| | | productNew.setProductName(product.getString("note")); |
| | | productNew.setErpCode(product.getString("itemNo")); |
| | | productNew.setProductType(product.getString("grade")); |
| | | productNew.setUnitName(product.getString("unitName")); |
| | | if(StrUtil.equals(tan,"tenant1")){ |
| | | productNew.setCompId(2089995177814495234L); |
| | | } |
| | |
| | | productNew.setParentId(productClass.getId()); |
| | | TaxCode taxCode = taxCodeMapper.selectOne(Wrappers.<TaxCode>lambdaQuery().eq(TaxCode::getBm,product.getString("tfTaxClass")).last("limit 1")); |
| | | if (ObjUtil.isNotNull(taxCode)){ |
| | | productClass.setTaxClass(taxCode.getSphwjc()); |
| | | productClass.setTaxRate(Double.valueOf(taxCode.getSl().replace("%",""))); |
| | | productNew.setTaxClass(taxCode.getSphwjc()); |
| | | productNew.setTaxRate(Double.valueOf(taxCode.getSl().replace("%",""))); |
| | | } |
| | | baseMapper.insert(productNew); |
| | | log.info("产品:{}新增成功",product.getString("itemNo")); |
| | |
| | | } |
| | | return ""; |
| | | } |
| | | |
| | | |
| | | @Override |
| | | public R pullProductData() { |
| | | String startDate = DateUtil.formatDate(DateUtil.offsetDay(new Date(), -1)); |
| | | |
| | | String token = ""; |
| | | if (redisTemplate.hasKey("SMJ_ERP_TOKEN")) { |
| | | token = (String) redisTemplate.opsForValue().get("SMJ_ERP_TOKEN"); |
| | | } else { |
| | | token = getErpToken(); |
| | | } |
| | | if (StrUtil.isEmpty(token)){ |
| | | return R.failed("石煤机登录获取token失败"); |
| | | } |
| | | List<String> list = Arrays.asList("tenant1","tenant2","tenant3"); |
| | | String tan = ""; |
| | | if (StrUtil.equals(smj,SecurityUtils.getUser().getCompId()+"")||StrUtil.equals(smjhw,SecurityUtils.getUser().getCompId()+"")){ |
| | | tan = "tenant1"; |
| | | } |
| | | if (StrUtil.equals(smjsc,SecurityUtils.getUser().getCompId()+"")){ |
| | | tan = "tenant2"; |
| | | } |
| | | if (StrUtil.equals(smjzt,SecurityUtils.getUser().getCompId()+"")){ |
| | | tan = "tenant3"; |
| | | } |
| | | if (StrUtil.isBlank(tan)){ |
| | | return R.failed("帐号信息异常请联系技术人员"); |
| | | } |
| | | HttpResponse response = HttpRequest.get(smjErp + "/api/item/v1/byDateCre?startDate=" + startDate+"&tenantId="+tan) |
| | | .header("token", token) // 添加认证头 |
| | | .execute(); // 执行请求.post(ymjErp,request.toJSONString()); |
| | | log.info("石煤机——"+tan+"产品获取回参:{}", response.body()); |
| | | JSONObject proResult = JSONObject.parseObject(response.body()); |
| | | JSONArray items = proResult.getJSONArray("data"); |
| | | if (CollUtil.isNotEmpty(items)){ |
| | | log.info("石煤机产品获取数量:{}", items.size()); |
| | | String finalTan = tan; |
| | | items.stream().forEach(item->{ |
| | | JSONObject product = (JSONObject) item; |
| | | Product productClass = baseMapper.selectOne(Wrappers.<Product>lambdaQuery() |
| | | .eq(Product::getProductName,product.getString("itemClassName")) |
| | | // .and(wrapper -> wrapper.eq(Product::getCompId,"2089995177814495234") |
| | | // .or().eq(Product::getCompId,"2089996921978040321") |
| | | // .or().eq(Product::getCompId,"2089997578009128962") |
| | | // ) |
| | | .eq(StrUtil.equals(finalTan,"tenant1"),Product::getCompId,"2089995177814495234") |
| | | .eq(StrUtil.equals(finalTan,"tenant2"),Product::getCompId,"2089996921978040321") |
| | | .eq(StrUtil.equals(finalTan,"tenant3"),Product::getCompId,"2089997578009128962") |
| | | .last("limit 1") |
| | | ); |
| | | if(ObjUtil.isNull(productClass)){ |
| | | log.info("产品分类:{}不存在",product.getString("itemClassName")); |
| | | productClass = new Product(); |
| | | productClass.setProductName(product.getString("itemClassName")); |
| | | productClass.setErpCode(product.getString("itemClassName")); |
| | | productClass.setParentId(0L); |
| | | if(StrUtil.equals(finalTan,"tenant1")){ |
| | | productClass.setCompId(2089995177814495234L); |
| | | } |
| | | if(StrUtil.equals(finalTan,"tenant2")){ |
| | | productClass.setCompId(2089996921978040321L); |
| | | } |
| | | if(StrUtil.equals(finalTan,"tenant3")){ |
| | | productClass.setCompId(2089997578009128962L); |
| | | } |
| | | TaxCode taxCode = taxCodeMapper.selectOne(Wrappers.<TaxCode>lambdaQuery().eq(TaxCode::getBm,product.getString("tfTaxClass")).last("limit 1")); |
| | | if (ObjUtil.isNotNull(taxCode)){ |
| | | productClass.setTaxClass(taxCode.getSphwjc()); |
| | | productClass.setTaxRate(Double.valueOf(taxCode.getSl().replace("%",""))); |
| | | } |
| | | baseMapper.insert(productClass); |
| | | log.info("产品分类:{}新增成功",product.getString("itemClassName")); |
| | | } |
| | | Product productNew = baseMapper.selectOne(Wrappers.<Product>lambdaQuery() |
| | | .eq(Product::getErpCode,product.getString("itemNo")) |
| | | // .and(wrapper -> wrapper.eq(Product::getCompId,"2089995177814495234") |
| | | // .or().eq(Product::getCompId,"2089996921978040321") |
| | | // .or().eq(Product::getCompId,"2089997578009128962") |
| | | // ) |
| | | .eq(StrUtil.equals(finalTan,"tenant1"),Product::getCompId,"2089995177814495234") |
| | | .eq(StrUtil.equals(finalTan,"tenant2"),Product::getCompId,"2089996921978040321") |
| | | .eq(StrUtil.equals(finalTan,"tenant3"),Product::getCompId,"2089997578009128962") |
| | | .last("limit 1") |
| | | ); |
| | | if(ObjUtil.isNull(productNew)){ |
| | | log.info("产品:{}不存在",product.getString("itemNo")); |
| | | productNew = new Product(); |
| | | productNew.setProductName(product.getString("note")); |
| | | productNew.setErpCode(product.getString("itemNo")); |
| | | productNew.setProductType(product.getString("grade")); |
| | | productNew.setUnitName(product.getString("unitName")); |
| | | if(StrUtil.equals(finalTan,"tenant1")){ |
| | | productNew.setCompId(2089995177814495234L); |
| | | } |
| | | if(StrUtil.equals(finalTan,"tenant2")){ |
| | | productNew.setCompId(2089996921978040321L); |
| | | } |
| | | if(StrUtil.equals(finalTan,"tenant3")){ |
| | | productNew.setCompId(2089997578009128962L); |
| | | } |
| | | productNew.setParentId(productClass.getId()); |
| | | TaxCode taxCode = taxCodeMapper.selectOne(Wrappers.<TaxCode>lambdaQuery().eq(TaxCode::getBm,product.getString("tfTaxClass")).last("limit 1")); |
| | | if (ObjUtil.isNotNull(taxCode)){ |
| | | productNew.setTaxClass(taxCode.getSphwjc()); |
| | | productNew.setTaxRate(Double.valueOf(taxCode.getSl().replace("%",""))); |
| | | } |
| | | baseMapper.insert(productNew); |
| | | log.info("产品:{}新增成功",product.getString("itemNo")); |
| | | return; |
| | | } |
| | | log.info("产品:{}存在",product.getString("itemNo")); |
| | | }); |
| | | } |
| | | |
| | | |
| | | return R.ok(); |
| | | } |
| | | |
| | | @Override |
| | | public R pullProductPage() { |
| | | String token = ""; |
| | | if (redisTemplate.hasKey("SMJ_ERP_TOKEN")) { |
| | | token = (String) redisTemplate.opsForValue().get("SMJ_ERP_TOKEN"); |
| | | } else { |
| | | token = getErpToken(); |
| | | } |
| | | if (StrUtil.isEmpty(token)){ |
| | | return R.failed("石煤机登录获取token失败"); |
| | | } |
| | | List<String> list = Arrays.asList("tenant1","tenant2","tenant3"); |
| | | String tan = ""; |
| | | if (StrUtil.equals(smj,SecurityUtils.getUser().getCompId()+"")||StrUtil.equals(smjhw,SecurityUtils.getUser().getCompId()+"")){ |
| | | tan = "tenant1"; |
| | | } |
| | | if (StrUtil.equals(smjsc,SecurityUtils.getUser().getCompId()+"")){ |
| | | tan = "tenant2"; |
| | | } |
| | | if (StrUtil.equals(smjzt,SecurityUtils.getUser().getCompId()+"")){ |
| | | tan = "tenant3"; |
| | | } |
| | | if (StrUtil.isBlank(tan)){ |
| | | return R.failed("帐号信息异常请联系技术人员"); |
| | | } |
| | | JSONObject req = new JSONObject(); |
| | | req.put("page","1"); |
| | | req.put("size","100"); |
| | | HttpResponse response = HttpRequest.post(smjErp + "/api/item/v1/queryPage?tenantId="+tan) |
| | | .header("token", token) // 添加认证头 |
| | | .body(req.toJSONString()) |
| | | .execute(); // 执行请求.post(ymjErp,request.toJSONString()); |
| | | log.info("石煤机——"+tan+"产品获取回参:{}", response.body()); |
| | | JSONObject proResult = JSONObject.parseObject(response.body()); |
| | | JSONObject data = proResult.getJSONObject("data"); |
| | | if (ObjUtil.isNotNull(data)&&data.containsKey("pages")){ |
| | | Integer pages = data.getInteger("pages"); |
| | | for (int i = 1; i < pages+1; i++) { |
| | | JSONObject reqPage = new JSONObject(); |
| | | reqPage.put("page",i); |
| | | reqPage.put("size","100"); |
| | | HttpResponse responsePage = HttpRequest.post(smjErp + "/api/item/v1/queryPage?tenantId="+tan) |
| | | .header("token", token) // 添加认证头 |
| | | .body(req.toJSONString()) |
| | | .execute(); // 执行请求.post(ymjErp,request.toJSONString()); |
| | | log.info("石煤机——"+tan+"产品获取回参:{}", responsePage.body()); |
| | | JSONObject pageResult = JSONObject.parseObject(response.body()); |
| | | JSONObject dataPage = pageResult.getJSONObject("data"); |
| | | if (ObjUtil.isNotNull(data)&&dataPage.containsKey("records")&&CollUtil.isNotEmpty(dataPage.getJSONArray("records"))){ |
| | | if (CollUtil.isNotEmpty(dataPage.getJSONArray("records"))){ |
| | | log.info("石煤机产品获取数量:{}", dataPage.getJSONArray("records").size()); |
| | | String finalTan = tan; |
| | | dataPage.getJSONArray("records").stream().forEach(item->{ |
| | | JSONObject product = (JSONObject) item; |
| | | Product productClass = baseMapper.selectOne(Wrappers.<Product>lambdaQuery() |
| | | .eq(Product::getProductName,product.getString("itemClassName")) |
| | | // .and(wrapper -> wrapper.eq(Product::getCompId,"2089995177814495234") |
| | | // .or().eq(Product::getCompId,"2089996921978040321") |
| | | // .or().eq(Product::getCompId,"2089997578009128962") |
| | | // ) |
| | | .eq(StrUtil.equals(finalTan,"tenant1"),Product::getCompId,"2089995177814495234") |
| | | .eq(StrUtil.equals(finalTan,"tenant2"),Product::getCompId,"2089996921978040321") |
| | | .eq(StrUtil.equals(finalTan,"tenant3"),Product::getCompId,"2089997578009128962") |
| | | .last("limit 1") |
| | | ); |
| | | if(ObjUtil.isNull(productClass)){ |
| | | log.info("产品分类:{}不存在",product.getString("itemClassName")); |
| | | productClass = new Product(); |
| | | productClass.setProductName(product.getString("itemClassName")); |
| | | productClass.setErpCode(product.getString("itemClassName")); |
| | | productClass.setParentId(0L); |
| | | if(StrUtil.equals(finalTan,"tenant1")){ |
| | | productClass.setCompId(2089995177814495234L); |
| | | } |
| | | if(StrUtil.equals(finalTan,"tenant2")){ |
| | | productClass.setCompId(2089996921978040321L); |
| | | } |
| | | if(StrUtil.equals(finalTan,"tenant3")){ |
| | | productClass.setCompId(2089997578009128962L); |
| | | } |
| | | TaxCode taxCode = taxCodeMapper.selectOne(Wrappers.<TaxCode>lambdaQuery().eq(TaxCode::getBm,product.getString("tfTaxClass")).last("limit 1")); |
| | | if (ObjUtil.isNotNull(taxCode)){ |
| | | productClass.setTaxClass(taxCode.getSphwjc()); |
| | | productClass.setTaxRate(Double.valueOf(taxCode.getSl().replace("%",""))); |
| | | } |
| | | baseMapper.insert(productClass); |
| | | log.info("产品分类:{}新增成功",product.getString("itemClassName")); |
| | | } |
| | | Product productNew = baseMapper.selectOne(Wrappers.<Product>lambdaQuery() |
| | | .eq(Product::getErpCode,product.getString("itemNo")) |
| | | // .and(wrapper -> wrapper.eq(Product::getCompId,"2089995177814495234") |
| | | // .or().eq(Product::getCompId,"2089996921978040321") |
| | | // .or().eq(Product::getCompId,"2089997578009128962") |
| | | // ) |
| | | .eq(StrUtil.equals(finalTan,"tenant1"),Product::getCompId,"2089995177814495234") |
| | | .eq(StrUtil.equals(finalTan,"tenant2"),Product::getCompId,"2089996921978040321") |
| | | .eq(StrUtil.equals(finalTan,"tenant3"),Product::getCompId,"2089997578009128962") |
| | | .last("limit 1") |
| | | ); |
| | | if(ObjUtil.isNull(productNew)){ |
| | | log.info("产品:{}不存在",product.getString("itemNo")); |
| | | productNew = new Product(); |
| | | productNew.setProductName(product.getString("note")); |
| | | productNew.setErpCode(product.getString("itemNo")); |
| | | productNew.setProductType(product.getString("grade")); |
| | | productNew.setUnitName(product.getString("unitName")); |
| | | if(StrUtil.equals(finalTan,"tenant1")){ |
| | | productNew.setCompId(2089995177814495234L); |
| | | } |
| | | if(StrUtil.equals(finalTan,"tenant2")){ |
| | | productNew.setCompId(2089996921978040321L); |
| | | } |
| | | if(StrUtil.equals(finalTan,"tenant3")){ |
| | | productNew.setCompId(2089997578009128962L); |
| | | } |
| | | productNew.setParentId(productClass.getId()); |
| | | TaxCode taxCode = taxCodeMapper.selectOne(Wrappers.<TaxCode>lambdaQuery().eq(TaxCode::getBm,product.getString("tfTaxClass")).last("limit 1")); |
| | | if (ObjUtil.isNotNull(taxCode)){ |
| | | productNew.setTaxClass(taxCode.getSphwjc()); |
| | | productNew.setTaxRate(Double.valueOf(taxCode.getSl().replace("%",""))); |
| | | } |
| | | baseMapper.insert(productNew); |
| | | log.info("产品:{}新增成功",product.getString("itemNo")); |
| | | return; |
| | | } |
| | | if(ObjUtil.isNotNull(productNew)) { |
| | | log.info("产品:{}存在", product.getString("itemNo")); |
| | | productNew.setProductType(product.getString("grade")); |
| | | productNew.setUnitName(product.getString("unitName")); |
| | | TaxCode taxCode = taxCodeMapper.selectOne(Wrappers.<TaxCode>lambdaQuery().eq(TaxCode::getBm,product.getString("tfTaxClass")).last("limit 1")); |
| | | if (ObjUtil.isNotNull(taxCode)){ |
| | | productNew.setTaxClass(taxCode.getSphwjc()); |
| | | productNew.setTaxRate(Double.valueOf(taxCode.getSl().replace("%",""))); |
| | | } |
| | | baseMapper.updateById(productNew); |
| | | } |
| | | }); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | return R.ok(); |
| | | } |
| | | } |