|
|
@@ -24,12 +24,13 @@ import java.lang.reflect.ParameterizedType;
|
|
|
import java.util.Date;
|
|
|
import java.util.List;
|
|
|
import java.util.UUID;
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
|
|
public abstract class BaseService<T> extends ServiceImpl<com.baomidou.mybatisplus.core.mapper.BaseMapper<T>, T> {
|
|
|
|
|
|
public abstract BaseMapper<T> getRepository();
|
|
|
|
|
|
- public String getPrimaryKey(){
|
|
|
+ public String getPrimaryKey() {
|
|
|
return "id";
|
|
|
}
|
|
|
|
|
|
@@ -112,6 +113,42 @@ public abstract class BaseService<T> extends ServiceImpl<com.baomidou.mybatisplu
|
|
|
@Transactional(
|
|
|
rollbackFor = {Exception.class}
|
|
|
)
|
|
|
+ public ResponseResultVO<Boolean> disableBatch(List<String> ids) {
|
|
|
+ List<UUID> uuidList = ids.stream()
|
|
|
+ .map(s -> {
|
|
|
+ try {
|
|
|
+ return UUID.fromString(s);
|
|
|
+ } catch (IllegalArgumentException e) {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ })
|
|
|
+ .collect(Collectors.toList());
|
|
|
+ return super.update(new UpdateWrapper<T>().set(String.valueOf(PojoConfig.VALUES.get("validKey")), PojoConfig.VALUES.get("unValid")).in(getPrimaryKey(), uuidList).eq(String.valueOf(PojoConfig.VALUES.get("validKey")), PojoConfig.VALUES.get("isValid"))) ?
|
|
|
+ ResponseResultUtil.success() : ResponseResultUtil.error(ResponseCodeEnum.DISABLE_FAIL);
|
|
|
+// return ResponseResultUtil.success(SqlHelper.retBool(getRepository().disableBatch(ids)));
|
|
|
+ }
|
|
|
+
|
|
|
+ @Transactional(
|
|
|
+ rollbackFor = {Exception.class}
|
|
|
+ )
|
|
|
+ public ResponseResultVO<Boolean> enableBatch(List<String> ids) {
|
|
|
+ List<UUID> uuidList = ids.stream()
|
|
|
+ .map(s -> {
|
|
|
+ try {
|
|
|
+ return UUID.fromString(s);
|
|
|
+ } catch (IllegalArgumentException e) {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ })
|
|
|
+ .collect(Collectors.toList());
|
|
|
+ return super.update(new UpdateWrapper<T>().set(String.valueOf(PojoConfig.VALUES.get("validKey")), PojoConfig.VALUES.get("unValid")).in(getPrimaryKey(), uuidList).eq(String.valueOf(PojoConfig.VALUES.get("validKey")), PojoConfig.VALUES.get("isValid"))) ?
|
|
|
+ ResponseResultUtil.success() : ResponseResultUtil.error(ResponseCodeEnum.ENABLE_FAIL);
|
|
|
+// return ResponseResultUtil.success(SqlHelper.retBool(getRepository().disableBatch(ids)));
|
|
|
+ }
|
|
|
+
|
|
|
+ @Transactional(
|
|
|
+ rollbackFor = {Exception.class}
|
|
|
+ )
|
|
|
public ResponseResultVO<Boolean> insertBatch(List<T> list) {
|
|
|
// boolean flag = saveBatch(list);
|
|
|
// if (flag) {
|
|
|
@@ -130,9 +167,9 @@ public abstract class BaseService<T> extends ServiceImpl<com.baomidou.mybatisplu
|
|
|
result += getRepository().insertBatch(list.subList(start, end));
|
|
|
start = end;
|
|
|
if (end + 200 > size) {
|
|
|
- end=size;
|
|
|
+ end = size;
|
|
|
} else {
|
|
|
- end+=200;
|
|
|
+ end += 200;
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
@@ -201,24 +238,6 @@ public abstract class BaseService<T> extends ServiceImpl<com.baomidou.mybatisplu
|
|
|
@Transactional(
|
|
|
rollbackFor = {Exception.class}
|
|
|
)
|
|
|
- public ResponseResultVO<Boolean> disableBatch(List<Long> ids) {
|
|
|
- return super.update(new UpdateWrapper<T>().set(String.valueOf(PojoConfig.VALUES.get("validKey")), PojoConfig.VALUES.get("unValid")).in(getPrimaryKey(), ids).eq(String.valueOf(PojoConfig.VALUES.get("validKey")), PojoConfig.VALUES.get("isValid"))) ?
|
|
|
- ResponseResultUtil.success() : ResponseResultUtil.error(ResponseCodeEnum.DISABLE_FAIL);
|
|
|
-// return ResponseResultUtil.success(SqlHelper.retBool(getRepository().disableBatch(ids)));
|
|
|
- }
|
|
|
-
|
|
|
- @Transactional(
|
|
|
- rollbackFor = {Exception.class}
|
|
|
- )
|
|
|
- public ResponseResultVO<Boolean> enableBatch(List<Long> ids) {
|
|
|
- return super.update(new UpdateWrapper<T>().set(String.valueOf(PojoConfig.VALUES.get("validKey")), PojoConfig.VALUES.get("isValid")).in(getPrimaryKey(), ids).eq(String.valueOf(PojoConfig.VALUES.get("validKey")), PojoConfig.VALUES.get("unValid"))) ?
|
|
|
- ResponseResultUtil.success() : ResponseResultUtil.error(ResponseCodeEnum.ENABLE_FAIL);
|
|
|
-// return ResponseResultUtil.success(SqlHelper.retBool(getRepository().enableBatch(ids)));
|
|
|
- }
|
|
|
-
|
|
|
- @Transactional(
|
|
|
- rollbackFor = {Exception.class}
|
|
|
- )
|
|
|
public ResponseResultVO<Boolean> importList(List<T> list) {
|
|
|
return this.insertBatch(list);
|
|
|
}
|
|
|
@@ -261,8 +280,8 @@ public abstract class BaseService<T> extends ServiceImpl<com.baomidou.mybatisplu
|
|
|
return ResponseResultUtil.success(pageList);
|
|
|
}
|
|
|
|
|
|
- public <Res>ResponseResultVO<PageList <Res>> mergeListWithCount(Object object, List list, Long total) {
|
|
|
- PageList <Res> pageList = new PageList(list, total);
|
|
|
+ public <Res> ResponseResultVO<PageList<Res>> mergeListWithCount(Object object, List list, Long total) {
|
|
|
+ PageList<Res> pageList = new PageList(list, total);
|
|
|
if (object instanceof PageInfo && ((PageInfo) object).getPageSize() != null && ((PageInfo) object).getPageSize() != 0 &&
|
|
|
((PageInfo) object).getCurrentPage() != null && ((PageInfo) object).getCurrentPage() != 0) {
|
|
|
pageList.setPageSize(((PageInfo) object).getPageSize()).setCurrentPage(((PageInfo) object).getCurrentPage());
|
|
|
@@ -330,12 +349,12 @@ public abstract class BaseService<T> extends ServiceImpl<com.baomidou.mybatisplu
|
|
|
* @return com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper<T>
|
|
|
* @author H_x_d
|
|
|
*/
|
|
|
- private UpdateWrapper<T> getUpdateWrapperWhenUpdate(JSONObject jsonObject, String pk){
|
|
|
+ private UpdateWrapper<T> getUpdateWrapperWhenUpdate(JSONObject jsonObject, String pk) {
|
|
|
UpdateWrapper<T> updateWrapper = new UpdateWrapper<T>().eq(getPrimaryKey(), jsonObject.get(pk));
|
|
|
//是否有删除标识字段
|
|
|
Class<T> entityClass = (Class<T>) ((ParameterizedType) getClass().getGenericSuperclass()).getActualTypeArguments()[0];
|
|
|
DeleteFlag deleteFlag = entityClass.getAnnotation(DeleteFlag.class);
|
|
|
- if (deleteFlag !=null && deleteFlag.value()) {
|
|
|
+ if (deleteFlag != null && deleteFlag.value()) {
|
|
|
updateWrapper.ne(String.valueOf(PojoConfig.VALUES.get("deleteKey")), PojoConfig.VALUES.get("isDelete"));
|
|
|
}
|
|
|
return updateWrapper;
|
|
|
@@ -350,13 +369,13 @@ public abstract class BaseService<T> extends ServiceImpl<com.baomidou.mybatisplu
|
|
|
* @return com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper<T>
|
|
|
* @author H_x_d
|
|
|
*/
|
|
|
- private UpdateWrapper<T> getUpdateWrapperWhenUpdateUuid(JSONObject jsonObject, String pk){
|
|
|
+ private UpdateWrapper<T> getUpdateWrapperWhenUpdateUuid(JSONObject jsonObject, String pk) {
|
|
|
UUID uuid = UUID.fromString(jsonObject.get(pk).toString());
|
|
|
UpdateWrapper<T> updateWrapper = new UpdateWrapper<T>().eq(getPrimaryKey(), uuid);
|
|
|
//是否有删除标识字段
|
|
|
Class<T> entityClass = (Class<T>) ((ParameterizedType) getClass().getGenericSuperclass()).getActualTypeArguments()[0];
|
|
|
DeleteFlag deleteFlag = entityClass.getAnnotation(DeleteFlag.class);
|
|
|
- if (deleteFlag !=null && deleteFlag.value()) {
|
|
|
+ if (deleteFlag != null && deleteFlag.value()) {
|
|
|
updateWrapper.ne(String.valueOf(PojoConfig.VALUES.get("deleteKey")), PojoConfig.VALUES.get("isDelete"));
|
|
|
}
|
|
|
return updateWrapper;
|