| | |
| | | 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.doc.annotation.*; |
| | | import com.java110.dto.community.CommunityDto; |
| | | import com.java110.dto.community.PropertyManagementRecordDto; |
| | | import com.java110.dto.privilege.RoleCommunityDto; |
| | | import com.java110.intf.community.ICommunityV1InnerServiceSMO; |
| | | import com.java110.intf.community.PropertyManagementRecordsServiceSMO; |
| | | import com.java110.intf.user.IRoleCommunityV1InnerServiceSMO; |
| | | import com.java110.po.community.PropertyManagementRecordPo; |
| | | import com.java110.po.privilege.RoleCommunityPo; |
| | | import com.java110.utils.exception.CmdException; |
| | | import com.java110.utils.util.Assert; |
| | | import com.java110.utils.util.DateUtil; |
| | | import com.java110.utils.util.StringUtil; |
| | | import com.java110.vo.ResultVo; |
| | | import org.slf4j.Logger; |
| | | import com.java110.core.log.LoggerFactory; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | |
| | | |
| | | @Java110CmdDoc(title = "修改小区", |
| | |
| | | url = "http://{ip}:{port}/app/community.updateCommunity", |
| | | resource = "communityDoc", |
| | | author = "吴学文", |
| | | serviceCode = "community.updateCommunity" |
| | | serviceCode = "community.updateCommunity", |
| | | seq = 2 |
| | | ) |
| | | |
| | | @Java110ParamsDoc(params = { |
| | | @Java110ParamDoc(name = "communityId", length = 30, remark = "小区编码"), |
| | | @Java110ParamDoc(name = "address", length = 30, remark = "小区地址"), |
| | | @Java110ParamDoc(name = "cityCode", length = 12, remark = "地区编码"), |
| | | @Java110ParamDoc(name = "feePrice", type = "int",length = 11, remark = "小区收费价格"), |
| | | @Java110ParamDoc(name = "feePrice", type = "int", length = 11, remark = "小区收费价格"), |
| | | @Java110ParamDoc(name = "mapX", length = 12, remark = "经度"), |
| | | @Java110ParamDoc(name = "mapY", length = 12, remark = "纬度"), |
| | | @Java110ParamDoc(name = "name", length = 64, remark = "名称"), |
| | | @Java110ParamDoc(name = "nearbyLandmarks", length = 64, remark = "地标,如xx 公园旁"), |
| | | @Java110ParamDoc(name = "payFeeMonth", type = "int",length = 11, remark = "小区收费周期"), |
| | | @Java110ParamDoc(name = "payFeeMonth", type = "int", length = 11, remark = "小区收费周期"), |
| | | @Java110ParamDoc(name = "tel", length = 11, remark = "小区客服电话"), |
| | | }) |
| | | |
| | |
| | | ) |
| | | |
| | | @Java110ExampleDoc( |
| | | reqBody="{\"communityId\":\"2022092293190329\",\"name\":\"api接口小区1\",\"address\":\"天津省天津市和平区api接口小区\",\"nearbyLandmarks\":\"23\",\"cityCode\":\"120101\",\"mapX\":\"101.33\",\"mapY\":\"101.33\",\"payFeeMonth\":12,\"feePrice\":0,\"tel\":\"18909711443\",\"attrs\":[{\"domain\":\"COMMON\",\"listShow\":\"Y\",\"page\":-1,\"records\":0,\"required\":\"Y\",\"row\":0,\"specCd\":\"9329000004\",\"specHoldplace\":\"必填,请填写社区编码\",\"specId\":\"9329000004\",\"specName\":\"社区编码\",\"specShow\":\"Y\",\"specType\":\"2233\",\"specValueType\":\"1001\",\"statusCd\":\"0\",\"tableName\":\"building_community_attr\",\"total\":0,\"value\":\"123123\",\"values\":[],\"attrId\":\"112022092280950341\"}]}", |
| | | resBody="{'code':0,'msg':'成功'}" |
| | | reqBody = "{\"communityId\":\"2022092293190329\",\"name\":\"api接口小区1\",\"address\":\"天津省天津市和平区api接口小区\",\"nearbyLandmarks\":\"23\",\"cityCode\":\"120101\",\"mapX\":\"101.33\",\"mapY\":\"101.33\",\"payFeeMonth\":12,\"feePrice\":0,\"tel\":\"18909711443\",\"attrs\":[{\"domain\":\"COMMON\",\"listShow\":\"Y\",\"page\":-1,\"records\":0,\"required\":\"Y\",\"row\":0,\"specCd\":\"9329000004\",\"specHoldplace\":\"必填,请填写社区编码\",\"specId\":\"9329000004\",\"specName\":\"社区编码\",\"specShow\":\"Y\",\"specType\":\"2233\",\"specValueType\":\"1001\",\"statusCd\":\"0\",\"tableName\":\"building_community_attr\",\"total\":0,\"value\":\"123123\",\"values\":[],\"attrId\":\"112022092280950341\"}]}", |
| | | resBody = "{'code':0,'msg':'成功'}" |
| | | ) |
| | | /** |
| | | * 类表述:更新 |
| | |
| | | @Autowired |
| | | private ICommunityV1InnerServiceSMO communityV1InnerServiceSMOImpl; |
| | | |
| | | @Autowired |
| | | private IRoleCommunityV1InnerServiceSMO roleCommunityV1InnerServiceSMOImpl; |
| | | |
| | | |
| | | @Autowired |
| | | private ICommunityBMO communityBMOImpl; |
| | |
| | | |
| | | Assert.hasKeyAndValue(reqJson, "communityId", "小区ID不能为空"); |
| | | Assert.hasKeyAndValue(reqJson, "name", "必填,请填写小区名称"); |
| | | Assert.hasKeyAndValue(reqJson, "address", "必填,请填写小区地址"); |
| | | // Assert.hasKeyAndValue(reqJson, "address", "必填,请填写小区地址"); |
| | | Assert.hasKeyAndValue(reqJson, "nearbyLandmarks", "必填,请填写小区附近地标"); |
| | | |
| | | Assert.judgeAttrValue(reqJson); |
| | | |
| | | } |
| | | |
| | | @Autowired |
| | | private PropertyManagementRecordsServiceSMO propertyManagementRecordsServiceSMO; |
| | | |
| | | @Override |
| | | @Java110Transactional |
| | | public void doCmd(CmdEvent event, ICmdDataFlowContext cmdDataFlowContext, JSONObject reqJson) throws CmdException { |
| | | |
| | | // 保存原始状态用于判断是否修改了状态 |
| | | CommunityDto communityDto = new CommunityDto(); |
| | | communityDto.setCommunityId(reqJson.getString("communityId")); |
| | | String originalState = communityV1InnerServiceSMOImpl.queryCommunitys(communityDto).get(0).getState(); |
| | | String newState = reqJson.getString("state"); |
| | | |
| | | communityBMOImpl.updateCommunityOne(reqJson, cmdDataFlowContext); |
| | | |
| | | // 新增:处理状态变更(在管/退管) |
| | | // 只有状态发生变化时才处理 |
| | | if (!StringUtil.isEmpty(originalState) && !originalState.equals(newState)) { |
| | | handleCommunityStateChange(reqJson.getString("communityId"), newState, communityV1InnerServiceSMOImpl.queryCommunitys(communityDto).get(0)); |
| | | } |
| | | |
| | | if (!reqJson.containsKey("attrs")) { |
| | | return; |
| | | } |
| | | |
| | | JSONArray attrs = reqJson.getJSONArray("attrs"); |
| | | if (attrs.size() < 1) { |
| | | if (attrs == null || attrs.size() < 1) { |
| | | return; |
| | | } |
| | | |
| | |
| | | communityBMOImpl.updateAttr(attr, cmdDataFlowContext); |
| | | } |
| | | |
| | | //todo 如果没有修改名称直接返回 |
| | | if (StringUtil.isEmpty(reqJson.getString("name"))) { |
| | | return; |
| | | } |
| | | |
| | | //todo 修改角色小区 |
| | | |
| | | RoleCommunityDto roleCommunityDto = new RoleCommunityDto(); |
| | | roleCommunityDto.setCommunityId(reqJson.getString("communityId")); |
| | | List<RoleCommunityDto> roleCommunityDtos = roleCommunityV1InnerServiceSMOImpl.queryRoleCommunitys(roleCommunityDto); |
| | | |
| | | if (roleCommunityDtos == null || roleCommunityDtos.size() < 1) { |
| | | return; |
| | | } |
| | | RoleCommunityPo roleCommunityPo = null; |
| | | for (RoleCommunityDto tmpRoleCommunityDto : roleCommunityDtos) { |
| | | roleCommunityPo = new RoleCommunityPo(); |
| | | roleCommunityPo.setRcId(tmpRoleCommunityDto.getRcId()); |
| | | roleCommunityPo.setCommunityName(reqJson.getString("name")); |
| | | roleCommunityV1InnerServiceSMOImpl.updateRoleCommunity(roleCommunityPo); |
| | | } |
| | | |
| | | |
| | | cmdDataFlowContext.setResponseEntity(ResultVo.success()); |
| | | } |
| | | /** |
| | | * 处理小区状态变更(适配property_management_records表) |
| | | * @param communityId 小区ID |
| | | * @param newState 新状态(1400-退管,其他-在管) |
| | | */ |
| | | private void handleCommunityStateChange(String communityId, String newState , CommunityDto communityDto) { |
| | | if (communityDto.getTakeTime() == null) { |
| | | return; |
| | | } |
| | | |
| | | // 1. 退管状态(state=1400):为该小区的有效在管记录添加退管时间 |
| | | if ("1400".equals(newState)) { |
| | | // 查询小区当前有效的在管记录(status=0表示有效,management_end_date为null表示未退管) |
| | | PropertyManagementRecordDto queryDto = new PropertyManagementRecordDto(); |
| | | queryDto.setCommunityId(communityId); |
| | | queryDto.setStatus(0); // 有效记录 |
| | | |
| | | List<Map> records = propertyManagementRecordsServiceSMO.queryPropertyManagementRecords(queryDto); |
| | | |
| | | if (records != null && !records.isEmpty()) { |
| | | PropertyManagementRecordPo updatePo = new PropertyManagementRecordPo(); |
| | | updatePo.setManagementEndDate(communityDto.getTakeTime()); // 设置当前时间为退管时间 |
| | | // 退管后记录状态仍为有效(status=0),通过end_date区分是否在管 |
| | | |
| | | |
| | | |
| | | updatePo.setId((String) records.get(records.size() - 1).get("id")); // 表主键ID |
| | | int flag = propertyManagementRecordsServiceSMO.updatePropertyManagementRecord(updatePo); |
| | | if (flag < 1) { |
| | | throw new CmdException("更新小区[" + communityId + "]退管记录失败"); |
| | | } |
| | | } |
| | | } |
| | | // 2. 在管状态(state != 1400):为小区添加新的在管记录 |
| | | else { |
| | | // 查询小区是否已有未退管的有效记录(避免重复添加) |
| | | PropertyManagementRecordDto checkDto = new PropertyManagementRecordDto(); |
| | | checkDto.setCommunityId(communityId); |
| | | checkDto.setStatus(0); // 有效记录 |
| | | |
| | | // 创建新的在管记录 |
| | | PropertyManagementRecordPo addPo = new PropertyManagementRecordPo(); |
| | | addPo.setId(GenerateCodeFactory.getGeneratorId(GenerateCodeFactory.CODE_PREFIX_id)); // 生成主键ID |
| | | addPo.setCommunityId(communityId); |
| | | addPo.setCommunityName(getCommunityName(communityId)); // 从小区信息中获取名称(需实现) |
| | | addPo.setManagementStartDate(communityDto.getOutTime()); // 开始时间为当前时间 |
| | | addPo.setManagementEndDate(null); // 未退管,退管时间为null |
| | | addPo.setStatus(0); // 状态:0-有效 |
| | | addPo.setRemark("小区状态变更为在管时自动添加"); |
| | | |
| | | int flag = propertyManagementRecordsServiceSMO.savePropertyManagementRecord(addPo); |
| | | if (flag < 1) { |
| | | throw new CmdException("添加小区[" + communityId + "]在管记录失败"); |
| | | } |
| | | } |
| | | } |
| | | |
| | | // 辅助方法:获取小区名称(需根据实际业务实现,例如从小区表查询) |
| | | private String getCommunityName(String communityId) { |
| | | // 示例:从小区服务查询名称 |
| | | CommunityDto communityDto = new CommunityDto(); |
| | | communityDto.setCommunityId(communityId); |
| | | List<CommunityDto> communities = communityV1InnerServiceSMOImpl.queryCommunitys(communityDto); |
| | | return communities != null && !communities.isEmpty() ? communities.get(0).getName() : ""; |
| | | } |
| | | |
| | | // 辅助方法:获取当前管理公司ID(需根据实际业务实现,例如从登录信息或请求参数中获取) |
| | | private String getCurrentManagementCompanyId() { |
| | | // 示例:从请求上下文或当前登录信息中获取,此处仅为占位 |
| | | return "当前管理公司ID"; // 实际应替换为真实逻辑 |
| | | } |
| | | |
| | | // 辅助方法:获取当前管理公司名称(同上) |
| | | private String getCurrentManagementCompanyName() { |
| | | return "当前管理公司名称"; // 实际应替换为真实逻辑 |
| | | } |
| | | } |