负载均衡深度改造,增加分布式锁,表唯一约束等
This commit is contained in:
@@ -6,7 +6,6 @@ import org.quartz.CronExpression;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import tech.easyflow.common.constant.enums.EnumJobStatus;
|
||||
import tech.easyflow.common.domain.Result;
|
||||
import tech.easyflow.common.satoken.util.SaTokenUtil;
|
||||
import tech.easyflow.common.web.controller.BaseCurdController;
|
||||
@@ -38,23 +37,14 @@ public class SysJobController extends BaseCurdController<SysJobService, SysJob>
|
||||
@GetMapping("/start")
|
||||
@SaCheckPermission("/api/v1/sysJob/save")
|
||||
public Result<Void> start(BigInteger id) {
|
||||
SysJob sysJob = service.getById(id);
|
||||
sysJob.setStatus(EnumJobStatus.RUNNING.getCode());
|
||||
service.addJob(sysJob);
|
||||
service.updateById(sysJob);
|
||||
service.startJob(id);
|
||||
return Result.ok();
|
||||
}
|
||||
|
||||
@GetMapping("/stop")
|
||||
@SaCheckPermission("/api/v1/sysJob/save")
|
||||
public Result<Void> stop(BigInteger id) {
|
||||
SysJob sysJob = new SysJob();
|
||||
sysJob.setId(id);
|
||||
sysJob.setStatus(EnumJobStatus.STOP.getCode());
|
||||
ArrayList<Serializable> ids = new ArrayList<>();
|
||||
ids.add(id);
|
||||
service.deleteJob(ids);
|
||||
service.updateById(sysJob);
|
||||
service.stopJob(id);
|
||||
return Result.ok();
|
||||
}
|
||||
|
||||
@@ -88,4 +78,4 @@ public class SysJobController extends BaseCurdController<SysJobService, SysJob>
|
||||
service.deleteJob(ids);
|
||||
return super.onRemoveBefore(ids);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,6 +16,7 @@ import cn.dev33.satoken.stp.StpUtil;
|
||||
import cn.hutool.crypto.digest.BCrypt;
|
||||
import com.mybatisflex.core.paginate.Page;
|
||||
import com.mybatisflex.core.query.QueryWrapper;
|
||||
import org.springframework.dao.DuplicateKeyException;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
@@ -156,4 +157,14 @@ public class SysAccountController extends BaseCurdController<SysAccountService,
|
||||
service.updateById(update);
|
||||
return Result.ok();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@PostMapping("save")
|
||||
public Result<?> save(@JsonBody SysAccount entity) {
|
||||
try {
|
||||
return super.save(entity);
|
||||
} catch (DuplicateKeyException e) {
|
||||
return Result.fail(1, "用户名已存在");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,12 +10,14 @@ import tech.easyflow.common.web.jsonbody.JsonBody;
|
||||
import tech.easyflow.system.entity.SysOption;
|
||||
import tech.easyflow.system.service.SysOptionService;
|
||||
import com.mybatisflex.core.query.QueryWrapper;
|
||||
import org.springframework.dao.DuplicateKeyException;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.math.BigInteger;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
@@ -39,7 +41,10 @@ public class SysOptionController extends BaseController {
|
||||
if (keys == null || keys.length == 0) {
|
||||
return Result.ok(data);
|
||||
}
|
||||
List<SysOption> list = service.list(QueryWrapper.create().in(SysOption::getKey, (Object[]) keys));
|
||||
BigInteger tenantId = SaTokenUtil.getLoginAccount().getTenantId();
|
||||
List<SysOption> list = service.list(QueryWrapper.create()
|
||||
.eq(SysOption::getTenantId, tenantId)
|
||||
.in(SysOption::getKey, (Object[]) keys));
|
||||
for (SysOption sysOption : list) {
|
||||
data.put(sysOption.getKey(), sysOption.getValue());
|
||||
}
|
||||
@@ -62,12 +67,21 @@ public class SysOptionController extends BaseController {
|
||||
if (key == null || key.isEmpty()) {
|
||||
throw new BusinessException("key is empty");
|
||||
}
|
||||
sysOption.setTenantId(SaTokenUtil.getLoginAccount().getTenantId());
|
||||
SysOption record = service.getByOptionKey(key);
|
||||
if (record == null) {
|
||||
service.save(sysOption);
|
||||
} else {
|
||||
BigInteger tenantId = SaTokenUtil.getLoginAccount().getTenantId();
|
||||
sysOption.setTenantId(tenantId);
|
||||
try {
|
||||
SysOption record = service.getByOptionKey(key, tenantId);
|
||||
if (record == null) {
|
||||
service.save(sysOption);
|
||||
} else {
|
||||
QueryWrapper w = QueryWrapper.create();
|
||||
w.eq(SysOption::getTenantId, tenantId);
|
||||
w.eq(SysOption::getKey, key);
|
||||
service.update(sysOption, w);
|
||||
}
|
||||
} catch (DuplicateKeyException e) {
|
||||
QueryWrapper w = QueryWrapper.create();
|
||||
w.eq(SysOption::getTenantId, tenantId);
|
||||
w.eq(SysOption::getKey, key);
|
||||
service.update(sysOption, w);
|
||||
}
|
||||
@@ -79,6 +93,7 @@ public class SysOptionController extends BaseController {
|
||||
if (key == null || key.isEmpty()) {
|
||||
throw new BusinessException("key is empty");
|
||||
}
|
||||
return Result.ok(service.getByOptionKey(key));
|
||||
BigInteger tenantId = SaTokenUtil.getLoginAccount().getTenantId();
|
||||
return Result.ok(service.getByOptionKey(key, tenantId));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user