| | |
| | | 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.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
| | |
| | | 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.RedisUtils; |
| | | import com.chinaztt.mes.common.util.JsonUtil; |
| | | import com.chinaztt.ztt.common.core.util.R; |
| | | import com.chinaztt.ztt.common.security.util.SecurityUtils; |
| | | 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.config.RequestConfig; |
| | | import org.apache.http.client.methods.CloseableHttpResponse; |
| | | import org.apache.http.client.methods.HttpPost; |
| | | import org.apache.http.entity.ContentType; |
| | |
| | | import org.springframework.util.StringUtils; |
| | | |
| | | import java.io.IOException; |
| | | import java.util.HashMap; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | import java.math.BigDecimal; |
| | | import java.util.*; |
| | | |
| | | /** |
| | | * 零件 |
| | |
| | | */ |
| | | @AllArgsConstructor |
| | | @Service |
| | | @Slf4j |
| | | public class PartServiceImpl extends ServiceImpl<PartMapper, Part> implements PartService { |
| | | private DictUtils dictUtils; |
| | | private PartUtils partUtils; |
| | | private IfsFeignClient ifsFeignClient; |
| | | private DiscoveryClient discoveryClient; |
| | | private Environment environment; |
| | | private RedisTemplate redisTemplate;; |
| | | private RedisTemplate redisTemplate; |
| | | ; |
| | | |
| | | @Override |
| | | public void importPartExcel(List<PartData> list) { |
| | |
| | | if (redisTemplate.hasKey(key)) { |
| | | throw new RuntimeException("有同步任务正在处理"); |
| | | } |
| | | redisTemplate.opsForValue().set(key,1,1000 * 3600); |
| | | redisTemplate.opsForValue().set(key, 1, 1000 * 3600); |
| | | CloseableHttpClient httpClient = HttpClientBuilder.create().build(); |
| | | String syncErpUrl = environment.getProperty("erpPartUrl"); |
| | | HttpPost httpPost = new HttpPost(syncErpUrl); |
| | | httpPost.getParams().setParameter(CoreConnectionPNames.CONNECTION_TIMEOUT, 10000); |
| | | httpPost.getParams().setParameter(CoreConnectionPNames.SO_TIMEOUT,1000 * 3600); |
| | | httpPost.getParams().setParameter(CoreConnectionPNames.SO_TIMEOUT, 1000 * 3600); |
| | | // 将参数转换为JSON字符串 |
| | | Map<String, String> params = new HashMap<>(); |
| | | // params.put("startTime", customOrderSyncDTO.getStartTime()); |
| | |
| | | } |
| | | } |
| | | |
| | | |
| | | @Transactional(rollbackFor = Exception.class) |
| | | @Override |
| | | 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(); |
| | | if (redisTemplate.hasKey(key)) { |
| | | 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>(); |
| | | 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>(); |
| | | data.forEach(l->{ |
| | | Part part = new Part(); |
| | | part.setPartNo(String.valueOf(l.get("PART_NO"))); |
| | | no.add(part.getPartNo()); |
| | | part.setPartName(String.valueOf(l.get("PART_DESC"))); |
| | | part.setMaterialType(dicmattype.get(l.get("TYPE_CODE"))); |
| | | part.setUnit(dicunit.get(l.get("UNIT_MEAS"))); |
| | | part.setAssortment(String.valueOf(l.get("FIRST_CLASS"))); |
| | | part.setCategory(String.valueOf(l.get("SECOND_CLASS"))); |
| | | part.setThreeLevelClassification(String.valueOf(l.get("THIRD_CLASS"))); |
| | | // part1.setMaterialAttribute(dicmatatype.get(part.get("ACCOUNTING_GROUP_DESC"))); |
| | | Object netWeight = Optional.ofNullable(l.get("NET_WEIGHT")).orElse("1"); |
| | | if(!Objects.equals(netWeight,"1")){ |
| | | part.setWeight(BigDecimal.valueOf(Double.parseDouble(String.valueOf(l.get("NET_WEIGHT"))))); |
| | | } |
| | | part.setEngChgLevel("1"); |
| | | part.setPlanningMethod(String.valueOf(l.get("PART_STATUS"))); |
| | | //part.setPlanningMethodIfs(l.get("PART_STATUS")); |
| | | part.setLotTrackingIfs(!(l.get("LOT_TRACK_DB").equals("NOT LOT TRACKING"))); |
| | | part.setSunit(dicunit.get(l.get("UNIT_MEAS_FOR_WEIGHT"))); |
| | | partList.add(part); |
| | | }); |
| | | 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(); |
| | | } |
| | | } |