Compare commits
No commits in common. "e0ce8e5a68430da02144469cd8426591887a6046" and "8ed948e6088983587031870b82bed06750c8a5d8" have entirely different histories.
e0ce8e5a68
...
8ed948e608
|
|
@ -5,27 +5,26 @@ import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
|
||||||
import com.syjiaer.clinic.server.common.constants.Constants;
|
import com.syjiaer.clinic.server.common.constants.Constants;
|
||||||
import com.syjiaer.clinic.server.common.enums.*;
|
import com.syjiaer.clinic.server.common.enums.*;
|
||||||
import com.syjiaer.clinic.server.common.exception.MessageException;
|
import com.syjiaer.clinic.server.common.exception.MessageException;
|
||||||
import com.syjiaer.clinic.server.common.util.HttpUtil;
|
import com.syjiaer.clinic.server.common.util.DateUtil;
|
||||||
import com.syjiaer.clinic.server.common.vo.Page;
|
import com.syjiaer.clinic.server.common.vo.Page;
|
||||||
import com.syjiaer.clinic.server.entity.goods.Goods;
|
import com.syjiaer.clinic.server.entity.goods.Goods;
|
||||||
import com.syjiaer.clinic.server.entity.goods.GoodsCate;
|
|
||||||
import com.syjiaer.clinic.server.entity.inventory.*;
|
import com.syjiaer.clinic.server.entity.inventory.*;
|
||||||
import com.syjiaer.clinic.server.entity.inventory.dto.PurchaseOrderQuery;
|
import com.syjiaer.clinic.server.entity.inventory.dto.PurchaseOrderQuery;
|
||||||
import com.syjiaer.clinic.server.entity.inventory.vo.InventoryGoodsVo;
|
import com.syjiaer.clinic.server.entity.inventory.vo.InventoryGoodsVo;
|
||||||
import com.syjiaer.clinic.server.entity.inventory.vo.InventoryPurchaseVo;
|
import com.syjiaer.clinic.server.entity.inventory.vo.InventoryPurchaseVo;
|
||||||
import com.syjiaer.clinic.server.entity.manager.ManagerUser;
|
import com.syjiaer.clinic.server.entity.manager.ManagerUser;
|
||||||
import com.syjiaer.clinic.server.mapper.goods.GoodsCateMapper;
|
|
||||||
import com.syjiaer.clinic.server.mapper.goods.GoodsMapper;
|
import com.syjiaer.clinic.server.mapper.goods.GoodsMapper;
|
||||||
import com.syjiaer.clinic.server.mapper.inventory.*;
|
import com.syjiaer.clinic.server.mapper.inventory.*;
|
||||||
import com.syjiaer.clinic.server.mapper.manager.ManagerUserMapper;
|
import com.syjiaer.clinic.server.mapper.manager.ManagerUserMapper;
|
||||||
import com.syjiaer.clinic.server.service.BaseService;
|
import com.syjiaer.clinic.server.service.BaseService;
|
||||||
import com.syjiaer.clinic.server.service.goods.GoodsService;
|
import com.syjiaer.clinic.server.service.goods.GoodsService;
|
||||||
import lombok.val;
|
import jakarta.annotation.Resource;
|
||||||
import org.apache.poi.ss.usermodel.*;
|
import org.apache.poi.ss.usermodel.*;
|
||||||
import org.springframework.beans.BeanUtils;
|
import org.springframework.beans.BeanUtils;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
import org.springframework.util.ResourceUtils;
|
||||||
|
|
||||||
import java.io.*;
|
import java.io.*;
|
||||||
import java.math.BigDecimal;
|
import java.math.BigDecimal;
|
||||||
|
|
@ -33,8 +32,6 @@ import java.math.RoundingMode;
|
||||||
import java.text.SimpleDateFormat;
|
import java.text.SimpleDateFormat;
|
||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.logging.Logger;
|
|
||||||
|
|
||||||
@Service
|
@Service
|
||||||
public class InventoryPurchaseService extends BaseService {
|
public class InventoryPurchaseService extends BaseService {
|
||||||
@Autowired
|
@Autowired
|
||||||
|
|
@ -57,10 +54,8 @@ public class InventoryPurchaseService extends BaseService {
|
||||||
private InventoryPurchaseMapper inventoryPurchaseMapper;
|
private InventoryPurchaseMapper inventoryPurchaseMapper;
|
||||||
@Autowired
|
@Autowired
|
||||||
private InventoryPurchaseLogMapper inventoryPurchaseLogMapper;
|
private InventoryPurchaseLogMapper inventoryPurchaseLogMapper;
|
||||||
@Autowired
|
|
||||||
private GoodsCateMapper goodsCateMapper;
|
|
||||||
|
|
||||||
private Logger logger = Logger.getLogger(HttpUtil.class.getName());
|
|
||||||
/*
|
/*
|
||||||
* 创建采购订单
|
* 创建采购订单
|
||||||
* @param inventoryPurchase 采购订单
|
* @param inventoryPurchase 采购订单
|
||||||
|
|
@ -428,112 +423,41 @@ public class InventoryPurchaseService extends BaseService {
|
||||||
}
|
}
|
||||||
public String toExcel(List<Integer> cateIdList){
|
public String toExcel(List<Integer> cateIdList){
|
||||||
|
|
||||||
//查询goodsCate
|
|
||||||
QueryWrapper<GoodsCate> goodsCateQueryWrapper = new QueryWrapper<>();
|
|
||||||
goodsCateQueryWrapper.in("id", cateIdList);
|
|
||||||
List<GoodsCate> goodsCatesList = goodsCateMapper.selectList(goodsCateQueryWrapper);
|
|
||||||
|
|
||||||
Map<Integer, String> cateMap = new HashMap<>();
|
|
||||||
|
|
||||||
for (GoodsCate goodsCate : goodsCatesList) {
|
|
||||||
cateMap.put(goodsCate.getId(), goodsCate.getName());
|
|
||||||
}
|
|
||||||
|
|
||||||
//查询goods
|
|
||||||
QueryWrapper<Goods> goodsWrapper = new QueryWrapper<>();
|
|
||||||
goodsWrapper.in("cate_id", cateIdList);
|
|
||||||
List<Goods> goodsList = goodsMapper.selectList(goodsWrapper);
|
|
||||||
System.out.println(goodsList);
|
|
||||||
|
|
||||||
/*
|
|
||||||
表格拼接字段映射
|
|
||||||
|
|
||||||
药品编码 id
|
|
||||||
药品 name
|
|
||||||
规格 min_packaging_number min_packaging_unit / packaging_unit
|
|
||||||
厂家 producer
|
|
||||||
分类 type
|
|
||||||
二级分类 goodsCate表中的name
|
|
||||||
单位 packaging_unit
|
|
||||||
*/
|
|
||||||
|
|
||||||
String fileName="";
|
|
||||||
try {
|
try {
|
||||||
|
|
||||||
|
|
||||||
ClassLoader classLoader = getClass().getClassLoader();
|
ClassLoader classLoader = getClass().getClassLoader();
|
||||||
// 资源文件的路径
|
// 资源文件的路径
|
||||||
InputStream inputStream = classLoader.getResourceAsStream("excelTemplate/PurchasingTemplate.xlsx");
|
InputStream inputStream = classLoader.getResourceAsStream("excelTemplate/PurchasingTemplate.xlsx");
|
||||||
|
Workbook workbook = WorkbookFactory.create(inputStream);
|
||||||
|
|
||||||
if (inputStream == null)
|
// 2. 获取第一个Sheet
|
||||||
{
|
Sheet sheet = workbook.getSheetAt(0);
|
||||||
throw new MessageException("模板表格文件获取失败");
|
|
||||||
|
// 3. 修改内容(例如在A1单元格写入新内容)
|
||||||
|
Row row = sheet.getRow(10);
|
||||||
|
if (row == null) {
|
||||||
|
row = sheet.createRow(10);
|
||||||
}
|
}
|
||||||
|
Cell cell = row.getCell(0);
|
||||||
Workbook workbook = WorkbookFactory.create(inputStream);
|
if (cell == null) {
|
||||||
|
cell = row.createCell(0);
|
||||||
// 2. 获取第一个Sheet
|
|
||||||
Sheet sheet = workbook.getSheetAt(0);
|
|
||||||
|
|
||||||
// 此处配置5等于表格里面的第6行
|
|
||||||
int sheetRowNum = 5;
|
|
||||||
|
|
||||||
for (Goods goodsRow : goodsList) {
|
|
||||||
sheetRowNum = sheetRowNum + 1;
|
|
||||||
|
|
||||||
Row excelSheetRow = sheet.getRow(sheetRowNum);
|
|
||||||
|
|
||||||
if (excelSheetRow == null) {
|
|
||||||
excelSheetRow = sheet.createRow(sheetRowNum);
|
|
||||||
}
|
|
||||||
|
|
||||||
setCellValue(excelSheetRow,0,goodsRow.getId());
|
|
||||||
setCellValue(excelSheetRow,1,goodsRow.getName());
|
|
||||||
|
|
||||||
String packagingString = goodsRow.getMinPackagingNumber() + goodsRow.getMinPackagingUnit() + "/" + goodsRow.getPackagingUnit();
|
|
||||||
setCellValue(excelSheetRow,2,packagingString);
|
|
||||||
|
|
||||||
setCellValue(excelSheetRow,3,goodsRow.getProducer());
|
|
||||||
|
|
||||||
String desc="";
|
|
||||||
GoodsTypeEnum goodsTypeEnum = GoodsTypeEnum.getByType(goodsRow.getType());
|
|
||||||
if(goodsTypeEnum!=null){
|
|
||||||
desc = goodsTypeEnum.getDesc();
|
|
||||||
}
|
|
||||||
setCellValue(excelSheetRow,4,desc);
|
|
||||||
|
|
||||||
String cateName = cateMap.getOrDefault(goodsRow.getCateId(),"");
|
|
||||||
|
|
||||||
setCellValue(excelSheetRow,5,cateName);
|
|
||||||
setCellValue(excelSheetRow,6,goodsRow.getPackagingUnit());
|
|
||||||
}
|
}
|
||||||
//生成系统临时文件
|
cell.setCellValue("你好");
|
||||||
File file = File.createTempFile("excel", ".xlsx");
|
|
||||||
|
|
||||||
// 4. 保存为新文件
|
// 4. 保存为新文件
|
||||||
FileOutputStream outFile = new FileOutputStream(file);
|
FileOutputStream outFile = new FileOutputStream("D:\\new_excel.xlsx");
|
||||||
workbook.write(outFile);
|
workbook.write(outFile);
|
||||||
|
|
||||||
// 5. 关闭流
|
// 5. 关闭流
|
||||||
outFile.close();
|
outFile.close();
|
||||||
inputStream.close();
|
inputStream.close();
|
||||||
fileName=file.getAbsolutePath();
|
|
||||||
System.out.println("Excel文件生成成功!");
|
System.out.println("Excel文件生成成功!");
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
logger.warning(e.getMessage());
|
e.printStackTrace();
|
||||||
throw new MessageException("excel创建失败");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return fileName;
|
return "";
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
private void setCellValue(Row row, int column, Object value) {
|
|
||||||
Cell cell = row.getCell(column, Row.MissingCellPolicy.CREATE_NULL_AS_BLANK);
|
|
||||||
if (value == null) {
|
|
||||||
cell.setCellValue("");
|
|
||||||
} else if (value instanceof Number) {
|
|
||||||
cell.setCellValue(((Number) value).doubleValue());
|
|
||||||
} else {
|
|
||||||
cell.setCellValue(value.toString());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue