提交 6973513a authored 作者: 吕本才's avatar 吕本才

货需导入

上级 98db7ec1
...@@ -91,6 +91,12 @@ ...@@ -91,6 +91,12 @@
<groupId>cn.hutool</groupId> <groupId>cn.hutool</groupId>
<artifactId>hutool-all</artifactId> <artifactId>hutool-all</artifactId>
</dependency> </dependency>
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>easyexcel</artifactId>
</dependency>
</dependencies> </dependencies>
<build> <build>
......
package com.link.bi.controller.core;
import com.link.bi.service.IEcGoodsSupplyDemandService;
import com.sfa.common.core.web.controller.BaseController;
import com.sfa.common.log.annotation.Log;
import com.sfa.common.log.enums.BusinessType;
import com.sfa.common.security.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;
import javax.servlet.http.HttpServletResponse;
/**
* 电商-货物供需Controller
*
* @author admin
* @date 2024-12-05
*/
@RestController
@RequestMapping("/demand/core")
public class EcGoodsSupplyDemandCoreController extends BaseController
{
@Autowired
private IEcGoodsSupplyDemandService ecGoodsSupplyDemandService;
/**
* 导出电商-货物供需列表
*/
@RequiresPermissions("bi:demand:import")
@Log(title = "电商-货物供需", businessType = BusinessType.IMPORT)
@PostMapping("/import")
public String importData(HttpServletResponse response, MultipartFile file,Integer year)
{
ecGoodsSupplyDemandService.importData(file,year);
return "导入货需数据完成";
}
}
package com.link.bi.domain.dao;
import com.link.bi.domain.entity.EcGoodsSupplyDemand;
import java.util.List;
/**
* @author : liqiulin
* @date : 2024-11-21 16
* @describe :
*/
public interface IEcGoodsSupplyDemandDao {
void batchSaveEcGoodsSupplyDemands(List<EcGoodsSupplyDemand> demandList);
Integer deleteByYear(Integer year);
}
package com.link.bi.domain.dao.impl;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.link.bi.domain.dao.IEcGoodsSupplyDemandDao;
import com.link.bi.domain.entity.EcGoodsSupplyDemand;
import com.link.bi.domain.mapper.EcGoodsSupplyDemandMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;
/**
* @author : liqiulin
* @date : 2024-11-21 16
* @describe :
*/
@Service
public class EcGoodsSupplyDemandDaoImpl implements IEcGoodsSupplyDemandDao {
@Autowired
EcGoodsSupplyDemandMapper mapper;
@Override
public void batchSaveEcGoodsSupplyDemands(List<EcGoodsSupplyDemand> demandList) {
mapper.batchSaveEcGoodsSupplyDemands(demandList);
}
@Override
public Integer deleteByYear(Integer year) {
Integer delete = mapper.delete(new LambdaQueryWrapper<EcGoodsSupplyDemand>()
.eq(EcGoodsSupplyDemand::getYear, year));
System.out.println("删除" + delete + "条数据");
return delete;
}
}
package com.link.bi.domain.dao.impl; package com.link.bi.domain.dao.impl;
import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.link.bi.domain.dao.IProductDao; import com.link.bi.domain.dao.IProductDao;
...@@ -63,7 +64,7 @@ public class ProductDaoImpl implements IProductDao { ...@@ -63,7 +64,7 @@ public class ProductDaoImpl implements IProductDao {
@Override @Override
public List<PrdInfoDto> selectListByCodes(List<String> prdCodes) { public List<PrdInfoDto> selectListByCodes(List<String> prdCodes) {
List<PrdInfo> prdInfos = prdInfoMapper.selectList(new LambdaQueryWrapper<PrdInfo>().in(PrdInfo::getPrdCode, prdCodes)); List<PrdInfo> prdInfos = prdInfoMapper.selectList(new LambdaQueryWrapper<PrdInfo>().in(ObjectUtil.isNotEmpty(prdCodes),PrdInfo::getPrdCode, prdCodes));
return BeanUtils.transitionDtos(prdInfos, PrdInfoDto.class); return BeanUtils.transitionDtos(prdInfos, PrdInfoDto.class);
} }
} }
package com.link.bi.domain.entity;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.sfa.common.core.annotation.Excel;
import lombok.Data;
import java.util.Date;
/**
* 电商-货物供需对象 ec_goods_supply_demand
*
* @author admin
* @date 2024-12-05
*/
@TableName(value ="ec_goods_supply_demand")
@Data
public class EcGoodsSupplyDemand
{
@TableField(exist = false)
private static final long serialVersionUID = 1L;
/** 主键id */
@TableId(type = IdType.AUTO)
private Long supplyDemandId;
/** 年 */
@Excel(name = "年")
private Long year;
/** 月 */
@Excel(name = "月")
private Long month;
/** 周 */
@Excel(name = "周")
private Integer week;
/** 统计日期类型:1年 2月 3周 4日 */
@Excel(name = "统计日期类型:1年 2月 3周 4日")
private Long reportDateType;
/** 统计日期开始时间 */
@JsonFormat(pattern = "yyyy-MM-dd")
@Excel(name = "统计日期开始时间", width = 30, dateFormat = "yyyy-MM-dd")
private Date reportDateBegin;
/** 统计日期结束时间 */
@JsonFormat(pattern = "yyyy-MM-dd")
@Excel(name = "统计日期结束时间", width = 30, dateFormat = "yyyy-MM-dd")
private Date reportDateEnd;
/** 商品/货品编码 */
@Excel(name = "商品/货品编码")
private String prdCode;
/** 商品/货品名称 */
@Excel(name = "商品/货品名称")
private String prdName;
/** 商品条码,69码 */
@Excel(name = "商品条码,69码")
private String prdBarcode;
/** 商品/货品状态 */
@Excel(name = "商品/货品状态")
private Long prdStatus;
/** 商品系列id */
@Excel(name = "商品系列id")
private Integer seriesId;
/** 商品系列 */
@Excel(name = "商品系列")
private String series;
/** 平台id */
@Excel(name = "平台id")
private Long platformId;
/** platform平台:1 天猫; 2 抖音; 3 拼多多; 4 京东; 5 私域; 6 分销; 7 线下; 8 样品; 9 团购; 10 其他; */
@Excel(name = "platform平台:1 天猫; 2 抖音; 3 拼多多; 4 京东; 5 私域; 6 分销; 7 线下; 8 样品; 9 团购; 10 其他;")
private String platform;
/** 货需数量 */
@Excel(name = "货需数量")
// 做校验下 是否为正整数
private Long supplyDemandAmount;
@Excel(name = "创建时间")
private Date createTime;
/** 创建人id */
@Excel(name = "创建人id")
private Long createUserId;
/** 创建人 */
@Excel(name = "创建人")
private String createBy;
/** 修改人id */
@Excel(name = "修改人id")
private Long updateUserId;
/** 修改人 */
@Excel(name = "修改人")
private Long updateBy;
@Excel(name = "修改时间")
private Date updateTime;
}
package com.link.bi.domain.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.link.bi.domain.entity.EcGoodsSupplyDemand;
import org.apache.ibatis.annotations.Mapper;
import org.springframework.stereotype.Repository;
import java.util.List;
/**
* 电商-货物供需Mapper接口
*
* @author admin
* @date 2024-12-05
*/
@Repository
@Mapper
public interface EcGoodsSupplyDemandMapper extends BaseMapper<EcGoodsSupplyDemand> {
void batchSaveEcGoodsSupplyDemands(List<EcGoodsSupplyDemand> demandList);
}
package com.link.bi.service;
import com.baomidou.mybatisplus.extension.service.IService;
import com.link.bi.domain.entity.EcGoodsSupplyDemand;
import org.springframework.web.multipart.MultipartFile;
import java.util.List;
/**
* 电商-货物供需Service接口
*
* @author admin
* @date 2024-12-05
*/
public interface IEcGoodsSupplyDemandService extends IService<EcGoodsSupplyDemand> {
List<EcGoodsSupplyDemand> importData(MultipartFile ecGoodsSupplyDemand, Integer year);
// 批量保存
void batchSaveEcGoodsSupplyDemands(List<EcGoodsSupplyDemand> demandList);
void deleteByYear(Integer year);
}
package com.link.bi.service; package com.link.bi.service;
import com.link.bi.pojo.request.ProductVo; import com.link.bi.pojo.request.ProductVo;
import com.link.bi.pojo.response.PrdInfoDto;
import com.sfa.common.core.web.domain.PageInfo; import com.sfa.common.core.web.domain.PageInfo;
import java.util.List; import java.util.List;
...@@ -15,4 +16,6 @@ public interface IProductService { ...@@ -15,4 +16,6 @@ public interface IProductService {
PageInfo productPage(ProductVo productVo); PageInfo productPage(ProductVo productVo);
List<PrdInfoDto> selectListByCodes(List<String> codeLists);
} }
package com.link.bi.service.impl;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.ObjectUtil;
import com.alibaba.excel.EasyExcel;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.link.bi.config.listener.EcGoodsSupplyDemandListener;
import com.link.bi.domain.dao.IEcGoodsSupplyDemandDao;
import com.link.bi.domain.entity.EcGoodsSupplyDemand;
import com.link.bi.domain.mapper.EcGoodsSupplyDemandMapper;
import com.link.bi.pojo.response.PrdInfoDto;
import com.link.bi.service.IEcGoodsSupplyDemandService;
import com.link.bi.service.IProductService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
/**
* 电商-货物供需Service业务层处理
*
* @author admin
* @date 2024-12-05
*/
@Service
@Slf4j
public class EcGoodsSupplyDemandServiceImpl extends ServiceImpl<EcGoodsSupplyDemandMapper, EcGoodsSupplyDemand> implements IEcGoodsSupplyDemandService {
@Autowired
IEcGoodsSupplyDemandDao demandDao;
@Autowired
IProductService productService;
@Override
public List<EcGoodsSupplyDemand> importData(MultipartFile multipartFile, Integer year) {
// 上传并解析excel
File file = transferToFile(multipartFile);
List<String> codeLists = new ArrayList<>();
List<PrdInfoDto> prdInfoDtos = productService.selectListByCodes(codeLists);
// 创建EcGoodsSupplyDemandListener实例
EcGoodsSupplyDemandListener listener = new EcGoodsSupplyDemandListener(this,prdInfoDtos,year);
// 读取文件内容
EasyExcel.read(file, listener).ignoreEmptyRow(true)
.headRowNumber(4).sheet("电商-需求").doRead();
// 获取读取到的数据
List<EcGoodsSupplyDemand> data = listener.getDemandList();
return data;
}
public File transferToFile(MultipartFile multipartFile) {
// 选择用缓冲区来实现这个转换即使用java 创建的临时文件 使用 MultipartFile.transferto()方法 。
File file = null;
try {
String originalFilename = multipartFile.getOriginalFilename();
String[] filename = originalFilename.split("\\.");
file = File.createTempFile(filename[0], filename[1] + ".");
multipartFile.transferTo(file);
file.deleteOnExit();
} catch (IOException e) {
e.printStackTrace();
log.error(e.getMessage(),e);
}
return file;
//————————————————
//
// 版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
//
// 原文链接:https://blog.csdn.net/qq_42383970/article/details/120201524
}
// 批量保存
@Override
public void batchSaveEcGoodsSupplyDemands(List<EcGoodsSupplyDemand> demandList) {
demandDao.batchSaveEcGoodsSupplyDemands(demandList);
}
@Override
public void deleteByYear(Integer year) {
if (ObjectUtil.isEmpty(year)) {
year = DateUtil.thisYear();
}
demandDao.deleteByYear(year);
}
}
...@@ -3,6 +3,7 @@ package com.link.bi.service.impl; ...@@ -3,6 +3,7 @@ package com.link.bi.service.impl;
import com.link.bi.domain.dao.IProductDao; import com.link.bi.domain.dao.IProductDao;
import com.link.bi.domain.wq.ProductWq; import com.link.bi.domain.wq.ProductWq;
import com.link.bi.pojo.request.ProductVo; import com.link.bi.pojo.request.ProductVo;
import com.link.bi.pojo.response.PrdInfoDto;
import com.link.bi.service.IProductService; import com.link.bi.service.IProductService;
import com.sfa.common.core.web.domain.PageInfo; import com.sfa.common.core.web.domain.PageInfo;
import org.springframework.beans.BeanUtils; import org.springframework.beans.BeanUtils;
...@@ -30,8 +31,14 @@ public class ProductServiceImpl implements IProductService { ...@@ -30,8 +31,14 @@ public class ProductServiceImpl implements IProductService {
@Override @Override
public PageInfo productPage(ProductVo productVo) { public PageInfo productPage(ProductVo productVo) {
ProductWq qw = new ProductWq(); ProductWq qw = new ProductWq();
BeanUtils.copyProperties(productVo,qw); BeanUtils.copyProperties(productVo, qw);
qw.setPrdNameLike(productVo.getPrdName()); qw.setPrdNameLike(productVo.getPrdName());
return productDao.productPage(qw); return productDao.productPage(qw);
} }
@Override
public List<PrdInfoDto> selectListByCodes(List<String> prdCodes) {
List<PrdInfoDto> prdInfos = productDao.selectListByCodes(prdCodes);
return prdInfos;
}
} }
<?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.link.bi.domain.mapper.EcGoodsSupplyDemandMapper">
<resultMap type="com.link.bi.domain.entity.EcGoodsSupplyDemand" id="EcGoodsSupplyDemandResult">
<result property="supplyDemandId" column="supply_demand_id"/>
<result property="year" column="year"/>
<result property="month" column="month"/>
<result property="week" column="week"/>
<result property="reportDateType" column="report_date_type"/>
<result property="reportDateBegin" column="report_date_begin"/>
<result property="reportDateEnd" column="report_date_end"/>
<result property="prdCode" column="prd_code"/>
<result property="prdName" column="prd_name"/>
<result property="prdBarcode" column="prd_barcode"/>
<result property="prdStatus" column="prd_status"/>
<result property="seriesId" column="series_id"/>
<result property="series" column="series"/>
<result property="platformId" column="platform_id"/>
<result property="platform" column="platform"/>
<result property="supplyDemandAmount" column="supply_demand_amount"/>
<result property="createBy" column="create_by"/>
<result property="createUserId" column="create_user_id"/>
<result property="createTime" column="create_time"/>
<result property="updateBy" column="update_by"/>
<result property="updateUserId" column="update_user_id"/>
<result property="updateTime" column="update_time"/>
</resultMap>
<sql id="selectEcGoodsSupplyDemandVo">
select supply_demand_id, year, month, week, report_date_type, report_date_begin, report_date_end, prd_code, prd_name, prd_barcode, prd_status, series_id, series, platform_id, platform, supply_demand_amount, create_by, create_user_id, create_time, update_by, update_user_id, update_time
from ec_goods_supply_demand
</sql>
<select id="selectEcGoodsSupplyDemandList" parameterType="com.link.bi.domain.entity.EcGoodsSupplyDemand"
resultMap="EcGoodsSupplyDemandResult">
<include refid="selectEcGoodsSupplyDemandVo"/>
<where>
<if test="year != null ">and year = #{year}</if>
<if test="month != null ">and month = #{month}</if>
<if test="week != null ">and week = #{week}</if>
<if test="reportDateType != null ">and report_date_type = #{reportDateType}</if>
<if test="reportDateBegin != null ">and report_date_begin = #{reportDateBegin}</if>
<if test="reportDateEnd != null ">and report_date_end = #{reportDateEnd}</if>
<if test="prdCode != null and prdCode != ''">and prd_code = #{prdCode}</if>
<if test="prdName != null and prdName != ''">and prd_name like concat('%', #{prdName}, '%')</if>
<if test="prdBarcode != null and prdBarcode != ''">and prd_barcode = #{prdBarcode}</if>
<if test="prdStatus != null ">and prd_status = #{prdStatus}</if>
<if test="seriesId != null ">and series_id = #{seriesId}</if>
<if test="series != null and series != ''">and series = #{series}</if>
<if test="platformId != null ">and platform_id = #{platformId}</if>
<if test="platform != null and platform != ''">and platform = #{platform}</if>
<if test="supplyDemandAmount != null ">and supply_demand_amount = #{supplyDemandAmount}</if>
<if test="createUserId != null ">and create_user_id = #{createUserId}</if>
<if test="updateUserId != null ">and update_user_id = #{updateUserId}</if>
</where>
</select>
<select id="selectEcGoodsSupplyDemandById" parameterType="Long" resultMap="EcGoodsSupplyDemandResult">
<include refid="selectEcGoodsSupplyDemandVo"/>
where supply_demand_id = #{supplyDemandId}
</select>
<insert id="batchSaveEcGoodsSupplyDemands" parameterType="java.util.List">
insert into ec_goods_supply_demand
(year, month, week, report_date_type, report_date_begin, report_date_end, prd_code,
prd_name, prd_barcode, prd_status, series_id, series, platform_id, platform,
supply_demand_amount, create_user_id, update_user_id)
values
<foreach collection="list" item="item" index="index" separator=",">
( #{item.year}, #{item.month}, #{item.week}, #{item.reportDateType}, #{item.reportDateBegin},
#{item.reportDateEnd}, #{item.prdCode}, #{item.prdName}, #{item.prdBarcode}, #{item.prdStatus},
#{item.seriesId},
#{item.series}, #{item.platformId}, #{item.platform}, #{item.supplyDemandAmount}, #{item.createUserId},
#{item.updateUserId})
</foreach>
</insert>
</mapper>
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论