| | |
| | | package com.chinaztt.mes.basic.service.impl; |
| | | |
| | | import cn.hutool.core.collection.CollectionUtil; |
| | | import cn.hutool.core.date.DateUtil; |
| | | import cn.hutool.http.HttpRequest; |
| | | import com.alibaba.fastjson.JSONArray; |
| | | import com.alibaba.fastjson.JSONObject; |
| | |
| | | import com.chinaztt.mes.basic.service.PartService; |
| | | import com.chinaztt.mes.basic.util.DictUtils; |
| | | import com.chinaztt.mes.basic.util.PartUtils; |
| | | import com.chinaztt.mes.basic.util.TransactionUtils; |
| | | import com.chinaztt.mes.common.util.JsonUtil; |
| | | import com.chinaztt.ztt.common.core.util.R; |
| | | import com.chinaztt.ztt.common.security.util.SecurityUtils; |
| | |
| | | import org.springframework.data.redis.core.RedisTemplate; |
| | | import org.springframework.scheduling.annotation.Async; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.TransactionDefinition; |
| | | import org.springframework.transaction.TransactionStatus; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | import org.springframework.util.StringUtils; |
| | | |
| | | import java.io.IOException; |
| | | import java.math.BigDecimal; |
| | | import java.sql.Connection; |
| | | import java.sql.PreparedStatement; |
| | | import java.util.*; |
| | | |
| | | /** |
| | |
| | | private DiscoveryClient discoveryClient; |
| | | private Environment environment; |
| | | private RedisTemplate redisTemplate; |
| | | private TransactionUtils transactionUtils; |
| | | ; |
| | | |
| | | |
| | | @Override |
| | | public void importPartExcel(List<PartData> list) { |
| | |
| | | } |
| | | |
| | | |
| | | @Transactional(rollbackFor = Exception.class) |
| | | @Override |
| | | public Long syncNewIfs(Date date) { |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public Long syncNewIfs(String date) { |
| | | TransactionStatus transaction = transactionUtils.begin(TransactionDefinition.ISOLATION_READ_COMMITTED); |
| | | Map<String, String> dicmattype = dictUtils.getDicKey("material_type"); |
| | | Map<String, String> dicunit = dictUtils.getDicKey("unit"); |
| | | String key = "syncPart_lock" + SecurityUtils.getUser().getId(); |
| | |
| | | throw new RuntimeException("有同步任务正在处理"); |
| | | } |
| | | 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>(); |
| | | Connection conn =null; |
| | | PreparedStatement pstmt =null; |
| | | try { |
| | | String url =""; |
| | | //判断日期有否 |
| | | if (Objects.isNull(date)){ |
| | | url = "http://192.168.20.47:8008/PurchService.ashx?contract=KJZS&contractKey=4ttDeLKNsZuhstjtROMcRE1USNFXKdFYE7lQ2p1m5Bo=&procedureName=QUERY_INVENTORY_PART_INFO_STD&userId=7632&inAttr={}"; |
| | | }else { |
| | | Map<String, Object>map=new HashMap<>(); |
| | | map.put("MODIFY_DATE", date); |
| | | url = "http://192.168.20.47:8008/PurchService.ashx?contract=KJZS&contractKey=4ttDeLKNsZuhstjtROMcRE1USNFXKdFYE7lQ2p1m5Bo=&procedureName=QUERY_INVENTORY_PART_INFO_STD&userId=7632&inAttr="+new ObjectMapper().writeValueAsString(map); |
| | | } |
| | | 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); |
| | | System.out.println(data.size()); |
| | | //data.forEach(System.out::println); |
| | | List<String>no=new ArrayList<String>(); |
| | | data.forEach(l->{ |
| | | Part part = new Part(); |
| | |
| | | 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); |
| | | System.out.println("过滤长度=============================》"+partList.size()); |
| | | partList.forEach(l -> { |
| | | baseMapper.insert(l); |
| | | }); |
| | |
| | | e.printStackTrace(); |
| | | throw new RuntimeException(e.getMessage()); |
| | | } finally { |
| | | //JDBCUtil.close(pstmt,conn); |
| | | redisTemplate.delete(key); |
| | | } |
| | | return (long) partList.size(); |