导入excel生成卡片新接口
This commit is contained in:
@@ -13,4 +13,6 @@ import java.util.List;
|
|||||||
@Data
|
@Data
|
||||||
public class ReturnExcelInfo {
|
public class ReturnExcelInfo {
|
||||||
List<ReturnExcelInfoDetails> infoDetails;
|
List<ReturnExcelInfoDetails> infoDetails;
|
||||||
|
private String name;
|
||||||
|
private String phone;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -131,4 +131,15 @@ public class LpkGiftCardRest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ApiOperation(value = "批量发行导入")
|
||||||
|
@PostMapping("/getExcelInfo2")
|
||||||
|
public ResultBean getExcelInfo2(
|
||||||
|
@RequestParam(value = "startDate") String startDate,
|
||||||
|
@RequestParam(value = "endDate") String endDate,
|
||||||
|
@RequestParam(value = "file") MultipartFile file,
|
||||||
|
HttpServletRequest request,
|
||||||
|
HttpServletResponse response) throws IOException, ParseException {
|
||||||
|
return lpkGiftCardService.getExcelInfo2(startDate,endDate,file,request,response);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -32,6 +32,7 @@ import com.yxt.yyth.api.lpkgiftbag.LpkGiftBagDto;
|
|||||||
import com.yxt.yyth.api.lpkgiftbaggoods.LpkGiftBagGoodsVo;
|
import com.yxt.yyth.api.lpkgiftbaggoods.LpkGiftBagGoodsVo;
|
||||||
import com.yxt.yyth.api.lpkgiftcard.*;
|
import com.yxt.yyth.api.lpkgiftcard.*;
|
||||||
import com.yxt.yyth.api.lpkgoods.LpkGoods;
|
import com.yxt.yyth.api.lpkgoods.LpkGoods;
|
||||||
|
import com.yxt.yyth.api.lpkgoods.LpkGoodsDto;
|
||||||
import com.yxt.yyth.api.lpkreserveorder.LpkReserveOrderCardVo;
|
import com.yxt.yyth.api.lpkreserveorder.LpkReserveOrderCardVo;
|
||||||
import com.yxt.yyth.api.lpkreserveorder.LpkReserveOrderVo;
|
import com.yxt.yyth.api.lpkreserveorder.LpkReserveOrderVo;
|
||||||
import com.yxt.yyth.api.lpkreserveordergoods.LpkReserveOrderGoods;
|
import com.yxt.yyth.api.lpkreserveordergoods.LpkReserveOrderGoods;
|
||||||
@@ -1085,6 +1086,218 @@ public class LpkGiftCardService extends MybatisBaseService<LpkGiftCardMapper, Lp
|
|||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public ResultBean getExcelInfo2(String startDate, String endDate, MultipartFile file, HttpServletRequest request, HttpServletResponse response) throws IOException {
|
||||||
|
ResultBean rb = ResultBean.fireFail();
|
||||||
|
String temp = request.getSession().getServletContext().getRealPath(File.separator) + "temp";// 临时目录
|
||||||
|
File tempFile = new File(temp);
|
||||||
|
if (!tempFile.exists()) {
|
||||||
|
tempFile.mkdirs();
|
||||||
|
}
|
||||||
|
String fileName = file.getOriginalFilename();
|
||||||
|
if (!fileName.matches("^.+\\.(?i)(xls)$") && !fileName.matches("^.+\\.(?i)(xlsx)$")) {
|
||||||
|
return rb.fail().setMsg("上传文件不正确");
|
||||||
|
}
|
||||||
|
int[] resultCell = new int[]{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15};
|
||||||
|
boolean isExcel2003 = true;
|
||||||
|
if (fileName.matches("^.+\\.(?i)(xlsx)$")) {
|
||||||
|
isExcel2003 = false;
|
||||||
|
}
|
||||||
|
InputStream is = file.getInputStream();
|
||||||
|
Workbook wb = null;
|
||||||
|
if (isExcel2003) {
|
||||||
|
wb = new HSSFWorkbook(is);
|
||||||
|
} else {
|
||||||
|
wb = new XSSFWorkbook(is);
|
||||||
|
}
|
||||||
|
Sheet sheet = wb.getSheetAt(0);
|
||||||
|
ReturnMsg returnMsg = getSheetVal2(sheet, resultCell);
|
||||||
|
Set<String> setMsg = returnMsg.getSetMsg();
|
||||||
|
StringBuffer sbMsg = new StringBuffer();
|
||||||
|
if (null != setMsg && setMsg.size() > 0) {
|
||||||
|
for (String s : setMsg) {
|
||||||
|
sbMsg.append(s).append(",");
|
||||||
|
}
|
||||||
|
sbMsg.delete(sbMsg.length() - 1, sbMsg.length());
|
||||||
|
if (StringUtils.isNotBlank(sbMsg.toString())) {
|
||||||
|
return rb.setMsg(sbMsg.toString());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
List<ReturnExcelInfo> importReturn = returnMsg.getInfos();
|
||||||
|
importReturn.removeAll(Collections.singleton(null));
|
||||||
|
if (!importReturn.isEmpty()) {
|
||||||
|
for (ReturnExcelInfo info : importReturn) {
|
||||||
|
//生成礼包
|
||||||
|
LpkGiftCardDto dtoCard = new LpkGiftCardDto();
|
||||||
|
dtoCard.setCardArea("88");
|
||||||
|
dtoCard.setNum("1");
|
||||||
|
String cardSid = getCardByExcel(dtoCard);
|
||||||
|
LpkGiftCard lpkGiftCard = fetchBySid(cardSid);
|
||||||
|
String cardNo = "";
|
||||||
|
if (null != lpkGiftCard) {
|
||||||
|
if (StringUtils.isNotBlank(lpkGiftCard.getSerialNumber())) {
|
||||||
|
cardNo = lpkGiftCard.getSerialNumber();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
LpkGiftBagDto dtoBag = new LpkGiftBagDto();
|
||||||
|
dtoBag.setDateStart(startDate);
|
||||||
|
dtoBag.setDateEnd(endDate);
|
||||||
|
List<ReturnExcelInfoDetails> infoDetails = info.getInfoDetails();
|
||||||
|
List<GiftBagGoods> goods = new ArrayList<>();
|
||||||
|
if (!infoDetails.isEmpty()) {
|
||||||
|
for (ReturnExcelInfoDetails detail : infoDetails) {
|
||||||
|
GiftBagGoods giftBagGoods = new GiftBagGoods();
|
||||||
|
if (StringUtils.isNotBlank(detail.getGoodNum()) && StringUtils.isNotBlank(detail.getGoodName())) {
|
||||||
|
LpkGoods lpkGoods = lpkGoodsService.getGoodsByName(detail.getGoodName());
|
||||||
|
if (null != lpkGoods) {
|
||||||
|
giftBagGoods.setName(lpkGoods.getName());
|
||||||
|
giftBagGoods.setGoodsSid(lpkGoods.getSid());
|
||||||
|
if (detail.getGoodNum().contains(".")) {
|
||||||
|
String num = detail.getGoodNum().substring(0, detail.getGoodNum().indexOf("."));
|
||||||
|
giftBagGoods.setGoodsNumber(num);
|
||||||
|
} else {
|
||||||
|
giftBagGoods.setGoodsNumber(detail.getGoodNum());
|
||||||
|
}
|
||||||
|
goods.add(giftBagGoods);
|
||||||
|
} else {
|
||||||
|
//没有新增商品
|
||||||
|
LpkGoodsDto goodsDto = new LpkGoodsDto();
|
||||||
|
goodsDto.setName(detail.getGoodName());
|
||||||
|
String goodsSid = lpkGoodsService.saveGoods(goodsDto).getData();
|
||||||
|
if (StringUtils.isNotBlank(goodsSid)) {
|
||||||
|
giftBagGoods.setName(detail.getGoodName());
|
||||||
|
giftBagGoods.setGoodsSid(goodsSid);
|
||||||
|
if (detail.getGoodNum().contains(".")) {
|
||||||
|
String num = detail.getGoodNum().substring(0, detail.getGoodNum().indexOf("."));
|
||||||
|
giftBagGoods.setGoodsNumber(num);
|
||||||
|
} else {
|
||||||
|
giftBagGoods.setGoodsNumber(detail.getGoodNum());
|
||||||
|
}
|
||||||
|
goods.add(giftBagGoods);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
dtoBag.setGoods(goods);
|
||||||
|
dtoBag.setName("家庭菜窖" + cardNo);
|
||||||
|
String bagSid = lpkGiftBagService.saveGiftBag(dtoBag).getData();
|
||||||
|
if (StringUtils.isNotBlank(bagSid)) {
|
||||||
|
lpkGiftCard.setGiftbagSid(bagSid);
|
||||||
|
baseMapper.updateById(lpkGiftCard);
|
||||||
|
LpkCardBuildRecord cardBuildRecord = lpkCardBuildRecordService.fetchBySid(lpkGiftCard.getRecordSid());
|
||||||
|
cardBuildRecord.setGiftbagSid(bagSid);
|
||||||
|
lpkCardBuildRecordService.updateById(cardBuildRecord);
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return rb.success().setMsg("导入成功");
|
||||||
|
}
|
||||||
|
|
||||||
|
private ReturnMsg getSheetVal2(Sheet sheet, int[] resultCell) {
|
||||||
|
ReturnMsg returnMsg = new ReturnMsg();
|
||||||
|
List<ReturnExcelInfo> voList = new ArrayList<>();
|
||||||
|
int[] resultIndex = new int[resultCell.length];
|
||||||
|
Set<String> setMsg = new HashSet<>();
|
||||||
|
Row row1 = sheet.getRow(1);
|
||||||
|
int startNo = 0;
|
||||||
|
int endNo = 0;
|
||||||
|
for (int i = 0; i < row1.getPhysicalNumberOfCells(); i++) {
|
||||||
|
String trim = new String();
|
||||||
|
try {
|
||||||
|
trim = getCellVal(row1.getCell(i)).toString().trim();
|
||||||
|
String temp = getCellVal(row1.getCell(i)).toString().trim();
|
||||||
|
if (StringUtils.isNotBlank(temp)) {
|
||||||
|
if (temp.equals("菜品")) {
|
||||||
|
startNo = i;
|
||||||
|
}
|
||||||
|
if (temp.equals("菜窖重量合计(斤)")) {
|
||||||
|
endNo = i - 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Row row2 = sheet.getRow(2);
|
||||||
|
Map<Integer,String> mapGoods = new HashMap<>();
|
||||||
|
for (int i = startNo; i <= endNo; i++) {
|
||||||
|
String trim = new String();
|
||||||
|
try {
|
||||||
|
trim = getCellVal(row2.getCell(i)).toString().trim();
|
||||||
|
String temp = getCellVal(row2.getCell(i)).toString().trim();
|
||||||
|
if (StringUtils.isNotBlank(temp)) {
|
||||||
|
String substring = temp.substring(0, temp.indexOf("("));
|
||||||
|
mapGoods.put(i,substring);
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for (int r = 3; r <= sheet.getLastRowNum(); r++) {
|
||||||
|
ReturnExcelInfo info = new ReturnExcelInfo();
|
||||||
|
List<ReturnExcelInfoDetails> importVoList = new ArrayList<>();
|
||||||
|
Row row = sheet.getRow(r);
|
||||||
|
if (row == null) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
String name = new String();
|
||||||
|
String phone = new String();
|
||||||
|
for (int i = 4; i <= endNo; i++) {
|
||||||
|
String trim = new String();
|
||||||
|
try {
|
||||||
|
trim = getCellVal(row.getCell(i)).toString().trim();
|
||||||
|
String temp = getCellVal(row.getCell(i)).toString().trim();
|
||||||
|
if (i == 4 ) {
|
||||||
|
info.setName(temp);
|
||||||
|
}
|
||||||
|
if (i == 5) {
|
||||||
|
info.setPhone(temp);
|
||||||
|
}
|
||||||
|
if (StringUtils.isNotBlank(temp)) {
|
||||||
|
if (i > 5 && i <= endNo) {
|
||||||
|
ReturnExcelInfoDetails details = new ReturnExcelInfoDetails();
|
||||||
|
details.setGoodNum(temp);
|
||||||
|
String goodsName = mapGoods.get(i);
|
||||||
|
details.setGoodName(goodsName);
|
||||||
|
importVoList.add(details);
|
||||||
|
if (!isNum(temp)) {
|
||||||
|
setMsg.add("菜品数量必须为整数");
|
||||||
|
} else {
|
||||||
|
if (temp.contains(".")) {
|
||||||
|
String num = temp.substring(temp.indexOf(".") + 1);
|
||||||
|
if (Integer.parseInt(num) != 0) {
|
||||||
|
setMsg.add("菜品数量必须为整数");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
info.setInfoDetails(importVoList);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!importVoList.isEmpty()) {
|
||||||
|
voList.add(info);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (voList != null && voList.size() > 0) {
|
||||||
|
for (ReturnExcelInfo returnExcelInfoDetails : voList) {
|
||||||
|
if (StringUtils.isBlank(returnExcelInfoDetails.getName())) {
|
||||||
|
setMsg.add("客户姓名不能为空");
|
||||||
|
}
|
||||||
|
if (StringUtils.isBlank(returnExcelInfoDetails.getPhone())) {
|
||||||
|
setMsg.add("客户电话不能为空");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
returnMsg.setSetMsg(setMsg);
|
||||||
|
returnMsg.setInfos(voList);
|
||||||
|
return returnMsg;
|
||||||
|
}
|
||||||
// public static void main(String[] args) {
|
// public static void main(String[] args) {
|
||||||
// LocalDate start = LocalDate.of(2021, Month.JANUARY, 1); // 设置起始日期为2021年1月1日
|
// LocalDate start = LocalDate.of(2021, Month.JANUARY, 1); // 设置起始日期为2021年1月1日
|
||||||
// LocalDate end = LocalDate.now(); // 设置结束日期为当前日期
|
// LocalDate end = LocalDate.now(); // 设置结束日期为当前日期
|
||||||
|
|||||||
@@ -35,7 +35,7 @@ public class LpkGoodsRest {
|
|||||||
|
|
||||||
@ApiOperation("保存修改")
|
@ApiOperation("保存修改")
|
||||||
@PostMapping("/saveGoods")
|
@PostMapping("/saveGoods")
|
||||||
public ResultBean saveGoods(@RequestBody LpkGoodsDto dto) {
|
public ResultBean<String> saveGoods(@RequestBody LpkGoodsDto dto) {
|
||||||
return lpkGoodsService.saveGoods(dto);
|
return lpkGoodsService.saveGoods(dto);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -34,7 +34,7 @@ public class LpkGoodsService extends MybatisBaseService<LpkGoodsMapper, LpkGoods
|
|||||||
ResultBean rb = ResultBean.fireFail();
|
ResultBean rb = ResultBean.fireFail();
|
||||||
LpkGoodsQuery query = pq.getParams();
|
LpkGoodsQuery query = pq.getParams();
|
||||||
QueryWrapper<LpkGoods> qw = new QueryWrapper<>();
|
QueryWrapper<LpkGoods> qw = new QueryWrapper<>();
|
||||||
qw.eq("1","1");
|
qw.eq("1", "1");
|
||||||
if (StringUtils.isNotBlank(query.getName())) {
|
if (StringUtils.isNotBlank(query.getName())) {
|
||||||
qw.like("name", query.getName());
|
qw.like("name", query.getName());
|
||||||
}
|
}
|
||||||
@@ -54,9 +54,11 @@ public class LpkGoodsService extends MybatisBaseService<LpkGoodsMapper, LpkGoods
|
|||||||
return rb.success().setData(p);
|
return rb.success().setData(p);
|
||||||
}
|
}
|
||||||
|
|
||||||
public ResultBean saveGoods(LpkGoodsDto dto) {
|
public ResultBean<String> saveGoods(LpkGoodsDto dto) {
|
||||||
ResultBean rb = ResultBean.fireFail();
|
ResultBean rb = ResultBean.fireFail();
|
||||||
|
String sid = "";
|
||||||
if (StringUtils.isNotBlank(dto.getSid())) {
|
if (StringUtils.isNotBlank(dto.getSid())) {
|
||||||
|
sid = dto.getSid();
|
||||||
LpkGoods lpkGoods = fetchBySid(dto.getSid());
|
LpkGoods lpkGoods = fetchBySid(dto.getSid());
|
||||||
BeanUtil.copyProperties(dto, lpkGoods, "id", "sid");
|
BeanUtil.copyProperties(dto, lpkGoods, "id", "sid");
|
||||||
if (StringUtils.isNotBlank(dto.getPicUrl())) {
|
if (StringUtils.isNotBlank(dto.getPicUrl())) {
|
||||||
@@ -67,6 +69,7 @@ public class LpkGoodsService extends MybatisBaseService<LpkGoodsMapper, LpkGoods
|
|||||||
baseMapper.updateById(lpkGoods);
|
baseMapper.updateById(lpkGoods);
|
||||||
} else {
|
} else {
|
||||||
LpkGoods lpkGoods = new LpkGoods();
|
LpkGoods lpkGoods = new LpkGoods();
|
||||||
|
sid = lpkGoods.getSid();
|
||||||
BeanUtil.copyProperties(dto, lpkGoods, "id", "sid");
|
BeanUtil.copyProperties(dto, lpkGoods, "id", "sid");
|
||||||
lpkGoods.setCreateTime(new DateTime());
|
lpkGoods.setCreateTime(new DateTime());
|
||||||
if (StringUtils.isNotBlank(dto.getPicUrl())) {
|
if (StringUtils.isNotBlank(dto.getPicUrl())) {
|
||||||
@@ -76,7 +79,7 @@ public class LpkGoodsService extends MybatisBaseService<LpkGoodsMapper, LpkGoods
|
|||||||
}
|
}
|
||||||
baseMapper.insert(lpkGoods);
|
baseMapper.insert(lpkGoods);
|
||||||
}
|
}
|
||||||
return rb.success();
|
return rb.success().setData(sid);
|
||||||
}
|
}
|
||||||
|
|
||||||
public ResultBean<LpkGoodsDetailsVo> goodsInit(String sid) {
|
public ResultBean<LpkGoodsDetailsVo> goodsInit(String sid) {
|
||||||
@@ -93,6 +96,7 @@ public class LpkGoodsService extends MybatisBaseService<LpkGoodsMapper, LpkGoods
|
|||||||
}
|
}
|
||||||
return rb.success().setData(vo);
|
return rb.success().setData(vo);
|
||||||
}
|
}
|
||||||
|
|
||||||
public ResultBean<LpkGoodsDetailsVo> goodsDetails(String sid) {
|
public ResultBean<LpkGoodsDetailsVo> goodsDetails(String sid) {
|
||||||
ResultBean rb = ResultBean.fireFail();
|
ResultBean rb = ResultBean.fireFail();
|
||||||
LpkGoodsDetailsVo vo = new LpkGoodsDetailsVo();
|
LpkGoodsDetailsVo vo = new LpkGoodsDetailsVo();
|
||||||
|
|||||||
Reference in New Issue
Block a user