完善单据明细导入接口的逻辑
This commit is contained in:
@@ -877,7 +877,6 @@ public class DepotItemController {
|
|||||||
String message = "";
|
String message = "";
|
||||||
try {
|
try {
|
||||||
String barCodes = "";
|
String barCodes = "";
|
||||||
Map<String, Map<String, String>> barCodeNumMap = new HashMap<>();
|
|
||||||
//文件合法性校验
|
//文件合法性校验
|
||||||
Sheet src = null;
|
Sheet src = null;
|
||||||
try {
|
try {
|
||||||
@@ -889,31 +888,32 @@ public class DepotItemController {
|
|||||||
res.code = 400;
|
res.code = 400;
|
||||||
res.data = data;
|
res.data = data;
|
||||||
}
|
}
|
||||||
int length = src.getRows();
|
if(src.getRows()>1000) {
|
||||||
if(length>1000) {
|
|
||||||
message = "导入失败,明细不能超出1000条";
|
message = "导入失败,明细不能超出1000条";
|
||||||
res.code = 500;
|
res.code = 500;
|
||||||
data.put("message", message);
|
data.put("message", message);
|
||||||
res.data = data;
|
res.data = data;
|
||||||
} else {
|
} else {
|
||||||
for (int i = 2; i < length; i++) {
|
List<Map<String, String>> detailList = new ArrayList<>();
|
||||||
|
for (int i = 2; i < src.getRows(); i++) {
|
||||||
String barCode = ExcelUtils.getContent(src, i, 0);
|
String barCode = ExcelUtils.getContent(src, i, 0);
|
||||||
String num = ExcelUtils.getContent(src, i, 2);
|
String num = ExcelUtils.getContent(src, i, 2);
|
||||||
String unitPrice = ExcelUtils.getContent(src, i, 3);
|
String unitPrice = ExcelUtils.getContent(src, i, 3);
|
||||||
String taxRate = ExcelUtils.getContent(src, i, 4);
|
String taxRate = ExcelUtils.getContent(src, i, 4);
|
||||||
String remark = ExcelUtils.getContent(src, i, 5);
|
String remark = ExcelUtils.getContent(src, i, 5);
|
||||||
Map<String, String> materialMap = new HashMap<>();
|
Map<String, String> materialMap = new HashMap<>();
|
||||||
|
materialMap.put("barCode", barCode);
|
||||||
materialMap.put("num", num);
|
materialMap.put("num", num);
|
||||||
materialMap.put("unitPrice", unitPrice);
|
materialMap.put("unitPrice", unitPrice);
|
||||||
materialMap.put("taxRate", taxRate);
|
materialMap.put("taxRate", taxRate);
|
||||||
materialMap.put("remark", remark);
|
materialMap.put("remark", remark);
|
||||||
barCodeNumMap.put(barCode, materialMap);
|
detailList.add(materialMap);
|
||||||
barCodes += barCode + ",";
|
barCodes += "'" + barCode + "',";
|
||||||
}
|
}
|
||||||
if (StringUtil.isNotEmpty(barCodes)) {
|
if (StringUtil.isNotEmpty(barCodes)) {
|
||||||
barCodes = barCodes.substring(0, barCodes.length() - 1);
|
barCodes = barCodes.substring(0, barCodes.length() - 1);
|
||||||
}
|
}
|
||||||
JSONObject map = depotItemService.parseMapByExcelData(barCodes, barCodeNumMap, prefixNo);
|
JSONObject map = depotItemService.parseMapByExcelData(barCodes, detailList, prefixNo);
|
||||||
if (map != null) {
|
if (map != null) {
|
||||||
res.code = 200;
|
res.code = 200;
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -1114,65 +1114,72 @@ public class DepotItemService {
|
|||||||
return depotItemMapperEx.getCountByMaterialAndDepot(mId, depotId);
|
return depotItemMapperEx.getCountByMaterialAndDepot(mId, depotId);
|
||||||
}
|
}
|
||||||
|
|
||||||
public JSONObject parseMapByExcelData(String barCodes, Map<String, Map<String, String>> barCodeNumMap, String prefixNo) {
|
public JSONObject parseMapByExcelData(String barCodes, List<Map<String, String>> detailList, String prefixNo) {
|
||||||
JSONObject map = new JSONObject();
|
JSONObject map = new JSONObject();
|
||||||
try {
|
try {
|
||||||
JSONArray arr = new JSONArray();
|
JSONArray arr = new JSONArray();
|
||||||
List<MaterialVo4Unit> list = depotItemMapperEx.getBillItemByParam(barCodes);
|
List<MaterialVo4Unit> list = depotItemMapperEx.getBillItemByParam(barCodes);
|
||||||
for (MaterialVo4Unit m: list) {
|
Map<String, MaterialVo4Unit> materialMap = new HashMap<>();
|
||||||
|
for (MaterialVo4Unit material: list) {
|
||||||
|
materialMap.put(material.getmBarCode(), material);
|
||||||
|
}
|
||||||
|
for (Map<String, String> detailMap: detailList) {
|
||||||
JSONObject item = new JSONObject();
|
JSONObject item = new JSONObject();
|
||||||
item.put("barCode", m.getmBarCode());
|
String barCode = detailMap.get("barCode");
|
||||||
item.put("name", m.getName());
|
MaterialVo4Unit m = materialMap.get(barCode);
|
||||||
item.put("standard", m.getStandard());
|
if(m!=null) {
|
||||||
if(StringUtil.isNotEmpty(m.getModel())) {
|
item.put("barCode", barCode);
|
||||||
item.put("model", m.getModel());
|
item.put("name", m.getName());
|
||||||
}
|
item.put("standard", m.getStandard());
|
||||||
if(StringUtil.isNotEmpty(m.getColor())) {
|
if(StringUtil.isNotEmpty(m.getModel())) {
|
||||||
item.put("color", m.getColor());
|
item.put("model", m.getModel());
|
||||||
}
|
|
||||||
if(StringUtil.isNotEmpty(m.getSku())) {
|
|
||||||
item.put("sku", m.getSku());
|
|
||||||
}
|
|
||||||
BigDecimal stock = depotItemMapperEx.getCurrentStockByParam(null, m.getId());
|
|
||||||
item.put("stock", stock);
|
|
||||||
item.put("unit", m.getCommodityUnit());
|
|
||||||
Map<String, String> materialMap = barCodeNumMap.get(m.getmBarCode());
|
|
||||||
BigDecimal operNumber = BigDecimal.ZERO;
|
|
||||||
BigDecimal unitPrice = BigDecimal.ZERO;
|
|
||||||
BigDecimal taxRate = BigDecimal.ZERO;
|
|
||||||
if(materialMap.get("num")!=null) {
|
|
||||||
operNumber = new BigDecimal(materialMap.get("num"));
|
|
||||||
}
|
|
||||||
if(StringUtil.isNotEmpty(materialMap.get("unitPrice"))) {
|
|
||||||
unitPrice = new BigDecimal(materialMap.get("unitPrice"));
|
|
||||||
} else {
|
|
||||||
if("CGDD".equals(prefixNo)) {
|
|
||||||
unitPrice = m.getPurchaseDecimal();
|
|
||||||
} else if("XSDD".equals(prefixNo)) {
|
|
||||||
unitPrice = m.getWholesaleDecimal();
|
|
||||||
}
|
}
|
||||||
|
if(StringUtil.isNotEmpty(m.getColor())) {
|
||||||
|
item.put("color", m.getColor());
|
||||||
|
}
|
||||||
|
if(StringUtil.isNotEmpty(m.getSku())) {
|
||||||
|
item.put("sku", m.getSku());
|
||||||
|
}
|
||||||
|
BigDecimal stock = depotItemMapperEx.getCurrentStockByParam(null, m.getId());
|
||||||
|
item.put("stock", stock);
|
||||||
|
item.put("unit", m.getCommodityUnit());
|
||||||
|
BigDecimal operNumber = BigDecimal.ZERO;
|
||||||
|
BigDecimal unitPrice = BigDecimal.ZERO;
|
||||||
|
BigDecimal taxRate = BigDecimal.ZERO;
|
||||||
|
if(StringUtil.isNotEmpty(detailMap.get("num"))) {
|
||||||
|
operNumber = new BigDecimal(detailMap.get("num"));
|
||||||
|
}
|
||||||
|
if(StringUtil.isNotEmpty(detailMap.get("unitPrice"))) {
|
||||||
|
unitPrice = new BigDecimal(detailMap.get("unitPrice"));
|
||||||
|
} else {
|
||||||
|
if("CGDD".equals(prefixNo)) {
|
||||||
|
unitPrice = m.getPurchaseDecimal();
|
||||||
|
} else if("XSDD".equals(prefixNo)) {
|
||||||
|
unitPrice = m.getWholesaleDecimal();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if(StringUtil.isNotEmpty(detailMap.get("taxRate"))) {
|
||||||
|
taxRate = new BigDecimal(detailMap.get("taxRate"));
|
||||||
|
}
|
||||||
|
String remark = detailMap.get("remark");
|
||||||
|
item.put("operNumber", operNumber);
|
||||||
|
item.put("unitPrice", unitPrice);
|
||||||
|
BigDecimal allPrice = BigDecimal.ZERO;
|
||||||
|
if(unitPrice!=null && unitPrice.compareTo(BigDecimal.ZERO)!=0) {
|
||||||
|
allPrice = unitPrice.multiply(operNumber);
|
||||||
|
}
|
||||||
|
BigDecimal taxMoney = BigDecimal.ZERO;
|
||||||
|
if(taxRate.compareTo(BigDecimal.ZERO) != 0) {
|
||||||
|
taxMoney = taxRate.multiply(allPrice).divide(BigDecimal.valueOf(100), 2, BigDecimal.ROUND_HALF_UP);
|
||||||
|
}
|
||||||
|
BigDecimal taxLastMoney = allPrice.add(taxMoney);
|
||||||
|
item.put("allPrice", allPrice);
|
||||||
|
item.put("taxRate", taxRate);
|
||||||
|
item.put("taxMoney", taxMoney);
|
||||||
|
item.put("taxLastMoney", taxLastMoney);
|
||||||
|
item.put("remark", remark);
|
||||||
|
arr.add(item);
|
||||||
}
|
}
|
||||||
if(materialMap.get("taxRate")!=null) {
|
|
||||||
taxRate = new BigDecimal(materialMap.get("taxRate"));
|
|
||||||
}
|
|
||||||
String remark = materialMap.get("remark");
|
|
||||||
item.put("operNumber", operNumber);
|
|
||||||
item.put("unitPrice", unitPrice);
|
|
||||||
BigDecimal allPrice = BigDecimal.ZERO;
|
|
||||||
if(unitPrice!=null && unitPrice.compareTo(BigDecimal.ZERO)!=0) {
|
|
||||||
allPrice = unitPrice.multiply(operNumber);
|
|
||||||
}
|
|
||||||
BigDecimal taxMoney = BigDecimal.ZERO;
|
|
||||||
if(taxRate.compareTo(BigDecimal.ZERO) != 0) {
|
|
||||||
taxMoney = taxRate.multiply(allPrice).divide(BigDecimal.valueOf(100), 2, BigDecimal.ROUND_HALF_UP);
|
|
||||||
}
|
|
||||||
BigDecimal taxLastMoney = allPrice.add(taxMoney);
|
|
||||||
item.put("allPrice", allPrice);
|
|
||||||
item.put("taxRate", taxRate);
|
|
||||||
item.put("taxMoney", taxMoney);
|
|
||||||
item.put("taxLastMoney", taxLastMoney);
|
|
||||||
item.put("remark", remark);
|
|
||||||
arr.add(item);
|
|
||||||
}
|
}
|
||||||
map.put("rows", arr);
|
map.put("rows", arr);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
|
|||||||
@@ -931,7 +931,6 @@
|
|||||||
from jsh_material m
|
from jsh_material m
|
||||||
left join jsh_material_extend me on m.id=me.material_id and ifnull(me.delete_Flag,'0') !='1'
|
left join jsh_material_extend me on m.id=me.material_id and ifnull(me.delete_Flag,'0') !='1'
|
||||||
where 1=1
|
where 1=1
|
||||||
and me.default_flag='1'
|
|
||||||
<if test="barCodes != null">
|
<if test="barCodes != null">
|
||||||
and me.bar_code in (${barCodes})
|
and me.bar_code in (${barCodes})
|
||||||
</if>
|
</if>
|
||||||
|
|||||||
Reference in New Issue
Block a user