|
@@ -1,7 +1,9 @@
|
|
|
package com.zhaoliangsz.grainsearch.service.impl;
|
|
|
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
+import com.zhaoliangsz.grainsearch.domain.entity.InventoryTable;
|
|
|
import com.zhaoliangsz.grainsearch.domain.entity.TestTable;
|
|
|
+import com.zhaoliangsz.grainsearch.mapper.InventoryTableMapper;
|
|
|
import com.zhaoliangsz.grainsearch.mapper.TestTableMapper;
|
|
|
import com.zhaoliangsz.grainsearch.service.ITestTableService;
|
|
|
import com.baomidou.mybatisplus.extension.service.IService;
|
|
@@ -14,6 +16,7 @@ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
|
|
|
import java.sql.Wrapper;
|
|
|
+import java.time.LocalDate;
|
|
|
import java.util.*;
|
|
|
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
@@ -31,6 +34,8 @@ import com.zhaoliangsz.grainsearch.basic.exception.ExceptionDefinition;
|
|
|
public class TestTableServiceImpl extends ServiceImpl<TestTableMapper, TestTable> implements ITestTableService {
|
|
|
@Autowired
|
|
|
private TestTableMapper testTableMapper;
|
|
|
+ @Autowired
|
|
|
+ private InventoryTableMapper inventoryTableMapper;
|
|
|
@Override
|
|
|
public PageResult<TestTable> queryTestTableList(TestTable queryTestTable) throws ServiceException{
|
|
|
try{
|
|
@@ -52,20 +57,100 @@ public class TestTableServiceImpl extends ServiceImpl<TestTableMapper, TestTable
|
|
|
@Override
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
public String addTestTable(TestTable addTestTable) throws ServiceException {
|
|
|
+ //查询相同条件是否已添加过
|
|
|
TestTable testTable=testTableMapper.selectOne(new QueryWrapper<TestTable>()
|
|
|
.eq("type",addTestTable.getType())
|
|
|
.eq("banci",addTestTable.getBanci())
|
|
|
.eq("banzu",addTestTable.getBanzu())
|
|
|
.eq("date",addTestTable.getDate()));
|
|
|
boolean flag;
|
|
|
+ InventoryTable inventoryTable=inventoryTableMapper.selectOne(new QueryWrapper<InventoryTable>()
|
|
|
+ .eq("date",addTestTable.getDate()));
|
|
|
+ //编辑
|
|
|
if (testTable!=null){
|
|
|
addTestTable.setUpdateTime(new Date());
|
|
|
addTestTable.setId(testTable.getId());
|
|
|
+ LocalDate today = addTestTable.getDate();
|
|
|
+ //入库
|
|
|
+ if ("入库".equals(addTestTable.getType())){
|
|
|
+ inventoryTable.setInNum(addTestTable.getInNum());
|
|
|
+ //库存=当天库存减原入库加新入库
|
|
|
+ inventoryTable.setInventory(inventoryTable.getInventory()-testTable.getInNum()+addTestTable.getInNum());
|
|
|
+ }
|
|
|
+ //出库
|
|
|
+ else{
|
|
|
+ //出库量先减原出库量再进行累加
|
|
|
+ inventoryTable.setOutNum(inventoryTable.getOutNum()-testTable.getTotal()+addTestTable.getTotal());
|
|
|
+ //库存=当天库存加原出库减新出库
|
|
|
+ inventoryTable.setInventory(inventoryTable.getInventory()+testTable.getTotal()-addTestTable.getTotal());
|
|
|
+ }
|
|
|
+ inventoryTable.setUpdateTime(new Date());
|
|
|
+ inventoryTableMapper.updateById(inventoryTable);
|
|
|
flag= this.updateById(addTestTable);
|
|
|
}
|
|
|
+ //新增
|
|
|
else {
|
|
|
addTestTable.setCreateTime(new Date());
|
|
|
addTestTable.setUpdateTime(new Date());
|
|
|
+ //获取本条数据日期
|
|
|
+ LocalDate today = addTestTable.getDate();
|
|
|
+ //获取前一天日期 查询前一天库存
|
|
|
+ LocalDate yesterday = today.minusDays(1);
|
|
|
+ InventoryTable inventoryTable1=inventoryTableMapper.selectOne(new QueryWrapper<InventoryTable>()
|
|
|
+ .eq("date",yesterday));
|
|
|
+ //入库
|
|
|
+ if ("入库".equals(addTestTable.getType())){
|
|
|
+ if (inventoryTable!=null){
|
|
|
+ inventoryTable.setInNum(addTestTable.getInNum());
|
|
|
+ //库存=当天库存加入库
|
|
|
+ inventoryTable.setInventory(inventoryTable.getInventory()+addTestTable.getInNum());
|
|
|
+ inventoryTable.setUpdateTime(new Date());
|
|
|
+ inventoryTableMapper.updateById(inventoryTable);
|
|
|
+ }
|
|
|
+ else{
|
|
|
+ InventoryTable inventoryTable2=new InventoryTable();
|
|
|
+ inventoryTable2.setCreateTime(new Date());
|
|
|
+ inventoryTable2.setUpdateTime(new Date());
|
|
|
+ inventoryTable2.setDate(addTestTable.getDate());
|
|
|
+ inventoryTable2.setInNum(addTestTable.getInNum());
|
|
|
+ //库存=前一天库存加入库
|
|
|
+ if (inventoryTable1!=null){
|
|
|
+ inventoryTable2.setInventory(inventoryTable1.getInventory()+addTestTable.getInNum());
|
|
|
+ }
|
|
|
+ else{
|
|
|
+ throw new ServiceException(ExceptionDefinition.NOT_YESTERDAY_INVENTORY);
|
|
|
+
|
|
|
+ }
|
|
|
+ inventoryTableMapper.insert(inventoryTable2);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //出库
|
|
|
+ else{
|
|
|
+ if (inventoryTable!=null){
|
|
|
+ //出库量累加
|
|
|
+ inventoryTable.setOutNum(inventoryTable.getOutNum()+addTestTable.getTotal());
|
|
|
+ //库存=当天库存减出库
|
|
|
+ inventoryTable.setInventory(inventoryTable.getInventory()-addTestTable.getTotal());
|
|
|
+ inventoryTable.setUpdateTime(new Date());
|
|
|
+ inventoryTableMapper.updateById(inventoryTable);
|
|
|
+ }
|
|
|
+ else{
|
|
|
+ InventoryTable inventoryTable2=new InventoryTable();
|
|
|
+ inventoryTable2.setCreateTime(new Date());
|
|
|
+ inventoryTable2.setUpdateTime(new Date());
|
|
|
+ inventoryTable2.setDate(addTestTable.getDate());
|
|
|
+ inventoryTable2.setOutNum(addTestTable.getTotal());
|
|
|
+ //库存=前一天库存减出库
|
|
|
+ if (inventoryTable1!=null){
|
|
|
+ inventoryTable2.setInventory(inventoryTable1.getInventory()-addTestTable.getTotal());
|
|
|
+ }
|
|
|
+ else{
|
|
|
+ throw new ServiceException(ExceptionDefinition.NOT_YESTERDAY_INVENTORY);
|
|
|
+
|
|
|
+ }
|
|
|
+ inventoryTableMapper.insert(inventoryTable2);
|
|
|
+ }
|
|
|
+ }
|
|
|
flag= this.save(addTestTable);
|
|
|
}
|
|
|
|