|
|
|
|
@ -1,13 +1,14 @@
|
|
|
|
|
package cn.ysk.cashier.cons.service.impl;
|
|
|
|
|
|
|
|
|
|
import cn.ysk.cashier.cons.domain.TbConsInfo;
|
|
|
|
|
import cn.ysk.cashier.cons.domain.TbConsInfoFlow;
|
|
|
|
|
import cn.ysk.cashier.cons.domain.TbConsSuppFlow;
|
|
|
|
|
import cn.ysk.cashier.cons.domain.TbConsType;
|
|
|
|
|
import cn.ysk.cashier.cons.domain.*;
|
|
|
|
|
import cn.ysk.cashier.cons.repository.TbConsInfoFlowRepository;
|
|
|
|
|
import cn.ysk.cashier.cons.repository.TbConsInfoRepository;
|
|
|
|
|
import cn.ysk.cashier.cons.repository.TbConsSuppFlowRepository;
|
|
|
|
|
import cn.ysk.cashier.cons.repository.TbConsTypeRepository;
|
|
|
|
|
import cn.ysk.cashier.cons.service.mapstruct.TbConsSuppFlowMapper;
|
|
|
|
|
import cn.ysk.cashier.cons.service.TbConsInfoService;
|
|
|
|
|
import cn.ysk.cashier.cons.service.dto.TbConsInfoDto;
|
|
|
|
|
import cn.ysk.cashier.cons.service.dto.TbConsInfoQueryCriteria;
|
|
|
|
|
import cn.ysk.cashier.cons.service.mapstruct.TbConsInfoMapper;
|
|
|
|
|
import cn.ysk.cashier.pojo.product.TbProductStockOperate;
|
|
|
|
|
import cn.ysk.cashier.pojo.shop.TbShopInfo;
|
|
|
|
|
import cn.ysk.cashier.pojo.shop.TbShopPurveyor;
|
|
|
|
|
@ -22,43 +23,34 @@ import cn.ysk.cashier.utils.QueryHelp;
|
|
|
|
|
import cn.ysk.cashier.utils.ValidationUtil;
|
|
|
|
|
import com.alibaba.fastjson.JSON;
|
|
|
|
|
import lombok.RequiredArgsConstructor;
|
|
|
|
|
import cn.ysk.cashier.cons.repository.TbConsInfoRepository;
|
|
|
|
|
import cn.ysk.cashier.cons.service.TbConsInfoService;
|
|
|
|
|
import cn.ysk.cashier.cons.service.dto.TbConsInfoDto;
|
|
|
|
|
import cn.ysk.cashier.cons.service.dto.TbConsInfoQueryCriteria;
|
|
|
|
|
import cn.ysk.cashier.cons.service.mapstruct.TbConsInfoMapper;
|
|
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
import org.springframework.data.domain.Page;
|
|
|
|
|
import org.springframework.data.domain.Pageable;
|
|
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
|
|
|
|
import javax.servlet.http.HttpServletResponse;
|
|
|
|
|
import java.io.IOException;
|
|
|
|
|
import java.math.BigDecimal;
|
|
|
|
|
import java.sql.Timestamp;
|
|
|
|
|
import java.util.*;
|
|
|
|
|
import java.io.IOException;
|
|
|
|
|
import javax.servlet.http.HttpServletResponse;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @website https://eladmin.vip
|
|
|
|
|
* @description 服务实现
|
|
|
|
|
* @author admin
|
|
|
|
|
* @date 2024-06-22
|
|
|
|
|
**/
|
|
|
|
|
* @author admin
|
|
|
|
|
* @website https://eladmin.vip
|
|
|
|
|
* @description 服务实现
|
|
|
|
|
* @date 2024-06-22
|
|
|
|
|
**/
|
|
|
|
|
@Service
|
|
|
|
|
@RequiredArgsConstructor
|
|
|
|
|
@Slf4j
|
|
|
|
|
public class TbConsInfoServiceImpl implements TbConsInfoService {
|
|
|
|
|
|
|
|
|
|
public final TbConsTypeRepository tbConsTypeRepository;
|
|
|
|
|
public final TbConsInfoFlowRepository tbConsInfoFlowRepository;
|
|
|
|
|
public final TbConsSuppFlowRepository tbConsSuppFlowRepository;
|
|
|
|
|
private final TbConsInfoRepository tbConsInfoRepository;
|
|
|
|
|
private final TbConsInfoMapper tbConsInfoMapper;
|
|
|
|
|
|
|
|
|
|
public final TbConsTypeRepository tbConsTypeRepository;
|
|
|
|
|
|
|
|
|
|
public final TbConsInfoFlowRepository tbConsInfoFlowRepository;
|
|
|
|
|
|
|
|
|
|
public final TbConsSuppFlowRepository tbConsSuppFlowRepository;
|
|
|
|
|
|
|
|
|
|
private final TbShopPurveyorRepository tbShopPurveyorRepository;
|
|
|
|
|
|
|
|
|
|
private final TbShopInfoRepository tbShopInfoRepository;
|
|
|
|
|
@ -71,21 +63,21 @@ public class TbConsInfoServiceImpl implements TbConsInfoService {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public Map<String,Object> queryAll(TbConsInfoQueryCriteria criteria, Pageable pageable){
|
|
|
|
|
Page<TbConsInfo> page = tbConsInfoRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root,criteria,criteriaBuilder),pageable);
|
|
|
|
|
public Map<String, Object> queryAll(TbConsInfoQueryCriteria criteria, Pageable pageable) {
|
|
|
|
|
Page<TbConsInfo> page = tbConsInfoRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root, criteria, criteriaBuilder), pageable);
|
|
|
|
|
return PageUtil.toPage(page.map(tbConsInfoMapper::toDto));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public List<TbConsInfoDto> queryAll(TbConsInfoQueryCriteria criteria){
|
|
|
|
|
return tbConsInfoMapper.toDto(tbConsInfoRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root,criteria,criteriaBuilder)));
|
|
|
|
|
public List<TbConsInfoDto> queryAll(TbConsInfoQueryCriteria criteria) {
|
|
|
|
|
return tbConsInfoMapper.toDto(tbConsInfoRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root, criteria, criteriaBuilder)));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
@Transactional
|
|
|
|
|
public TbConsInfoDto findById(Integer id) {
|
|
|
|
|
TbConsInfo tbConsInfo = tbConsInfoRepository.findById(id).orElseGet(TbConsInfo::new);
|
|
|
|
|
ValidationUtil.isNull(tbConsInfo.getId(),"TbConsInfo","id",id);
|
|
|
|
|
ValidationUtil.isNull(tbConsInfo.getId(), "TbConsInfo", "id", id);
|
|
|
|
|
return tbConsInfoMapper.toDto(tbConsInfo);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@ -94,15 +86,14 @@ public class TbConsInfoServiceImpl implements TbConsInfoService {
|
|
|
|
|
public TbConsInfoDto create(TbConsInfo resources) throws Exception {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
TbConsType tbConsType= tbConsTypeRepository.getById(resources.getConTypeId());
|
|
|
|
|
if(Objects.isNull(tbConsType)){
|
|
|
|
|
TbConsType tbConsType = tbConsTypeRepository.getById(resources.getConTypeId());
|
|
|
|
|
if (Objects.isNull(tbConsType)) {
|
|
|
|
|
throw new Exception("不存在的耗材类型");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int count= tbConsInfoRepository.countByConCode(resources.getConCode());
|
|
|
|
|
if(count>0){
|
|
|
|
|
int count = tbConsInfoRepository.countByConCode(resources.getConCode());
|
|
|
|
|
if (count > 0) {
|
|
|
|
|
throw new Exception("耗材代码不允许重复");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@ -120,7 +111,7 @@ public class TbConsInfoServiceImpl implements TbConsInfoService {
|
|
|
|
|
public void update(TbConsInfo resources) throws Exception {
|
|
|
|
|
TbConsInfo tbConsInfo = tbConsInfoRepository.findById(resources.getId()).orElseGet(TbConsInfo::new);
|
|
|
|
|
|
|
|
|
|
if(Objects.isNull(tbConsInfo)){
|
|
|
|
|
if (Objects.isNull(tbConsInfo)) {
|
|
|
|
|
throw new Exception("耗材信息不存在");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@ -146,7 +137,7 @@ public class TbConsInfoServiceImpl implements TbConsInfoService {
|
|
|
|
|
public void download(List<TbConsInfoDto> all, HttpServletResponse response) throws IOException {
|
|
|
|
|
List<Map<String, Object>> list = new ArrayList<>();
|
|
|
|
|
for (TbConsInfoDto tbConsInfo : all) {
|
|
|
|
|
Map<String,Object> map = new LinkedHashMap<>();
|
|
|
|
|
Map<String, Object> map = new LinkedHashMap<>();
|
|
|
|
|
map.put("耗材类型id", tbConsInfo.getConTypeId());
|
|
|
|
|
map.put("耗材类型名称", tbConsInfo.getConTypeName());
|
|
|
|
|
map.put("耗材代码", tbConsInfo.getConCode());
|
|
|
|
|
@ -155,7 +146,7 @@ public class TbConsInfoServiceImpl implements TbConsInfoService {
|
|
|
|
|
map.put("单位值", tbConsInfo.getConUnit());
|
|
|
|
|
map.put("最近一次入库量", tbConsInfo.getLasterInStock());
|
|
|
|
|
map.put("创建时间", tbConsInfo.getCreateTime());
|
|
|
|
|
map.put("耗材预警值",tbConsInfo.getConWarning());
|
|
|
|
|
map.put("耗材预警值", tbConsInfo.getConWarning());
|
|
|
|
|
map.put("更新时间", tbConsInfo.getUpdateTime());
|
|
|
|
|
map.put("店铺id", tbConsInfo.getShopId());
|
|
|
|
|
list.add(map);
|
|
|
|
|
@ -165,30 +156,54 @@ public class TbConsInfoServiceImpl implements TbConsInfoService {
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
|
|
public void stockInOut(List<TbConsSuppFlow> resources) throws Exception {
|
|
|
|
|
if(Objects.isNull(resources)&&resources.size()<=0){
|
|
|
|
|
public void stockInOut(SuppFlow resources) throws Exception {
|
|
|
|
|
if (Objects.isNull(resources)) {
|
|
|
|
|
throw new Exception("参数错误");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for (TbConsSuppFlow resource : resources) {
|
|
|
|
|
TbConsInfo info= tbConsInfoRepository.getById(resource.getConInfoId());
|
|
|
|
|
if(Objects.isNull(info)){
|
|
|
|
|
TbShopInfo tbShopInfo = tbShopInfoRepository.getById(resources.getShopId());
|
|
|
|
|
if (Objects.isNull(tbShopInfo)) {
|
|
|
|
|
throw new Exception("店铺信息不存在");
|
|
|
|
|
}
|
|
|
|
|
TbShopPurveyor purveyor = tbShopPurveyorRepository.getById(resources.getSupplierId());
|
|
|
|
|
if (Objects.isNull(purveyor)) {
|
|
|
|
|
throw new Exception("不存在的供应商");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
TbProductStockOperate stockOperate = new TbProductStockOperate();
|
|
|
|
|
stockOperate.setShopId(tbShopInfo.getId().toString());
|
|
|
|
|
stockOperate.setStockSnap("");
|
|
|
|
|
stockOperate.setType(resources.getType());
|
|
|
|
|
stockOperate.setSubType(-1);
|
|
|
|
|
Map<String, String> operatorSnapMap = new HashMap<>();
|
|
|
|
|
operatorSnapMap.put("name", tbShopInfo.getShopName());
|
|
|
|
|
operatorSnapMap.put("account", tbShopInfo.getAccount());
|
|
|
|
|
|
|
|
|
|
stockOperate.setOperatorSnap(JSON.toJSONString(operatorSnapMap));
|
|
|
|
|
stockOperate.setBatchNumber("");
|
|
|
|
|
stockOperate.setRemark("");
|
|
|
|
|
stockOperate.setStockTime(System.currentTimeMillis());
|
|
|
|
|
stockOperate.setCreatedAt(System.currentTimeMillis());
|
|
|
|
|
stockOperate.setUpdatedAt(System.currentTimeMillis());
|
|
|
|
|
stockOperate.setStatus("normal");
|
|
|
|
|
stockOperate.setPurveyorId(resources.getSupplierId().toString());
|
|
|
|
|
stockOperate.setPurveyorName(purveyor.getPurveyorName());
|
|
|
|
|
|
|
|
|
|
tbProductStockOperateRepository.save(stockOperate);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for (SuppFlow.ConInfos conInfos : resources.getList()) {
|
|
|
|
|
|
|
|
|
|
TbConsInfo info = tbConsInfoRepository.getById(conInfos.getConInfold());
|
|
|
|
|
if (Objects.isNull(info)) {
|
|
|
|
|
log.info("耗材信息不存在");
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
TbShopInfo tbShopInfo= tbShopInfoRepository.getById(resource.getShopId());
|
|
|
|
|
if(Objects.isNull(tbShopInfo)){
|
|
|
|
|
log.info("店铺信息不存在");
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
TbShopPurveyor purveyor= tbShopPurveyorRepository.getById(resource.getSupplierId());
|
|
|
|
|
if(Objects.isNull(purveyor)){
|
|
|
|
|
log.info("不存在的供应商");
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TbConsInfoFlow flow=new TbConsInfoFlow();
|
|
|
|
|
TbConsSuppFlow suppFlow = new TbConsSuppFlow();
|
|
|
|
|
|
|
|
|
|
TbConsInfoFlow flow = new TbConsInfoFlow();
|
|
|
|
|
|
|
|
|
|
TbShopPurveyorTransact purveyorTransact = new TbShopPurveyorTransact();
|
|
|
|
|
purveyorTransact.setShopId(tbShopInfo.getId().toString());
|
|
|
|
|
@ -198,96 +213,80 @@ public class TbConsInfoServiceImpl implements TbConsInfoService {
|
|
|
|
|
purveyorTransact.setCreatedAt(System.currentTimeMillis());
|
|
|
|
|
purveyorTransact.setUpdatedAt(System.currentTimeMillis());
|
|
|
|
|
|
|
|
|
|
suppFlow.setConInfoId(info.getConTypeId());
|
|
|
|
|
suppFlow.setShopId(resources.getShopId());
|
|
|
|
|
suppFlow.setSupplierId(resources.getSupplierId());
|
|
|
|
|
suppFlow.setType(resources.getType());
|
|
|
|
|
suppFlow.setStockNumber(conInfos.getStockNumber());
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if ("in".equals(resources.getType())) {
|
|
|
|
|
info.setStockNumber(info.getStockNumber().add(conInfos.getStockNumber()));
|
|
|
|
|
info.setLasterInStock(conInfos.getStockNumber());
|
|
|
|
|
|
|
|
|
|
suppFlow.setBalance(info.getStockNumber().subtract(info.getStockConsume()).add(conInfos.getStockNumber()));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
TbProductStockOperate stockOperate = new TbProductStockOperate();
|
|
|
|
|
stockOperate.setShopId(tbShopInfo.getId().toString());
|
|
|
|
|
stockOperate.setStockSnap("");
|
|
|
|
|
stockOperate.setType(resource.getType());
|
|
|
|
|
stockOperate.setSubType(-1);
|
|
|
|
|
Map<String, String> operatorSnapMap = new HashMap<>();
|
|
|
|
|
operatorSnapMap.put("name", tbShopInfo.getShopName());
|
|
|
|
|
operatorSnapMap.put("account", tbShopInfo.getAccount());
|
|
|
|
|
|
|
|
|
|
stockOperate.setOperatorSnap(JSON.toJSONString(operatorSnapMap));
|
|
|
|
|
stockOperate.setBatchNumber("");
|
|
|
|
|
stockOperate.setRemark("");
|
|
|
|
|
stockOperate.setStockTime(System.currentTimeMillis());
|
|
|
|
|
stockOperate.setCreatedAt(System.currentTimeMillis());
|
|
|
|
|
stockOperate.setUpdatedAt(System.currentTimeMillis());
|
|
|
|
|
stockOperate.setStatus("normal");
|
|
|
|
|
stockOperate.setPurveyorId(resource.getSupplierId().toString());
|
|
|
|
|
stockOperate.setPurveyorName(purveyor.getPurveyorName());
|
|
|
|
|
|
|
|
|
|
tbProductStockOperateRepository.save(stockOperate);
|
|
|
|
|
|
|
|
|
|
if("in".equals(resource.getType())){
|
|
|
|
|
info.setStockNumber(info.getStockNumber().add(resource.getStockNumber()));
|
|
|
|
|
info.setLasterInStock(resource.getStockNumber());
|
|
|
|
|
resource.setType("in");
|
|
|
|
|
|
|
|
|
|
flow.setBizCode("stockIn");
|
|
|
|
|
flow.setBizName("耗材入库");
|
|
|
|
|
flow.setBizType("+");
|
|
|
|
|
|
|
|
|
|
purveyorTransact.setTotalAmount(resource.getAccountsPayable());
|
|
|
|
|
purveyorTransact.setPaidAmount(resource.getActualPayment());
|
|
|
|
|
purveyorTransact.setWaitAmount((resource.getAccountsPayable().subtract(resource.getActualPayment())));
|
|
|
|
|
purveyorTransact.setTotalAmount(resources.getAccountsPayable());
|
|
|
|
|
purveyorTransact.setPaidAmount(resources.getActualPayment());
|
|
|
|
|
purveyorTransact.setWaitAmount((resources.getAccountsPayable().subtract(resources.getActualPayment())));
|
|
|
|
|
purveyorTransact.setType("cons_in");
|
|
|
|
|
}else {
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
|
|
info.setStockNumber(info.getStockNumber().subtract(conInfos.getStockNumber()));
|
|
|
|
|
suppFlow.setBalance(info.getStockNumber().subtract(info.getStockConsume()).subtract(conInfos.getStockNumber()));
|
|
|
|
|
|
|
|
|
|
info.setStockNumber(info.getStockNumber().subtract(resource.getStockNumber()));
|
|
|
|
|
resource.setType("out");
|
|
|
|
|
|
|
|
|
|
flow.setBizCode("stockout");
|
|
|
|
|
flow.setBizName("耗材出库");
|
|
|
|
|
flow.setBizType("-");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
purveyorTransact.setTotalAmount(resource.getAccountsPayable().negate());
|
|
|
|
|
purveyorTransact.setPaidAmount(resource.getActualPayment());
|
|
|
|
|
purveyorTransact.setWaitAmount((resource.getAccountsPayable().subtract(resource.getActualPayment())).negate());
|
|
|
|
|
purveyorTransact.setTotalAmount(resources.getAccountsPayable().negate());
|
|
|
|
|
purveyorTransact.setPaidAmount(resources.getActualPayment());
|
|
|
|
|
purveyorTransact.setWaitAmount((resources.getAccountsPayable().subtract(resources.getActualPayment())).negate());
|
|
|
|
|
purveyorTransact.setType("cons_out");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
suppFlow.setPrice(conInfos.getPrice());
|
|
|
|
|
suppFlow.setAmount(conInfos.getStockNumber());
|
|
|
|
|
suppFlow.setAccountsPayable(resources.getAccountsPayable());
|
|
|
|
|
suppFlow.setActualPayment(resources.getActualPayment());
|
|
|
|
|
suppFlow.setCreateTime(new Timestamp(System.currentTimeMillis()));
|
|
|
|
|
|
|
|
|
|
if (resource.getAccountsPayable().compareTo(resource.getActualPayment()) <= 0) {
|
|
|
|
|
|
|
|
|
|
if (resources.getAccountsPayable().compareTo(resources.getActualPayment()) <= 0) {
|
|
|
|
|
purveyorTransact.setStatus(1);
|
|
|
|
|
} else {
|
|
|
|
|
purveyorTransact.setStatus(0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
purveyorTransact.setPaidAt(System.currentTimeMillis());
|
|
|
|
|
|
|
|
|
|
purveyorTransactRepository.save(purveyorTransact);
|
|
|
|
|
if (resource.getSupplierId() != null) {
|
|
|
|
|
tbShopPurveyorRepository.upLastTransactAt(resource.getSupplierId().toString());
|
|
|
|
|
if (resources.getSupplierId() != null) {
|
|
|
|
|
tbShopPurveyorRepository.upLastTransactAt(resources.getSupplierId().toString());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
tbConsInfoRepository.save(info);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
resource.setAmount(resource.getStockNumber());
|
|
|
|
|
resource.setBalance(info.getStockNumber());
|
|
|
|
|
resource.setCreateTime(new Timestamp(System.currentTimeMillis()));
|
|
|
|
|
tbConsSuppFlowRepository.save(resource);
|
|
|
|
|
tbConsSuppFlowRepository.save(suppFlow);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
flow.setConsId(info.getId());
|
|
|
|
|
flow.setShopId(info.getShopId());
|
|
|
|
|
flow.setConName(info.getConName());
|
|
|
|
|
flow.setAmount(resource.getStockNumber());
|
|
|
|
|
flow.setAmount(conInfos.getStockNumber());
|
|
|
|
|
flow.setBalance(info.getStockNumber());
|
|
|
|
|
|
|
|
|
|
flow.setCreateTime(new Timestamp(System.currentTimeMillis()));
|
|
|
|
|
tbConsInfoFlowRepository.save(flow);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|