package com.fzzy.igds.service;
|
|
import com.fzzy.igds.domain.DepotStore;
|
import com.fzzy.igds.repository.DepotRepository;
|
import com.fzzy.igds.repository.DepotStoreRepository;
|
import com.fzzy.igds.utils.ContextUtil;
|
import com.ruoyi.common.utils.StringUtils;
|
import lombok.extern.slf4j.Slf4j;
|
import org.apache.commons.lang3.time.DateFormatUtils;
|
import org.springframework.data.domain.Page;
|
import org.springframework.data.domain.Pageable;
|
import org.springframework.data.jpa.domain.Specification;
|
import org.springframework.stereotype.Service;
|
import javax.annotation.Resource;
|
import java.util.Date;
|
import java.util.List;
|
|
/**
|
* @Description
|
* @Author CZT
|
* @Date 2025/11/27 13:44
|
*/
|
@Slf4j
|
@Service
|
public class DepotStoreService {
|
|
@Resource
|
private DepotStoreRepository depotStoreRepository;
|
@Resource
|
private DepotRepository depotRepository;
|
|
/**
|
* JPA分页查询数据
|
*
|
* @param specification
|
* @param pageable
|
* @return
|
*/
|
public Page<DepotStore> findAll(Specification<DepotStore> specification, Pageable pageable) {
|
return depotStoreRepository.findAll(specification, pageable);
|
}
|
|
/**
|
* JPA更新保存数据
|
*
|
* @param data
|
*/
|
public void saveDepotStore(DepotStore data) {
|
if (StringUtils.isEmpty(data.getCompanyId())) {
|
data.setCompanyId(ContextUtil.getCompanyId());
|
}
|
if (StringUtils.isEmpty(data.getDeptId())) {
|
data.setDeptId(ContextUtil.subDeptId(null));
|
}
|
data.setUpdateBy(ContextUtil.getLoginUserName());
|
data.setUpdateTime(new Date());
|
|
data.setId(data.getDepotId() + "_" + DateFormatUtils.format(data.getStoreDate(), "yyyyMMddHHmmss") + "_" + DateFormatUtils.format(data.getUpdateTime(), "yyyyMMddHHmmss"));
|
data.setCreateTime(new Date());
|
data.setRemark("系统生成");
|
|
depotStoreRepository.save(data);
|
}
|
|
/**
|
* JPA删除数据
|
*
|
* @param data
|
* @return
|
*/
|
public String delDepotStore(DepotStore data) {
|
depotStoreRepository.delete(data);
|
return null;
|
}
|
|
/**
|
* JPA获取仓库最后一条库存数据
|
*
|
* @param depotId
|
* @param time
|
* @return
|
*/
|
public DepotStore getLastData(String depotId, Date time) {
|
List<DepotStore> list = depotStoreRepository.getDataByDepotId(depotId, time);
|
if (null == list || list.isEmpty()) {
|
return null;
|
}
|
return list.get(0);
|
}
|
|
public void addDepotStore(DepotStore store, boolean updateDepot) {
|
if (null == store.getUpdateTime()) store.setUpdateTime(new Date());
|
if (null == store.getId()) store.setId(ContextUtil.generateId());
|
|
depotStoreRepository.save(store);
|
|
if (updateDepot) {
|
depotRepository.updateDepotStorage(store.getStorageReal(), store.getDepotId());
|
}
|
}
|
|
|
}
|