Commit 0155f7ef authored by 耿迪迪's avatar 耿迪迪

多账户关联

parent b54fe7f7
package com.zehong.web.controller.userRelation;
import java.util.List;
import com.zehong.common.annotation.Log;
import com.zehong.common.core.controller.BaseController;
import com.zehong.common.core.domain.AjaxResult;
import com.zehong.common.core.domain.entity.SysUser;
import com.zehong.common.core.exception.BusinessException;
import com.zehong.common.core.page.TableDataInfo;
import com.zehong.common.enums.BusinessType;
import com.zehong.common.utils.SecurityUtils;
import com.zehong.common.utils.StringUtils;
import com.zehong.common.utils.poi.ExcelUtil;
import com.zehong.system.domain.TUserRelation;
import com.zehong.system.service.ISysUserService;
import org.springframework.security.access.prepost.PreAuthorize;
import com.zehong.system.service.ITUserRelationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.util.CollectionUtils;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.zehong.common.annotation.Log;
import com.zehong.common.core.controller.BaseController;
import com.zehong.common.core.domain.AjaxResult;
import com.zehong.common.enums.BusinessType;
import com.zehong.system.domain.TUserRelation;
import com.zehong.system.service.ITUserRelationService;
import com.zehong.common.utils.poi.ExcelUtil;
import com.zehong.common.core.page.TableDataInfo;
import org.springframework.web.bind.annotation.*;
import java.util.List;
/**
* 用户关联Controller
......@@ -91,6 +83,7 @@ public class TUserRelationController extends BaseController
return toAjax(tUserRelationService.insertTUserRelation(tUserRelation));
}
/**
* 校验关联信息
* @param tUserRelation 关联信息
......@@ -115,6 +108,23 @@ public class TUserRelationController extends BaseController
throw new BusinessException("不能关联当前账户");
}
tUserRelation.setRelationUserId(sysUser.getUserId());
//关联对方账号
relationEachOther(sysUser.getUserId(),tUserRelation.getUserId());
}
/**
* 关联对方账号
* @param userId 账号
* @param relationUserId 对方账号
*/
private void relationEachOther(Long userId, Long relationUserId) {
TUserRelation relation = new TUserRelation();
relation.setUserId(userId);
relation.setRelationUserId(relationUserId);
List<TUserRelation> relations = tUserRelationService.selectTUserRelationList(relation);
if(CollectionUtils.isEmpty(relations)){
tUserRelationService.insertTUserRelation(relation);
}
}
/**
......
package com.zehong.system.mapper;
import java.util.List;
import java.util.Map;
import com.zehong.system.domain.TUserRelation;
/**
......@@ -58,4 +60,6 @@ public interface TUserRelationMapper
* @return 结果
*/
public int deleteTUserRelationByIds(Long[] relationIds);
int deleteUserRelationByUserIdAndRelationUserId(Map<String,Long> map);
}
package com.zehong.system.service.impl;
import java.util.List;
import com.zehong.common.utils.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.zehong.system.mapper.TUserRelationMapper;
import com.zehong.system.domain.TUserRelation;
import com.zehong.system.mapper.TUserRelationMapper;
import com.zehong.system.service.ITUserRelationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* 用户关联Service业务层处理
......@@ -77,8 +81,16 @@ public class TUserRelationServiceImpl implements ITUserRelationService
* @return 结果
*/
@Override
@Transactional(rollbackFor = Exception.class)
public int deleteTUserRelationByIds(Long[] relationIds)
{
for(Long relationId : relationIds){
TUserRelation relation = tUserRelationMapper.selectTUserRelationById(relationId);
Map<String,Long> map = new HashMap<>();
map.put("userId",relation.getRelationUserId());
map.put("relationUserId",relation.getUserId());
tUserRelationMapper.deleteUserRelationByUserIdAndRelationUserId(map);
}
return tUserRelationMapper.deleteTUserRelationByIds(relationIds);
}
......
......@@ -89,4 +89,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
#{relationId}
</foreach>
</delete>
<delete id="deleteUserRelationByUserIdAndRelationUserId" parameterType="Map">
delete from t_user_relation where user_id = #{userId} AND relation_user_id = #{relationUserId}
</delete>
</mapper>
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment