| | |
| | | import com.fasterxml.jackson.databind.ObjectMapper; |
| | | import com.google.gson.Gson; |
| | | import lombok.AllArgsConstructor; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.apache.http.HttpEntity; |
| | | import org.apache.http.client.methods.CloseableHttpResponse; |
| | | import org.apache.http.client.methods.HttpPost; |
| | |
| | | */ |
| | | @AllArgsConstructor |
| | | @Service |
| | | @Slf4j |
| | | public class PartServiceImpl extends ServiceImpl<PartMapper, Part> implements PartService { |
| | | private DictUtils dictUtils; |
| | | private PartUtils partUtils; |
| | |
| | | |
| | | @Transactional(rollbackFor = Exception.class) |
| | | @Override |
| | | public void syncNewIfs(Date date) { |
| | | public Long syncNewIfs(Date date) { |
| | | Map<String, String> dicmattype = dictUtils.getDicKey("material_type"); |
| | | Map<String, String> dicunit = dictUtils.getDicKey("unit"); |
| | | String key = "syncPart_lock" + SecurityUtils.getUser().getId(); |
| | |
| | | redisTemplate.opsForValue().set(key, 1, 1000 * 3600); |
| | | Map<String, Object>map=new HashMap<>(); |
| | | map.put("MODIFY_DATE", DateUtil.format(date,"yyyy-MM-dd")); |
| | | List<Part>partList=new ArrayList<Part>(); |
| | | try { |
| | | log.info("开始执行同步==========》"); |
| | | String url = "http://192.168.20.47:8008/PurchService.ashx?contract=ZTKJ&contractKey=4ttDeLKNsZuhstjtROMcRE1USNFXKdFYE7lQ2p1m5Bo=&procedureName=QUERY_INVENTORY_PART_INFO_STD&userId=7632&inAttr="+new ObjectMapper().writeValueAsString(map); |
| | | String body = HttpRequest.get(url).execute().body(); |
| | | log.info("执行同步结束===========》"); |
| | | Map<String, Object> mapResult = JsonUtil.jsonToPojo(body, Map.class); |
| | | List<Map<String, Object>> data = JsonUtil.jsonToPojo(JsonUtil.jsonToString(mapResult.get("INVENTORY_PART_INFO")), List.class); |
| | | List<String>no=new ArrayList<String>(); |
| | | List<Part>partList=new ArrayList<Part>(); |
| | | data.forEach(l->{ |
| | | Part part = new Part(); |
| | | part.setPartNo(String.valueOf(l.get("PART_NO"))); |
| | |
| | | part.setSunit(dicunit.get(l.get("UNIT_MEAS_FOR_WEIGHT"))); |
| | | partList.add(part); |
| | | }); |
| | | QueryWrapper<Part>queryWrapper=new QueryWrapper<>(); |
| | | queryWrapper.lambda().select(Part::getPartNo).in(Part::getPartNo,no); |
| | | List<Part> selectList = baseMapper.selectList(queryWrapper); |
| | | //System.out.println(baseMapper.selectList(queryWrapper)); |
| | | partList.removeIf(mainObj -> selectList.stream().anyMatch(subObj -> subObj.getPartNo().equals(mainObj.getPartNo()))); |
| | | //System.out.println(partList); |
| | | partList.forEach(l->{ |
| | | baseMapper.insert(l); |
| | | }); |
| | | if(partList.size()>0) { |
| | | QueryWrapper<Part> queryWrapper = new QueryWrapper<>(); |
| | | queryWrapper.lambda().select(Part::getPartNo).in(Part::getPartNo, no); |
| | | List<Part> selectList = baseMapper.selectList(queryWrapper); |
| | | //System.out.println(baseMapper.selectList(queryWrapper)); |
| | | partList.removeIf(mainObj -> selectList.stream().anyMatch(subObj -> subObj.getPartNo().equals(mainObj.getPartNo()))); |
| | | //System.out.println(partList); |
| | | partList.forEach(l -> { |
| | | baseMapper.insert(l); |
| | | }); |
| | | } |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | throw new RuntimeException(e.getMessage()); |
| | | } finally { |
| | | redisTemplate.delete(key); |
| | | } |
| | | return (long) partList.size(); |
| | | } |
| | | } |