1.初步完成出入库汇总逻辑

master
x_z 2 years ago
parent c1cfccbf87
commit 2f48a29839

@ -4,6 +4,7 @@ import com.glxp.api.dao.BaseMapperPlus;
import com.glxp.api.entity.inout.IoOrderDetailResultEntity; import com.glxp.api.entity.inout.IoOrderDetailResultEntity;
import com.glxp.api.req.inout.FilterOrderDetailResultRequest; import com.glxp.api.req.inout.FilterOrderDetailResultRequest;
import com.glxp.api.res.inout.IoOrderDetailResultResponse; import com.glxp.api.res.inout.IoOrderDetailResultResponse;
import org.apache.ibatis.annotations.Param;
import java.util.List; import java.util.List;
@ -25,5 +26,12 @@ public interface IoOrderDetailResultDao extends BaseMapperPlus<IoOrderDetailBizD
*/ */
List<IoOrderDetailResultResponse> filterOrderList(FilterOrderDetailResultRequest orderDetailResultRequest); List<IoOrderDetailResultResponse> filterOrderList(FilterOrderDetailResultRequest orderDetailResultRequest);
/**
*
*
* @param beginOfDay
* @param endOfDay
* @return
*/
List<IoOrderDetailResultEntity> selectStatDataByTime(@Param("date") String date);
} }

@ -26,4 +26,8 @@ public class FilterStatDataDetailRequest extends ListPageRequest {
*/ */
private String recordKey; private String recordKey;
/**
*
*/
private String ggxh;
} }

@ -24,11 +24,11 @@ public class FilterStatDataRequest extends ListPageRequest {
/** /**
* *
*/ */
private String startDate; private String startTime;
/** /**
* *
*/ */
private String endDate; private String endTime;
} }

