供应商
This commit is contained in:
@@ -188,7 +188,7 @@ public class TbProductStockOperateServiceImpl implements TbProductStockOperateSe
|
||||
purveyorTransact.setTotalAmount(resources.getTotalAmount());
|
||||
purveyorTransact.setPaidAmount(resources.getPaidAmount());
|
||||
purveyorTransact.setWaitAmount(resources.getTotalAmount().subtract(resources.getPaidAmount()));
|
||||
if (resources.getTotalAmount().compareTo(resources.getPaidAmount()) < 0) {
|
||||
if (resources.getTotalAmount().compareTo(resources.getPaidAmount()) <= 0) {
|
||||
purveyorTransact.setStatus(1);
|
||||
} else {
|
||||
purveyorTransact.setStatus(0);
|
||||
|
||||
@@ -1,47 +1,27 @@
|
||||
/*
|
||||
* Copyright 2019-2020 Zheng Jie
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package cn.ysk.cashier.service.impl.shopimpl;
|
||||
|
||||
import cn.ysk.cashier.repository.shop.TbShopPurveyorRepository;
|
||||
import cn.ysk.cashier.pojo.shop.TbShopPurveyorTransact;
|
||||
import cn.ysk.cashier.vo.PurveyorTransactVO;
|
||||
import cn.ysk.cashier.utils.ValidationUtil;
|
||||
import cn.ysk.cashier.utils.FileUtil;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import cn.ysk.cashier.repository.shop.TbShopPurveyorTransactRepository;
|
||||
import cn.ysk.cashier.service.shop.TbShopPurveyorTransactService;
|
||||
import cn.ysk.cashier.dto.shop.TbShopPurveyorTransactDto;
|
||||
import cn.ysk.cashier.dto.shop.TbShopPurveyorTransactQueryCriteria;
|
||||
import cn.ysk.cashier.mapper.shop.TbShopPurveyorTransactMapper;
|
||||
import cn.ysk.cashier.pojo.shop.TbShopPurveyorTransact;
|
||||
import cn.ysk.cashier.repository.shop.TbShopPurveyorRepository;
|
||||
import cn.ysk.cashier.repository.shop.TbShopPurveyorTransactRepository;
|
||||
import cn.ysk.cashier.service.shop.TbShopPurveyorTransactService;
|
||||
import cn.ysk.cashier.utils.FileUtil;
|
||||
import cn.ysk.cashier.utils.QueryHelp;
|
||||
import cn.ysk.cashier.utils.ValidationUtil;
|
||||
import cn.ysk.cashier.vo.PurveyorTransactVO;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.PageRequest;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.data.domain.Sort;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import cn.ysk.cashier.utils.QueryHelp;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.math.BigInteger;
|
||||
import java.util.*;
|
||||
import java.io.IOException;
|
||||
import javax.persistence.EntityManager;
|
||||
import javax.persistence.PersistenceContext;
|
||||
import javax.persistence.Query;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.IOException;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* @website https://eladmin.vip
|
||||
@@ -57,33 +37,6 @@ public class TbShopPurveyorTransactServiceImpl implements TbShopPurveyorTransact
|
||||
private final TbShopPurveyorTransactMapper tbShopPurveyorTransactMapper;
|
||||
private final TbShopPurveyorRepository tbShopPurveyorRepository;
|
||||
|
||||
private final String LEFTQUERYSQL="SELECT\n" +
|
||||
"\ta.purveyor_name AS purveyorName,\n" +
|
||||
"\tb.last_transact_at AS lastTransactAt,\n" +
|
||||
"\tIFNULL( b.waitAmount, 0 ) AS waitAmount,\n" +
|
||||
"\tIFNULL( b.waitCount, 0 ) AS waitCount,\n" +
|
||||
"\ta.id AS purveyorId \n" +
|
||||
"FROM\n" +
|
||||
"\ttb_shop_purveyor a\n" +
|
||||
"\tLEFT JOIN (\n" +
|
||||
"\tSELECT\n" +
|
||||
"\t\tsum( a.wait_amount ) AS waitAmount,\n" +
|
||||
"\t\tcount( a.id ) AS waitCount,\n" +
|
||||
"\t\ta.purveyor_id AS id,\n" +
|
||||
"\t\tb.purveyor_name,\n" +
|
||||
"\t\tb.last_transact_at \n" +
|
||||
"\tFROM\n" +
|
||||
"\t\ttb_shop_purveyor_transact a\n" +
|
||||
"\t\tLEFT JOIN tb_shop_purveyor b ON a.purveyor_id = b.id \n" +
|
||||
"\tWHERE " +
|
||||
"a.`status` = 0 ";
|
||||
private final String RIGHTQUERYSQL = " GROUP BY\n" +
|
||||
"\t\tb.id \n" +
|
||||
"\t) b ON a.id = b.id\n" +
|
||||
"WHERE 1=1";
|
||||
@PersistenceContext
|
||||
private EntityManager em;
|
||||
|
||||
@Override
|
||||
public Map<String, Object> queryPurveyorTransact(TbShopPurveyorTransactQueryCriteria criteria) {
|
||||
Sort sort = Sort.by(Sort.Direction.DESC, "id");
|
||||
@@ -97,55 +50,14 @@ public class TbShopPurveyorTransactServiceImpl implements TbShopPurveyorTransact
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, Object> queryTransactDate(TbShopPurveyorTransactQueryCriteria criteria, Pageable pageable){
|
||||
// 构建动态SQL语句
|
||||
StringBuilder sqlQuery = new StringBuilder(LEFTQUERYSQL);
|
||||
sqlQuery.append(" and b.shop_id=").append(criteria.getShopId()).append(" AND a.type=").append("'purveyor'").append(RIGHTQUERYSQL);
|
||||
//没有条件时
|
||||
if (criteria.getStatus() == null && "".equals(criteria.getPurveyorName())){
|
||||
sqlQuery.append(" AND a.shop_id = ").append(criteria.getShopId());
|
||||
}
|
||||
//付款状态
|
||||
if (criteria.getStatus() != null) {
|
||||
sqlQuery.append(" AND a.id IN (SELECT purveyor_id FROM tb_shop_purveyor_transact WHERE shop_id AND `status` = ").append(criteria.getStatus())
|
||||
.append(" GROUP BY purveyor_id)");
|
||||
}
|
||||
//供应商名字
|
||||
if (criteria.getPurveyorName() != null && !"".equals(criteria.getPurveyorName())) {
|
||||
sqlQuery.append(" AND a.purveyor_name LIKE '").append(criteria.getPurveyorName()).append("%'");
|
||||
}
|
||||
|
||||
//获取页码号
|
||||
int pageNum = pageable.getPageNumber();
|
||||
//获取每页大小
|
||||
int pageSize = pageable.getPageSize();
|
||||
int beginNo;
|
||||
if(pageNum <=0){
|
||||
beginNo = 0;
|
||||
}else{
|
||||
beginNo = (pageNum - 1) * pageSize;
|
||||
}
|
||||
sqlQuery.append(" LIMIT ").append(beginNo).append(",").append(pageSize);
|
||||
Query query = em.createNativeQuery(String.valueOf(sqlQuery));
|
||||
|
||||
List<Object[]> resultList = query.getResultList();
|
||||
List<PurveyorTransactVO> userVOs = new ArrayList<>();
|
||||
for (Object[] result : resultList) {
|
||||
PurveyorTransactVO purveyorTransactVO = new PurveyorTransactVO();
|
||||
purveyorTransactVO.setLastTransactAt((BigInteger) result[1]);
|
||||
purveyorTransactVO.setPurveyorId((Integer) result[4]);
|
||||
purveyorTransactVO.setPurveyorName((String) result[0]);
|
||||
purveyorTransactVO.setWaitAmount((BigDecimal) result[2]);
|
||||
purveyorTransactVO.setWaitCount((BigInteger) result[3]);
|
||||
public Page<PurveyorTransactVO> queryTransactDate(TbShopPurveyorTransactQueryCriteria criteria){
|
||||
Pageable pageable = PageRequest.of(criteria.getPage(), criteria.getSize());
|
||||
Page<PurveyorTransactVO> purveyorTransactVOS = tbShopPurveyorTransactRepository.queryTransactDate(criteria.getType(), criteria.getShopId(), criteria.getPurveyorName(), pageable);
|
||||
for (PurveyorTransactVO purveyorTransactVO : purveyorTransactVOS.getContent()) {
|
||||
purveyorTransactVO.setType(purveyorTransactVO.getWaitCount().intValue()<1?1:0);
|
||||
userVOs.add(purveyorTransactVO);
|
||||
}
|
||||
Integer byCount = tbShopPurveyorRepository.findByCount(criteria.getShopId());
|
||||
Map<String, Object> map = new HashMap<>();
|
||||
map.put("content",userVOs);
|
||||
map.put("totalElements",byCount);
|
||||
return purveyorTransactVOS;
|
||||
|
||||
return map;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -185,6 +97,21 @@ public class TbShopPurveyorTransactServiceImpl implements TbShopPurveyorTransact
|
||||
tbShopPurveyorTransactRepository.save(tbShopPurveyorTransact);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void payTransact(TbShopPurveyorTransact resources) {
|
||||
TbShopPurveyorTransact tbShopPurveyorTransact = tbShopPurveyorTransactRepository.findById(resources.getId()).orElseGet(TbShopPurveyorTransact::new);
|
||||
ValidationUtil.isNull( tbShopPurveyorTransact.getId(),"TbShopPurveyorTransact","id",resources.getId());
|
||||
tbShopPurveyorTransact.setPaidAmount(tbShopPurveyorTransact.getPaidAmount().add(resources.getPaidAmount()));
|
||||
tbShopPurveyorTransact.setWaitAmount(tbShopPurveyorTransact.getWaitAmount().subtract(resources.getPaidAmount()));
|
||||
tbShopPurveyorTransact.setPaidAt(System.currentTimeMillis());
|
||||
if(tbShopPurveyorTransact.getWaitAmount().subtract(resources.getPaidAmount()).equals(0)){
|
||||
tbShopPurveyorTransact.setStatus(1);
|
||||
}
|
||||
tbShopPurveyorTransactRepository.save(tbShopPurveyorTransact);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void deleteAll(Integer[] ids) {
|
||||
for (Integer id : ids) {
|
||||
|
||||
@@ -1,24 +1,10 @@
|
||||
/*
|
||||
* Copyright 2019-2020 Zheng Jie
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package cn.ysk.cashier.service.shop;
|
||||
|
||||
import cn.ysk.cashier.pojo.shop.TbShopPurveyorTransact;
|
||||
import cn.ysk.cashier.dto.shop.TbShopPurveyorTransactDto;
|
||||
import cn.ysk.cashier.dto.shop.TbShopPurveyorTransactQueryCriteria;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import cn.ysk.cashier.vo.PurveyorTransactVO;
|
||||
import org.springframework.data.domain.Page;
|
||||
import java.util.Map;
|
||||
import java.util.List;
|
||||
import java.io.IOException;
|
||||
@@ -38,7 +24,7 @@ public interface TbShopPurveyorTransactService {
|
||||
* @return Map<String,Object>
|
||||
*/
|
||||
Map<String,Object> queryPurveyorTransact(TbShopPurveyorTransactQueryCriteria criteria);
|
||||
Map<String, Object> queryTransactDate(TbShopPurveyorTransactQueryCriteria criteria, Pageable pageable);
|
||||
Page<PurveyorTransactVO> queryTransactDate(TbShopPurveyorTransactQueryCriteria criteria);
|
||||
|
||||
Map<String, Object> queryTransactSum(TbShopPurveyorTransactQueryCriteria criteria);
|
||||
|
||||
@@ -69,6 +55,8 @@ public interface TbShopPurveyorTransactService {
|
||||
*/
|
||||
void update(TbShopPurveyorTransact resources);
|
||||
|
||||
void payTransact(TbShopPurveyorTransact resources);
|
||||
|
||||
/**
|
||||
* 多选删除
|
||||
* @param ids /
|
||||
|
||||
Reference in New Issue
Block a user