From 232cab080647152de06755fbac3d4170629d5b3c Mon Sep 17 00:00:00 2001
From: 叶松 <2217086471@qq.com>
Date: 星期二, 26 九月 2023 10:25:58 +0800
Subject: [PATCH] Merge branch 'master' of http://111.30.93.211:10101/r/supipe

---
 hd/pipe/materialsManage/src/main/java/com/thhy/materials/modules/biz/embedment/service/impl/SysEmbedmentRecordServiceImpl.java |  248 +++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 248 insertions(+), 0 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
new file mode 100644
index 0000000..73740a3
--- /dev/null
+++ b/hd/pipe/materialsManage/src/main/java/com/thhy/materials/modules/biz/embedment/service/impl/SysEmbedmentRecordServiceImpl.java
@@ -0,0 +1,248 @@
+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.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.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;
+import org.springframework.web.multipart.MultipartFile;
+
+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
+ * @CreateDate 2023-09-22 16:28:24
+ * 预埋件出入库实现
+ */
+@Service
+public class SysEmbedmentRecordServiceImpl implements SysEmbedmentRecordService{
+
+	@Autowired
+	private SysEmbedmentRecordMapper sysEmbedmentRecordMapper;
+
+	@Autowired
+	private SysEmbedmentGoodsMapper sysEmbedmentGoodsMapper;
+
+
+	@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(result < 0 ){
+					return BasicResult.faild("11111","库存不足","库存不足");
+				}
+				entity.setStock(result);
+				sysEmbedmentGoodsMapper.update(entity);//更改库存
+			}else {
+				return BasicResult.faild("11111","库存没有该预埋件,请到【预埋件种类】添加","库存没有该预埋件,请到【预埋件种类】添加");
+			}
+			sysEmbedmentRecordMapper.insert(sysEmbedmentRecordEntity);
+		return BasicResult.success();
+	}
+
+	@Override
+	public BasicResult embedmentRecordDel(String id) {
+		sysEmbedmentRecordMapper.embedmentRecordDel(id);
+		return BasicResult.success();
+	}
+
+	@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();
+	}
+
+	@Override
+	public BasicResult embedmentRecordList(EmbedmentRecordDto embedmentRecordDto) {
+		SysUserInfo sysUserInfo = UserInfoUtils.getInstance().getUserInfo();
+		embedmentRecordDto.setCompanyId(sysUserInfo.getCompanyId());
+		PageHelper.startPage(embedmentRecordDto.getPageNum(),embedmentRecordDto.getPageSize());
+		List<SysEmbedmentRecordEntity> sysEmbedmentRecordEntities = sysEmbedmentRecordMapper.embedmentRecordList(embedmentRecordDto);
+		PageInfo<SysEmbedmentRecordEntity> info = new PageInfo<>(sysEmbedmentRecordEntities);
+		return BasicResult.success(info);
+	}
+
+	@Override
+	public BasicResult embedmentRecordOutList(EmbedmentRecordDto embedmentRecordDto) {
+		SysUserInfo sysUserInfo = UserInfoUtils.getInstance().getUserInfo();
+		embedmentRecordDto.setCompanyId(sysUserInfo.getCompanyId());
+		PageHelper.startPage(embedmentRecordDto.getPageNum(),embedmentRecordDto.getPageSize());
+		List<SysEmbedmentRecordEntity> sysEmbedmentRecordEntities = sysEmbedmentRecordMapper.embedmentRecordOutList(embedmentRecordDto);
+		PageInfo<SysEmbedmentRecordEntity> info = new PageInfo<>(sysEmbedmentRecordEntities);
+		return BasicResult.success(info);
+	}
+
+	@Override
+	public BasicResult embedmentRecordInfo(String id) {
+		return BasicResult.success(sysEmbedmentRecordMapper.embedmentRecordInfo(id));
+	}
+
+	@Override
+	public void export(EmbedmentRecordDto embedmentRecordDto, HttpServletResponse response) {
+		SysUserInfo sysUserInfo = UserInfoUtils.getInstance().getUserInfo();
+		embedmentRecordDto.setCompanyId(sysUserInfo.getCompanyId());
+		List<SysEmbedmentRecordEntity> sysEmbedmentRecordEntities = sysEmbedmentRecordMapper.embedmentRecordList(embedmentRecordDto);
+		ExcelUtils.downExcel(sysEmbedmentRecordEntities,SysEmbedmentRecordEntity.class,response,"预埋件入库");
+	}
+
+	@Override
+	public void recordExportTemplate(EmbedmentRecordDto embedmentRecordDto, HttpServletResponse response) {
+		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("备注");
+		embedmentRecordDto.setCompanyId(companyId);
+		List<String> lx = sysEmbedmentRecordMapper.embedmentRecordList(embedmentRecordDto).stream().map(s -> s.getEmbedmentNameAndModel()).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
+	@Transactional(rollbackFor = Exception.class)
+	public BasicResult variateExcel(MultipartFile file, HttpServletRequest request) {
+		List<List<Object>> lists = null;//去工具类处理,返回excel中的数据
+		try {
+			lists = ExcelUtil.getUserListByExcel(file.getInputStream(), file.getOriginalFilename());
+		} catch (Exception e) {
+			e.printStackTrace();
+		}
+		lists.remove(0);
+		if (lists.size()>0){
+			for (List<Object> list :lists){
+				String embedmentNameAndModel = list.get(0).toString();
+				String[] split = embedmentNameAndModel.split("-");
+				String embedmentName = split[0];
+				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(1).toString());
+				sysEmbedmentRecordEntity.setChangeStock(changeStock);
+				//单价
+				String dj = list.get(2).toString();
+				BigDecimal singlePrice = new BigDecimal(dj);
+				sysEmbedmentRecordEntity.setSinglePrice(singlePrice);
+				//金额
+				String je = list.get(3).toString();
+				BigDecimal amount = new BigDecimal(je);
+				sysEmbedmentRecordEntity.setAmount(amount);
+				//备注
+				String remark = list.get(4).toString();
+				sysEmbedmentRecordEntity.setRemark(remark);
+				//入库人
+				SysUserInfo sysUserInfo = UserInfoUtils.getInstance().getUserInfo();
+				String companyId = sysUserInfo.getCompanyId();
+				sysEmbedmentRecordEntity.setCreateUser(sysUserInfo.getRealName());
+				sysEmbedmentRecordEntity.setCompanyId(companyId);
+				//stockType 1入库
+				sysEmbedmentRecordEntity.setStockType("1");
+				SysEmbedmentGoodsEntity entity = sysEmbedmentGoodsMapper.findEntity(sysEmbedmentRecordEntity.getEmbedmentId());
+				if(entity!=null){
+					int result = entity.getStock() + sysEmbedmentRecordEntity.getChangeStock();
+					entity.setStock(result);
+					sysEmbedmentGoodsMapper.update(entity);//更改库存
+				}else {
+					throw new BasicException(new BasicMessage("500","库存没有【"+embedmentName+"】,请到预埋件种类新增,新增完可重新导入!"));
+				}
+				sysEmbedmentRecordMapper.insert(sysEmbedmentRecordEntity);
+			}
+			return BasicResult.success("导入成功");
+		}else {
+			return BasicResult.faild("11111","error","空文件");
+		}
+	}
+
+
+}

--
Gitblit v1.9.3