java110
2022-07-19 f498c77c01ea479fa67663286fbbb3cf8b66e689
优化设备 调整为cmd 模式
5个文件已删除
10个文件已修改
1个文件已添加
1136 ■■■■■ 已修改文件
java110-db/src/main/resources/mapper/common/MachineAttrServiceDaoImplMapper.xml 18 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
java110-interface/src/main/java/com/java110/intf/common/IMachineAttrInnerServiceSMO.java 2 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
service-acct/src/main/java/com/java110/acct/api/AccountApi.java 6 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
service-api/src/main/java/com/java110/api/listener/machine/DeleteMachineListener.java 53 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
service-api/src/main/java/com/java110/api/listener/machine/ListMachinesListener.java 342 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
service-api/src/main/java/com/java110/api/listener/machine/SaveMachineListener.java 91 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
service-api/src/main/java/com/java110/api/listener/machine/UpdateMachineListener.java 102 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
service-api/src/main/java/com/java110/api/listener/machine/UpdateMachineStateListener.java 69 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
service-common/src/main/java/com/java110/common/cmd/machine/DeleteMachineCmd.java 11 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
service-common/src/main/java/com/java110/common/cmd/machine/ListMachineCmd.java 256 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
service-common/src/main/java/com/java110/common/cmd/machine/SaveMachineCmd.java 57 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
service-common/src/main/java/com/java110/common/cmd/machine/UpdateMachineCmd.java 58 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
service-common/src/main/java/com/java110/common/cmd/machine/UpdateMachineStateCmd.java 55 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
service-common/src/main/java/com/java110/common/dao/IMachineAttrServiceDao.java 4 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
service-common/src/main/java/com/java110/common/dao/impl/MachineAttrServiceDaoImpl.java 7 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
service-common/src/main/java/com/java110/common/smo/impl/MachineAttrInnerServiceSMOImpl.java 5 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
java110-db/src/main/resources/mapper/common/MachineAttrServiceDaoImplMapper.xml
@@ -134,15 +134,6 @@
        <if test="newBId != null and newBId != ''">
            ,t.b_id = #{newBId}
        </if>
        <if test="machineId !=null and machineId != ''">
            , t.machine_id= #{machineId}
        </if>
        <if test="specCd !=null and specCd != ''">
            , t.spec_cd= #{specCd}
        </if>
        <if test="communityId !=null and communityId != ''">
            , t.community_id= #{communityId}
        </if>
        <if test="value !=null and value != ''">
            , t.value= #{value}
        </if>
@@ -153,6 +144,15 @@
        <if test="bId !=null and bId != ''">
            and t.b_id= #{bId}
        </if>
        <if test="communityId !=null and communityId != ''">
            and t.community_id= #{communityId}
        </if>
        <if test="specCd !=null and specCd != ''">
            and t.spec_cd= #{specCd}
        </if>
        <if test="machineId !=null and machineId != ''">
            and t.machine_id= #{machineId}
        </if>
    </update>
