| | |
| | | import com.alibaba.fastjson.JSONObject; |
| | | import com.aps.common.core.utils.DateUtils; |
| | | import com.aps.common.core.utils.StringUtils; |
| | | import com.aps.common.core.utils.uuid.IdUtils; |
| | | import com.aps.job.domain.ApsBomHeaderJob; |
| | | import com.aps.job.domain.ApsBomLineJob; |
| | | import com.aps.job.domain.ApsWorkOrderJobLog; |
| | |
| | | |
| | | @Override |
| | | public boolean syncBomData(Integer pageIndex, Integer pageSize, String orgCode, String itemCodeList) { |
| | | JSONObject requestBody = new JSONObject(); |
| | | ResponseEntity<String> response = null; |
| | | ApsWorkOrderJobLog jobLog = new ApsWorkOrderJobLog(); |
| | | String batchNum = ""; |
| | | try { |
| | | // 设置请求头 |
| | | HttpHeaders headers = new HttpHeaders(); |
| | | headers.setContentType(MediaType.APPLICATION_JSON); |
| | | // 设置请求体 |
| | | while (true) { |
| | | ApsWorkOrderJobLog jobLog = new ApsWorkOrderJobLog(); |
| | | JSONObject requestBody = new JSONObject(); |
| | | batchNum = IdUtils.fastSimpleUUID(); |
| | | jobLog = new ApsWorkOrderJobLog(); |
| | | requestBody = new JSONObject(); |
| | | requestBody.put("PageIndex", pageIndex); |
| | | requestBody.put("PageSize", pageSize); |
| | | if(!StringUtils.isEmpty(orgCode)){ |
| | |
| | | // 创建HttpEntity对象 |
| | | HttpEntity<String> request = new HttpEntity<>(requestBody.toJSONString(), headers); |
| | | // 发送POST请求 |
| | | ResponseEntity<String> response = restTemplate.postForEntity(getBomUrl, request, String.class); |
| | | response = restTemplate.postForEntity(getBomUrl, request, String.class); |
| | | JSONObject responseBodyJson = JSONObject.parseObject(response.getBody()); |
| | | if (response.getStatusCode().is2xxSuccessful() && "200".equals(responseBodyJson.getString("status"))) { |
| | | JSONArray jsonArray = responseBodyJson.getJSONArray("data"); |
| | |
| | | insertBomHeader.setStartDate(DateUtils.parseDate(bomHeader.getString("HEffectiveDate"))); |
| | | insertBomHeader.setEndDate(DateUtils.parseDate(bomHeader.getString("HDisableDate"))); |
| | | insertBomHeader.setOrgCode(bomHeader.getString("HOrgName").contains("沈阳")?"FORTUNE":bomHeader.getString("HOrgName").contains("南通")?"FORTUNA":bomHeader.getString("HOrgName").contains("北京")?"FORTUBE":bomHeader.getString("HOrgName")); |
| | | insertBomHeader.setCreateBy(batchNum); |
| | | headerList.add(insertBomHeader); |
| | | for(Object line : bomLines){ |
| | | JSONObject lineJson = (JSONObject) line; |
| | |
| | | bomLine.setStartDate(DateUtils.parseDate(lineJson.getString("LEffectiveDate"))); |
| | | bomLine.setEndDate(DateUtils.parseDate(lineJson.getString("LDisableDate"))); |
| | | bomLine.setOrgCode(lineJson.getString("LOrgName").contains("沈阳")?"FORTUNE":lineJson.getString("LOrgName").contains("南通")?"FORTUNA":lineJson.getString("LOrgName").contains("北京")?"FORTUBE":lineJson.getString("LOrgName")); |
| | | bomLine.setCreateBy(batchNum); |
| | | lineList.add(bomLine); |
| | | } |
| | | } |
| | |
| | | jobLog.setCreateTime(DateUtils.getNowDate()); |
| | | jobLog.setBizType("bom"); |
| | | jobLog.setResult("header:"+headerList.size() + " line:"+lineList.size()); |
| | | jobLog.setCreateBy(batchNum); |
| | | jobLogMapper.insertApsWorkOrderJobLog(jobLog); |
| | | pageIndex++; |
| | | }else{ |
| | |
| | | jobLog.setCreateTime(DateUtils.getNowDate()); |
| | | jobLog.setBizType("bom"); |
| | | jobLog.setResult("error"); |
| | | jobLog.setCreateBy(batchNum); |
| | | jobLogMapper.insertApsWorkOrderJobLog(jobLog); |
| | | break; |
| | | } |
| | | } |
| | | }catch (Exception e){ |
| | | e.printStackTrace(); |
| | | jobLog.setRequestData(requestBody.toJSONString()); |
| | | jobLog.setResponseData(response.getBody()); |
| | | jobLog.setPageNum(Long.valueOf(pageIndex)); |
| | | jobLog.setPageCount(Long.valueOf(pageSize)); |
| | | jobLog.setCreateTime(DateUtils.getNowDate()); |
| | | jobLog.setBizType("bom"); |
| | | jobLog.setResult("error"); |
| | | jobLog.setCreateBy(batchNum); |
| | | jobLogMapper.insertApsWorkOrderJobLog(jobLog); |
| | | return false; |
| | | } |
| | | return true; |