|
|
@@ -1,1232 +1,1239 @@
|
|
|
-package com.uas.platform.b2b.service.impl;
|
|
|
-
|
|
|
-import com.uas.platform.b2b.core.util.ContextUtils;
|
|
|
-import com.uas.platform.b2b.core.util.SplitArray;
|
|
|
-import com.uas.platform.b2b.core.util.ThreadTask;
|
|
|
-import com.uas.platform.b2b.dao.*;
|
|
|
-import com.uas.platform.b2b.erp.model.PurchaseNotify;
|
|
|
-import com.uas.platform.b2b.event.SaleSendAcceptReleaseEvent;
|
|
|
-import com.uas.platform.b2b.model.*;
|
|
|
-import com.uas.platform.b2b.ps.service.PersonalProductService;
|
|
|
-import com.uas.platform.b2b.search.SearchService;
|
|
|
-import com.uas.platform.b2b.service.PurchaseNoticeService;
|
|
|
-import com.uas.platform.b2b.service.UserService;
|
|
|
-import com.uas.platform.b2b.support.*;
|
|
|
-import com.uas.platform.core.exception.IllegalOperatorException;
|
|
|
-import com.uas.platform.core.logging.BufferedLoggerManager;
|
|
|
-import com.uas.platform.core.model.Constant;
|
|
|
-import com.uas.platform.core.model.PageInfo;
|
|
|
-import com.uas.platform.core.model.Status;
|
|
|
-import com.uas.platform.core.persistence.criteria.PredicateUtils;
|
|
|
-import com.uas.search.b2b.model.SPage;
|
|
|
-import org.apache.commons.collections.CollectionUtils;
|
|
|
-import org.springframework.beans.factory.annotation.Autowired;
|
|
|
-import org.springframework.data.domain.Page;
|
|
|
-import org.springframework.data.jpa.domain.Specification;
|
|
|
-import org.springframework.stereotype.Service;
|
|
|
-import org.springframework.transaction.annotation.Transactional;
|
|
|
-import org.springframework.util.StringUtils;
|
|
|
-
|
|
|
-import javax.persistence.criteria.CriteriaBuilder;
|
|
|
-import javax.persistence.criteria.CriteriaQuery;
|
|
|
-import javax.persistence.criteria.Predicate;
|
|
|
-import javax.persistence.criteria.Root;
|
|
|
-import java.math.BigDecimal;
|
|
|
-import java.text.SimpleDateFormat;
|
|
|
-import java.util.*;
|
|
|
-
|
|
|
-/**
|
|
|
- * 发货提醒
|
|
|
- *
|
|
|
- * @author US50
|
|
|
- */
|
|
|
-@Service
|
|
|
-public class PurchaseNoticeServiceImpl implements PurchaseNoticeService {
|
|
|
-
|
|
|
- private final static UsageBufferedLogger logger = BufferedLoggerManager.getLogger(UsageBufferedLogger.class);
|
|
|
-
|
|
|
- @Autowired
|
|
|
- private PurchaseNoticeDao purchaseNoticeDao;
|
|
|
-
|
|
|
- @Autowired
|
|
|
- private SaleSendDao saleSendDao;
|
|
|
-
|
|
|
- @Autowired
|
|
|
- private SaleSendItemDao saleSendItemDao;
|
|
|
-
|
|
|
- @Autowired
|
|
|
- private SaleSendAllDao saleSendAllDao;
|
|
|
-
|
|
|
- @Autowired
|
|
|
- private SaleSendItemVerifyDao saleSendItemVerifyDao;
|
|
|
-
|
|
|
- @Autowired
|
|
|
- private B2bCodeSetDao b2bCodeSetDao;
|
|
|
-
|
|
|
- @Autowired
|
|
|
- private BarPackageDao barPackageDao;
|
|
|
-
|
|
|
- @Autowired
|
|
|
- private BarSendNotifyDao barSendNotifyDao;
|
|
|
-
|
|
|
- @Autowired
|
|
|
- private BarPackageDetailDao barPackageDetailDao;
|
|
|
-
|
|
|
- @Autowired
|
|
|
- private CommonDao commonDao;
|
|
|
-
|
|
|
- @Autowired
|
|
|
- private BarLPSetingDao barLPSetingDao;
|
|
|
-
|
|
|
- @Autowired
|
|
|
- private SearchService searchService;
|
|
|
-
|
|
|
- @Autowired
|
|
|
- private DistributeDao distributeDao;
|
|
|
-
|
|
|
- @Autowired
|
|
|
- private RoleDao roleDao;
|
|
|
-
|
|
|
- @Autowired
|
|
|
- private UserOrderDao userOrderDao;
|
|
|
-
|
|
|
- @Autowired
|
|
|
- private UserDao userDao;
|
|
|
-
|
|
|
- @Autowired
|
|
|
- private VendorDao vendorDao;
|
|
|
-
|
|
|
- @Autowired
|
|
|
- private PersonalProductService personalProductService;
|
|
|
-
|
|
|
- @Autowired
|
|
|
- private PurchaseNoticeEndDao noticeEndDao;
|
|
|
-
|
|
|
- @Autowired
|
|
|
- private UserService userService;
|
|
|
-
|
|
|
- /**
|
|
|
- * 最多数量
|
|
|
- */
|
|
|
- final Integer MAX_SIZE = 1000;
|
|
|
-
|
|
|
- @Override
|
|
|
- public List<PurchaseNotice> save(List<PurchaseNotice> notices) {
|
|
|
- notices = purchaseNoticeDao.save(notices);
|
|
|
- saveUserOrders(notices);
|
|
|
- return notices;
|
|
|
- }
|
|
|
-
|
|
|
- private void saveUserOrders(final List<PurchaseNotice> notices) {
|
|
|
-
|
|
|
- ThreadTask.getInstance().execute(new Runnable() {
|
|
|
- @Override
|
|
|
- public void run() {
|
|
|
- /* 添加供应商的阅读记录*/
|
|
|
- for(PurchaseNotice notice : notices) {
|
|
|
- Set<Long> userUUs = new HashSet<>();
|
|
|
- // 添加管理员
|
|
|
- List<Role> roles = roleDao.findByEnUUAndIssys(notice.getVendUU(), Constant.YES);
|
|
|
- if (!CollectionUtils.isEmpty(roles)) {
|
|
|
- List<User> admins = userDao.findByRole(roles.get(0).getId());
|
|
|
- for (User admin : admins) {
|
|
|
- if (!userUUs.contains(admin.getUserUU())) {
|
|
|
- userUUs.add(admin.getUserUU());
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- List<Vendor> vendors = vendorDao.findByMyEnUUAndVendUU(notice.getEnUU(), notice.getVendUU());
|
|
|
- // 查找有权限的用户
|
|
|
- if (!CollectionUtils.isEmpty(vendors)) {
|
|
|
- Long vendorId = vendors.get(0).getId();
|
|
|
- List<Distribute> distributes = distributeDao.findByVendorId(vendorId);
|
|
|
- if (!CollectionUtils.isEmpty(distributes)) {
|
|
|
- for (Distribute distribute : distributes) {
|
|
|
- if (!userUUs.contains(distribute.getUserUU())) {
|
|
|
- userUUs.add(distribute.getUserUU());
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- UserOrders userOrders;
|
|
|
- List<UserOrders> list = new ArrayList<>();
|
|
|
- for (Long userUU : userUUs) {
|
|
|
- if (userUU == null) {
|
|
|
- continue;
|
|
|
- }
|
|
|
- userOrders = new UserOrders(userUU, notice.getVendUU(), notice.getId(), "sale", "purc$notice");
|
|
|
- list.add(userOrders);
|
|
|
- }
|
|
|
-
|
|
|
- /* 添加采购员的阅读记录*/
|
|
|
- if (notice.getOrderItem().getOrder().getUserUU() != null) {
|
|
|
- userOrders = new UserOrders(notice.getOrderItem().getOrder().getUserUU(), notice.getEnUU(), notice.getId(), "purc", "purc$notice");
|
|
|
- userOrders.setReadStatus((short) Status.READ.value());
|
|
|
- list.add(userOrders);
|
|
|
- }
|
|
|
- userOrderDao.save(list);
|
|
|
- }
|
|
|
- }
|
|
|
- });
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public Page<PurchaseNotice> findAllByPageInfo(final PageInfo pageInfo, final String keyword, final Long fromDate,
|
|
|
- final Long endDate, final SearchFilter filter) {
|
|
|
- return purchaseNoticeDao.findAll(new Specification<PurchaseNotice>() {
|
|
|
- @Override
|
|
|
- public Predicate toPredicate(Root<PurchaseNotice> root, CriteriaQuery<?> query, CriteriaBuilder builder) {
|
|
|
- if (filter != null) {
|
|
|
- if (!CollectionUtils.isEmpty(filter.getDistribute())) {
|
|
|
- pageInfo.expression(PredicateUtils.in("enUU", filter.getDistribute(), false));
|
|
|
- }
|
|
|
- }
|
|
|
- if (StringUtils.hasText(keyword)) {
|
|
|
- List<Object> lists = new ArrayList<>();
|
|
|
- List<PurchaseNotice> listss = searchService.searchPurchaseNoticeIds(keyword, null).getContent();
|
|
|
- for (PurchaseNotice list : listss) {
|
|
|
- lists.add(list.getId());
|
|
|
- }
|
|
|
- pageInfo.expression(PredicateUtils.in("id", lists, false));
|
|
|
- }
|
|
|
- if (fromDate != null) {
|
|
|
- pageInfo.expression(PredicateUtils.in("id", purchaseNoticeDao.findByFromDate(
|
|
|
- SystemSession.getUser().getEnterprise().getUu(), new Date(fromDate)), false));
|
|
|
- }
|
|
|
- if (endDate != null) {
|
|
|
- pageInfo.expression(PredicateUtils.in("id", purchaseNoticeDao
|
|
|
- .findByEndDate(SystemSession.getUser().getEnterprise().getUu(), new Date(endDate)), false));
|
|
|
- }
|
|
|
- return query.where(pageInfo.getPredicates(root, query, builder)).getRestriction();
|
|
|
- }
|
|
|
- }, pageInfo);
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public Page<PurchaseNotice> findDoneByPageInfo(final PageInfo pageInfo, final String keyword, final Long fromDate,
|
|
|
- final Long endDate) {
|
|
|
- return purchaseNoticeDao.findAll(new Specification<PurchaseNotice>() {
|
|
|
- @Override
|
|
|
- public Predicate toPredicate(Root<PurchaseNotice> root, CriteriaQuery<?> query, CriteriaBuilder builder) {
|
|
|
- pageInfo.filter("status", Status.REPLIED.value());
|
|
|
- pageInfo.expression(
|
|
|
- PredicateUtils.or(PredicateUtils.isNull("end"), PredicateUtils.ne("end", Constant.YES, false)));
|
|
|
- if (StringUtils.hasText(keyword)) {
|
|
|
- List<Object> lists = new ArrayList<>();
|
|
|
- List<PurchaseNotice> listss = searchService.searchPurchaseNoticeIds(keyword, null).getContent();
|
|
|
- for (PurchaseNotice list : listss) {
|
|
|
- lists.add(list.getId());
|
|
|
- }
|
|
|
- pageInfo.expression(PredicateUtils.in("id", lists, false));
|
|
|
- }
|
|
|
- if (fromDate != null) {
|
|
|
- pageInfo.expression(PredicateUtils.in("id", purchaseNoticeDao.findByFromDate(
|
|
|
- SystemSession.getUser().getEnterprise().getUu(), new Date(fromDate)), false));
|
|
|
- }
|
|
|
- if (endDate != null) {
|
|
|
- pageInfo.expression(PredicateUtils.in("id", purchaseNoticeDao
|
|
|
- .findByEndDate(SystemSession.getUser().getEnterprise().getUu(), new Date(endDate)), false));
|
|
|
- }
|
|
|
- return query.where(pageInfo.getPredicates(root, query, builder)).getRestriction();
|
|
|
- }
|
|
|
- }, pageInfo);
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public PurchaseNotice findById(Long id) {
|
|
|
- return purchaseNoticeDao.findOne(id);
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public void send(List<SaleSendItem> sendItems) {
|
|
|
- saleSendItemDao.save(sendItems);
|
|
|
- for (SaleSendItem item : sendItems) {
|
|
|
- if (item.getNoticeId() != null) {
|
|
|
- Double sendQty = saleSendItemDao.getSendQtyByNoticeId(item.getNoticeId());
|
|
|
- purchaseNoticeDao.updateBySend(item.getNoticeId(), sendQty);
|
|
|
- logger.log("更新发货提醒发货数量", "ERP主动收料通知单/上传发货单更新发货提醒已发货数量",
|
|
|
- "发货单: " + item.getNoticeId() + ",更新数量: " + sendQty);
|
|
|
- // 更新发货状态
|
|
|
- updateNoticeStatus(item.getNoticeId());
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public List<SaleSendItem> findSendById(long noticeId) {
|
|
|
- return saleSendItemDao.findByNoticeId(noticeId);
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public List<PurchaseNotice> findNotUploadNotice() {
|
|
|
- return purchaseNoticeDao.findByVendUUAndSendStatus(SystemSession.getUser().getEnterprise().getUu(),
|
|
|
- (short) Status.NOT_UPLOAD.value());
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public void onNoticeDownSuccess(String[] idArray) {
|
|
|
- for (String id : idArray) {
|
|
|
- PurchaseNotice notice = purchaseNoticeDao.findOne(Long.parseLong(id));
|
|
|
- if (notice != null) {
|
|
|
- notice.setSendStatus((short) Status.DOWNLOADED.value());
|
|
|
- purchaseNoticeDao.save(notice);
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public List<SaleSend> findNotUploadSend() {
|
|
|
- return saleSendDao.findByCustUUAndSendStatus(SystemSession.getUser().getEnterprise().getUu(),
|
|
|
- (short) Status.NOT_UPLOAD.value());
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public List<SaleSend> findNotUploadSendEDI(Long enUU) {
|
|
|
- return saleSendDao.findByCustUUAndSendStatus(enUU,
|
|
|
- (short) Status.NOT_UPLOAD.value());
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public List<SaleSend> findNotSendSend() {
|
|
|
- return saleSendDao.findByEnUUAndBackStatus(SystemSession.getUser().getEnterprise().getUu(),
|
|
|
- (short) Status.NOT_UPLOAD.value());
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public void onSendUploadSuccess(String[] idArray) {
|
|
|
- for (String id : idArray) {
|
|
|
- SaleSend send = saleSendDao.findOne(Long.parseLong(id));
|
|
|
- if (send != null) {
|
|
|
- send.setSendStatus((short) Status.DOWNLOADED.value());
|
|
|
- saleSendDao.save(send);
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public void onSendDownSuccess(String[] idArray) {
|
|
|
- for (String id : idArray) {
|
|
|
- SaleSend send = saleSendDao.findOne(Long.parseLong(id));
|
|
|
- if (send != null) {
|
|
|
- send.setBackStatus((short) Status.DOWNLOADED.value());
|
|
|
- saleSendDao.save(send);
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public void end(List<PurchaseNotify> notifies) {
|
|
|
- long enUU = SystemSession.getUser().getEnterprise().getUu();
|
|
|
- List<PurchaseNoticeEnd> noticeList = noticeEndDao.findByEnUUAndSourceIdList(enUU, CollectionUtil.getKeyCollection(notifies));
|
|
|
- if (!CollectionUtils.isEmpty(noticeList)) {
|
|
|
- for (PurchaseNoticeEnd notice : noticeList) {
|
|
|
- notice.setEnd(Constant.YES);
|
|
|
- notice.setEndStatus((short) Status.NOT_UPLOAD.value());
|
|
|
- notice.setErpDate(new Date(System.currentTimeMillis()));
|
|
|
- }
|
|
|
- }
|
|
|
- noticeEndDao.save(noticeList);
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public List<PurchaseNotice> findNotSendEnd() {
|
|
|
- return purchaseNoticeDao.findByVendUUAndEndStatus(SystemSession.getUser().getEnterprise().getUu(),
|
|
|
- (short) Status.NOT_UPLOAD.value());
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public void onEndDownSuccess(String[] idArray) {
|
|
|
- for (String id : idArray) {
|
|
|
- PurchaseNoticeEnd noticeEnd = noticeEndDao.findOne(Long.parseLong(id));
|
|
|
- if (noticeEnd != null) {
|
|
|
- noticeEnd.setEndStatus((short) Status.DOWNLOADED.value());
|
|
|
- noticeEndDao.save(noticeEnd);
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public SaleSend send(Long noticeId, SaleSend send) {
|
|
|
- PurchaseNotice notice = purchaseNoticeDao.findOne(noticeId);
|
|
|
- List<SaleSend> sends = saleSendDao.findByUuid(send.getUuid());
|
|
|
- //限制同一个供应商给同一个客户发货单号不可以重复,(避免一次发货产生多张单)
|
|
|
- if (notice != null && CollectionUtils.isEmpty(sends)) {
|
|
|
- if (notice.getEnd() != null && notice.getEnd() == Constant.YES) {
|
|
|
- throw new IllegalOperatorException("客户已经取消了本次送货提醒,请刷新重试!");
|
|
|
- }
|
|
|
- double thisQty = 0;
|
|
|
- for (SaleSendItem item : send.getSendItems()) {
|
|
|
- thisQty += item.getQty();
|
|
|
- }
|
|
|
- double endQty = (notice.getEndQty() == null ? 0.0 : notice.getEndQty()) + thisQty;
|
|
|
- if (endQty > notice.getQty()) {
|
|
|
- throw new IllegalOperatorException("累计发货数量将超出本次送货提醒的需求数!");
|
|
|
- }
|
|
|
- PurchaseOrder order = notice.getOrderItem().getOrder();
|
|
|
- send.setCurrency(order.getCurrency());
|
|
|
- send.setBackStatus((short) Status.NOT_UPLOAD.value());
|
|
|
- send.setSendStatus((short) Status.NOT_UPLOAD.value());
|
|
|
- // 未收料
|
|
|
- send.setVerifystatus(Constant.NO);
|
|
|
- send.setCustUU(notice.getEnUU());
|
|
|
- send.setCustUserUU(order.getUserUU());
|
|
|
- send.setDate(new Date());
|
|
|
- send.setEnUU(SystemSession.getUser().getEnterprise().getUu());
|
|
|
- send.setPayments(order.getPayments());
|
|
|
- send.setRate(order.getRate());
|
|
|
- send.setRecorder(SystemSession.getUser().getUserName());
|
|
|
- short number = 0;
|
|
|
- for (SaleSendItem item : send.getSendItems()) {
|
|
|
- item.setNoticeId(noticeId);
|
|
|
- item.setNotice(notice);
|
|
|
- item.setNumber(++number);
|
|
|
- item.setOrderItem(notice.getOrderItem());
|
|
|
- item.setOrderItemId(notice.getOrderItem().getId());
|
|
|
- item.setPrice(notice.getOrderItem().getPrice());
|
|
|
- item.setSend(send);
|
|
|
- }
|
|
|
- List<SaleSendItem> sendItems = saleSendItemDao.save(send.getSendItems());
|
|
|
- notice.setEndQty(endQty);
|
|
|
- notice.setStatus((short) (endQty == notice.getQty() ? Status.REPLIED.value() : Status.NOT_REPLY.value()));
|
|
|
- purchaseNoticeDao.save(notice);
|
|
|
- if (!CollectionUtils.isEmpty(sendItems)) {
|
|
|
- List<SaleSend> saleSends = new ArrayList<SaleSend>();
|
|
|
- saleSends.add(sendItems.get(0).getSend());
|
|
|
- }
|
|
|
- // 我的产品库更新
|
|
|
- personalProductService.covertPersonalProduct(notice.getOrderItem().getProductId(), "单个发货");
|
|
|
- return sendItems.get(0).getSend();
|
|
|
- } else {
|
|
|
- throw new IllegalOperatorException("请对有效的送货提醒发货!");
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public int getOnhandCount() {
|
|
|
- return purchaseNoticeDao.getCountByVendUUAndStatus(SystemSession.getUser().getEnterprise().getUu(),
|
|
|
- (short) Status.NOT_REPLY.value());
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public SaleSend send(SaleSend saleSend) {
|
|
|
- //限制同一个供应商给同一个客户发货单号不可以重复,(避免一次发货产生多张单),存在时不做处理
|
|
|
- List<SaleSend> sendList = saleSendDao.findByUuid(saleSend.getUuid());
|
|
|
- if (saleSend != null && CollectionUtils.isEmpty(sendList)) {
|
|
|
- saleSend.setBackStatus((short) Status.NOT_UPLOAD.value());
|
|
|
- saleSend.setSendStatus((short) Status.NOT_UPLOAD.value());
|
|
|
- saleSend.setEnUU(SystemSession.getUser().getEnterprise().getUu());
|
|
|
- saleSend.setRecorder(SystemSession.getUser().getUserName());
|
|
|
- saleSend.setDate(new Date());
|
|
|
- // 未收料
|
|
|
- saleSend.setVerifystatus(Constant.NO);
|
|
|
- short number = 0;
|
|
|
- List<SaleSendItem> sendItems = new ArrayList<SaleSendItem>();
|
|
|
- for (SaleSendItem item : saleSend.getSendItems()) {
|
|
|
- PurchaseNotice notice = purchaseNoticeDao.findOne(item.getNoticeId());
|
|
|
- if (notice != null) {
|
|
|
- if (notice.getEnd() != null && notice.getEnd() == Constant.YES) {
|
|
|
- String error = "货车中订单:" + notice.getOrderItem().getOrder().getCode() + "的物料号为"
|
|
|
- + notice.getOrderItem().getProduct().getCode() + "的发货通知被取消!";
|
|
|
- throw new IllegalOperatorException(error);
|
|
|
- } else {
|
|
|
- double thisQty = item.getQty();
|
|
|
- double endQty = (notice.getEndQty() == null ? 0.0 : notice.getEndQty()) + thisQty;
|
|
|
- if (endQty > notice.getQty()) {
|
|
|
- throw new IllegalOperatorException("累计发货数量将超出本次送货提醒的需求数!");
|
|
|
- }
|
|
|
- item.setNotice(notice);
|
|
|
- // 带了序号则不重设序号,不带这重设序号
|
|
|
- if (item.getNumber() == null || item.getNumber() == 0) {
|
|
|
- item.setNumber(++number);
|
|
|
- }
|
|
|
- item.setOrderItem(notice.getOrderItem());
|
|
|
- item.setOrderItemId(notice.getOrderItemId());
|
|
|
- saleSend.setRate(notice.getOrderItem().getOrder().getRate());
|
|
|
- item.setSend(saleSend);
|
|
|
- sendItems.add(item);
|
|
|
- }
|
|
|
- } else {
|
|
|
- throw new IllegalOperatorException("参数错误,无效的客户送货提醒单!");
|
|
|
- }
|
|
|
-
|
|
|
- }
|
|
|
- sendItems = saleSendItemDao.save(sendItems);
|
|
|
- for (SaleSendItem sendItem : sendItems) {
|
|
|
- PurchaseNotice notice = purchaseNoticeDao.findOne(sendItem.getNoticeId());
|
|
|
- double endQty = (notice.getEndQty() == null ? 0.0 : notice.getEndQty()) + sendItem.getQty();
|
|
|
- if (endQty > notice.getQty()) {
|
|
|
- throw new IllegalOperatorException("累计发货数量将超出本次送货提醒的需求数!");
|
|
|
- }
|
|
|
- notice.setEndQty(endQty);
|
|
|
- notice.setStatus(
|
|
|
- (short) (endQty == notice.getQty() ? Status.REPLIED.value() : Status.NOT_REPLY.value()));
|
|
|
- purchaseNoticeDao.save(notice);
|
|
|
- // 转入我的物料库
|
|
|
- personalProductService.covertPersonalProduct(notice.getOrderItem().getProductId(), "批量发货");
|
|
|
- }
|
|
|
- if (!CollectionUtils.isEmpty(sendItems)) {
|
|
|
- List<SaleSend> saleSends = new ArrayList<SaleSend>();
|
|
|
- saleSends.add(sendItems.get(0).getSend());
|
|
|
- }
|
|
|
- return sendItems.get(0).getSend();
|
|
|
- } else {
|
|
|
- throw new IllegalArgumentException();
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public void onSaleSendChange(List<SaleSendItem> sendItems) {
|
|
|
- for (SaleSendItem item : sendItems) {
|
|
|
- saleSendItemDao.updateByReply(item.getId(), item.getQty(), item.getReplyRemark());
|
|
|
- if (item.getNoticeId() != null) {
|
|
|
- Double sendQty = saleSendItemDao.getSendQtyByNoticeId(item.getNoticeId());
|
|
|
- purchaseNoticeDao.updateBySend(item.getNoticeId(), sendQty);
|
|
|
- logger.log("更新发货提醒发货数量", "ERP上传收料通知的确认数量更新发货提醒已发货数量",
|
|
|
- "发货单: " + item.getNoticeId() + ",更新数量: " + sendQty);
|
|
|
- updateNoticeStatus(item.getNoticeId());
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 更新发货提醒状态
|
|
|
- *
|
|
|
- * @param noticeId 发货提醒id
|
|
|
- */
|
|
|
- private void updateNoticeStatus(Long noticeId) {
|
|
|
- PurchaseNotice notice = purchaseNoticeDao.findOne(noticeId);
|
|
|
- if (notice.getEndQty() < notice.getQty() && notice.getStatus() == Status.REPLIED.value()) {
|
|
|
- purchaseNoticeDao.updateStatus(notice.getId(), (short) Status.NOT_REPLY.value());
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public List<PurchaseNotice> findById(Long[] ids) {
|
|
|
- return purchaseNoticeDao.findUnEndByIds(ids);
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public void onVerify(List<SaleSendItemVerify> verifies) {
|
|
|
- verifies = saleSendItemVerifyDao.save(verifies);
|
|
|
- List<SaleSendItem> saleSendItems = new ArrayList<>();
|
|
|
- for (SaleSendItemVerify verify : verifies) {
|
|
|
- saleSendItemDao.updateByVerify(verify.getSendItemId());
|
|
|
- updateVerifyStatus(verify.getSendItemId());
|
|
|
- SaleSendItem item = saleSendItemDao.findOne(verify.getSendItemId());
|
|
|
- saleSendItems.add(item);
|
|
|
- }
|
|
|
- // 买家收料之后给卖家发消息
|
|
|
- ContextUtils.publishEvent(new SaleSendAcceptReleaseEvent(SaleSendItem.distinct(saleSendItems)));
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public void unVerify(List<SaleSendItemVerify> verifies) {
|
|
|
- saleSendItemVerifyDao.delete(verifies);
|
|
|
- for (SaleSendItemVerify verify : verifies) {
|
|
|
- saleSendItemDao.updateByVerify(verify.getSendItemId());
|
|
|
- updateVerifyStatus(verify.getSendItemId());
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 更新发货单的收料状态
|
|
|
- *
|
|
|
- * @param sendItemId
|
|
|
- */
|
|
|
- private void updateVerifyStatus(Long sendItemId) {
|
|
|
- SaleSendItem sendItem = saleSendItemDao.findOne(sendItemId);
|
|
|
- int totalCount = saleSendItemDao.getTotalCountBySendId(sendItem.getSend().getId());
|
|
|
- int verifyCount = saleSendItemDao.getFullVerifyCountBySendId(sendItem.getSend().getId());
|
|
|
- if (verifyCount == totalCount) {
|
|
|
- sendItem.getSend().setVerifystatus(Constant.YES);
|
|
|
- } else {
|
|
|
- sendItem.getSend().setVerifystatus(Constant.NO);
|
|
|
- }
|
|
|
- saleSendItemDao.save(sendItem);
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public SaleSendAll findSaleSendById(Long id) {
|
|
|
- SaleSendAll send = saleSendAllDao.findOne(id);
|
|
|
- if (send == null) {
|
|
|
- throw new IllegalOperatorException("您查找的发货单不存在!");
|
|
|
- }
|
|
|
- return send;
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public Long getAllCount() {
|
|
|
- return purchaseNoticeDao.countByVendUU(SystemSession.getUser().getEnterprise().getUu());
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public Long getAllNoticeCountByEnUU(Long enUU) {
|
|
|
- return purchaseNoticeDao.getCountByEnUUAndStatus(enUU, (short) Status.REPLIED.value());
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public Long getTodoNoticeCountByEnUU(Long enUU) {
|
|
|
- return purchaseNoticeDao.getCountByEnUUAndStatus(enUU, (short) Status.NOT_REPLY.value());
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public Long getWatingNoticeCountByEnUU(Long enUU) {
|
|
|
- return purchaseNoticeDao.getWatingCountByEnUUAndStatus(enUU);
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public Long getEndNoticeCountByEnUU(Long enUU) {
|
|
|
- return purchaseNoticeDao.getEndCountByEnUUAndStatus(enUU);
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public void updateBarCode(Long id, Double packageQty, Double outBoxQty) {
|
|
|
- saleSendItemDao.updatePackageQty(id, packageQty, outBoxQty);
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- @Transactional(rollbackFor = Exception.class)
|
|
|
- public void generateBarcodes(Long id, List<SaleSendItem> sendItem, Long enUU) {
|
|
|
- SaleSend saleSend = saleSendDao.findOne(id);
|
|
|
- Long custUU = saleSend.getCustUU();
|
|
|
- // 获取条码生成规则,判断规则是否审核,已审核,根据规则拼接
|
|
|
- B2bCodeSet barcodeSet = b2bCodeSetDao.findByEnUUAndType(custUU, "BATCH");
|
|
|
- // 条码生成规则不为空,已审核
|
|
|
- if (barcodeSet != null) {
|
|
|
- if (!"AUDITED".equals(barcodeSet.getStatuscode())) {
|
|
|
- throw new IllegalOperatorException("请先审核条码生成规则!");
|
|
|
- }
|
|
|
- } else {
|
|
|
- throw new IllegalOperatorException("请先维护条码生成规则!");
|
|
|
- }
|
|
|
- // 是否维护包装箱生成规则
|
|
|
- B2bCodeSet outboxSet = b2bCodeSetDao.findByEnUUAndType(custUU, "PACK");
|
|
|
- if (outboxSet == null) {
|
|
|
- throw new IllegalOperatorException("请先维护外箱生成规则!");
|
|
|
- }
|
|
|
- String AUDITED_STATUS = "AUDITED";
|
|
|
- if (!AUDITED_STATUS.equals(outboxSet.getStatuscode())) {
|
|
|
- throw new IllegalOperatorException("请先审核外箱生成规则!");
|
|
|
- }
|
|
|
- for (SaleSendItem item : sendItem) {
|
|
|
- // 清空原有箱号,箱号明细,条码
|
|
|
- List<BarSendNotify> bsNotify = barSendNotifyDao.findBySiid(item.getId());
|
|
|
- for (BarSendNotify notify : bsNotify) {
|
|
|
- if (notify.getOutboxid() != null) {
|
|
|
- BarPackage barPackage = barPackageDao.findOne(notify.getOutboxid());
|
|
|
- if (barPackage != null) {
|
|
|
- barPackageDetailDao.delete(barPackage.getDetail());
|
|
|
- barPackageDao.delete(barPackage);
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- barSendNotifyDao.deleteAllBySiid(item.getId());
|
|
|
- // 获取明细,最小包装数,外箱容量等信息
|
|
|
- SaleSendItem sItem = saleSendItemDao.findOne(item.getId());
|
|
|
- double pQty = sItem.getPackageQty(), bQty = sItem.getOutBoxQty(), qty = sItem.getQty();
|
|
|
- String bar_code, pr_code = sItem.getOrderItem().getProduct().getCode();
|
|
|
- // 最小包装数件数
|
|
|
- int aNum = (int) (qty / pQty);
|
|
|
- double aqtyA = (new BigDecimal(Double.toString(qty))).subtract(new BigDecimal(Double.toString(aNum * pQty)))
|
|
|
- .doubleValue(); // 小于最小包装数的
|
|
|
- // ERP中对应的物料ID
|
|
|
- String sourceId = String.valueOf(sItem.getOrderItem().getProduct().getSourceId());
|
|
|
- // 获取是否勾选了生成外箱
|
|
|
- if (item.getIsOutboxChecked()) {
|
|
|
- // 判断外箱容量是否为最小包装数的整数倍
|
|
|
- String out_boxcode = null;
|
|
|
- Long pa_id = null;
|
|
|
- // 每箱件数
|
|
|
- int sumJ = (int) (bQty / pQty);
|
|
|
- if (sumJ * pQty != bQty) {
|
|
|
- throw new IllegalOperatorException("序号:" + sItem.getNumber() + ",外箱容量不是最小包装数的整数倍!");
|
|
|
- }
|
|
|
- // 整数箱数
|
|
|
- int bNum = (int) (qty / bQty);
|
|
|
- // 零散数
|
|
|
- double bqtyB = (new BigDecimal(Double.toString(qty)))
|
|
|
- .subtract(new BigDecimal(Double.toString(bNum * bQty))).doubleValue();
|
|
|
- if (aNum >= 1) {
|
|
|
- for (int i = 0; i < aNum; i++) {
|
|
|
- if (i % sumJ == 0) {
|
|
|
- BarPackage barPackage = new BarPackage();
|
|
|
- out_boxcode = outboxMethod(sourceId, outboxSet);
|
|
|
- barPackage.setCustUU(custUU);
|
|
|
- barPackage.setEnUU(enUU);
|
|
|
- barPackage.setOutboxcode(out_boxcode);
|
|
|
- barPackage.setProdcode(pr_code);
|
|
|
- barPackage.setLevel((long) 1);
|
|
|
- barPackage.setPackdate(new Date());
|
|
|
- barPackage.setSendStatus((short) Status.NOT_UPLOAD.value());
|
|
|
- if (i >= aNum - sumJ && bqtyB > 0) {
|
|
|
- barPackage.setPackageqty(aNum - sumJ);
|
|
|
- barPackage.setTotalqty(bqtyB);
|
|
|
- } else {
|
|
|
- barPackage.setPackageqty(sumJ);
|
|
|
- barPackage.setTotalqty(bQty);
|
|
|
- }
|
|
|
- barPackageDao.save(barPackage);
|
|
|
- barPackage = barPackageDao.findByOutboxcodeAndEnUU(out_boxcode, enUU);
|
|
|
- pa_id = barPackage.getId();
|
|
|
- }
|
|
|
- bar_code = barcodeMethod(sourceId, barcodeSet);
|
|
|
- insertBarPd(pa_id, out_boxcode, pQty, bar_code, sItem, enUU);
|
|
|
- }
|
|
|
- }
|
|
|
- if (aqtyA > 0) {
|
|
|
- bar_code = barcodeMethod(sourceId, barcodeSet);
|
|
|
- insertBarPd(pa_id, out_boxcode, aqtyA, bar_code, sItem, enUU);
|
|
|
- }
|
|
|
- logger.log("发货单", "生成条码和箱号",
|
|
|
- "发货单:" + sItem.getSend().getCode() + ",明细行序号:" + sItem.getNumber() + ",生成条码和箱号!");
|
|
|
- } else {
|
|
|
- if (aNum >= 1) {
|
|
|
- for (int i = 0; i < aNum; i++) {
|
|
|
- insertBar(sItem, pQty, enUU, barcodeSet);
|
|
|
- }
|
|
|
- }
|
|
|
- if (aqtyA > 0) {
|
|
|
- insertBar(sItem, aqtyA, enUU, barcodeSet);
|
|
|
- }
|
|
|
- logger.log("发货单", "生成条码",
|
|
|
- "发货单:" + sItem.getSend().getCode() + ",明细行序号:" + sItem.getNumber() + ",生成条码!");
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- private String lpad(int length, String number) {
|
|
|
- while (number.length() < length) {
|
|
|
- number = "0" + number;
|
|
|
- }
|
|
|
- number = number.substring(number.length() - length, number.length());
|
|
|
- return number;
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * YYMMDD 日期格式
|
|
|
- */
|
|
|
- final String YYMMDD_PATTERN = "YYMMDD";
|
|
|
-
|
|
|
- /**
|
|
|
- * YYMM日期格式
|
|
|
- */
|
|
|
- final String YYMM_PATTERN= "YYMM";
|
|
|
-
|
|
|
- /**
|
|
|
- * MMDD日期格式
|
|
|
- */
|
|
|
- final String MMDD_PATTERN = "MMDD";
|
|
|
-
|
|
|
- /**
|
|
|
- * 默认数量
|
|
|
- */
|
|
|
- final Integer NULL_COUNT = 0;
|
|
|
-
|
|
|
- /**
|
|
|
- * 生成条码号
|
|
|
- *
|
|
|
- * @param pr_id
|
|
|
- * @param barcodeSet
|
|
|
- * @return
|
|
|
- */
|
|
|
- public String barcodeMethod(String pr_id, B2bCodeSet barcodeSet) {
|
|
|
- StringBuffer code = new StringBuffer();
|
|
|
- String date = "0";
|
|
|
- String formPlat = barcodeSet.getFromplat(), dataStr = barcodeSet.getDatestr(),
|
|
|
- maxdate = barcodeSet.getMaxdate();
|
|
|
- int lennum = barcodeSet.getLennum().intValue(), maxnum = barcodeSet.getMaxnum().intValue(),
|
|
|
- lenprid = barcodeSet.getLenprid().intValue();
|
|
|
- // 拼接
|
|
|
- // 平台标识
|
|
|
- code.append(formPlat);
|
|
|
- // PR_ID物料ID的长度
|
|
|
- code.append(lpad(lenprid, pr_id));
|
|
|
- if (YYMMDD_PATTERN.equals(dataStr)) {
|
|
|
- SimpleDateFormat YMD = new SimpleDateFormat("yyMMdd");
|
|
|
- date = YMD.format(new Date());
|
|
|
- } else if (YYMM_PATTERN.equals(dataStr)) {
|
|
|
- SimpleDateFormat YM = new SimpleDateFormat("yyMM");
|
|
|
- date = YM.format(new Date());
|
|
|
- } else if (MMDD_PATTERN.equals(dataStr)) {
|
|
|
- SimpleDateFormat MD = new SimpleDateFormat("MMdd");
|
|
|
- date = MD.format(new Date());
|
|
|
- }
|
|
|
- code.append(date);
|
|
|
- barcodeSet.setMaxdate(date);
|
|
|
- // 如果当前日期大于上次日期
|
|
|
- if (!("").equals(maxdate) && null != maxdate && (!NULL_COUNT.equals(date))
|
|
|
- && (Integer.valueOf(maxdate) > Integer.valueOf(date))) {
|
|
|
- // 流水重新开始
|
|
|
- code.append(lpad(lennum, "1"));
|
|
|
- // 流水号增加1
|
|
|
- barcodeSet.setMaxnum((long) 2);
|
|
|
- } else {
|
|
|
- // 当前流水号
|
|
|
- code.append(lpad(lennum, String.valueOf(maxnum)));
|
|
|
- // 流水号增加1
|
|
|
- barcodeSet.setMaxnum((long) (maxnum + 1));
|
|
|
- }
|
|
|
- b2bCodeSetDao.save(barcodeSet);
|
|
|
- return code.toString();
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 生成外箱号
|
|
|
- *
|
|
|
- * @param pr_id
|
|
|
- * @param barcodeSet
|
|
|
- * @return
|
|
|
- */
|
|
|
- public String outboxMethod(String pr_id, B2bCodeSet barcodeSet) {
|
|
|
- StringBuffer code = new StringBuffer();
|
|
|
- String date = "0";
|
|
|
- String formPlat = barcodeSet.getFromplat(), dataStr = barcodeSet.getDatestr(),
|
|
|
- maxdate = barcodeSet.getMaxdate();
|
|
|
- int lennum = barcodeSet.getLennum().intValue(), maxnum = barcodeSet.getMaxnum().intValue(),
|
|
|
- lenprid = barcodeSet.getLenprid().intValue();
|
|
|
- // 平台标识
|
|
|
- code.append(formPlat);
|
|
|
- // PR_ID物料ID的长度
|
|
|
- code.append(lpad(lenprid, pr_id));
|
|
|
- if (YYMMDD_PATTERN.equals(dataStr)) {
|
|
|
- SimpleDateFormat YMD = new SimpleDateFormat("yyMMdd");
|
|
|
- date = YMD.format(new Date());
|
|
|
- } else if (YYMM_PATTERN.equals(dataStr)) {
|
|
|
- SimpleDateFormat YM = new SimpleDateFormat("yyMM");
|
|
|
- date = YM.format(new Date());
|
|
|
- } else if (MMDD_PATTERN.equals(dataStr)) {
|
|
|
- SimpleDateFormat MD = new SimpleDateFormat("MMdd");
|
|
|
- date = MD.format(new Date());
|
|
|
- }
|
|
|
- code.append(date);
|
|
|
- barcodeSet.setMaxdate(date);
|
|
|
- // 如果当前日期大于上次日期
|
|
|
- if (!("").equals(maxdate) && null != maxdate && (!NULL_COUNT.equals(date))
|
|
|
- && (Integer.valueOf(maxdate) > Integer.valueOf(date))) {
|
|
|
- // 流水重新开始
|
|
|
- code.append(lpad(lennum, "1"));
|
|
|
- // 流水号增加1
|
|
|
- barcodeSet.setMaxnum((long) 2);
|
|
|
- } else {
|
|
|
- // 当前流水号
|
|
|
- code.append(lpad(lennum, String.valueOf(maxnum)));
|
|
|
- // 流水号增加1
|
|
|
- barcodeSet.setMaxnum((long) (maxnum + 1));
|
|
|
- }
|
|
|
- b2bCodeSetDao.save(barcodeSet);
|
|
|
- return code.toString();
|
|
|
- }
|
|
|
-
|
|
|
- private void insertBarPd(Long pa_id, String out_boxcode, double qty, String bar_code, SaleSendItem sItem,
|
|
|
- Long enUU) {
|
|
|
- BarSendNotify barSendNotify = new BarSendNotify();
|
|
|
- barSendNotify.setBarcode(bar_code);
|
|
|
- barSendNotify.setOutboxcode(out_boxcode);
|
|
|
- barSendNotify.setOutboxid(pa_id);
|
|
|
- barSendNotify.setPrintstatus("0");
|
|
|
- barSendNotify.setProdcode(sItem.getOrderItem().getProduct().getCode());
|
|
|
- barSendNotify.setProdid(sItem.getOrderItem().getProduct().getSourceId());
|
|
|
- barSendNotify.setQty(qty);
|
|
|
- barSendNotify.setSendStatus((short) Status.NOT_UPLOAD.value());
|
|
|
- SaleSendItemAll sendItem = new SaleSendItemAll();
|
|
|
- sendItem.setId(sItem.getId());
|
|
|
- barSendNotify.setSaleSendItem(sendItem);
|
|
|
- barSendNotify.setSinumber(sItem.getNumber());
|
|
|
- barSendNotify.setSscode(sItem.getSend().getCode());
|
|
|
- barSendNotify.setSsid(sItem.getSend().getId());
|
|
|
- barSendNotify.setVendcode(enUU);
|
|
|
- // 保存发货单明细中的条码
|
|
|
- barSendNotifyDao.save(barSendNotify);
|
|
|
-
|
|
|
- BarPackageDetail barPackageDetail = new BarPackageDetail();
|
|
|
- barPackageDetail.setBarcode(bar_code);
|
|
|
- barPackageDetail.setBarpackage(barPackageDao.findOne(pa_id));
|
|
|
- barPackageDetail.setInnerqty(qty);
|
|
|
- // 保存包装箱明细
|
|
|
- barPackageDetailDao.save(barPackageDetail);
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 发货单明细条码明细生成
|
|
|
- *
|
|
|
- * @param sItem
|
|
|
- * @param qty
|
|
|
- * @param enUU
|
|
|
- * @param barcodeSet
|
|
|
- */
|
|
|
- private void insertBar(SaleSendItem sItem, double qty, Long enUU, B2bCodeSet barcodeSet) {
|
|
|
- BarSendNotify barSendNotify = new BarSendNotify();
|
|
|
- String bar_code = barcodeMethod(String.valueOf(sItem.getOrderItem().getProductId()), barcodeSet);
|
|
|
- barSendNotify.setBarcode(bar_code);
|
|
|
- barSendNotify.setPrintstatus("0");
|
|
|
- barSendNotify.setProdcode(sItem.getOrderItem().getProduct().getCode());
|
|
|
- barSendNotify.setProdid(sItem.getOrderItem().getProduct().getSourceId());
|
|
|
- barSendNotify.setQty(qty);
|
|
|
- barSendNotify.setSendStatus((short) Status.NOT_UPLOAD.value());
|
|
|
- SaleSendItemAll sendItem = new SaleSendItemAll();
|
|
|
- sendItem.setId(sItem.getId());
|
|
|
- barSendNotify.setSaleSendItem(sendItem);
|
|
|
- barSendNotify.setSinumber(sItem.getNumber());
|
|
|
- barSendNotify.setSscode(sItem.getSend().getCode());
|
|
|
- barSendNotify.setSsid(sItem.getSend().getId());
|
|
|
- barSendNotify.setVendcode(enUU);
|
|
|
- // 保存发货单明细中的条码
|
|
|
- barSendNotifyDao.save(barSendNotify);
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public List<Map<String, Object>> getPrintBarcodes(Long lpsId, List<SaleSendItem> sendItem, Long enUU) {
|
|
|
- List<Map<String, Object>> list2 = new ArrayList<Map<String, Object>>();
|
|
|
- String va = "";
|
|
|
- String regex = "\\{(?:[A-Za-z][A-Za-z0-9_]*)\\}";
|
|
|
- BarLabelPrintSetting setting = barLPSetingDao.findOne(lpsId);
|
|
|
- // 获取打印明细的设置参数
|
|
|
- List<Map<String, Object>> parameter = commonDao.queryForList(
|
|
|
- "select la_pagesize, lp_id,lp_valuetype,lp_encode,lp_name,lp_leftrate,lp_toprate,lp_width,lp_ifshownote,lp_font,lp_size,lp_notealignjustify,lp_height from bar$labelParameter left join bar$label on la_id=lp_laid where la_id="
|
|
|
- + setting.getLabel().getId());
|
|
|
- for (SaleSendItem item : sendItem) {
|
|
|
- List<BarSendNotify> bars = barSendNotifyDao.findBySiid(item.getId());
|
|
|
- List<Map<String, Object>> list = new ArrayList<Map<String, Object>>();
|
|
|
- for (BarSendNotify barcode : bars) {
|
|
|
- List<Map<String, Object>> list1 = new ArrayList<Map<String, Object>>();
|
|
|
- Map<String, Object> mp1 = new HashMap<String, Object>();
|
|
|
- va = setting.getSql().replaceAll(regex, String.valueOf(barcode.getId()));
|
|
|
- List<Map<String, Object>> listData = commonDao.queryForList(va);
|
|
|
- for (Map<String, Object> mapD : listData) {
|
|
|
- for (Map<String, Object> param : parameter) {
|
|
|
- mp1 = param;
|
|
|
- mp1.put("value", mapD.get(param.get("lp_name")));
|
|
|
- list1.add(mp1);
|
|
|
- }
|
|
|
- }
|
|
|
- Map<String, Object> mp = new HashMap<String, Object>();
|
|
|
- mp.put("store", list1);
|
|
|
- list.add(mp);
|
|
|
- }
|
|
|
- Map<String, Object> mp = new HashMap<String, Object>();
|
|
|
- mp.put("si_id", item.getId());
|
|
|
- mp.put("pagesize", parameter.get(0).get("la_pagesize"));
|
|
|
- mp.put("data", list);
|
|
|
- list2.add(mp);
|
|
|
- }
|
|
|
- return list2;
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public List<BarLabelPrintSetting> getPrintTemplate(Long id, String type) {
|
|
|
- SaleSend saleSend = saleSendDao.findOne(id);
|
|
|
- Long custUU = saleSend.getCustUU();
|
|
|
- String caller;
|
|
|
- String BAR_TYPE = "Bar";
|
|
|
- if (BAR_TYPE.equals(type)) {
|
|
|
- caller = "B2B!BarPrint";
|
|
|
- } else {
|
|
|
- caller = "B2B!OutBoxPrint";
|
|
|
- }
|
|
|
- List<BarLabelPrintSetting> setting = barLPSetingDao.findByEnUUAndCaller(custUU, caller);
|
|
|
- if (setting.size() > 0) {
|
|
|
- return setting;
|
|
|
- } else {
|
|
|
- throw new IllegalOperatorException("未维护相关的打印模板!");
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public List<Map<String, Object>> getSPrintBarcode(Long lpsId, Long bsnId) {
|
|
|
- List<Map<String, Object>> list = new ArrayList<Map<String, Object>>();
|
|
|
- String va = "";
|
|
|
- String regex = "\\{(?:[A-Za-z][A-Za-z0-9_]*)\\}";
|
|
|
- BarLabelPrintSetting setting = barLPSetingDao.findOne(lpsId);
|
|
|
- // 获取打印明细的设置参数
|
|
|
- List<Map<String, Object>> parameter = commonDao.queryForList(
|
|
|
- "select la_pagesize, lp_id,lp_valuetype,lp_encode,lp_name,lp_leftrate,lp_toprate,lp_width,lp_ifshownote,lp_font,lp_size,lp_notealignjustify,lp_height from bar$labelParameter left join bar$label on la_id=lp_laid where la_id="
|
|
|
- + setting.getLabel().getId());
|
|
|
- Map<String, Object> map = new HashMap<String, Object>();
|
|
|
- va = setting.getSql().replaceAll(regex, String.valueOf(bsnId));
|
|
|
- List<Map<String, Object>> listData = commonDao.queryForList(va);
|
|
|
- for (Map<String, Object> mapD : listData) {
|
|
|
- for (Map<String, Object> param : parameter) {
|
|
|
- map = param;
|
|
|
- map.put("value", mapD.get(param.get("lp_name")));
|
|
|
- list.add(map);
|
|
|
- }
|
|
|
- }
|
|
|
- return list;
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public void updatePrintStatus(List<SaleSendItem> saleSendItems) {
|
|
|
- List<SaleSendItem> items = new ArrayList<SaleSendItem>();
|
|
|
- if (!CollectionUtils.isEmpty(saleSendItems)) {
|
|
|
- for (SaleSendItem item : saleSendItems) {
|
|
|
- item = saleSendItemDao.findOne(item.getId());
|
|
|
- if (item != null) {
|
|
|
- item.setBarPrintStatus((long) 1);
|
|
|
- items.add(item);
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- saleSendItemDao.save(items);
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public void printCount(Long id) {
|
|
|
- SaleSendAll send = saleSendAllDao.findOne(id);
|
|
|
- if (null == send.getPrint()) {
|
|
|
- send.setPrint((short) 1);
|
|
|
- } else {
|
|
|
- send.setPrint((short) (send.getPrint() + 1));
|
|
|
- }
|
|
|
- saleSendAllDao.save(send);
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public Map<String, Integer> getNoticeCount(String category) {
|
|
|
- List<Long> unreadIds = getUnreadIds(category);
|
|
|
- Map<String, Integer> map = new HashMap<>(3);
|
|
|
- // 已回复数量
|
|
|
- Integer repliedCount = 0;
|
|
|
- // 未回复数量
|
|
|
- Integer notReplyCount = 0;
|
|
|
- if (CollectionUtils.isEmpty(unreadIds)){
|
|
|
- return map;
|
|
|
- }
|
|
|
- // 超过1000条需要拆分,不然会报错
|
|
|
- if (unreadIds.size() > MAX_SIZE) {
|
|
|
- List<List<Long>> idsArray = SplitArray.splitAry(unreadIds, SplitArray.QUERY_MAX_NUMBER);
|
|
|
- for (List<Long> ids : idsArray) {
|
|
|
- // 超过100不再查询,页面显示99+,减少服务器负担
|
|
|
- if (repliedCount < 100) {
|
|
|
- repliedCount = repliedCount + purchaseNoticeDao.findRepliedId(ids).size();
|
|
|
- }
|
|
|
- if (notReplyCount < 100) {
|
|
|
- notReplyCount = notReplyCount + purchaseNoticeDao.findNotReplyId(ids).size();
|
|
|
- }
|
|
|
- // 当需要查询的数量大于99时停止循环,减少不必要的操作
|
|
|
- if (notReplyCount > 99 && repliedCount > 99) {
|
|
|
- break;
|
|
|
- }
|
|
|
- }
|
|
|
- } else {
|
|
|
- repliedCount = repliedCount + purchaseNoticeDao.findRepliedId(unreadIds).size();
|
|
|
- notReplyCount = notReplyCount + purchaseNoticeDao.findNotReplyId(unreadIds).size();
|
|
|
- }
|
|
|
- map.put("replied", repliedCount);
|
|
|
- map.put("notReply", notReplyCount);
|
|
|
- map.put("all", repliedCount + notReplyCount);
|
|
|
- return map;
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public SPage<PurchaseNotice> findDoneNoticesByPageInfo(final PageInfo pageInfo, String keyword, final SearchFilter filter) {
|
|
|
- Page<PurchaseNotice> notices = purchaseNoticeDao.findAll(new Specification<PurchaseNotice>() {
|
|
|
- @Override
|
|
|
- public Predicate toPredicate(Root<PurchaseNotice> root, CriteriaQuery<?> query, CriteriaBuilder builder) {
|
|
|
- if (filter != null) {
|
|
|
- if (!CollectionUtils.isEmpty(filter.getDistribute())) {
|
|
|
- pageInfo.expression(PredicateUtils.in("enUU", filter.getDistribute(), false));
|
|
|
- }
|
|
|
- if (filter.getFromDate() != null) {
|
|
|
- pageInfo.expression(PredicateUtils.gte("date", new Date(filter.getFromDate()), false));
|
|
|
- }
|
|
|
- if (filter.getEndDate() != null) {
|
|
|
- pageInfo.expression(PredicateUtils.lte("date", new Date(filter.getEndDate()), false));
|
|
|
- }
|
|
|
- }
|
|
|
- pageInfo.expression(
|
|
|
- PredicateUtils.or(PredicateUtils.isNull("end"), PredicateUtils.ne("end", Constant.YES, false)));
|
|
|
- return query.where(pageInfo.getPredicates(root, query, builder)).getRestriction();
|
|
|
- }
|
|
|
- }, pageInfo);
|
|
|
- return SPageUtils.covertSPage(notices);
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 查询未阅读数量
|
|
|
- *
|
|
|
- * @param category 表名
|
|
|
- * @return
|
|
|
- */
|
|
|
- @Override
|
|
|
- public List<Long> getUnreadIds(String category) {
|
|
|
- return userOrderDao.getUnreadIds(SystemSession.getUser().getEnterprise().getUu(), SystemSession.getUser().getUserUU(), "purc$notice", category);
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 查询发货提醒
|
|
|
- *
|
|
|
- * @param pageInfo 分页信息
|
|
|
- * @param keyword 关键字
|
|
|
- * @param filter 过滤条件
|
|
|
- * @return
|
|
|
- */
|
|
|
- @Override
|
|
|
- public SPage<PurchaseNotice> findAllNoticesByPageInfo(final PageInfo pageInfo, String keyword, final SearchFilter filter) {
|
|
|
- if (filter != null) {
|
|
|
- if (!CollectionUtils.isEmpty(filter.getDistribute())) {
|
|
|
- pageInfo.expression(PredicateUtils.in("enUU", filter.getDistribute(), false));
|
|
|
- }
|
|
|
- if (filter.getFromDate() != null) {
|
|
|
- pageInfo.expression(PredicateUtils.gte("date", new Date(filter.getFromDate()), false));
|
|
|
- }
|
|
|
- if (filter.getEndDate() != null) {
|
|
|
- pageInfo.expression(PredicateUtils.lte("date", new Date(filter.getEndDate()), false));
|
|
|
- }
|
|
|
- }
|
|
|
- pageInfo.expression(PredicateUtils.isNull("end"));
|
|
|
- Page<PurchaseNotice> notices = purchaseNoticeDao.findAll(new Specification<PurchaseNotice>() {
|
|
|
- @Override
|
|
|
- public Predicate toPredicate(Root<PurchaseNotice> root, CriteriaQuery<?> query, CriteriaBuilder builder) {
|
|
|
- List<Predicate> predicatesList = new ArrayList<Predicate>();
|
|
|
- if (!StringUtils.isEmpty(keyword)) {
|
|
|
- Predicate custName = builder.like(root.get("orderItem").get("order").get("enterprise").get("enName"), "%" + keyword+ "%");
|
|
|
- if (keyword.matches(SearchUtils.UU_REGEXP)) {
|
|
|
- Predicate custUU = builder.like(root.get("orderItem").get("order").get("enterprise").get("uu"), "%" + keyword+ "%");
|
|
|
- builder.or(custUU);
|
|
|
- }
|
|
|
- Predicate productCode = builder.like(root.get("orderItem").get("productCode"), "%" + keyword+ "%");
|
|
|
- Predicate productTitle = builder.like(root.get("orderItem").get("productTitle"), "%" + keyword+ "%");
|
|
|
- Predicate productSpec = builder.like(root.get("orderItem").get("productSpec"), "%" + keyword+ "%");
|
|
|
- Predicate orderCode = builder.like(root.get("orderItem").get("order").get("code"), "%" + keyword+ "%");
|
|
|
- predicatesList.add(builder.or(custName, productCode, productTitle, productSpec, orderCode));
|
|
|
- }
|
|
|
- Predicate[] predicates = pageInfo.getPredicates(root, query, builder);
|
|
|
- Arrays.stream(predicates).forEach(predicate -> {
|
|
|
- predicatesList.add(predicate);
|
|
|
- });
|
|
|
- return builder.and(predicatesList.toArray(new Predicate[predicatesList.size()]));
|
|
|
- }
|
|
|
- }, pageInfo);
|
|
|
- return SPageUtils.covertSPage(notices);
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 按条件查询发货提醒
|
|
|
- *
|
|
|
- * @param pageInfo 分页信息,过滤条件
|
|
|
- * @param keyword 搜索词
|
|
|
- * @param filter 过滤条件
|
|
|
- * @param state 状态
|
|
|
- * @return SPage封装的数据
|
|
|
- */
|
|
|
- @Override
|
|
|
- public SPage<PurchaseNotice> findNoticesByPageInfo(PageInfo pageInfo, String keyword, SearchFilter filter, String state) {
|
|
|
- // 根据状态设置其他条件
|
|
|
- setState(pageInfo, state, filter);
|
|
|
- if (filter != null) {
|
|
|
- if (!CollectionUtils.isEmpty(filter.getDistribute())) {
|
|
|
- pageInfo.expression(PredicateUtils.in("enUU", filter.getDistribute(), false));
|
|
|
- }
|
|
|
- if (filter.getFromDate() != null) {
|
|
|
- pageInfo.expression(PredicateUtils.gte("date", new Date(filter.getFromDate()), false));
|
|
|
- }
|
|
|
- if (filter.getEndDate() != null) {
|
|
|
- pageInfo.expression(PredicateUtils.lte("date", new Date(filter.getEndDate()), false));
|
|
|
- }
|
|
|
- }
|
|
|
- Page<PurchaseNotice> notices = purchaseNoticeDao.findAll(new Specification<PurchaseNotice>() {
|
|
|
- @Override
|
|
|
- public Predicate toPredicate(Root<PurchaseNotice> root, CriteriaQuery<?> query, CriteriaBuilder builder) {
|
|
|
- List<Predicate> predicatesList = new ArrayList<Predicate>();
|
|
|
- if (!StringUtils.isEmpty(keyword)) {
|
|
|
- Predicate custName = builder.like(root.get("orderItem").get("order").get("enterprise").get("enName"), "%" + keyword+ "%");
|
|
|
- if (keyword.matches(SearchUtils.UU_REGEXP)) {
|
|
|
- Predicate custUU = builder.like(root.get("orderItem").get("order").get("enterprise").get("uu"), "%" + keyword+ "%");
|
|
|
- builder.or(custUU);
|
|
|
- }
|
|
|
- Predicate productCode = builder.like(root.get("orderItem").get("productCode"), "%" + keyword+ "%");
|
|
|
- Predicate productTitle = builder.like(root.get("orderItem").get("productTitle"), "%" + keyword+ "%");
|
|
|
- Predicate productSpec = builder.like(root.get("orderItem").get("productSpec"), "%" + keyword+ "%");
|
|
|
- Predicate orderCode = builder.like(root.get("orderItem").get("order").get("code"), "%" + keyword+ "%");
|
|
|
- predicatesList.add(builder.or(custName, productCode, productTitle, productSpec, orderCode));
|
|
|
- }
|
|
|
- Predicate[] predicates = pageInfo.getPredicates(root, query, builder);
|
|
|
- Arrays.stream(predicates).forEach(predicate -> {
|
|
|
- predicatesList.add(predicate);
|
|
|
- });
|
|
|
- return builder.and(predicatesList.toArray(new Predicate[predicatesList.size()]));
|
|
|
- }
|
|
|
- }, pageInfo);
|
|
|
- return SPageUtils.covertSPage(notices);
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 封装相关查询条件
|
|
|
- *
|
|
|
- * @param pageInfo 分页参数
|
|
|
- * @param state 状态
|
|
|
- * <pre>
|
|
|
- * _todo : 待发货
|
|
|
- * done: 已发货
|
|
|
- * end: 已取消
|
|
|
- * </pre>
|
|
|
- * @param filter 过滤条件
|
|
|
- */
|
|
|
- private void setState(PageInfo pageInfo, String state, SearchFilter filter) {
|
|
|
- pageInfo.filter("vendUU", SystemSession.getUser().getEnterprise().getUu());
|
|
|
- SearchFilter distribute = userService.distribute();
|
|
|
- if (distribute != null && !CollectionUtils.isEmpty(distribute.getDistribute())) {
|
|
|
- List<Object> list = new ArrayList<>();
|
|
|
- list.addAll(distribute.getDistribute());
|
|
|
- filter.setDistribute(list);
|
|
|
- }
|
|
|
- if (SearchUtils.TODO_STATE.equals(state)) {
|
|
|
- pageInfo.expression(PredicateUtils.or(PredicateUtils.isNull("end"), PredicateUtils.eq("end", Constant.NO, false)));
|
|
|
- pageInfo.filter("status", (short)Status.NOT_REPLY.value());
|
|
|
- pageInfo.filter("waiting", Constant.NO);
|
|
|
- } else if (SearchUtils.DONE_STATE.equals(state)) {
|
|
|
- pageInfo.expression(PredicateUtils.or(PredicateUtils.isNull("end"), PredicateUtils.eq("end", Constant.NO, false)));
|
|
|
- pageInfo.filter("status", (short)Status.REPLIED.value());
|
|
|
- } else if (SearchUtils.END_STATE.equals(state)) {
|
|
|
- pageInfo.filter("end", Constant.YES);
|
|
|
- } else if (SearchUtils.WAITING_STATE.equals(state)) {
|
|
|
- pageInfo.filter("waiting", Constant.YES);
|
|
|
- pageInfo.expression(PredicateUtils.or(PredicateUtils.isNull("end"), PredicateUtils.eq("end", Constant.NO, false)));
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- @Transactional(rollbackFor = Exception.class)
|
|
|
- public void setReadByOrder(String category, Long[] sourceId) {
|
|
|
- userOrderDao.setReadStatus(SystemSession.getUser().getEnterprise().getUu(), SystemSession.getUser().getUserUU(), "purc$notice", category, (short) Status.READ.value(), sourceId);
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- @Transactional(rollbackFor = Exception.class)
|
|
|
- public Integer setReadByState(String category) {
|
|
|
- List<Long> unreadIds = getUnreadIds(category);
|
|
|
- Integer deleteCount = 0;
|
|
|
- if (CollectionUtils.isEmpty(unreadIds)){
|
|
|
- return deleteCount;
|
|
|
- }
|
|
|
- List<Long> repliedIds = null;
|
|
|
- if (unreadIds.size() > MAX_SIZE) {
|
|
|
- List<List<Long>> idsArray = SplitArray.splitAry(unreadIds, SplitArray.QUERY_MAX_NUMBER);
|
|
|
- for (List<Long> ids : idsArray) {
|
|
|
- repliedIds = purchaseNoticeDao.findRepliedId(ids);
|
|
|
- if (repliedIds.size() != 0) {
|
|
|
- deleteCount = deleteCount + userOrderDao.delete(SystemSession.getUser().getEnterprise().getUu(),
|
|
|
- SystemSession.getUser().getUserUU(), "purc$notice", category, repliedIds.toArray(new Long[repliedIds.size()]));
|
|
|
- }
|
|
|
- }
|
|
|
- } else {
|
|
|
- repliedIds = purchaseNoticeDao.findRepliedId(unreadIds);
|
|
|
- if (repliedIds.size() != 0) {
|
|
|
- deleteCount = deleteCount + userOrderDao.delete(SystemSession.getUser().getEnterprise().getUu(),
|
|
|
- SystemSession.getUser().getUserUU(), "purc$notice", category, repliedIds.toArray(new Long[repliedIds.size()]));
|
|
|
- }
|
|
|
- }
|
|
|
- return deleteCount;
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 通过ids查询发货信息
|
|
|
- *
|
|
|
- * @param ids
|
|
|
- * @return
|
|
|
- */
|
|
|
- @Override
|
|
|
- public List<PurchaseNotice> findByIds(List<Long> ids) {
|
|
|
- return purchaseNoticeDao.findAll(ids);
|
|
|
- }
|
|
|
-}
|
|
|
+package com.uas.platform.b2b.service.impl;
|
|
|
+
|
|
|
+import com.uas.platform.b2b.core.util.ContextUtils;
|
|
|
+import com.uas.platform.b2b.core.util.SplitArray;
|
|
|
+import com.uas.platform.b2b.core.util.ThreadTask;
|
|
|
+import com.uas.platform.b2b.dao.*;
|
|
|
+import com.uas.platform.b2b.erp.model.PurchaseNotify;
|
|
|
+import com.uas.platform.b2b.event.SaleSendAcceptReleaseEvent;
|
|
|
+import com.uas.platform.b2b.model.*;
|
|
|
+import com.uas.platform.b2b.ps.service.PersonalProductService;
|
|
|
+import com.uas.platform.b2b.search.SearchService;
|
|
|
+import com.uas.platform.b2b.service.PurchaseNoticeService;
|
|
|
+import com.uas.platform.b2b.service.UserService;
|
|
|
+import com.uas.platform.b2b.support.*;
|
|
|
+import com.uas.platform.core.exception.IllegalOperatorException;
|
|
|
+import com.uas.platform.core.logging.BufferedLoggerManager;
|
|
|
+import com.uas.platform.core.model.Constant;
|
|
|
+import com.uas.platform.core.model.PageInfo;
|
|
|
+import com.uas.platform.core.model.Status;
|
|
|
+import com.uas.platform.core.persistence.criteria.PredicateUtils;
|
|
|
+import com.uas.search.b2b.model.SPage;
|
|
|
+import org.apache.commons.collections.CollectionUtils;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.data.domain.Page;
|
|
|
+import org.springframework.data.jpa.domain.Specification;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+import org.springframework.transaction.annotation.Transactional;
|
|
|
+import org.springframework.util.StringUtils;
|
|
|
+
|
|
|
+import javax.persistence.criteria.CriteriaBuilder;
|
|
|
+import javax.persistence.criteria.CriteriaQuery;
|
|
|
+import javax.persistence.criteria.Predicate;
|
|
|
+import javax.persistence.criteria.Root;
|
|
|
+import java.math.BigDecimal;
|
|
|
+import java.text.SimpleDateFormat;
|
|
|
+import java.util.*;
|
|
|
+
|
|
|
+/**
|
|
|
+ * 发货提醒
|
|
|
+ *
|
|
|
+ * @author US50
|
|
|
+ */
|
|
|
+@Service
|
|
|
+public class PurchaseNoticeServiceImpl implements PurchaseNoticeService {
|
|
|
+
|
|
|
+ private final static UsageBufferedLogger logger = BufferedLoggerManager.getLogger(UsageBufferedLogger.class);
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private PurchaseNoticeDao purchaseNoticeDao;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private SaleSendDao saleSendDao;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private SaleSendItemDao saleSendItemDao;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private SaleSendAllDao saleSendAllDao;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private SaleSendItemVerifyDao saleSendItemVerifyDao;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private B2bCodeSetDao b2bCodeSetDao;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private BarPackageDao barPackageDao;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private BarSendNotifyDao barSendNotifyDao;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private BarPackageDetailDao barPackageDetailDao;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private CommonDao commonDao;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private BarLPSetingDao barLPSetingDao;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private SearchService searchService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private DistributeDao distributeDao;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private RoleDao roleDao;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private UserOrderDao userOrderDao;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private UserDao userDao;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private VendorDao vendorDao;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private PersonalProductService personalProductService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private PurchaseNoticeEndDao noticeEndDao;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private EnterpriseDao enterpriseDao;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private UserService userService;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 最多数量
|
|
|
+ */
|
|
|
+ final Integer MAX_SIZE = 1000;
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public List<PurchaseNotice> save(List<PurchaseNotice> notices) {
|
|
|
+ notices = purchaseNoticeDao.save(notices);
|
|
|
+ saveUserOrders(notices);
|
|
|
+ return notices;
|
|
|
+ }
|
|
|
+
|
|
|
+ private void saveUserOrders(final List<PurchaseNotice> notices) {
|
|
|
+
|
|
|
+ ThreadTask.getInstance().execute(new Runnable() {
|
|
|
+ @Override
|
|
|
+ public void run() {
|
|
|
+ /* 添加供应商的阅读记录*/
|
|
|
+ for(PurchaseNotice notice : notices) {
|
|
|
+ Set<Long> userUUs = new HashSet<>();
|
|
|
+ // 添加管理员
|
|
|
+ List<Role> roles = roleDao.findByEnUUAndIssys(notice.getVendUU(), Constant.YES);
|
|
|
+ if (!CollectionUtils.isEmpty(roles)) {
|
|
|
+ List<User> admins = userDao.findByRole(roles.get(0).getId());
|
|
|
+ for (User admin : admins) {
|
|
|
+ if (!userUUs.contains(admin.getUserUU())) {
|
|
|
+ userUUs.add(admin.getUserUU());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ List<Vendor> vendors = vendorDao.findByMyEnUUAndVendUU(notice.getEnUU(), notice.getVendUU());
|
|
|
+ // 查找有权限的用户
|
|
|
+ if (!CollectionUtils.isEmpty(vendors)) {
|
|
|
+ Long vendorId = vendors.get(0).getId();
|
|
|
+ List<Distribute> distributes = distributeDao.findByVendorId(vendorId);
|
|
|
+ if (!CollectionUtils.isEmpty(distributes)) {
|
|
|
+ for (Distribute distribute : distributes) {
|
|
|
+ if (!userUUs.contains(distribute.getUserUU())) {
|
|
|
+ userUUs.add(distribute.getUserUU());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ UserOrders userOrders;
|
|
|
+ List<UserOrders> list = new ArrayList<>();
|
|
|
+ for (Long userUU : userUUs) {
|
|
|
+ if (userUU == null) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ userOrders = new UserOrders(userUU, notice.getVendUU(), notice.getId(), "sale", "purc$notice");
|
|
|
+ list.add(userOrders);
|
|
|
+ }
|
|
|
+
|
|
|
+ /* 添加采购员的阅读记录*/
|
|
|
+ if (notice.getOrderItem().getOrder().getUserUU() != null) {
|
|
|
+ userOrders = new UserOrders(notice.getOrderItem().getOrder().getUserUU(), notice.getEnUU(), notice.getId(), "purc", "purc$notice");
|
|
|
+ userOrders.setReadStatus((short) Status.READ.value());
|
|
|
+ list.add(userOrders);
|
|
|
+ }
|
|
|
+ userOrderDao.save(list);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Page<PurchaseNotice> findAllByPageInfo(final PageInfo pageInfo, final String keyword, final Long fromDate,
|
|
|
+ final Long endDate, final SearchFilter filter) {
|
|
|
+ return purchaseNoticeDao.findAll(new Specification<PurchaseNotice>() {
|
|
|
+ @Override
|
|
|
+ public Predicate toPredicate(Root<PurchaseNotice> root, CriteriaQuery<?> query, CriteriaBuilder builder) {
|
|
|
+ if (filter != null) {
|
|
|
+ if (!CollectionUtils.isEmpty(filter.getDistribute())) {
|
|
|
+ pageInfo.expression(PredicateUtils.in("enUU", filter.getDistribute(), false));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (StringUtils.hasText(keyword)) {
|
|
|
+ List<Object> lists = new ArrayList<>();
|
|
|
+ List<PurchaseNotice> listss = searchService.searchPurchaseNoticeIds(keyword, null).getContent();
|
|
|
+ for (PurchaseNotice list : listss) {
|
|
|
+ lists.add(list.getId());
|
|
|
+ }
|
|
|
+ pageInfo.expression(PredicateUtils.in("id", lists, false));
|
|
|
+ }
|
|
|
+ if (fromDate != null) {
|
|
|
+ pageInfo.expression(PredicateUtils.in("id", purchaseNoticeDao.findByFromDate(
|
|
|
+ SystemSession.getUser().getEnterprise().getUu(), new Date(fromDate)), false));
|
|
|
+ }
|
|
|
+ if (endDate != null) {
|
|
|
+ pageInfo.expression(PredicateUtils.in("id", purchaseNoticeDao
|
|
|
+ .findByEndDate(SystemSession.getUser().getEnterprise().getUu(), new Date(endDate)), false));
|
|
|
+ }
|
|
|
+ return query.where(pageInfo.getPredicates(root, query, builder)).getRestriction();
|
|
|
+ }
|
|
|
+ }, pageInfo);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Page<PurchaseNotice> findDoneByPageInfo(final PageInfo pageInfo, final String keyword, final Long fromDate,
|
|
|
+ final Long endDate) {
|
|
|
+ return purchaseNoticeDao.findAll(new Specification<PurchaseNotice>() {
|
|
|
+ @Override
|
|
|
+ public Predicate toPredicate(Root<PurchaseNotice> root, CriteriaQuery<?> query, CriteriaBuilder builder) {
|
|
|
+ pageInfo.filter("status", Status.REPLIED.value());
|
|
|
+ pageInfo.expression(
|
|
|
+ PredicateUtils.or(PredicateUtils.isNull("end"), PredicateUtils.ne("end", Constant.YES, false)));
|
|
|
+ if (StringUtils.hasText(keyword)) {
|
|
|
+ List<Object> lists = new ArrayList<>();
|
|
|
+ List<PurchaseNotice> listss = searchService.searchPurchaseNoticeIds(keyword, null).getContent();
|
|
|
+ for (PurchaseNotice list : listss) {
|
|
|
+ lists.add(list.getId());
|
|
|
+ }
|
|
|
+ pageInfo.expression(PredicateUtils.in("id", lists, false));
|
|
|
+ }
|
|
|
+ if (fromDate != null) {
|
|
|
+ pageInfo.expression(PredicateUtils.in("id", purchaseNoticeDao.findByFromDate(
|
|
|
+ SystemSession.getUser().getEnterprise().getUu(), new Date(fromDate)), false));
|
|
|
+ }
|
|
|
+ if (endDate != null) {
|
|
|
+ pageInfo.expression(PredicateUtils.in("id", purchaseNoticeDao
|
|
|
+ .findByEndDate(SystemSession.getUser().getEnterprise().getUu(), new Date(endDate)), false));
|
|
|
+ }
|
|
|
+ return query.where(pageInfo.getPredicates(root, query, builder)).getRestriction();
|
|
|
+ }
|
|
|
+ }, pageInfo);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public PurchaseNotice findById(Long id) {
|
|
|
+ return purchaseNoticeDao.findOne(id);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void send(List<SaleSendItem> sendItems) {
|
|
|
+ saleSendItemDao.save(sendItems);
|
|
|
+ for (SaleSendItem item : sendItems) {
|
|
|
+ if (item.getNoticeId() != null) {
|
|
|
+ Double sendQty = saleSendItemDao.getSendQtyByNoticeId(item.getNoticeId());
|
|
|
+ purchaseNoticeDao.updateBySend(item.getNoticeId(), sendQty);
|
|
|
+ logger.log("更新发货提醒发货数量", "ERP主动收料通知单/上传发货单更新发货提醒已发货数量",
|
|
|
+ "发货单: " + item.getNoticeId() + ",更新数量: " + sendQty);
|
|
|
+ // 更新发货状态
|
|
|
+ updateNoticeStatus(item.getNoticeId());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public List<SaleSendItem> findSendById(long noticeId) {
|
|
|
+ return saleSendItemDao.findByNoticeId(noticeId);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public List<PurchaseNotice> findNotUploadNotice() {
|
|
|
+ return purchaseNoticeDao.findByVendUUAndSendStatus(SystemSession.getUser().getEnterprise().getUu(),
|
|
|
+ (short) Status.NOT_UPLOAD.value());
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onNoticeDownSuccess(String[] idArray) {
|
|
|
+ for (String id : idArray) {
|
|
|
+ PurchaseNotice notice = purchaseNoticeDao.findOne(Long.parseLong(id));
|
|
|
+ if (notice != null) {
|
|
|
+ notice.setSendStatus((short) Status.DOWNLOADED.value());
|
|
|
+ purchaseNoticeDao.save(notice);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public List<SaleSend> findNotUploadSend() {
|
|
|
+ return saleSendDao.findByCustUUAndSendStatus(SystemSession.getUser().getEnterprise().getUu(),
|
|
|
+ (short) Status.NOT_UPLOAD.value());
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public List<SaleSend> findNotUploadSendEDI(Long enUU) {
|
|
|
+ return saleSendDao.findByCustUUAndSendStatus(enUU,
|
|
|
+ (short) Status.NOT_UPLOAD.value());
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public List<SaleSend> findNotSendSend() {
|
|
|
+ return saleSendDao.findByEnUUAndBackStatus(SystemSession.getUser().getEnterprise().getUu(),
|
|
|
+ (short) Status.NOT_UPLOAD.value());
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onSendUploadSuccess(String[] idArray) {
|
|
|
+ for (String id : idArray) {
|
|
|
+ SaleSend send = saleSendDao.findOne(Long.parseLong(id));
|
|
|
+ if (send != null) {
|
|
|
+ send.setSendStatus((short) Status.DOWNLOADED.value());
|
|
|
+ saleSendDao.save(send);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onSendDownSuccess(String[] idArray) {
|
|
|
+ for (String id : idArray) {
|
|
|
+ SaleSend send = saleSendDao.findOne(Long.parseLong(id));
|
|
|
+ if (send != null) {
|
|
|
+ send.setBackStatus((short) Status.DOWNLOADED.value());
|
|
|
+ saleSendDao.save(send);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void end(List<PurchaseNotify> notifies) {
|
|
|
+ long enUU = SystemSession.getUser().getEnterprise().getUu();
|
|
|
+ List<PurchaseNoticeEnd> noticeList = noticeEndDao.findByEnUUAndSourceIdList(enUU, CollectionUtil.getKeyCollection(notifies));
|
|
|
+ if (!CollectionUtils.isEmpty(noticeList)) {
|
|
|
+ for (PurchaseNoticeEnd notice : noticeList) {
|
|
|
+ notice.setEnd(Constant.YES);
|
|
|
+ notice.setEndStatus((short) Status.NOT_UPLOAD.value());
|
|
|
+ notice.setErpDate(new Date(System.currentTimeMillis()));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ noticeEndDao.save(noticeList);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public List<PurchaseNotice> findNotSendEnd() {
|
|
|
+ return purchaseNoticeDao.findByVendUUAndEndStatus(SystemSession.getUser().getEnterprise().getUu(),
|
|
|
+ (short) Status.NOT_UPLOAD.value());
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onEndDownSuccess(String[] idArray) {
|
|
|
+ for (String id : idArray) {
|
|
|
+ PurchaseNoticeEnd noticeEnd = noticeEndDao.findOne(Long.parseLong(id));
|
|
|
+ if (noticeEnd != null) {
|
|
|
+ noticeEnd.setEndStatus((short) Status.DOWNLOADED.value());
|
|
|
+ noticeEndDao.save(noticeEnd);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public SaleSend send(Long noticeId, SaleSend send) {
|
|
|
+ PurchaseNotice notice = purchaseNoticeDao.findOne(noticeId);
|
|
|
+ List<SaleSend> sends = saleSendDao.findByUuid(send.getUuid());
|
|
|
+ //限制同一个供应商给同一个客户发货单号不可以重复,(避免一次发货产生多张单)
|
|
|
+ if (notice != null && CollectionUtils.isEmpty(sends)) {
|
|
|
+ if (notice.getEnd() != null && notice.getEnd() == Constant.YES) {
|
|
|
+ throw new IllegalOperatorException("客户已经取消了本次送货提醒,请刷新重试!");
|
|
|
+ }
|
|
|
+ double thisQty = 0;
|
|
|
+ for (SaleSendItem item : send.getSendItems()) {
|
|
|
+ thisQty += item.getQty();
|
|
|
+ }
|
|
|
+ double endQty = (notice.getEndQty() == null ? 0.0 : notice.getEndQty()) + thisQty;
|
|
|
+ if (endQty > notice.getQty()) {
|
|
|
+ throw new IllegalOperatorException("累计发货数量将超出本次送货提醒的需求数!");
|
|
|
+ }
|
|
|
+ PurchaseOrder order = notice.getOrderItem().getOrder();
|
|
|
+ send.setCurrency(order.getCurrency());
|
|
|
+ send.setBackStatus((short) Status.NOT_UPLOAD.value());
|
|
|
+ send.setSendStatus((short) Status.NOT_UPLOAD.value());
|
|
|
+ // 未收料
|
|
|
+ send.setVerifystatus(Constant.NO);
|
|
|
+ send.setCustUU(notice.getEnUU());
|
|
|
+ if (!StringUtils.isEmpty(notice.getOrderItem().getCustPurchaseCode())) {
|
|
|
+ send.setCustUserUU(enterpriseDao.findOne(notice.getEnUU()).getEnAdminuu());
|
|
|
+ } else {
|
|
|
+ send.setCustUserUU(order.getUserUU());
|
|
|
+ }
|
|
|
+ send.setDate(new Date());
|
|
|
+ send.setEnUU(SystemSession.getUser().getEnterprise().getUu());
|
|
|
+ send.setPayments(order.getPayments());
|
|
|
+ send.setRate(order.getRate());
|
|
|
+ send.setRecorder(SystemSession.getUser().getUserName());
|
|
|
+ short number = 0;
|
|
|
+ for (SaleSendItem item : send.getSendItems()) {
|
|
|
+ item.setNoticeId(noticeId);
|
|
|
+ item.setNotice(notice);
|
|
|
+ item.setNumber(++number);
|
|
|
+ item.setOrderItem(notice.getOrderItem());
|
|
|
+ item.setOrderItemId(notice.getOrderItem().getId());
|
|
|
+ item.setPrice(notice.getOrderItem().getPrice());
|
|
|
+ item.setSend(send);
|
|
|
+ }
|
|
|
+ List<SaleSendItem> sendItems = saleSendItemDao.save(send.getSendItems());
|
|
|
+ notice.setEndQty(endQty);
|
|
|
+ notice.setStatus((short) (endQty == notice.getQty() ? Status.REPLIED.value() : Status.NOT_REPLY.value()));
|
|
|
+ purchaseNoticeDao.save(notice);
|
|
|
+ if (!CollectionUtils.isEmpty(sendItems)) {
|
|
|
+ List<SaleSend> saleSends = new ArrayList<SaleSend>();
|
|
|
+ saleSends.add(sendItems.get(0).getSend());
|
|
|
+ }
|
|
|
+ // 我的产品库更新
|
|
|
+ personalProductService.covertPersonalProduct(notice.getOrderItem().getProductId(), "单个发货");
|
|
|
+ return sendItems.get(0).getSend();
|
|
|
+ } else {
|
|
|
+ throw new IllegalOperatorException("请对有效的送货提醒发货!");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public int getOnhandCount() {
|
|
|
+ return purchaseNoticeDao.getCountByVendUUAndStatus(SystemSession.getUser().getEnterprise().getUu(),
|
|
|
+ (short) Status.NOT_REPLY.value());
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public SaleSend send(SaleSend saleSend) {
|
|
|
+ //限制同一个供应商给同一个客户发货单号不可以重复,(避免一次发货产生多张单),存在时不做处理
|
|
|
+ List<SaleSend> sendList = saleSendDao.findByUuid(saleSend.getUuid());
|
|
|
+ if (saleSend != null && CollectionUtils.isEmpty(sendList)) {
|
|
|
+ saleSend.setBackStatus((short) Status.NOT_UPLOAD.value());
|
|
|
+ saleSend.setSendStatus((short) Status.NOT_UPLOAD.value());
|
|
|
+ saleSend.setEnUU(SystemSession.getUser().getEnterprise().getUu());
|
|
|
+ saleSend.setRecorder(SystemSession.getUser().getUserName());
|
|
|
+ saleSend.setDate(new Date());
|
|
|
+ // 未收料
|
|
|
+ saleSend.setVerifystatus(Constant.NO);
|
|
|
+ short number = 0;
|
|
|
+ List<SaleSendItem> sendItems = new ArrayList<SaleSendItem>();
|
|
|
+ for (SaleSendItem item : saleSend.getSendItems()) {
|
|
|
+ PurchaseNotice notice = purchaseNoticeDao.findOne(item.getNoticeId());
|
|
|
+ if (notice != null) {
|
|
|
+ if (notice.getEnd() != null && notice.getEnd() == Constant.YES) {
|
|
|
+ String error = "货车中订单:" + notice.getOrderItem().getOrder().getCode() + "的物料号为"
|
|
|
+ + notice.getOrderItem().getProduct().getCode() + "的发货通知被取消!";
|
|
|
+ throw new IllegalOperatorException(error);
|
|
|
+ } else {
|
|
|
+ double thisQty = item.getQty();
|
|
|
+ double endQty = (notice.getEndQty() == null ? 0.0 : notice.getEndQty()) + thisQty;
|
|
|
+ if (endQty > notice.getQty()) {
|
|
|
+ throw new IllegalOperatorException("累计发货数量将超出本次送货提醒的需求数!");
|
|
|
+ }
|
|
|
+ item.setNotice(notice);
|
|
|
+ // 带了序号则不重设序号,不带这重设序号
|
|
|
+ if (item.getNumber() == null || item.getNumber() == 0) {
|
|
|
+ item.setNumber(++number);
|
|
|
+ }
|
|
|
+ item.setOrderItem(notice.getOrderItem());
|
|
|
+ item.setOrderItemId(notice.getOrderItemId());
|
|
|
+ saleSend.setRate(notice.getOrderItem().getOrder().getRate());
|
|
|
+ item.setSend(saleSend);
|
|
|
+ sendItems.add(item);
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ throw new IllegalOperatorException("参数错误,无效的客户送货提醒单!");
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ sendItems = saleSendItemDao.save(sendItems);
|
|
|
+ for (SaleSendItem sendItem : sendItems) {
|
|
|
+ PurchaseNotice notice = purchaseNoticeDao.findOne(sendItem.getNoticeId());
|
|
|
+ double endQty = (notice.getEndQty() == null ? 0.0 : notice.getEndQty()) + sendItem.getQty();
|
|
|
+ if (endQty > notice.getQty()) {
|
|
|
+ throw new IllegalOperatorException("累计发货数量将超出本次送货提醒的需求数!");
|
|
|
+ }
|
|
|
+ notice.setEndQty(endQty);
|
|
|
+ notice.setStatus(
|
|
|
+ (short) (endQty == notice.getQty() ? Status.REPLIED.value() : Status.NOT_REPLY.value()));
|
|
|
+ purchaseNoticeDao.save(notice);
|
|
|
+ // 转入我的物料库
|
|
|
+ personalProductService.covertPersonalProduct(notice.getOrderItem().getProductId(), "批量发货");
|
|
|
+ }
|
|
|
+ if (!CollectionUtils.isEmpty(sendItems)) {
|
|
|
+ List<SaleSend> saleSends = new ArrayList<SaleSend>();
|
|
|
+ saleSends.add(sendItems.get(0).getSend());
|
|
|
+ }
|
|
|
+ return sendItems.get(0).getSend();
|
|
|
+ } else {
|
|
|
+ throw new IllegalArgumentException();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onSaleSendChange(List<SaleSendItem> sendItems) {
|
|
|
+ for (SaleSendItem item : sendItems) {
|
|
|
+ saleSendItemDao.updateByReply(item.getId(), item.getQty(), item.getReplyRemark());
|
|
|
+ if (item.getNoticeId() != null) {
|
|
|
+ Double sendQty = saleSendItemDao.getSendQtyByNoticeId(item.getNoticeId());
|
|
|
+ purchaseNoticeDao.updateBySend(item.getNoticeId(), sendQty);
|
|
|
+ logger.log("更新发货提醒发货数量", "ERP上传收料通知的确认数量更新发货提醒已发货数量",
|
|
|
+ "发货单: " + item.getNoticeId() + ",更新数量: " + sendQty);
|
|
|
+ updateNoticeStatus(item.getNoticeId());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 更新发货提醒状态
|
|
|
+ *
|
|
|
+ * @param noticeId 发货提醒id
|
|
|
+ */
|
|
|
+ private void updateNoticeStatus(Long noticeId) {
|
|
|
+ PurchaseNotice notice = purchaseNoticeDao.findOne(noticeId);
|
|
|
+ if (notice.getEndQty() < notice.getQty() && notice.getStatus() == Status.REPLIED.value()) {
|
|
|
+ purchaseNoticeDao.updateStatus(notice.getId(), (short) Status.NOT_REPLY.value());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public List<PurchaseNotice> findById(Long[] ids) {
|
|
|
+ return purchaseNoticeDao.findUnEndByIds(ids);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onVerify(List<SaleSendItemVerify> verifies) {
|
|
|
+ verifies = saleSendItemVerifyDao.save(verifies);
|
|
|
+ List<SaleSendItem> saleSendItems = new ArrayList<>();
|
|
|
+ for (SaleSendItemVerify verify : verifies) {
|
|
|
+ saleSendItemDao.updateByVerify(verify.getSendItemId());
|
|
|
+ updateVerifyStatus(verify.getSendItemId());
|
|
|
+ SaleSendItem item = saleSendItemDao.findOne(verify.getSendItemId());
|
|
|
+ saleSendItems.add(item);
|
|
|
+ }
|
|
|
+ // 买家收料之后给卖家发消息
|
|
|
+ ContextUtils.publishEvent(new SaleSendAcceptReleaseEvent(SaleSendItem.distinct(saleSendItems)));
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void unVerify(List<SaleSendItemVerify> verifies) {
|
|
|
+ saleSendItemVerifyDao.delete(verifies);
|
|
|
+ for (SaleSendItemVerify verify : verifies) {
|
|
|
+ saleSendItemDao.updateByVerify(verify.getSendItemId());
|
|
|
+ updateVerifyStatus(verify.getSendItemId());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 更新发货单的收料状态
|
|
|
+ *
|
|
|
+ * @param sendItemId
|
|
|
+ */
|
|
|
+ private void updateVerifyStatus(Long sendItemId) {
|
|
|
+ SaleSendItem sendItem = saleSendItemDao.findOne(sendItemId);
|
|
|
+ int totalCount = saleSendItemDao.getTotalCountBySendId(sendItem.getSend().getId());
|
|
|
+ int verifyCount = saleSendItemDao.getFullVerifyCountBySendId(sendItem.getSend().getId());
|
|
|
+ if (verifyCount == totalCount) {
|
|
|
+ sendItem.getSend().setVerifystatus(Constant.YES);
|
|
|
+ } else {
|
|
|
+ sendItem.getSend().setVerifystatus(Constant.NO);
|
|
|
+ }
|
|
|
+ saleSendItemDao.save(sendItem);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public SaleSendAll findSaleSendById(Long id) {
|
|
|
+ SaleSendAll send = saleSendAllDao.findOne(id);
|
|
|
+ if (send == null) {
|
|
|
+ throw new IllegalOperatorException("您查找的发货单不存在!");
|
|
|
+ }
|
|
|
+ return send;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Long getAllCount() {
|
|
|
+ return purchaseNoticeDao.countByVendUU(SystemSession.getUser().getEnterprise().getUu());
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Long getAllNoticeCountByEnUU(Long enUU) {
|
|
|
+ return purchaseNoticeDao.getCountByEnUUAndStatus(enUU, (short) Status.REPLIED.value());
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Long getTodoNoticeCountByEnUU(Long enUU) {
|
|
|
+ return purchaseNoticeDao.getCountByEnUUAndStatus(enUU, (short) Status.NOT_REPLY.value());
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Long getWatingNoticeCountByEnUU(Long enUU) {
|
|
|
+ return purchaseNoticeDao.getWatingCountByEnUUAndStatus(enUU);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Long getEndNoticeCountByEnUU(Long enUU) {
|
|
|
+ return purchaseNoticeDao.getEndCountByEnUUAndStatus(enUU);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void updateBarCode(Long id, Double packageQty, Double outBoxQty) {
|
|
|
+ saleSendItemDao.updatePackageQty(id, packageQty, outBoxQty);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
+ public void generateBarcodes(Long id, List<SaleSendItem> sendItem, Long enUU) {
|
|
|
+ SaleSend saleSend = saleSendDao.findOne(id);
|
|
|
+ Long custUU = saleSend.getCustUU();
|
|
|
+ // 获取条码生成规则,判断规则是否审核,已审核,根据规则拼接
|
|
|
+ B2bCodeSet barcodeSet = b2bCodeSetDao.findByEnUUAndType(custUU, "BATCH");
|
|
|
+ // 条码生成规则不为空,已审核
|
|
|
+ if (barcodeSet != null) {
|
|
|
+ if (!"AUDITED".equals(barcodeSet.getStatuscode())) {
|
|
|
+ throw new IllegalOperatorException("请先审核条码生成规则!");
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ throw new IllegalOperatorException("请先维护条码生成规则!");
|
|
|
+ }
|
|
|
+ // 是否维护包装箱生成规则
|
|
|
+ B2bCodeSet outboxSet = b2bCodeSetDao.findByEnUUAndType(custUU, "PACK");
|
|
|
+ if (outboxSet == null) {
|
|
|
+ throw new IllegalOperatorException("请先维护外箱生成规则!");
|
|
|
+ }
|
|
|
+ String AUDITED_STATUS = "AUDITED";
|
|
|
+ if (!AUDITED_STATUS.equals(outboxSet.getStatuscode())) {
|
|
|
+ throw new IllegalOperatorException("请先审核外箱生成规则!");
|
|
|
+ }
|
|
|
+ for (SaleSendItem item : sendItem) {
|
|
|
+ // 清空原有箱号,箱号明细,条码
|
|
|
+ List<BarSendNotify> bsNotify = barSendNotifyDao.findBySiid(item.getId());
|
|
|
+ for (BarSendNotify notify : bsNotify) {
|
|
|
+ if (notify.getOutboxid() != null) {
|
|
|
+ BarPackage barPackage = barPackageDao.findOne(notify.getOutboxid());
|
|
|
+ if (barPackage != null) {
|
|
|
+ barPackageDetailDao.delete(barPackage.getDetail());
|
|
|
+ barPackageDao.delete(barPackage);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ barSendNotifyDao.deleteAllBySiid(item.getId());
|
|
|
+ // 获取明细,最小包装数,外箱容量等信息
|
|
|
+ SaleSendItem sItem = saleSendItemDao.findOne(item.getId());
|
|
|
+ double pQty = sItem.getPackageQty(), bQty = sItem.getOutBoxQty(), qty = sItem.getQty();
|
|
|
+ String bar_code, pr_code = sItem.getOrderItem().getProduct().getCode();
|
|
|
+ // 最小包装数件数
|
|
|
+ int aNum = (int) (qty / pQty);
|
|
|
+ double aqtyA = (new BigDecimal(Double.toString(qty))).subtract(new BigDecimal(Double.toString(aNum * pQty)))
|
|
|
+ .doubleValue(); // 小于最小包装数的
|
|
|
+ // ERP中对应的物料ID
|
|
|
+ String sourceId = String.valueOf(sItem.getOrderItem().getProduct().getSourceId());
|
|
|
+ // 获取是否勾选了生成外箱
|
|
|
+ if (item.getIsOutboxChecked()) {
|
|
|
+ // 判断外箱容量是否为最小包装数的整数倍
|
|
|
+ String out_boxcode = null;
|
|
|
+ Long pa_id = null;
|
|
|
+ // 每箱件数
|
|
|
+ int sumJ = (int) (bQty / pQty);
|
|
|
+ if (sumJ * pQty != bQty) {
|
|
|
+ throw new IllegalOperatorException("序号:" + sItem.getNumber() + ",外箱容量不是最小包装数的整数倍!");
|
|
|
+ }
|
|
|
+ // 整数箱数
|
|
|
+ int bNum = (int) (qty / bQty);
|
|
|
+ // 零散数
|
|
|
+ double bqtyB = (new BigDecimal(Double.toString(qty)))
|
|
|
+ .subtract(new BigDecimal(Double.toString(bNum * bQty))).doubleValue();
|
|
|
+ if (aNum >= 1) {
|
|
|
+ for (int i = 0; i < aNum; i++) {
|
|
|
+ if (i % sumJ == 0) {
|
|
|
+ BarPackage barPackage = new BarPackage();
|
|
|
+ out_boxcode = outboxMethod(sourceId, outboxSet);
|
|
|
+ barPackage.setCustUU(custUU);
|
|
|
+ barPackage.setEnUU(enUU);
|
|
|
+ barPackage.setOutboxcode(out_boxcode);
|
|
|
+ barPackage.setProdcode(pr_code);
|
|
|
+ barPackage.setLevel((long) 1);
|
|
|
+ barPackage.setPackdate(new Date());
|
|
|
+ barPackage.setSendStatus((short) Status.NOT_UPLOAD.value());
|
|
|
+ if (i >= aNum - sumJ && bqtyB > 0) {
|
|
|
+ barPackage.setPackageqty(aNum - sumJ);
|
|
|
+ barPackage.setTotalqty(bqtyB);
|
|
|
+ } else {
|
|
|
+ barPackage.setPackageqty(sumJ);
|
|
|
+ barPackage.setTotalqty(bQty);
|
|
|
+ }
|
|
|
+ barPackageDao.save(barPackage);
|
|
|
+ barPackage = barPackageDao.findByOutboxcodeAndEnUU(out_boxcode, enUU);
|
|
|
+ pa_id = barPackage.getId();
|
|
|
+ }
|
|
|
+ bar_code = barcodeMethod(sourceId, barcodeSet);
|
|
|
+ insertBarPd(pa_id, out_boxcode, pQty, bar_code, sItem, enUU);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (aqtyA > 0) {
|
|
|
+ bar_code = barcodeMethod(sourceId, barcodeSet);
|
|
|
+ insertBarPd(pa_id, out_boxcode, aqtyA, bar_code, sItem, enUU);
|
|
|
+ }
|
|
|
+ logger.log("发货单", "生成条码和箱号",
|
|
|
+ "发货单:" + sItem.getSend().getCode() + ",明细行序号:" + sItem.getNumber() + ",生成条码和箱号!");
|
|
|
+ } else {
|
|
|
+ if (aNum >= 1) {
|
|
|
+ for (int i = 0; i < aNum; i++) {
|
|
|
+ insertBar(sItem, pQty, enUU, barcodeSet);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (aqtyA > 0) {
|
|
|
+ insertBar(sItem, aqtyA, enUU, barcodeSet);
|
|
|
+ }
|
|
|
+ logger.log("发货单", "生成条码",
|
|
|
+ "发货单:" + sItem.getSend().getCode() + ",明细行序号:" + sItem.getNumber() + ",生成条码!");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private String lpad(int length, String number) {
|
|
|
+ while (number.length() < length) {
|
|
|
+ number = "0" + number;
|
|
|
+ }
|
|
|
+ number = number.substring(number.length() - length, number.length());
|
|
|
+ return number;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * YYMMDD 日期格式
|
|
|
+ */
|
|
|
+ final String YYMMDD_PATTERN = "YYMMDD";
|
|
|
+
|
|
|
+ /**
|
|
|
+ * YYMM日期格式
|
|
|
+ */
|
|
|
+ final String YYMM_PATTERN= "YYMM";
|
|
|
+
|
|
|
+ /**
|
|
|
+ * MMDD日期格式
|
|
|
+ */
|
|
|
+ final String MMDD_PATTERN = "MMDD";
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 默认数量
|
|
|
+ */
|
|
|
+ final Integer NULL_COUNT = 0;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 生成条码号
|
|
|
+ *
|
|
|
+ * @param pr_id
|
|
|
+ * @param barcodeSet
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public String barcodeMethod(String pr_id, B2bCodeSet barcodeSet) {
|
|
|
+ StringBuffer code = new StringBuffer();
|
|
|
+ String date = "0";
|
|
|
+ String formPlat = barcodeSet.getFromplat(), dataStr = barcodeSet.getDatestr(),
|
|
|
+ maxdate = barcodeSet.getMaxdate();
|
|
|
+ int lennum = barcodeSet.getLennum().intValue(), maxnum = barcodeSet.getMaxnum().intValue(),
|
|
|
+ lenprid = barcodeSet.getLenprid().intValue();
|
|
|
+ // 拼接
|
|
|
+ // 平台标识
|
|
|
+ code.append(formPlat);
|
|
|
+ // PR_ID物料ID的长度
|
|
|
+ code.append(lpad(lenprid, pr_id));
|
|
|
+ if (YYMMDD_PATTERN.equals(dataStr)) {
|
|
|
+ SimpleDateFormat YMD = new SimpleDateFormat("yyMMdd");
|
|
|
+ date = YMD.format(new Date());
|
|
|
+ } else if (YYMM_PATTERN.equals(dataStr)) {
|
|
|
+ SimpleDateFormat YM = new SimpleDateFormat("yyMM");
|
|
|
+ date = YM.format(new Date());
|
|
|
+ } else if (MMDD_PATTERN.equals(dataStr)) {
|
|
|
+ SimpleDateFormat MD = new SimpleDateFormat("MMdd");
|
|
|
+ date = MD.format(new Date());
|
|
|
+ }
|
|
|
+ code.append(date);
|
|
|
+ barcodeSet.setMaxdate(date);
|
|
|
+ // 如果当前日期大于上次日期
|
|
|
+ if (!("").equals(maxdate) && null != maxdate && (!NULL_COUNT.equals(date))
|
|
|
+ && (Integer.valueOf(maxdate) > Integer.valueOf(date))) {
|
|
|
+ // 流水重新开始
|
|
|
+ code.append(lpad(lennum, "1"));
|
|
|
+ // 流水号增加1
|
|
|
+ barcodeSet.setMaxnum((long) 2);
|
|
|
+ } else {
|
|
|
+ // 当前流水号
|
|
|
+ code.append(lpad(lennum, String.valueOf(maxnum)));
|
|
|
+ // 流水号增加1
|
|
|
+ barcodeSet.setMaxnum((long) (maxnum + 1));
|
|
|
+ }
|
|
|
+ b2bCodeSetDao.save(barcodeSet);
|
|
|
+ return code.toString();
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 生成外箱号
|
|
|
+ *
|
|
|
+ * @param pr_id
|
|
|
+ * @param barcodeSet
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public String outboxMethod(String pr_id, B2bCodeSet barcodeSet) {
|
|
|
+ StringBuffer code = new StringBuffer();
|
|
|
+ String date = "0";
|
|
|
+ String formPlat = barcodeSet.getFromplat(), dataStr = barcodeSet.getDatestr(),
|
|
|
+ maxdate = barcodeSet.getMaxdate();
|
|
|
+ int lennum = barcodeSet.getLennum().intValue(), maxnum = barcodeSet.getMaxnum().intValue(),
|
|
|
+ lenprid = barcodeSet.getLenprid().intValue();
|
|
|
+ // 平台标识
|
|
|
+ code.append(formPlat);
|
|
|
+ // PR_ID物料ID的长度
|
|
|
+ code.append(lpad(lenprid, pr_id));
|
|
|
+ if (YYMMDD_PATTERN.equals(dataStr)) {
|
|
|
+ SimpleDateFormat YMD = new SimpleDateFormat("yyMMdd");
|
|
|
+ date = YMD.format(new Date());
|
|
|
+ } else if (YYMM_PATTERN.equals(dataStr)) {
|
|
|
+ SimpleDateFormat YM = new SimpleDateFormat("yyMM");
|
|
|
+ date = YM.format(new Date());
|
|
|
+ } else if (MMDD_PATTERN.equals(dataStr)) {
|
|
|
+ SimpleDateFormat MD = new SimpleDateFormat("MMdd");
|
|
|
+ date = MD.format(new Date());
|
|
|
+ }
|
|
|
+ code.append(date);
|
|
|
+ barcodeSet.setMaxdate(date);
|
|
|
+ // 如果当前日期大于上次日期
|
|
|
+ if (!("").equals(maxdate) && null != maxdate && (!NULL_COUNT.equals(date))
|
|
|
+ && (Integer.valueOf(maxdate) > Integer.valueOf(date))) {
|
|
|
+ // 流水重新开始
|
|
|
+ code.append(lpad(lennum, "1"));
|
|
|
+ // 流水号增加1
|
|
|
+ barcodeSet.setMaxnum((long) 2);
|
|
|
+ } else {
|
|
|
+ // 当前流水号
|
|
|
+ code.append(lpad(lennum, String.valueOf(maxnum)));
|
|
|
+ // 流水号增加1
|
|
|
+ barcodeSet.setMaxnum((long) (maxnum + 1));
|
|
|
+ }
|
|
|
+ b2bCodeSetDao.save(barcodeSet);
|
|
|
+ return code.toString();
|
|
|
+ }
|
|
|
+
|
|
|
+ private void insertBarPd(Long pa_id, String out_boxcode, double qty, String bar_code, SaleSendItem sItem,
|
|
|
+ Long enUU) {
|
|
|
+ BarSendNotify barSendNotify = new BarSendNotify();
|
|
|
+ barSendNotify.setBarcode(bar_code);
|
|
|
+ barSendNotify.setOutboxcode(out_boxcode);
|
|
|
+ barSendNotify.setOutboxid(pa_id);
|
|
|
+ barSendNotify.setPrintstatus("0");
|
|
|
+ barSendNotify.setProdcode(sItem.getOrderItem().getProduct().getCode());
|
|
|
+ barSendNotify.setProdid(sItem.getOrderItem().getProduct().getSourceId());
|
|
|
+ barSendNotify.setQty(qty);
|
|
|
+ barSendNotify.setSendStatus((short) Status.NOT_UPLOAD.value());
|
|
|
+ SaleSendItemAll sendItem = new SaleSendItemAll();
|
|
|
+ sendItem.setId(sItem.getId());
|
|
|
+ barSendNotify.setSaleSendItem(sendItem);
|
|
|
+ barSendNotify.setSinumber(sItem.getNumber());
|
|
|
+ barSendNotify.setSscode(sItem.getSend().getCode());
|
|
|
+ barSendNotify.setSsid(sItem.getSend().getId());
|
|
|
+ barSendNotify.setVendcode(enUU);
|
|
|
+ // 保存发货单明细中的条码
|
|
|
+ barSendNotifyDao.save(barSendNotify);
|
|
|
+
|
|
|
+ BarPackageDetail barPackageDetail = new BarPackageDetail();
|
|
|
+ barPackageDetail.setBarcode(bar_code);
|
|
|
+ barPackageDetail.setBarpackage(barPackageDao.findOne(pa_id));
|
|
|
+ barPackageDetail.setInnerqty(qty);
|
|
|
+ // 保存包装箱明细
|
|
|
+ barPackageDetailDao.save(barPackageDetail);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 发货单明细条码明细生成
|
|
|
+ *
|
|
|
+ * @param sItem
|
|
|
+ * @param qty
|
|
|
+ * @param enUU
|
|
|
+ * @param barcodeSet
|
|
|
+ */
|
|
|
+ private void insertBar(SaleSendItem sItem, double qty, Long enUU, B2bCodeSet barcodeSet) {
|
|
|
+ BarSendNotify barSendNotify = new BarSendNotify();
|
|
|
+ String bar_code = barcodeMethod(String.valueOf(sItem.getOrderItem().getProductId()), barcodeSet);
|
|
|
+ barSendNotify.setBarcode(bar_code);
|
|
|
+ barSendNotify.setPrintstatus("0");
|
|
|
+ barSendNotify.setProdcode(sItem.getOrderItem().getProduct().getCode());
|
|
|
+ barSendNotify.setProdid(sItem.getOrderItem().getProduct().getSourceId());
|
|
|
+ barSendNotify.setQty(qty);
|
|
|
+ barSendNotify.setSendStatus((short) Status.NOT_UPLOAD.value());
|
|
|
+ SaleSendItemAll sendItem = new SaleSendItemAll();
|
|
|
+ sendItem.setId(sItem.getId());
|
|
|
+ barSendNotify.setSaleSendItem(sendItem);
|
|
|
+ barSendNotify.setSinumber(sItem.getNumber());
|
|
|
+ barSendNotify.setSscode(sItem.getSend().getCode());
|
|
|
+ barSendNotify.setSsid(sItem.getSend().getId());
|
|
|
+ barSendNotify.setVendcode(enUU);
|
|
|
+ // 保存发货单明细中的条码
|
|
|
+ barSendNotifyDao.save(barSendNotify);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public List<Map<String, Object>> getPrintBarcodes(Long lpsId, List<SaleSendItem> sendItem, Long enUU) {
|
|
|
+ List<Map<String, Object>> list2 = new ArrayList<Map<String, Object>>();
|
|
|
+ String va = "";
|
|
|
+ String regex = "\\{(?:[A-Za-z][A-Za-z0-9_]*)\\}";
|
|
|
+ BarLabelPrintSetting setting = barLPSetingDao.findOne(lpsId);
|
|
|
+ // 获取打印明细的设置参数
|
|
|
+ List<Map<String, Object>> parameter = commonDao.queryForList(
|
|
|
+ "select la_pagesize, lp_id,lp_valuetype,lp_encode,lp_name,lp_leftrate,lp_toprate,lp_width,lp_ifshownote,lp_font,lp_size,lp_notealignjustify,lp_height from bar$labelParameter left join bar$label on la_id=lp_laid where la_id="
|
|
|
+ + setting.getLabel().getId());
|
|
|
+ for (SaleSendItem item : sendItem) {
|
|
|
+ List<BarSendNotify> bars = barSendNotifyDao.findBySiid(item.getId());
|
|
|
+ List<Map<String, Object>> list = new ArrayList<Map<String, Object>>();
|
|
|
+ for (BarSendNotify barcode : bars) {
|
|
|
+ List<Map<String, Object>> list1 = new ArrayList<Map<String, Object>>();
|
|
|
+ Map<String, Object> mp1 = new HashMap<String, Object>();
|
|
|
+ va = setting.getSql().replaceAll(regex, String.valueOf(barcode.getId()));
|
|
|
+ List<Map<String, Object>> listData = commonDao.queryForList(va);
|
|
|
+ for (Map<String, Object> mapD : listData) {
|
|
|
+ for (Map<String, Object> param : parameter) {
|
|
|
+ mp1 = param;
|
|
|
+ mp1.put("value", mapD.get(param.get("lp_name")));
|
|
|
+ list1.add(mp1);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ Map<String, Object> mp = new HashMap<String, Object>();
|
|
|
+ mp.put("store", list1);
|
|
|
+ list.add(mp);
|
|
|
+ }
|
|
|
+ Map<String, Object> mp = new HashMap<String, Object>();
|
|
|
+ mp.put("si_id", item.getId());
|
|
|
+ mp.put("pagesize", parameter.get(0).get("la_pagesize"));
|
|
|
+ mp.put("data", list);
|
|
|
+ list2.add(mp);
|
|
|
+ }
|
|
|
+ return list2;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public List<BarLabelPrintSetting> getPrintTemplate(Long id, String type) {
|
|
|
+ SaleSend saleSend = saleSendDao.findOne(id);
|
|
|
+ Long custUU = saleSend.getCustUU();
|
|
|
+ String caller;
|
|
|
+ String BAR_TYPE = "Bar";
|
|
|
+ if (BAR_TYPE.equals(type)) {
|
|
|
+ caller = "B2B!BarPrint";
|
|
|
+ } else {
|
|
|
+ caller = "B2B!OutBoxPrint";
|
|
|
+ }
|
|
|
+ List<BarLabelPrintSetting> setting = barLPSetingDao.findByEnUUAndCaller(custUU, caller);
|
|
|
+ if (setting.size() > 0) {
|
|
|
+ return setting;
|
|
|
+ } else {
|
|
|
+ throw new IllegalOperatorException("未维护相关的打印模板!");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public List<Map<String, Object>> getSPrintBarcode(Long lpsId, Long bsnId) {
|
|
|
+ List<Map<String, Object>> list = new ArrayList<Map<String, Object>>();
|
|
|
+ String va = "";
|
|
|
+ String regex = "\\{(?:[A-Za-z][A-Za-z0-9_]*)\\}";
|
|
|
+ BarLabelPrintSetting setting = barLPSetingDao.findOne(lpsId);
|
|
|
+ // 获取打印明细的设置参数
|
|
|
+ List<Map<String, Object>> parameter = commonDao.queryForList(
|
|
|
+ "select la_pagesize, lp_id,lp_valuetype,lp_encode,lp_name,lp_leftrate,lp_toprate,lp_width,lp_ifshownote,lp_font,lp_size,lp_notealignjustify,lp_height from bar$labelParameter left join bar$label on la_id=lp_laid where la_id="
|
|
|
+ + setting.getLabel().getId());
|
|
|
+ Map<String, Object> map = new HashMap<String, Object>();
|
|
|
+ va = setting.getSql().replaceAll(regex, String.valueOf(bsnId));
|
|
|
+ List<Map<String, Object>> listData = commonDao.queryForList(va);
|
|
|
+ for (Map<String, Object> mapD : listData) {
|
|
|
+ for (Map<String, Object> param : parameter) {
|
|
|
+ map = param;
|
|
|
+ map.put("value", mapD.get(param.get("lp_name")));
|
|
|
+ list.add(map);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return list;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void updatePrintStatus(List<SaleSendItem> saleSendItems) {
|
|
|
+ List<SaleSendItem> items = new ArrayList<SaleSendItem>();
|
|
|
+ if (!CollectionUtils.isEmpty(saleSendItems)) {
|
|
|
+ for (SaleSendItem item : saleSendItems) {
|
|
|
+ item = saleSendItemDao.findOne(item.getId());
|
|
|
+ if (item != null) {
|
|
|
+ item.setBarPrintStatus((long) 1);
|
|
|
+ items.add(item);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ saleSendItemDao.save(items);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void printCount(Long id) {
|
|
|
+ SaleSendAll send = saleSendAllDao.findOne(id);
|
|
|
+ if (null == send.getPrint()) {
|
|
|
+ send.setPrint((short) 1);
|
|
|
+ } else {
|
|
|
+ send.setPrint((short) (send.getPrint() + 1));
|
|
|
+ }
|
|
|
+ saleSendAllDao.save(send);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Map<String, Integer> getNoticeCount(String category) {
|
|
|
+ List<Long> unreadIds = getUnreadIds(category);
|
|
|
+ Map<String, Integer> map = new HashMap<>(3);
|
|
|
+ // 已回复数量
|
|
|
+ Integer repliedCount = 0;
|
|
|
+ // 未回复数量
|
|
|
+ Integer notReplyCount = 0;
|
|
|
+ if (CollectionUtils.isEmpty(unreadIds)){
|
|
|
+ return map;
|
|
|
+ }
|
|
|
+ // 超过1000条需要拆分,不然会报错
|
|
|
+ if (unreadIds.size() > MAX_SIZE) {
|
|
|
+ List<List<Long>> idsArray = SplitArray.splitAry(unreadIds, SplitArray.QUERY_MAX_NUMBER);
|
|
|
+ for (List<Long> ids : idsArray) {
|
|
|
+ // 超过100不再查询,页面显示99+,减少服务器负担
|
|
|
+ if (repliedCount < 100) {
|
|
|
+ repliedCount = repliedCount + purchaseNoticeDao.findRepliedId(ids).size();
|
|
|
+ }
|
|
|
+ if (notReplyCount < 100) {
|
|
|
+ notReplyCount = notReplyCount + purchaseNoticeDao.findNotReplyId(ids).size();
|
|
|
+ }
|
|
|
+ // 当需要查询的数量大于99时停止循环,减少不必要的操作
|
|
|
+ if (notReplyCount > 99 && repliedCount > 99) {
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ repliedCount = repliedCount + purchaseNoticeDao.findRepliedId(unreadIds).size();
|
|
|
+ notReplyCount = notReplyCount + purchaseNoticeDao.findNotReplyId(unreadIds).size();
|
|
|
+ }
|
|
|
+ map.put("replied", repliedCount);
|
|
|
+ map.put("notReply", notReplyCount);
|
|
|
+ map.put("all", repliedCount + notReplyCount);
|
|
|
+ return map;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public SPage<PurchaseNotice> findDoneNoticesByPageInfo(final PageInfo pageInfo, String keyword, final SearchFilter filter) {
|
|
|
+ Page<PurchaseNotice> notices = purchaseNoticeDao.findAll(new Specification<PurchaseNotice>() {
|
|
|
+ @Override
|
|
|
+ public Predicate toPredicate(Root<PurchaseNotice> root, CriteriaQuery<?> query, CriteriaBuilder builder) {
|
|
|
+ if (filter != null) {
|
|
|
+ if (!CollectionUtils.isEmpty(filter.getDistribute())) {
|
|
|
+ pageInfo.expression(PredicateUtils.in("enUU", filter.getDistribute(), false));
|
|
|
+ }
|
|
|
+ if (filter.getFromDate() != null) {
|
|
|
+ pageInfo.expression(PredicateUtils.gte("date", new Date(filter.getFromDate()), false));
|
|
|
+ }
|
|
|
+ if (filter.getEndDate() != null) {
|
|
|
+ pageInfo.expression(PredicateUtils.lte("date", new Date(filter.getEndDate()), false));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ pageInfo.expression(
|
|
|
+ PredicateUtils.or(PredicateUtils.isNull("end"), PredicateUtils.ne("end", Constant.YES, false)));
|
|
|
+ return query.where(pageInfo.getPredicates(root, query, builder)).getRestriction();
|
|
|
+ }
|
|
|
+ }, pageInfo);
|
|
|
+ return SPageUtils.covertSPage(notices);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 查询未阅读数量
|
|
|
+ *
|
|
|
+ * @param category 表名
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public List<Long> getUnreadIds(String category) {
|
|
|
+ return userOrderDao.getUnreadIds(SystemSession.getUser().getEnterprise().getUu(), SystemSession.getUser().getUserUU(), "purc$notice", category);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 查询发货提醒
|
|
|
+ *
|
|
|
+ * @param pageInfo 分页信息
|
|
|
+ * @param keyword 关键字
|
|
|
+ * @param filter 过滤条件
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public SPage<PurchaseNotice> findAllNoticesByPageInfo(final PageInfo pageInfo, String keyword, final SearchFilter filter) {
|
|
|
+ if (filter != null) {
|
|
|
+ if (!CollectionUtils.isEmpty(filter.getDistribute())) {
|
|
|
+ pageInfo.expression(PredicateUtils.in("enUU", filter.getDistribute(), false));
|
|
|
+ }
|
|
|
+ if (filter.getFromDate() != null) {
|
|
|
+ pageInfo.expression(PredicateUtils.gte("date", new Date(filter.getFromDate()), false));
|
|
|
+ }
|
|
|
+ if (filter.getEndDate() != null) {
|
|
|
+ pageInfo.expression(PredicateUtils.lte("date", new Date(filter.getEndDate()), false));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ pageInfo.expression(PredicateUtils.isNull("end"));
|
|
|
+ Page<PurchaseNotice> notices = purchaseNoticeDao.findAll(new Specification<PurchaseNotice>() {
|
|
|
+ @Override
|
|
|
+ public Predicate toPredicate(Root<PurchaseNotice> root, CriteriaQuery<?> query, CriteriaBuilder builder) {
|
|
|
+ List<Predicate> predicatesList = new ArrayList<Predicate>();
|
|
|
+ if (!StringUtils.isEmpty(keyword)) {
|
|
|
+ Predicate custName = builder.like(root.get("orderItem").get("order").get("enterprise").get("enName"), "%" + keyword+ "%");
|
|
|
+ if (keyword.matches(SearchUtils.UU_REGEXP)) {
|
|
|
+ Predicate custUU = builder.like(root.get("orderItem").get("order").get("enterprise").get("uu"), "%" + keyword+ "%");
|
|
|
+ builder.or(custUU);
|
|
|
+ }
|
|
|
+ Predicate productCode = builder.like(root.get("orderItem").get("productCode"), "%" + keyword+ "%");
|
|
|
+ Predicate productTitle = builder.like(root.get("orderItem").get("productTitle"), "%" + keyword+ "%");
|
|
|
+ Predicate productSpec = builder.like(root.get("orderItem").get("productSpec"), "%" + keyword+ "%");
|
|
|
+ Predicate orderCode = builder.like(root.get("orderItem").get("order").get("code"), "%" + keyword+ "%");
|
|
|
+ predicatesList.add(builder.or(custName, productCode, productTitle, productSpec, orderCode));
|
|
|
+ }
|
|
|
+ Predicate[] predicates = pageInfo.getPredicates(root, query, builder);
|
|
|
+ Arrays.stream(predicates).forEach(predicate -> {
|
|
|
+ predicatesList.add(predicate);
|
|
|
+ });
|
|
|
+ return builder.and(predicatesList.toArray(new Predicate[predicatesList.size()]));
|
|
|
+ }
|
|
|
+ }, pageInfo);
|
|
|
+ return SPageUtils.covertSPage(notices);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 按条件查询发货提醒
|
|
|
+ *
|
|
|
+ * @param pageInfo 分页信息,过滤条件
|
|
|
+ * @param keyword 搜索词
|
|
|
+ * @param filter 过滤条件
|
|
|
+ * @param state 状态
|
|
|
+ * @return SPage封装的数据
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public SPage<PurchaseNotice> findNoticesByPageInfo(PageInfo pageInfo, String keyword, SearchFilter filter, String state) {
|
|
|
+ // 根据状态设置其他条件
|
|
|
+ setState(pageInfo, state, filter);
|
|
|
+ if (filter != null) {
|
|
|
+ if (!CollectionUtils.isEmpty(filter.getDistribute())) {
|
|
|
+ pageInfo.expression(PredicateUtils.in("enUU", filter.getDistribute(), false));
|
|
|
+ }
|
|
|
+ if (filter.getFromDate() != null) {
|
|
|
+ pageInfo.expression(PredicateUtils.gte("date", new Date(filter.getFromDate()), false));
|
|
|
+ }
|
|
|
+ if (filter.getEndDate() != null) {
|
|
|
+ pageInfo.expression(PredicateUtils.lte("date", new Date(filter.getEndDate()), false));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ Page<PurchaseNotice> notices = purchaseNoticeDao.findAll(new Specification<PurchaseNotice>() {
|
|
|
+ @Override
|
|
|
+ public Predicate toPredicate(Root<PurchaseNotice> root, CriteriaQuery<?> query, CriteriaBuilder builder) {
|
|
|
+ List<Predicate> predicatesList = new ArrayList<Predicate>();
|
|
|
+ if (!StringUtils.isEmpty(keyword)) {
|
|
|
+ Predicate custName = builder.like(root.get("orderItem").get("order").get("enterprise").get("enName"), "%" + keyword+ "%");
|
|
|
+ if (keyword.matches(SearchUtils.UU_REGEXP)) {
|
|
|
+ Predicate custUU = builder.like(root.get("orderItem").get("order").get("enterprise").get("uu"), "%" + keyword+ "%");
|
|
|
+ builder.or(custUU);
|
|
|
+ }
|
|
|
+ Predicate productCode = builder.like(root.get("orderItem").get("productCode"), "%" + keyword+ "%");
|
|
|
+ Predicate productTitle = builder.like(root.get("orderItem").get("productTitle"), "%" + keyword+ "%");
|
|
|
+ Predicate productSpec = builder.like(root.get("orderItem").get("productSpec"), "%" + keyword+ "%");
|
|
|
+ Predicate orderCode = builder.like(root.get("orderItem").get("order").get("code"), "%" + keyword+ "%");
|
|
|
+ predicatesList.add(builder.or(custName, productCode, productTitle, productSpec, orderCode));
|
|
|
+ }
|
|
|
+ Predicate[] predicates = pageInfo.getPredicates(root, query, builder);
|
|
|
+ Arrays.stream(predicates).forEach(predicate -> {
|
|
|
+ predicatesList.add(predicate);
|
|
|
+ });
|
|
|
+ return builder.and(predicatesList.toArray(new Predicate[predicatesList.size()]));
|
|
|
+ }
|
|
|
+ }, pageInfo);
|
|
|
+ return SPageUtils.covertSPage(notices);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 封装相关查询条件
|
|
|
+ *
|
|
|
+ * @param pageInfo 分页参数
|
|
|
+ * @param state 状态
|
|
|
+ * <pre>
|
|
|
+ * _todo : 待发货
|
|
|
+ * done: 已发货
|
|
|
+ * end: 已取消
|
|
|
+ * </pre>
|
|
|
+ * @param filter 过滤条件
|
|
|
+ */
|
|
|
+ private void setState(PageInfo pageInfo, String state, SearchFilter filter) {
|
|
|
+ pageInfo.filter("vendUU", SystemSession.getUser().getEnterprise().getUu());
|
|
|
+ SearchFilter distribute = userService.distribute();
|
|
|
+ if (distribute != null && !CollectionUtils.isEmpty(distribute.getDistribute())) {
|
|
|
+ List<Object> list = new ArrayList<>();
|
|
|
+ list.addAll(distribute.getDistribute());
|
|
|
+ filter.setDistribute(list);
|
|
|
+ }
|
|
|
+ if (SearchUtils.TODO_STATE.equals(state)) {
|
|
|
+ pageInfo.expression(PredicateUtils.or(PredicateUtils.isNull("end"), PredicateUtils.eq("end", Constant.NO, false)));
|
|
|
+ pageInfo.filter("status", (short)Status.NOT_REPLY.value());
|
|
|
+ pageInfo.filter("waiting", Constant.NO);
|
|
|
+ } else if (SearchUtils.DONE_STATE.equals(state)) {
|
|
|
+ pageInfo.expression(PredicateUtils.or(PredicateUtils.isNull("end"), PredicateUtils.eq("end", Constant.NO, false)));
|
|
|
+ pageInfo.filter("status", (short)Status.REPLIED.value());
|
|
|
+ } else if (SearchUtils.END_STATE.equals(state)) {
|
|
|
+ pageInfo.filter("end", Constant.YES);
|
|
|
+ } else if (SearchUtils.WAITING_STATE.equals(state)) {
|
|
|
+ pageInfo.filter("waiting", Constant.YES);
|
|
|
+ pageInfo.expression(PredicateUtils.or(PredicateUtils.isNull("end"), PredicateUtils.eq("end", Constant.NO, false)));
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
+ public void setReadByOrder(String category, Long[] sourceId) {
|
|
|
+ userOrderDao.setReadStatus(SystemSession.getUser().getEnterprise().getUu(), SystemSession.getUser().getUserUU(), "purc$notice", category, (short) Status.READ.value(), sourceId);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
+ public Integer setReadByState(String category) {
|
|
|
+ List<Long> unreadIds = getUnreadIds(category);
|
|
|
+ Integer deleteCount = 0;
|
|
|
+ if (CollectionUtils.isEmpty(unreadIds)){
|
|
|
+ return deleteCount;
|
|
|
+ }
|
|
|
+ List<Long> repliedIds = null;
|
|
|
+ if (unreadIds.size() > MAX_SIZE) {
|
|
|
+ List<List<Long>> idsArray = SplitArray.splitAry(unreadIds, SplitArray.QUERY_MAX_NUMBER);
|
|
|
+ for (List<Long> ids : idsArray) {
|
|
|
+ repliedIds = purchaseNoticeDao.findRepliedId(ids);
|
|
|
+ if (repliedIds.size() != 0) {
|
|
|
+ deleteCount = deleteCount + userOrderDao.delete(SystemSession.getUser().getEnterprise().getUu(),
|
|
|
+ SystemSession.getUser().getUserUU(), "purc$notice", category, repliedIds.toArray(new Long[repliedIds.size()]));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ repliedIds = purchaseNoticeDao.findRepliedId(unreadIds);
|
|
|
+ if (repliedIds.size() != 0) {
|
|
|
+ deleteCount = deleteCount + userOrderDao.delete(SystemSession.getUser().getEnterprise().getUu(),
|
|
|
+ SystemSession.getUser().getUserUU(), "purc$notice", category, repliedIds.toArray(new Long[repliedIds.size()]));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return deleteCount;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 通过ids查询发货信息
|
|
|
+ *
|
|
|
+ * @param ids
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public List<PurchaseNotice> findByIds(List<Long> ids) {
|
|
|
+ return purchaseNoticeDao.findAll(ids);
|
|
|
+ }
|
|
|
+}
|