|
@@ -0,0 +1,110 @@
|
|
|
+package com.usky.dxtop.service.impl;
|
|
|
+
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
+import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
|
+import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
|
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
+
|
|
|
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
+import com.usky.dxtop.common.core.page.CommonPage;
|
|
|
+import com.usky.dxtop.common.exception.CustomException;
|
|
|
+import com.usky.dxtop.common.utils.SecurityUtils;
|
|
|
+import com.usky.dxtop.common.utils.StringUtils;
|
|
|
+import com.usky.dxtop.mapper.AccountLockMapper;
|
|
|
+import com.usky.dxtop.model.AccountLock;
|
|
|
+import com.usky.dxtop.service.AccountLockService;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+
|
|
|
+import java.util.Objects;
|
|
|
+
|
|
|
+/**
|
|
|
+ * <p>
|
|
|
+ * 服务实现类
|
|
|
+ * </p>
|
|
|
+ *
|
|
|
+ * @author ya
|
|
|
+ * @since 2022-04-06
|
|
|
+ */
|
|
|
+@Service
|
|
|
+public class AccountLockServiceImpl extends ServiceImpl<AccountLockMapper, AccountLock> implements AccountLockService {
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Boolean add(AccountLock accountLock) {
|
|
|
+ accountLock.setCreateBy(SecurityUtils.getUsername());
|
|
|
+ if (checkNameUnique(accountLock)){
|
|
|
+ throw new CustomException("名称不能重复");
|
|
|
+ }
|
|
|
+ if (null != accountLock.getIsEnable() && accountLock.getIsEnable()){
|
|
|
+ updateEnable();
|
|
|
+ }
|
|
|
+ return this.save(accountLock);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Boolean update(AccountLock accountLock) {
|
|
|
+ if (checkNameUnique(accountLock)){
|
|
|
+ throw new CustomException("名称不能重复");
|
|
|
+ }
|
|
|
+ if (null != accountLock.getIsEnable() && accountLock.getIsEnable()){
|
|
|
+ updateEnable();
|
|
|
+ }
|
|
|
+ return this.updateById(accountLock);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Boolean checkNameUnique(AccountLock accountLock) {
|
|
|
+ Long id = null == accountLock.getId() ? -1 : accountLock.getId();
|
|
|
+ LambdaQueryWrapper<AccountLock> queryWrapper = Wrappers.lambdaQuery();
|
|
|
+ queryWrapper.eq(AccountLock::getName,accountLock.getName())
|
|
|
+ .eq(AccountLock::getDelFlag,false);
|
|
|
+ AccountLock one = this.getOne(queryWrapper);
|
|
|
+ if (Objects.nonNull(one) && one.getId() != id.longValue())
|
|
|
+ {
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Boolean delete(Long id) {
|
|
|
+ AccountLock byId = this.getById(id);
|
|
|
+ if (byId.getIsEnable()){
|
|
|
+ throw new CustomException("默认开关已打开,关闭后再删除");
|
|
|
+ }
|
|
|
+ AccountLock accountLock = new AccountLock();
|
|
|
+ accountLock.setId(id);
|
|
|
+ accountLock.setDelFlag(true);
|
|
|
+ return this.updateById(accountLock);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public CommonPage<AccountLock> page(Integer current, Integer size, String name) {
|
|
|
+ IPage<AccountLock> page = new Page<>(current, size);
|
|
|
+ LambdaQueryWrapper<AccountLock> queryWrapper = Wrappers.lambdaQuery();
|
|
|
+ queryWrapper
|
|
|
+ .like(StringUtils.isNotBlank(name),AccountLock::getName,name)
|
|
|
+ .eq(AccountLock::getDelFlag,false)
|
|
|
+ .orderByDesc(AccountLock::getId);
|
|
|
+ page = this.page(page,queryWrapper);
|
|
|
+ return new CommonPage<>(page.getRecords(),page.getTotal(),page.getSize(),page.getCurrent());
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public AccountLock isEnableOne() {
|
|
|
+ LambdaQueryWrapper<AccountLock> queryWrapper = Wrappers.lambdaQuery();
|
|
|
+ queryWrapper
|
|
|
+ .eq(AccountLock::getIsEnable,true)
|
|
|
+ .eq(AccountLock::getDelFlag,false);
|
|
|
+ return this.getOne(queryWrapper);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Boolean updateEnable() {
|
|
|
+ AccountLock enableOne = isEnableOne();
|
|
|
+ if (null != enableOne){
|
|
|
+ enableOne.setIsEnable(false);
|
|
|
+ this.updateById(enableOne);
|
|
|
+ }
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+}
|