package com.fzzy.igds.service;
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
import com.fzzy.igds.constant.Constant;
|
import com.fzzy.igds.data.NoticeDto;
|
import com.fzzy.igds.data.NoticeParam;
|
import com.fzzy.igds.mapper.InoutNoticeInMapper;
|
import com.fzzy.igds.mapper.InoutNoticeMapper;
|
import com.fzzy.igds.repository.InoutNoticeInRepository;
|
import com.fzzy.igds.repository.InoutNoticeOutRepository;
|
import com.fzzy.igds.domain.InoutNoticeIn;
|
import com.fzzy.igds.domain.InoutNoticeOut;
|
import com.fzzy.igds.utils.ContextUtil;
|
import com.ruoyi.common.utils.StringUtils;
|
import lombok.extern.slf4j.Slf4j;
|
import org.springframework.beans.BeanUtils;
|
|
import org.springframework.data.domain.Pageable;
|
import org.springframework.data.jpa.domain.Specification;
|
import org.springframework.stereotype.Service;
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
import javax.annotation.Resource;
|
import java.util.Date;
|
import java.util.List;
|
import java.util.Map;
|
|
/**
|
* @Description 出入库通知单service层,包含入库通知单和出库通知单
|
* @Author CZT
|
* @Date 2025/11/29 16:33
|
*/
|
@Slf4j
|
@Service
|
public class InoutNoticeService {
|
|
@Resource
|
private InoutNoticeInRepository noticeInRepository;
|
@Resource
|
private InoutNoticeOutRepository noticeOutRepository;
|
@Resource
|
private InoutNoticeMapper noticeMapper;
|
|
@Resource
|
private InoutNoticeInMapper noticeInMapper;
|
|
|
/* *//**
|
* JPA分页查询数据
|
*
|
*//*
|
public Page<InoutNoticeIn> queryAllNoticeIn(Specification<InoutNoticeIn> specification, Pageable pageable) {
|
return noticeInRepository.findAll(specification, pageable);
|
}*/
|
|
public void pageQueryIn(Page<InoutNoticeIn> page, NoticeParam param) {
|
QueryWrapper<InoutNoticeIn> queryWrapper = new QueryWrapper<>();
|
|
if(null == param) param = new NoticeParam();
|
param.setCompanyId(ContextUtil.getCompanyId());
|
|
queryWrapper.eq("company_id", param.getCompanyId());
|
|
noticeInMapper.selectPage(page, queryWrapper);
|
}
|
|
/**
|
* JPA查询数据
|
* @param companyId
|
* @param deptId
|
* @return
|
*/
|
public List<InoutNoticeIn> listNoticeIn(String companyId, String deptId) {
|
return noticeInRepository.listNoticeIn(companyId, deptId, Constant.COMPLETE_STATUS_NONE);
|
}
|
|
/**
|
* jpa 获取信息
|
* @param companyId
|
* @return
|
*/
|
public List<InoutNoticeIn> getUnComNoticeIn(String companyId) {
|
if (StringUtils.isEmpty(companyId)) {
|
companyId = ContextUtil.getCompanyId();
|
}
|
return noticeInRepository.listNoticeIn(companyId, Constant.COMPLETE_STATUS_NONE);
|
}
|
|
/**
|
* JPA - 保存更新数据
|
*
|
* @param data
|
* @return
|
*/
|
public String saveOrUpdateIn(InoutNoticeIn data) {
|
if (null == data.getUpdateBy()) {
|
data.setUpdateBy(ContextUtil.getLoginUserName());
|
data.setUpdateTime(new Date());
|
data.setCreateBy(ContextUtil.getLoginUserName());
|
data.setCreateTime(new Date());
|
data.setAuditStatus(Constant.COMPLETE_STATUS_NONE);
|
data.setCompleteStatus(Constant.COMPLETE_STATUS_NONE);
|
noticeInRepository.save(data);
|
} else {
|
data.setUpdateBy(ContextUtil.getLoginUserName());
|
data.setUpdateTime(new Date());
|
noticeInRepository.save(data);
|
}
|
|
return null;
|
}
|
|
/**
|
* JPA - 删除数据
|
*
|
* @param data
|
* @return
|
*/
|
public String delDataIn(InoutNoticeIn data) {
|
noticeInRepository.delete(data);
|
return null;
|
}
|
|
/**
|
* JPA分页查询数据
|
*
|
* @param specification
|
* @param pageable
|
* @return
|
*/
|
public Page<InoutNoticeOut> queryAllNoticeOut(Specification<InoutNoticeOut> specification, Pageable pageable) {
|
//return noticeOutRepository.findAll(specification, pageable);
|
return null;
|
}
|
|
/**
|
* JPA查询数据
|
* @param companyId
|
* @param deptId
|
* @return
|
*/
|
public List<InoutNoticeOut> listNoticeOut(String companyId, String deptId) {
|
return noticeOutRepository.listNoticeOut(companyId, deptId, Constant.COMPLETE_STATUS_NONE);
|
}
|
|
/**
|
* Mybatis-plus 获取信息
|
* @param companyId
|
* @return
|
*/
|
public List<InoutNoticeOut> getUnComNoticeOut(String companyId) {
|
if (StringUtils.isEmpty(companyId)) {
|
companyId = ContextUtil.getCompanyId();
|
}
|
return noticeOutRepository.listNoticeOut(companyId, Constant.COMPLETE_STATUS_NONE);
|
}
|
|
/**
|
* JPA - 保存更新数据
|
*
|
* @param data
|
* @return
|
*/
|
public String saveOrUpdateOut(InoutNoticeOut data) {
|
if (Constant.YN_Y.equals(data.getTag())) {
|
data.setCreateBy(ContextUtil.getLoginUserName());
|
data.setCreateTime(new Date());
|
data.setAuditStatus(Constant.COMPLETE_STATUS_NONE);
|
data.setCompleteStatus(Constant.COMPLETE_STATUS_NONE);
|
}
|
data.setUpdateBy(ContextUtil.getLoginUserName());
|
data.setUpdateTime(new Date());
|
noticeOutRepository.save(data);
|
return null;
|
}
|
|
/**
|
* JPA - 删除数据
|
*
|
* @param data
|
* @return
|
*/
|
public String delDataOut(InoutNoticeOut data) {
|
noticeOutRepository.delete(data);
|
return null;
|
}
|
|
/**
|
* JPA - 根据ID获取通知单信息
|
* @param id
|
* @param type
|
* @return
|
*/
|
public NoticeDto queryNoticeById(String id, String type) {
|
if (StringUtils.isEmpty(id) || StringUtils.isEmpty(type)) {
|
return null;
|
}
|
NoticeDto noticeDto = new NoticeDto();
|
if (Constant.TYPE_IN.equals(type)) {
|
InoutNoticeIn noticeIn = noticeInRepository.getDataById(ContextUtil.getCompanyId(), ContextUtil.subDeptId(null), id);
|
BeanUtils.copyProperties(noticeIn, noticeDto);
|
} else {
|
InoutNoticeOut noticeOut = noticeOutRepository.getDataById(ContextUtil.getCompanyId(), ContextUtil.subDeptId(null), id);
|
BeanUtils.copyProperties(noticeOut, noticeDto);
|
}
|
return noticeDto;
|
}
|
|
/**
|
* Mybatis-plus 更新信息
|
* @param noticeInList
|
* @return
|
*/
|
public void updateSumNoticeIn(List<InoutNoticeIn> noticeInList) {
|
|
if (null == noticeInList || noticeInList.isEmpty()) {
|
return;
|
}
|
|
//遍历通知单
|
NoticeParam param;
|
for (InoutNoticeIn noticeIn : noticeInList) {
|
|
param = new NoticeParam(noticeIn.getCompanyId(), noticeIn.getDeptId(),
|
noticeIn.getCustomerName(), noticeIn.getFoodVariety(), noticeIn.getId());
|
|
log.info("开始更新出库通知单={}", param.toString());
|
|
String msg = this.reSumNoticeInComplete(param);
|
if (msg != null) {
|
log.info("入库通知单完成量统计失败={},失败原因={}", param.toString(), msg);
|
}
|
}
|
}
|
|
/**
|
* Mybatis-plus 获取信息
|
* @param param
|
* @return
|
*/
|
public String reSumNoticeInComplete(NoticeParam param) {
|
if (StringUtils.isEmpty(param.getCustomerName())) {
|
return "客户编码为空!";
|
}
|
if (StringUtils.isEmpty(param.getFoodVariety())) {
|
return "粮食品种为空!";
|
}
|
if (StringUtils.isEmpty(param.getCompanyId())) {
|
param.setCompanyId(ContextUtil.getCompanyId());
|
}
|
if (StringUtils.isEmpty(param.getDeptId())) {
|
param.setDeptId(ContextUtil.subDeptId(null));
|
}
|
noticeMapper.reSumNoticeInComplete(param);
|
return null;
|
}
|
|
/**
|
* Mybatis-plus 更新信息
|
* @param noticeOutList
|
* @return
|
*/
|
public void updateSumNoticeOut(List<InoutNoticeOut> noticeOutList) {
|
|
if (null == noticeOutList || noticeOutList.isEmpty()) {
|
return;
|
}
|
|
//遍历通知单
|
NoticeParam param;
|
for (InoutNoticeOut noticeOut : noticeOutList) {
|
|
param = new NoticeParam(noticeOut.getCompanyId(), noticeOut.getDeptId(), noticeOut.getDepotId(),
|
noticeOut.getCustomerId(), noticeOut.getFoodVariety(), noticeOut.getId());
|
|
log.info("开始更新出库通知单={}", param.toString());
|
|
String msg = this.reSumNoticeOutComplete(param);
|
if (msg != null) {
|
log.info("出库通知单完成量统计失败={},失败原因={}", param.toString(), msg);
|
}
|
}
|
}
|
|
/**
|
* Mybatis-plus 更新信息
|
* @param param
|
* @return
|
*/
|
public String reSumNoticeOutComplete(NoticeParam param) {
|
if (StringUtils.isEmpty(param.getCustomerName())) {
|
return "客户编码为空!";
|
}
|
if (StringUtils.isEmpty(param.getFoodVariety())) {
|
return "粮食品种为空!";
|
}
|
if (StringUtils.isEmpty(param.getDepotId())) {
|
return "仓库编码为空!";
|
}
|
if (StringUtils.isEmpty(param.getCompanyId())) {
|
param.setCompanyId(ContextUtil.getCompanyId());
|
}
|
if (StringUtils.isEmpty(param.getDeptId())) {
|
param.setDeptId(ContextUtil.subDeptId(null));
|
}
|
noticeMapper.reSumNoticeOutComplete(param);
|
return null;
|
}
|
|
|
}
|