|
@@ -0,0 +1,100 @@
|
|
|
|
|
+package com.ydtech.modules.admin.service.impl;
|
|
|
|
|
+
|
|
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
|
|
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
|
|
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
|
|
+import com.ydtech.exception.SystemException;
|
|
|
|
|
+import com.ydtech.modules.admin.dao.SysPasswordMapper;
|
|
|
|
|
+import com.ydtech.modules.admin.model.SysPassword;
|
|
|
|
|
+import com.ydtech.modules.admin.model.vo.SysPasswordVo;
|
|
|
|
|
+import com.ydtech.modules.admin.service.SysPasswordService;
|
|
|
|
|
+import com.ydtech.modules.order.entity.BasePageResult;
|
|
|
|
|
+import com.ydtech.modules.protocol.utils.AssertionUtils;
|
|
|
|
|
+import com.ydtech.security.utils.PasswordUtils;
|
|
|
|
|
+import com.ydtech.utils.StringUtils;
|
|
|
|
|
+import com.ydtech.utils.idgen.IdGenerate;
|
|
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
|
|
+
|
|
|
|
|
+import javax.annotation.Resource;
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+@Service
|
|
|
|
|
+public class SysPasswordServiceImpl extends ServiceImpl<SysPasswordMapper, SysPassword>
|
|
|
|
|
+ implements SysPasswordService {
|
|
|
|
|
+
|
|
|
|
|
+ @Resource
|
|
|
|
|
+ private SysPasswordService sysPasswordService;
|
|
|
|
|
+
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public void add(SysPassword sysPassword) {
|
|
|
|
|
+ if (!sysPassword.getPassword().equals(sysPassword.getVerifyPassword())) {
|
|
|
|
|
+ throw new SystemException("两次输入的密码不一致");
|
|
|
|
|
+ }
|
|
|
|
|
+ // 检查数据库中是否存在相同的code或name
|
|
|
|
|
+ long count = sysPasswordService.count(new QueryWrapper<SysPassword>()
|
|
|
|
|
+ .eq("code", sysPassword.getCode())
|
|
|
|
|
+ .or()
|
|
|
|
|
+ .eq("name", sysPassword.getName()));
|
|
|
|
|
+ if (count > 0) {
|
|
|
|
|
+ throw new SystemException("已存在相同的编码或功能");
|
|
|
|
|
+ }
|
|
|
|
|
+ SysPassword sysPwd = new SysPassword();
|
|
|
|
|
+ String salt = PasswordUtils.getSalt();
|
|
|
|
|
+ sysPwd.setId(IdGenerate.nextId());
|
|
|
|
|
+ sysPwd.setCode(sysPassword.getCode());
|
|
|
|
|
+ sysPwd.setName(sysPassword.getName());
|
|
|
|
|
+ sysPwd.setSalt(salt);
|
|
|
|
|
+ sysPwd.setPassword(PasswordUtils.encode(sysPassword.getPassword(), salt));
|
|
|
|
|
+ boolean save = save(sysPwd);
|
|
|
|
|
+ AssertionUtils.isSucceed(save, "添加失败");
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public void update(SysPasswordVo sysPasswordVo) {
|
|
|
|
|
+ if (StringUtils.isEmpty(sysPasswordVo.getId())) {
|
|
|
|
|
+ throw new SystemException("ID不能为空");
|
|
|
|
|
+ }
|
|
|
|
|
+ SysPassword sysPwd = sysPasswordService.getById(sysPasswordVo.getId());
|
|
|
|
|
+ if (sysPwd == null) {
|
|
|
|
|
+ throw new SystemException("ID不存在");
|
|
|
|
|
+ }
|
|
|
|
|
+ if (StringUtils.isEmpty(sysPasswordVo.getOriginalPassword())) {
|
|
|
|
|
+ throw new SystemException("原密码不能为空");
|
|
|
|
|
+ }
|
|
|
|
|
+ if (StringUtils.isEmpty(sysPasswordVo.getPassword())) {
|
|
|
|
|
+ throw new SystemException("新密码不能为空");
|
|
|
|
|
+ }
|
|
|
|
|
+ if (!PasswordUtils.matches(sysPwd.getSalt(), sysPasswordVo.getOriginalPassword(), sysPwd.getPassword())) {
|
|
|
|
|
+ throw new SystemException("原密码错误");
|
|
|
|
|
+ }
|
|
|
|
|
+ if (sysPasswordVo.getOriginalPassword().equals(sysPasswordVo.getPassword())) {
|
|
|
|
|
+ throw new SystemException("新密码不能与原密码相同");
|
|
|
|
|
+ }
|
|
|
|
|
+ // 检查数据库中是否存在相同的code或name
|
|
|
|
|
+ long count = sysPasswordService.count(new QueryWrapper<SysPassword>()
|
|
|
|
|
+ .ne("id", sysPasswordVo.getId())
|
|
|
|
|
+ .and(wrapper -> wrapper
|
|
|
|
|
+ .eq("code", sysPasswordVo.getCode())
|
|
|
|
|
+ .or()
|
|
|
|
|
+ .eq("name", sysPasswordVo.getName())));
|
|
|
|
|
+ if (count > 0) {
|
|
|
|
|
+ throw new SystemException("数据库中已存在相同的编码或功能");
|
|
|
|
|
+ }
|
|
|
|
|
+ //密码加密
|
|
|
|
|
+ String pwd = PasswordUtils.encode(sysPasswordVo.getPassword(), sysPwd.getSalt());
|
|
|
|
|
+ sysPwd.setPassword(pwd);
|
|
|
|
|
+ sysPasswordService.updateById(sysPwd);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public BasePageResult<SysPassword> pageQuery(SysPasswordVo sysPasswordVo) {
|
|
|
|
|
+ Page<SysPassword> page = new Page<>(sysPasswordVo.getPageNum(), sysPasswordVo.getPageSize());
|
|
|
|
|
+ LambdaQueryWrapper<SysPassword> wrapper = new LambdaQueryWrapper<>();
|
|
|
|
|
+ wrapper.eq(StringUtils.isNotEmpty(sysPasswordVo.getCode()), SysPassword::getCode, sysPasswordVo.getCode())
|
|
|
|
|
+ .eq(StringUtils.isNotEmpty(sysPasswordVo.getName()), SysPassword::getName, sysPasswordVo.getName());
|
|
|
|
|
+ Page<SysPassword> sysPasswordPage = page(page, wrapper);
|
|
|
|
|
+ return new BasePageResult<>(sysPasswordVo.getPageNum(), page.getSize(), sysPasswordPage.getTotal(), page.getPages(),
|
|
|
|
|
+ sysPasswordPage.getRecords());
|
|
|
|
|
+ }
|
|
|
|
|
+}
|