|
|
@@ -64,6 +64,25 @@ public abstract class BaseService<T> extends ServiceImpl<com.baomidou.mybatisplu
|
|
|
@Transactional(
|
|
|
rollbackFor = {Exception.class}
|
|
|
)
|
|
|
+ public ResponseResultVO<Boolean> updateByUuid(T t) {
|
|
|
+ if (t != null) {
|
|
|
+ JSONObject jsonObject = JSONObject.parseObject(JSONObject.toJSONString(t));
|
|
|
+ String pk = getPrimaryKey();
|
|
|
+ if (pk.contains("_")) {
|
|
|
+ //下划线转驼峰
|
|
|
+ pk = CaseFormat.UPPER_UNDERSCORE.to(CaseFormat.LOWER_CAMEL, getPrimaryKey());
|
|
|
+ }
|
|
|
+ if (jsonObject != null && jsonObject.get(pk) != null) {
|
|
|
+ return super.update(t, getUpdateWrapperWhenUpdateUuid(jsonObject, pk)) ?
|
|
|
+ ResponseResultUtil.success() : ResponseResultUtil.error(ResponseCodeEnum.UPDATE_FAIL);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return ResponseResultUtil.error(ResponseCodeEnum.UPDATE_FAIL);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Transactional(
|
|
|
+ rollbackFor = {Exception.class}
|
|
|
+ )
|
|
|
public ResponseResultVO<Boolean> delete(Long id) {
|
|
|
return super.update(new UpdateWrapper<T>().set(String.valueOf(PojoConfig.VALUES.get("deleteKey")), PojoConfig.VALUES.get("isDelete")).eq(getPrimaryKey(), id)) ?
|
|
|
ResponseResultUtil.success() : ResponseResultUtil.error(ResponseCodeEnum.DELETE_FAIL);
|
|
|
@@ -321,4 +340,25 @@ public abstract class BaseService<T> extends ServiceImpl<com.baomidou.mybatisplu
|
|
|
}
|
|
|
return updateWrapper;
|
|
|
}
|
|
|
+
|
|
|
+ /**
|
|
|
+ * <b>
|
|
|
+ * description: 获取修改时的修改参数
|
|
|
+ * </b><p>
|
|
|
+ * date_time: 2022-03-07 11:32
|
|
|
+ *
|
|
|
+ * @return com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper<T>
|
|
|
+ * @author H_x_d
|
|
|
+ */
|
|
|
+ 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()) {
|
|
|
+ updateWrapper.ne(String.valueOf(PojoConfig.VALUES.get("deleteKey")), PojoConfig.VALUES.get("isDelete"));
|
|
|
+ }
|
|
|
+ return updateWrapper;
|
|
|
+ }
|
|
|
}
|