Commit a7f34569 by 赵剑炜

修正单警柜方法

parent 55ab604d
...@@ -17,20 +17,14 @@ import lombok.NoArgsConstructor; ...@@ -17,20 +17,14 @@ import lombok.NoArgsConstructor;
@AllArgsConstructor @AllArgsConstructor
@NoArgsConstructor @NoArgsConstructor
@TableName("base_cabinet") @TableName("base_cabinet")
public class Cabinet implements Serializable { public class Cabinet implements Serializable {
/** /**
* 单警柜ID * 单警柜ID
*/ */
@TableId(value = "id",type = IdType.ASSIGN_UUID ) @TableId(value = "id",type = IdType.ASSIGN_UUID )
@ApiModelProperty(value = "单警柜ID")
private String id; private String id;
/**
* 单警柜编号
*/
@ApiModelProperty(value = "单警柜编号")
@TableField("cabinet_num")
private String cabinetNum;
/** /**
* 单警柜名称 * 单警柜名称
*/ */
...@@ -44,7 +38,11 @@ public class Cabinet implements Serializable { ...@@ -44,7 +38,11 @@ public class Cabinet implements Serializable {
@TableField("org_id_int") @TableField("org_id_int")
private Long orgIdInt; private Long orgIdInt;
/**
* 单警柜编号
*/
@TableField("cabinet_num")
private String cabinetNum;
/** /**
* 部门id * 部门id
*/ */
...@@ -129,14 +127,10 @@ public class Cabinet implements Serializable { ...@@ -129,14 +127,10 @@ public class Cabinet implements Serializable {
*/ */
@ApiModelProperty(value = "箱数") @ApiModelProperty(value = "箱数")
private Integer num; private Integer num;
private String policeName; private String policeName;
private String policeId; private String policeId;
private Integer number; private Integer number;
private String orgName;
private String boxId; private String boxId;
private String containType; private String containType;
private String boxState; private String boxState;
......
...@@ -46,95 +46,97 @@ public class CabinetBoxServiceImpl extends ServiceImpl<CabinetBoxMapper, Cabinet ...@@ -46,95 +46,97 @@ public class CabinetBoxServiceImpl extends ServiceImpl<CabinetBoxMapper, Cabinet
@Override @Override
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = Exception.class)
public String AddOrUpdateBoxInfo(UpdateCabinetReq req) { public String AddOrUpdateBoxInfo(UpdateCabinetReq req) {
Cabinet cabinet = cabinetService.getOne(new LambdaQueryWrapper<Cabinet>() // Cabinet cabinet = cabinetService.getOne(new LambdaQueryWrapper<Cabinet>()
.eq(Cabinet::getCabinetNum, req.getSerialNum())); // .eq(Cabinet::getCabinetNum, req.getSerialNum()));
if (ObjectUtil.isNull(cabinet)) { // if (ObjectUtil.isNull(cabinet)) {
throw new ServiceException(CabinetExceptionEnum.CABINET_ISNOT_EXISTS); // throw new ServiceException(CabinetExceptionEnum.CABINET_ISNOT_EXISTS);
} // }
//
List<UpdateCabinetBoxReq> addList = req.getCabinetBoxList(); // List<UpdateCabinetBoxReq> addList = req.getCabinetBoxList();
List<CabinetBox> existingBoxes = list(new LambdaQueryWrapper<CabinetBox>() // List<CabinetBox> existingBoxes = list(new LambdaQueryWrapper<CabinetBox>()
.eq(CabinetBox::getCabinetId, cabinet.getId())); // .eq(CabinetBox::getCabinetId, cabinet.getId()));
//
Map<Integer, CabinetBox> existingBoxMap = existingBoxes.stream() // Map<Integer, CabinetBox> existingBoxMap = existingBoxes.stream()
.collect(Collectors.toMap(CabinetBox::getNum, Function.identity())); // .collect(Collectors.toMap(CabinetBox::getNum, Function.identity()));
//
List<CabinetBox> boxListAdd = new ArrayList<>(); // List<CabinetBox> boxListAdd = new ArrayList<>();
//
for (UpdateCabinetBoxReq boxReq : addList) { // for (UpdateCabinetBoxReq boxReq : addList) {
CabinetBox box = new CabinetBox(); // CabinetBox box = new CabinetBox();
box.setCabinetId(cabinet.getId()); // box.setCabinetId(cabinet.getId());
box.setPower(boxReq.getPower()); // box.setPower(boxReq.getPower());
box.setEquipmentConfig(boxReq.getEquipmentConfig()); // box.setEquipmentConfig(boxReq.getEquipmentConfig());
box.setContainType(boxReq.getContainType()); // box.setContainType(boxReq.getContainType());
box.setState(0); // box.setState(0);
box.setBoxName(boxReq.getBoxName()); // box.setBoxName(boxReq.getBoxName());
box.setNum(boxReq.getNum()); // box.setNum(boxReq.getNum());
box.setUpdateTime(new Date()); // box.setUpdateTime(new Date());
// 在内存中比较是否存在相同 SerialNum 和相同 num 的数据 // // 在内存中比较是否存在相同 SerialNum 和相同 num 的数据
CabinetBox existingBox = existingBoxMap.get(boxReq.getNum()); // CabinetBox existingBox = existingBoxMap.get(boxReq.getNum());
//
if (existingBox != null) { // if (existingBox != null) {
// 如果存在,则更新数据 // // 如果存在,则更新数据
box.setId(existingBox.getId()); // box.setId(existingBox.getId());
updateById(box); // updateById(box);
} else { // } else {
// 如果不存在,则新增数据 // // 如果不存在,则新增数据
boxListAdd.add(box); // boxListAdd.add(box);
} // }
} // }
//
Integer num = cabinet.getNum();//获取当前柜的总数量 // Integer num = cabinet.getNum();//获取当前柜的总数量
if (num == null) { // if (num == null) {
num = 0; // num = 0;
} // }
//
// 更新 Cabinet 实体 // // 更新 Cabinet 实体
cabinet.setNum(num + addList.size()); // cabinet.setNum(num + addList.size());
cabinetService.updateById(cabinet); // cabinetService.updateById(cabinet);
//
if (req.getActionFrom().equals("platform"))//请求来源于平台,则进行推送 // if (req.getActionFrom().equals("platform"))//请求来源于平台,则进行推送
{ // {
MQ.SendMsg("cabinetMsg",req.getSerialNum(),"cabinetChange"); // MQ.SendMsg("cabinetMsg",req.getSerialNum(),"cabinetChange");
} // }
// 批量保存新增的数据 // // 批量保存新增的数据
saveBatch(boxListAdd); // saveBatch(boxListAdd);
//
return cabinet.getId(); // return cabinet.getId();
return null;
} }
//删除箱门 //删除箱门
@Override @Override
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = Exception.class)
public String DeleteBox(UpdateCabinetReq req) { public String DeleteBox(UpdateCabinetReq req) {
Cabinet cabinet = cabinetService.getOne(new LambdaQueryWrapper<Cabinet>() // Cabinet cabinet = cabinetService.getOne(new LambdaQueryWrapper<Cabinet>()
.eq(Cabinet::getCabinetNum, req.getSerialNum())); // .eq(Cabinet::getCabinetNum, req.getSerialNum()));
if (ObjectUtil.isNull(cabinet)){ // if (ObjectUtil.isNull(cabinet)){
throw new ServiceException(CabinetExceptionEnum.CABINET_ISNOT_EXISTS); // throw new ServiceException(CabinetExceptionEnum.CABINET_ISNOT_EXISTS);
} // }
CabinetBox one = getOne(new LambdaQueryWrapper<CabinetBox>() // CabinetBox one = getOne(new LambdaQueryWrapper<CabinetBox>()
.eq(CabinetBox::getCabinetId, cabinet.getId()) // .eq(CabinetBox::getCabinetId, cabinet.getId())
.eq(CabinetBox::getId,req.getId())); // .eq(CabinetBox::getId,req.getId()));
if (ObjectUtil.isNotNull(one)){ // if (ObjectUtil.isNotNull(one)){
throw new ServiceException(CabinetBoxExceptionEnum.CABINETBOX_IS_EXISTS); // throw new ServiceException(CabinetBoxExceptionEnum.CABINETBOX_IS_EXISTS);
} // }
//添加单警柜箱门信息默认状态为0正常 // //添加单警柜箱门信息默认状态为0正常
List<String> boxNumList = req.getNumList(); // List<String> boxNumList = req.getNumList();
remove(new LambdaQueryWrapper<CabinetBox>() // remove(new LambdaQueryWrapper<CabinetBox>()
.eq(CabinetBox::getCabinetId, cabinet.getId()) // .eq(CabinetBox::getCabinetId, cabinet.getId())
.in(CabinetBox::getNum, boxNumList)); // .in(CabinetBox::getNum, boxNumList));
//
// 更新 Cabinet 实体的 num 字段 // // 更新 Cabinet 实体的 num 字段
Integer cabinetNum = cabinet.getNum(); // Integer cabinetNum = cabinet.getNum();
if (cabinetNum != null) { // if (cabinetNum != null) {
cabinet.setNum(cabinetNum - boxNumList.size()); // cabinet.setNum(cabinetNum - boxNumList.size());
cabinetService.updateById(cabinet); // cabinetService.updateById(cabinet);
} // }
if (req.getActionFrom().equals("platform"))//请求来源于平台,则进行推送 // if (req.getActionFrom().equals("platform"))//请求来源于平台,则进行推送
{ // {
MQ.SendMsg("cabinetMsg",req.getSerialNum(),"cabinetChange"); // MQ.SendMsg("cabinetMsg",req.getSerialNum(),"cabinetChange");
} // }
return cabinet.getId(); // return cabinet.getId();
return null;
} }
//判断箱子信息是否存在 //判断箱子信息是否存在
@Override @Override
......
...@@ -192,13 +192,14 @@ public class CabinetServiceImpl extends ServiceImpl<CabinetMapper, Cabinet> impl ...@@ -192,13 +192,14 @@ public class CabinetServiceImpl extends ServiceImpl<CabinetMapper, Cabinet> impl
groupedCabinets.forEach((id, cabinets) -> { groupedCabinets.forEach((id, cabinets) -> {
// 对每个分组内的数据按照 num 字段升序排序 // 对每个分组内的数据按照 num 字段升序排序
List<Cabinet> sortedCabinets = cabinets.stream() List<Cabinet> sortedCabinets = cabinets.stream()
.sorted(Comparator.comparingInt(Cabinet::getNum)) .sorted(Comparator.comparingInt(Cabinet::getNumber))
.collect(Collectors.toList()); .collect(Collectors.toList());
// 创建 CabinetDto 对象并设置属性 // 创建 CabinetDto 对象并设置属性
CabinetDto cabinetDto = new CabinetDto(); CabinetDto cabinetDto = new CabinetDto();
BeanPlusUtil.copyProperties(sortedCabinets.get(0), cabinetDto); BeanPlusUtil.copyProperties(sortedCabinets.get(0), cabinetDto);
cabinetDto.setOrgId(sortedCabinets.get(0).getOrgIdInt());
cabinetDto.setOrgName(sortedCabinets.get(0).getOrgName());
List<CabinetBoxDto> cabinetBoxList = new ArrayList<>(); List<CabinetBoxDto> cabinetBoxList = new ArrayList<>();
for (Cabinet cabinet : sortedCabinets) { for (Cabinet cabinet : sortedCabinets) {
CabinetBoxDto cabinetBoxDto = new CabinetBoxDto(); CabinetBoxDto cabinetBoxDto = new CabinetBoxDto();
......
...@@ -2,7 +2,8 @@ ...@@ -2,7 +2,8 @@
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.junmp.jyzb.mapper.CabinetMapper"> <mapper namespace="com.junmp.jyzb.mapper.CabinetMapper">
<resultMap id="cabinetResultMap" type="com.junmp.jyzb.entity.Cabinet"> <resultMap id="cabinetResultMap" type="com.junmp.jyzb.entity.Cabinet">
<result property="id" column="id" />
<id column="id" jdbcType="VARCHAR" property="id" />
<result property="cabinetNum" column="cabinet_num" /> <result property="cabinetNum" column="cabinet_num" />
<result property="name" column="name" /> <result property="name" column="name" />
<result property="orgIdInt" column="org_id_int" /> <result property="orgIdInt" column="org_id_int" />
...@@ -23,6 +24,7 @@ ...@@ -23,6 +24,7 @@
<result property="boxState" column="box_state" /> <result property="boxState" column="box_state" />
<result property="equipmentConfig" column="equipment_config" /> <result property="equipmentConfig" column="equipment_config" />
<result property="number" column="number" /> <result property="number" column="number" />
<result property="orgName" column="org_name" />
<result property="updateUser" column="update_user" /> <result property="updateUser" column="update_user" />
<!-- </collection>--> <!-- </collection>-->
...@@ -31,7 +33,7 @@ ...@@ -31,7 +33,7 @@
<sql id="Base_Column_List"> <sql id="Base_Column_List">
<!--@mbg.generated--> <!--@mbg.generated-->
id, cabinet_num, `name`, org_id, `location`, error_state, create_time, update_time, id, cabinet_num, `name`, org_id, `location`, error_state, create_time, update_time,
create_user, update_user create_user, update_user
</sql> </sql>
<update id="SetInventoryInfo" parameterType="java.lang.String"> <update id="SetInventoryInfo" parameterType="java.lang.String">
...@@ -77,14 +79,16 @@ ...@@ -77,14 +79,16 @@
</foreach> </foreach>
</select> </select>
<select id="getAllCabinetsWithSingleCabinet" resultType="com.junmp.jyzb.entity.Cabinet"> <select id="getAllCabinetsWithSingleCabinet" resultType="com.junmp.jyzb.entity.Cabinet">
SELECT c.*,c.id as id,cb.id as box_id,cb.contain_type,cb.state as box_state,
cb.equipment_config, cb.num as number,bp.`name` as police_name,bp.id as police_id SELECT cabinet.id as id,cabinet.cabinet_num,cabinet.name,cabinet.org_id_int,cabinet.location,cabinet.state,
FROM base_cabinet c cabinet.online_state,cabinet.create_time,cabinet.update_time,cabinet.num,cb.id as box_id,cb.contain_type,cb.state as box_state,
JOIN pub_org o ON c.org_id_int = o.org_id cb.equipment_config, cb.num as number,bp.`name` as police_name,bp.id as police_id,o.org_name
LEFT JOIN base_cabinet_box cb ON cb.cabinet_id = c.id FROM base_cabinet cabinet
left join pub_org o ON cabinet.org_id_int = o.org_id
LEFT JOIN base_cabinet_box cb ON cb.cabinet_id = cabinet.id
LEFT JOIN base_cabinet_box_police ccp ON ccp.cabinet_box_id = cb.id LEFT JOIN base_cabinet_box_police ccp ON ccp.cabinet_box_id = cb.id
LEFT JOIN base_policeman bp ON bp.id = ccp.police_id LEFT JOIN base_policeman bp ON bp.id = ccp.police_id
WHERE c.org_id_int = #{orgId} and cb.num is not null; WHERE cabinet.org_id_int = #{orgId} and cb.num is not null;
</select> </select>
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论