耗材分类查询接口增加已绑定数量字段

This commit is contained in:
SongZhang 2024-07-12 10:45:16 +08:00
parent 5226b1719a
commit 86c39780ee
4 changed files with 23 additions and 5 deletions

View File

@ -64,6 +64,9 @@ public class TbConsType implements Serializable {
@ApiModelProperty(value = "店铺id")
private Integer shopId;
@Transient
private int productNum;
public void copy(TbConsType source){
BeanUtil.copyProperties(source,this, CopyOptions.create().setIgnoreNullValue(true));
}

View File

@ -3,6 +3,7 @@ package cn.ysk.cashier.cons.repository;
import cn.ysk.cashier.cons.domain.TbConsType;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
/**
* @website https://eladmin.vip
@ -14,4 +15,7 @@ public interface TbConsTypeRepository extends JpaRepository<TbConsType, Integer>
int countByConTypeCode(String conTypeCode);
TbConsType findByConTypeCode(String conTypeCode);
}
@Query("SELECT count(*) FROM TbProskuCon c LEFT JOIN TbConsInfo i ON c.conInfoId = i.id WHERE i.conTypeId = :id")
int countProByTypeId(Integer id);
}

View File

@ -45,4 +45,5 @@ public class TbConsTypeDto implements Serializable {
/** 店铺id */
private Integer shopId;
}
private int productNum;
}

View File

@ -38,8 +38,18 @@ public class TbConsTypeServiceImpl implements TbConsTypeService {
@Override
public Map<String,Object> queryAll(TbConsTypeQueryCriteria criteria, Pageable pageable){
Page<TbConsType> page = tbConsTypeRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root,criteria,criteriaBuilder),pageable);
return PageUtil.toPage(page.map(tbConsTypeMapper::toDto));
Page<TbConsType> page = tbConsTypeRepository
.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root,criteria,criteriaBuilder),pageable);
for (TbConsType tbConsType : page.getContent()) {
tbConsType.setProductNum(tbConsTypeRepository.countProByTypeId(tbConsType.getId()));
}
Map<String,Object> map = new LinkedHashMap<>(2);
map.put("content",page.getContent());
map.put("totalElements",page.getTotalElements());
return map;
}
@Override
@ -105,4 +115,4 @@ public class TbConsTypeServiceImpl implements TbConsTypeService {
}
FileUtil.downloadExcel(list, response);
}
}
}