Commit 76ac6478 by 李小惠

Merge branch 'develop' of http://gitlab.sothing.top/843502640/jyzb_platformV2 into develop-lxh

parents 123d14e2 d8edd4b1
package com.junmp.jyzb.api.bean.req;
import lombok.Data;
import java.math.BigDecimal;
import java.util.List;
@Data
public class EquipmentsReq {
private String typeId;
private String typeName;
private String sizeId;
private String sizeName;
private Integer num;
private Integer outNum;
private Integer inNum;
private BigDecimal price;
private BigDecimal outPrice;
private BigDecimal inPrice;
}
\ No newline at end of file
...@@ -23,4 +23,6 @@ public class PoliceListReq { ...@@ -23,4 +23,6 @@ public class PoliceListReq {
// * 角色id列表 // * 角色id列表
// */ // */
private List<Long> rolesList; private List<Long> rolesList;
private List<EquipmentsReq> equipments;
} }
...@@ -649,18 +649,24 @@ public class PolicemanServiceImpl extends ServiceImpl<PolicemanMapper, Policeman ...@@ -649,18 +649,24 @@ public class PolicemanServiceImpl extends ServiceImpl<PolicemanMapper, Policeman
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = Exception.class)
public boolean UploadPolicemanList(CabinetUploadReq req) { public boolean UploadPolicemanList(CabinetUploadReq req) {
List<CabinetDataList> dataList = req.getDataList(); List<CabinetDataList> dataList = req.getDataList();
Cabinet cabinetOrg = cabinetService.getOne(new LambdaQueryWrapper<Cabinet>().eq(Cabinet::getCabinetNum, req.getSerialNum()));
for (CabinetDataList orgList : dataList) { for (CabinetDataList orgList : dataList) {
// 获取上报的警员列表
List<PoliceListReq> policeReqList = orgList.getPoliceList();
Set<String> reqPoliceIds = policeReqList.stream().map(PoliceListReq::getPoliceID).collect(Collectors.toSet());
// 查询数据库中的警员列表 // 查询数据库中的警员列表
List<Policeman> policeList = this.list(new LambdaQueryWrapper<Policeman>() List<Policeman> policeListCurrent = this.list(new LambdaQueryWrapper<Policeman>()
.eq(Policeman::getOrgId, orgList.getOrgId())); .eq(Policeman::getOrgId, orgList.getOrgId()));
// 从数据库中查询指定警员ID的数据
List<Policeman> policeList = this.list(new LambdaQueryWrapper<Policeman>().in(Policeman::getId, reqPoliceIds));
// 获取上报的警员列表 PubOrg orgInfo = pubOrgService.getOne(new LambdaQueryWrapper<PubOrg>().eq(PubOrg::getOrgId, orgList.getOrgId()));
List<PoliceListReq> policeReqList = orgList.getPoliceList();
// 比较并处理新增、删除和修改的数据 // 比较并处理新增、删除和修改的数据
List<Policeman> toAdd = new ArrayList<>(); List<Policeman> toAdd = new ArrayList<>();
List<Policeman> toDelete = new ArrayList<>(); List<Policeman> toDelete = new ArrayList<>();
List<CabinetBoxPolice> toDeleteCabAndPo = new ArrayList<>();
List<Policeman> toUpdate = new ArrayList<>(); List<Policeman> toUpdate = new ArrayList<>();
// 处理新增和修改 // 处理新增和修改
...@@ -669,20 +675,23 @@ public class PolicemanServiceImpl extends ServiceImpl<PolicemanMapper, Policeman ...@@ -669,20 +675,23 @@ public class PolicemanServiceImpl extends ServiceImpl<PolicemanMapper, Policeman
if (dbPolice == null) { if (dbPolice == null) {
// 新增数据 // 新增数据
Policeman newPolice = convertToPoliceman(reqPolice,orgList.getOrgId()); Policeman newPolice = convertToPoliceman(reqPolice, orgList.getOrgId());
toAdd.add(newPolice); toAdd.add(newPolice);
} else { } else {
// 修改数据 // 修改数据
Policeman updatedPolice = updatePoliceman(dbPolice, reqPolice); Policeman updatedPolice = updatePoliceman(dbPolice, reqPolice, orgInfo, cabinetOrg);
toUpdate.add(updatedPolice); toUpdate.add(updatedPolice);
} }
} }
// 处理删除 // 处理删除
for (Policeman dbPolice : policeList) { for (Policeman dbPolice : policeListCurrent) {
PoliceListReq matchingReqPolice = findPoliceReqById(policeReqList, dbPolice.getId()); PoliceListReq matchingReqPolice = findPoliceReqById(policeReqList, dbPolice.getId());
if (matchingReqPolice == null) { if (matchingReqPolice == null) {
dbPolice.setState(0); dbPolice.setState(0);
// 将箱门全部清除
List<CabinetBoxPolice> cbplist = cabinetBoxPoliceService.list(new LambdaQueryWrapper<CabinetBoxPolice>().eq(CabinetBoxPolice::getPoliceId, dbPolice.getId()));
toDeleteCabAndPo.addAll(cbplist);
// 数据库中存在但上报数据中不存在,需要删除 // 数据库中存在但上报数据中不存在,需要删除
toDelete.add(dbPolice); toDelete.add(dbPolice);
} }
...@@ -696,20 +705,21 @@ public class PolicemanServiceImpl extends ServiceImpl<PolicemanMapper, Policeman ...@@ -696,20 +705,21 @@ public class PolicemanServiceImpl extends ServiceImpl<PolicemanMapper, Policeman
this.updateBatchById(toUpdate); this.updateBatchById(toUpdate);
} }
if (!toDelete.isEmpty()) { if (!toDelete.isEmpty()) {
this.updateBatchById(toUpdate); this.updateBatchById(toDelete);
cabinetBoxPoliceService.removeBatchByIds(toDeleteCabAndPo);
} }
} }
//人员信息修改之后推送至本地主机和单警柜
List<Cabinet> cabinets= cabinetService.list(new LambdaQueryWrapper<Cabinet>().eq(Cabinet::getOrgIdInt, req.getCabinetOrgId()));//拿到组织机构下所有的警柜用于消息推送 // 人员信息修改之后推送至本地主机和单警柜
if (cabinets.size()>0) List<Cabinet> cabinets = cabinetService.list(new LambdaQueryWrapper<Cabinet>().eq(Cabinet::getOrgIdInt, req.getCabinetOrgId()));
{ if (!cabinets.isEmpty()) {
cabinets.forEach(t-> MQ.SendMsg("cabinetMsg",t.getCabinetNum(),"policeChange")); cabinets.forEach(t -> MQ.SendMsg("cabinetMsg", t.getCabinetNum(), "policeChange"));
} }
req.getDataList().forEach(t-> MQ.SendMsg("warehouseMsg",t.getOrgId(),"policeChange"));//推送至仓库主机 req.getDataList().forEach(t -> MQ.SendMsg("warehouseMsg", t.getOrgId(), "policeChange"));// 推送至仓库主机
return true; return true;
} }
// 辅助方法:根据警员ID在列表中查找警员 // 辅助方法:根据警员ID在列表中查找警员
private Policeman findPoliceById(List<Policeman> policeList, String policeId) { private Policeman findPoliceById(List<Policeman> policeList, String policeId) {
return policeList.stream().filter(p -> Objects.equals(p.getId(), policeId)).findFirst().orElse(null); return policeList.stream().filter(p -> Objects.equals(p.getId(), policeId)).findFirst().orElse(null);
...@@ -754,14 +764,167 @@ public class PolicemanServiceImpl extends ServiceImpl<PolicemanMapper, Policeman ...@@ -754,14 +764,167 @@ public class PolicemanServiceImpl extends ServiceImpl<PolicemanMapper, Policeman
} }
// 辅助方法:更新 Policeman 对象的属性 // 辅助方法:更新 Policeman 对象的属性
private Policeman updatePoliceman(Policeman dbPolice, PoliceListReq reqPolice) { private Policeman updatePoliceman(Policeman dbPolice, PoliceListReq reqPolice, PubOrg org, Cabinet cabinet) {
//判断警员是否存在 CabinetBox cb = cabinetBoxService.getById(reqPolice.getCabinetBoxId());
//判断传入的修改的警员编号与本身编号一致,如果一致则无所谓,如果不一致则需要判断修改的警员编号是否已经存在 if (cb.getBoxName() == null) {
BeanPlusUtil.copyProperties(reqPolice, dbPolice); cb.setBoxName("");
}
// 判断警员是否存在
// 判断传入的修改的警员编号与本身编号一致,如果一致则无所谓,如果不一致则需要判断修改的警员编号是否已经存在
dbPolice.setUpdateTime(DateTimeUtil.getCurrentDateTime()); dbPolice.setUpdateTime(DateTimeUtil.getCurrentDateTime());
List<PoliceEquipment> policeEqsList = policeEquipmentService.list(new LambdaQueryWrapper<PoliceEquipment>()
.eq(PoliceEquipment::getPoliceId, dbPolice.getId()));
if (!dbPolice.getOrgId().equals(org.getOrgId())) {//现有警员组织机构和原有的不一样,说明是调岗的
policeEquipmentService.removeBatchByIds(policeEqsList);
List<PoliceEquipment> addEqsList = new ArrayList<>();
List<EquipmentsReq> reqEquipment = reqPolice.getEquipments();
List<InventorySummary> toUpdateInventoryList = new ArrayList<>();
List<InventorySummary> toAddInventoryList = new ArrayList<>();
List<InventorySummary> toDeleteInventoryList = new ArrayList<>();
for (EquipmentsReq reqEq : reqEquipment) {
PoliceEquipment pe = new PoliceEquipment();
pe.setId(UUID.randomUUID().toString());
pe.setPoliceId(dbPolice.getId());
pe.setPoliceName(dbPolice.getName());
pe.setNum(Integer.valueOf(reqEq.getNum()));
pe.setPrice(reqEq.getPrice());
pe.setCreateTime(DateTimeUtil.getCurrentDateTime());
pe.setUpdateTime(DateTimeUtil.getCurrentDateTime());
pe.setOrgId(org.getOrgId());
pe.setOutNum(Integer.valueOf(reqEq.getOutNum()));
pe.setInNum(Integer.valueOf(reqEq.getInNum()));
pe.setLocationId(cb.getId());
pe.setLocationName(cabinet.getName() + "-" + cb.getBoxName());
BeanPlusUtil.copyProperties(reqEq, pe);
addEqsList.add(pe);
List<InventorySummary> inventoryList = inventorySummaryService.list(
new LambdaQueryWrapper<InventorySummary>().eq(InventorySummary::getOrgId, dbPolice.getOrgId())
);
// 判断是否存在相同编号的设备
Optional<InventorySummary> existingInventory = inventoryList.stream()
.filter(inventory -> inventory.getSizeId().equals(reqEq.getSizeId()) &&
inventory.getTypeId().equals(reqEq.getTypeId())&&inventory.getPrice().equals(
reqEq.getPrice()
))
.findFirst();//原有组织机构数据
List<InventorySummary> NowInventoryList = inventorySummaryService.list(
new LambdaQueryWrapper<InventorySummary>().eq(InventorySummary::getOrgId, org.getOrgId())
);
// 判断是否存在相同编号的设备
Optional<InventorySummary> NowExistingInventory = NowInventoryList.stream()
.filter(inventory -> inventory.getSizeId().equals(reqEq.getSizeId()) &&
inventory.getTypeId().equals(reqEq.getTypeId())&&inventory.getPrice().equals(
reqEq.getPrice()))
.findFirst();//现在组织机构数据
if (dbPolice.getOrgId() == null) {//如果为空则说明调岗中,则只需要为当前组织机构增加相应数据即可
if (existingInventory.isPresent()) {
// 如果存在,更新数据库中的数据
InventorySummary existingInventorySummary = existingInventory.get();
existingInventorySummary.setNumber(Integer.valueOf(reqEq.getNum() + existingInventorySummary.getNumber()));
existingInventorySummary.setPrice(existingInventorySummary.getPrice().add(reqEq.getPrice()));
existingInventorySummary.setOutboundNumber(existingInventorySummary.getOutboundNumber() - Integer.valueOf(reqEq.getOutNum()));
existingInventorySummary.setStockNumber(existingInventorySummary.getStockNumber() + Integer.valueOf(reqEq.getInNum()));
toUpdateInventoryList.add(existingInventorySummary);
} else {
// 如果不存在,新增数据到数据库
InventorySummary newInventory = new InventorySummary();
BeanPlusUtil.copyProperties(reqEq, newInventory);
newInventory.setPrice(reqEq.getPrice());
newInventory.setNumber(Integer.valueOf(reqEq.getNum()));
newInventory.setOutboundNumber(Integer.valueOf(reqEq.getOutNum()));
newInventory.setLocationType("1");
newInventory.setStockNumber(Integer.valueOf(reqEq.getInNum()));
newInventory.setLocationId(cabinet.getCabinetNum());
newInventory.setOrgId(org.getOrgId());
newInventory.setOrgCode(org.getOrgCode());
newInventory.setOrgName(org.getOrgName());
newInventory.setCreateTime(DateTimeUtil.getCurrentDateTime());
newInventory.setUpdateTime(DateTimeUtil.getCurrentDateTime());
toAddInventoryList.add(newInventory);
}
} else {
if (existingInventory.isPresent()) {
// 如果存在,减去对应数量
InventorySummary existingInventorySummary = existingInventory.get();
existingInventorySummary.setNumber(Math.max(0, existingInventorySummary.getNumber() - Integer.parseInt(String.valueOf(reqEq.getNum()))));
existingInventorySummary.setPrice(
existingInventorySummary.getPrice().subtract(reqEq.getPrice()).max(BigDecimal.ZERO)
);
existingInventorySummary.setOutboundNumber(Math.max(0, existingInventorySummary.getOutboundNumber() - Integer.parseInt(String.valueOf(reqEq.getOutNum()))));
existingInventorySummary.setStockNumber(Math.max(0, existingInventorySummary.getStockNumber() - Integer.parseInt(String.valueOf(reqEq.getInNum()))));
// existingInventorySummary.setOutboundNumberPrice(
// existingInventorySummary.getOutboundNumberPrice().subtract(reqEq.getOutPrice()).max(BigDecimal.ZERO)
// );
// existingInventorySummary.setStockNumberPrice(
// existingInventorySummary.getStockNumberPrice().subtract(reqEq.getInPrice()).max(BigDecimal.ZERO)
// );
// 判断 Number 是否为 0 或者小于 0
if (existingInventorySummary.getNumber() <= 0) {
toDeleteInventoryList.add(existingInventorySummary);
} else {
toUpdateInventoryList.add(existingInventorySummary);
}
}
if (NowExistingInventory.isPresent()) {
// 如果存在,更新数据库中的数据
InventorySummary existingInventorySummary = existingInventory.get();
existingInventorySummary.setNumber(Integer.valueOf(reqEq.getNum() + existingInventorySummary.getNumber()));
existingInventorySummary.setPrice(existingInventorySummary.getPrice().add(reqEq.getPrice()));
existingInventorySummary.setOutboundNumber(existingInventorySummary.getOutboundNumber() - Integer.valueOf(reqEq.getOutNum()));
existingInventorySummary.setStockNumber(existingInventorySummary.getStockNumber() + Integer.valueOf(reqEq.getInNum()));
toUpdateInventoryList.add(existingInventorySummary);
} else {
// 如果不存在,新增数据到数据库
InventorySummary newInventory = new InventorySummary();
BeanPlusUtil.copyProperties(reqEq, newInventory);
newInventory.setPrice(reqEq.getPrice());
newInventory.setNumber(Integer.valueOf(reqEq.getNum()));
newInventory.setOutboundNumber(Integer.valueOf(reqEq.getOutNum()));
newInventory.setLocationType("1");
newInventory.setStockNumber(Integer.valueOf(reqEq.getInNum()));
newInventory.setLocationId(cabinet.getCabinetNum());
newInventory.setOrgId(org.getOrgId());
newInventory.setOrgCode(org.getOrgCode());
newInventory.setOrgName(org.getOrgName());
newInventory.setCreateTime(DateTimeUtil.getCurrentDateTime());
newInventory.setUpdateTime(DateTimeUtil.getCurrentDateTime());
toAddInventoryList.add(newInventory);
}
}
}
// 批量更新
if (!toUpdateInventoryList.isEmpty()) {
inventorySummaryService.updateBatchById(toUpdateInventoryList);
}
// 批量插入
if (!toAddInventoryList.isEmpty()) {
inventorySummaryService.saveBatch(toAddInventoryList);
}
// 执行删除操作
if (!toDeleteInventoryList.isEmpty()) {
inventorySummaryService.removeByIds(
toDeleteInventoryList.stream().map(InventorySummary::getId).collect(Collectors.toList())
);
}
policeEquipmentService.saveBatch(addEqsList);
}
dbPolice.setOrgId(Long.valueOf(org.getOrgId()));
dbPolice.setState(1);
BeanPlusUtil.copyProperties(reqPolice, dbPolice);
return dbPolice; return dbPolice;
} }
/** /**
* 修改用户状态 * 修改用户状态
* *
......
...@@ -3,7 +3,7 @@ scanner: ...@@ -3,7 +3,7 @@ scanner:
easy-es: easy-es:
enable: true enable: true
address: 192.168.3.188:9200 address: 192.168.3.121:9200
username: username:
password: password:
......
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
easy-es: easy-es:
enable: true enable: true
address: 192.168.3.188:9200 address: 192.168.3.121:9200
username: username:
password: password:
server: server:
...@@ -14,7 +14,7 @@ server: ...@@ -14,7 +14,7 @@ server:
spring: spring:
elasticsearch: elasticsearch:
rest: rest:
uris: http://192.168.3.188:9200 uris: http://192.168.3.121:9200
main: main:
#bea同名类进行注册时,准许覆盖注册 #bea同名类进行注册时,准许覆盖注册
allow-bean-definition-overriding: true allow-bean-definition-overriding: true
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论