package com.juseerp.business.store.retailPricing.controller;
import cn.afterturn.easypoi.excel.ExcelImportUtil;
import cn.afterturn.easypoi.excel.entity.ImportParams;
import cn.afterturn.easypoi.excel.entity.result.ExcelImportResult;
import cn.hutool.core.collection.CollectionUtil;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.juseerp.business.common.bean.BaseApprovalDTO;
import com.juseerp.business.common.constant.BusinessConstant;
import com.juseerp.business.erp.basicfile.enums.BusinessTypeEnum;
import com.juseerp.business.erp.qualityMamage.bean.ErpProductInfo;
import com.juseerp.business.erp.qualityMamage.enums.CommodityDisassemblyEnum;
import com.juseerp.business.erp.retailPricing.enums.PricingStateEnum;
import com.juseerp.business.erp.retailPricing.excel.ErpProductDetailExcelDTO;
import com.juseerp.business.login.bean.LoginUser;
import com.juseerp.business.login.service.LoginService;
import com.juseerp.business.store.basicfile.service.PosProductInfoService;
import com.juseerp.business.store.retailPricing.dto.PosProductDTO;
import com.juseerp.business.store.retailPricing.dto.PosProductRetailPricingDTO;
import com.juseerp.business.store.retailPricing.dto.PosProductRetailPricingSaveDTO;
import com.juseerp.business.store.retailPricing.dto.PosProductRetailPricingStateDTO;
import com.juseerp.business.store.retailPricing.service.PosProductRetailPricingDetailExcelService;
import com.juseerp.business.store.retailPricing.service.PosProductRetailPricingService;
import com.juseerp.business.store.retailPricing.vo.PosProductRetailPricingDetailExcelSaveVO;
import com.juseerp.business.store.retailPricing.vo.PosProductRetailPricingDetailExcelVO;
import com.juseerp.business.store.retailPricing.vo.PosProductRetailPricingDetailVO;
import com.juseerp.business.store.retailPricing.vo.PosProductRetailPricingVO;
import com.juseerp.common.bean.R;
import com.juseerp.common.exception.GlobleException;
import com.juseerp.common.logs.annotation.Log;
import com.juseerp.common.logs.enums.log.BusinessType;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;
/**
* 门店-商品零售定价-控制类
*
* @author glaive.xiao
* @version 1.0.0
* @ClassName
* @Description 门店-商品零售定价
* @createTime 2022年02月21日 18:28:00
*/
@Api(value = "门店-商品零售定价", tags = {"门店-商品零售定价"})
@RestController
@RequestMapping("/posProductRetailPricing")
@Slf4j
public class PosProductRetailPricingController {
@Resource
private PosProductRetailPricingService posProductRetailPricingService;
@Resource
private PosProductRetailPricingDetailExcelService posProductRetailPricingDetailExcelService;
@Resource
private PosProductInfoService posProductInfoService;
@Resource
private LoginService loginService;
@ApiOperation("导入明细")
@PostMapping("/importExcel")
@Log(title = "委托配送请货 导入请货明细", businessType = BusinessType.IMPORT)
public R importExcel(@RequestParam("file") MultipartFile multipartFile, @RequestParam("randomId") String randomId) throws Exception {
LoginUser loginUser = loginService.getLoginUser();
//校验文件类型
String originalFilename = multipartFile.getOriginalFilename();
if (StringUtils.isEmpty(originalFilename)) {
return R.failInfo("获取导入excel文件名失败!");
}
int lastIndex = originalFilename.lastIndexOf(".");
if (lastIndex <= 0) {
return R.failInfo("获取导入excel文件格式不正确!");
}
String suffix = originalFilename.substring(lastIndex);
if (!(BusinessConstant.DOWNLOAD_PATH_SUFFIX.equals(suffix) || BusinessConstant.OLD_EXCEL_SUFFIX.equals(suffix))) {
return R.failInfo("文件格式不正确!");
}
ImportParams params = new ImportParams();
// 表头设置为2行
params.setHeadRows(1);
// 标题行设置为0行,默认是0,可以不设置
params.setTitleRows(0);
// 开启Excel校验
params.setNeedVerfiy(true);
ExcelImportResult<ErpProductDetailExcelDTO> result;
try {
result = ExcelImportUtil.importExcelMore(multipartFile.getInputStream(),
ErpProductDetailExcelDTO.class, params);
} catch (Exception e) {
log.error("导入excel失败:{}", e);
return R.failInfo("导入文件不是模板!");
}
if (result == null) {
return R.failInfo("导入文件不是模板!");
}
if (result.isVerfiyFail()) {
StringBuffer str = new StringBuffer();
for (ErpProductDetailExcelDTO entity : result.getFailList()) {
str.append("第").append(entity.getRowNum()).append("行").append(entity.getErrorMsg());
}
return R.failInfo(str.toString());
}
if (CollectionUtil.isEmpty(result.getList())) {
return R.sucess();
}
List<PosProductRetailPricingDetailExcelVO> list = new ArrayList<>();
//对导入的数据做补充处理,校验是不是在t_pos_product_info表中不存在
for (ErpProductDetailExcelDTO dto : result.getList()) {
ErpProductInfo productInfo = posProductInfoService.findByHaidianCode(dto.getHaidianCode(), loginUser.getStoreId());
if (productInfo == null) {
throw new GlobleException(dto.getHaidianCode() + ":商品详情未查询到!");
}
PosProductRetailPricingDetailExcelVO vo = new PosProductRetailPricingDetailExcelVO();
BeanUtils.copyProperties(dto, vo);
vo.setProductId(productInfo.getId());
vo.setProductName(productInfo.getProductName());
vo.setSpecification(productInfo.getSpecification());
vo.setUnit(productInfo.getUnit());
vo.setGenerateManufacturer(productInfo.getGenerateManufacturer());
vo.setNowPurchasePrice(productInfo.getRetailPrice());
vo.setRandomId(randomId);
if(productInfo.getCommodityDisassembly().equals(CommodityDisassemblyEnum.NOT_ALLOW.getValue())){
//说明拆零价不需要修改,去掉
vo.setNowDisassemblyPrice(null);
vo.setNowVipDisassemblyPrice(null);
}
list.add(vo);
}
PosProductRetailPricingDetailExcelSaveVO e = new PosProductRetailPricingDetailExcelSaveVO();
e.setRandomId(randomId);
e.setExcelVOList(list);
posProductRetailPricingDetailExcelService.batchInsert(e);
return R.sucess(randomId);
}
}
没有合适的资源?快使用搜索试试~ 我知道了~
文件上传工具,批量导入代码
共6个文件
java:5个
yml:1个
需积分: 5 0 下载量 139 浏览量
2022-03-03
11:19:39
上传
评论
收藏 7KB ZIP 举报
温馨提示
文件上传工具,批量导入代码
资源详情
资源评论
资源推荐
收起资源包目录
文件上传.zip (6个子文件)
文件上传
BusinessConstant.java 2KB
UploadUtils.java 3KB
PosProductRetailPricingController.java 7KB
TemplateFilePathEnum.java 1KB
配置文件.yml 213B
OssUploadController.java 4KB
共 6 条
- 1
南宫龙码
- 粉丝: 6
- 资源: 4
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- 基于SpringBoot+MySQL+Guava+Redis+RabbitMQ实现高并发商品限时秒杀系统.rar
- 22222222222222222
- ADSP-BF533的例程源码60:NORFLASH驱动源码(s29al016)
- Linux centos telnet 离线安装rpm
- ADSP-BF533的例程源码58:汉字字库源码
- newtask3-1newtask3-1newtask3-1newtask3-1
- Vue前端开发手册pdf
- 【STM32F103】STM32F103读取PAC功率传感器
- 超级好用的zotero插件,用以进行pdf文件的翻译
- ADSP-BF533的例程源码57:光标显示源码
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
评论0