Commit 8c26c0f4 authored by tangwei's avatar tangwei

修改导入

parent 008874f8
......@@ -576,14 +576,14 @@ public class EquipmentDetailController extends AbstractBaseController {
// }
// List<EquipmentDetailDownloadTemplateVO> equipmentDetailDownloadS = ExcelUtils.importExcel(file, 1, 1, EquipmentDetailDownloadTemplateVO.class);
Object date="";
ExcelEnums excelEnums = ExcelEnums.getByKey(type);
ExcelDto excelDto = new ExcelDto(excelEnums.getFileName(), excelEnums.getSheetName(), excelEnums.getClassUrl(), excelEnums.getType());
excelService.commonUpload(file, excelDto, getSelectedOrgInfo(), getUserInfo());
date= excelService.commonUpload(file, excelDto, getSelectedOrgInfo(), getUserInfo());
EquipmentDetailController controllerProxy = SpringUtils.getBean(EquipmentDetailController.class);
controllerProxy.refreshAllCount();
return ResponseHelper.buildResponse(null);
return ResponseHelper.buildResponse(date);
}
@Async
......
......@@ -18,5 +18,7 @@ public interface IExcelService {
*/
List<EquipmentPoint> exportPointData(Map<String, Object> paramsMap);
void commonUpload(MultipartFile multipartFile, ExcelDto excelDto, ReginParams reginParams, AgencyUserModel agencyUserModel);
//void commonUpload(MultipartFile multipartFile, ExcelDto excelDto, ReginParams reginParams, AgencyUserModel agencyUserModel);
Object commonUpload(MultipartFile multipartFile, ExcelDto excelDto, ReginParams reginParams, AgencyUserModel agencyUserModel);
}
......@@ -31,7 +31,8 @@ public interface IStockService extends IService<Stock> {
* @return
*/
List<EquipmentSpecific> uploadList(List<EquipmentDetailDownloadVO> equipmentDetailDownloadVOS, ReginParams reginParams, AgencyUserModel agencyUserModel);
List<EquipmentSpecific> uploadListByTemplate(List<EquipmentDetailDownloadTemplateDto> equipmentDetailDownloadVOS, ReginParams reginParams, AgencyUserModel agencyUserModel);
//List<EquipmentSpecific> uploadListByTemplate(List<EquipmentDetailDownloadTemplateDto> equipmentDetailDownloadVOS, ReginParams reginParams, AgencyUserModel agencyUserModel);
Object uploadListByTemplate(List<EquipmentDetailDownloadTemplateDto> equipmentDetailDownloadVOS, ReginParams reginParams, AgencyUserModel agencyUserModel);
}
......@@ -49,11 +49,12 @@ public class ExcelServiceImpl implements IExcelService {
}
@Override
public void commonUpload(MultipartFile multipartFile, ExcelDto excelDto, ReginParams reginParams, AgencyUserModel agencyUserModel) {
public Object commonUpload(MultipartFile multipartFile, ExcelDto excelDto, ReginParams reginParams, AgencyUserModel agencyUserModel) {
Object date="";
switch (excelDto.getType()) {
case "XFZB":
try {
excelImportFireEquipment(multipartFile, reginParams, agencyUserModel);
date= excelImportFireEquipment(multipartFile, reginParams, agencyUserModel);
} catch (Exception e) {
throw new BadRequest(e.getMessage());
}
......@@ -67,19 +68,21 @@ public class ExcelServiceImpl implements IExcelService {
}
break;
}
return;
return date;
}
private void excelImportFireEquipment(MultipartFile multipartFile, ReginParams reginParams, AgencyUserModel agencyUserModel) throws Exception {
private Object excelImportFireEquipment(MultipartFile multipartFile, ReginParams reginParams, AgencyUserModel agencyUserModel) throws Exception {
Object date="";
List<EquipmentDetailDownloadTemplateDto> excelDtoList = ExcelUtil.readFirstSheetExcel(multipartFile,
EquipmentDetailDownloadTemplateDto.class, 1);
if (excelDtoList != null && excelDtoList.size() > 0) {
iStockService.uploadListByTemplate(excelDtoList, reginParams, agencyUserModel);
date=iStockService.uploadListByTemplate(excelDtoList, reginParams, agencyUserModel);
} else {
throw new BadRequest("请填写数据后再上传!");
}
return date;
}
private void excelImporVideo(MultipartFile multipartFile) throws Exception {
......
......@@ -7,6 +7,8 @@ import java.util.stream.Collectors;
import javax.annotation.Resource;
import com.sun.org.apache.bcel.internal.generic.RETURN;
import com.yeejoin.equipmanage.common.entity.*;
import com.yeejoin.equipmanage.common.utils.SpringUtils;
import com.alibaba.fastjson.JSONObject;
import com.yeejoin.amos.boot.biz.common.utils.RedisUtils;
......@@ -17,6 +19,9 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Lazy;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;
import org.springframework.transaction.PlatformTransactionManager;
import org.springframework.transaction.TransactionDefinition;
import org.springframework.transaction.TransactionStatus;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.transaction.support.TransactionSynchronization;
import org.springframework.transaction.support.TransactionSynchronizationManager;
......@@ -28,21 +33,6 @@ import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.yeejoin.amos.boot.biz.common.bo.ReginParams;
import com.yeejoin.amos.feign.privilege.model.AgencyUserModel;
import com.yeejoin.equipmanage.common.entity.Equipment;
import com.yeejoin.equipmanage.common.entity.EquipmentDetail;
import com.yeejoin.equipmanage.common.entity.EquipmentIndex;
import com.yeejoin.equipmanage.common.entity.EquipmentManageEntity;
import com.yeejoin.equipmanage.common.entity.EquipmentSpecific;
import com.yeejoin.equipmanage.common.entity.EquipmentSpecificIndex;
import com.yeejoin.equipmanage.common.entity.EquipmentSystemSourceStatistics;
import com.yeejoin.equipmanage.common.entity.FireFightingSystemEntity;
import com.yeejoin.equipmanage.common.entity.Journal;
import com.yeejoin.equipmanage.common.entity.ManufacturerInfo;
import com.yeejoin.equipmanage.common.entity.Stock;
import com.yeejoin.equipmanage.common.entity.StockBill;
import com.yeejoin.equipmanage.common.entity.StockBillDetail;
import com.yeejoin.equipmanage.common.entity.StockDetail;
import com.yeejoin.equipmanage.common.entity.WarehouseStructure;
import com.yeejoin.equipmanage.common.entity.vo.EquipmentDetailDownloadVO;
import com.yeejoin.equipmanage.common.utils.ExcelUtils;
import com.yeejoin.equipmanage.common.utils.QRCodeUtil;
......@@ -127,6 +117,16 @@ public class StockServiceImpl extends ServiceImpl<StockMapper, Stock> implements
@Autowired
private RedisUtils redisUtils;
@Autowired
private PlatformTransactionManager platformTransactionManager;
@Autowired
private TransactionDefinition transactionDefinition;
@Override
@Transactional(rollbackFor = {Exception.class})
public StockBill in(List<StockDetail> list, String type, AgencyUserModel agencyUserModel) {
......@@ -288,200 +288,436 @@ public class StockServiceImpl extends ServiceImpl<StockMapper, Stock> implements
@Override
// @Transactional(rollbackFor = Exception.class)
public List<EquipmentSpecific> uploadListByTemplate(List<EquipmentDetailDownloadTemplateDto> equipmentDetailDownloadVOS, ReginParams reginParams, AgencyUserModel agencyUserModel) {
public Object uploadListByTemplate(List<EquipmentDetailDownloadTemplateDto> equipmentDetailDownloadVOS, ReginParams reginParams, AgencyUserModel agencyUserModel) {
StringBuffer fireFightSysIdsBuffer = new StringBuffer();
StringBuffer errBufferName= new StringBuffer();
StringBuffer erryy= new StringBuffer();
int errNum=0; //失败条数
int okNum=0; //成功条数
errBufferName.append("导入失败装备:");
SimpleDateFormat stf = new SimpleDateFormat("yyyy-MM-dd");
List<EquipmentSpecific> list = new ArrayList<>();
if (equipmentDetailDownloadVOS.size() == 0) {
throw new BadRequest("请填写数据后再上传!");
}
for (int i = 0; i < equipmentDetailDownloadVOS.size(); i++) {
//查询装备定义信息
QueryWrapper<Equipment> equipmentQueryWrapper = new QueryWrapper<>();
equipmentQueryWrapper.lambda().eq(Equipment::getCode, equipmentDetailDownloadVOS.get(i).getCode());
Equipment equipment = equipmentMapper.selectOne(equipmentQueryWrapper);
if (equipment == null) {
throw new BadRequest(String.format("装备(器材)编码[%S]填写错误,请输入正确的装备(器材)编码!",equipmentDetailDownloadVOS.get(i).getCode()));
}
String sysCode = equipmentDetailDownloadVOS.get(i).getSystemCode();
if (StringUtils.isNotEmpty(sysCode) && StringUtils.isNotEmpty(sysCode.trim())) {
Integer code = equipmentSpecificMapper.selectCount(new QueryWrapper<EquipmentSpecific>().eq("code", sysCode.trim()));
if (code != 0) {
throw new BadRequest(String.format("设备编码[%S]填写重复,请重新输入!",sysCode));
}
}
String iot = equipmentDetailDownloadVOS.get(i).getIotCode();
if (StringUtils.isNotEmpty(iot) && StringUtils.isNotEmpty(iot.trim())) {
Integer iot_code = equipmentSpecificMapper.selectCount(new QueryWrapper<EquipmentSpecific>().eq("iot_code", iot.trim()));
if (iot_code != 0) {
throw new BadRequest(String.format("物联编码[%S]填写重复,请重新输入!",iot));
}
}
AtomicReference<String> fightSysIds = new AtomicReference<>("");
String fightingSysCodes = equipmentDetailDownloadVOS.get(i).getFightingSysCodes();
if (StringUtils.isNotBlank(fightingSysCodes)) {
String[] idsArr = fightingSysCodes.split("-");
List<FireFightingSystemEntity> fightingSystemList = fireFightingSystemService.getFightingSysByCodes(idsArr);
if (!fightingSystemList.isEmpty()) {
fightingSystemList.stream().forEach(x -> {
String sysCodes = fightSysIds.get();
if (StringUtils.isNotBlank(sysCodes)) {
fightSysIds.set(String.join(",", sysCodes, String.valueOf(x.getId())));
} else {
fightSysIds.set(String.join(",", String.valueOf(x.getId())));
}
});
}
}
//插入模板信息
EquipmentDetail equipmentDetail = new EquipmentDetail();
equipmentDetail.setCode(equipmentDetailDownloadVOS.get(i).getCode());
equipmentDetail.setBrand(equipmentDetailDownloadVOS.get(i).getBrand());
equipmentDetail.setStandard(equipmentDetailDownloadVOS.get(i).getStandard());
LambdaQueryWrapper<ManufacturerInfo> queryWrapper = new LambdaQueryWrapper<>();
ManufacturerInfo info = manufacturerInfoService.getOne(queryWrapper.eq(ManufacturerInfo::getName, equipmentDetailDownloadVOS.get(i).getManufacturerName()));
if (StringUtil.isNotEmpty(info)) {
// throw new BadRequest("名称为" + equipmentDetailDownloadVOS.get(i).getManufacturerName() + "的生产厂商不存在!");
equipmentDetail.setManufacturerId(info.getId());
equipmentDetail.setManufacturerName(equipmentDetailDownloadVOS.get(i).getManufacturerName());
}
equipmentDetail.setEquipmentId(equipment.getId());
equipmentDetail.setEquipmentName(equipment.getName());
equipmentDetail.setName(equipmentDetailDownloadVOS.get(i).getName());
equipmentDetail.setArea(equipmentDetailDownloadVOS.get(i).getDescription());
// 导入新增所属单位
if (StringUtils.isNotBlank(equipmentDetailDownloadVOS.get(i).getCompanyName())) {
String[] company = equipmentDetailDownloadVOS.get(i).getCompanyName().split("@");
equipmentDetail.setCompanyName(company[0]);
try {
if (equipmentDetailDownloadVOS.size() == 0) {
throw new BadRequest("请填写数据后再上传!");
}
equipmentDetailMapper.insert(equipmentDetail);
//生成单件设备信息
String qrCode = QRCodeUtil.generateQRCode();
EquipmentSpecific equipmentSpecific = new EquipmentSpecific();
equipmentSpecific.setQrCode(qrCode);
equipmentSpecific.setEquipmentDetailId(equipmentDetail.getId());
equipmentSpecific.setOrgCode(reginParams.getCompany().getOrgCode());
equipmentSpecific.setEquipmentCode(equipmentDetail.getCode());
equipmentSpecific.setName(equipmentDetail.getName());
String iotCode = equipmentDetailDownloadVOS.get(i).getIotCode();
iotCode = ExcelUtils.replaceAllBlank(iotCode);
equipmentSpecific.setIotCode(iotCode);
equipmentSpecific.setCode(equipmentDetailDownloadVOS.get(i).getSystemCode());
equipmentSpecific.setSystemId(fightSysIds.get());
equipmentSpecific.setNum(1);
equipmentSpecific.setSingle(true);
fireFightSysIdsBuffer.append(fightSysIds.get() + ",");
// 导入新增所属队伍
if (StringUtils.isNotBlank(equipmentDetailDownloadVOS.get(i).getFireTeam())) {
String[] fireTeam = equipmentDetailDownloadVOS.get(i).getFireTeam().split("@");
equipmentSpecific.setTeamName(fireTeam[0]);
equipmentSpecific.setTeamId(fireTeam[1]);
// for (int i = 0; i < equipmentDetailDownloadVOS.size(); i++) {
// //查询装备定义信息
// QueryWrapper<Equipment> equipmentQueryWrapper = new QueryWrapper<>();
// equipmentQueryWrapper.lambda().eq(Equipment::getCode, equipmentDetailDownloadVOS.get(i).getCode());
// Equipment equipment = equipmentMapper.selectOne(equipmentQueryWrapper);
// if (equipment == null) {
// throw new BadRequest(String.format("装备(器材)编码[%S]填写错误,请输入正确的装备(器材)编码!",equipmentDetailDownloadVOS.get(i).getCode()));
// }
// String sysCode = equipmentDetailDownloadVOS.get(i).getSystemCode();
// if (StringUtils.isNotEmpty(sysCode) && StringUtils.isNotEmpty(sysCode.trim())) {
// Integer code = equipmentSpecificMapper.selectCount(new QueryWrapper<EquipmentSpecific>().eq("code", sysCode.trim()));
// if (code != 0) {
// throw new BadRequest(String.format("设备编码[%S]填写重复,请重新输入!",sysCode));
// }
// }
// String iot = equipmentDetailDownloadVOS.get(i).getIotCode();
// if (StringUtils.isNotEmpty(iot) && StringUtils.isNotEmpty(iot.trim())) {
// Integer iot_code = equipmentSpecificMapper.selectCount(new QueryWrapper<EquipmentSpecific>().eq("iot_code", iot.trim()));
// if (iot_code != 0) {
// throw new BadRequest(String.format("物联编码[%S]填写重复,请重新输入!",iot));
// }
// }
// AtomicReference<String> fightSysIds = new AtomicReference<>("");
// String fightingSysCodes = equipmentDetailDownloadVOS.get(i).getFightingSysCodes();
// if (StringUtils.isNotBlank(fightingSysCodes)) {
// String[] idsArr = fightingSysCodes.split("-");
// List<FireFightingSystemEntity> fightingSystemList = fireFightingSystemService.getFightingSysByCodes(idsArr);
// if (!fightingSystemList.isEmpty()) {
// fightingSystemList.stream().forEach(x -> {
// String sysCodes = fightSysIds.get();
// if (StringUtils.isNotBlank(sysCodes)) {
// fightSysIds.set(String.join(",", sysCodes, String.valueOf(x.getId())));
// } else {
// fightSysIds.set(String.join(",", String.valueOf(x.getId())));
// }
// });
// }
// }
//
// //插入模板信息
// EquipmentDetail equipmentDetail = new EquipmentDetail();
// equipmentDetail.setCode(equipmentDetailDownloadVOS.get(i).getCode());
// equipmentDetail.setBrand(equipmentDetailDownloadVOS.get(i).getBrand());
// equipmentDetail.setStandard(equipmentDetailDownloadVOS.get(i).getStandard());
// LambdaQueryWrapper<ManufacturerInfo> queryWrapper = new LambdaQueryWrapper<>();
// ManufacturerInfo info = manufacturerInfoService.getOne(queryWrapper.eq(ManufacturerInfo::getName, equipmentDetailDownloadVOS.get(i).getManufacturerName()));
// if (StringUtil.isNotEmpty(info)) {
// // throw new BadRequest("名称为" + equipmentDetailDownloadVOS.get(i).getManufacturerName() + "的生产厂商不存在!");
// equipmentDetail.setManufacturerId(info.getId());
// equipmentDetail.setManufacturerName(equipmentDetailDownloadVOS.get(i).getManufacturerName());
// }
// equipmentDetail.setEquipmentId(equipment.getId());
// equipmentDetail.setEquipmentName(equipment.getName());
// equipmentDetail.setName(equipmentDetailDownloadVOS.get(i).getName());
// equipmentDetail.setArea(equipmentDetailDownloadVOS.get(i).getDescription());
//
// // 导入新增所属单位
//
// if (StringUtils.isNotBlank(equipmentDetailDownloadVOS.get(i).getCompanyName())) {
// String[] company = equipmentDetailDownloadVOS.get(i).getCompanyName().split("@");
// equipmentDetail.setCompanyName(company[0]);
// }
//
// equipmentDetailMapper.insert(equipmentDetail);
//
// //生成单件设备信息
// String qrCode = QRCodeUtil.generateQRCode();
// EquipmentSpecific equipmentSpecific = new EquipmentSpecific();
// equipmentSpecific.setQrCode(qrCode);
// equipmentSpecific.setEquipmentDetailId(equipmentDetail.getId());
// equipmentSpecific.setOrgCode(reginParams.getCompany().getOrgCode());
// equipmentSpecific.setEquipmentCode(equipmentDetail.getCode());
// equipmentSpecific.setName(equipmentDetail.getName());
// String iotCode = equipmentDetailDownloadVOS.get(i).getIotCode();
// iotCode = ExcelUtils.replaceAllBlank(iotCode);
// equipmentSpecific.setIotCode(iotCode);
// equipmentSpecific.setCode(equipmentDetailDownloadVOS.get(i).getSystemCode());
// equipmentSpecific.setSystemId(fightSysIds.get());
// equipmentSpecific.setNum(1);
// equipmentSpecific.setSingle(true);
// fireFightSysIdsBuffer.append(fightSysIds.get() + ",");
// // 导入新增所属队伍
// if (StringUtils.isNotBlank(equipmentDetailDownloadVOS.get(i).getFireTeam())) {
// String[] fireTeam = equipmentDetailDownloadVOS.get(i).getFireTeam().split("@");
// equipmentSpecific.setTeamName(fireTeam[0]);
// equipmentSpecific.setTeamId(fireTeam[1]);
// }
// // 导入新增所属单位
//
// if (StringUtils.isNotBlank(equipmentDetailDownloadVOS.get(i).getCompanyName())) {
// String[] company = equipmentDetailDownloadVOS.get(i).getCompanyName().split("@");
// equipmentSpecific.setAgencyId(company[1]);
// equipmentSpecific.setAgencyName(company[0]);
// equipmentSpecific.setBizOrgCode(company[2]);
// equipmentSpecific.setBizOrgName(company[0]);
//
//
// }
// equipmentSpecificMapper.insert(equipmentSpecific);
// StockServiceImpl controllerProxy = SpringUtils.getBean(StockServiceImpl.class);
// //添加对于装备类型统计数据的刷新
// controllerProxy.refreshCount(equipmentSpecific.getBizOrgCode());
// //位置编码不为空入库
// if (equipmentDetailDownloadVOS.get(i) != null && equipmentDetailDownloadVOS.get(i).getWarehouseStructCode() != null) {
// QueryWrapper<WarehouseStructure> warehouseStructureQueryWrapper = new QueryWrapper<>();
// warehouseStructureQueryWrapper.lambda().eq(WarehouseStructure::getCode, equipmentDetailDownloadVOS.get(i).getWarehouseStructCode());
// WarehouseStructure warehouseStructure = warehouseStructureService.getOne(warehouseStructureQueryWrapper);
// if (warehouseStructure == null) {
// throw new BadRequest(String.format("货位编码[%S]填写错误,请输入正确的货位编码!",equipmentDetailDownloadVOS.get(i).getWarehouseStructCode()));
// } else {
// equipmentSpecific.setPosition(warehouseStructure.getFullName());
// equipmentSpecificMapper.updateById(equipmentSpecific);
// }
// // 插入库存
// Stock stock = new Stock();
// stock.setAmount(Double.valueOf(equipmentSpecific.getNum()));
// stock.setCompanyName(reginParams.getCompany().getCompanyName());
// stock.setCompanyName(reginParams.getCompany().getOrgCode());
// stock.setDepartmentOrgcode(reginParams.getDepartment().getOrgCode());
// stock.setCompanyName(reginParams.getDepartment().getDepartmentName());
// stock.setEquipmentDetailId(equipmentSpecific.getEquipmentDetailId());
// stock.setWarehouseId(warehouseStructure.getWarehouseId());
// equipmentSpecific.setStock(stock);
// this.save(stock);
//
// //库存详情
// StockDetail stockDetail = new StockDetail();
// stockDetail.setCompanyName(reginParams.getCompany().getCompanyName());
// stockDetail.setOrgCode(reginParams.getCompany().getOrgCode());
// stockDetail.setDepartmentName(reginParams.getDepartment().getDepartmentName());
// stockDetail.setDepartmentOrgcode(reginParams.getDepartment().getOrgCode());
// stockDetail.setEquipmentDetailId(equipmentSpecific.getEquipmentDetailId());
// stockDetail.setEquipmentSpecificId(equipmentSpecific.getId());
// stockDetail.setStockId(stock.getId());
// stockDetail.setStatus(StockBillTypeEnum.DBRK.getValue());
// stockDetail.setUpdateDate(new Date());
// stockDetail.setQrCode(qrCode);
// stockDetail.setWarehouseStructureId(warehouseStructure.getId());
// stockDetail.setDescription(equipmentDetailDownloadVOS.get(i).getDescription());
// stockDetail.setWarehouseId(warehouseStructure.getWarehouseId());
// stockDetail.setAmount(1.00);
// equipmentSpecific.setStockDetail(stockDetail);
// stockDetailService.save(stockDetail);
//
// //生成入库单
// StockBill stockBill = new StockBill();
// stockBill.setCreatorId(Long.valueOf(agencyUserModel.getUserId()));
// stockBill.setCreatorName(agencyUserModel.getRealName());
// stockBill.setCompanyName(reginParams.getCompany().getCompanyName());
// stockBill.setDepartmentName(reginParams.getDepartment().getDepartmentName());
// stockBill.setDepartmentOrgcode(String.valueOf(reginParams.getDepartment().getDeptOrgCode()));
// stockBill.setOrgCode(reginParams.getCompany().getOrgCode());
// stockBill.setWarehouseId(warehouseStructure.getWarehouseId());
// stockBill.setBillCode(stockBillService.generateQrCode("RK"));
// stockBill.setBillType(StockBillTypeEnum.DBRK.getValue());
// stockBillService.save(stockBill);
//
// //生成入库单详情
// StockBillDetail stockBillDetail = new StockBillDetail();
// stockBillDetail.setAmount(stockDetail.getAmount());
// stockBillDetail.setEquipmentDetailId(equipmentDetail.getId());
// stockBillDetail.setStockDetailId(stockDetail.getId());
// stockBillDetail.setBatchNum(stf.format(new Date()));
// stockBillDetail.setCreatorId(Long.valueOf(agencyUserModel.getUserId()));
// stockBillDetail.setSingleEquipCode(stockDetail.getQrCode());
// stockBillDetail.setStockBillId(stockBill.getId());
// stockBillDetail.setWarehouseStructureId(warehouseStructure.getId());
// stockBillDetailService.save(stockBillDetail);
// }
// list.add(equipmentSpecific);
// this.equipmentSpecificIndexSave(equipmentDetail, equipmentSpecific);
// }
for (int i = 0; i < equipmentDetailDownloadVOS.size(); i++) {
try {
seveRK( equipmentDetailDownloadVOS.get(i), reginParams, agencyUserModel, fireFightSysIdsBuffer,list, errBufferName ,erryy , errNum,
okNum);
} catch (Exception e) {
e.printStackTrace();
}
}
if(fireFightSysIdsBuffer!=null){
relationRedisUtil.delSysRedisKey(fireFightSysIdsBuffer.toString());
}
// 导入新增所属单位
if (StringUtils.isNotBlank(equipmentDetailDownloadVOS.get(i).getCompanyName())) {
String[] company = equipmentDetailDownloadVOS.get(i).getCompanyName().split("@");
equipmentSpecific.setAgencyId(company[1]);
equipmentSpecific.setAgencyName(company[0]);
equipmentSpecific.setBizOrgCode(company[2]);
equipmentSpecific.setBizOrgName(company[0]);
}
equipmentSpecificMapper.insert(equipmentSpecific);
StockServiceImpl controllerProxy = SpringUtils.getBean(StockServiceImpl.class);
//添加对于装备类型统计数据的刷新
controllerProxy.refreshCount(equipmentSpecific.getBizOrgCode());
//位置编码不为空入库
if (equipmentDetailDownloadVOS.get(i) != null && equipmentDetailDownloadVOS.get(i).getWarehouseStructCode() != null) {
QueryWrapper<WarehouseStructure> warehouseStructureQueryWrapper = new QueryWrapper<>();
warehouseStructureQueryWrapper.lambda().eq(WarehouseStructure::getCode, equipmentDetailDownloadVOS.get(i).getWarehouseStructCode());
WarehouseStructure warehouseStructure = warehouseStructureService.getOne(warehouseStructureQueryWrapper);
if (warehouseStructure == null) {
throw new BadRequest(String.format("货位编码[%S]填写错误,请输入正确的货位编码!",equipmentDetailDownloadVOS.get(i).getWarehouseStructCode()));
} else {
equipmentSpecific.setPosition(warehouseStructure.getFullName());
equipmentSpecificMapper.updateById(equipmentSpecific);
TransactionSynchronizationManager.registerSynchronization(new TransactionSynchronization() {
@Override
public void afterCommit() {
List<EquipmentSpecificVo> data = equipmentSpecificMapper.getEquipOrCarByIotCode(null);
if (redisUtils.hasKey("equipAndCarIotCodes")) {
redisUtils.del("equipAndCarIotCodes");
}
redisUtils.set("equipAndCarIotCodes", JSONObject.toJSONString(data));
}
// 插入库存
Stock stock = new Stock();
stock.setAmount(Double.valueOf(equipmentSpecific.getNum()));
stock.setCompanyName(reginParams.getCompany().getCompanyName());
stock.setCompanyName(reginParams.getCompany().getOrgCode());
stock.setDepartmentOrgcode(reginParams.getDepartment().getOrgCode());
stock.setCompanyName(reginParams.getDepartment().getDepartmentName());
stock.setEquipmentDetailId(equipmentSpecific.getEquipmentDetailId());
stock.setWarehouseId(warehouseStructure.getWarehouseId());
equipmentSpecific.setStock(stock);
this.save(stock);
//库存详情
StockDetail stockDetail = new StockDetail();
stockDetail.setCompanyName(reginParams.getCompany().getCompanyName());
stockDetail.setOrgCode(reginParams.getCompany().getOrgCode());
stockDetail.setDepartmentName(reginParams.getDepartment().getDepartmentName());
stockDetail.setDepartmentOrgcode(reginParams.getDepartment().getOrgCode());
stockDetail.setEquipmentDetailId(equipmentSpecific.getEquipmentDetailId());
stockDetail.setEquipmentSpecificId(equipmentSpecific.getId());
stockDetail.setStockId(stock.getId());
stockDetail.setStatus(StockBillTypeEnum.DBRK.getValue());
stockDetail.setUpdateDate(new Date());
stockDetail.setQrCode(qrCode);
stockDetail.setWarehouseStructureId(warehouseStructure.getId());
stockDetail.setDescription(equipmentDetailDownloadVOS.get(i).getDescription());
stockDetail.setWarehouseId(warehouseStructure.getWarehouseId());
stockDetail.setAmount(1.00);
equipmentSpecific.setStockDetail(stockDetail);
stockDetailService.save(stockDetail);
//生成入库单
StockBill stockBill = new StockBill();
stockBill.setCreatorId(Long.valueOf(agencyUserModel.getUserId()));
stockBill.setCreatorName(agencyUserModel.getRealName());
stockBill.setCompanyName(reginParams.getCompany().getCompanyName());
stockBill.setDepartmentName(reginParams.getDepartment().getDepartmentName());
stockBill.setDepartmentOrgcode(String.valueOf(reginParams.getDepartment().getDeptOrgCode()));
stockBill.setOrgCode(reginParams.getCompany().getOrgCode());
stockBill.setWarehouseId(warehouseStructure.getWarehouseId());
stockBill.setBillCode(stockBillService.generateQrCode("RK"));
stockBill.setBillType(StockBillTypeEnum.DBRK.getValue());
stockBillService.save(stockBill);
});
//生成入库单详情
StockBillDetail stockBillDetail = new StockBillDetail();
stockBillDetail.setAmount(stockDetail.getAmount());
stockBillDetail.setEquipmentDetailId(equipmentDetail.getId());
stockBillDetail.setStockDetailId(stockDetail.getId());
stockBillDetail.setBatchNum(stf.format(new Date()));
stockBillDetail.setCreatorId(Long.valueOf(agencyUserModel.getUserId()));
stockBillDetail.setSingleEquipCode(stockDetail.getQrCode());
stockBillDetail.setStockBillId(stockBill.getId());
stockBillDetail.setWarehouseStructureId(warehouseStructure.getId());
stockBillDetailService.save(stockBillDetail);
}
list.add(equipmentSpecific);
this.equipmentSpecificIndexSave(equipmentDetail, equipmentSpecific);
} catch (Exception e) {
//处理异常 返回 成功失败条数
e.printStackTrace();
String date="上传成功:"+okNum+"条---上传失败:"+errNum+"条(失败编号:"+errBufferName+"详情:"+erryy+")";
log.error(date);
return date;
}
relationRedisUtil.delSysRedisKey(fireFightSysIdsBuffer.toString());
TransactionSynchronizationManager.registerSynchronization(new TransactionSynchronization() {
@Override
public void afterCommit() {
List<EquipmentSpecificVo> data = equipmentSpecificMapper.getEquipOrCarByIotCode(null);
if (redisUtils.hasKey("equipAndCarIotCodes")) {
redisUtils.del("equipAndCarIotCodes");
}
redisUtils.set("equipAndCarIotCodes", JSONObject.toJSONString(data));
}
});
return list;
String date="上传成功:"+okNum+"条---上传失败:"+errNum+"条(失败编号:"+errBufferName+"详情:"+erryy+")";
log.error(date);
return date;
}
@Async
public void seveRK(EquipmentDetailDownloadTemplateDto equipmentDetailDownloadVOS,
ReginParams reginParams,
AgencyUserModel agencyUserModel,
StringBuffer fireFightSysIdsBuffer,
List<EquipmentSpecific> list,
StringBuffer errBufferName,
StringBuffer erryy,
int errNum,
int okNum
){
SimpleDateFormat stf = new SimpleDateFormat("yyyy-MM-dd");
TransactionStatus transactionStatus = platformTransactionManager.getTransaction(transactionDefinition);
try {
//查询装备定义信息
QueryWrapper<Equipment> equipmentQueryWrapper = new QueryWrapper<>();
equipmentQueryWrapper.lambda().eq(Equipment::getCode, equipmentDetailDownloadVOS.getCode());
Equipment equipment = equipmentMapper.selectOne(equipmentQueryWrapper);
if (equipment == null) {
throw new RuntimeException(String.format("装备(器材)编码[%S]填写错误,请输入正确的装备(器材)编码!",equipmentDetailDownloadVOS.getCode()));
}
String sysCode = equipmentDetailDownloadVOS.getSystemCode();
if (StringUtils.isNotEmpty(sysCode) && StringUtils.isNotEmpty(sysCode.trim())) {
Integer code = equipmentSpecificMapper.selectCount(new QueryWrapper<EquipmentSpecific>().eq("code", sysCode.trim()));
if (code != 0) {
throw new RuntimeException(String.format("设备编码[%S]填写重复,请重新输入!",sysCode));
}
}
String iot = equipmentDetailDownloadVOS.getIotCode();
if (StringUtils.isNotEmpty(iot) && StringUtils.isNotEmpty(iot.trim())) {
Integer iot_code = equipmentSpecificMapper.selectCount(new QueryWrapper<EquipmentSpecific>().eq("iot_code", iot.trim()));
if (iot_code != 0) {
throw new RuntimeException(String.format("物联编码[%S]填写重复,请重新输入!",iot));
}
}
AtomicReference<String> fightSysIds = new AtomicReference<>("");
String fightingSysCodes = equipmentDetailDownloadVOS.getFightingSysCodes();
if (StringUtils.isNotBlank(fightingSysCodes)) {
String[] idsArr = fightingSysCodes.split("-");
List<FireFightingSystemEntity> fightingSystemList = fireFightingSystemService.getFightingSysByCodes(idsArr);
if (!fightingSystemList.isEmpty()) {
fightingSystemList.stream().forEach(x -> {
String sysCodes = fightSysIds.get();
if (StringUtils.isNotBlank(sysCodes)) {
fightSysIds.set(String.join(",", sysCodes, String.valueOf(x.getId())));
} else {
fightSysIds.set(String.join(",", String.valueOf(x.getId())));
}
});
}
}
//插入模板信息
EquipmentDetail equipmentDetail = new EquipmentDetail();
equipmentDetail.setCode(equipmentDetailDownloadVOS.getCode());
equipmentDetail.setBrand(equipmentDetailDownloadVOS.getBrand());
equipmentDetail.setStandard(equipmentDetailDownloadVOS.getStandard());
LambdaQueryWrapper<ManufacturerInfo> queryWrapper = new LambdaQueryWrapper<>();
ManufacturerInfo info = manufacturerInfoService.getOne(queryWrapper.eq(ManufacturerInfo::getName, equipmentDetailDownloadVOS.getManufacturerName()));
if (StringUtil.isNotEmpty(info)) {
// throw new BadRequest("名称为" + equipmentDetailDownloadVOS.get(i).getManufacturerName() + "的生产厂商不存在!");
equipmentDetail.setManufacturerId(info.getId());
equipmentDetail.setManufacturerName(equipmentDetailDownloadVOS.getManufacturerName());
}
equipmentDetail.setEquipmentId(equipment.getId());
equipmentDetail.setEquipmentName(equipment.getName());
equipmentDetail.setName(equipmentDetailDownloadVOS.getName());
equipmentDetail.setArea(equipmentDetailDownloadVOS.getDescription());
// 导入新增所属单位
if (StringUtils.isNotBlank(equipmentDetailDownloadVOS.getCompanyName())) {
String[] company = equipmentDetailDownloadVOS.getCompanyName().split("@");
equipmentDetail.setCompanyName(company[0]);
}
equipmentDetailMapper.insert(equipmentDetail);
//生成单件设备信息
String qrCode = QRCodeUtil.generateQRCode();
EquipmentSpecific equipmentSpecific = new EquipmentSpecific();
equipmentSpecific.setQrCode(qrCode);
equipmentSpecific.setEquipmentDetailId(equipmentDetail.getId());
equipmentSpecific.setOrgCode(reginParams.getCompany().getOrgCode());
equipmentSpecific.setEquipmentCode(equipmentDetail.getCode());
equipmentSpecific.setName(equipmentDetail.getName());
String iotCode = equipmentDetailDownloadVOS.getIotCode();
iotCode = ExcelUtils.replaceAllBlank(iotCode);
equipmentSpecific.setIotCode(iotCode);
equipmentSpecific.setCode(equipmentDetailDownloadVOS.getSystemCode());
equipmentSpecific.setSystemId(fightSysIds.get());
equipmentSpecific.setNum(1);
equipmentSpecific.setSingle(true);
fireFightSysIdsBuffer.append(fightSysIds.get() + ",");
// 导入新增所属队伍
if (StringUtils.isNotBlank(equipmentDetailDownloadVOS.getFireTeam())) {
String[] fireTeam = equipmentDetailDownloadVOS.getFireTeam().split("@");
equipmentSpecific.setTeamName(fireTeam[0]);
equipmentSpecific.setTeamId(fireTeam[1]);
}
// 导入新增所属单位
if (StringUtils.isNotBlank(equipmentDetailDownloadVOS.getCompanyName())) {
String[] company = equipmentDetailDownloadVOS.getCompanyName().split("@");
equipmentSpecific.setAgencyId(company[1]);
equipmentSpecific.setAgencyName(company[0]);
equipmentSpecific.setBizOrgCode(company[2]);
equipmentSpecific.setBizOrgName(company[0]);
}
equipmentSpecificMapper.insert(equipmentSpecific);
StockServiceImpl controllerProxy = SpringUtils.getBean(StockServiceImpl.class);
//添加对于装备类型统计数据的刷新
controllerProxy.refreshCount(equipmentSpecific.getBizOrgCode());
//位置编码不为空入库
if (equipmentDetailDownloadVOS != null && equipmentDetailDownloadVOS.getWarehouseStructCode() != null) {
QueryWrapper<WarehouseStructure> warehouseStructureQueryWrapper = new QueryWrapper<>();
warehouseStructureQueryWrapper.lambda().eq(WarehouseStructure::getCode, equipmentDetailDownloadVOS.getWarehouseStructCode());
WarehouseStructure warehouseStructure = warehouseStructureService.getOne(warehouseStructureQueryWrapper);
if (warehouseStructure == null) {
throw new RuntimeException(String.format("货位编码[%S]填写错误,请输入正确的货位编码!",equipmentDetailDownloadVOS.getWarehouseStructCode()));
} else {
equipmentSpecific.setPosition(warehouseStructure.getFullName());
equipmentSpecificMapper.updateById(equipmentSpecific);
}
// 插入库存
Stock stock = new Stock();
stock.setAmount(Double.valueOf(equipmentSpecific.getNum()));
stock.setCompanyName(reginParams.getCompany().getCompanyName());
stock.setCompanyName(reginParams.getCompany().getOrgCode());
stock.setDepartmentOrgcode(reginParams.getDepartment().getOrgCode());
stock.setCompanyName(reginParams.getDepartment().getDepartmentName());
stock.setEquipmentDetailId(equipmentSpecific.getEquipmentDetailId());
stock.setWarehouseId(warehouseStructure.getWarehouseId());
equipmentSpecific.setStock(stock);
this.save(stock);
//库存详情
StockDetail stockDetail = new StockDetail();
stockDetail.setCompanyName(reginParams.getCompany().getCompanyName());
stockDetail.setOrgCode(reginParams.getCompany().getOrgCode());
stockDetail.setDepartmentName(reginParams.getDepartment().getDepartmentName());
stockDetail.setDepartmentOrgcode(reginParams.getDepartment().getOrgCode());
stockDetail.setEquipmentDetailId(equipmentSpecific.getEquipmentDetailId());
stockDetail.setEquipmentSpecificId(equipmentSpecific.getId());
stockDetail.setStockId(stock.getId());
stockDetail.setStatus(StockBillTypeEnum.DBRK.getValue());
stockDetail.setUpdateDate(new Date());
stockDetail.setQrCode(qrCode);
stockDetail.setWarehouseStructureId(warehouseStructure.getId());
stockDetail.setDescription(equipmentDetailDownloadVOS.getDescription());
stockDetail.setWarehouseId(warehouseStructure.getWarehouseId());
stockDetail.setAmount(1.00);
equipmentSpecific.setStockDetail(stockDetail);
stockDetailService.save(stockDetail);
//生成入库单
StockBill stockBill = new StockBill();
stockBill.setCreatorId(Long.valueOf(agencyUserModel.getUserId()));
stockBill.setCreatorName(agencyUserModel.getRealName());
stockBill.setCompanyName(reginParams.getCompany().getCompanyName());
stockBill.setDepartmentName(reginParams.getDepartment().getDepartmentName());
stockBill.setDepartmentOrgcode(String.valueOf(reginParams.getDepartment().getDeptOrgCode()));
stockBill.setOrgCode(reginParams.getCompany().getOrgCode());
stockBill.setWarehouseId(warehouseStructure.getWarehouseId());
stockBill.setBillCode(stockBillService.generateQrCode("RK"));
stockBill.setBillType(StockBillTypeEnum.DBRK.getValue());
stockBillService.save(stockBill);
//生成入库单详情
StockBillDetail stockBillDetail = new StockBillDetail();
stockBillDetail.setAmount(stockDetail.getAmount());
stockBillDetail.setEquipmentDetailId(equipmentDetail.getId());
stockBillDetail.setStockDetailId(stockDetail.getId());
stockBillDetail.setBatchNum(stf.format(new Date()));
stockBillDetail.setCreatorId(Long.valueOf(agencyUserModel.getUserId()));
stockBillDetail.setSingleEquipCode(stockDetail.getQrCode());
stockBillDetail.setStockBillId(stockBill.getId());
stockBillDetail.setWarehouseStructureId(warehouseStructure.getId());
stockBillDetailService.save(stockBillDetail);
}
list.add(equipmentSpecific);
this.equipmentSpecificIndexSave(equipmentDetail, equipmentSpecific);
platformTransactionManager.commit(transactionStatus);
okNum=okNum+1;
} catch (Exception e) {
platformTransactionManager.rollback(transactionStatus);
errNum=errNum+1;
errBufferName.append(equipmentDetailDownloadVOS.getCode() + ",");
e.printStackTrace();
throw new RuntimeException();
}
}
// @Async
public void refreshCount(String bizOrgCode) {
equipmentSpecificSerivce.refreshStaData();
try {
......@@ -508,7 +744,7 @@ public class StockServiceImpl extends ServiceImpl<StockMapper, Stock> implements
}).collect(Collectors.toList());
if (!equipmentSpecificIndices.isEmpty()) {
iEquipmentSpecificIndexSerivce.saveBatch(equipmentSpecificIndices);
}
}
if (equipmentSpecific.getSingle() && StringUtil.isNotEmpty(equipmentSpecific.getIotCode())) {
EquipmentSpecificSerivceImpl.registerMqttTopic(equipmentSpecific.getIotCode(), equipmentIotMqttReceiveConfig);
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment