|  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | import cn.hutool.core.bean.BeanUtil; | 
|---|
|  |  |  | import com.alibaba.fastjson.JSON; | 
|---|
|  |  |  | import com.alibaba.fastjson.JSONArray; | 
|---|
|  |  |  | import com.alibaba.fastjson.JSONObject; | 
|---|
|  |  |  | import com.baomidou.mybatisplus.mapper.EntityWrapper; | 
|---|
|  |  |  | import com.core.common.Cools; | 
|---|
|  |  |  | import com.core.exception.CoolException; | 
|---|
|  |  |  | import com.zy.asrs.entity.MesLocDetl; | 
|---|
|  |  |  | import com.zy.asrs.entity.ReportData; | 
|---|
|  |  |  | import com.zy.asrs.entity.ReportDataLog; | 
|---|
|  |  |  | import com.zy.asrs.entity.param.MesStock; | 
|---|
|  |  |  | import com.zy.asrs.service.ApiLogService; | 
|---|
|  |  |  | import com.zy.asrs.service.MesLocDetlService; | 
|---|
|  |  |  | import com.zy.asrs.service.ReportDataLogService; | 
|---|
|  |  |  | import com.zy.asrs.service.ReportDataService; | 
|---|
|  |  |  | import com.zy.asrs.task.AbstractHandler; | 
|---|
|  |  |  | 
|---|
|  |  |  | import org.springframework.stereotype.Service; | 
|---|
|  |  |  | import org.springframework.transaction.annotation.Transactional; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | import java.util.Date; | 
|---|
|  |  |  | import java.util.Map; | 
|---|
|  |  |  | import java.util.*; | 
|---|
|  |  |  | import java.util.concurrent.TimeUnit; | 
|---|
|  |  |  | import java.util.stream.Collectors; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * Created by vincent on 2020/7/7 | 
|---|
|  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | private ApiLogService apiLogService; | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | private MesLocDetlService mesLocDetlService; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Value("${mes.url}") | 
|---|
|  |  |  | private String url; | 
|---|
|  |  |  | 
|---|
|  |  |  | throw new CoolException("mes接口调用失败,返回信息:" + jsonObject); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | success = true; | 
|---|
|  |  |  | return null; | 
|---|
|  |  |  | return response; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | } catch (Exception e) { | 
|---|
|  |  |  | log.error("mes接口调用失败,返回信息:{}", e.getMessage()); | 
|---|
|  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Transactional | 
|---|
|  |  |  | public ReturnT<String> stock(Map<String, Object> mesTokenInfo) { | 
|---|
|  |  |  | String result = doHttpRequest("{}", mesTokenInfo, "同步MES库存", url, stock, null, "127.0.0.1"); | 
|---|
|  |  |  | List<MesLocDetl> all = mesLocDetlService.selectList(new EntityWrapper<>()); | 
|---|
|  |  |  | if (all != null) { | 
|---|
|  |  |  | List<Long> collect = all.stream().map(MesLocDetl::getId).collect(Collectors.toList()); | 
|---|
|  |  |  | boolean del = true; | 
|---|
|  |  |  | int d = 1; | 
|---|
|  |  |  | while (del && collect.size() > 0) { | 
|---|
|  |  |  | if (collect.size() > d * 1000) { | 
|---|
|  |  |  | mesLocDetlService.deleteBatchIds(collect.subList((d - 1) * 1000, d * 1000)); | 
|---|
|  |  |  | } else { | 
|---|
|  |  |  | mesLocDetlService.deleteBatchIds(collect.subList((d - 1) * 1000, collect.size())); | 
|---|
|  |  |  | del = false; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | d++; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | boolean flag = true; | 
|---|
|  |  |  | Map<String, Object> req = new HashMap<>(); | 
|---|
|  |  |  | int i = 1; | 
|---|
|  |  |  | while (flag) { | 
|---|
|  |  |  | req.put("page", i); | 
|---|
|  |  |  | req.put("size", 1000); | 
|---|
|  |  |  | String result = doHttpRequest(JSONObject.toJSONString(req), mesTokenInfo, "同步MES库存", url, stock, null, "127.0.0.1"); | 
|---|
|  |  |  | JSONObject jsonObject = JSONObject.parseObject(result); | 
|---|
|  |  |  | Object o = jsonObject.get("data"); | 
|---|
|  |  |  | List<MesLocDetl> mesLocDetls = new ArrayList<>(); | 
|---|
|  |  |  | MesLocDetl mesLocDetl; | 
|---|
|  |  |  | if (o != null) { | 
|---|
|  |  |  | JSONObject jsonObject1 = JSONObject.parseObject(o.toString()); | 
|---|
|  |  |  | Object o1 = jsonObject1.get("list"); | 
|---|
|  |  |  | if (o1 != null) { | 
|---|
|  |  |  | List<MesStock> mesStocks = JSONArray.parseArray(o1.toString(), MesStock.class); | 
|---|
|  |  |  | if (mesStocks.isEmpty()) { | 
|---|
|  |  |  | flag = false; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | for (MesStock mesStock : mesStocks) { | 
|---|
|  |  |  | mesLocDetl = new MesLocDetl(); | 
|---|
|  |  |  | mesLocDetl.setMatnr(mesStock.getMaterialInfo().getMaterialCode()); | 
|---|
|  |  |  | mesLocDetl.setMaktx(mesStock.getMaterialInfo().getMaterialName()); | 
|---|
|  |  |  | mesLocDetl.setBatch(mesStock.getBatchNo()); | 
|---|
|  |  |  | mesLocDetl.setAnfme(mesStock.getOpAmount().getAmount().getAmount()); | 
|---|
|  |  |  | mesLocDetls.add(mesLocDetl); | 
|---|
|  |  |  | mesLocDetlService.insert(mesLocDetl); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } else { | 
|---|
|  |  |  | flag = false; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if (!mesLocDetls.isEmpty()) { | 
|---|
|  |  |  | //mesLocDetlService.insertBatch(mesLocDetls); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | i++; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | return SUCCESS; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | } | 
|---|