|
@@ -0,0 +1,135 @@
|
|
|
+package com.xy.service;
|
|
|
+
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
+import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
|
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
+import com.github.yitter.idgen.YitIdHelper;
|
|
|
+import com.xy.annotation.Lock;
|
|
|
+import com.xy.dto.SysWorkUser.AddDto;
|
|
|
+import com.xy.dto.SysWorkUser.UpdateDto;
|
|
|
+import com.xy.dto.UserInfoDto;
|
|
|
+import com.xy.entity.UserInfo;
|
|
|
+import com.xy.mapper.UserInfoMapper;
|
|
|
+import com.xy.utils.*;
|
|
|
+import io.swagger.annotations.Api;
|
|
|
+import io.swagger.annotations.ApiOperation;
|
|
|
+import lombok.AllArgsConstructor;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+import org.springframework.validation.annotation.Validated;
|
|
|
+import org.springframework.web.bind.annotation.PostMapping;
|
|
|
+import org.springframework.web.bind.annotation.RequestBody;
|
|
|
+
|
|
|
+import java.util.List;
|
|
|
+import java.util.StringJoiner;
|
|
|
+
|
|
|
+import static com.xy.utils.Beans.copy;
|
|
|
+import static com.xy.utils.PlusBeans.toIPage;
|
|
|
+import static com.xy.utils.PlusBeans.toPageBean;
|
|
|
+
|
|
|
+
|
|
|
+/**
|
|
|
+ * <p>
|
|
|
+ * 用户表 服务实现类
|
|
|
+ * </p>
|
|
|
+ *
|
|
|
+ * @author lijin
|
|
|
+ * @since 2023-01-12
|
|
|
+ */
|
|
|
+@Service
|
|
|
+@AllArgsConstructor
|
|
|
+@Api(tags = "用户表")
|
|
|
+public class UserInfoServiceImpl extends ServiceImpl<UserInfoMapper, UserInfo> implements UserInfoService {
|
|
|
+
|
|
|
+ private SysWorkUserService sysWorkUserService;
|
|
|
+
|
|
|
+ @PostMapping("obj")
|
|
|
+ @ApiOperation("对象查询")
|
|
|
+ public R<UserInfoDto.Vo> obj(@RequestBody UserInfoDto.Vo vo) {
|
|
|
+ LambdaQueryWrapper<UserInfo> lambdaQueryWrapper = new MybatisPlusQuery().eqWrapper(vo, UserInfo.class)
|
|
|
+ .like(UserInfo::getSysIds, vo.getSysIds())
|
|
|
+ .build();
|
|
|
+ List<UserInfo> list = list(lambdaQueryWrapper);
|
|
|
+ if (Emptys.check(list)) {
|
|
|
+ return R.ok(copy(UserInfoDto.Vo.class, list.get(0)));
|
|
|
+ }
|
|
|
+ return R.ok();
|
|
|
+ }
|
|
|
+
|
|
|
+ @PostMapping("page")
|
|
|
+ @ApiOperation("分页查询")
|
|
|
+ private R<PageBean<UserInfoDto.Vo>> page(@RequestBody UserInfoDto.Page page) {
|
|
|
+ PageBean pageBean = page.getPage();
|
|
|
+ LambdaQueryWrapper<UserInfo> lambdaQueryWrapper = new MybatisPlusQuery().eqWrapper(page, UserInfo.class)
|
|
|
+ .like(UserInfo::getTel, page.getTel())
|
|
|
+ .like(UserInfo::getMail, page.getMail())
|
|
|
+ .like(UserInfo::getUnionid, page.getUnionid())
|
|
|
+ .like(UserInfo::getSysIds, page.getSysIds())
|
|
|
+ .ge(UserInfo::getCreateTime, page.getBeginCreateTime())
|
|
|
+ .le(UserInfo::getCreateTime, page.getEndCreateTime())
|
|
|
+ .build()
|
|
|
+ .orderByDesc(!Emptys.check(pageBean.getOrders()), UserInfo::getCreateTime);
|
|
|
+ IPage<UserInfo> iPage = page(toIPage(pageBean), lambdaQueryWrapper);
|
|
|
+ return R.ok(toPageBean(UserInfoDto.Vo.class, iPage));
|
|
|
+ }
|
|
|
+
|
|
|
+ @PostMapping("save")
|
|
|
+ @ApiOperation("添加")
|
|
|
+ @Lock(value = "save.tel", prefix = "user_save_")
|
|
|
+ public R save(@RequestBody @Validated UserInfoDto.Save save) {
|
|
|
+ //校验
|
|
|
+ UserInfo userInfo = getOne(new LambdaQueryWrapper<UserInfo>()
|
|
|
+ .eq(UserInfo::getTel, save.getTel())
|
|
|
+ .or()
|
|
|
+ .eq(UserInfo::getMail, save.getMail())
|
|
|
+ .or()
|
|
|
+ .eq(UserInfo::getUnionid, save.getUnionid())
|
|
|
+ .or()
|
|
|
+ .eq(UserInfo::getAuthorizeUserId, save.getAuthorizeUserId())
|
|
|
+ );
|
|
|
+ if (userInfo != null) {
|
|
|
+ return R.fail("用户已存在", userInfo);
|
|
|
+ }
|
|
|
+ //添加权限用户
|
|
|
+ AddDto addDto = copy(AddDto.class, save)
|
|
|
+ .setEmail(save.getMail())
|
|
|
+ .setPhone(save.getTel())
|
|
|
+ .setAccount(save.getTel());
|
|
|
+ Long authorizeUserId = sysWorkUserService.register(addDto).getData();
|
|
|
+ if (!Emptys.check(authorizeUserId)) {
|
|
|
+ return R.fail();
|
|
|
+ }
|
|
|
+ //添加用户
|
|
|
+ UserInfo saveInfo = copy(UserInfo.class, save).createUserTime(AuthorizeUtils.getLoginId(Long.class))
|
|
|
+ .setUserId(YitIdHelper.nextId())
|
|
|
+ .setAuthorizeUserId(authorizeUserId)
|
|
|
+ .createUserTime(AuthorizeUtils.getLoginId(Long.class));
|
|
|
+ save(saveInfo);
|
|
|
+ return R.ok();
|
|
|
+ }
|
|
|
+
|
|
|
+ @PostMapping("update")
|
|
|
+ @ApiOperation("修改")
|
|
|
+ @Lock(value = "update.userId", prefix = "user_update_")
|
|
|
+ public R update(@RequestBody @Validated UserInfoDto.Update update) {
|
|
|
+ UserInfo byId = getById(update.getUserId());
|
|
|
+ //系统累加
|
|
|
+ if (Emptys.check(update.getSysIds())) {
|
|
|
+ update.setSysIds(byId.getSysIds().indexOf(update.getSysIds()) == -1 ? new StringJoiner(",").add(byId.getSysIds()).add(update.getSysIds()).toString() : null);
|
|
|
+ }
|
|
|
+ UserInfo updateInfo = copy(UserInfo.class, update).updateUserTime(AuthorizeUtils.getLoginId(Long.class));
|
|
|
+ //修改权限用户
|
|
|
+ if (Emptys.check(update.getTel()) || Emptys.check(update.getMail()) || Emptys.check(update.getStatus()) || Emptys.check(update.getPassword())) {
|
|
|
+ UpdateDto updateDto = new UpdateDto()
|
|
|
+ .setId(byId.getAuthorizeUserId())
|
|
|
+ .setPhone(update.getTel())
|
|
|
+ .setEmail(update.getMail())
|
|
|
+ .setAccount(update.getTel())
|
|
|
+ .setPassword(update.getPassword())
|
|
|
+ .setStatus(update.getStatus());
|
|
|
+ sysWorkUserService.update(updateDto);
|
|
|
+ }
|
|
|
+ //修改用户
|
|
|
+ updateById(updateInfo);
|
|
|
+ return R.ok();
|
|
|
+ }
|
|
|
+}
|