供应商

This commit is contained in:
wangw 2024-06-26 14:20:53 +08:00
parent 29299d3689
commit 6f9afcb246
6 changed files with 107 additions and 187 deletions

View File

@ -44,23 +44,15 @@ public class TbShopPurveyorTransactController {
private final TbShopPurveyorTransactService tbShopPurveyorTransactService;
@ApiOperation("导出数据")
@GetMapping(value = "/download")
@PreAuthorize("@el.check('tbShopPurveyorTransact:list')")
public void exportTbShopPurveyorTransact(HttpServletResponse response, TbShopPurveyorTransactQueryCriteria criteria) throws IOException {
tbShopPurveyorTransactService.download(tbShopPurveyorTransactService.queryAll(criteria), response);
}
/**
* 进货账目
* 供应商列表
* @param criteria
* @param pageable
* @return
*/
@GetMapping
@ApiOperation("查询帐目往来")
public ResponseEntity<Object> queryTbShopPurveyorTransactSum(TbShopPurveyorTransactQueryCriteria criteria, Pageable pageable){
return new ResponseEntity<>(tbShopPurveyorTransactService.queryTransactDate(criteria,pageable),HttpStatus.OK);
@ApiOperation("供应商列表")
public ResponseEntity<Object> queryTransactDate(TbShopPurveyorTransactQueryCriteria criteria){
return new ResponseEntity<>(tbShopPurveyorTransactService.queryTransactDate(criteria),HttpStatus.OK);
}
/**
@ -79,10 +71,17 @@ public class TbShopPurveyorTransactController {
* @return
*/
@GetMapping("/sum")
public ResponseEntity<Object> queryTransactSum( TbShopPurveyorTransactQueryCriteria criteria){
public ResponseEntity<Object> queryTransactSum(TbShopPurveyorTransactQueryCriteria criteria){
return new ResponseEntity<>(tbShopPurveyorTransactService.queryTransactSum(criteria),HttpStatus.OK);
}
@PostMapping("/payTransact")
@ApiOperation("账单付款")
public ResponseEntity<Object> payTransact(@RequestBody TbShopPurveyorTransact resources){
tbShopPurveyorTransactService.payTransact(resources);
return new ResponseEntity<>(HttpStatus.OK);
}
@PostMapping
@ApiOperation("新增帐目往来")
public ResponseEntity<Object> createTbShopPurveyorTransact(@Validated @RequestBody TbShopPurveyorTransact resources){

View File

@ -1,41 +1,35 @@
/*
* 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.dto.shop;
import lombok.Data;
import java.util.List;
import cn.ysk.cashier.annotation.Query;
import org.apache.commons.lang3.StringUtils;
/**
* @website https://eladmin.vip
* @author lyf
* @date 2024-01-23
**/
* @author lyf
* @website https://eladmin.vip
* @date 2024-01-23
**/
@Data
public class TbShopPurveyorTransactQueryCriteria{
public class TbShopPurveyorTransactQueryCriteria {
/** 精确 */
/**
* 精确
*/
@Query
private String shopId;
/** 精确 */
/**
* 精确
*/
@Query(type = Query.Type.LEFT_LIKE)
private String purveyorName;
/** 精确 */
/**
* 精确
*/
@Query
private String purveyorId;
/**
@ -54,11 +48,21 @@ public class TbShopPurveyorTransactQueryCriteria{
private Integer size;
private String sort;
public void setShopId(String shopId) {
if (StringUtils.isNotBlank(shopId) && !shopId.equals("1")) {
this.shopId = shopId;
}
}
public void setStatus(Integer status) {
if (status != null) {
this.status = status;
}
}
public void setType(String type) {
if (StringUtils.isNotBlank(type)) {
this.type = type;
}
}
}

View File

@ -1,22 +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.repository.shop;
import cn.ysk.cashier.pojo.shop.TbShopPurveyorTransact;
import cn.ysk.cashier.vo.PurveyorTransactVO;
import org.apache.ibatis.annotations.Param;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
@ -30,14 +18,7 @@ import java.util.Map;
**/
public interface TbShopPurveyorTransactRepository extends JpaRepository<TbShopPurveyorTransact, Integer>, JpaSpecificationExecutor<TbShopPurveyorTransact> {
// @Query("SELECT sum(transact.waitAmount) as waitAmount,count(transact.id) as waitCount, transact.purveyorId as purveyorId, from TbShopPurveyorTransact transact " +
// "where transact.purveyorId = :purveyorId and transact.type =:type GROUP BY transact.purveyorId")
// List<Map<String,Object>> findByPurveyorIds(@Param("purveyorId") String purveyorId, @Param("type") String type);
// @Query(value = "select transact.* from tb_shop_purveyor_transact transact where transact.shop_id =:shopId and transact.status =:status " +
// "GROUP BY transact.purveyor_id LIMIT :page, :size ", nativeQuery = true)
// List<TbShopPurveyorTransact> findByGroup(@Param("status")Integer status, @Param("shopId") String shopId,@Param("page") Integer page, @Param("size") Integer size);
//
@Query(value = "SELECT\n" +
@Query(value = "SELECT " +
"IFNULL(sum( b.wait_amount ), 0 ) AS waitAmount," +
"IFNULL(count( b.id ), 0 ) AS waitCount," +
"IFNULL(SUM(b.paid_amount),0) AS paidAmount," +
@ -46,10 +27,31 @@ public interface TbShopPurveyorTransactRepository extends JpaRepository<TbShopPu
" tb_shop_purveyor_transact b" +
" WHERE" +
" b.purveyor_id = :purveyorId" +
" AND b.type = :type",nativeQuery = true)
" AND (:type IS NULL OR b.type = :type)",nativeQuery = true)
Map<String,Object> findBySum(@Param("purveyorId") String purveyorId,@Param("type")String type);
//
@Query("SELECT new cn.ysk.cashier.vo.PurveyorTransactVO(" +
"b.id," +
"b.purveyorName," +
"b.purveyorTelephone," +
"b.address," +
"b.remark," +
"b.lastTransactAt," +
"sum(a.waitAmount) ," +
"count(a.id)) " +
"from " +
"TbShopPurveyor b " +
"LEFT JOIN TbShopPurveyorTransact a ON a.purveyorId = b.id " +
"WHERE " +
"1=1 " +
"AND (:type IS NULL OR a.type = :type )" +
"AND (:shopId IS NULL OR b.shopId = :shopId) " +
"AND (:name IS NULL OR b.purveyorName LIKE %:name%) " +
"GROUP BY b.id " +
"order by b.lastTransactAt desc,a.purveyorId")
Page<PurveyorTransactVO> queryTransactDate(String type, String shopId, String name, Pageable page);
@Query(value = "SELECT IFNULL(count(b.id),0) AS waitNumber FROM tb_shop_purveyor_transact b WHERE" +
" b.purveyor_id = :purveyorId AND b.type = :type AND b.`status`= :status",nativeQuery = true)
" b.purveyor_id = :purveyorId AND (:type IS NULL OR b.type = :type) AND b.`status`= :status",nativeQuery = true)
Map<String,Object> findByStatusSum(@Param("purveyorId") String purveyorId,@Param("type")String type,@Param("status")Integer status);
}

View File

@ -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);

View File

@ -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) {

View File

@ -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 /