wuxw
2024-09-14 4e43292ef963be988afdb83e3888e91adeac4e17
service-user/src/main/java/com/java110/user/cmd/roleCommunity/SaveRoleCommunityCmd.java
@@ -15,6 +15,7 @@
 */
package com.java110.user.cmd.roleCommunity;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.java110.core.annotation.Java110Cmd;
import com.java110.core.annotation.Java110Transactional;
@@ -23,10 +24,9 @@
import com.java110.core.event.cmd.CmdEvent;
import com.java110.core.factory.GenerateCodeFactory;
import com.java110.intf.user.IRoleCommunityV1InnerServiceSMO;
import com.java110.po.roleCommunity.RoleCommunityPo;
import com.java110.po.privilege.RoleCommunityPo;
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;
@@ -55,20 +55,30 @@
    @Override
    public void validate(CmdEvent event, ICmdDataFlowContext cmdDataFlowContext, JSONObject reqJson) {
        Assert.hasKeyAndValue(reqJson, "roleId", "请求报文中未包含roleId");
Assert.hasKeyAndValue(reqJson, "communityId", "请求报文中未包含communityId");
        if (!reqJson.containsKey("communitys") || reqJson.getJSONArray("communitys").size() < 1) {
            throw new IllegalArgumentException("未包含小区信息");
        }
    }
    @Override
    @Java110Transactional
    public void doCmd(CmdEvent event, ICmdDataFlowContext cmdDataFlowContext, JSONObject reqJson) throws CmdException {
        String storeId = cmdDataFlowContext.getReqHeaders().get("store-id");
       RoleCommunityPo roleCommunityPo = BeanConvertUtil.covertBean(reqJson, RoleCommunityPo.class);
        roleCommunityPo.setRcId(GenerateCodeFactory.getGeneratorId(CODE_PREFIX_ID));
        int flag = roleCommunityV1InnerServiceSMOImpl.saveRoleCommunity(roleCommunityPo);
        RoleCommunityPo roleCommunityPo = null;
        JSONArray communitys = reqJson.getJSONArray("communitys");
        for (int communityIndex = 0; communityIndex < communitys.size(); communityIndex++) {
            roleCommunityPo = new RoleCommunityPo();
            roleCommunityPo.setCommunityId(communitys.getJSONObject(communityIndex).getString("communityId"));
            roleCommunityPo.setCommunityName(communitys.getJSONObject(communityIndex).getString("communityName"));
            roleCommunityPo.setRoleId(reqJson.getString("roleId"));
            roleCommunityPo.setStoreId(storeId);
            roleCommunityPo.setRcId(GenerateCodeFactory.getGeneratorId(CODE_PREFIX_ID));
            int flag = roleCommunityV1InnerServiceSMOImpl.saveRoleCommunity(roleCommunityPo);
        if (flag < 1) {
            throw new CmdException("保存数据失败");
            if (flag < 1) {
                throw new CmdException("保存数据失败");
            }
        }
        cmdDataFlowContext.setResponseEntity(ResultVo.success());