@ -56,9 +56,7 @@ public class IoStatDayServiceImpl implements IoStatDayService {
public void statData(Date date) { public void statData(Date date) {
//汇总前一天的数据 //汇总前一天的数据
DateTime yesterday = DateUtil.offsetDay(date, -1); DateTime yesterday = DateUtil.offsetDay(date, -1);
List<IoOrderDetailResultEntity> orderDetailResultEntities = ioOrderDetailResultDao.selectList(new QueryWrapper<IoOrderDetailResultEntity>() List<IoOrderDetailResultEntity> orderDetailResultEntities = ioOrderDetailResultDao.selectStatDataByTime(yesterday.toString("yyyy-MM-dd"));
.select("orderIdFk", "bindRlFk", "nameCode", "batchNo", "productDate", "expireDate", "coName", "spec", "price", "count", "reCount")
.between("createTime", DateUtil.beginOfDay(yesterday), DateUtil.endOfDay(yesterday)));
if (CollUtil.isNotEmpty(orderDetailResultEntities)) { if (CollUtil.isNotEmpty(orderDetailResultEntities)) {
//声明用于存放汇总数据的集合 //声明用于存放汇总数据的集合
List<IoStatDayEntity> dataList = new ArrayList<>(); List<IoStatDayEntity> dataList = new ArrayList<>();
@ -71,43 +69,17 @@ public class IoStatDayServiceImpl implements IoStatDayService {
if (order.getMainAction().equals(ConstantType.TYPE_PUT)) { if (order.getMainAction().equals(ConstantType.TYPE_PUT)) {
//入库 //入库
statData.setInCount(orderDetailResultEntity.getReCount() + statData.getInCount()); statData.setInCount(orderDetailResultEntity.getReCount() + statData.getInCount());
statData.setInPrice(orderDetailResultEntity.getPrice()); if (null != orderDetailResultEntity.getPrice()) {
BigDecimal inAmount = orderDetailResultEntity.getPrice().multiply(BigDecimal.valueOf(orderDetailResultEntity.getReCount())); BigDecimal inAmount = orderDetailResultEntity.getPrice().multiply(BigDecimal.valueOf(orderDetailResultEntity.getReCount()));
statData.setInAmount(inAmount.add(statData.getInAmount())); statData.setInAmount(inAmount.add(statData.getInAmount()));
//计算结余金额
long balanceCount;
BigDecimal balanceAmount;
if (statData.getBalanceCount() == 0) {
balanceCount = statData.getBeginCount() + statData.getInCount();
balanceAmount = orderDetailResultEntity.getPrice().multiply(BigDecimal.valueOf(balanceCount));
} else {
balanceCount = statData.getBalanceCount() + orderDetailResultEntity.getReCount();
balanceAmount = statData.getBalanceAmount().add(statData.getInAmount());
} }
statData.setBalanceCount(Long.valueOf(balanceCount).intValue());
statData.setBalanceAmount(balanceAmount);
} else if (order.getMainAction().equals(ConstantType.TYPE_OUT)) { } else if (order.getMainAction().equals(ConstantType.TYPE_OUT)) {
//出库 //出库
statData.setOutCount(orderDetailResultEntity.getReCount() + statData.getOutCount()); statData.setOutCount(orderDetailResultEntity.getReCount() + statData.getOutCount());
statData.setOutPrice(orderDetailResultEntity.getPrice()); if (null != orderDetailResultEntity.getPrice()) {
BigDecimal outAmount = statData.getBeginAmount().add(orderDetailResultEntity.getPrice().multiply(BigDecimal.valueOf(orderDetailResultEntity.getReCount()))); BigDecimal outAmount = orderDetailResultEntity.getPrice().multiply(BigDecimal.valueOf(orderDetailResultEntity.getReCount()));
statData.setOutAmount(outAmount.add(statData.getOutAmount())); statData.setOutAmount(outAmount.add(statData.getOutAmount()));
//计算结余金额
long balanceCount;
BigDecimal balanceAmount;
if (statData.getBalanceCount() == 0) {
balanceCount = Long.valueOf(statData.getBeginCount()) - orderDetailResultEntity.getReCount();
balanceAmount = orderDetailResultEntity.getPrice().multiply(BigDecimal.valueOf(balanceCount));
} else {
balanceCount = statData.getBalanceCount() + orderDetailResultEntity.getReCount();
balanceAmount = statData.getBalanceAmount().subtract(statData.getOutAmount());
} }
statData.setBalanceCount(Long.valueOf(balanceCount).intValue());
statData.setBalanceAmount(balanceAmount);
} }
}); });
@ -137,7 +109,7 @@ public class IoStatDayServiceImpl implements IoStatDayService {
private IoStatDayEntity getStatData(List<IoStatDayEntity> dataList, IoOrderDetailResultEntity orderDetailResultEntity, DateTime yesterday) { private IoStatDayEntity getStatData(List<IoStatDayEntity> dataList, IoOrderDetailResultEntity orderDetailResultEntity, DateTime yesterday) {
if (CollUtil.isNotEmpty(dataList)) { if (CollUtil.isNotEmpty(dataList)) {
for (IoStatDayEntity statDayEntity : dataList) { for (IoStatDayEntity statDayEntity : dataList) {
if (statDayEntity.getRelIdFk().equals(orderDetailResultEntity.getBindRlFk())) { if (Long.valueOf(statDayEntity.getRelIdFk()).equals(orderDetailResultEntity.getBindRlFk())) {
if ((StrUtil.isNotBlank(statDayEntity.getBatchNo()) && StrUtil.isNotBlank(orderDetailResultEntity.getBatchNo())) && statDayEntity.getBatchNo().equals(orderDetailResultEntity.getBatchNo())) { if ((StrUtil.isNotBlank(statDayEntity.getBatchNo()) && StrUtil.isNotBlank(orderDetailResultEntity.getBatchNo())) && statDayEntity.getBatchNo().equals(orderDetailResultEntity.getBatchNo())) {
return statDayEntity; return statDayEntity;
} else if (StrUtil.isBlank(statDayEntity.getBatchNo()) && StrUtil.isBlank(orderDetailResultEntity.getBatchNo())) { } else if (StrUtil.isBlank(statDayEntity.getBatchNo()) && StrUtil.isBlank(orderDetailResultEntity.getBatchNo())) {
@ -161,11 +133,11 @@ public class IoStatDayServiceImpl implements IoStatDayService {
statData.setBalancePrice(orderDetailResultEntity.getPrice()); statData.setBalancePrice(orderDetailResultEntity.getPrice());
//设置初始化出入库数量和价格 //设置初始化出入库数量和价格
statData.setInCount(0); statData.setInCount(0);
statData.setInPrice(orderDetailResultEntity.getPrice()); statData.setInPrice(null == orderDetailResultEntity.getPrice() ? BigDecimal.ZERO : orderDetailResultEntity.getPrice());
statData.setInAmount(BigDecimal.ZERO); statData.setInAmount(BigDecimal.ZERO);
statData.setOutCount(0); statData.setOutCount(0);
statData.setOutPrice(orderDetailResultEntity.getPrice()); statData.setOutPrice(null == orderDetailResultEntity.getPrice() ? BigDecimal.ZERO : orderDetailResultEntity.getPrice());
statData.setOutAmount(BigDecimal.ZERO); statData.setOutAmount(BigDecimal.ZERO);
//设置期初数据 //设置期初数据
@ -173,11 +145,11 @@ public class IoStatDayServiceImpl implements IoStatDayService {
if (null == statDayEntity) { if (null == statDayEntity) {
//第一次汇总日数据 //第一次汇总日数据
statData.setBeginCount(0); statData.setBeginCount(0);
statData.setBeginPrice(orderDetailResultEntity.getPrice()); statData.setBeginPrice(null == orderDetailResultEntity.getPrice() ? BigDecimal.ZERO : orderDetailResultEntity.getPrice());
statData.setBeginAmount(BigDecimal.ZERO); statData.setBeginAmount(BigDecimal.ZERO);
statData.setBalanceCount(0); statData.setBalanceCount(0);
statData.setBalancePrice(orderDetailResultEntity.getPrice()); statData.setBalanceAmount(BigDecimal.ZERO);
} else { } else {
//已存在此产品汇总数据,基于旧数据生成新的汇总数据 //已存在此产品汇总数据,基于旧数据生成新的汇总数据
statData.setBeginCount(statDayEntity.getBalanceCount()); statData.setBeginCount(statDayEntity.getBalanceCount());
@ -189,7 +161,7 @@ public class IoStatDayServiceImpl implements IoStatDayService {
} }
//设置结余价格 //设置结余价格
statData.setBalancePrice(orderDetailResultEntity.getPrice()); statData.setBalancePrice(null == orderDetailResultEntity.getPrice() ? BigDecimal.ZERO : orderDetailResultEntity.getPrice());
dataList.add(statData); dataList.add(statData);
return statData; return statData;
@ -205,7 +177,7 @@ public class IoStatDayServiceImpl implements IoStatDayService {
//生成汇总记录 //生成汇总记录
IoStatOrderEntity statOrderEntity = new IoStatOrderEntity(); IoStatOrderEntity statOrderEntity = new IoStatOrderEntity();
//生成记录号 //生成记录号
OrderNoTypeBean orderNoTypeBean = new OrderNoTypeBean("STATD", " yyyyMMdd"); OrderNoTypeBean orderNoTypeBean = new OrderNoTypeBean("STATD", "yyyyMMdd");
String orderNo = gennerOrderUtils.createStatOrderNo(orderNoTypeBean); String orderNo = gennerOrderUtils.createStatOrderNo(orderNoTypeBean);
statOrderEntity.setRecordKey(orderNo); statOrderEntity.setRecordKey(orderNo);
statOrderEntity.setType(4); statOrderEntity.setType(4);
@ -222,6 +194,11 @@ public class IoStatDayServiceImpl implements IoStatDayService {
dataList.forEach(statDayEntity -> { dataList.forEach(statDayEntity -> {
statDayEntity.setUpdateTime(updateTime); statDayEntity.setUpdateTime(updateTime);
statDayEntity.setRecordKeyFk(orderNo); statDayEntity.setRecordKeyFk(orderNo);
//计算结余数据
statDayEntity.setBalanceCount(statDayEntity.getBalanceCount() + statDayEntity.getInCount() - statDayEntity.getOutCount());
statDayEntity.setBalanceAmount(statDayEntity.getBalanceAmount().add(statDayEntity.getInAmount()).subtract(statDayEntity.getOutAmount()));
mapper.insert(statDayEntity); mapper.insert(statDayEntity);
}); });

@ -72,10 +72,6 @@ public class IoStatMonthServiceImpl implements IoStatMonthService {
statData.setOutCount(statData.getOutCount() + statDayEntity.getOutCount()); statData.setOutCount(statData.getOutCount() + statDayEntity.getOutCount());
statData.setOutPrice(statDayEntity.getBalancePrice()); statData.setOutPrice(statDayEntity.getBalancePrice());
statData.setOutAmount(statData.getOutAmount().add(statDayEntity.getOutAmount())); statData.setOutAmount(statData.getOutAmount().add(statDayEntity.getOutAmount()));
//设置结余数据
statData.setBalanceCount(statData.getBalanceCount() + statData.getInCount() - statData.getOutCount());
statData.setBalanceAmount(statData.getBalanceAmount().add(statData.getInAmount()).subtract(statData.getOutAmount()));
}); });
//插入汇总记录 //插入汇总记录
@ -121,6 +117,10 @@ public class IoStatMonthServiceImpl implements IoStatMonthService {
dataList.forEach(statMonthEntity -> { dataList.forEach(statMonthEntity -> {
statMonthEntity.setUpdateTime(updateTime); statMonthEntity.setUpdateTime(updateTime);
statMonthEntity.setRecordKeyFk(orderNo); statMonthEntity.setRecordKeyFk(orderNo);
//计算结余数据
statMonthEntity.setBalanceCount(statMonthEntity.getBalanceCount() + statMonthEntity.getInCount() - statMonthEntity.getOutCount());
statMonthEntity.setBalanceAmount(statMonthEntity.getBalanceAmount().add(statMonthEntity.getInAmount()).subtract(statMonthEntity.getOutAmount()));
mapper.insert(statMonthEntity); mapper.insert(statMonthEntity);
}); });

@ -66,10 +66,6 @@ public class IoStatQuarterServiceImpl implements IoStatQuarterService {
statData.setOutCount(statData.getOutCount() + statMonthEntity.getOutCount()); statData.setOutCount(statData.getOutCount() + statMonthEntity.getOutCount());
statData.setOutPrice(statMonthEntity.getOutPrice()); statData.setOutPrice(statMonthEntity.getOutPrice());
statData.setOutAmount(statData.getOutAmount().add(statMonthEntity.getOutAmount())); statData.setOutAmount(statData.getOutAmount().add(statMonthEntity.getOutAmount()));
//设置结余数据
statData.setBalanceCount(statData.getBalanceCount() + statData.getInCount() - statData.getOutCount());
statData.setBalanceAmount(statData.getBalanceAmount().add(statData.getInAmount()).subtract(statData.getOutAmount()));
}); });
//插入汇总数据 //插入汇总数据
@ -116,6 +112,11 @@ public class IoStatQuarterServiceImpl implements IoStatQuarterService {
dataList.forEach(statQuarterEntity -> { dataList.forEach(statQuarterEntity -> {
statQuarterEntity.setUpdateTime(updateTime); statQuarterEntity.setUpdateTime(updateTime);
statQuarterEntity.setRecordKeyFk(orderNo); statQuarterEntity.setRecordKeyFk(orderNo);
//设置结余数据
statQuarterEntity.setBalanceCount(statQuarterEntity.getBalanceCount() + statQuarterEntity.getInCount() - statQuarterEntity.getOutCount());
statQuarterEntity.setBalanceAmount(statQuarterEntity.getBalanceAmount().add(statQuarterEntity.getInAmount()).subtract(statQuarterEntity.getOutAmount()));
mapper.insert(statQuarterEntity); mapper.insert(statQuarterEntity);
}); });

@ -69,16 +69,11 @@ public class IoStatYearServiceImpl implements IoStatYearService {
statData.setOutCount(statData.getOutCount() + statQuarterEntity.getOutCount()); statData.setOutCount(statData.getOutCount() + statQuarterEntity.getOutCount());
statData.setOutPrice(statQuarterEntity.getOutPrice()); statData.setOutPrice(statQuarterEntity.getOutPrice());
statData.setOutAmount(statData.getOutAmount().add(statQuarterEntity.getOutAmount())); statData.setOutAmount(statData.getOutAmount().add(statQuarterEntity.getOutAmount()));
//设置结余数据
statData.setBalanceCount(statData.getBalanceCount() + statData.getInCount() - statData.getOutCount());
statData.setBalanceAmount(statData.getBalanceAmount().add(statData.getInAmount()).subtract(statData.getOutAmount()));
}); });
//插入汇总数据 //插入汇总数据
saveData(yesterday, dataList); saveData(yesterday, dataList);
} }
} }
@Override @Override
@ -119,6 +114,10 @@ public class IoStatYearServiceImpl implements IoStatYearService {
dataList.forEach(statYearEntity -> { dataList.forEach(statYearEntity -> {
statYearEntity.setUpdateTime(updateTime); statYearEntity.setUpdateTime(updateTime);
statYearEntity.setRecordKeyFk(orderNo); statYearEntity.setRecordKeyFk(orderNo);
//设置结余数据
statYearEntity.setBalanceCount(statYearEntity.getBalanceCount() + statYearEntity.getInCount() - statYearEntity.getOutCount());
statYearEntity.setBalanceAmount(statYearEntity.getBalanceAmount().add(statYearEntity.getInAmount()).subtract(statYearEntity.getOutAmount()));
mapper.insert(statYearEntity); mapper.insert(statYearEntity);
}); });

@ -73,4 +73,18 @@
</if> </if>
</where> </where>
</select> </select>
<select id="selectStatDataByTime" resultType="com.glxp.api.entity.inout.IoOrderDetailResultEntity">
select orderIdFk,
bindRlFk,
nameCode,
batchNo,
coName,
spec,
price,
reCount
from io_order_detail_result
where orderIdFk in
(select billNo from io_order where date_format(updateTime, '%Y-%m-%d') = date_format(#{date}, '%Y-%m-%d'))
</select>
</mapper> </mapper>

@ -14,6 +14,9 @@
<if test="productName != null and productName != ''"> <if test="productName != null and productName != ''">
AND productName like concat('%', #{productName}, '%') AND productName like concat('%', #{productName}, '%')
</if> </if>
<if test="ggxh != null and ggxh != ''">
AND ggxh like concat('%', #{ggxh}, '%')
</if>
</where> </where>
</select> </select>

@ -14,6 +14,9 @@
<if test="productName != null and productName != ''"> <if test="productName != null and productName != ''">
AND productName like concat('%', #{productName}, '%') AND productName like concat('%', #{productName}, '%')
</if> </if>
<if test="ggxh != null and ggxh != ''">
AND ggxh like concat('%', #{ggxh}, '%')
</if>
</where> </where>
</select> </select>
</mapper> </mapper>

@ -9,13 +9,13 @@
and type = #{type} and type = #{type}
</if> </if>
<if test="recordKey != null and recordKey != ''"> <if test="recordKey != null and recordKey != ''">
and recordKey like concat('%', #{recordKey}, '#') and recordKey like concat('%', #{recordKey}, '%')
</if> </if>
<if test="startDate != null and startDate != ''"> <if test="startTime != null and startTime != ''">
and format(date, '%Y-%m-%d') >= format(#{startDate}, '%Y-%m-%d') and date_format(date, '%Y-%m-%d') >= date_format(#{startTime}, '%Y-%m-%d')
</if> </if>
<if test="endDate != null and endDate != ''"> <if test="endTime != null and endTime != ''">
and format(date, '%Y-%m-%d') &lt;= format(#{endDate}, '%Y-%m-%d') and date_format(date, '%Y-%m-%d') &lt;= date_format(#{endTime}, '%Y-%m-%d')
</if> </if>
</where> </where>
</select> </select>

@ -14,6 +14,9 @@
<if test="productName != null and productName != ''"> <if test="productName != null and productName != ''">
AND productName like concat('%', #{productName}, '%') AND productName like concat('%', #{productName}, '%')
</if> </if>
<if test="ggxh != null and ggxh != ''">
AND ggxh like concat('%', #{ggxh}, '%')
</if>
</where> </where>
</select> </select>
</mapper> </mapper>

@ -14,6 +14,9 @@
<if test="productName != null and productName != ''"> <if test="productName != null and productName != ''">
AND productName like concat('%', #{productName}, '%') AND productName like concat('%', #{productName}, '%')
</if> </if>
<if test="ggxh != null and ggxh != ''">
AND ggxh like concat('%', #{ggxh}, '%')
</if>
</where> </where>
</select> </select>
</mapper> </mapper>
Loading…
Cancel
Save