|
|
@ -17,12 +17,14 @@ |
|
|
|
|
|
|
|
|
package com.elink.esua.epdc.modules.category.service.impl; |
|
|
package com.elink.esua.epdc.modules.category.service.impl; |
|
|
|
|
|
|
|
|
|
|
|
import cn.hutool.core.collection.CollUtil; |
|
|
import com.alibaba.fastjson.JSONArray; |
|
|
import com.alibaba.fastjson.JSONArray; |
|
|
import com.alibaba.fastjson.JSONObject; |
|
|
import com.alibaba.fastjson.JSONObject; |
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
|
|
import com.elink.esua.epdc.commons.mybatis.service.impl.BaseServiceImpl; |
|
|
import com.elink.esua.epdc.commons.mybatis.service.impl.BaseServiceImpl; |
|
|
import com.elink.esua.epdc.commons.tools.constant.Constant; |
|
|
import com.elink.esua.epdc.commons.tools.constant.Constant; |
|
|
import com.elink.esua.epdc.commons.tools.constant.NumConstant; |
|
|
import com.elink.esua.epdc.commons.tools.constant.NumConstant; |
|
|
|
|
|
import com.elink.esua.epdc.commons.tools.constant.StrConstant; |
|
|
import com.elink.esua.epdc.commons.tools.exception.ErrorCode; |
|
|
import com.elink.esua.epdc.commons.tools.exception.ErrorCode; |
|
|
import com.elink.esua.epdc.commons.tools.exception.RenException; |
|
|
import com.elink.esua.epdc.commons.tools.exception.RenException; |
|
|
import com.elink.esua.epdc.commons.tools.redis.RedisKeys; |
|
|
import com.elink.esua.epdc.commons.tools.redis.RedisKeys; |
|
|
@ -78,8 +80,7 @@ public class CategoryServiceImpl extends BaseServiceImpl<CategoryDao, CategoryEn |
|
|
|
|
|
|
|
|
private int totalCells = 0;// 总条数
|
|
|
private int totalCells = 0;// 总条数
|
|
|
|
|
|
|
|
|
public static int Guid=100;//id自增值
|
|
|
public static int Guid = 100;//id自增值
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private Logger logger = LoggerFactory.getLogger(getClass()); |
|
|
private Logger logger = LoggerFactory.getLogger(getClass()); |
|
|
@ -253,13 +254,13 @@ public class CategoryServiceImpl extends BaseServiceImpl<CategoryDao, CategoryEn |
|
|
Result result = new Result(); |
|
|
Result result = new Result(); |
|
|
//需存储的实体
|
|
|
//需存储的实体
|
|
|
List<CategoryEntity> list = new ArrayList<CategoryEntity>(); |
|
|
List<CategoryEntity> list = new ArrayList<CategoryEntity>(); |
|
|
try{ |
|
|
try { |
|
|
Workbook wb = null; |
|
|
Workbook wb = null; |
|
|
InputStream is = file.getInputStream(); |
|
|
InputStream is = file.getInputStream(); |
|
|
if ("true".equals(isExcel2003)) { |
|
|
if ("true".equals(isExcel2003)) { |
|
|
// 当excel是2003时,创建excel2003
|
|
|
// 当excel是2003时,创建excel2003
|
|
|
wb = new HSSFWorkbook(is); |
|
|
wb = new HSSFWorkbook(is); |
|
|
}else if("false".equals(isExcel2003)){ |
|
|
} else if ("false".equals(isExcel2003)) { |
|
|
// 当excel是2007时,创建excel2007
|
|
|
// 当excel是2007时,创建excel2007
|
|
|
wb = new XSSFWorkbook(is); |
|
|
wb = new XSSFWorkbook(is); |
|
|
} else { |
|
|
} else { |
|
|
@ -282,13 +283,13 @@ public class CategoryServiceImpl extends BaseServiceImpl<CategoryDao, CategoryEn |
|
|
QueryWrapper<CategoryEntity> wrapper = new QueryWrapper<CategoryEntity>(categoryEntity); |
|
|
QueryWrapper<CategoryEntity> wrapper = new QueryWrapper<CategoryEntity>(categoryEntity); |
|
|
List<CategoryEntity> categoryEntityList = baseDao.selectList(wrapper); |
|
|
List<CategoryEntity> categoryEntityList = baseDao.selectList(wrapper); |
|
|
int numm = categoryEntityList.size(); |
|
|
int numm = categoryEntityList.size(); |
|
|
if(numm >= 0){ |
|
|
if (numm >= 0) { |
|
|
numm -= 1; |
|
|
numm -= 1; |
|
|
} |
|
|
} |
|
|
//一级分类
|
|
|
//一级分类
|
|
|
String firstClassName = ""; |
|
|
String firstClassName = ""; |
|
|
Long firstClassId = 0L; |
|
|
Long firstClassId = 0L; |
|
|
Integer firstClassSort = Integer.parseInt(numm+""); |
|
|
Integer firstClassSort = Integer.parseInt(numm + ""); |
|
|
//二级分类
|
|
|
//二级分类
|
|
|
String secondClassName = ""; |
|
|
String secondClassName = ""; |
|
|
Long secondClassId = 0L; |
|
|
Long secondClassId = 0L; |
|
|
@ -319,7 +320,7 @@ public class CategoryServiceImpl extends BaseServiceImpl<CategoryDao, CategoryEn |
|
|
//领域列
|
|
|
//领域列
|
|
|
firstClassNameCurrent = ""; |
|
|
firstClassNameCurrent = ""; |
|
|
String value = getCellContent(cell); |
|
|
String value = getCellContent(cell); |
|
|
if(!"".equals(value)){ |
|
|
if (!"".equals(value)) { |
|
|
firstClassName = value; |
|
|
firstClassName = value; |
|
|
firstClassNameCurrent = value; |
|
|
firstClassNameCurrent = value; |
|
|
firstClassId = getLongRandom(); |
|
|
firstClassId = getLongRandom(); |
|
|
@ -332,7 +333,7 @@ public class CategoryServiceImpl extends BaseServiceImpl<CategoryDao, CategoryEn |
|
|
//大类列
|
|
|
//大类列
|
|
|
secondClassNameCurrent = ""; |
|
|
secondClassNameCurrent = ""; |
|
|
String value = getCellContent(cell); |
|
|
String value = getCellContent(cell); |
|
|
if(!"".equals(value)){ |
|
|
if (!"".equals(value)) { |
|
|
secondClassName = value; |
|
|
secondClassName = value; |
|
|
secondClassNameCurrent = value; |
|
|
secondClassNameCurrent = value; |
|
|
secondClassId = getLongRandom(); |
|
|
secondClassId = getLongRandom(); |
|
|
@ -344,7 +345,7 @@ public class CategoryServiceImpl extends BaseServiceImpl<CategoryDao, CategoryEn |
|
|
//小类列
|
|
|
//小类列
|
|
|
thirdClassNameCurrent = ""; |
|
|
thirdClassNameCurrent = ""; |
|
|
String value = getCellContent(cell); |
|
|
String value = getCellContent(cell); |
|
|
if(!"".equals(value)){ |
|
|
if (!"".equals(value)) { |
|
|
thirdClassName = value; |
|
|
thirdClassName = value; |
|
|
thirdClassNameCurrent = value; |
|
|
thirdClassNameCurrent = value; |
|
|
thirdClassId = getLongRandom(); |
|
|
thirdClassId = getLongRandom(); |
|
|
@ -355,7 +356,7 @@ public class CategoryServiceImpl extends BaseServiceImpl<CategoryDao, CategoryEn |
|
|
//细类名称列
|
|
|
//细类名称列
|
|
|
fourthClassNameCurrent = ""; |
|
|
fourthClassNameCurrent = ""; |
|
|
String value = getCellContent(cell); |
|
|
String value = getCellContent(cell); |
|
|
if(!"".equals(value)){ |
|
|
if (!"".equals(value)) { |
|
|
fourthClassName = value; |
|
|
fourthClassName = value; |
|
|
fourthClassNameCurrent = value; |
|
|
fourthClassNameCurrent = value; |
|
|
fourthClassId = getLongRandom(); |
|
|
fourthClassId = getLongRandom(); |
|
|
@ -364,36 +365,36 @@ public class CategoryServiceImpl extends BaseServiceImpl<CategoryDao, CategoryEn |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
if(!"".equals(firstClassNameCurrent)){ |
|
|
if (!"".equals(firstClassNameCurrent)) { |
|
|
//领域
|
|
|
//领域
|
|
|
CategoryEntity insertEntity = getCategoryEntity(firstClassId,0L,"0",firstClassName, |
|
|
CategoryEntity insertEntity = getCategoryEntity(firstClassId, 0L, "0", firstClassName, |
|
|
firstClassId+"","0",firstClassSort,0,""); |
|
|
firstClassId + "", "0", firstClassSort, 0, ""); |
|
|
list.add(insertEntity); |
|
|
list.add(insertEntity); |
|
|
} |
|
|
} |
|
|
if(!"".equals(secondClassNameCurrent)){ |
|
|
if (!"".equals(secondClassNameCurrent)) { |
|
|
//大类
|
|
|
//大类
|
|
|
CategoryEntity insertEntity = getCategoryEntity(secondClassId,firstClassId,firstClassId+"",secondClassName, |
|
|
CategoryEntity insertEntity = getCategoryEntity(secondClassId, firstClassId, firstClassId + "", secondClassName, |
|
|
secondClassId+"","1",secondClassSort,0,firstClassName); |
|
|
secondClassId + "", "1", secondClassSort, 0, firstClassName); |
|
|
list.add(insertEntity); |
|
|
list.add(insertEntity); |
|
|
} |
|
|
} |
|
|
if(!"".equals(thirdClassNameCurrent)){ |
|
|
if (!"".equals(thirdClassNameCurrent)) { |
|
|
//小类
|
|
|
//小类
|
|
|
String pids = firstClassId + "," + secondClassId + ""; |
|
|
String pids = firstClassId + "," + secondClassId + ""; |
|
|
CategoryEntity insertEntity = getCategoryEntity(thirdClassId,secondClassId,pids,thirdClassName, |
|
|
CategoryEntity insertEntity = getCategoryEntity(thirdClassId, secondClassId, pids, thirdClassName, |
|
|
thirdClassId+"","2",thirdClassSort,0,secondClassName); |
|
|
thirdClassId + "", "2", thirdClassSort, 0, secondClassName); |
|
|
list.add(insertEntity); |
|
|
list.add(insertEntity); |
|
|
} |
|
|
} |
|
|
if(!"".equals(fourthClassNameCurrent)){ |
|
|
if (!"".equals(fourthClassNameCurrent)) { |
|
|
//细分类
|
|
|
//细分类
|
|
|
String pids = firstClassId + "," + secondClassId + "," + thirdClassId + ""; |
|
|
String pids = firstClassId + "," + secondClassId + "," + thirdClassId + ""; |
|
|
CategoryEntity insertEntity = getCategoryEntity(fourthClassId,thirdClassId,pids,fourthClassName, |
|
|
CategoryEntity insertEntity = getCategoryEntity(fourthClassId, thirdClassId, pids, fourthClassName, |
|
|
fourthClassId+"","3",fourthClassSort,0,thirdClassName); |
|
|
fourthClassId + "", "3", fourthClassSort, 0, thirdClassName); |
|
|
list.add(insertEntity); |
|
|
list.add(insertEntity); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
if(list.size() > 0){ |
|
|
if (list.size() > 0) { |
|
|
CategoryEntity[] categoryEntities = new CategoryEntity[list.size()]; |
|
|
CategoryEntity[] categoryEntities = new CategoryEntity[list.size()]; |
|
|
for(int k = 0 ; k < list.size() ; k++){ |
|
|
for (int k = 0; k < list.size(); k++) { |
|
|
categoryEntities[k] = list.get(k); |
|
|
categoryEntities[k] = list.get(k); |
|
|
} |
|
|
} |
|
|
baseDao.insertList(categoryEntities); |
|
|
baseDao.insertList(categoryEntities); |
|
|
@ -402,7 +403,7 @@ public class CategoryServiceImpl extends BaseServiceImpl<CategoryDao, CategoryEn |
|
|
result.setCode(0); |
|
|
result.setCode(0); |
|
|
result.setData("数据导入成功!"); |
|
|
result.setData("数据导入成功!"); |
|
|
return result; |
|
|
return result; |
|
|
}catch(Exception e){ |
|
|
} catch (Exception e) { |
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
result.setMsg("defeat"); |
|
|
result.setMsg("defeat"); |
|
|
@ -413,10 +414,11 @@ public class CategoryServiceImpl extends BaseServiceImpl<CategoryDao, CategoryEn |
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
|
* 获取单元格内容 |
|
|
* 获取单元格内容 |
|
|
|
|
|
* |
|
|
* @param cell |
|
|
* @param cell |
|
|
* @return |
|
|
* @return |
|
|
*/ |
|
|
*/ |
|
|
public String getCellContent(Cell cell){ |
|
|
public String getCellContent(Cell cell) { |
|
|
String value = ""; |
|
|
String value = ""; |
|
|
if (cell.getCellType() == HSSFCell.CELL_TYPE_NUMERIC) { |
|
|
if (cell.getCellType() == HSSFCell.CELL_TYPE_NUMERIC) { |
|
|
value = String.valueOf(cell.getNumericCellValue()); |
|
|
value = String.valueOf(cell.getNumericCellValue()); |
|
|
@ -424,33 +426,35 @@ public class CategoryServiceImpl extends BaseServiceImpl<CategoryDao, CategoryEn |
|
|
value = cell.getStringCellValue(); |
|
|
value = cell.getStringCellValue(); |
|
|
} |
|
|
} |
|
|
//内容超过25个字进行长度限制,否则数据库会超限
|
|
|
//内容超过25个字进行长度限制,否则数据库会超限
|
|
|
if(value.length() > 25){ |
|
|
if (value.length() > 25) { |
|
|
value = value.substring(0,25) + "..."; |
|
|
value = value.substring(0, 25) + "..."; |
|
|
} |
|
|
} |
|
|
return value; |
|
|
return value; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
|
* 获取19位随机数 |
|
|
* 获取19位随机数 |
|
|
|
|
|
* |
|
|
* @return |
|
|
* @return |
|
|
*/ |
|
|
*/ |
|
|
public Long getLongRandom(){ |
|
|
public Long getLongRandom() { |
|
|
Guid+=1; |
|
|
Guid += 1; |
|
|
long now = System.currentTimeMillis(); |
|
|
long now = System.currentTimeMillis(); |
|
|
SimpleDateFormat dateFormat=new SimpleDateFormat("MMdd"); |
|
|
SimpleDateFormat dateFormat = new SimpleDateFormat("MMdd"); |
|
|
String time=dateFormat.format(now); |
|
|
String time = dateFormat.format(now); |
|
|
String currentTimeMillis=now+""; |
|
|
String currentTimeMillis = now + ""; |
|
|
int ran=0; |
|
|
int ran = 0; |
|
|
if(Guid>999){ |
|
|
if (Guid > 999) { |
|
|
Guid=100; |
|
|
Guid = 100; |
|
|
} |
|
|
} |
|
|
ran=Guid; |
|
|
ran = Guid; |
|
|
String str = time+currentTimeMillis.substring(1, currentTimeMillis.length())+ran; |
|
|
String str = time + currentTimeMillis.substring(1, currentTimeMillis.length()) + ran; |
|
|
return Long.parseLong(str); |
|
|
return Long.parseLong(str); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
|
* 拼接entity |
|
|
* 拼接entity |
|
|
|
|
|
* |
|
|
* @param id ID |
|
|
* @param id ID |
|
|
* @param pid 上级分类ID |
|
|
* @param pid 上级分类ID |
|
|
* @param categoryName 分类名称 |
|
|
* @param categoryName 分类名称 |
|
|
@ -460,8 +464,8 @@ public class CategoryServiceImpl extends BaseServiceImpl<CategoryDao, CategoryEn |
|
|
* @param delFlag 删除标识 0:未删除 1:删除 |
|
|
* @param delFlag 删除标识 0:未删除 1:删除 |
|
|
* @param parentName 上级部门名称 |
|
|
* @param parentName 上级部门名称 |
|
|
*/ |
|
|
*/ |
|
|
public CategoryEntity getCategoryEntity(Long id,Long pid,String pids,String categoryName,String categoryCode, |
|
|
public CategoryEntity getCategoryEntity(Long id, Long pid, String pids, String categoryName, String categoryCode, |
|
|
String categoryType,Integer sort,Integer delFlag,String parentName) { |
|
|
String categoryType, Integer sort, Integer delFlag, String parentName) { |
|
|
CategoryEntity entity = new CategoryEntity(); |
|
|
CategoryEntity entity = new CategoryEntity(); |
|
|
Long userId = SecurityUser.getUserId(); |
|
|
Long userId = SecurityUser.getUserId(); |
|
|
entity.setId(id); |
|
|
entity.setId(id); |
|
|
@ -482,6 +486,7 @@ public class CategoryServiceImpl extends BaseServiceImpl<CategoryDao, CategoryEn |
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
|
* 获取excle版本 |
|
|
* 获取excle版本 |
|
|
|
|
|
* |
|
|
* @param mFile |
|
|
* @param mFile |
|
|
* @return |
|
|
* @return |
|
|
*/ |
|
|
*/ |
|
|
@ -504,6 +509,7 @@ public class CategoryServiceImpl extends BaseServiceImpl<CategoryDao, CategoryEn |
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
|
* 验证EXCEL文件 |
|
|
* 验证EXCEL文件 |
|
|
|
|
|
* |
|
|
* @param filePath |
|
|
* @param filePath |
|
|
* @return |
|
|
* @return |
|
|
*/ |
|
|
*/ |
|
|
@ -518,6 +524,7 @@ public class CategoryServiceImpl extends BaseServiceImpl<CategoryDao, CategoryEn |
|
|
public static boolean isExcel2003(String filePath) { |
|
|
public static boolean isExcel2003(String filePath) { |
|
|
return filePath.matches("^.+\\.(?i)(xls)$"); |
|
|
return filePath.matches("^.+\\.(?i)(xls)$"); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
// @描述:是否是2007的excel,返回true是2007
|
|
|
// @描述:是否是2007的excel,返回true是2007
|
|
|
public static boolean isExcel2007(String filePath) { |
|
|
public static boolean isExcel2007(String filePath) { |
|
|
return filePath.matches("^.+\\.(?i)(xlsx)$"); |
|
|
return filePath.matches("^.+\\.(?i)(xlsx)$"); |
|
|
@ -550,24 +557,37 @@ public class CategoryServiceImpl extends BaseServiceImpl<CategoryDao, CategoryEn |
|
|
**/ |
|
|
**/ |
|
|
@Override |
|
|
@Override |
|
|
public List<CategoryInfoResultDTO> listCategoryInfo(CategoryInfoFormDTO formDTO) { |
|
|
public List<CategoryInfoResultDTO> listCategoryInfo(CategoryInfoFormDTO formDTO) { |
|
|
List<CategoryInfoResultDTO> categoryInfoResultDTOList = new ArrayList<>(); |
|
|
List<CategoryInfoResultDTO> result = Lists.newArrayList(); |
|
|
|
|
|
CategoryInfoResultDTO categoryInfoResult; |
|
|
|
|
|
|
|
|
for (Long id : formDTO.getIds()) { |
|
|
for (Long id : formDTO.getIds()) { |
|
|
CategoryEntity entity = baseDao.getById(id); |
|
|
CategoryEntity entity = baseDao.getById(id); |
|
|
if (null != entity) { |
|
|
if (null == entity) { |
|
|
List<String> parentNameList = new ArrayList<>(); |
|
|
continue; |
|
|
if (StringUtils.isNotBlank(entity.getPids())) { |
|
|
} |
|
|
String[] pidList = entity.getPids().split(","); |
|
|
if(StringUtils.isBlank(entity.getPids())){ |
|
|
for (String pid : pidList) { |
|
|
categoryInfoResult = ConvertUtils.sourceToTarget(entity, CategoryInfoResultDTO.class); |
|
|
CategoryEntity parentEntity = baseDao.getById(Long.valueOf(pid)); |
|
|
result.add(categoryInfoResult); |
|
|
|
|
|
continue; |
|
|
|
|
|
} |
|
|
|
|
|
List<String> parentNameList = Lists.newArrayList(); |
|
|
|
|
|
String[] pidList = entity.getPids().split(StrConstant.COMMA); |
|
|
|
|
|
if (null != pidList && pidList.length > NumConstant.ZERO) { |
|
|
|
|
|
CategoryEntity parentEntity; |
|
|
|
|
|
for (int i = 0; i < pidList.length; i++) { |
|
|
|
|
|
parentEntity = baseDao.getById(Long.valueOf(pidList[i])); |
|
|
|
|
|
if (null != parentEntity) { |
|
|
parentNameList.add(parentEntity.getCategoryName()); |
|
|
parentNameList.add(parentEntity.getCategoryName()); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
CategoryInfoResultDTO categoryInfoResultDTO = ConvertUtils.sourceToTarget(entity, CategoryInfoResultDTO.class); |
|
|
|
|
|
categoryInfoResultDTO.setParentNames(parentNameList); |
|
|
|
|
|
categoryInfoResultDTOList.add(categoryInfoResultDTO); |
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
categoryInfoResult = ConvertUtils.sourceToTarget(entity, CategoryInfoResultDTO.class); |
|
|
|
|
|
if (CollUtil.isNotEmpty(parentNameList)) { |
|
|
|
|
|
categoryInfoResult.setParentNames(StringUtils.join(parentNameList, StrConstant.HYPHEN)); |
|
|
} |
|
|
} |
|
|
return categoryInfoResultDTOList; |
|
|
result.add(categoryInfoResult); |
|
|
|
|
|
} |
|
|
|
|
|
return result; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
|
|