| | |
| | | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
| | | import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper; |
| | | import com.baomidou.mybatisplus.core.metadata.IPage; |
| | | import com.baomidou.mybatisplus.extension.api.R; |
| | | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
| | | import com.doumee.biz.system.SystemDictDataBiz; |
| | | import com.doumee.config.DataSyncConfig; |
| | | import com.doumee.config.Jwt.JwtPayLoad; |
| | | import com.doumee.config.Jwt.JwtTokenUtil; |
| | | import com.doumee.core.constants.ResponseStatus; |
| | | import com.doumee.core.erp.ErpConstants; |
| | | import com.doumee.core.erp.ErpTool; |
| | |
| | | import com.doumee.core.utils.DESUtil; |
| | | import com.doumee.core.utils.DateUtil; |
| | | import com.doumee.core.utils.Utils; |
| | | import com.doumee.core.utils.redis.RedisUtil; |
| | | import com.doumee.core.wx.wxPlat.WxPlatNotice; |
| | | import com.doumee.dao.business.*; |
| | | import com.doumee.dao.business.dao.CompanyMapper; |
| | | import com.doumee.dao.business.join.CarEventJoinMapper; |
| | | import com.doumee.dao.business.join.DeviceEventJoinMapper; |
| | | import com.doumee.dao.business.join.VisitEventJoinMapper; |
| | | import com.doumee.dao.business.model.*; |
| | | import com.doumee.service.business.ext.ERPSyncService; |
| | | import com.doumee.service.business.InterfaceLogService; |
| | | import com.doumee.service.business.impl.MemberServiceImpl; |
| | | import com.doumee.service.business.impl.hksync.ferp.HkSyncOrgUserToHKServiceImpl; |
| | | import com.github.yulichang.wrapper.MPJLambdaWrapper; |
| | | import lombok.Synchronized; |
| | |
| | | import org.springframework.beans.factory.annotation.Value; |
| | | import org.springframework.data.redis.core.RedisTemplate; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Propagation; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | |
| | | import javax.annotation.PostConstruct; |
| | |
| | | |
| | | @Autowired |
| | | private VisitEventMapper visitEventMapper; |
| | | |
| | | |
| | | @Autowired |
| | | private VisitEventJoinMapper visitEventJoinMapper; |
| | |
| | | List<Company> allList = companyMapper.selectList(new QueryWrapper<Company>().lambda().eq(Company::getType,Constants.ONE)); |
| | | dealCompanyChangeList(list,addList,updateList,delIds,allList); |
| | | if(addList.size()>0){ |
| | | companyMapper.insertBatchSomeColumn(addList); |
| | | companyMapper.insert(addList); |
| | | } |
| | | if(updateList.size()>0){ |
| | | for(Company c : updateList){ |
| | |
| | | .eq(Member::getType, Constants.memberType.internal)); |
| | | dealUserChangeList(list,addList,updateList,delList,allList,param); |
| | | if(addList.size()>0){ |
| | | memberMapper.insertBatchSomeColumn(addList); |
| | | memberMapper.insert(addList); |
| | | /* for (Member member:addList) { |
| | | dealRoleEmpower(member ); |
| | | }*/ |
| | |
| | | return false; |
| | | } |
| | | |
| | | @Override |
| | | public AccessTokenResponse createERPToken(String accessKey, String accessSecret){ |
| | | AccessTokenResponse result = new AccessTokenResponse(); |
| | | try{ |
| | | String erpAccessKey = systemDictDataBiz.queryByCode(Constants.ERP_CONFIG,Constants.ERP_ACCESS_KEY).getCode(); |
| | | String erpAccessSecret = systemDictDataBiz.queryByCode(Constants.ERP_CONFIG,Constants.ERP_ACCESS_SECRET).getCode(); |
| | | if(!(accessKey.equals(erpAccessKey)&&erpAccessSecret.equals(accessSecret))){ |
| | | throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"秘钥匹配失败"); |
| | | } |
| | | JwtPayLoad payLoad = new JwtPayLoad(erpAccessKey+"-"+erpAccessSecret); |
| | | String token = JwtTokenUtil.generateToken(payLoad); |
| | | RedisUtil.addObject(redisTemplate,Constants.RedisKeys.ERP_TOKEN,token,Constants.RedisKeys.EXPIRE_TIME); |
| | | result.setToken(token); |
| | | result.setExpireTime(Constants.RedisKeys.EXPIRE_TIME); |
| | | return result; |
| | | }catch (BusinessException e){ |
| | | throw e; |
| | | }finally { |
| | | Map<String,String> param = new HashMap<>(); |
| | | param.put("accessKey",accessKey); |
| | | param.put("accessSecret",accessSecret); |
| | | saveInterfaceLog(param,"/visitBiz/accesstoken",JSONObject.toJSONString(result),Constants.ZERO); |
| | | } |
| | | |
| | | } |
| | | // @Override |
| | | // public AccessTokenResponse createERPToken(String accessKey, String accessSecret){ |
| | | // AccessTokenResponse result = new AccessTokenResponse(); |
| | | // try{ |
| | | // String erpAccessKey = systemDictDataBiz.queryByCode(Constants.ERP_CONFIG,Constants.ERP_ACCESS_KEY).getCode(); |
| | | // String erpAccessSecret = systemDictDataBiz.queryByCode(Constants.ERP_CONFIG,Constants.ERP_ACCESS_SECRET).getCode(); |
| | | // if(!(accessKey.equals(erpAccessKey)&&erpAccessSecret.equals(accessSecret))){ |
| | | // throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"秘钥匹配失败"); |
| | | // |
| | | // String token = JwtTokenUtil.generateToken(payLoad); |
| | | // RedisUtil.addObject(redisTemplate,Constants.RedisKeys.ERP_TOKEN,token,Constants.RedisKeys.EXPIRE_TIME); |
| | | // result.setToken(token); |
| | | // result.setExpireTime(Constants.RedisKeys.EXPIRE_TIME); |
| | | // return result; |
| | | // }catch (BusinessException e){ |
| | | // throw e; |
| | | // }finally { |
| | | // Map<String,String> param = new HashMap<>(); |
| | | // param.put("accessKey",accessKey); |
| | | // param.put("accessSecret",accessSecret); |
| | | // saveInterfaceLog(param,"/visitBiz/accesstoken",JSONObject.toJSONString(result),Constants.ZERO); |
| | | // } |
| | | // |
| | | // } |
| | | |
| | | /** |
| | | * 门禁组全量接口 |
| | |
| | | } |
| | | } |
| | | if(memberCardList.size()>0){ |
| | | memberCardMapper.insertBatchSomeColumn(memberCardList); |
| | | memberCardMapper.insert(memberCardList); |
| | | } |
| | | } |
| | | } |
| | | private Integer getRoleIdByParam(Integer[] param, Member member) { |
| | | //添加人员角色关联数据 |
| | | member.setRoleId(null); |
| | | List<MemberRole> roleList = memberRoleMapper.selectList( new QueryWrapper<MemberRole>().lambda() |
| | | .eq(MemberRole::getIsdeleted,Constants.ZERO) |
| | | .eq(MemberRole::getMemberId,member.getId())); |
| | | if((param == null || param.length==0 ) &&( roleList==null || roleList.size()==0)){ |
| | | //检查用户权限是否发现变化 |
| | | return 0; |
| | | } |
| | | if((param == null || param.length==0 ) &&( roleList!=null && roleList.size()>0) ){ |
| | | //如果原来有权限,接口进行权限删除 |
| | | memberRoleMapper.delete(new QueryWrapper<MemberRole>().lambda().eq(MemberRole::getMemberId,member.getId())); |
| | | return 1; |
| | | } |
| | | if(!Objects.isNull(param)&¶m.length>Constants.ZERO){ |
| | | if(roleList!=null && roleList.size()>0) { |
| | | //和原有权限进行对比,看是否权限发生变化 |
| | | boolean ischange1=false; |
| | | for (MemberRole role : roleList) { |
| | | ischange1=false; |
| | | for (int j = 0; j < param.length; j++) { |
| | | if(Constants.equalsInteger(role.getRoleId(),param[j])){ |
| | | ischange1=true; |
| | | break; |
| | | } |
| | | } |
| | | if(!ischange1){ |
| | | break; |
| | | } |
| | | } |
| | | |
| | | boolean ischange2 =false; |
| | | for (int j = 0; j < param.length; j++) { |
| | | ischange2=false; |
| | | for (MemberRole role : roleList) { |
| | | if(Constants.equalsInteger(role.getRoleId(),param[j])){ |
| | | ischange2=true; |
| | | break; |
| | | } |
| | | } |
| | | if(!ischange2){ |
| | | break; |
| | | } |
| | | } |
| | | if(ischange2 && ischange1){ |
| | | return 0;//权限未发生改变 |
| | | } |
| | | } |
| | | //如果原来有权限,接口进行权限删除 |
| | | memberRoleMapper.delete(new QueryWrapper<MemberRole>().lambda().eq(MemberRole::getMemberId,member.getId())); |
| | | //查询数据库存在的权限 |
| | | List<DeviceRole> deviceRoleList= deviceRoleMapper.selectList(new QueryWrapper<DeviceRole>().lambda() |
| | | .eq(DeviceRole::getType,Constants.TWO) |
| | | .in(DeviceRole::getId,param)); |
| | | if(CollectionUtils.isNotEmpty(deviceRoleList)){ |
| | | List<MemberRole> memberRoleList = new ArrayList<>(); |
| | | String ids = ""; |
| | | List<Integer> r = new ArrayList<>(); |
| | | for (int i = 0; i < deviceRoleList.size(); i++) { |
| | | DeviceRole deviceRole =deviceRoleList.get(i); |
| | | if(i>0){ |
| | | ids += ","; |
| | | } |
| | | Integer id =deviceRole.getId(); |
| | | ids += "["+id+"]"; |
| | | String doorids =deviceRole.getDoorIds(); |
| | | if(StringUtils.isNotBlank(doorids)){ |
| | | String[] ss = doorids.split(","); |
| | | try { |
| | | for(String s :ss){ |
| | | r.add(Integer.parseInt(s)); |
| | | } |
| | | }catch (Exception e){ |
| | | //脏数据不处理 |
| | | } |
| | | } |
| | | MemberRole memberRole = new MemberRole(); |
| | | memberRole.setCreateDate(new Date()); |
| | | memberRole.setMemberId(member.getId()); |
| | | memberRole.setIsdeleted(Constants.ZERO); |
| | | memberRole.setRoleId(deviceRole.getId()); |
| | | memberRoleList.add(memberRole); |
| | | } |
| | | member.setRoleId(ids); |
| | | memberRoleMapper.insertBatchSomeColumn(memberRoleList); |
| | | member.setRoleId(ids); |
| | | } |
| | | return 1; |
| | | } |
| | | return 0; |
| | | } |
| | | |
| | | |
| | |
| | | if(Objects.isNull(member)){ |
| | | throw new BusinessException(ResponseStatus.DATA_EMPTY.getCode(),"对不起,用户信息不存在!"); |
| | | } |
| | | Integer ischange = getRoleIdByParam(param.getRoleIds(),member); |
| | | Integer ischange = MemberServiceImpl.getRoleIdByParam(param.getRoleIds(),member,memberRoleMapper,deviceRoleMapper); |
| | | if(ischange == 0){ |
| | | return;//未发现权限变化,直接返回 |
| | | } |
| | |
| | | parkBook.setRemark("待同步安防平台"); |
| | | parkBookList.add(parkBook); |
| | | } |
| | | parkBookMapper.insertBatchSomeColumn(parkBookList); |
| | | parkBookMapper.insert(parkBookList); |
| | | }else{ |
| | | throw new BusinessException(ResponseStatus.DATA_EMPTY.getCode(),"对不起,停车库信息不存在,授权失败"); |
| | | } |