Skip to content

Commit

Permalink
fix:添加用户时,存在更新失败的问题
Browse files Browse the repository at this point in the history
oddfar committed Aug 6, 2023
1 parent 3085181 commit fa53771
Showing 4 changed files with 34 additions and 8 deletions.
Original file line number Diff line number Diff line change
@@ -130,6 +130,24 @@ public IUser() {

}

public IUser(Long mobile, JSONObject jsonObject) {
JSONObject data = jsonObject.getJSONObject("data");
this.userId = data.getLong("userId");
this.mobile = mobile;
this.token = data.getString("token");
this.cookie = data.getString("cookie");
this.jsonResult = StringUtils.substring(jsonObject.toJSONString(), 0, 2000);

if (StringUtils.isEmpty(this.remark)) {
this.remark = data.getString("userName");
}

Calendar calendar = Calendar.getInstance();
calendar.add(Calendar.DAY_OF_MONTH, 30);
Date thirtyDaysLater = calendar.getTime();
this.expireTime = thirtyDaysLater;
}

public IUser(Long mobile, String deviceId, JSONObject jsonObject) {
JSONObject data = jsonObject.getJSONObject("data");
this.userId = data.getLong("userId");
Original file line number Diff line number Diff line change
@@ -15,6 +15,7 @@
import com.alibaba.fastjson2.JSONObject;
import com.oddfar.campus.business.entity.IUser;
import com.oddfar.campus.business.mapper.IShopMapper;
import com.oddfar.campus.business.mapper.IUserMapper;
import com.oddfar.campus.business.service.IMTLogFactory;
import com.oddfar.campus.business.service.IMTService;
import com.oddfar.campus.business.service.IShopService;
@@ -46,7 +47,9 @@ public class IMTServiceImpl implements IMTService {
private static final Logger logger = LoggerFactory.getLogger(IMTServiceImpl.class);

@Autowired
IShopMapper iShopMapper;
private IShopMapper iShopMapper;
@Autowired
private IUserMapper iUserMapper;

@Autowired
private RedisCache redisCache;
@@ -147,7 +150,10 @@ public boolean login(String mobile, String code, String deviceId) {

HttpRequest request = HttpUtil.createRequest(Method.POST,
"https://app.moutai519.com.cn/xhr/front/user/register/login");

IUser user = iUserMapper.selectById(mobile);
if (user != null) {
deviceId = user.getDeviceId();
}
request.header("MT-Device-ID", deviceId);
request.header("MT-APP-Version", getMTVersion());
request.header("User-Agent", "iOS;16.3;Apple;?unrecognized?");
@@ -163,7 +169,7 @@ public boolean login(String mobile, String code, String deviceId) {
return true;
} else {
logger.error("「登录请求-失败」" + body.toJSONString());
throw new ServiceException("登录失败,日志已记录");
throw new ServiceException("登录失败,本地错误日志已记录");
// return false;
}

Original file line number Diff line number Diff line change
@@ -33,18 +33,19 @@ public PageResult<IUser> page(IUser iUser) {
@Override
public int insertIUser(Long mobile, String deviceId, JSONObject jsonObject) {
JSONObject data = jsonObject.getJSONObject("data");
if (StringUtils.isEmpty(deviceId)) {
deviceId = UUID.randomUUID().toString().toLowerCase();
}

IUser user = iUserMapper.selectById(mobile);

if (user != null) {
//存在则更新
IUser iUser = new IUser(mobile, deviceId, jsonObject);
IUser iUser = new IUser(mobile, jsonObject);
iUser.setCreateUser(SecurityUtils.getUserId());
BeanUtil.copyProperties(iUser, user);
return iUserMapper.updateById(user);
} else {
if (StringUtils.isEmpty(deviceId)) {
deviceId = UUID.randomUUID().toString().toLowerCase();
}
IUser iUser = new IUser(mobile, deviceId, jsonObject);
iUser.setCreateUser(SecurityUtils.getUserId());
return iUserMapper.insert(iUser);
3 changes: 2 additions & 1 deletion vue_campus_admin/src/views/imt/user/index.vue
Original file line number Diff line number Diff line change
@@ -793,6 +793,7 @@ export default {
this.$modal.msgSuccess(msg);
this.open = false;
this.openUser = false;
this.refreshToken = false;
this.getList();
});
},
@@ -820,4 +821,4 @@ export default {
margin-bottom: 0;
width: 50%;
}
</style>
</style>

0 comments on commit fa53771

Please sign in to comment.