Commit 9a100cd1 by 李小惠

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

parents 8fa04ff9 5344d7cf
......@@ -17,7 +17,7 @@ public class CabinetBoxDto implements Serializable {
* 箱号
*/
@ApiModelProperty(value = "箱门号")
private Integer BoxNum;
private Integer num;
/**
* 异常状态:1正常/0异常
......@@ -31,6 +31,7 @@ public class CabinetBoxDto implements Serializable {
@ApiModelProperty(value = "异常原因")
private String errorMsg;
/**
* 箱门绑定警员id
*/
......@@ -41,4 +42,10 @@ public class CabinetBoxDto implements Serializable {
*/
private String policeName;
/**
* 箱门类型:1单警柜,2公共柜
*/
@ApiModelProperty(value = "箱门类型:1单警柜,2公共柜")
private Integer boxType;
}
......@@ -47,9 +47,18 @@ public class CabinetDto implements Serializable{
*/
@ApiModelProperty(value = "位置信息")
private String location;
/**
* 单警柜号
*/
@ApiModelProperty(value = "单警柜号")
private String serverNum;
private Integer state;
/**
* 在线状态
*/
@ApiModelProperty(value = "在线状态")
private Integer onlineState;
private List<CabinetBoxDto> cabinetBoxList;
......
......@@ -15,15 +15,16 @@ public class CabinetReq extends BaseRequest {
/**
* 单警柜ID
*/
@NotNull(message = "单警柜ID主键不能为空", groups = {edit.class, delete.class, detail.class})
@ApiModelProperty(value = "单警柜ID")
private String id;
/**
* 单警柜编号
*/
@NotNull(message = "单警柜ID主键不能为空", groups = {edit.class, delete.class, detail.class})
@ApiModelProperty(value = "单警柜编号")
private String cabinetNum;
private String serialNum;
/**
* 箱数
......@@ -32,6 +33,11 @@ public class CabinetReq extends BaseRequest {
private Integer num;
/**
* 类型
*/
@ApiModelProperty(value = "类型")
private String containType;
/**
* 单警柜名称
*/
@ApiModelProperty(value = "单警柜名称")
......
......@@ -7,20 +7,22 @@ import lombok.EqualsAndHashCode;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import java.util.List;
@Data
@EqualsAndHashCode(callSuper = true)
public class UpdateCabinetBoxReq extends BaseRequest {
@NotBlank(message = "箱门id不能为空",groups = {add.class,edit.class})
// @NotBlank(message = "箱门id不能为空",groups = {add.class,edit.class})
private String id;
@NotNull(message = "箱门状态不能为空",groups = {edit.class})
private Integer state;
private String errorMsg;
private String boxName;
//单警柜编号
@NotBlank(message = "单警柜编号不能为空",groups = {add.class})
private String cabinetNum;
private String equipmentConfig;
private String boxType;
private String power;
private List<String> boxNum;
private Integer num;
}
......@@ -25,13 +25,7 @@ public class UpdateCabinetReq extends BaseRequest {
*/
@NotBlank(message = "单警柜编号不能为空", groups = {add.class,edit.class, detail.class})
@ApiModelProperty(value = "单警柜编号")
private String cabinetNum;
/**
* 箱数
*/
@ApiModelProperty(value = "箱数")
private Integer num;
private String serialNum;
/**
* 单警柜名称
......@@ -39,6 +33,11 @@ public class UpdateCabinetReq extends BaseRequest {
@NotBlank(message = "单警柜名称不能为空", groups = {add.class,edit.class, detail.class})
@ApiModelProperty(value = "单警柜名称")
private String name;
/**
* 单警柜名称
*/
@ApiModelProperty(value = "动作来源")
private String actionFrom;
/**
* 组织机构号
......@@ -50,7 +49,7 @@ public class UpdateCabinetReq extends BaseRequest {
/**
* 位置信息
*/
@NotBlank(message = "位置信息不能为空", groups = {add.class, edit.class})
@ApiModelProperty(value = "位置信息")
private String location;
......@@ -88,6 +87,8 @@ public class UpdateCabinetReq extends BaseRequest {
//箱门信息列表
private List<UpdateCabinetBoxReq> cabinetBoxList;
//箱门信息列表
private List<String> numList;
//单警柜id列表
private List<String> cabinetList;
......
package com.junmp.jyzb.controller;
import com.junmp.jyzb.api.bean.req.UpdateCabinetBoxReq;
import com.junmp.jyzb.api.bean.req.UpdateCabinetReq;
import com.junmp.jyzb.service.CabinetBoxService;
import com.junmp.v2.common.bean.request.ValidationApi;
import com.junmp.v2.common.bean.response.ApiRes;
......@@ -25,7 +26,14 @@ public class CabinetBoxController {
//添加箱门信息
@PostMapping("/AddBoxInfo")
@ApiOperation("添加箱门信息")
public ApiRes<String> AddBoxInfo(@RequestBody @Validated(ValidationApi.add.class) UpdateCabinetBoxReq req){
return ApiRes.success(cabinetBoxService.AddBoxInfo(req));
public ApiRes<String> AddOrUpdateBoxInfo(@RequestBody UpdateCabinetReq req){
return ApiRes.success(cabinetBoxService.AddOrUpdateBoxInfo(req));
}
//添加箱门信息
@PostMapping("/DeleteBox")
@ApiOperation("删除箱门")
public ApiRes<String> DeleteBox(@RequestBody @Validated(ValidationApi.delete.class) UpdateCabinetReq req){
return ApiRes.success(cabinetBoxService.DeleteBox(req));
}
}
......@@ -59,9 +59,9 @@ public class CabinetController {
return ApiRes.success(cabinetService.deleteCabinetInfo(req));
}
@PostMapping("/UpdateCabinetInfo")
@ApiOperation("修改单警柜信息")
public ApiRes<Boolean> updateCabinetInfo(@RequestBody UpdateCabinetReq req) {
@PostMapping("/UpdateCabinetServer")
@ApiOperation("修改单警柜信息,平台使用")
public ApiRes<Boolean> UpdateCabinetServer(@RequestBody UpdateCabinetReq req) {
boolean result = cabinetService.updateCabinetInfo(req);
if (!result){
return ApiRes.failure("操作失败");
......@@ -69,7 +69,15 @@ public class CabinetController {
return ApiRes.success(result);
}
@PostMapping("/UpdateCabinetClient")
@ApiOperation("修改单警柜信息,警柜使用")
public ApiRes<Boolean> UpdateCabinetClient(@RequestBody UpdateCabinetReq req) {
boolean result = cabinetService.updateCabinetInfo(req);
if (!result){
return ApiRes.failure("操作失败");
}
return ApiRes.success(result);
}
//通过单警柜id查询单个箱门及其箱门信息
@PostMapping("/ShowOneCabinet")
......
......@@ -42,7 +42,7 @@ public class Cabinet implements Serializable {
*/
@ApiModelProperty(value = "新版本组织机构号")
@TableField("org_id_int")
private Long orgId;
private Long orgIdInt;
/**
......@@ -62,7 +62,12 @@ public class Cabinet implements Serializable {
*/
@ApiModelProperty(value = "单警柜当前状态,0正常,1异常")
private Integer state;
/**
* 单警柜在线状态,0正常,1异常
*/
@ApiModelProperty(value = "单警柜在线状态,0离线,1在线")
@TableField("online_state")
private Integer onlineState;
/**
* 装备总数
*/
......@@ -90,20 +95,13 @@ public class Cabinet implements Serializable {
@TableField("price_total")
private BigDecimal priceTotal;
/**
* 创建时间
*/
@ApiModelProperty(value = "创建时间")
@TableField(value="create_time")
@TableField(fill = FieldFill.INSERT_UPDATE, value = "create_time")
private Date createTime;
/**
* 更新时间
*/
@ApiModelProperty(value = "更新时间")
@TableField(value = "update_time")
@TableField(fill = FieldFill.INSERT_UPDATE, value = "update_time")
private Date updateTime;
/**
* 新增人员
*/
......
package com.junmp.jyzb.entity;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.baomidou.mybatisplus.annotation.*;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import java.io.Serializable;
import java.util.Date;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
......@@ -38,6 +37,19 @@ public class CabinetBox implements Serializable {
private Integer num;
/**
* 装备配置信息
*/
@ApiModelProperty(value = "装备配置信息")
@TableField("equipment_config")
private String equipmentConfig;
/**
* 功率
*/
@ApiModelProperty(value = "power")
@TableField("power")
private String power;
/**
* 异常状态:1正常/0异常
*/
@ApiModelProperty(value = "异常状态:1正常/0异常")
......@@ -49,7 +61,18 @@ public class CabinetBox implements Serializable {
@ApiModelProperty(value = "异常原因")
@TableField("error_msg")
private String errorMsg;
/**
* 别名
*/
@ApiModelProperty(value = "别名")
@TableField("box_name")
private String boxName;
/**
* 箱门类型:1单警柜,2公共柜
*/
@ApiModelProperty(value = "箱门类型:1单警柜,2公共柜")
@TableField("box_type")
private String boxType;
/**
* 使用日志存储位置信息
*/
......@@ -66,4 +89,10 @@ public class CabinetBox implements Serializable {
private static final long serialVersionUID = 1L;
@TableField(fill = FieldFill.INSERT_UPDATE, value = "create_time")
private Date createTime;
@TableField(fill = FieldFill.INSERT_UPDATE, value = "update_time")
private Date updateTime;
}
\ No newline at end of file
......@@ -13,7 +13,7 @@ import java.util.Map;
public interface CabinetMapper extends BaseMapper<Cabinet> {
List<Cabinet> getAllCabinetByOrgList(@Param("list") List<Long> allOrgId);
List<Cabinet> getAllCabinetsWithSingleCabinet(@Param("orgId")String id, @Param("boxType") String boxType);
boolean SetInventoryInfo(String id);
}
\ No newline at end of file
......@@ -3,6 +3,7 @@ package com.junmp.jyzb.service;
import com.baomidou.mybatisplus.extension.service.IService;
import com.junmp.jyzb.api.bean.query.CabinetReq;
import com.junmp.jyzb.api.bean.req.UpdateCabinetBoxReq;
import com.junmp.jyzb.api.bean.req.UpdateCabinetReq;
import com.junmp.jyzb.entity.CabinetBox;
import com.junmp.jyzb.entity.Policeman;
......@@ -13,8 +14,9 @@ public interface CabinetBoxService extends IService<CabinetBox> {
//添加箱门信息
String AddBoxInfo(UpdateCabinetBoxReq req);
String AddOrUpdateBoxInfo(UpdateCabinetReq req);
//添加箱门信息
String DeleteBox(UpdateCabinetReq req);
//判断箱门信息是否存在
CabinetBox CabinetBoxExist(String id);
}
......@@ -46,13 +46,19 @@ public interface CabinetService extends IService<Cabinet> {
CabinetDto showOneCabinet(CabinetReq req);
/**
* 修改单警柜信息
* 修改单警柜信息,平台使用
* @param req
* @return
*/
boolean updateCabinetInfo(UpdateCabinetReq req);
/**
* 修改单警柜信息,警柜使用
* @param req
* @return
*/
boolean updateCabinetClient(UpdateCabinetReq req);
/**
* 箱门绑定人员
* @param req
* @return
......
......@@ -5,23 +5,32 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.junmp.jyzb.api.bean.query.CabinetReq;
import com.junmp.jyzb.api.bean.req.UpdateCabinetBoxReq;
import com.junmp.jyzb.api.bean.req.UpdateCabinetReq;
import com.junmp.jyzb.entity.Cabinet;
import com.junmp.jyzb.entity.CabinetBox;
import com.junmp.jyzb.api.exception.enums.CabinetBoxExceptionEnum;
import com.junmp.jyzb.api.exception.enums.CabinetExceptionEnum;
import com.junmp.jyzb.entity.ES.Blog;
import com.junmp.jyzb.mapper.CabinetBoxMapper;
import com.junmp.jyzb.mapper.PoliceFingerMapper;
import com.junmp.jyzb.mapper.PolicemanMapper;
import com.junmp.jyzb.service.CabinetBoxService;
import com.junmp.jyzb.service.CabinetService;
import com.junmp.jyzb.utils.RabbitMQSendMsg;
import com.junmp.v2.common.exception.base.ServiceException;
import com.junmp.v2.common.util.BeanPlusUtil;
import org.apache.poi.ss.formula.functions.Now;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.function.Function;
import java.util.stream.Collectors;
@Service
public class CabinetBoxServiceImpl extends ServiceImpl<CabinetBoxMapper, CabinetBox> implements CabinetBoxService {
......@@ -29,15 +38,77 @@ public class CabinetBoxServiceImpl extends ServiceImpl<CabinetBoxMapper, Cabinet
@Resource
private CabinetService cabinetService;
@Autowired
private RabbitMQSendMsg MQ;
//添加箱门信息
@Override
@Transactional(rollbackFor = Exception.class)
public String AddBoxInfo(UpdateCabinetBoxReq req) {
public String AddOrUpdateBoxInfo(UpdateCabinetReq req) {
Cabinet cabinet = cabinetService.getOne(new LambdaQueryWrapper<Cabinet>()
.eq(Cabinet::getCabinetNum, req.getSerialNum()));
if (ObjectUtil.isNull(cabinet)) {
throw new ServiceException(CabinetExceptionEnum.CABINET_ISNOT_EXISTS);
}
List<UpdateCabinetBoxReq> addList = req.getCabinetBoxList();
List<CabinetBox> existingBoxes = list(new LambdaQueryWrapper<CabinetBox>()
.eq(CabinetBox::getCabinetId, cabinet.getId()));
Map<Integer, CabinetBox> existingBoxMap = existingBoxes.stream()
.collect(Collectors.toMap(CabinetBox::getNum, Function.identity()));
List<CabinetBox> boxListAdd = new ArrayList<>();
for (UpdateCabinetBoxReq boxReq : addList) {
CabinetBox box = new CabinetBox();
box.setCabinetId(cabinet.getId());
box.setPower(boxReq.getPower());
box.setEquipmentConfig(boxReq.getEquipmentConfig());
box.setBoxType(boxReq.getBoxType());
box.setState(0);
box.setBoxName(boxReq.getBoxName());
box.setNum(boxReq.getNum());
box.setUpdateTime(new Date());
// 在内存中比较是否存在相同 SerialNum 和相同 num 的数据
CabinetBox existingBox = existingBoxMap.get(boxReq.getNum());
if (existingBox != null) {
// 如果存在,则更新数据
box.setId(existingBox.getId());
updateById(box);
} else {
// 如果不存在,则新增数据
boxListAdd.add(box);
}
}
Integer num = cabinet.getNum();//获取当前柜的总数量
if (num == null) {
num = 0;
}
// 更新 Cabinet 实体
cabinet.setNum(num + addList.size());
cabinetService.updateById(cabinet);
if (req.getActionFrom().equals("platform"))//请求来源于平台,则进行推送
{
MQ.SendMsg("cabinetMsg",req.getSerialNum(),"cabinetChange");
}
// 批量保存新增的数据
saveBatch(boxListAdd);
return cabinet.getId();
}
//删除箱门
@Override
@Transactional(rollbackFor = Exception.class)
public String DeleteBox(UpdateCabinetReq req) {
Cabinet cabinet = cabinetService.getOne(new LambdaQueryWrapper<Cabinet>()
.eq(Cabinet::getCabinetNum, req.getCabinetNum()));
.eq(Cabinet::getCabinetNum, req.getSerialNum()));
if (ObjectUtil.isNull(cabinet)){
throw new ServiceException(CabinetExceptionEnum.CABINET_ISNOT_EXISTS);
}
......@@ -47,26 +118,24 @@ public class CabinetBoxServiceImpl extends ServiceImpl<CabinetBoxMapper, Cabinet
if (ObjectUtil.isNotNull(one)){
throw new ServiceException(CabinetBoxExceptionEnum.CABINETBOX_IS_EXISTS);
}
CabinetBoxExist(req.getId());
CabinetBox cabinetBox = new CabinetBox();
BeanPlusUtil.copyProperties(req,cabinetBox);
//添加单警柜箱门信息默认状态为0正常
cabinetBox.setState(0);
cabinetBox.setCabinetId(cabinet.getId());
Integer num = cabinet.getNum();
if (num==null){
num=1;
cabinet.setNum(num);
cabinetBox.setNum(num);
}else {
cabinet.setNum(num+1);
cabinetBox.setNum(num+1);
}
List<String> boxNumList = req.getNumList();
remove(new LambdaQueryWrapper<CabinetBox>()
.eq(CabinetBox::getCabinetId, cabinet.getId())
.in(CabinetBox::getNum, boxNumList));
// 更新 Cabinet 实体的 num 字段
Integer cabinetNum = cabinet.getNum();
if (cabinetNum != null) {
cabinet.setNum(cabinetNum - boxNumList.size());
cabinetService.updateById(cabinet);
save(cabinetBox);
return cabinetBox.getId();
}
if (req.getActionFrom().equals("platform"))//请求来源于平台,则进行推送
{
MQ.SendMsg("cabinetMsg",req.getSerialNum(),"cabinetChange");
}
return cabinet.getId();
}
//判断箱子信息是否存在
@Override
public CabinetBox CabinetBoxExist(String id) {
......
package com.junmp.jyzb.service.impl;
import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.junmp.jyzb.api.bean.dto.CabinetDto;
......@@ -21,12 +23,14 @@ import com.junmp.v2.common.util.BeanPlusUtil;
import com.junmp.v2.db.api.factory.PageFactory;
import com.junmp.v2.db.api.factory.PageResultFactory;
import com.junmp.v2.db.api.page.PageResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import javax.annotation.Resource;
import java.util.*;
import java.util.stream.Collectors;
@Service
......@@ -35,18 +39,14 @@ public class CabinetServiceImpl extends ServiceImpl<CabinetMapper, Cabinet> impl
@Resource
private CabinetMapper cabinetMapper;
@Resource
private PubOrgService pubOrgService;
@Resource
private CabinetBoxService cabinetBoxService;
@Resource
private PolicemanService policemanService;
@Resource
private OrderMainService orderMainService;
@Autowired
private RabbitMQSendMsg MQ;
private List<Long> getAllOrgId(CabinetReq req, String includeLowerLevel) {
List<Long> allOrg = new ArrayList<>();
......@@ -76,34 +76,39 @@ public class CabinetServiceImpl extends ServiceImpl<CabinetMapper, Cabinet> impl
@Override
public String addCabinetInfo(UpdateCabinetReq req) {
Cabinet cabinet = new Cabinet();
//查询传入的组织机构id是否存在
// 查询传入的组织机构id是否存在
pubOrgService.PubOrgExist(req.getOrgId());
//查询是否有重复的单警柜编号
// 查询是否有重复的单警柜编号
List<Cabinet> list = this.list(new LambdaQueryWrapper<Cabinet>()
.eq(ObjectUtil.isNotEmpty(req.getCabinetNum()),Cabinet::getCabinetNum,req.getCabinetNum()));
if (list.size()>0) {
//抛出单警柜重复异常
.eq(ObjectUtil.isNotEmpty(req.getSerialNum()), Cabinet::getCabinetNum, req.getSerialNum()));
if (list.size() > 0) {
// 抛出单警柜重复异常
throw new ServiceException(CabinetExceptionEnum.CABINETID_IS_EXISTS);
}
BeanPlusUtil.copyProperties(req, cabinet);
cabinet.setCreateTime(DateTimeUtil.getCurrentDateTime());
cabinet.setUpdateTime(DateTimeUtil.getCurrentDateTime());
//添加单警柜
cabinet.setCabinetNum(req.getSerialNum());
cabinet.setNum(req.getCabinetBoxList().size());
cabinet.setOnlineState(1);//新增后设置离线
cabinet.setUpdateTime(new Date());
cabinet.setCreateTime(new Date());
// 添加或更新单警柜
save(cabinet);
List<CabinetBox> objects = new ArrayList<>();
//判断num值是否传递,如果没有不做操作
if (ObjectUtil.isNotNull(req.getNum()) && req.getNum().intValue()>=1){
for (int i = 1; i <= req.getNum(); i++) {
CabinetBox cabinetBox = new CabinetBox();
cabinetBox.setCabinetId(cabinet.getId());
cabinetBox.setState(0);
cabinetBox.setNum(i);
//添加到列表进行批量增加
objects.add(cabinetBox);
}
cabinetBoxService.saveBatch(objects);
}else if (ObjectUtil.isNotNull(req.getNum()) && req.getNum().intValue()<1){
throw new ServiceException(CabinetExceptionEnum.PARAMETER_ERROR);
// 处理箱门信息
if (CollectionUtil.isNotEmpty(req.getCabinetBoxList())) {
List<CabinetBox> boxList = req.getCabinetBoxList().stream()
.map(boxReq -> {
CabinetBox box = new CabinetBox();
box.setCabinetId(cabinet.getId());
box.setPower(boxReq.getPower());
box.setEquipmentConfig(boxReq.getEquipmentConfig());
box.setBoxType(boxReq.getBoxType());
box.setState(0);
box.setNum(boxReq.getNum());
return box;
})
.collect(Collectors.toList());
cabinetBoxService.saveOrUpdateBatch(boxList);
}
return cabinet.getId();
......@@ -174,90 +179,66 @@ public class CabinetServiceImpl extends ServiceImpl<CabinetMapper, Cabinet> impl
*/
@Override
public List<CabinetDto> getAllCabinetList(CabinetReq req) {
//判断组织机构是否存在
// 判断组织机构是否存在
PubOrg pubOrg = pubOrgService.PubOrgExist(req.getOrgId());
List<CabinetDto> cabinetList=new ArrayList<>();
List<Cabinet> list = list(new LambdaQueryWrapper<Cabinet>()
.eq(Cabinet::getOrgId, req.getOrgId()));
if (list.size()==0){
List<CabinetDto> cabinetList = new ArrayList<>();
List<Cabinet> list = cabinetMapper.getAllCabinetsWithSingleCabinet(String.valueOf(req.getOrgId()),req.getContainType());
if (list.size() == 0) {
return new ArrayList<>();
}
for (Cabinet cabinet:list) {
for (Cabinet cabinet : list) {
CabinetDto cabinetDto = new CabinetDto();
BeanPlusUtil.copyProperties(cabinet,cabinetDto);
List<CabinetBox> list1 = cabinetBoxService.list(new LambdaQueryWrapper<CabinetBox>()
.eq(CabinetBox::getCabinetId, cabinet.getId()));
List<CabinetBoxDto> cabinetBoxList=new ArrayList<>();
for (CabinetBox cabinetBox:list1) {
CabinetBoxDto cabinetBoxDto = new CabinetBoxDto();
BeanPlusUtil.copyProperties(cabinetBox,cabinetBoxDto);
//查询箱门绑定的警员id和姓名
List<Policeman> policeList = policemanService.list(new LambdaQueryWrapper<Policeman>()
.eq(Policeman::getCabinetBoxId, cabinetBox.getId()));
if (policeList.size()!=0){
Policeman policeman = policeList.get(0);
cabinetBoxDto.setPoliceId(policeman.getId());
cabinetBoxDto.setPoliceName(policeman.getName());
}
cabinetBoxDto.setBoxNum(cabinetBox.getNum());
cabinetBoxList.add(cabinetBoxDto);
}
cabinetDto.setCabinetBoxList(cabinetBoxList);
BeanPlusUtil.copyProperties(cabinet, cabinetDto);
cabinetDto.setOrgName(pubOrg.getOrgName());
cabinetList.add(cabinetDto);
}
return cabinetList;
}
//根据组织机构id查询出单警柜的详细信息(page)
@Override
public PageResult<CabinetDto> ShowCabinetPage(CabinetReq req) {
//判断组织机构是否存在
// 判断组织机构是否存在
PubOrg pubOrg = pubOrgService.PubOrgExist(req.getOrgId());
List<CabinetDto> cabinetList=new ArrayList<>();
LambdaQueryWrapper<Cabinet> eq = new LambdaQueryWrapper<Cabinet>()
.eq(Cabinet::getOrgId, req.getOrgId())
.like(ObjectUtil.isNotNull(req.getName()),Cabinet::getName,req.getName())
.like(ObjectUtil.isNotNull(req.getCabinetNum()),Cabinet::getCabinetNum,req.getCabinetNum());
List<Cabinet> list = list(eq);
long size = list.size();
if (list.size()==0){
Page<CabinetDto> page = PageFactory.getDefaultPage(req.getPageNo(), req.getPageSize());
page.setRecords(cabinetList);
page.setTotal(cabinetList.size());
return PageResultFactory.createPageResult(page);
}
Page<Cabinet> page = page(PageFactory.getDefaultPage(req.getPageNo(), req.getPageSize()), eq);
List<Cabinet> records = page.getRecords();
for (Cabinet cabinet:records) {
.eq(Cabinet::getOrgIdInt, req.getOrgId())
.like(ObjectUtil.isNotNull(req.getName()), Cabinet::getName, req.getName())
.like(ObjectUtil.isNotNull(req.getSerialNum()), Cabinet::getCabinetNum, req.getSerialNum());
// 使用 PageHelper 开始分页
Page<Cabinet> page = PageFactory.getDefaultPage(req.getPageNo(), req.getPageSize());
// 执行分页查询
IPage<Cabinet> cabinetPage = page(page, eq);
// 获取查询结果列表
List<Cabinet> records = cabinetPage.getRecords();
// 将 Cabinet 转换为 CabinetDto
List<CabinetDto> cabinetList = records.stream()
.map(cabinet -> {
CabinetDto cabinetDto = new CabinetDto();
BeanPlusUtil.copyProperties(cabinet,cabinetDto);
List<CabinetBox> list1 = cabinetBoxService.list(new LambdaQueryWrapper<CabinetBox>()
.eq(CabinetBox::getCabinetId, cabinet.getId())
.orderByAsc(CabinetBox::getNum));
List<CabinetBoxDto> cabinetBoxList=new ArrayList<>();
for (CabinetBox cabinetBox:list1) {
CabinetBoxDto cabinetBoxDto = new CabinetBoxDto();
BeanPlusUtil.copyProperties(cabinetBox,cabinetBoxDto);
//查询箱门绑定的警员id和姓名
List<Policeman> policeList = policemanService.list(new LambdaQueryWrapper<Policeman>()
.eq(Policeman::getCabinetBoxId, cabinetBox.getId()));
if (policeList.size()!=0){
Policeman policeman = policeList.get(0);
cabinetBoxDto.setPoliceId(policeman.getId());
cabinetBoxDto.setPoliceName(policeman.getName());
}
cabinetBoxDto.setBoxNum(cabinetBox.getNum());
cabinetBoxList.add(cabinetBoxDto);
}
cabinetDto.setCabinetBoxList(cabinetBoxList);
BeanPlusUtil.copyProperties(cabinet, cabinetDto);
cabinetDto.setOrgName(pubOrg.getOrgName());
cabinetList.add(cabinetDto);
}
Page<CabinetDto> page1 = PageFactory.getDefaultPage(req.getPageNo(), req.getPageSize());
page1.setRecords(cabinetList);
page1.setTotal(size);
return PageResultFactory.createPageResult(page1);
return cabinetDto;
})
.collect(Collectors.toList());
// 构造一个新的 Page 对象,将 cabinetPage 的数据拷贝到新的对象中
Page<CabinetDto> newPage = new Page<>(cabinetPage.getCurrent(), cabinetPage.getSize(), cabinetPage.getTotal());
newPage.setRecords(cabinetList);
// 使用新的 Page 对象构造返回的 PageResult 对象
PageResult<CabinetDto> result = PageResultFactory.createPageResult(newPage);
return result;
}
/**
......@@ -268,21 +249,27 @@ public class CabinetServiceImpl extends ServiceImpl<CabinetMapper, Cabinet> impl
*/
@Override
public CabinetDto showOneCabinet(CabinetReq req) {
//查询单警柜信息
Cabinet cabinet = CabinetExist(req.getId());
//查询单警柜的箱门信息
// 查询单警柜信息
Cabinet cabinet = CabinetExistByNum(req.getSerialNum());
// 查询单警柜的箱门信息
List<CabinetBox> list = cabinetBoxService.list(new LambdaQueryWrapper<CabinetBox>()
.eq(ObjectUtil.isNotEmpty(req.getId()), CabinetBox::getCabinetId, req.getId()));
List<CabinetBoxDto> boxList=new ArrayList<>();
for (CabinetBox cabinetBox: list) {
.eq(ObjectUtil.isNotEmpty(cabinet.getId()), CabinetBox::getCabinetId, cabinet.getId())
.eq(ObjectUtil.isNotEmpty(req.getContainType()), CabinetBox::getBoxType, req.getContainType()));
List<CabinetBoxDto> boxList = list.stream()
.map(cabinetBox -> {
CabinetBoxDto cabinetBoxDto = new CabinetBoxDto();
BeanPlusUtil.copyProperties(cabinetBox,cabinetBoxDto);
boxList.add(cabinetBoxDto);
}
//将单警柜的信息和它的箱门信息返回
BeanPlusUtil.copyProperties(cabinetBox, cabinetBoxDto);
return cabinetBoxDto;
})
.collect(Collectors.toList());
// 将单警柜的信息和它的箱门信息返回
CabinetDto cabinetDto = new CabinetDto();
BeanPlusUtil.copyProperties(cabinet,cabinetDto);
BeanPlusUtil.copyProperties(cabinet, cabinetDto);
cabinetDto.setCabinetBoxList(boxList);
return cabinetDto;
}
......@@ -299,26 +286,44 @@ public class CabinetServiceImpl extends ServiceImpl<CabinetMapper, Cabinet> impl
Cabinet one = getById(req.getId());
//查询是否有重复的单警柜编号
List<Cabinet> list = this.list(new LambdaQueryWrapper<Cabinet>()
.eq(Cabinet::getCabinetNum,req.getCabinetNum()));
.eq(Cabinet::getCabinetNum,req.getSerialNum()));
if (list.size()>0 && !list.get(0).getCabinetNum().equals(one.getCabinetNum())) {
//抛出单警柜重复异常
throw new ServiceException(CabinetExceptionEnum.CABINETID_IS_EXISTS);
}
Cabinet cabinet = new Cabinet();
BeanPlusUtil.copyProperties(req, cabinet);
//判断传递的箱数是否相同,如果相同则表示没有新增箱门数量,否则添加箱门信息
List<CabinetBox> cabinetBoxList=new ArrayList<>();
if(req.getNum() != one.getNum()){
int startNum = (one.getNum() != null) ? one.getNum() + 1 : 0;
for(int i=startNum+1;i<=req.getNum();i++){
CabinetBox cabinetBox = new CabinetBox();
cabinetBox.setNum(i);
cabinetBox.setCabinetId(req.getId());
cabinetBox.setState(0);
cabinetBoxList.add(cabinetBox);
//后面还要进行消息推送
MQ.SendMsg("cabinetMsg",req.getSerialNum(),"cabinetChange");
return this.updateById(cabinet);
}
/**
* 修改单警柜信息,警柜使用
* 新增箱数
* @param req
* @return
*/
@Override
public boolean updateCabinetClient(UpdateCabinetReq req) {
//查询传入的组织机构id是否存在
pubOrgService.PubOrgExist(req.getOrgId());
Cabinet one = getOne(new LambdaQueryWrapper<Cabinet>()
.eq(Cabinet::getCabinetNum,req.getSerialNum()));
if (one==null)
{
throw new ServiceException(CabinetExceptionEnum.CABINET_ISNOT_EXISTS);
}
//查询是否有重复的单警柜编号
List<Cabinet> list = this.list(new LambdaQueryWrapper<Cabinet>()
.eq(Cabinet::getCabinetNum,req.getSerialNum()));
if (list.size()>0 && !list.get(0).getCabinetNum().equals(one.getCabinetNum())) {
//抛出单警柜重复异常
throw new ServiceException(CabinetExceptionEnum.CABINETID_IS_EXISTS);
}
cabinetBoxService.saveBatch(cabinetBoxList);
Cabinet cabinet = new Cabinet();
BeanPlusUtil.copyProperties(req, cabinet);
//后面还要进行消息推送
return this.updateById(cabinet);
}
......@@ -346,7 +351,7 @@ public class CabinetServiceImpl extends ServiceImpl<CabinetMapper, Cabinet> impl
//单警柜不存在异常
throw new ServiceException(CabinetExceptionEnum.CABINET_ISNOT_EXISTS);
}
long orgId = one1.getOrgId();
long orgId = one1.getOrgIdInt();
//通过警员id获取警员所在的机构id
Policeman one2 = policemanService.getOne(new LambdaQueryWrapper<Policeman>()
.eq(ObjectUtil.isNotEmpty(req.getPoliceId()), Policeman::getId, req.getPoliceId()));
......@@ -372,7 +377,7 @@ public class CabinetServiceImpl extends ServiceImpl<CabinetMapper, Cabinet> impl
@Override
public boolean ChangeCabinetState(UpdateCabinetReq req) {
//查询单警柜是否存在
CabinetExist(req.getId());
CabinetExistByNum(req.getSerialNum());
if (ObjectUtil.isNull(req.getCabinetBoxList()) || req.getCabinetBoxList().size()==0){
throw new ServiceException(CabinetExceptionEnum.PARAMETER_ERROR);
}
......@@ -389,8 +394,8 @@ public class CabinetServiceImpl extends ServiceImpl<CabinetMapper, Cabinet> impl
//根据单警柜id查询出组织机构id
@Override
public Long SearchOrgId(CabinetReq req) {
Cabinet cabinet = CabinetExist(req.getId());
return cabinet.getOrgId();
Cabinet cabinet = CabinetExistByNum(req.getSerialNum());
return cabinet.getOrgIdInt();
}
//根据单警柜id判断单警柜是否存在
......@@ -402,7 +407,15 @@ public class CabinetServiceImpl extends ServiceImpl<CabinetMapper, Cabinet> impl
}
return one;
}
//根据单警柜id判断单警柜是否存在
public Cabinet CabinetExistByNum(String serverNum) {
Cabinet one = getOne(new LambdaQueryWrapper<Cabinet>()
.eq(ObjectUtil.isNotEmpty(serverNum), Cabinet::getCabinetNum, serverNum));
if (ObjectUtil.isNull(one)){
throw new ServiceException(CabinetExceptionEnum.CABINET_ISNOT_EXISTS);
}
return one;
}
//设置单警柜库存数量信息
@Override
public boolean SetInventoryInfo(String id) {
......
......@@ -21,6 +21,8 @@ import com.junmp.jyzb.entity.*;
import com.junmp.jyzb.mapper.OrderMainMapper;
import com.junmp.jyzb.service.*;
import com.junmp.jyzb.utils.DateTimeUtil;
import com.junmp.jyzb.utils.RabbitMQSendMsg;
import com.junmp.jyzb.utils.RedisUtils;
import com.junmp.v2.common.bean.response.ApiRes;
import com.junmp.v2.common.exception.base.ServiceException;
import com.junmp.v2.common.exception.enums.DefaultBizExceptionEnum;
......@@ -41,6 +43,7 @@ import org.springframework.amqp.core.Queue;
import org.springframework.amqp.rabbit.core.RabbitAdmin;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.amqp.core.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
......@@ -108,6 +111,8 @@ public class OrderMainServiceImpl extends ServiceImpl<OrderMainMapper, OrderMain
@Resource
protected TaskService taskService;
@Autowired
private RabbitMQSendMsg MQ;
@Transactional(rollbackFor = Exception.class)
......@@ -285,29 +290,13 @@ public class OrderMainServiceImpl extends ServiceImpl<OrderMainMapper, OrderMain
}
//将完成的任务单直接推送到消息队列rabbitmq中(需要判断是入库单还是出库单,入库单传发物单位id,出库单传收物单位id)
//方法1:一个交换机,一个队列。通过中间对象,object存储对象,type表标识
// if(req.getOrderType().equals("in")){
// rabbitTemplate.convertAndSend("OrderExchange","OrderRouting",new MessageWrapper(req,req.getStartOrgId()));
// }else {
// rabbitTemplate.convertAndSend("OrderExchange","OrderRouting",new MessageWrapper(req,req.getEndOrgId()));
// }
//方法2:一个交换机,多个队列。动态创建队列
String exchangeName="orderExchange";
//需要判断是入库单还是出库单,入库单传收物单位id,出库单传发物单位id
if(req.getOrderType().equals("in")){
Queue queue=new Queue( req.getEndOrgId().toString(),true,false,false);
Exchange exchange = new DirectExchange(exchangeName, true, false);
rabbitAdmin.declareQueue(queue);
rabbitAdmin.declareExchange(exchange);
rabbitAdmin.declareBinding(BindingBuilder.bind(queue).to(exchange).with(req.getEndOrgId().toString()).noargs());
rabbitTemplate.convertAndSend(exchangeName, req.getEndOrgId().toString(), req);
MQ.SendMsg(exchangeName,req.getEndOrgId().toString(),req);
}else {
Queue queue = new Queue(req.getStartOrgId().toString(), true, false, false);
Exchange exchange = new DirectExchange(exchangeName, true, false);
rabbitAdmin.declareQueue(queue);
rabbitAdmin.declareExchange(exchange);
rabbitAdmin.declareBinding(BindingBuilder.bind(queue).to(exchange).with(req.getStartOrgId().toString()).noargs());
rabbitTemplate.convertAndSend(exchangeName, req.getStartOrgId().toString(), req);
MQ.SendMsg(exchangeName,req.getStartOrgId().toString(),req);
}
return req.getId();
}
......
......@@ -520,7 +520,7 @@ public class PolicemanServiceImpl extends ServiceImpl<PolicemanMapper, Policeman
//判断单警柜id是否正确
Cabinet cabinet = cabinetService.CabinetExist(req.getId());
PubOrg pubOrg = pubOrgService.getOne(new LambdaQueryWrapper<PubOrg>()
.eq(PubOrg::getOrgId, cabinet.getOrgId()));
.eq(PubOrg::getOrgId, cabinet.getOrgIdInt()));
//通过箱门id查询出警员
List<Policeman> policemenList = policemanMapper.SearchPoliceList(req.getId());
List<PolicemanDto> list = new ArrayList<>();
......@@ -550,7 +550,7 @@ public class PolicemanServiceImpl extends ServiceImpl<PolicemanMapper, Policeman
//判断单警柜id是否正确
Cabinet cabinet = cabinetService.CabinetExist(req.getId());
PubOrg pubOrg = pubOrgService.getOne(new LambdaQueryWrapper<PubOrg>()
.eq(PubOrg::getOrgId, cabinet.getOrgId()));
.eq(PubOrg::getOrgId, cabinet.getOrgIdInt()));
//通过箱门id查询出警员
Page<Policeman> page = PageFactory.getDefaultPage(req.getPageNo(), req.getPageSize());
long size = policemanMapper.SearchPoliceSize(req.getId());
......
package com.junmp.jyzb.utils;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.DirectExchange;
import org.springframework.amqp.core.Exchange;
import org.springframework.amqp.core.Queue;
import org.springframework.amqp.rabbit.core.RabbitAdmin;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
@Service
public class RabbitMQSendMsg {
@Resource
private RabbitTemplate rabbitTemplate;
@Resource
private RabbitAdmin rabbitAdmin;
public void SendMsg(String exchangeName,String name,Object msg)
{
Queue queue=new Queue(name,true,false,false);
Exchange exchange = new DirectExchange(exchangeName, true, false);
rabbitAdmin.declareQueue(queue);
rabbitAdmin.declareExchange(exchange);
rabbitAdmin.declareBinding(BindingBuilder.bind(queue).to(exchange).with(name).noargs());
rabbitTemplate.convertAndSend(exchangeName, name, msg);
}
}
......@@ -5,7 +5,7 @@
<id property="id" column="id" />
<result property="cabinetNum" column="cabinet_num" />
<result property="name" column="name" />
<result property="orgId" column="org_id_int" />
<result property="orgIdInt" column="org_id_int" />
<result property="departmentId" column="department_id" />
<result property="location" column="location" />
<result property="state" column="state" />
......@@ -72,6 +72,18 @@
#{item}
</foreach>
</select>
<select id="getAllCabinetsWithSingleCabinet" resultType="com.junmp.jyzb.entity.Cabinet">
SELECT c.*
FROM base_cabinet c
JOIN pub_org o ON c.org_id_int = o.org_id
WHERE c.org_id_int = #{orgId}
AND (#{boxType} IS NULL OR #{boxType} = '' OR EXISTS (
SELECT 1
FROM base_cabinet_box cb
WHERE cb.cabinet_id = c.id
AND cb.box_type = #{boxType}
))
</select>
</mapper>
\ No newline at end of file
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论