diff --git a/src/main/java/vip/fuck/sm/common/exception/handler/AppFilter.java b/src/main/java/vip/fuck/sm/common/exception/handler/AppFilter.java index 11d247f..065bf97 100644 --- a/src/main/java/vip/fuck/sm/common/exception/handler/AppFilter.java +++ b/src/main/java/vip/fuck/sm/common/exception/handler/AppFilter.java @@ -2,6 +2,7 @@ package vip.fuck.sm.common.exception.handler; import cn.dev33.satoken.exception.NotLoginException; import cn.dev33.satoken.exception.NotPermissionException; +import org.apache.ibatis.exceptions.PersistenceException; import vip.fuck.sm.common.exception.BusinessException; import vip.fuck.sm.common.exception.code.BaseResponseCode; import vip.fuck.sm.common.utils.DataResult; @@ -12,36 +13,64 @@ import org.noear.solon.core.handle.*; import org.noear.solon.validation.ValidatorException; import org.thymeleaf.exceptions.TemplateEngineException; +import java.sql.SQLIntegrityConstraintViolationException; + @Component(index = 0) //index 为顺序位(不加,则默认为0) @Slf4j public class AppFilter implements Filter { @Override public void doFilter(Context ctx, FilterChain chain) throws Throwable { + String pathNew = ctx.pathNew(); try { chain.doFilter(ctx); } catch (NotLoginException e){ ctx.redirect("/index/login"); + return; } catch (NotPermissionException e){ ctx.redirect("/index/403"); + return; }catch (ValidatorException e) { ctx.render(DataResult.getResult( BaseResponseCode.METHODARGUMENTNOTVALIDEXCEPTION.getCode(), e.getMessage())); + return; }catch (BusinessException e){ ctx.render(new DataResult(e.getMessageCode(), e.getDetailMessage(),e.getThrowable(),null)); - } catch (StatusException e){ - ctx.status(e.getCode()); - if (e.getCode() == 404){ - String pathNew = ctx.pathNew(); - log.error("404:{}",pathNew); - ctx.redirect("/index/404"); - } else { - ctx.redirect("/index/500"); - } + return; } catch (TemplateEngineException e){ ctx.render(" /** 【页面异常】 **/"); + return; } catch (Throwable e) { + if ( e instanceof StatusException){ + StatusException se = (StatusException) e; + ctx.status(se.getCode()); + if (se.getCode() == 400){ + log.error("400:{}",pathNew); + ctx.status(200); + ctx.render(new DataResult(BaseResponseCode.DATA_ERROR.getCode(), "参数错误", null,null)); + return; + }else if (se.getCode() == 404){ + log.error("404:{}",pathNew); + ctx.redirect("/index/404"); + return; + } else if (se.getCode() == 403){ + log.error("403:{}",pathNew); + ctx.redirect("/index/404"); + return; + } else if(se.getCode() == 500){ + log.error("500:{}",pathNew); + ctx.redirect("/index/500"); + return; + } + } + if(e instanceof PersistenceException){ + if(e.getMessage().contains("java.sql.SQLIntegrityConstraintViolationException: Duplicate entry")){ + ctx.render(new DataResult(BaseResponseCode.OPERATION_ERRO.getCode(), "数据重复",e,null)); + return; + } + } log.error(e.getMessage(),e); + ctx.status(500); ctx.render(DataResult.getResult(BaseResponseCode.SYSTEM_BUSY)); } } diff --git a/src/main/java/vip/fuck/sm/controller/SysPlugsController.java b/src/main/java/vip/fuck/sm/controller/SysPlugsController.java index 9b8b8f1..48ec233 100644 --- a/src/main/java/vip/fuck/sm/controller/SysPlugsController.java +++ b/src/main/java/vip/fuck/sm/controller/SysPlugsController.java @@ -1,5 +1,6 @@ package vip.fuck.sm.controller; +import cn.hutool.core.util.ObjectUtil; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.toolkit.Wrappers; import cn.dev33.satoken.annotation.SaCheckPermission; @@ -46,12 +47,28 @@ public class SysPlugsController { @ApiOperation(value = "查询分页数据") @Post @Mapping ("sysPlugs/listByPage") @SaCheckPermission("sysPlugs:list") - public DataResult findListByPage( SysPlugsEntity sysPlugs){ - LambdaQueryWrapper queryWrapper = Wrappers.lambdaQuery(); - //查询条件示例 - queryWrapper.eq(sysPlugs.getQualifiedVersion() != null, SysPlugsEntity::getQualifiedVersion, sysPlugs.getQualifiedVersion()); - queryWrapper.orderByDesc(SysPlugsEntity::getQualifiedVersion); - IPage iPage = sysPlugsService.page(sysPlugs.getQueryPage(), queryWrapper); + public DataResult findListByPage(SysPlugsEntity sysPlugs ,String key){ + LambdaQueryWrapper q = Wrappers.lambdaQuery(); + if(ObjectUtil.isNotEmpty(key)){ + q.or(qq->{ + qq.like(SysPlugsEntity::getQualifiedVersion,key); + }); + q.or(qq->{ + qq.like(SysPlugsEntity::getAuthor,key); + }); + q.or(qq->{ + qq.like(SysPlugsEntity::getVersion,key); + }); + q.or(qq->{ + qq.like(SysPlugsEntity::getDescription,key); + }); + }else{ + //查询条件示例 + q.eq(sysPlugs.getQualifiedVersion() != null, SysPlugsEntity::getQualifiedVersion, sysPlugs.getQualifiedVersion()); + } + + q.orderByDesc(SysPlugsEntity::getQualifiedVersion); + IPage iPage = sysPlugsService.page(sysPlugs.getQueryPage(), q); return DataResult.success(iPage); } diff --git a/src/main/java/vip/fuck/sm/entity/SysPlugsEntity.java b/src/main/java/vip/fuck/sm/entity/SysPlugsEntity.java index b434051..f777312 100644 --- a/src/main/java/vip/fuck/sm/entity/SysPlugsEntity.java +++ b/src/main/java/vip/fuck/sm/entity/SysPlugsEntity.java @@ -1,10 +1,8 @@ package vip.fuck.sm.entity; -import com.baomidou.mybatisplus.annotation.TableId; -import com.baomidou.mybatisplus.annotation.TableName; -import com.baomidou.mybatisplus.annotation.TableField; +import com.baomidou.mybatisplus.annotation.*; import vip.fuck.sm.entity.BasePageEntity; -import com.baomidou.mybatisplus.annotation.FieldFill; + import java.util.Date; import java.io.Serializable; @@ -25,7 +23,7 @@ public class SysPlugsEntity extends BasePageEntity implements Serializable { /** * 全限版本 */ - @TableId("qualified_version") + @TableId(value = "qualified_version",type = IdType.INPUT) private String qualifiedVersion; /** diff --git a/src/main/resources/static/js/core.util.js b/src/main/resources/static/js/core.util.js index 8571f98..fe917c1 100644 --- a/src/main/resources/static/js/core.util.js +++ b/src/main/resources/static/js/core.util.js @@ -37,15 +37,15 @@ var CoreUtil = (function () { }, success: function (res) { top.layer.close(loadIndex); - if (res.code==0){ - if(ft!=null&&ft!=undefined){ + if (res.code===0){ + if(typeof ft === 'function'){ ft(res); } - }else if(res.code==401001){ //凭证过期重新登录 + }else if(res.code===401001){ //凭证过期重新登录 layer.msg("凭证过期请重新登录", {time:2000}, function () { top.window.location.href=ctx + "index/login" }) - }else if(res.code==401008){ //凭证过期重新登录 + }else if(res.code===401008){ //凭证过期重新登录 layer.msg("抱歉!您暂无权限", {time:2000}) } else { layer.msg(res.msg); @@ -53,8 +53,10 @@ var CoreUtil = (function () { }, error:function (XMLHttpRequest, textStatus, errorThrown) { top.layer.close(loadIndex); - if(XMLHttpRequest.status==404){ + if(XMLHttpRequest.status===404){ top.window.location.href= ctx + "index/404"; + }else if(XMLHttpRequest.status === 400){ + layer.msg("参数错误,请检查"); }else{ layer.msg("服务器好像除了点问题!请稍后试试"); } diff --git a/src/main/resources/template/list.html.vm b/src/main/resources/template/list.html.vm index 16f480d..176bd7c 100644 --- a/src/main/resources/template/list.html.vm +++ b/src/main/resources/template/list.html.vm @@ -118,9 +118,9 @@ $(".title").html("新增"); setTimeout(function () { form.val('info', { - "test": "test" + "test": null #foreach($column in $htmlColumns) - , "${column.attrname}": "" + , "${column.attrname}": null #end }); }, 200); @@ -208,7 +208,7 @@ $(".title").html("查看"); setTimeout(function () { form.val('info', { - "test": "test" + "test": null #foreach($column in $htmlColumns) , "${column.attrname}": data.${column.attrname} #end diff --git a/src/main/resources/templates/sysplugs/list.html b/src/main/resources/templates/sysplugs/list.html index d7e58e0..dd37338 100644 --- a/src/main/resources/templates/sysplugs/list.html +++ b/src/main/resources/templates/sysplugs/list.html @@ -11,7 +11,12 @@
- +
+ +
+ +
+