继续优化单据的逻辑

This commit is contained in:
季圣华
2020-10-13 23:13:48 +08:00
parent 4428352b35
commit df4fa41b23
7 changed files with 214 additions and 259 deletions

View File

@@ -341,7 +341,7 @@ public class DepotHeadController {
public Object addDepotHeadAndDetail(@RequestBody DepotHeadVo4Body body, HttpServletRequest request) throws Exception{
JSONObject result = ExceptionConstants.standardSuccess();
String beanJson = body.getInfo();
String inserted = body.getInserted();
String rows = body.getRows();
Long billsNumLimit = Long.parseLong(request.getSession().getAttribute("billsNumLimit").toString());
Long tenantId = Long.parseLong(request.getSession().getAttribute("tenantId").toString());
Long count = depotHeadService.countDepotHead(null,null,null,null,null,null,null,null);
@@ -349,7 +349,7 @@ public class DepotHeadController {
throw new BusinessParamCheckingException(ExceptionConstants.DEPOT_HEAD_OVER_LIMIT_FAILED_CODE,
ExceptionConstants.DEPOT_HEAD_OVER_LIMIT_FAILED_MSG);
} else {
depotHeadService.addDepotHeadAndDetail(beanJson,inserted,tenantId, request);
depotHeadService.addDepotHeadAndDetail(beanJson,rows,tenantId, request);
}
return result;
}
@@ -367,9 +367,9 @@ public class DepotHeadController {
JSONObject result = ExceptionConstants.standardSuccess();
Long id = body.getId();
String beanJson = body.getInfo();
String inserted = body.getInserted();
String rows = body.getRows();
BigDecimal preTotalPrice = body.getPreTotalPrice();
depotHeadService.updateDepotHeadAndDetail(id,beanJson,inserted,preTotalPrice,tenantId,request);
depotHeadService.updateDepotHeadAndDetail(id,beanJson,rows,preTotalPrice,tenantId,request);
return result;
}

View File

@@ -8,11 +8,7 @@ public class DepotHeadVo4Body {
private String info;
private String inserted;
private String deleted;
private String updated;
private String rows;
private BigDecimal preTotalPrice;
@@ -32,28 +28,12 @@ public class DepotHeadVo4Body {
this.info = info;
}
public String getInserted() {
return inserted;
public String getRows() {
return rows;
}
public void setInserted(String inserted) {
this.inserted = inserted;
}
public String getDeleted() {
return deleted;
}
public void setDeleted(String deleted) {
this.deleted = deleted;
}
public String getUpdated() {
return updated;
}
public void setUpdated(String updated) {
this.updated = updated;
public void setRows(String rows) {
this.rows = rows;
}
public BigDecimal getPreTotalPrice() {

View File

@@ -52,7 +52,7 @@ public interface SerialNumberMapperEx {
* */
int sellSerialNumber(@Param("materialId")Long materialId, @Param("depotHeadId")Long depotHeadId,@Param("count")Integer count, @Param("updateTime") Date updateTime,@Param("updater") Long updater);
/**
* 赎回update jsh_serial_number set is_Sell='0' where 1=1 and material_Id='materialId'
* 赎回update jsh_serial_number set is_Sell='0',depothead_Id=null where 1=1 and material_Id='materialId'
* and depothead_Id='depotheadId' and is_Sell ='0' and delete_Flag !='1' {limit 0count}
* */
int cancelSerialNumber(@Param("materialId")Long materialId, @Param("depotHeadId")Long depotHeadId, @Param("count")Integer count, @Param("updateTime") Date updateTime,@Param("updater") Long updater);

View File

@@ -469,13 +469,13 @@ public class DepotHeadService {
/**
* 新增单据主表及单据子表信息
* @param beanJson
* @param inserted
* @param rows
* @param tenantId
* @param request
* @throws Exception
*/
@Transactional(value = "transactionManager", rollbackFor = Exception.class)
public void addDepotHeadAndDetail(String beanJson, String inserted, Long tenantId,
public void addDepotHeadAndDetail(String beanJson, String rows, Long tenantId,
HttpServletRequest request) throws Exception {
/**处理单据主表数据*/
DepotHead depotHead = JSONObject.parseObject(beanJson, DepotHead.class);
@@ -502,7 +502,7 @@ public class DepotHeadService {
if(list!=null) {
Long headId = list.get(0).getId();
/**入库和出库处理单据子表信息*/
depotItemService.saveDetials(inserted,headId,tenantId, request);
depotItemService.saveDetials(rows,headId,tenantId, request);
}
/**如果关联单据号非空则更新订单的状态为2 */
if(depotHead.getLinkNumber()!=null) {
@@ -525,14 +525,14 @@ public class DepotHeadService {
* 更新单据主表及单据子表信息
* @param id
* @param beanJson
* @param inserted
* @param rows
* @param preTotalPrice
* @param tenantId
* @param request
* @throws Exception
*/
@Transactional(value = "transactionManager", rollbackFor = Exception.class)
public void updateDepotHeadAndDetail(Long id, String beanJson, String inserted,
public void updateDepotHeadAndDetail(Long id, String beanJson, String rows,
BigDecimal preTotalPrice, Long tenantId,HttpServletRequest request)throws Exception {
/**更新单据主表信息*/
DepotHead depotHead = JSONObject.parseObject(beanJson, DepotHead.class);
@@ -550,7 +550,7 @@ public class DepotHeadService {
}
}
/**入库和出库处理单据子表信息*/
depotItemService.saveDetials(inserted,depotHead.getId(),tenantId,request);
depotItemService.saveDetials(rows,depotHead.getId(),tenantId,request);
logService.insertLog("单据",
new StringBuffer(BusinessConstants.LOG_OPERATION_TYPE_EDIT).append(depotHead.getNumber()).toString(),
((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest());

View File

@@ -296,74 +296,46 @@ public class DepotItemService {
}
@Transactional(value = "transactionManager", rollbackFor = Exception.class)
public String saveDetials(String inserted, Long headerId, Long tenantId, HttpServletRequest request) throws Exception{
public void saveDetials(String rows, Long headerId, Long tenantId, HttpServletRequest request) throws Exception{
//查询单据主表信息
DepotHead depotHead=null;
try{
depotHead =depotHeadMapper.selectByPrimaryKey(headerId);
}catch(Exception e){
JshException.readFail(logger, e);
}
//获得当前操作人
User userInfo=userService.getCurrentUser();
//转为json
JSONArray insertedJson = JSONArray.parseArray(inserted);
//获得当前操作人
User userInfo=userService.getCurrentUser();
//首先回收序列号,如果是调拨,不用处理序列号
if(BusinessConstants.DEPOTHEAD_TYPE_OUT.equals(depotHead.getType())
&&!BusinessConstants.SUB_TYPE_TRANSFER.equals(depotHead.getSubType())){
List<DepotItem> depotItemList = getListByHeaderId(headerId);
for(DepotItem depotItem : depotItemList){
Material material= materialService.getMaterial(depotItem.getMaterialId());
if(material==null){
continue;
}
if(BusinessConstants.ENABLE_SERIAL_NUMBER_ENABLED.equals(material.getEnableSerialNumber())){
serialNumberService.cancelSerialNumber(depotItem.getMaterialId(),depotItem.getHeaderId(),
(depotItem.getBasicNumber()==null?0:depotItem.getBasicNumber()).intValue(), userInfo);
}
}
}
//删除单据的明细
deleteDepotItemHeadId(headerId);
// if (null != deletedJson) {
// StringBuffer bf=new StringBuffer();
// for (int i = 0; i < deletedJson.size(); i++) {
// //首先回收序列号,如果是调拨,不用处理序列号
// JSONObject tempDeletedJson = JSONObject.parseObject(deletedJson.getString(i));
// if(BusinessConstants.DEPOTHEAD_TYPE_OUT.equals(depotHead.getType())
// &&!BusinessConstants.SUB_TYPE_TRANSFER.equals(depotHead.getSubType())){
// DepotItem depotItem = getDepotItem(tempDeletedJson.getLong("Id"));
// if(depotItem==null){
// continue;
// }
// /**
// * 判断商品是否开启序列号,开启的收回序列号,未开启的跳过
// * */
// Material material= materialService.getMaterial(depotItem.getMaterialId());
// if(material==null){
// continue;
// }
// if(BusinessConstants.ENABLE_SERIAL_NUMBER_ENABLED.equals(material.getEnableSerialNumber())){
// serialNumberService.cancelSerialNumber(depotItem.getMaterialId(),depotItem.getHeaderId(),(depotItem.getBasicNumber()==null?0:depotItem.getBasicNumber()).intValue(),
// userInfo);
// }
// }
// bf.append(tempDeletedJson.getLong("Id"));
// if(i<(deletedJson.size()-1)){
// bf.append(",");
// }
// }
// this.batchDeleteDepotItemByIds(bf.toString());
// //更新当前库存
// for (int i = 0; i < deletedJson.size(); i++) {
// JSONObject tempDeletedJson = JSONObject.parseObject(deletedJson.getString(i));
// DepotItem depotItem = getDepotItem(tempDeletedJson.getLong("Id"));
// updateCurrentStock(depotItem,tenantId);
// }
// }
if (null != insertedJson) {
for (int i = 0; i < insertedJson.size(); i++) {
JSONArray rowArr = JSONArray.parseArray(rows);
if (null != rowArr) {
for (int i = 0; i < rowArr.size(); i++) {
DepotItem depotItem = new DepotItem();
JSONObject tempInsertedJson = JSONObject.parseObject(insertedJson.getString(i));
JSONObject rowObj = JSONObject.parseObject(rowArr.getString(i));
depotItem.setHeaderId(headerId);
Long materialExtendId = tempInsertedJson.getLong("MaterialExtendId");
Long materialExtendId = rowObj.getLong("MaterialExtendId");
Long materialId = materialExtendService.getMaterialExtend(materialExtendId).getMaterialId();
depotItem.setMaterialId(materialId);
depotItem.setMaterialExtendId(tempInsertedJson.getLong("MaterialExtendId"));
depotItem.setMaterialUnit(tempInsertedJson.getString("Unit"));
if (StringUtil.isExist(tempInsertedJson.get("OperNumber"))) {
depotItem.setOperNumber(tempInsertedJson.getBigDecimal("OperNumber"));
depotItem.setMaterialExtendId(rowObj.getLong("MaterialExtendId"));
depotItem.setMaterialUnit(rowObj.getString("Unit"));
if (StringUtil.isExist(rowObj.get("OperNumber"))) {
depotItem.setOperNumber(rowObj.getBigDecimal("OperNumber"));
try {
String Unit = tempInsertedJson.get("Unit").toString();
BigDecimal oNumber = tempInsertedJson.getBigDecimal("OperNumber");
String Unit = rowObj.get("Unit").toString();
BigDecimal oNumber = rowObj.getBigDecimal("OperNumber");
//以下进行单位换算
String unitName = materialService.findUnitName(materialId); //查询计量单位名称
if (!StringUtil.isEmpty(unitName)) {
@@ -384,36 +356,36 @@ public class DepotItemService {
logger.error(">>>>>>>>>>>>>>>>>>>设置基础数量异常", e);
}
}
if (StringUtil.isExist(tempInsertedJson.get("UnitPrice"))) {
depotItem.setUnitPrice(tempInsertedJson.getBigDecimal("UnitPrice"));
if (StringUtil.isExist(rowObj.get("UnitPrice"))) {
depotItem.setUnitPrice(rowObj.getBigDecimal("UnitPrice"));
}
if (StringUtil.isExist(tempInsertedJson.get("TaxUnitPrice"))) {
depotItem.setTaxUnitPrice(tempInsertedJson.getBigDecimal("TaxUnitPrice"));
if (StringUtil.isExist(rowObj.get("TaxUnitPrice"))) {
depotItem.setTaxUnitPrice(rowObj.getBigDecimal("TaxUnitPrice"));
}
if (StringUtil.isExist(tempInsertedJson.get("AllPrice"))) {
depotItem.setAllPrice(tempInsertedJson.getBigDecimal("AllPrice"));
if (StringUtil.isExist(rowObj.get("AllPrice"))) {
depotItem.setAllPrice(rowObj.getBigDecimal("AllPrice"));
}
depotItem.setRemark(tempInsertedJson.getString("Remark"));
if (tempInsertedJson.get("DepotId") != null && !StringUtil.isEmpty(tempInsertedJson.get("DepotId").toString())) {
depotItem.setDepotId(tempInsertedJson.getLong("DepotId"));
depotItem.setRemark(rowObj.getString("Remark"));
if (rowObj.get("DepotId") != null && !StringUtil.isEmpty(rowObj.get("DepotId").toString())) {
depotItem.setDepotId(rowObj.getLong("DepotId"));
}
if (tempInsertedJson.get("AnotherDepotId") != null && !StringUtil.isEmpty(tempInsertedJson.get("AnotherDepotId").toString())) {
depotItem.setAnotherDepotId(tempInsertedJson.getLong("AnotherDepotId"));
if (rowObj.get("AnotherDepotId") != null && !StringUtil.isEmpty(rowObj.get("AnotherDepotId").toString())) {
depotItem.setAnotherDepotId(rowObj.getLong("AnotherDepotId"));
}
if (StringUtil.isExist(tempInsertedJson.get("TaxRate"))) {
depotItem.setTaxRate(tempInsertedJson.getBigDecimal("TaxRate"));
if (StringUtil.isExist(rowObj.get("TaxRate"))) {
depotItem.setTaxRate(rowObj.getBigDecimal("TaxRate"));
}
if (StringUtil.isExist(tempInsertedJson.get("TaxMoney"))) {
depotItem.setTaxMoney(tempInsertedJson.getBigDecimal("TaxMoney"));
if (StringUtil.isExist(rowObj.get("TaxMoney"))) {
depotItem.setTaxMoney(rowObj.getBigDecimal("TaxMoney"));
}
if (StringUtil.isExist(tempInsertedJson.get("TaxLastMoney"))) {
depotItem.setTaxLastMoney(tempInsertedJson.getBigDecimal("TaxLastMoney"));
if (StringUtil.isExist(rowObj.get("TaxLastMoney"))) {
depotItem.setTaxLastMoney(rowObj.getBigDecimal("TaxLastMoney"));
}
if (tempInsertedJson.get("MType") != null) {
depotItem.setMaterialType(tempInsertedJson.getString("MType"));
if (rowObj.get("MType") != null) {
depotItem.setMaterialType(rowObj.getString("MType"));
}
if (tempInsertedJson.get("Remark") != null) {
depotItem.setRemark(tempInsertedJson.getString("Remark"));
if (rowObj.get("Remark") != null) {
depotItem.setRemark(rowObj.getString("Remark"));
}
//出库时判断库存是否充足
if(BusinessConstants.DEPOTHEAD_TYPE_OUT.equals(depotHead.getType())){
@@ -444,7 +416,9 @@ public class DepotItemService {
updateCurrentStock(depotItem,tenantId);
}
}
return null;
}catch(Exception e){
JshException.writeFail(logger, e);
}
}
/**
* 查询计量单位信息

View File

@@ -180,7 +180,7 @@
<update id="cancelSerialNumber">
update jsh_serial_number
<set>
is_sell = '0',
is_sell = '0', depot_head_id=null,
<if test="updateTime !=null ">
update_time = #{updateTime},
</if>