no message
parent
4ad74a1dc9
commit
f97b445d30
|
|
@ -0,0 +1,13 @@
|
|||
package com.youchain.basicdata.inputJson;
|
||||
|
||||
import cn.idev.excel.annotation.ExcelProperty;
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class StockImportForm {
|
||||
@ExcelProperty("代码")
|
||||
private String code;
|
||||
|
||||
@ExcelProperty("类型")
|
||||
private String stockType;
|
||||
}
|
||||
|
|
@ -16,7 +16,9 @@
|
|||
package com.youchain.basicdata.repository;
|
||||
|
||||
import com.youchain.basicdata.domain.Stock;
|
||||
import com.youchain.basicdata.service.dto.StockExcelDto;
|
||||
import com.youchain.businessdata.domain.Inventory;
|
||||
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;
|
||||
|
|
@ -45,4 +47,11 @@ public interface StockRepository extends JpaRepository<Stock, Long>, JpaSpecific
|
|||
|
||||
@Query(" from Stock s where s.point.area.name = :areaName and s.point.id > 0 and s.point.enabled=true and s.point.status = 'USED' and s.status = :status and s.enabled = true ")
|
||||
List<Stock> findByFreeOrUsedStock(String areaName, String status);
|
||||
|
||||
@Query(value = "select stock.id,stock.code, stock.stock_type as stockType " +
|
||||
"from base_stock stock " +
|
||||
"where (:stockCode is null or stock.code = :stockCode) " +
|
||||
"and stock.id > :lastId " +
|
||||
"order by stock.id asc ", nativeQuery = true)
|
||||
List<StockExcelDto> listByStocks(Long lastId, String stockCode, Pageable pageable);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -68,7 +68,7 @@ public class StockController {
|
|||
stockService.download(stockService.queryAll(criteria), response);
|
||||
}
|
||||
|
||||
@Log("导出 @author 卓大")
|
||||
@Log("导出数据")
|
||||
@ApiOperation("导出数据")
|
||||
@GetMapping("/download")
|
||||
public void exportStocks(HttpServletResponse response,StockQueryCriteria criteria){
|
||||
|
|
|
|||
|
|
@ -20,6 +20,7 @@ import com.youchain.appupdate.ReturnJson.ReturnTaskVo;
|
|||
import com.youchain.basicdata.domain.Point;
|
||||
import com.youchain.basicdata.domain.Stock;
|
||||
import com.youchain.basicdata.service.dto.StockDto;
|
||||
import com.youchain.basicdata.service.dto.StockExcelDto;
|
||||
import com.youchain.basicdata.service.dto.StockQueryCriteria;
|
||||
import com.youchain.basicdata.vo.StockExcelVO;
|
||||
import com.youchain.businessdata.domain.Pick;
|
||||
|
|
@ -171,7 +172,7 @@ public interface StockService {
|
|||
* @param criteria 查询参数
|
||||
* @return List<Stock>
|
||||
*/
|
||||
List<Stock> listByStocks(Long lastId, int pageSize, StockQueryCriteria criteria);
|
||||
List<StockExcelDto> listByStocks(Long lastId, int pageSize, StockQueryCriteria criteria);
|
||||
|
||||
/**
|
||||
* 导出
|
||||
|
|
|
|||
|
|
@ -0,0 +1,9 @@
|
|||
package com.youchain.basicdata.service.dto;
|
||||
|
||||
public interface StockExcelDto {
|
||||
Long getId();
|
||||
|
||||
String getCode();
|
||||
|
||||
String getStockType();
|
||||
}
|
||||
|
|
@ -15,7 +15,11 @@
|
|||
*/
|
||||
package com.youchain.basicdata.service.impl;
|
||||
|
||||
import cn.idev.excel.FastExcel;
|
||||
import com.youchain.basicdata.inputJson.StockImportForm;
|
||||
import com.youchain.basicdata.service.dto.StockExcelDto;
|
||||
import com.youchain.basicdata.vo.StockExcelVO;
|
||||
import org.apache.commons.collections4.CollectionUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import cn.hutool.poi.excel.ExcelReader;
|
||||
import cn.hutool.poi.excel.ExcelUtil;
|
||||
|
|
@ -39,6 +43,7 @@ import com.youchain.basicdata.service.dto.StockDto;
|
|||
import com.youchain.basicdata.service.dto.StockQueryCriteria;
|
||||
import com.youchain.basicdata.service.mapstruct.StockMapper;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.data.domain.PageRequest;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.data.domain.Page;
|
||||
|
|
@ -158,17 +163,23 @@ public class StockServiceImpl implements StockService {
|
|||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public String importStock(MultipartFile multipartFile) {
|
||||
FileUtil.checkSize(properties.getMaxSize(), multipartFile.getSize());
|
||||
String suffix = FileUtil.getExtensionName(multipartFile.getOriginalFilename());
|
||||
String type = FileUtil.getFileType(suffix);
|
||||
File file = FileUtil.upload(multipartFile, properties.getPath().getPath() + type + File.separator);
|
||||
ExcelReader reader = ExcelUtil.getReader(file);
|
||||
List<StockImportForm> dataList;
|
||||
try {
|
||||
dataList = FastExcel.read(multipartFile.getInputStream()).head(StockImportForm.class)
|
||||
.sheet()
|
||||
.doReadSync();
|
||||
} catch (IOException e) {
|
||||
throw new BadRequestException("数据格式存在问题,无法读取");
|
||||
}
|
||||
if (CollectionUtils.isEmpty(dataList)) {
|
||||
throw new BadRequestException("数据为空");
|
||||
}
|
||||
|
||||
|
||||
List<Map<String, Object>> readAll = reader.readAll();
|
||||
Set<String> stockCodes = new HashSet<>();//容器集合
|
||||
for (Map<String, Object> record : readAll) {
|
||||
String stockCode = record.get("代码").toString().trim();
|
||||
if (!StringUtils.isEmpty(stockCode)) {
|
||||
for (StockImportForm stockImportForm : dataList) {
|
||||
String stockCode = stockImportForm.getCode();
|
||||
if (StringUtils.isNoneBlank(stockCode)) {
|
||||
stockCodes.add(stockCode);
|
||||
}
|
||||
}
|
||||
|
|
@ -182,10 +193,9 @@ public class StockServiceImpl implements StockService {
|
|||
//修改容器集合
|
||||
List<Stock> stocksToUpdate = new ArrayList<>();
|
||||
|
||||
for (Map<String, Object> record : readAll) {
|
||||
String stockCode = record.get("代码").toString().trim();
|
||||
String stockType = record.get("类型").toString().trim();
|
||||
|
||||
for (StockImportForm stockImportForm : dataList) {
|
||||
String stockCode = stockImportForm.getCode();
|
||||
String stockType = stockImportForm.getStockType();
|
||||
//判断是否已存在容器
|
||||
if (existingStock.containsKey(stockCode)) {
|
||||
//修改容器
|
||||
|
|
@ -193,15 +203,17 @@ public class StockServiceImpl implements StockService {
|
|||
stocksToUpdate.add(updateStock(stock, stockType));
|
||||
} else {
|
||||
//新增容器
|
||||
stocksToCreate.add(createStock(stockType, UserUtils.getDept(), record));
|
||||
stocksToCreate.add(createStock(stockType, UserUtils.getDept(), stockCode));
|
||||
}
|
||||
}
|
||||
//批量新增Mo票
|
||||
|
||||
|
||||
//批量新增容器
|
||||
if (!stocksToCreate.isEmpty()) {
|
||||
stockRepository.saveAll(stocksToCreate);
|
||||
}
|
||||
|
||||
//批量更新Mo票
|
||||
//批量更新容器
|
||||
if (!stocksToUpdate.isEmpty()) {
|
||||
stockRepository.saveAll(stocksToUpdate);
|
||||
}
|
||||
|
|
@ -235,29 +247,13 @@ public class StockServiceImpl implements StockService {
|
|||
}
|
||||
|
||||
@Override
|
||||
public List<Stock> listByStocks(Long lastId, int pageSize, StockQueryCriteria criteria) {
|
||||
// 构建基础 HQL 查询语句
|
||||
String hql = "SELECT s FROM Stock s WHERE 1=1 ";
|
||||
if (StringUtils.isNotEmpty(criteria.getCode())) {
|
||||
hql += " AND s.code ='" + criteria.getCode() + "' ";
|
||||
}
|
||||
|
||||
// 添加游标条件:只获取比当前游标大的 id 的记录
|
||||
if (lastId != null) {
|
||||
hql += " AND s.id > " + lastId;
|
||||
}
|
||||
|
||||
// 按照 id 排序,确保结果集顺序一致
|
||||
hql += " ORDER BY s.id ASC";
|
||||
|
||||
// 创建查询对象
|
||||
TypedQuery<Stock> query = entityMapper.createQuery(hql, Stock.class);
|
||||
|
||||
// 设置分页大小
|
||||
query.setMaxResults(pageSize);
|
||||
|
||||
|
||||
return query.getResultList();
|
||||
public List<StockExcelDto> listByStocks(Long lastId, int pageSize, StockQueryCriteria criteria) {
|
||||
long startTime = System.currentTimeMillis();
|
||||
Pageable pageable = PageRequest.of(0, pageSize);
|
||||
String stockCode = criteria.getCode();
|
||||
List<StockExcelDto> list = stockRepository.listByStocks(lastId, stockCode, pageable);
|
||||
log.info("SQL耗时: {}ms", System.currentTimeMillis() - startTime);
|
||||
return list;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -273,7 +269,7 @@ public class StockServiceImpl implements StockService {
|
|||
.code(stock.getCode())
|
||||
.type(stock.getStockType())
|
||||
.build(),
|
||||
Stock::getId,
|
||||
StockExcelDto::getId,
|
||||
2000
|
||||
);
|
||||
} catch (IOException e) {
|
||||
|
|
@ -333,10 +329,10 @@ public class StockServiceImpl implements StockService {
|
|||
return stockRepository.findByPointCode(code);
|
||||
}
|
||||
|
||||
private Stock createStock(String stockType, Dept dept, Map<String, Object> record) {
|
||||
private Stock createStock(String stockType, Dept dept, String code) {
|
||||
Stock stock = new Stock();
|
||||
stock.setCode(record.get("代码").toString().trim());
|
||||
stock.setName(record.get("代码").toString().trim());
|
||||
stock.setCode(code);
|
||||
stock.setName(code);
|
||||
stock.setStockType(stockType);
|
||||
stock.setDept(dept);
|
||||
stock.setStatus(BaseStatus.FREE);
|
||||
|
|
|
|||
|
|
@ -22,7 +22,6 @@ import java.net.URLEncoder;
|
|||
import java.util.Collection;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.function.BiConsumer;
|
||||
import java.util.function.BiFunction;
|
||||
import java.util.function.Function;
|
||||
import java.util.function.ToLongFunction;
|
||||
|
|
|
|||
Loading…
Reference in New Issue