| | |
| | | package com.doumee.service.business.impl; |
| | | |
| | | import com.alibaba.fastjson.JSONArray; |
| | | import com.alibaba.fastjson.JSONObject; |
| | | import com.doumee.core.annotation.excel.ExcelImporter; |
| | | import com.doumee.core.constants.Constants; |
| | | import com.doumee.core.constants.ResponseStatus; |
| | |
| | | import com.doumee.dao.business.model.Company; |
| | | import com.doumee.dao.business.vo.CategoryDcaProblemDto; |
| | | import com.doumee.dao.business.vo.CompanyTree; |
| | | import com.doumee.dao.web.vo.CategoryMapTree; |
| | | import com.doumee.dao.web.vo.CategoryVO; |
| | | import com.doumee.dao.web.vo.CategoryVOTree; |
| | | import com.doumee.dao.business.vo.CategoryTree; |
| | |
| | | |
| | | import javax.annotation.PostConstruct; |
| | | import javax.annotation.Resource; |
| | | import java.io.BufferedReader; |
| | | import java.io.FileReader; |
| | | import java.io.IOException; |
| | | import java.io.Serializable; |
| | | import java.util.ArrayList; |
| | | import java.util.Date; |
| | | import java.util.List; |
| | | import java.util.Objects; |
| | | import java.util.*; |
| | | import java.util.stream.Collectors; |
| | | |
| | | /** |
| | |
| | | } |
| | | } |
| | | |
| | | |
| | | |
| | | @Override |
| | | public void dealjson(){ |
| | | String json = ""; |
| | | BufferedReader reader = null; |
| | | try { |
| | | reader = new BufferedReader(new FileReader("d://file.txt")); |
| | | String line; |
| | | while ((line = reader.readLine()) != null) { |
| | | json = json + line; |
| | | } |
| | | } catch (IOException e) { |
| | | e.printStackTrace(); |
| | | } finally { |
| | | try { |
| | | if (reader != null){ |
| | | reader.close(); |
| | | }; |
| | | } catch (IOException e) { |
| | | e.printStackTrace(); |
| | | } |
| | | } |
| | | JSONObject jsonObject = JSONObject.parseObject(json); |
| | | JSONArray jsonArray = jsonObject.getJSONArray("data"); |
| | | |
| | | List<Map<String,Object>> mapList = new ArrayList<>(); |
| | | for (int i = 0; i < jsonArray.size(); i++) { |
| | | JSONObject jsons = jsonArray.getJSONObject(i); |
| | | Map<String,Object> map = new HashMap<>(); |
| | | map.put("id",jsons.getString("id")); |
| | | map.put("level",jsons.getInteger("level")); |
| | | map.put("name",jsons.getString("name")); |
| | | map.put("parentId",jsons.getString("parentId")); |
| | | mapList.add(map); |
| | | } |
| | | CategoryMapTree categoryMapTree = new CategoryMapTree(mapList); |
| | | mapList = categoryMapTree.buildTree(); |
| | | |
| | | for (Map<String,Object> map:mapList) { |
| | | Category category = new Category(); |
| | | category.setCreateDate(new Date()); |
| | | category.setIsdeleted(Constants.ZERO); |
| | | category.setStatus(Constants.ZERO); |
| | | category.setType(Constants.SIX); |
| | | category.setName(map.get("name").toString()); |
| | | category.setNamePath(map.get("name").toString()); |
| | | categoryMapper.insert(category); |
| | | if(Objects.nonNull(map.get("childTree"))){ |
| | | List<Map<String,Object>> childOneMap = (List<Map<String, Object>>) map.get("childTree"); |
| | | for (Map<String,Object> oneMap:childOneMap) { |
| | | Category oneCategory = new Category(); |
| | | oneCategory.setCreateDate(new Date()); |
| | | oneCategory.setIsdeleted(Constants.ZERO); |
| | | oneCategory.setStatus(Constants.ZERO); |
| | | oneCategory.setType(Constants.SIX); |
| | | oneCategory.setName(oneMap.get("name").toString()); |
| | | oneCategory.setNamePath(category.getNamePath()+"/"+oneCategory.getName()); |
| | | oneCategory.setParentId(category.getId()); |
| | | categoryMapper.insert(oneCategory); |
| | | |
| | | if(Objects.nonNull(oneMap.get("childTree"))){ |
| | | List<Map<String,Object>> childTwoMap = (List<Map<String, Object>>) oneMap.get("childTree"); |
| | | for (Map<String,Object> twoMap:childTwoMap) { |
| | | Category twoCategory = new Category(); |
| | | twoCategory.setCreateDate(new Date()); |
| | | twoCategory.setIsdeleted(Constants.ZERO); |
| | | twoCategory.setStatus(Constants.ZERO); |
| | | twoCategory.setType(Constants.SIX); |
| | | twoCategory.setName(twoMap.get("name").toString()); |
| | | twoCategory.setNamePath(oneCategory.getNamePath() + "/" + twoCategory.getName()); |
| | | twoCategory.setParentId(oneCategory.getId()); |
| | | categoryMapper.insert(twoCategory); |
| | | } |
| | | } |
| | | } |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | } |
| | | |
| | | } |
| | | |
| | | |
| | | |
| | | |
| | | // for (int i = 0; i < jsonArray.size(); i++) { |
| | | // JSONObject jsonObject1 = jsonArray.getJSONObject(i); |
| | | // if(Constants.equalsInteger(jsonObject1.getInteger("level"),Constants.ONE)){ |
| | | // Boolean iHavaChild = false; |
| | | // for (int k = 0; i < jsonArray.size(); i++) { |
| | | // JSONObject jsonObject2 = jsonArray.getJSONObject(k); |
| | | // |
| | | // Boolean kHavaChild = false; |
| | | // if(Constants.equalsInteger(jsonObject2.getInteger("level"),Constants.TWO) |
| | | // &&jsonObject2.getString("parentId").equals(jsonObject1.getString("id"))){ |
| | | // iHavaChild = true; |
| | | // |
| | | // for (int g = 0; i < jsonArray.size(); i++) { |
| | | // JSONObject jsonObject3 = jsonArray.getJSONObject(g); |
| | | // if(Constants.equalsInteger(jsonObject3.getInteger("level"),Constants.THREE) |
| | | // &&jsonObject3.getString("parentId").equals(jsonObject2.getString("id"))) { |
| | | // kHavaChild = true; |
| | | // |
| | | // System.out.println(j.getString("id")+"---"+j.getString("name").replace("\n","")+"---"+j.getInteger("level")+"---"+j.getString("parentId")); |
| | | // } |
| | | // } |
| | | // |
| | | // } |
| | | // } |
| | | // if(!iHavaChild){ |
| | | // |
| | | // } |
| | | // } |
| | | // |
| | | // |
| | | //// System.out.println(j.getString("id")+"---"+j.getString("name").replace("\n","")+"---"+j.getInteger("level")+"---"+j.getString("parentId")); |
| | | // } |
| | | |
| | | |
| | | |
| | | } |
| | | |
| | | } |