|
|
@ -34,11 +34,23 @@ import com.yxt.common.base.utils.StringUtils; |
|
|
|
import com.yxt.common.core.query.PagerQuery; |
|
|
|
import com.yxt.common.core.result.ResultBean; |
|
|
|
import com.yxt.common.core.vo.PagerVo; |
|
|
|
import org.apache.poi.hssf.usermodel.HSSFWorkbook; |
|
|
|
import org.apache.poi.ss.usermodel.Cell; |
|
|
|
import org.apache.poi.ss.usermodel.Row; |
|
|
|
import org.apache.poi.ss.usermodel.Sheet; |
|
|
|
import org.apache.poi.ss.usermodel.Workbook; |
|
|
|
import org.apache.poi.xssf.usermodel.XSSFWorkbook; |
|
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
|
import org.springframework.stereotype.Service; |
|
|
|
import org.springframework.transaction.annotation.Transactional; |
|
|
|
import org.springframework.web.multipart.MultipartFile; |
|
|
|
|
|
|
|
import javax.servlet.http.HttpServletRequest; |
|
|
|
import java.io.File; |
|
|
|
import java.io.InputStream; |
|
|
|
import java.util.*; |
|
|
|
import java.util.regex.Matcher; |
|
|
|
import java.util.regex.Pattern; |
|
|
|
|
|
|
|
/** |
|
|
|
* @author wangpengfei |
|
|
@ -588,7 +600,7 @@ public class BaseGoodsSpuService extends MybatisBaseService<BaseGoodsSpuMapper, |
|
|
|
return rb.success().setData(i); |
|
|
|
} |
|
|
|
|
|
|
|
public ResultBean<List<YxtBaseFormCommon>> selPurchaseAssetInfo(String orgPath,String name) { |
|
|
|
public ResultBean<List<YxtBaseFormCommon>> selPurchaseAssetInfo(String orgPath, String name) { |
|
|
|
ResultBean rb = ResultBean.fireFail(); |
|
|
|
List<YxtBaseFormCommon> list = new ArrayList<>(); |
|
|
|
String useOrgSid = ""; |
|
|
@ -603,7 +615,7 @@ public class BaseGoodsSpuService extends MybatisBaseService<BaseGoodsSpuMapper, |
|
|
|
useOrgSid = sysOrganization.getSid(); |
|
|
|
} |
|
|
|
} |
|
|
|
List<BaseGoodsSpu> goodsSpus = baseMapper.selPurchaseAssetInfo(useOrgSid,name); |
|
|
|
List<BaseGoodsSpu> goodsSpus = baseMapper.selPurchaseAssetInfo(useOrgSid, name); |
|
|
|
if (!goodsSpus.isEmpty()) { |
|
|
|
goodsSpus.stream().forEach(details -> { |
|
|
|
YxtBaseFormCommon formCommon = new YxtBaseFormCommon(); |
|
|
@ -639,4 +651,269 @@ public class BaseGoodsSpuService extends MybatisBaseService<BaseGoodsSpuMapper, |
|
|
|
String typeName = baseMapper.selGoodsTypeBySid(sid); |
|
|
|
return rb.success().setData(typeName); |
|
|
|
} |
|
|
|
|
|
|
|
public ResultBean importGoodsSpuData(MultipartFile file, String orgPath, String userSid, HttpServletRequest request) { |
|
|
|
ResultBean rb = ResultBean.fireFail(); |
|
|
|
String useOrgSid = "";//部门sid
|
|
|
|
List<String> split = Arrays.asList(orgPath.split("/")); |
|
|
|
if (split.size() > 1) { |
|
|
|
//获取本级sid获取本级部门信息
|
|
|
|
SysOrganizationVo sysOrganization1 = sysOrganizationFeign.fetchBySid(split.get(split.size() - 1)).getData(); |
|
|
|
useOrgSid = sysOrganization1.getSid(); |
|
|
|
} else { |
|
|
|
SysOrganizationVo sysOrganization = sysOrganizationFeign.fetchBySid(split.get(0)).getData(); |
|
|
|
useOrgSid = sysOrganization.getSid(); |
|
|
|
} |
|
|
|
|
|
|
|
int size = 0; |
|
|
|
try { |
|
|
|
String temp = request.getSession().getServletContext().getRealPath(File.separator) + "temp";// 临时目录
|
|
|
|
File tempFile = new File(temp); |
|
|
|
if (!tempFile.exists()) { |
|
|
|
tempFile.mkdirs(); |
|
|
|
} |
|
|
|
String fileName = file.getOriginalFilename(); |
|
|
|
if (!fileName.matches("^.+\\.(?i)(xls)$") && !fileName.matches("^.+\\.(?i)(xlsx)$")) { |
|
|
|
return rb.fail().setMsg("上传文件不正确"); |
|
|
|
} |
|
|
|
boolean isExcel2003 = true; |
|
|
|
if (fileName.matches("^.+\\.(?i)(xlsx)$")) { |
|
|
|
isExcel2003 = false; |
|
|
|
} |
|
|
|
InputStream is = file.getInputStream(); |
|
|
|
Workbook wb = null; |
|
|
|
if (isExcel2003) { |
|
|
|
wb = new HSSFWorkbook(is); |
|
|
|
} else { |
|
|
|
wb = new XSSFWorkbook(is); |
|
|
|
} |
|
|
|
Sheet sheet = wb.getSheetAt(0); |
|
|
|
ReturnImportMsg returnMsg = getSleepSheetVal(sheet); |
|
|
|
Set<String> setMsg = returnMsg.getSetMsg(); |
|
|
|
StringBuffer sbMsg = new StringBuffer(); |
|
|
|
List<ImportDataVo> list = returnMsg.getList(); |
|
|
|
if (!list.isEmpty() && list.size() > 0) { |
|
|
|
for (ImportDataVo vo : list) { |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
if (null != setMsg && setMsg.size() > 0) { |
|
|
|
for (String s : setMsg) { |
|
|
|
sbMsg.append(s).append(","); |
|
|
|
} |
|
|
|
sbMsg.delete(sbMsg.length() - 1, sbMsg.length()); |
|
|
|
if (StringUtils.isNotBlank(sbMsg.toString())) { |
|
|
|
return rb.setMsg(sbMsg.toString()); |
|
|
|
} |
|
|
|
} |
|
|
|
size = list.size(); |
|
|
|
} catch (Exception e) { |
|
|
|
e.printStackTrace(); |
|
|
|
} |
|
|
|
return rb.success().setMsg("成功导入" + size + "条数据"); |
|
|
|
} |
|
|
|
|
|
|
|
private ReturnImportMsg getSleepSheetVal(Sheet sheet) { |
|
|
|
ReturnImportMsg returnMsg = new ReturnImportMsg(); |
|
|
|
List<ImportDataVo> voList = new ArrayList<>(); |
|
|
|
Set<String> setMsg = new HashSet<>(); |
|
|
|
Row row1 = sheet.getRow(0); |
|
|
|
Map<Integer, String> header = new HashMap<>(); |
|
|
|
Map<String, String> map = new HashMap<>(); |
|
|
|
for (int i = 0; i < 13; i++) { |
|
|
|
String trim = new String(); |
|
|
|
try { |
|
|
|
trim = getCellVal(row1.getCell(i)).toString().trim(); |
|
|
|
String temp = getCellVal(row1.getCell(i)).toString().trim(); |
|
|
|
if (StringUtils.isNotBlank(temp)) { |
|
|
|
header.put(i, temp); |
|
|
|
} |
|
|
|
} catch (Exception e) { |
|
|
|
e.printStackTrace(); |
|
|
|
} |
|
|
|
} |
|
|
|
for (int r = 1; r <= sheet.getLastRowNum(); r++) { |
|
|
|
ImportDataVo info = new ImportDataVo(); |
|
|
|
Row row = sheet.getRow(r); |
|
|
|
if (row == null) { |
|
|
|
continue; |
|
|
|
} |
|
|
|
for (int i = 0; i < header.size(); i++) { |
|
|
|
// String trim = new String();
|
|
|
|
try { |
|
|
|
// trim = getCellVal(row.getCell(i)).toString().trim();
|
|
|
|
String temp = ""; |
|
|
|
if (null != getCellVal(row.getCell(i))) { |
|
|
|
temp = getCellVal(row.getCell(i)).toString().trim(); |
|
|
|
} |
|
|
|
String head = header.get(i); |
|
|
|
String field = ""; |
|
|
|
if (StringUtils.isNotBlank(temp)) { |
|
|
|
field = temp; |
|
|
|
} |
|
|
|
if (head.equals("*排序号")) { |
|
|
|
if (StringUtils.isBlank(field)) { |
|
|
|
setMsg.add("第" + (r + 1) + "行排序号不能为空"); |
|
|
|
} else { |
|
|
|
if (!isNum(field)) { |
|
|
|
setMsg.add("第" + (r + 1) + "行排序号请填写数字"); |
|
|
|
} else { |
|
|
|
int parseInt = Integer.parseInt(field); |
|
|
|
field = String.valueOf(parseInt); |
|
|
|
} |
|
|
|
} |
|
|
|
info.setSortNo(field); |
|
|
|
} |
|
|
|
if (head.equals("*商品名称")) { |
|
|
|
if (StringUtils.isBlank(field)) { |
|
|
|
setMsg.add("第" + (r + 1) + "行商品名称不能为空"); |
|
|
|
} |
|
|
|
info.setGoodsName(field); |
|
|
|
} |
|
|
|
if (head.equals("*图号")) { |
|
|
|
if (StringUtils.isBlank(field)) { |
|
|
|
setMsg.add("第" + (r + 1) + "行图号不能为空"); |
|
|
|
} |
|
|
|
info.setGoodsCode(field); |
|
|
|
} |
|
|
|
if (head.equals("商品条码")) { |
|
|
|
info.setBarCode(field); |
|
|
|
} |
|
|
|
if (head.equals("*商品类别")) { |
|
|
|
if (StringUtils.isBlank(field)) { |
|
|
|
setMsg.add("第" + (r + 1) + "行商品类别不能为空"); |
|
|
|
} |
|
|
|
info.setGoodsTypeName(field); |
|
|
|
} |
|
|
|
if (head.equals("*品牌")) { |
|
|
|
if (StringUtils.isBlank(field)) { |
|
|
|
setMsg.add("第" + (r + 1) + "行品牌不能为空"); |
|
|
|
} |
|
|
|
info.setBrandName(field); |
|
|
|
} |
|
|
|
if (head.equals("*厂家")) { |
|
|
|
if (StringUtils.isBlank(field)) { |
|
|
|
setMsg.add("第" + (r + 1) + "行厂家不能为空"); |
|
|
|
} |
|
|
|
info.setManufacturerName(field); |
|
|
|
} |
|
|
|
if (head.equals("规格")) { |
|
|
|
info.setIndexes(field); |
|
|
|
} |
|
|
|
if (head.equals("*计量单位")) { |
|
|
|
if (StringUtils.isBlank(field)) { |
|
|
|
setMsg.add("第" + (r + 1) + "行计量单位不能为空"); |
|
|
|
} |
|
|
|
info.setGoodsUnitName(field); |
|
|
|
} |
|
|
|
if (head.equals("*库存上限")) { |
|
|
|
if (StringUtils.isBlank(field)) { |
|
|
|
setMsg.add("第" + (r + 1) + "行库存上限不能为空"); |
|
|
|
} else { |
|
|
|
if (!isNum(field)) { |
|
|
|
setMsg.add("第" + (r + 1) + "行库存上限请填写数字"); |
|
|
|
} else { |
|
|
|
int parseInt = Integer.parseInt(field); |
|
|
|
field = String.valueOf(parseInt); |
|
|
|
} |
|
|
|
} |
|
|
|
info.setInventoryAlertUpperLimit(field); |
|
|
|
} |
|
|
|
if (head.equals("*库存下限")) { |
|
|
|
if (StringUtils.isBlank(field)) { |
|
|
|
setMsg.add("第" + (r + 1) + "行库存下限不能为空"); |
|
|
|
} else { |
|
|
|
if (!isNum(field)) { |
|
|
|
setMsg.add("第" + (r + 1) + "行库存下限请填写数字"); |
|
|
|
} else { |
|
|
|
int parseInt = Integer.parseInt(field); |
|
|
|
field = String.valueOf(parseInt); |
|
|
|
} |
|
|
|
} |
|
|
|
info.setInventoryAlertLowerLimit(field); |
|
|
|
} |
|
|
|
if (head.equals("*商品等级")) { |
|
|
|
if (StringUtils.isBlank(field)) { |
|
|
|
setMsg.add("第" + (r + 1) + "行商品等级不能为空"); |
|
|
|
} |
|
|
|
info.setGoodsLevelValue(field); |
|
|
|
} |
|
|
|
if (head.equals("*商品类型")) { |
|
|
|
if (StringUtils.isBlank(field)) { |
|
|
|
setMsg.add("第" + (r + 1) + "行商品类型不能为空"); |
|
|
|
} |
|
|
|
info.setGoodsClassValue(field); |
|
|
|
} |
|
|
|
} catch (Exception e) { |
|
|
|
e.printStackTrace(); |
|
|
|
continue; |
|
|
|
} |
|
|
|
} |
|
|
|
voList.add(info); |
|
|
|
} |
|
|
|
returnMsg.setList(voList); |
|
|
|
returnMsg.setSetMsg(setMsg); |
|
|
|
return returnMsg; |
|
|
|
} |
|
|
|
|
|
|
|
public Object getCellVal(Cell cell) { |
|
|
|
Object obj = null; |
|
|
|
if (cell != null) { |
|
|
|
switch (cell.getCellTypeEnum()) { |
|
|
|
case BOOLEAN: |
|
|
|
obj = cell.getBooleanCellValue(); |
|
|
|
break; |
|
|
|
case ERROR: |
|
|
|
obj = cell.getErrorCellValue(); |
|
|
|
break; |
|
|
|
case NUMERIC: |
|
|
|
obj = cell.getNumericCellValue(); |
|
|
|
break; |
|
|
|
case STRING: |
|
|
|
obj = cell.getStringCellValue(); |
|
|
|
break; |
|
|
|
default: |
|
|
|
break; |
|
|
|
} |
|
|
|
} |
|
|
|
return obj; |
|
|
|
} |
|
|
|
|
|
|
|
public boolean isNum(String s) { |
|
|
|
if (org.apache.commons.lang3.StringUtils.isNotBlank(s)) { |
|
|
|
if (s.contains(".")) { |
|
|
|
return isNumeric(s); |
|
|
|
} else { |
|
|
|
return isNumericFirst(s); |
|
|
|
} |
|
|
|
} |
|
|
|
return false; |
|
|
|
} |
|
|
|
|
|
|
|
public boolean isNumeric(String s) { |
|
|
|
String substring = s.substring(0, s.lastIndexOf(".")); |
|
|
|
String substringLast = s.substring(s.lastIndexOf(".") + 1, s.length()); |
|
|
|
if (substring != null && !"".equals(substring.trim()) || substringLast != null && !"".equals(substringLast.trim())) { |
|
|
|
boolean matches = substring.matches("^[0-9]*$"); |
|
|
|
boolean b = substringLast.matches("^[0-9]*$"); |
|
|
|
if (matches && b) { |
|
|
|
return true; |
|
|
|
} else { |
|
|
|
return false; |
|
|
|
} |
|
|
|
} else |
|
|
|
return false; |
|
|
|
} |
|
|
|
|
|
|
|
public boolean isNumericFirst(String str) { |
|
|
|
Pattern pattern = Pattern.compile("[0-9]*"); |
|
|
|
System.out.println(str); |
|
|
|
Matcher isNum = pattern.matcher(str); |
|
|
|
if (!isNum.matches()) { |
|
|
|
return false; |
|
|
|
} |
|
|
|
return true; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|