Commit 4fb5e13c by 李小惠

修改bug

parent 9eefdeef
......@@ -56,6 +56,7 @@ public class TestController {
@PostMapping("/selectByItem")
public ApiRes<List<InventorySummary>> selectByItem(@RequestBody A a){
return ApiRes.success(inventorySummaryService.selectByItems(a.getA()));
}
}
......@@ -34,13 +34,6 @@ public interface InventorySummaryMapper extends BaseMapper<InventorySummary> {
List<InventorySummary> selectByEqs(@Param("orgId") Long orgId);
// @Select({
// "<script>",
// "<foreach collection='list' item='item' open='(' separator=',' close=')'>",
// "select * from base_inventory_summary",
// "where org_id_int=#{item[0]} and location_id=#{item[1]} and size_id=#{item[2]} and type_id=#{item[3]} and unit_price=#{item[4]}}}",
// "</foreach>",
// "</script>"
// })
List<InventorySummary> selectByItems(@Param("list") List<Object[]> list);
List<InventorySummary> selectByItems(@Param("list") List<Object[]> searchCriteria);
}
\ No newline at end of file
......@@ -515,6 +515,7 @@ public class InventorySummaryServiceImpl extends ServiceImpl<InventorySummaryMa
@Override
public List<InventorySummary> selectByItems(List<Object[]> searchCriteria) {
return inventorySummaryMapper.selectByItems(searchCriteria);
}
......
......@@ -21,6 +21,7 @@ import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import javax.annotation.Resource;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
......@@ -86,6 +87,7 @@ public class LogSummaryServiceImpl extends ServiceImpl<LogSummaryMapper, LogSumm
@Transactional(rollbackFor = Exception.class)
public Boolean processInventoryRecords(OutInLogsReq req) {
//1.判断业务类型,如果是采购,更新装备库存表
boolean a=false;
if (req.getBussinessType().equals("purchase")){
List<PurchaseEqsReq> purchaseList = req.getOrderMain().getPurchaseList();
List<Inventory> collect = purchaseList.stream().map(purchaseEqsReq -> {
......@@ -93,9 +95,11 @@ public class LogSummaryServiceImpl extends ServiceImpl<LogSummaryMapper, LogSumm
BeanPlusUtil.copyProperties(purchaseEqsReq, inventory);
return inventory;
}).collect(Collectors.toList());
inventoryService.saveBatch(collect);
a=inventoryService.saveBatch(collect);
}
//2.如果有单据,更新单据
boolean b=false;
boolean c=false;
if (ObjectUtil.isNotNull(req.getOrderMain())){
OrderReq orderMain = req.getOrderMain();
List<DetailOrderReq> orderDetailList = orderMain.getOrderDetail();
......@@ -104,28 +108,30 @@ public class LogSummaryServiceImpl extends ServiceImpl<LogSummaryMapper, LogSumm
one.setPrice(orderMain.getPrice());
one.setActualQuantity(orderMain.getActualQuantity());
one.setOrderState(one.getOrderState());
orderMainService.updateById(one);
b=orderMainService.updateById(one);
List<OrderDetail> collect = orderDetailList.stream().map(detailOrderReq -> {
OrderDetail orderDetail = new OrderDetail();
BeanPlusUtil.copyProperties(detailOrderReq, orderDetail);
return orderDetail;
}).collect(Collectors.toList());
orderDetailService.updateBatchById(collect);
c=orderDetailService.updateBatchById(collect);
}
//3.对出入库记录进行存储
List<NormalInOutDto> inventorySumDtos = saveInOutRecords(req);
//4.如果没有单据,当作日常出入库,需要对库存汇总表进行更新
if (req.getBussinessType().equals("normal")){
//4.如果没有单据当作日常出入库或者采购时,需要对库存汇总表进行更新
boolean d=false;
if (req.getBussinessType().equals("normal")|| req.getBussinessType().equals("purchase")){
//获取到组织机构和仓库,将出入库的装备进行分组统计,并且对inventorysummary进行更新操作
updateNumToSum(inventorySumDtos,req.getOutInState());
d = updateNumToSum(req.getOutInState(), inventorySumDtos, req.getOutInState());
}
return false;
return (a && b && c && d);
}
//对库存汇总表进行更新(只限于日常出入库)
private void updateNumToSum(List<NormalInOutDto> inventorySumDtos,String OutInState) {
@Transactional(rollbackFor = Exception.class)
public boolean updateNumToSum(String outInState,List<NormalInOutDto> inventorySumDtos,String OutInState) {
List<NormalInOutDto> groupedResult = inventorySumDtos.stream()
.collect(Collectors.groupingBy(dto -> dto.getOrgId() + "_" + dto.getLocationId() + "_" +
......@@ -142,15 +148,70 @@ public class LogSummaryServiceImpl extends ServiceImpl<LogSummaryMapper, LogSumm
})))
.values().stream()
.collect(Collectors.toList());
//将查询条件存入searchCriteria中一次性查询出满足条件的数据
List<Object[]> searchCriteria = new ArrayList<>();
for (NormalInOutDto groupedDto : groupedResult) {
Object[] criteria = new Object[]{groupedDto.getOrgId(), groupedDto.getLocationId(),
groupedDto.getSizeId(), groupedDto.getTypeId(), groupedDto.getPrice()};
searchCriteria.add(criteria);
}
inventorySummaryMapper.selectByItems(searchCriteria);
//满足条件的数据
List<InventorySummary> inventorySummaryList = inventorySummaryMapper.selectByItems(searchCriteria);
List<InventorySummary> addList=new ArrayList<>();
List<InventorySummary> updateList=new ArrayList<>();
//遍历两者,判断数据库中是否全部存在,如果不存在,则进行增加数据操作,如果存在,则更新数据即可
for (NormalInOutDto outDto:groupedResult) {
boolean flag=false;
for (InventorySummary is:inventorySummaryList) {
if (outDto.getOrgId()==is.getOrgId() && outDto.getLocationId().equals(is.getLocationId())
&& outDto.getSizeId().equals(is.getSizeId()) && outDto.getTypeId().equals(is.getTypeId())
&& outDto.getPrice().compareTo(is.getUnitPrice())==0){
if (outInState.equals("in")){
is.setOutboundNumber(is.getOutboundNumber()-outDto.getNumber());
is.setStockNumber(is.getStockNumber()+outDto.getNumber());
is.setPrice(is.getPrice().add(BigDecimal.valueOf(outDto.getNumber()).multiply(outDto.getPrice())) );
}else {
is.setOutboundNumber(is.getOutboundNumber()+outDto.getNumber());
is.setStockNumber(is.getStockNumber()-outDto.getNumber());
is.setPrice(is.getPrice().subtract(BigDecimal.valueOf(outDto.getNumber()).multiply(outDto.getPrice())) );
}
updateList.add(is);
flag=true;
break;
}
}
if (!flag){
InventorySummary inventorySummary = new InventorySummary();
BeanPlusUtil.copyProperties(outDto,inventorySummary);
inventorySummary.setPrice(BigDecimal.valueOf(outDto.getNumber()).multiply(outDto.getPrice()));
inventorySummary.setUnitPrice(outDto.getPrice());
inventorySummary.setBrokenNumber(0);
inventorySummary.setExpireNumber(0);
inventorySummary.setDestructionNumber(0);
inventorySummary.setNearBrokenNumber(0);
inventorySummary.setCreateTime(DateTimeUtil.getCurrentDateTime());
if (outInState.equals("in")){
inventorySummary.setOutboundNumber(0);
inventorySummary.setUseNumber(0);
inventorySummary.setStockNumber(outDto.getNumber());
}else {
inventorySummary.setOutboundNumber(0);
inventorySummary.setUseNumber(outDto.getNumber());
inventorySummary.setStockNumber(outDto.getNumber());
}
addList.add(inventorySummary);
}
}
boolean a=true;
if (addList.size()>0){
boolean b = inventorySummaryService.saveBatch(addList);
a = b;
}
if (updateList.size()>0){
boolean b = inventorySummaryService.updateBatchById(updateList);
a = a && b;
}
return a;
}
//对出入库记录进行存储
......
......@@ -264,11 +264,11 @@
HAVING stockNumber>0
</select>
<select id="selectByItems" resultType="com.junmp.jyzb.entity.InventorySummary">
<foreach collection="list" item="item" open="(" separator="," close=")">
select * from base_inventory_summary where
org_id_int = #{item[0]} AND location_id = #{item[1]}
AND size_id = #{item[2]} AND type_id = #{item[3]}
AND unit_price = #{item[4]}
<foreach collection="list" item="item" separator="or">
(
org_id_int = ${item[0]} AND location_id = '${item[1]}' AND size_id = '${item[2]}' AND type_id = ${item[3]} AND unit_price = ${item[4]}
)
</foreach>
</select>
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论