
9 changed files with 372 additions and 0 deletions
@ -0,0 +1,25 @@ |
|||||
|
package com.yxt.supervise.gf.biz.inventory; |
||||
|
|
||||
|
import com.baomidou.mybatisplus.core.conditions.Wrapper; |
||||
|
import com.baomidou.mybatisplus.core.mapper.BaseMapper; |
||||
|
import com.baomidou.mybatisplus.core.metadata.IPage; |
||||
|
import com.baomidou.mybatisplus.core.toolkit.Constants; |
||||
|
import com.yxt.supervise.gf.api.inventory.Inventory; |
||||
|
import com.yxt.supervise.gf.api.inventory.InventoryVo; |
||||
|
import org.apache.ibatis.annotations.Mapper; |
||||
|
import org.apache.ibatis.annotations.Param; |
||||
|
import org.apache.ibatis.annotations.Select; |
||||
|
|
||||
|
import java.util.List; |
||||
|
|
||||
|
/** |
||||
|
* @author feikefei |
||||
|
* @create 2023-07-12-15:43 |
||||
|
*/ |
||||
|
@Mapper |
||||
|
public interface InventoryMapper extends BaseMapper<Inventory> { |
||||
|
IPage<InventoryVo> selectPageVo(IPage<Inventory> page, @Param(Constants.WRAPPER) Wrapper<Inventory> qw); |
||||
|
|
||||
|
@Select("select * from inventory where storehouse_name = #{storehouse_name}") |
||||
|
List<Inventory> selectInventoryByStorehouseName(@Param("storehouse_name") String storehouse_name); |
||||
|
} |
@ -0,0 +1,14 @@ |
|||||
|
<?xml version="1.0" encoding="UTF-8" ?> |
||||
|
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> |
||||
|
<mapper namespace="com.yxt.supervise.gf.biz.inventory.InventoryMapper"> |
||||
|
<select id="selectPageVo" resultType="com.yxt.supervise.gf.api.inventory.InventoryVo"> |
||||
|
SELECT |
||||
|
* |
||||
|
FROM |
||||
|
inventory |
||||
|
<where> |
||||
|
${ew.sqlSegment} |
||||
|
</where> |
||||
|
</select> |
||||
|
|
||||
|
</mapper> |
@ -0,0 +1,47 @@ |
|||||
|
package com.yxt.supervise.gf.biz.inventory; |
||||
|
|
||||
|
import com.yxt.common.core.query.PagerQuery; |
||||
|
import com.yxt.common.core.result.ResultBean; |
||||
|
import com.yxt.common.core.vo.PagerVo; |
||||
|
import com.yxt.supervise.gf.api.inventory.InventoryQuery; |
||||
|
import com.yxt.supervise.gf.api.inventory.InventoryVo; |
||||
|
import com.yxt.supervise.gf.shanhai.req.InventoryIndex; |
||||
|
import io.swagger.annotations.Api; |
||||
|
import io.swagger.annotations.ApiOperation; |
||||
|
import org.springframework.beans.factory.annotation.Autowired; |
||||
|
import org.springframework.web.bind.annotation.*; |
||||
|
|
||||
|
import javax.servlet.http.HttpServletResponse; |
||||
|
|
||||
|
/** |
||||
|
* @author feikefei |
||||
|
* @create 2023-07-12-15:42 |
||||
|
*/ |
||||
|
@Api(value = "货物库存明细表") |
||||
|
@RestController |
||||
|
@RequestMapping("gf/inventory") |
||||
|
public class InventoryRest { |
||||
|
|
||||
|
@Autowired |
||||
|
private InventoryService inventoryService; |
||||
|
|
||||
|
@PostMapping("/save") |
||||
|
@ApiOperation("添加入库数据") |
||||
|
public ResultBean save(@RequestBody InventoryIndex inventoryIndex){ |
||||
|
return inventoryService.save(inventoryIndex); |
||||
|
} |
||||
|
|
||||
|
@PostMapping("/listPage") |
||||
|
@ApiOperation("分页查询") |
||||
|
public ResultBean listPage(@RequestBody PagerQuery<InventoryQuery> pq){ |
||||
|
ResultBean rb = ResultBean.fireFail(); |
||||
|
PagerVo<InventoryVo> pagerVo = inventoryService.listPage(pq); |
||||
|
return rb.success().setData(pagerVo); |
||||
|
} |
||||
|
|
||||
|
@PostMapping("/export/{storehouse_name}") |
||||
|
@ApiOperation("导出数据") |
||||
|
public void export(@PathVariable String storehouse_name, HttpServletResponse response) throws Exception{ |
||||
|
inventoryService.export(storehouse_name, response); |
||||
|
} |
||||
|
} |
@ -0,0 +1,253 @@ |
|||||
|
package com.yxt.supervise.gf.biz.inventory; |
||||
|
|
||||
|
import cn.hutool.core.bean.BeanUtil; |
||||
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
||||
|
import com.baomidou.mybatisplus.core.metadata.IPage; |
||||
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
||||
|
import com.yxt.common.base.utils.PagerUtil; |
||||
|
import com.yxt.common.core.query.PagerQuery; |
||||
|
import com.yxt.common.core.result.ResultBean; |
||||
|
import com.yxt.common.core.vo.PagerVo; |
||||
|
import com.yxt.supervise.gf.api.inventory.Inventory; |
||||
|
import com.yxt.supervise.gf.api.inventory.InventoryQuery; |
||||
|
import com.yxt.supervise.gf.api.inventory.InventoryVo; |
||||
|
import com.yxt.supervise.gf.shanhai.ShRequester; |
||||
|
import com.yxt.supervise.gf.shanhai.req.InventoryIndex; |
||||
|
import com.yxt.supervise.gf.shanhai.resp.BaseResponse; |
||||
|
import com.yxt.supervise.gf.shanhai.resp.BaseResponseListObj; |
||||
|
import org.apache.poi.ss.usermodel.*; |
||||
|
import org.apache.poi.ss.util.CellRangeAddress; |
||||
|
import org.apache.poi.xssf.usermodel.XSSFWorkbook; |
||||
|
import org.springframework.beans.factory.annotation.Autowired; |
||||
|
import org.springframework.beans.factory.annotation.Value; |
||||
|
import org.springframework.stereotype.Service; |
||||
|
|
||||
|
import javax.servlet.http.HttpServletResponse; |
||||
|
import java.io.File; |
||||
|
import java.io.FileOutputStream; |
||||
|
import java.io.OutputStream; |
||||
|
import java.net.URLEncoder; |
||||
|
import java.text.SimpleDateFormat; |
||||
|
import java.util.Date; |
||||
|
import java.util.List; |
||||
|
|
||||
|
/** |
||||
|
* @author feikefei |
||||
|
* @create 2023-07-12-15:43 |
||||
|
*/ |
||||
|
@Service |
||||
|
public class InventoryService extends ServiceImpl<InventoryMapper, Inventory> { |
||||
|
|
||||
|
@Value("${import.filePath}") |
||||
|
private String filePath; |
||||
|
@Autowired |
||||
|
private HttpServletResponse response; |
||||
|
|
||||
|
public ResultBean save(InventoryIndex inventoryIndex){ |
||||
|
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); |
||||
|
Date date = new Date(); |
||||
|
ResultBean rb = ResultBean.fireFail(); |
||||
|
BaseResponse<BaseResponseListObj<com.yxt.supervise.gf.shanhai.resp.Inventory>> api$system$inventory$index = ShRequester.getApi$system$inventory$index(inventoryIndex); |
||||
|
List<com.yxt.supervise.gf.shanhai.resp.Inventory> list = api$system$inventory$index.getData().getList(); |
||||
|
try { |
||||
|
exportExcel(response,list); |
||||
|
}catch (Exception e){ |
||||
|
e.printStackTrace(); |
||||
|
} |
||||
|
for (com.yxt.supervise.gf.shanhai.resp.Inventory inventory : list) { |
||||
|
Inventory inventory1 = new Inventory(); |
||||
|
BeanUtil.copyProperties(inventory,inventory1); |
||||
|
inventory1.setTime(sdf.format(date)); |
||||
|
baseMapper.insert(inventory1); |
||||
|
} |
||||
|
return rb.success().setMsg("添加成功"); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 添加到数据库数据时生成的表格 |
||||
|
* @param list 导出数据 |
||||
|
* @throws Exception |
||||
|
*/ |
||||
|
public void exportExcel(HttpServletResponse response, List<com.yxt.supervise.gf.shanhai.resp.Inventory> list) throws Exception { |
||||
|
SimpleDateFormat sdf1 = new SimpleDateFormat("yyyyMMddHHmmss"); |
||||
|
XSSFWorkbook wb = new XSSFWorkbook(); |
||||
|
//标题行抽出字段
|
||||
|
String[] head = {"序号","库存数量","仓库编码", "物料id", "物料编码", "物料组id", "物料品牌", "物料名称", "物料单价(成本价)", "最后更新时间", "物料组明文", "最后更新时间明文", "仓库名称"}; |
||||
|
|
||||
|
//设置sheet名称,并创建新的sheet对象
|
||||
|
Sheet stuSheet = wb.createSheet(); |
||||
|
//获取表头行
|
||||
|
Row titleRow = stuSheet.createRow(0); |
||||
|
//创建单元格,设置style居中,字体,单元格大小等
|
||||
|
CellStyle style = wb.createCellStyle(); |
||||
|
Cell cell = null; |
||||
|
//把已经写好的标题行写入excel文件中
|
||||
|
for (int i = 0; i < head.length; i++) { |
||||
|
cell = titleRow.createCell(i); |
||||
|
cell.setCellValue(head[i]); |
||||
|
cell.setCellStyle(style); |
||||
|
} |
||||
|
//把从数据库中取得的数据一一写入excel文件中
|
||||
|
Row row = null; |
||||
|
for (int i = 0; i < list.size(); i++) { |
||||
|
//创建list.size()行数据
|
||||
|
row = stuSheet.createRow(i + 1); |
||||
|
//把值一一写进单元格里
|
||||
|
//设置第一列为自动递增的序号
|
||||
|
row.createCell(0).setCellValue(i + 1); |
||||
|
row.createCell(1).setCellValue(list.get(i).getNum()); |
||||
|
row.createCell(2).setCellValue(list.get(i).getStorehouse_code()); |
||||
|
row.createCell(3).setCellValue(list.get(i).getMateriel_id()); |
||||
|
row.createCell(4).setCellValue(list.get(i).getMateriel_no()); |
||||
|
row.createCell(5).setCellValue(list.get(i).getMateriel_group()); |
||||
|
row.createCell(6).setCellValue(list.get(i).getBrand_name()); |
||||
|
row.createCell(7).setCellValue(list.get(i).getMateriel_name()); |
||||
|
row.createCell(8).setCellValue(list.get(i).getPrice()); |
||||
|
row.createCell(9).setCellValue(list.get(i).getUpdate_time()); |
||||
|
row.createCell(10).setCellValue(list.get(i).getMateriel_group_text()); |
||||
|
row.createCell(11).setCellValue(list.get(i).getUpdate_time_text()); |
||||
|
row.createCell(12).setCellValue(list.get(i).getStorehouse_name()); |
||||
|
} |
||||
|
//设置单元格宽度自适应,在此基础上把宽度调至1.5倍
|
||||
|
for (int i = 0; i < head.length; i++) { |
||||
|
stuSheet.autoSizeColumn(i, true); |
||||
|
stuSheet.setColumnWidth(i, stuSheet.getColumnWidth(i) * 15 / 10); |
||||
|
} |
||||
|
File file = new File(filePath); |
||||
|
if (!file.exists()) { |
||||
|
file.mkdirs(); |
||||
|
} |
||||
|
//设置文件名
|
||||
|
String fileName = sdf1.format(new Date()) + "库存记录" + ".xlsx"; |
||||
|
String savePath = filePath + File.separator + fileName; |
||||
|
//下载
|
||||
|
OutputStream fileOut = new FileOutputStream(savePath); |
||||
|
wb.write(fileOut); |
||||
|
fileOut.close(); |
||||
|
} |
||||
|
|
||||
|
public PagerVo<InventoryVo> listPage(PagerQuery<InventoryQuery> pq){ |
||||
|
InventoryQuery params = pq.getParams(); |
||||
|
QueryWrapper<Inventory> wq = new QueryWrapper<>(); |
||||
|
if (params != null){ |
||||
|
if (params.getStorehouse_name() != null || !params.getStorehouse_name().equals("")) |
||||
|
wq.eq("storehouse_name",params.getStorehouse_name()); |
||||
|
} |
||||
|
IPage<Inventory> page = PagerUtil.queryToPage(pq); |
||||
|
IPage<InventoryVo> inventoryVoIPage = baseMapper.selectPageVo(page, wq); |
||||
|
PagerVo<InventoryVo> vo = PagerUtil.pageToVo(inventoryVoIPage, null); |
||||
|
return vo; |
||||
|
} |
||||
|
|
||||
|
public void export(String storehouse_name, HttpServletResponse response) throws Exception{ |
||||
|
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); |
||||
|
Date date = new Date(); |
||||
|
OutputStream out = response.getOutputStream(); |
||||
|
Workbook wb = new XSSFWorkbook(); |
||||
|
try { |
||||
|
response.setCharacterEncoding("UTF-8"); |
||||
|
response.setContentType("application/octet-stream; charset=utf-8"); |
||||
|
// 下载文件能正常显示中文
|
||||
|
response.setHeader( |
||||
|
"Content-Disposition", |
||||
|
"attachment;filename=" + URLEncoder.encode(storehouse_name + sdf.format(date)+".xlsx", "UTF-8"));//导出的Excel文件名称
|
||||
|
// response.setHeader("Access-Control-Expose-Headers", "FileName");
|
||||
|
List<Inventory> inventories = baseMapper.selectInventoryByStorehouseName(storehouse_name);//数据查询--需要导出的数据
|
||||
|
//行标题设置
|
||||
|
String[] headList = {"序号","仓库名称", "物料组", "物料编号", "物料名称", "物料品牌", "物料单价", "库存数量", "货值"}; |
||||
|
/*Excel文件创建完毕*/ |
||||
|
CreationHelper createHelper = wb.getCreationHelper(); //创建帮助工具
|
||||
|
/*创建表单*/ |
||||
|
Sheet sheet = wb.createSheet(storehouse_name != null ? storehouse_name : "Sheet"); |
||||
|
//设置字体
|
||||
|
Font headFont = wb.createFont(); |
||||
|
headFont.setFontHeightInPoints((short) 15); |
||||
|
headFont.setFontName("Courier New"); |
||||
|
headFont.setItalic(false); |
||||
|
headFont.setStrikeout(false); |
||||
|
//设置头部单元格样式
|
||||
|
CellStyle headStyle = wb.createCellStyle(); |
||||
|
headStyle.setAlignment(HorizontalAlignment.CENTER); //设置水平对齐方式
|
||||
|
headStyle.setVerticalAlignment(VerticalAlignment.CENTER); //设置垂直对齐方式
|
||||
|
headStyle.setShrinkToFit(true); //自动伸缩
|
||||
|
headStyle.setFont(headFont); //设置字体
|
||||
|
/*设置数据单元格格式*/ |
||||
|
CellStyle dataStyle = wb.createCellStyle(); |
||||
|
dataStyle.setVerticalAlignment(VerticalAlignment.CENTER); //设置垂直对齐方式
|
||||
|
dataStyle.setAlignment(HorizontalAlignment.CENTER); //设置水平对齐方式
|
||||
|
dataStyle.setShrinkToFit(true); //自动伸缩
|
||||
|
/*创建行Rows及单元格Cells*/ |
||||
|
Row headRow = sheet.createRow(0); //第一行为头
|
||||
|
Font head = wb.createFont(); |
||||
|
head.setFontHeightInPoints((short) 25); |
||||
|
CellStyle cellStyle = wb.createCellStyle(); |
||||
|
cellStyle.setFont(head); |
||||
|
cellStyle.setAlignment(HorizontalAlignment.CENTER); //设置水平对齐方式
|
||||
|
cellStyle.setVerticalAlignment(VerticalAlignment.CENTER); //设置垂直对齐方式
|
||||
|
CellRangeAddress callRangeAddress = new CellRangeAddress(0,0,0,headList.length-1); |
||||
|
Cell cell1 = headRow.createCell(0); |
||||
|
cell1.setCellStyle(cellStyle); |
||||
|
cell1.setCellValue(storehouse_name + "("+ sdf.format(date) +")"); |
||||
|
sheet.addMergedRegion(callRangeAddress); |
||||
|
Row headRow2 = sheet.createRow(1); |
||||
|
for (int i = 0; i < headList.length; i++) { //遍历表头数据
|
||||
|
Cell cell = headRow2.createCell(i); //创建单元格
|
||||
|
cell.setCellValue(createHelper.createRichTextString(headList[i])); //设置值
|
||||
|
cell.setCellStyle(headStyle); //设置样式
|
||||
|
} |
||||
|
int rowIndex = 2; //当前行索引
|
||||
|
int a = 1; |
||||
|
Double count = 0.0; |
||||
|
for (int j = 0; j < inventories.size(); j++) { //编译每一行
|
||||
|
Row row = sheet.createRow(rowIndex++); //第一行为头
|
||||
|
Cell cell = row.createCell(0); |
||||
|
cell.setCellStyle(dataStyle); |
||||
|
cell.setCellValue(createHelper.createRichTextString(String.valueOf(a++))); |
||||
|
cell = row.createCell(1); |
||||
|
cell.setCellValue(createHelper.createRichTextString(inventories.get(j) |
||||
|
.getStorehouse_name()==null?"":inventories.get(j).getStorehouse_name().toString())); |
||||
|
cell = row.createCell(2); |
||||
|
cell.setCellValue(createHelper.createRichTextString(inventories.get(j) |
||||
|
.getMateriel_group_text()==null?"":inventories.get(j).getMateriel_group_text().toString())); |
||||
|
cell = row.createCell(3); |
||||
|
cell.setCellValue(createHelper.createRichTextString(inventories.get(j) |
||||
|
.getMateriel_no()==null?"":inventories.get(j).getMateriel_no().toString())); |
||||
|
cell = row.createCell(4); |
||||
|
cell.setCellValue(createHelper.createRichTextString(inventories.get(j) |
||||
|
.getMateriel_name()==null?"":inventories.get(j).getMateriel_name().toString())); |
||||
|
cell = row.createCell(5); |
||||
|
cell.setCellValue(createHelper.createRichTextString(inventories.get(j) |
||||
|
.getBrand_name() == null?"":inventories.get(j).getBrand_name().toString())); |
||||
|
cell = row.createCell(6); |
||||
|
cell.setCellValue(createHelper.createRichTextString(inventories.get(j) |
||||
|
.getPrice()==null?"":inventories.get(j).getPrice().toString())); |
||||
|
cell = row.createCell(7); |
||||
|
cell.setCellValue(createHelper.createRichTextString(inventories.get(j) |
||||
|
.getNum()==null?"":inventories.get(j).getNum().toString())); |
||||
|
cell = row.createCell(8); |
||||
|
Double v = inventories.get(j).getPrice() * inventories.get(j).getNum(); |
||||
|
count+=v; |
||||
|
cell.setCellValue(createHelper.createRichTextString(v == null ? "":v.toString())); |
||||
|
} |
||||
|
|
||||
|
//创建合计
|
||||
|
Row row = sheet.createRow(inventories.size()+2); |
||||
|
Cell cell = row.createCell(0); |
||||
|
cell.setCellStyle(dataStyle); |
||||
|
cell.setCellValue(createHelper.createRichTextString("合计")); |
||||
|
cell = row.createCell(8); |
||||
|
cell.setCellValue(createHelper.createRichTextString(String.valueOf(count))); |
||||
|
/*创建rows和cells完毕*/ |
||||
|
/*设置列自动对齐*/ |
||||
|
for (int i = 0; i < headList.length; i++) { |
||||
|
sheet.autoSizeColumn(i); |
||||
|
} |
||||
|
wb.write(out); //将workbook写入文件流
|
||||
|
}catch (Exception e){ |
||||
|
e.printStackTrace(); |
||||
|
}finally { |
||||
|
wb.close(); |
||||
|
out.close(); |
||||
|
} |
||||
|
} |
||||
|
} |
@ -0,0 +1,28 @@ |
|||||
|
package com.yxt.supervise.gf.shanhai.timedtask; |
||||
|
|
||||
|
import com.yxt.common.core.result.ResultBean; |
||||
|
import com.yxt.supervise.gf.biz.inventory.InventoryService; |
||||
|
import com.yxt.supervise.gf.shanhai.req.InventoryIndex; |
||||
|
import io.swagger.annotations.ApiModel; |
||||
|
import org.springframework.beans.factory.annotation.Autowired; |
||||
|
import org.springframework.beans.factory.annotation.Value; |
||||
|
import org.springframework.scheduling.annotation.Scheduled; |
||||
|
import org.springframework.stereotype.Component; |
||||
|
|
||||
|
/** |
||||
|
* @author feikefei |
||||
|
* @create 2023-07-13-11:44 |
||||
|
*/ |
||||
|
@ApiModel(value = "定时查询第三方库存管理数据并添加到本地库") |
||||
|
@Component |
||||
|
public class ShanHaiTimedTask { |
||||
|
|
||||
|
@Autowired |
||||
|
private InventoryService inventoryService; |
||||
|
|
||||
|
// @Scheduled(cron = "0 0 3 * * ?")
|
||||
|
public void timedTask(){ |
||||
|
InventoryIndex inventoryIndex = new InventoryIndex(); |
||||
|
inventoryService.save(inventoryIndex); |
||||
|
} |
||||
|
} |
Loading…
Reference in new issue