package com.stylefeng.guns.modular.system.service.impl;
|
|
import com.alibaba.fastjson.JSON;
|
import com.alibaba.fastjson.JSONArray;
|
import com.alibaba.fastjson.JSONObject;
|
import com.baomidou.mybatisplus.mapper.EntityWrapper;
|
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
|
import com.stylefeng.guns.core.util.ToolUtil;
|
import com.stylefeng.guns.modular.system.dao.UserUserMapper;
|
import com.stylefeng.guns.modular.system.model.UserInfo;
|
import com.stylefeng.guns.modular.system.model.UserTaxiCard;
|
import com.stylefeng.guns.modular.system.model.UserUser;
|
import com.stylefeng.guns.modular.system.service.IUserInfoService;
|
import com.stylefeng.guns.modular.system.service.IUserTaxiCardService;
|
import com.stylefeng.guns.modular.system.service.IUserUserService;
|
import com.stylefeng.guns.modular.system.util.ResultUtil;
|
import com.stylefeng.guns.modular.system.warpper.BaseWarpper;
|
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.stereotype.Service;
|
|
import java.util.ArrayList;
|
import java.util.List;
|
|
@Service
|
public class UserUserServiceImpl extends ServiceImpl<UserUserMapper, UserUser> implements IUserUserService {
|
|
@Autowired
|
private IUserInfoService userInfoService;
|
|
@Autowired
|
private IUserTaxiCardService userTaxiCardService;
|
|
@Override
|
public List<BaseWarpper> getUserUserList(Integer uid) throws Exception {
|
List<UserUser> userUsers = this.selectList(new EntityWrapper<UserUser>().eq("userId", uid).orderBy("id"));
|
List<BaseWarpper> list = new ArrayList<>();
|
userUsers.forEach(userUser -> {
|
BaseWarpper baseWarpper = new BaseWarpper();
|
baseWarpper.setId(userUser.getId());
|
baseWarpper.setName(userUser.getCallName());
|
baseWarpper.setContent(userUser.getPhone());
|
list.add(baseWarpper);
|
});
|
return list;
|
}
|
|
@Override
|
public ResultUtil addUserUser(Integer uid, String content) throws Exception {
|
int nu = userTaxiCardService.selectCount(new EntityWrapper<UserTaxiCard>().eq("userId", uid));
|
if(nu == 0){
|
return ResultUtil.error("您暂未购买打车卡");
|
}
|
if(ToolUtil.isNotEmpty(content)){
|
JSONArray jsonArray = JSON.parseArray(content);
|
int num = 0;
|
for(int i = 0; i < jsonArray.size(); i++) {
|
JSONObject jsonObject = jsonArray.getJSONObject(i);
|
Integer id = jsonObject.getInteger("id");
|
if(null == id){
|
num++;
|
}
|
}
|
int number = this.selectCount(new EntityWrapper<UserUser>().eq("userId", uid));
|
int n = 15 - number;
|
if(n > 0 && n < num){
|
return ResultUtil.error("您还能添加" + n + "个亲密账户");
|
}
|
if(n == 0){
|
return ResultUtil.error("您已超出绑定上限15人");
|
}
|
|
for(int i = 0; i < jsonArray.size(); i++){
|
JSONObject jsonObject = jsonArray.getJSONObject(i);
|
Integer id = jsonObject.getInteger("id");
|
String phone = jsonObject.getString("phone");
|
String name = jsonObject.getString("name");
|
UserInfo userInfo = userInfoService.selectOne(new EntityWrapper<UserInfo>().eq("phone", phone).ne("flag", 3));
|
if(null != userInfo && userInfo.getId().compareTo(uid) == 0){
|
return ResultUtil.error("不能绑定自己");
|
}
|
if(null == id){
|
if(null != userInfo){
|
int i1 = this.selectCount(new EntityWrapper<UserUser>().eq("userId", uid).eq("bindUserId", userInfo.getId()));
|
if(i1 > 0){
|
return ResultUtil.error(phone + "号码已经绑定了");
|
}
|
}
|
if(null == userInfo){
|
return ResultUtil.error(phone + "该手机还未注册账户");
|
}
|
|
UserUser userUser = new UserUser();
|
userUser.setUserId(uid);
|
userUser.setBindUserId(userInfo.getId());
|
userUser.setCallName(name);
|
userUser.setPhone(phone);
|
this.insert(userUser);
|
}else{
|
UserUser userUser = this.selectById(id);
|
userUser.setPhone(phone);
|
userUser.setCallName(name);
|
this.updateById(userUser);
|
}
|
}
|
}
|
return ResultUtil.success();
|
}
|
|
@Override
|
public ResultUtil unbundleUserUser(Integer id) throws Exception {
|
this.deleteById(id);
|
return ResultUtil.success();
|
}
|
}
|