19 changed files with 59 additions and 422 deletions
@ -1,103 +0,0 @@ |
|||
package com.qs.serve.modules.ums.controller; |
|||
|
|||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
|||
import com.qs.serve.common.model.annotation.SysLog; |
|||
import com.qs.serve.common.model.dto.PageVo; |
|||
import com.qs.serve.common.model.dto.R; |
|||
import com.qs.serve.common.model.enums.BizType; |
|||
import com.qs.serve.common.model.enums.SystemModule; |
|||
import com.qs.serve.common.util.PageUtil; |
|||
import lombok.AllArgsConstructor; |
|||
import lombok.extern.slf4j.Slf4j; |
|||
import org.springframework.security.access.prepost.PreAuthorize; |
|||
import org.springframework.web.bind.annotation.*; |
|||
|
|||
import com.qs.serve.modules.ums.entity.UmsUser; |
|||
import com.qs.serve.modules.ums.service.UmsUserService; |
|||
|
|||
import javax.validation.Valid; |
|||
import java.util.List; |
|||
|
|||
/** |
|||
* 手机用户 |
|||
* @author YenHex |
|||
* @since 2022-09-13 |
|||
*/ |
|||
@Slf4j |
|||
@AllArgsConstructor |
|||
@RestController |
|||
@RequestMapping("ums/user") |
|||
public class UmsUserController { |
|||
|
|||
private UmsUserService umsUserService; |
|||
|
|||
/** |
|||
* 翻页查询 |
|||
* @param param |
|||
* @return |
|||
*/ |
|||
@GetMapping("/page") |
|||
@PreAuthorize("hasRole('ums:user:query')") |
|||
public R<PageVo<UmsUser>> getPage(UmsUser param){ |
|||
PageUtil.startPage(); |
|||
LambdaQueryWrapper<UmsUser> userWrapper = new LambdaQueryWrapper<>(param); |
|||
List<UmsUser> list = umsUserService.list(userWrapper); |
|||
return R.byPageHelperList(list); |
|||
} |
|||
|
|||
/** |
|||
* 根据ID查询 |
|||
* @param id |
|||
* @return |
|||
*/ |
|||
@GetMapping("/getById/{id}") |
|||
@SysLog(module = SystemModule.UMS, title = "手机用户", biz = BizType.QUERY) |
|||
@PreAuthorize("hasRole('ums:user:query')") |
|||
public R<UmsUser> getById(@PathVariable("id") String id){ |
|||
UmsUser umsUser = umsUserService.getById(id); |
|||
return R.ok(umsUser); |
|||
} |
|||
|
|||
|
|||
|
|||
/** |
|||
* 根据ID更新 |
|||
* @param param |
|||
* @return |
|||
*/ |
|||
@PostMapping("/updateById") |
|||
@SysLog(module = SystemModule.UMS, title = "手机用户", biz = BizType.UPDATE) |
|||
@PreAuthorize("hasRole('ums:user:update')") |
|||
public R<?> updateById(@RequestBody @Valid UmsUser param){ |
|||
boolean result = umsUserService.updateById(param); |
|||
return R.isTrue(result); |
|||
} |
|||
|
|||
/** |
|||
* 新增手机用户 |
|||
* @param param |
|||
* @return |
|||
*/ |
|||
@PostMapping("/save") |
|||
@SysLog(module = SystemModule.UMS, title = "手机用户", biz = BizType.INSERT) |
|||
@PreAuthorize("hasRole('ums:user:insert')") |
|||
public R<?> save(@RequestBody @Valid UmsUser param){ |
|||
boolean result = umsUserService.save(param); |
|||
return R.isTrue(result); |
|||
} |
|||
|
|||
/** |
|||
* 删除手机用户 |
|||
* @param id |
|||
* @return |
|||
*/ |
|||
@DeleteMapping("/deleteById/{id}") |
|||
@SysLog(module = SystemModule.UMS, title = "手机用户", biz = BizType.DELETE) |
|||
@PreAuthorize("hasRole('ums:user:delete')") |
|||
public R<?> deleteById(@PathVariable("id") String id){ |
|||
boolean result = umsUserService.removeById(id); |
|||
return R.isTrue(result); |
|||
} |
|||
|
|||
} |
|||
|
@ -1,76 +0,0 @@ |
|||
package com.qs.serve.modules.ums.entity; |
|||
|
|||
import java.time.LocalDateTime; |
|||
import java.io.Serializable; |
|||
|
|||
import com.baomidou.mybatisplus.annotation.*; |
|||
import com.fasterxml.jackson.annotation.JsonFormat; |
|||
import com.fasterxml.jackson.annotation.JsonIgnore; |
|||
import com.fasterxml.jackson.annotation.JsonProperty; |
|||
import lombok.Data; |
|||
import org.hibernate.validator.constraints.Length; |
|||
import org.springframework.format.annotation.DateTimeFormat; |
|||
|
|||
import javax.validation.constraints.NotNull; |
|||
import javax.validation.constraints.NotBlank; |
|||
|
|||
/** |
|||
* 手机用户 实体类 |
|||
* @author YenHex |
|||
* @since 2022-09-13 |
|||
*/ |
|||
@Data |
|||
@TableName("ums_user") |
|||
public class UmsUser implements Serializable { |
|||
|
|||
private static final long serialVersionUID = 1L; |
|||
|
|||
/** id */ |
|||
@TableId(type = IdType.AUTO) |
|||
private Long id; |
|||
|
|||
/** 名称 */ |
|||
@NotBlank(message = "名称不能为空") |
|||
@Length(max = 20,message = "名称长度不能超过20字") |
|||
private String name; |
|||
|
|||
/** 手机号 */ |
|||
@Length(max = 12,message = "手机号长度不能超过12字") |
|||
private String mobile; |
|||
|
|||
/** 头像 */ |
|||
@Length(max = 255,message = "头像长度不能超过255字") |
|||
private String avatar; |
|||
|
|||
/** 创建时间 */ |
|||
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") |
|||
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss",timezone = "GMT+8") |
|||
@TableField(fill = FieldFill.INSERT) |
|||
private LocalDateTime createTime; |
|||
|
|||
/** 创建人 */ |
|||
@TableField(fill = FieldFill.INSERT) |
|||
private String createBy; |
|||
|
|||
/** 更新时间 */ |
|||
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") |
|||
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss",timezone = "GMT+8") |
|||
@TableField(fill = FieldFill.UPDATE) |
|||
private LocalDateTime updateTime; |
|||
|
|||
/** 更新人 */ |
|||
@TableField(fill = FieldFill.UPDATE) |
|||
private String updateBy; |
|||
|
|||
/** 租户id */ |
|||
@JsonIgnore |
|||
@JsonProperty |
|||
private String tenantId; |
|||
|
|||
/** 删除标识 */ |
|||
@JsonIgnore |
|||
@JsonProperty |
|||
private Boolean delFlag; |
|||
|
|||
} |
|||
|
@ -1,42 +0,0 @@ |
|||
package com.qs.serve.modules.ums.entity; |
|||
|
|||
import java.time.LocalDateTime; |
|||
import java.io.Serializable; |
|||
|
|||
import com.baomidou.mybatisplus.annotation.*; |
|||
import com.fasterxml.jackson.annotation.JsonFormat; |
|||
import com.fasterxml.jackson.annotation.JsonIgnore; |
|||
import com.fasterxml.jackson.annotation.JsonProperty; |
|||
import lombok.Data; |
|||
import org.hibernate.validator.constraints.Length; |
|||
import org.springframework.format.annotation.DateTimeFormat; |
|||
|
|||
import javax.validation.constraints.NotNull; |
|||
import javax.validation.constraints.NotBlank; |
|||
|
|||
/** |
|||
* 微信用户关联 实体类 |
|||
* @author YenHex |
|||
* @since 2022-09-13 |
|||
*/ |
|||
@Data |
|||
@TableName("ums_wx_relate") |
|||
public class UmsWxRelate implements Serializable { |
|||
|
|||
private static final long serialVersionUID = 1L; |
|||
|
|||
/** */ |
|||
@TableId(type = IdType.AUTO) |
|||
private Long id; |
|||
|
|||
/** */ |
|||
@NotBlank(message = "不能为空") |
|||
@Length(max = 32,message = "长度不能超过32字") |
|||
private String wxUserId; |
|||
|
|||
/** */ |
|||
@NotNull(message = "不能为空") |
|||
private Long appUserId; |
|||
|
|||
} |
|||
|
@ -1,14 +0,0 @@ |
|||
package com.qs.serve.modules.ums.mapper; |
|||
|
|||
import com.baomidou.mybatisplus.core.mapper.BaseMapper; |
|||
import com.qs.serve.modules.ums.entity.UmsUser; |
|||
|
|||
/** |
|||
* 手机用户 Mapper |
|||
* @author YenHex |
|||
* @date 2022-09-13 |
|||
*/ |
|||
public interface UmsUserMapper extends BaseMapper<UmsUser> { |
|||
|
|||
} |
|||
|
@ -1,14 +0,0 @@ |
|||
package com.qs.serve.modules.ums.mapper; |
|||
|
|||
import com.baomidou.mybatisplus.core.mapper.BaseMapper; |
|||
import com.qs.serve.modules.ums.entity.UmsWxRelate; |
|||
|
|||
/** |
|||
* 微信用户关联 Mapper |
|||
* @author YenHex |
|||
* @date 2022-09-13 |
|||
*/ |
|||
public interface UmsWxRelateMapper extends BaseMapper<UmsWxRelate> { |
|||
|
|||
} |
|||
|
@ -1,36 +0,0 @@ |
|||
package com.qs.serve.modules.ums.service; |
|||
|
|||
import com.baomidou.mybatisplus.extension.service.IService; |
|||
import com.qs.serve.modules.ums.entity.UmsUser; |
|||
import com.qs.serve.modules.wx.entity.WxUser; |
|||
|
|||
/** |
|||
* 手机用户 服务接口 |
|||
* @author YenHex |
|||
* @date 2022-09-13 |
|||
*/ |
|||
public interface UmsUserService extends IService<UmsUser> { |
|||
|
|||
/** |
|||
* 通过微信用户获取App用户 |
|||
* @param wxUserId |
|||
* @param wxUser |
|||
* @return |
|||
*/ |
|||
UmsUser getByWxUserId(String wxUserId,WxUser wxUser); |
|||
|
|||
/** |
|||
* 获取当前app用户 |
|||
* @return |
|||
*/ |
|||
UmsUser getCurrentAppUser(); |
|||
|
|||
/** |
|||
* 创建用户 |
|||
* @param wxUser |
|||
* @return |
|||
*/ |
|||
UmsUser createByWxUser(WxUser wxUser); |
|||
|
|||
} |
|||
|
@ -1,14 +0,0 @@ |
|||
package com.qs.serve.modules.ums.service; |
|||
|
|||
import com.baomidou.mybatisplus.extension.service.IService; |
|||
import com.qs.serve.modules.ums.entity.UmsWxRelate; |
|||
|
|||
/** |
|||
* 微信用户关联 服务接口 |
|||
* @author YenHex |
|||
* @date 2022-09-13 |
|||
*/ |
|||
public interface UmsWxRelateService extends IService<UmsWxRelate> { |
|||
|
|||
} |
|||
|
@ -1,61 +0,0 @@ |
|||
package com.qs.serve.modules.ums.service.impl; |
|||
|
|||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
|||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
|||
import com.qs.serve.common.util.AuthContextUtils; |
|||
import com.qs.serve.modules.ums.entity.UmsWxRelate; |
|||
import com.qs.serve.modules.ums.mapper.UmsWxRelateMapper; |
|||
import com.qs.serve.modules.ums.service.UmsWxRelateService; |
|||
import com.qs.serve.modules.wx.entity.WxUser; |
|||
import lombok.AllArgsConstructor; |
|||
import lombok.extern.slf4j.Slf4j; |
|||
import org.springframework.stereotype.Service; |
|||
import com.qs.serve.modules.ums.entity.UmsUser; |
|||
import com.qs.serve.modules.ums.service.UmsUserService; |
|||
import com.qs.serve.modules.ums.mapper.UmsUserMapper; |
|||
|
|||
/** |
|||
* 手机用户 服务实现类 |
|||
* @author YenHex |
|||
* @since 2022-09-13 |
|||
*/ |
|||
@Slf4j |
|||
@Service |
|||
@AllArgsConstructor |
|||
public class UmsUserServiceImpl extends ServiceImpl<UmsUserMapper,UmsUser> implements UmsUserService { |
|||
|
|||
private final UmsWxRelateService umsWxRelateService; |
|||
|
|||
@Override |
|||
public UmsUser getByWxUserId(String wxUserId,WxUser wxUser) { |
|||
LambdaQueryWrapper<UmsWxRelate> lqwRelate = new LambdaQueryWrapper<>(); |
|||
lqwRelate.eq(UmsWxRelate::getWxUserId,wxUserId); |
|||
UmsWxRelate wxRelate = umsWxRelateService.getOne(lqwRelate,false); |
|||
if(wxRelate!=null){ |
|||
return this.getById(wxRelate.getAppUserId()); |
|||
}else { |
|||
UmsUser umsUser = this.createByWxUser(wxUser); |
|||
wxRelate = new UmsWxRelate(); |
|||
wxRelate.setAppUserId(umsUser.getId()); |
|||
wxRelate.setWxUserId(wxUser.getId()); |
|||
umsWxRelateService.save(wxRelate); |
|||
} |
|||
return null; |
|||
} |
|||
|
|||
@Override |
|||
public UmsUser getCurrentAppUser() { |
|||
return this.getById(AuthContextUtils.getAppUserId()); |
|||
} |
|||
|
|||
@Override |
|||
public UmsUser createByWxUser(WxUser wxUser) { |
|||
UmsUser umsUser = new UmsUser(); |
|||
umsUser.setName(wxUser.getNickName()); |
|||
umsUser.setAvatar(wxUser.getHeadimgUrl()); |
|||
umsUser.setMobile(wxUser.getPhone()); |
|||
this.save(umsUser); |
|||
return umsUser; |
|||
} |
|||
} |
|||
|
@ -1,22 +0,0 @@ |
|||
package com.qs.serve.modules.ums.service.impl; |
|||
|
|||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
|||
import lombok.AllArgsConstructor; |
|||
import lombok.extern.slf4j.Slf4j; |
|||
import org.springframework.stereotype.Service; |
|||
import com.qs.serve.modules.ums.entity.UmsWxRelate; |
|||
import com.qs.serve.modules.ums.service.UmsWxRelateService; |
|||
import com.qs.serve.modules.ums.mapper.UmsWxRelateMapper; |
|||
|
|||
/** |
|||
* 微信用户关联 服务实现类 |
|||
* @author YenHex |
|||
* @since 2022-09-13 |
|||
*/ |
|||
@Slf4j |
|||
@Service |
|||
@AllArgsConstructor |
|||
public class UmsWxRelateServiceImpl extends ServiceImpl<UmsWxRelateMapper,UmsWxRelate> implements UmsWxRelateService { |
|||
|
|||
} |
|||
|
Loading…
Reference in new issue