java110-interface/src/main/java/com/java110/intf/common/IMachineAttrInnerServiceSMO.java
@@ -50,4 +50,6 @@
    @RequestMapping(value = "/saveMachineAttrs", method = RequestMethod.POST)
    int saveMachineAttrs(@RequestBody MachineAttrPo machineAttrPo);
    @RequestMapping(value = "/updateMachineAttrs", method = RequestMethod.POST)
    int updateMachineAttrs(@RequestBody MachineAttrPo attr);
}
service-acct/src/main/java/com/java110/acct/api/AccountApi.java
@@ -99,18 +99,20 @@
            String payerObjType = feeDtos.get(0).getPayerObjType();
            //获取付费对象id
            String payerObjId = feeDtos.get(0).getPayerObjId();
            if (!StringUtil.isEmpty(payerObjType) && payerObjType.equals("3333")) { //房屋
            if (FeeDto.PAYER_OBJ_TYPE_ROOM.equals(payerObjType)) { //房屋
                OwnerRoomRelDto ownerRoomRelDto = new OwnerRoomRelDto();
                ownerRoomRelDto.setRoomId(payerObjId);
                List<OwnerRoomRelDto> ownerRoomRelDtos = ownerRoomRelInnerServiceSMOImpl.queryOwnerRoomRels(ownerRoomRelDto);
                Assert.listOnlyOne(ownerRoomRelDtos, "查询业主房屋关系表错误!");
                ownerId = ownerRoomRelDtos.get(0).getOwnerId();
            } else if (!StringUtil.isEmpty(payerObjType) && payerObjType.equals("6666")) {
            } else if (FeeDto.PAYER_OBJ_TYPE_CAR.equals(payerObjType)) {
                OwnerCarDto ownerCarDto = new OwnerCarDto();
                ownerCarDto.setCarId(payerObjId);
                List<OwnerCarDto> ownerCarDtos = ownerCarInnerServiceSMOImpl.queryOwnerCars(ownerCarDto);
//                Assert.listOnlyOne(ownerCarDtos, "查询业主车辆关系表错误!");
                ownerId = ownerCarDtos.get(0).getOwnerId();
            } else {
                ownerId = "-1";
            }
            accountDto.setObjId(ownerId);
        } else {
service-api/src/main/java/com/java110/api/listener/machine/DeleteMachineListener.java
File was deleted
service-api/src/main/java/com/java110/api/listener/machine/ListMachinesListener.java
File was deleted
service-api/src/main/java/com/java110/api/listener/machine/SaveMachineListener.java
File was deleted
service-api/src/main/java/com/java110/api/listener/machine/UpdateMachineListener.java
File was deleted
service-api/src/main/java/com/java110/api/listener/machine/UpdateMachineStateListener.java
File was deleted
service-common/src/main/java/com/java110/common/cmd/machine/DeleteMachineCmd.java
@@ -21,15 +21,16 @@
import com.java110.core.context.ICmdDataFlowContext;
import com.java110.core.event.cmd.Cmd;
import com.java110.core.event.cmd.CmdEvent;
import com.java110.core.log.LoggerFactory;
import com.java110.intf.common.IMachineV1InnerServiceSMO;
import com.java110.po.machine.MachinePo;
import com.java110.utils.exception.CmdException;
import com.java110.utils.util.Assert;
import com.java110.utils.util.BeanConvertUtil;
import com.java110.vo.ResultVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.slf4j.Logger;
import com.java110.core.log.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
/**
 * 类表述:删除
 * 服务编码:machine.deleteMachine
@@ -42,7 +43,7 @@
 */
@Java110Cmd(serviceCode = "machine.deleteMachine")
public class DeleteMachineCmd extends Cmd {
  private static Logger logger = LoggerFactory.getLogger(DeleteMachineCmd.class);
    private static Logger logger = LoggerFactory.getLogger(DeleteMachineCmd.class);
    @Autowired
    private IMachineV1InnerServiceSMO machineV1InnerServiceSMOImpl;
@@ -50,7 +51,7 @@
    @Override
    public void validate(CmdEvent event, ICmdDataFlowContext cmdDataFlowContext, JSONObject reqJson) {
        Assert.hasKeyAndValue(reqJson, "machineId", "machineId不能为空");
Assert.hasKeyAndValue(reqJson, "communityId", "communityId不能为空");
        Assert.hasKeyAndValue(reqJson, "communityId", "communityId不能为空");
    }
@@ -58,7 +59,7 @@
    @Java110Transactional
    public void doCmd(CmdEvent event, ICmdDataFlowContext cmdDataFlowContext, JSONObject reqJson) throws CmdException {
       MachinePo machinePo = BeanConvertUtil.covertBean(reqJson, MachinePo.class);
        MachinePo machinePo = BeanConvertUtil.covertBean(reqJson, MachinePo.class);
        int flag = machineV1InnerServiceSMOImpl.deleteMachine(machinePo);
        if (flag < 1) {
service-common/src/main/java/com/java110/common/cmd/machine/ListMachineCmd.java
@@ -20,12 +20,26 @@
import com.java110.core.context.ICmdDataFlowContext;
import com.java110.core.event.cmd.Cmd;
import com.java110.core.event.cmd.CmdEvent;
import com.java110.dto.RoomDto;
import com.java110.dto.community.CommunityDto;
import com.java110.dto.community.CommunityLocationDto;
import com.java110.dto.unit.FloorAndUnitDto;
import com.java110.intf.common.IMachineInnerServiceSMO;
import com.java110.intf.common.IMachineV1InnerServiceSMO;
import com.java110.intf.community.*;
import com.java110.utils.exception.CmdException;
import com.java110.utils.util.Assert;
import com.java110.utils.util.BeanConvertUtil;
import com.java110.utils.util.DateUtil;
import com.java110.utils.util.StringUtil;
import com.java110.vo.ResultVo;
import com.java110.vo.api.machine.ApiMachineDataVo;
import com.java110.vo.api.machine.ApiMachineVo;
import org.springframework.beans.factory.annotation.Autowired;
import com.java110.dto.machine.MachineDto;
import java.text.ParseException;
import java.util.Calendar;
import java.util.List;
import java.util.ArrayList;
import org.springframework.http.ResponseEntity;
@@ -44,37 +58,253 @@
 * 温馨提示:如果您对此文件进行修改 请不要删除原有作者及注释信息,请补充您的 修改的原因以及联系邮箱如下
 * // modify by 张三 at 2021-09-12 第10行在某种场景下存在某种bug 需要修复,注释10至20行 加入 20行至30行
 */
@Java110Cmd(serviceCode = "machine.listMachine")
@Java110Cmd(serviceCode = "machine.listMachines")
public class ListMachineCmd extends Cmd {
  private static Logger logger = LoggerFactory.getLogger(ListMachineCmd.class);
    @Autowired
    private IMachineV1InnerServiceSMO machineV1InnerServiceSMOImpl;
    private IMachineInnerServiceSMO machineInnerServiceSMOImpl;
    @Autowired
    private ICommunityInnerServiceSMO communityInnerServiceSMOImpl;
    @Autowired
    private IFloorInnerServiceSMO floorInnerServiceSMOImpl;
    @Autowired
    private IUnitInnerServiceSMO unitInnerServiceSMOImpl;
    @Autowired
    private IRoomInnerServiceSMO roomInnerServiceSMOImpl;
    @Autowired
    private ICommunityLocationInnerServiceSMO communityLocationInnerServiceSMOImpl;
    @Override
    public void validate(CmdEvent event, ICmdDataFlowContext cmdDataFlowContext, JSONObject reqJson) {
        super.validatePageInfo(reqJson);
        Assert.jsonObjectHaveKey(reqJson, "communityId", "请求报文中未包含小区信息");
    }
    @Override
    public void doCmd(CmdEvent event, ICmdDataFlowContext cmdDataFlowContext, JSONObject reqJson) throws CmdException {
           MachineDto machineDto = BeanConvertUtil.covertBean(reqJson, MachineDto.class);
        MachineDto machineDto = BeanConvertUtil.covertBean(reqJson, MachineDto.class);
           int count = machineV1InnerServiceSMOImpl.queryMachinesCount(machineDto);
        int count = machineInnerServiceSMOImpl.queryMachinesCount(machineDto);
           List<MachineDto> machineDtos = null;
        List<ApiMachineDataVo> machines = null;
           if (count > 0) {
               machineDtos = machineV1InnerServiceSMOImpl.queryMachines(machineDto);
           } else {
               machineDtos = new ArrayList<>();
           }
        if (count > 0) {
            List<MachineDto> machineDtos = machineInnerServiceSMOImpl.queryMachines(machineDto);
            // 刷新 位置信息
            //refreshMachines(machineDtos);
            refreshMachineLocation(machineDtos);
            machines = BeanConvertUtil.covertBeanList(machineDtos, ApiMachineDataVo.class);
        } else {
            machines = new ArrayList<>();
        }
           ResultVo resultVo = new ResultVo((int) Math.ceil((double) count / (double) reqJson.getInteger("row")), count, machineDtos);
        ApiMachineVo apiMachineVo = new ApiMachineVo();
           ResponseEntity<String> responseEntity = new ResponseEntity<String>(resultVo.toString(), HttpStatus.OK);
        apiMachineVo.setTotal(count);
        apiMachineVo.setRecords((int) Math.ceil((double) count / (double) reqJson.getInteger("row")));
        apiMachineVo.setMachines(machines);
           cmdDataFlowContext.setResponseEntity(responseEntity);
        ResponseEntity<String> responseEntity = new ResponseEntity<String>(JSONObject.toJSONString(apiMachineVo), HttpStatus.OK);
        cmdDataFlowContext.setResponseEntity(responseEntity);
    }
    private void refreshMachineLocation(List<MachineDto> machines) {
        for (MachineDto machineDto : machines) {
            freshMachineStateName(machineDto);
            getMachineLocation(machineDto);
        }
    }
    private void freshMachineStateName(MachineDto machineDto) {
        String heartbeatTime = machineDto.getHeartbeatTime();
        try {
            if (StringUtil.isEmpty(heartbeatTime)) {
                machineDto.setStateName(machineDto.getStateName() + ";设备离线");
            } else {
                Calendar calendar = Calendar.getInstance();
                calendar.setTime(DateUtil.getDateFromString(heartbeatTime, DateUtil.DATE_FORMATE_STRING_A));
                calendar.add(Calendar.MINUTE, 2);
                if (calendar.getTime().getTime() <= DateUtil.getCurrentDate().getTime()) {
                    machineDto.setStateName(machineDto.getStateName() + ";设备离线");
                } else {
                    machineDto.setStateName(machineDto.getStateName() + ";设备在线");
                }
            }
        } catch (ParseException e) {
            e.printStackTrace();
            machineDto.setStateName(machineDto.getStateName() + ";设备离线");
        }
    }
    private void refreshMachines(List<MachineDto> machines) {
        //批量处理 小区
        refreshCommunitys(machines);
        //批量处理单元信息
        refreshUnits(machines);
        //批量处理 房屋信息
        refreshRooms(machines);
        //位置未分配时
        refreshOther(machines);
    }
    private void getMachineLocation(MachineDto machineDto) {
        CommunityLocationDto communityLocationDto = new CommunityLocationDto();
        communityLocationDto.setCommunityId(machineDto.getCommunityId());
        communityLocationDto.setLocationId(machineDto.getLocationTypeCd());
        List<CommunityLocationDto> communityLocationDtos = communityLocationInnerServiceSMOImpl.queryCommunityLocations(communityLocationDto);
        if (communityLocationDtos == null || communityLocationDtos.size() < 1) {
            machineDto.setLocationType(machineDto.getLocationTypeCd());
            return;
        }
        machineDto.setLocationType(communityLocationDtos.get(0).getLocationType());
        machineDto.setLocationObjName(communityLocationDtos.get(0).getLocationName());
    }
    /**
     * 获取批量小区
     *
     * @param machines 设备信息
     * @return 批量userIds 信息
     */
    private void refreshCommunitys(List<MachineDto> machines) {
        List<String> communityIds = new ArrayList<String>();
        List<MachineDto> tmpMachineDtos = new ArrayList<>();
        for (MachineDto machineDto : machines) {
            getMachineLocation(machineDto);
            if (!"2000".equals(machineDto.getLocationType())
                    && !"3000".equals(machineDto.getLocationType())
                    && !"4000".equals(machineDto.getLocationType())
            ) {
                communityIds.add(machineDto.getLocationObjId());
                tmpMachineDtos.add(machineDto);
            }
        }
        if (communityIds.size() < 1) {
            return;
        }
        String[] tmpCommunityIds = communityIds.toArray(new String[communityIds.size()]);
        CommunityDto communityDto = new CommunityDto();
        communityDto.setCommunityIds(tmpCommunityIds);
        //根据 userId 查询用户信息
        List<CommunityDto> communityDtos = communityInnerServiceSMOImpl.queryCommunitys(communityDto);
        for (MachineDto machineDto : tmpMachineDtos) {
            for (CommunityDto tmpCommunityDto : communityDtos) {
                if (machineDto.getLocationObjId().equals(tmpCommunityDto.getCommunityId())) {
                    machineDto.setLocationObjName(tmpCommunityDto.getName() + " " + machineDto.getLocationTypeName());
                }
            }
        }
    }
    /**
     * 获取批量单元
     *
     * @param machines 设备信息
     * @return 批量userIds 信息
     */
    private void refreshUnits(List<MachineDto> machines) {
        List<String> unitIds = new ArrayList<String>();
        List<MachineDto> tmpMachineDtos = new ArrayList<>();
        for (MachineDto machineDto : machines) {
            getMachineLocation(machineDto);
            if ("2000".equals(machineDto.getLocationType())) {
                unitIds.add(machineDto.getLocationObjId());
                tmpMachineDtos.add(machineDto);
            }
        }
        if (unitIds.size() < 1) {
            return;
        }
        String[] tmpUnitIds = unitIds.toArray(new String[unitIds.size()]);
        FloorAndUnitDto floorAndUnitDto = new FloorAndUnitDto();
        floorAndUnitDto.setUnitIds(tmpUnitIds);
        //根据 userId 查询用户信息
        List<FloorAndUnitDto> unitDtos = unitInnerServiceSMOImpl.getFloorAndUnitInfo(floorAndUnitDto);
        for (MachineDto machineDto : tmpMachineDtos) {
            for (FloorAndUnitDto tmpUnitDto : unitDtos) {
                if (machineDto.getLocationObjId().equals(tmpUnitDto.getUnitId())) {
                    machineDto.setLocationObjName(tmpUnitDto.getFloorNum() + "栋" + tmpUnitDto.getUnitNum() + "单元");
                    BeanConvertUtil.covertBean(tmpUnitDto, machineDto);
                }
            }
        }
    }
    /**
     * 获取批量单元
     *
     * @param machines 设备信息
     * @return 批量userIds 信息
     */
    private void refreshRooms(List<MachineDto> machines) {
        List<String> roomIds = new ArrayList<String>();
        List<MachineDto> tmpMachineDtos = new ArrayList<>();
        for (MachineDto machineDto : machines) {
            getMachineLocation(machineDto);
            if ("3000".equals(machineDto.getLocationType())) {
                roomIds.add(machineDto.getLocationObjId());
                tmpMachineDtos.add(machineDto);
            }
        }
        if (roomIds.size() < 1) {
            return;
        }
        String[] tmpRoomIds = roomIds.toArray(new String[roomIds.size()]);
        RoomDto roomDto = new RoomDto();
        roomDto.setRoomIds(tmpRoomIds);
        roomDto.setCommunityId(machines.get(0).getCommunityId());
        //根据 userId 查询用户信息
        List<RoomDto> roomDtos = roomInnerServiceSMOImpl.queryRooms(roomDto);
        for (MachineDto machineDto : tmpMachineDtos) {
            for (RoomDto tmpRoomDto : roomDtos) {
                if (machineDto.getLocationObjId().equals(tmpRoomDto.getRoomId())) {
                    machineDto.setLocationObjName(tmpRoomDto.getFloorNum() + "栋" + tmpRoomDto.getUnitNum() + "单元" + tmpRoomDto.getRoomNum() + "室");
                    BeanConvertUtil.covertBean(tmpRoomDto, machineDto);
                }
            }
        }
    }
    /**
     * 获取批量单元
     *
     * @param machines 设备信息
     * @return 批量userIds 信息
     */
    private void refreshOther(List<MachineDto> machines) {
        for (MachineDto machineDto : machines) {
            if ("4000".equals(machineDto.getLocationTypeCd())) {
                machineDto.setLocationObjName("未分配");
            }
        }
    }
}
service-common/src/main/java/com/java110/common/cmd/machine/SaveMachineCmd.java
@@ -15,6 +15,7 @@
 */
package com.java110.common.cmd.machine;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.java110.core.annotation.Java110Cmd;
import com.java110.core.annotation.Java110Transactional;
@@ -22,15 +23,17 @@
import com.java110.core.event.cmd.Cmd;
import com.java110.core.event.cmd.CmdEvent;
import com.java110.core.factory.GenerateCodeFactory;
import com.java110.core.log.LoggerFactory;
import com.java110.intf.common.IMachineAttrInnerServiceSMO;
import com.java110.intf.common.IMachineV1InnerServiceSMO;
import com.java110.po.machine.MachineAttrPo;
import com.java110.po.machine.MachinePo;
import com.java110.utils.exception.CmdException;
import com.java110.utils.util.Assert;
import com.java110.utils.util.BeanConvertUtil;
import com.java110.vo.ResultVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.slf4j.Logger;
import com.java110.core.log.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
/**
 * 类表述:保存
@@ -52,16 +55,22 @@
    @Autowired
    private IMachineV1InnerServiceSMO machineV1InnerServiceSMOImpl;
    @Autowired
    private IMachineAttrInnerServiceSMO machineAttrInnerServiceSMOImpl;
    @Override
    public void validate(CmdEvent event, ICmdDataFlowContext cmdDataFlowContext, JSONObject reqJson) {
        Assert.hasKeyAndValue( reqJson, "machineCode", "请求报文中未包含machineCode" );
        Assert.hasKeyAndValue( reqJson, "machineVersion", "请求报文中未包含machineVersion" );
        Assert.hasKeyAndValue( reqJson, "machineTypeCd", "请求报文中未包含machineTypeCd" );
        Assert.hasKeyAndValue( reqJson, "communityId", "请求报文中未包含communityId" );
        Assert.hasKeyAndValue( reqJson, "machineName", "请求报文中未包含machineName" );
        Assert.hasKeyAndValue( reqJson, "authCode", "请求报文中未包含authCode" );
        Assert.hasKeyAndValue( reqJson, "direction", "请求报文中未包含direction" );
        Assert.hasKeyAndValue( reqJson, "typeId", "请求报文中未包含typeId" );
        Assert.hasKeyAndValue(reqJson, "machineCode", "必填,请填写设备编码");
        Assert.hasKeyAndValue(reqJson, "machineVersion", "必填,请填写设备版本号");
        Assert.hasKeyAndValue(reqJson, "machineName", "必填,请填写设备名称");
        Assert.hasKeyAndValue(reqJson, "machineTypeCd", "必填,请选择设备类型");
        Assert.hasKeyAndValue(reqJson, "direction", "必填,请选择设备方向");
        Assert.hasKeyAndValue(reqJson, "authCode", "必填,请填写鉴权编码");
        Assert.hasKeyAndValue(reqJson, "locationTypeCd", "必填,请选择位置类型");
        Assert.hasKeyAndValue(reqJson, "locationObjId", "必填,请填写位置对象ID");
        //属性校验
        Assert.judgeAttrValue(reqJson);
    }
@@ -77,6 +86,34 @@
            throw new CmdException( "保存数据失败" );
        }
        dealMachineAttr(reqJson);
        cmdDataFlowContext.setResponseEntity( ResultVo.success() );
    }
    private void dealMachineAttr(JSONObject paramObj) {
        if (!paramObj.containsKey("attrs")) {
            return;
        }
        JSONArray attrs = paramObj.getJSONArray("attrs");
        if (attrs.size() < 1) {
            return;
        }
        MachineAttrPo attr = null;
        int flag = 0;
        for (int attrIndex = 0; attrIndex < attrs.size(); attrIndex++) {
            attr = BeanConvertUtil.covertBean(attrs.getJSONObject(attrIndex), MachineAttrPo.class);
            attr.setCommunityId(paramObj.getString("communityId"));
            attr.setMachineId(paramObj.getString("machineId"));
            attr.setAttrId(GenerateCodeFactory.getGeneratorId(CODE_PREFIX_ID ));
            flag = machineAttrInnerServiceSMOImpl.saveMachineAttrs(attr);
            if (flag < 1) {
                throw new CmdException( "保存数据失败" );
            }
        }
    }
}
service-common/src/main/java/com/java110/common/cmd/machine/UpdateMachineCmd.java
@@ -15,21 +15,27 @@
 */
package com.java110.common.cmd.machine;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.java110.core.annotation.Java110Cmd;
import com.java110.core.annotation.Java110Transactional;
import com.java110.core.context.ICmdDataFlowContext;
import com.java110.core.event.cmd.Cmd;
import com.java110.core.event.cmd.CmdEvent;
import com.java110.core.factory.GenerateCodeFactory;
import com.java110.core.log.LoggerFactory;
import com.java110.intf.common.IMachineAttrInnerServiceSMO;
import com.java110.intf.common.IMachineV1InnerServiceSMO;
import com.java110.po.machine.MachineAttrPo;
import com.java110.po.machine.MachinePo;
import com.java110.utils.constant.BusinessTypeConstant;
import com.java110.utils.exception.CmdException;
import com.java110.utils.util.Assert;
import com.java110.utils.util.BeanConvertUtil;
import com.java110.utils.util.StringUtil;
import com.java110.vo.ResultVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.slf4j.Logger;
import com.java110.core.log.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
/**
@@ -45,16 +51,28 @@
@Java110Cmd(serviceCode = "machine.updateMachine")
public class UpdateMachineCmd extends Cmd {
  private static Logger logger = LoggerFactory.getLogger(UpdateMachineCmd.class);
    private static Logger logger = LoggerFactory.getLogger(UpdateMachineCmd.class);
    @Autowired
    private IMachineV1InnerServiceSMO machineV1InnerServiceSMOImpl;
    @Autowired
    private IMachineAttrInnerServiceSMO machineAttrInnerServiceSMOImpl;
    @Override
    public void validate(CmdEvent event, ICmdDataFlowContext cmdDataFlowContext, JSONObject reqJson) {
        Assert.hasKeyAndValue(reqJson, "machineId", "machineId不能为空");
Assert.hasKeyAndValue(reqJson, "communityId", "communityId不能为空");
        Assert.hasKeyAndValue(reqJson, "machineId", "设备ID不能为空");
        Assert.hasKeyAndValue(reqJson, "machineCode", "必填,请填写设备编码");
        Assert.hasKeyAndValue(reqJson, "machineVersion", "必填,请填写设备版本号");
        Assert.hasKeyAndValue(reqJson, "machineName", "必填,请填写设备名称");
        Assert.hasKeyAndValue(reqJson, "machineTypeCd", "必填,请选择设备类型");
        Assert.hasKeyAndValue(reqJson, "direction", "必填,请选择设备方向");
        Assert.hasKeyAndValue(reqJson, "authCode", "必填,请填写鉴权编码");
        Assert.hasKeyAndValue(reqJson, "locationTypeCd", "必填,请选择位置类型");
        Assert.hasKeyAndValue(reqJson, "locationObjId", "必填,请填写位置对象ID");
        Assert.judgeAttrValue(reqJson);
    }
@@ -62,13 +80,41 @@
    @Java110Transactional
    public void doCmd(CmdEvent event, ICmdDataFlowContext cmdDataFlowContext, JSONObject reqJson) throws CmdException {
       MachinePo machinePo = BeanConvertUtil.covertBean(reqJson, MachinePo.class);
        MachinePo machinePo = BeanConvertUtil.covertBean(reqJson, MachinePo.class);
        int flag = machineV1InnerServiceSMOImpl.updateMachine(machinePo);
        if (flag < 1) {
            throw new CmdException("更新数据失败");
        }
        JSONArray attrs = reqJson.getJSONArray("attrs");
        if (attrs.size() < 1) {
            return;
        }
        MachineAttrPo attr = null;
        JSONObject aObj = null;
        for (int attrIndex = 0; attrIndex < attrs.size(); attrIndex++) {
            aObj = attrs.getJSONObject(attrIndex);
            attr = BeanConvertUtil.covertBean(aObj, MachineAttrPo.class);
            attr.setCommunityId(reqJson.getString("communityId"));
            attr.setMachineId(reqJson.getString("machineId"));
            if (!aObj.containsKey("attrId") || aObj.getString("attrId").startsWith("-") || StringUtil.isEmpty(aObj.getString("attrId"))) {
                attr.setAttrId(GenerateCodeFactory.getGeneratorId("11"));
                flag = machineAttrInnerServiceSMOImpl.saveMachineAttrs(attr);
                if (flag < 1) {
                    throw new CmdException("添加数据失败");
                }
                continue;
            }
            attr.setAttrId(aObj.getString("attrId"));
            flag = machineAttrInnerServiceSMOImpl.updateMachineAttrs(attr);
            if (flag < 1) {
                throw new CmdException("更新数据失败");
            }
        }
        cmdDataFlowContext.setResponseEntity(ResultVo.success());
    }
}
service-common/src/main/java/com/java110/common/cmd/machine/UpdateMachineStateCmd.java
New file
@@ -0,0 +1,55 @@
package com.java110.common.cmd.machine;
import com.alibaba.fastjson.JSONObject;
import com.java110.core.annotation.Java110Cmd;
import com.java110.core.context.ICmdDataFlowContext;
import com.java110.core.event.cmd.Cmd;
import com.java110.core.event.cmd.CmdEvent;
import com.java110.dto.machine.MachineDto;
import com.java110.intf.common.IMachineInnerServiceSMO;
import com.java110.intf.common.IMachineV1InnerServiceSMO;
import com.java110.po.machine.MachinePo;
import com.java110.utils.exception.CmdException;
import com.java110.utils.util.Assert;
import com.java110.utils.util.BeanConvertUtil;
import org.springframework.beans.factory.annotation.Autowired;
import java.util.List;
@Java110Cmd(serviceCode = "machine.updateMachineState")
public class UpdateMachineStateCmd extends Cmd {
    @Autowired
    private IMachineInnerServiceSMO machineInnerServiceSMOImpl;
    @Autowired
    private IMachineV1InnerServiceSMO machineV1InnerServiceSMOImpl;
    @Override
    public void validate(CmdEvent event, ICmdDataFlowContext context, JSONObject reqJson) throws CmdException {
        Assert.hasKeyAndValue(reqJson, "machineId", "设备ID不能为空");
        Assert.hasKeyAndValue(reqJson, "communityId", "必填,请填写小区信息");
        Assert.hasKeyAndValue(reqJson, "state", "必填,请填写设备状态");
    }
    @Override
    public void doCmd(CmdEvent event, ICmdDataFlowContext context, JSONObject reqJson) throws CmdException {
        MachineDto machineDto = new MachineDto();
        machineDto.setCommunityId(reqJson.getString("communityId"));
        machineDto.setMachineId(reqJson.getString("machineId"));
        List<MachineDto> machineDtos = machineInnerServiceSMOImpl.queryMachines(machineDto);
        Assert.listOnlyOne(machineDtos, "根据设备编码查询到多条记录,请检查数据");
        JSONObject businessMachine = new JSONObject();
        businessMachine.putAll(BeanConvertUtil.beanCovertMap(machineDtos.get(0)));
        businessMachine.put("state", reqJson.getString("state"));
        //计算 应收金额
        MachinePo machinePo = BeanConvertUtil.covertBean(businessMachine, MachinePo.class);
        int flag = machineV1InnerServiceSMOImpl.updateMachine(machinePo);
        if (flag < 1) {
            throw new CmdException("更新数据失败");
        }
    }
}
service-common/src/main/java/com/java110/common/dao/IMachineAttrServiceDao.java
@@ -73,5 +73,7 @@
     */
    int queryMachineAttrsCount(Map info);
    int saveMachineAttrs(Map beanCovertMap);
    int saveMachineAttrs(Map info);
    int updateMachineAttrs(Map info);
}
service-common/src/main/java/com/java110/common/dao/impl/MachineAttrServiceDaoImpl.java
@@ -136,5 +136,12 @@
        return saveFlag;
    }
    @Override
    public int updateMachineAttrs(Map info) {
        int saveFlag = sqlSessionTemplate.update("machineAttrServiceDaoImpl.updateMachineAttrInfoInstance", info);
        return saveFlag;
    }
}
service-common/src/main/java/com/java110/common/smo/impl/MachineAttrInnerServiceSMOImpl.java
@@ -58,6 +58,11 @@
        return machineAttrServiceDaoImpl.saveMachineAttrs(BeanConvertUtil.beanCovertMap(machineAttrPo));
    }
    @Override
    public int updateMachineAttrs(@RequestBody MachineAttrPo machineAttrPo) {
        return machineAttrServiceDaoImpl.updateMachineAttrs(BeanConvertUtil.beanCovertMap(machineAttrPo));
    }
    public IMachineAttrServiceDao getMachineAttrServiceDaoImpl() {
        return machineAttrServiceDaoImpl;
    }