|
@@ -1,23 +1,33 @@
|
|
package com.fjhx.service.check.impl;
|
|
package com.fjhx.service.check.impl;
|
|
|
|
|
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
import com.fjhx.constants.HouseConstant;
|
|
import com.fjhx.constants.HouseConstant;
|
|
import com.fjhx.constants.StatusConstant;
|
|
import com.fjhx.constants.StatusConstant;
|
|
|
|
+import com.fjhx.constants.WebSocketConstant;
|
|
import com.fjhx.entity.check.Check;
|
|
import com.fjhx.entity.check.Check;
|
|
|
|
+import com.fjhx.entity.check.CheckDetail;
|
|
|
|
+import com.fjhx.entity.stock.Stock;
|
|
import com.fjhx.entity.water.WaterTag;
|
|
import com.fjhx.entity.water.WaterTag;
|
|
import com.fjhx.mapper.check.CheckMapper;
|
|
import com.fjhx.mapper.check.CheckMapper;
|
|
import com.fjhx.params.check.CheckVo;
|
|
import com.fjhx.params.check.CheckVo;
|
|
|
|
+import com.fjhx.service.WebSocketServer;
|
|
|
|
+import com.fjhx.service.check.CheckDetailService;
|
|
import com.fjhx.service.check.CheckService;
|
|
import com.fjhx.service.check.CheckService;
|
|
|
|
+import com.fjhx.service.stock.StockService;
|
|
import com.fjhx.service.water.WaterTagService;
|
|
import com.fjhx.service.water.WaterTagService;
|
|
import com.fjhx.utils.WrapperUtil;
|
|
import com.fjhx.utils.WrapperUtil;
|
|
|
|
+import org.springblade.core.tool.utils.ThreadUtil;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
|
|
+import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
-import java.util.List;
|
|
|
|
-import java.util.Map;
|
|
|
|
|
|
+import java.math.BigDecimal;
|
|
|
|
+import java.util.*;
|
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
|
|
/**
|
|
/**
|
|
* <p>
|
|
* <p>
|
|
@@ -30,9 +40,20 @@ import java.util.Map;
|
|
@Service
|
|
@Service
|
|
public class CheckServiceImpl extends ServiceImpl<CheckMapper, Check> implements CheckService {
|
|
public class CheckServiceImpl extends ServiceImpl<CheckMapper, Check> implements CheckService {
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
+ * 上位机读取的rfid
|
|
|
|
+ */
|
|
|
|
+ public static final List<String> RFID_LIST = Collections.synchronizedList(new ArrayList<>());
|
|
|
|
+
|
|
@Autowired
|
|
@Autowired
|
|
private WaterTagService waterTagService;
|
|
private WaterTagService waterTagService;
|
|
|
|
|
|
|
|
+ @Autowired
|
|
|
|
+ private StockService stockService;
|
|
|
|
+
|
|
|
|
+ @Autowired
|
|
|
|
+ private CheckDetailService checkDetailService;
|
|
|
|
+
|
|
@Override
|
|
@Override
|
|
public Page<Check> getPage(Map<String, String> condition) {
|
|
public Page<Check> getPage(Map<String, String> condition) {
|
|
|
|
|
|
@@ -60,19 +81,130 @@ public class CheckServiceImpl extends ServiceImpl<CheckMapper, Check> implements
|
|
removeById(checkVo.getId());
|
|
removeById(checkVo.getId());
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
@Override
|
|
@Override
|
|
- public void automaticCheck() {
|
|
|
|
|
|
+ public synchronized void automaticCheck() {
|
|
|
|
+
|
|
|
|
+ JSONObject data = new JSONObject();
|
|
|
|
+ data.put("instructions", "test");
|
|
|
|
+ data.put("type", 2);
|
|
|
|
+ data.put("flag", "automaticCheck");
|
|
|
|
+
|
|
|
|
+ WebSocketServer.sendInfo(WebSocketConstant.WEB_STOCK_PROGRAM, WebSocketConstant.OPERATING_UPPER_COMPUTER, data);
|
|
|
|
+
|
|
|
|
+ ThreadUtil.sleep(1000 * 60 * 10);
|
|
|
|
+
|
|
|
|
+ data.clear();
|
|
|
|
+ data.put("type", 9);
|
|
|
|
+ WebSocketServer.sendInfo(WebSocketConstant.WEB_STOCK_PROGRAM, WebSocketConstant.OPERATING_UPPER_COMPUTER, data);
|
|
|
|
+
|
|
|
|
+ // 获取在库标签
|
|
|
|
+ List<WaterTag> list = getInHouseWaterTag();
|
|
|
|
+
|
|
|
|
+ List<String> rfidList = RFID_LIST.stream().distinct().collect(Collectors.toList());
|
|
|
|
+ RFID_LIST.clear();
|
|
|
|
|
|
- List<WaterTag> list = waterTagService.list(Wrappers.<WaterTag>lambdaQuery()
|
|
|
|
- .eq(WaterTag::getStockHouseId, HouseConstant.FOURTH_FLOOR_ID)
|
|
|
|
|
|
+ // 异常物料id
|
|
|
|
+ List<Long> errorMaterialId = getErrorMaterialId(list, rfidList);
|
|
|
|
+
|
|
|
|
+ // 保存盘点结果
|
|
|
|
+ Long checkId = savaCheck(errorMaterialId);
|
|
|
|
+
|
|
|
|
+ // 保存盘点结果明细
|
|
|
|
+ savaCheckDetailList(errorMaterialId, checkId);
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 获取在库标签
|
|
|
|
+ */
|
|
|
|
+ private List<WaterTag> getInHouseWaterTag() {
|
|
|
|
+ return waterTagService.list(Wrappers.<WaterTag>lambdaQuery()
|
|
|
|
+ .eq(WaterTag::getStockHouseId, HouseConstant.GROUND_FLOOR_ID)
|
|
.eq(WaterTag::getInHouse, StatusConstant.YES)
|
|
.eq(WaterTag::getInHouse, StatusConstant.YES)
|
|
.eq(WaterTag::getUseStatus, StatusConstant.YES)
|
|
.eq(WaterTag::getUseStatus, StatusConstant.YES)
|
|
);
|
|
);
|
|
|
|
+ }
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
+ * 获取异常物料id
|
|
|
|
+ */
|
|
|
|
+ private List<Long> getErrorMaterialId(List<WaterTag> list, List<String> rfidList) {
|
|
|
|
+ // 异常物料id
|
|
|
|
+ HashSet<Long> errorMaterialIdList = new HashSet<>();
|
|
|
|
+
|
|
|
|
+ // 在库存,但没有扫描到rfid
|
|
|
|
+ for (WaterTag waterTag : list) {
|
|
|
|
+ String rfidCode = waterTag.getRfidCode();
|
|
|
|
+ if (rfidList.contains(rfidCode)) {
|
|
|
|
+ rfidList.remove(rfidCode);
|
|
|
|
+ } else {
|
|
|
|
+ errorMaterialIdList.add(waterTag.getMaterialId());
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ // 不在库存,但扫描到rfid
|
|
|
|
+ errorMaterialIdList.addAll(
|
|
|
|
+ waterTagService.list(Wrappers.<WaterTag>lambdaQuery()
|
|
|
|
+ .select(WaterTag::getMaterialId)
|
|
|
|
+ .in(WaterTag::getRfidCode, rfidList)
|
|
|
|
+ .eq(WaterTag::getUseStatus, StatusConstant.YES))
|
|
|
|
+ .stream().map(WaterTag::getMaterialId)
|
|
|
|
+ .collect(Collectors.toSet()));
|
|
|
|
+
|
|
|
|
+ return new ArrayList<>(errorMaterialIdList);
|
|
|
|
+ }
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
+ * 保存盘点结果
|
|
|
|
+ */
|
|
|
|
+ private Long savaCheck(List<Long> errorMaterialId) {
|
|
|
|
+ Check check = new Check();
|
|
|
|
+ check.setCheckResult(errorMaterialId.size() == 0 ? 1 : 0);
|
|
|
|
+ check.setType(1);
|
|
|
|
+ check.setStatus(0);
|
|
|
|
+ check.setStockHouseId(HouseConstant.GROUND_FLOOR_ID);
|
|
|
|
+ check.setBeginTime(new Date());
|
|
|
|
+ save(check);
|
|
|
|
+ return check.getId();
|
|
|
|
+ }
|
|
|
|
|
|
-
|
|
|
|
-
|
|
|
|
|
|
+ /**
|
|
|
|
+ * 保存盘点结果明细
|
|
|
|
+ */
|
|
|
|
+ private void savaCheckDetailList(List<Long> errorMaterialId, Long checkId) {
|
|
|
|
+
|
|
|
|
+ // 库存信息
|
|
|
|
+ List<Stock> stockList = stockService.list(q -> q.in(Stock::getMaterialId, errorMaterialId));
|
|
|
|
+ // 库存信息map
|
|
|
|
+ Map<Long, Stock> stockMap = stockList.stream().collect(Collectors.toMap(
|
|
|
|
+ Stock::getMaterialId,
|
|
|
|
+ item -> item,
|
|
|
|
+ (v1, v2) -> v1
|
|
|
|
+ ));
|
|
|
|
+
|
|
|
|
+ // 盘点结果明细列表
|
|
|
|
+ List<CheckDetail> checkDetailList = errorMaterialId.stream().map(materialId -> {
|
|
|
|
+ CheckDetail checkDetail = new CheckDetail();
|
|
|
|
+ checkDetail.setCheckId(checkId);
|
|
|
|
+ checkDetail.setMaterialId(materialId);
|
|
|
|
+
|
|
|
|
+ Stock stock = stockMap.get(materialId);
|
|
|
|
+ if (stock == null) {
|
|
|
|
+ checkDetail.setStockQuantity(BigDecimal.ZERO);
|
|
|
|
+ checkDetail.setStockCount(0);
|
|
|
|
+ } else {
|
|
|
|
+ checkDetail.setStockQuantity(stock.getQuantity());
|
|
|
|
+ checkDetail.setStockCount(stock.getNumber());
|
|
|
|
+ }
|
|
|
|
+ checkDetail.setCompleteCheck(StatusConstant.NO);
|
|
|
|
+ checkDetail.setStockHouseId(HouseConstant.GROUND_FLOOR_ID);
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ return checkDetail;
|
|
|
|
+ }).collect(Collectors.toList());
|
|
|
|
+
|
|
|
|
+ checkDetailService.saveBatch(checkDetailList);
|
|
}
|
|
}
|
|
|
|
|
|
}
|
|
}
|