From 61e3629c7ab2f8b15636614399bfa9300d2f2f29 Mon Sep 17 00:00:00 2001
From: 张晓波 <bingbo1993@126.com>
Date: 星期三, 18 十月 2023 16:39:17 +0800
Subject: [PATCH] 苏州配置文件简化
---
hd/pipe/materialsManage/src/main/java/com/thhy/materials/modules/biz/embedment/service/impl/SysEmbedmentRecordServiceImpl.java | 124 ++++++++++++++++++++++++++++++++---------
1 files changed, 97 insertions(+), 27 deletions(-)
diff --git a/hd/pipe/materialsManage/src/main/java/com/thhy/materials/modules/biz/embedment/service/impl/SysEmbedmentRecordServiceImpl.java b/hd/pipe/materialsManage/src/main/java/com/thhy/materials/modules/biz/embedment/service/impl/SysEmbedmentRecordServiceImpl.java
index bd82644..398276d 100644
--- a/hd/pipe/materialsManage/src/main/java/com/thhy/materials/modules/biz/embedment/service/impl/SysEmbedmentRecordServiceImpl.java
+++ b/hd/pipe/materialsManage/src/main/java/com/thhy/materials/modules/biz/embedment/service/impl/SysEmbedmentRecordServiceImpl.java
@@ -1,21 +1,32 @@
package com.thhy.materials.modules.biz.embedment.service.impl;
+import cn.hutool.core.text.StrBuilder;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.thhy.general.common.BasicMessage;
import com.thhy.general.common.BasicResult;
-import com.thhy.general.common.IBasicStatus;
import com.thhy.general.config.SysUserInfo;
import com.thhy.general.exception.BasicException;
import com.thhy.general.utils.ExcelUtils;
import com.thhy.general.utils.UserInfoUtils;
+import com.thhy.materials.modules.biz.embedment.dto.EmbedmentGoodsDto;
import com.thhy.materials.modules.biz.embedment.dto.EmbedmentRecordDto;
import com.thhy.materials.modules.biz.embedment.entity.SysEmbedmentGoodsEntity;
import com.thhy.materials.modules.biz.embedment.entity.SysEmbedmentRecordEntity;
import com.thhy.materials.modules.biz.embedment.mapper.SysEmbedmentGoodsMapper;
import com.thhy.materials.modules.biz.embedment.mapper.SysEmbedmentRecordMapper;
import com.thhy.materials.modules.biz.embedment.service.SysEmbedmentRecordService;
+import com.thhy.materials.modules.biz.materials.entity.SysAssistGood;
import com.thhy.materials.modules.biz.utils.ExcelUtil;
+import org.apache.commons.lang3.StringUtils;
+import org.apache.poi.ss.usermodel.DataValidation;
+import org.apache.poi.ss.usermodel.DataValidationConstraint;
+import org.apache.poi.ss.usermodel.DataValidationHelper;
+import org.apache.poi.ss.util.CellRangeAddressList;
+import org.apache.poi.util.IOUtils;
+import org.apache.poi.xssf.usermodel.XSSFRow;
+import org.apache.poi.xssf.usermodel.XSSFSheet;
+import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
@@ -23,10 +34,14 @@
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
+import java.io.OutputStream;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
+import java.util.Map;
+import java.util.stream.Collectors;
+import java.util.stream.Stream;
/**
* @Author QiuYuHao
@@ -44,28 +59,30 @@
@Override
+ @Transactional(rollbackFor = Exception.class)
public BasicResult insert(SysEmbedmentRecordEntity sysEmbedmentRecordEntity) {
SysUserInfo sysUserInfo = UserInfoUtils.getInstance().getUserInfo();
sysEmbedmentRecordEntity.setCreateUser(sysUserInfo.getRealName());
+ sysEmbedmentRecordEntity.setCompanyId(sysUserInfo.getCompanyId());
SysEmbedmentGoodsEntity entity = sysEmbedmentGoodsMapper.findEntity(sysEmbedmentRecordEntity.getEmbedmentId());
- if(entity!=null){
- String stockType = sysEmbedmentRecordEntity.getStockType();
- //stockType 1入库 2出库
- int result = entity.getStock();
- if("1".equals(stockType)){
- result= entity.getStock() + sysEmbedmentRecordEntity.getChangeStock();
- }else{
- result= entity.getStock() - sysEmbedmentRecordEntity.getChangeStock();
+ if(entity!=null){
+ String stockType = sysEmbedmentRecordEntity.getStockType();
+ //stockType 1入库 2出库
+ int result = entity.getStock();
+ if("1".equals(stockType)){
+ result= entity.getStock() + sysEmbedmentRecordEntity.getChangeStock();
+ }else{
+ result= entity.getStock() - sysEmbedmentRecordEntity.getChangeStock();
+ }
+ if(result < 0 ){
+ return BasicResult.faild("11111","库存不足","库存不足");
+ }
+ entity.setStock(result);
+ sysEmbedmentGoodsMapper.update(entity);//更改库存
+ }else {
+ return BasicResult.faild("11111","库存没有该预埋件,请到【预埋件种类】添加","库存没有该预埋件,请到【预埋件种类】添加");
}
- if(result < 0 ){
- return BasicResult.faild("11111","库存不足","库存不足");
- }
- entity.setStock(result);
- sysEmbedmentGoodsMapper.update(entity);//更改库存
- }else {
- return BasicResult.faild("11111","库存没有该预埋件,请到【预埋件种类】添加","库存没有该预埋件,请到【预埋件种类】添加");
- }
- sysEmbedmentRecordMapper.insert(sysEmbedmentRecordEntity);
+ sysEmbedmentRecordMapper.insert(sysEmbedmentRecordEntity);
return BasicResult.success();
}
@@ -76,7 +93,18 @@
}
@Override
+ @Transactional(rollbackFor = Exception.class)
public BasicResult update(SysEmbedmentRecordEntity sysEmbedmentRecordEntity) {
+ String id = sysEmbedmentRecordEntity.getId();//记录id
+ String embedmentId = sysEmbedmentRecordEntity.getEmbedmentId();//库存id
+ SysEmbedmentRecordEntity queryRecordData = sysEmbedmentRecordMapper.embedmentRecordInfo(id);//查询到的记录
+ Integer dataChangeStock = queryRecordData.getChangeStock();//拿到修改前的入库数量
+ Integer paramChangeStock = sysEmbedmentRecordEntity.getChangeStock();//当前传输入库数量
+ Integer nowChangeStock = paramChangeStock - dataChangeStock;//当前传的和库里的取差值
+ SysEmbedmentGoodsEntity entity = sysEmbedmentGoodsMapper.findEntity(embedmentId);
+ Integer resultStock = entity.getStock() + nowChangeStock;
+ entity.setStock(resultStock);
+ sysEmbedmentGoodsMapper.update(entity);
sysEmbedmentRecordMapper.update(sysEmbedmentRecordEntity);
return BasicResult.success();
}
@@ -115,9 +143,40 @@
}
@Override
- public void recordExportTemplate(EmbedmentRecordDto embedmentRecordDto, HttpServletResponse response) {
- List<SysEmbedmentRecordEntity> sysEmbedmentRecordEntities = new ArrayList<>();
- ExcelUtils.downExcel(sysEmbedmentRecordEntities,SysEmbedmentRecordEntity.class,response,"预埋件出入库");
+ public void recordExportTemplate(EmbedmentGoodsDto embedmentGoodsDto, HttpServletResponse response) {
+ embedmentGoodsDto = new EmbedmentGoodsDto();
+ SysUserInfo sysUserInfo = UserInfoUtils.getInstance().getUserInfo();
+ String companyId = sysUserInfo.getCompanyId();
+ XSSFWorkbook book = new XSSFWorkbook();
+ XSSFSheet sheet = book.createSheet();
+ XSSFRow row = sheet.createRow(0);
+ row.createCell(0).setCellValue("物品名称-规格型号");
+ row.createCell(1).setCellValue("入库数量");
+ row.createCell(2).setCellValue("单价");
+ row.createCell(3).setCellValue("金额");
+ row.createCell(4).setCellValue("备注");
+ embedmentGoodsDto.setCompanyId(companyId);
+ List<String> lx = sysEmbedmentGoodsMapper.findAll(embedmentGoodsDto).stream().map(s -> s.getEmbedmentName()+"-"+s.getEmbedmentModel()).collect(Collectors.toList());
+ String[] gjlx = lx.toArray(new String[lx.size()]);
+
+ //物品名称-规格型号
+ CellRangeAddressList regions1 = new CellRangeAddressList(1, 500, 0, 0);
+ DataValidationHelper dataValidationHelper = sheet.getDataValidationHelper();
+ DataValidationConstraint createExplicitListConstraint1 = dataValidationHelper.createExplicitListConstraint(gjlx);
+ DataValidation createValidation1 = dataValidationHelper.createValidation(createExplicitListConstraint1, regions1);
+ sheet.addValidationData(createValidation1);
+ response.setContentType("application/vnd.ms-excel;charset=UTF-8");
+ response.setHeader("Content-Disposition", "attachment;filename=test.xls");
+ OutputStream out = null;
+ try {
+ out = response.getOutputStream();
+ book.write(out);
+ out.close();
+ } catch (Exception e) {
+ e.printStackTrace();
+ } finally {
+ IOUtils.closeQuietly(out);
+ }
}
@Override
@@ -135,23 +194,34 @@
String embedmentNameAndModel = list.get(0).toString();
String[] split = embedmentNameAndModel.split("-");
String embedmentName = split[0];
- String embedmentModel = split[1];
- String id = sysEmbedmentGoodsMapper.embedmentNameAndType(embedmentName,null);
+ StringBuilder embedmentModel = new StringBuilder();
+ for (int i = 1; i < split.length; i++) {
+ if (StringUtils.isBlank(embedmentModel)){
+ embedmentModel.append(split[i]);
+ }else {
+ embedmentModel.append("-"+split[i]);
+ }
+
+ }
+ String id = sysEmbedmentGoodsMapper.embedmentNameAndType(embedmentName,null, embedmentModel.toString());
+ if(StringUtils.isBlank(id)) {
+ throw new BasicException(new BasicMessage("500","库存没有【"+embedmentName+"】,请到预埋件种类新增,新增完可重新导入!"));
+ }
SysEmbedmentRecordEntity sysEmbedmentRecordEntity = new SysEmbedmentRecordEntity();
sysEmbedmentRecordEntity.setEmbedmentId(id);
//入库数量
- Integer changeStock = Integer.valueOf(list.get(2).toString());
+ Integer changeStock = Integer.valueOf(list.get(1).toString());
sysEmbedmentRecordEntity.setChangeStock(changeStock);
//单价
- String dj = list.get(3).toString();
+ String dj = list.get(2).toString();
BigDecimal singlePrice = new BigDecimal(dj);
sysEmbedmentRecordEntity.setSinglePrice(singlePrice);
//金额
- String je = list.get(4).toString();
+ String je = list.get(3).toString();
BigDecimal amount = new BigDecimal(je);
sysEmbedmentRecordEntity.setAmount(amount);
//备注
- String remark = list.get(5).toString();
+ String remark = list.get(4).toString();
sysEmbedmentRecordEntity.setRemark(remark);
//入库人
SysUserInfo sysUserInfo = UserInfoUtils.getInstance().getUserInfo();
--
Gitblit v1.9.3