private Integer isInvoice;
private Integer invoiceStatus;
private String invoiceId;
前言
线上规范的操作。
可以下载一些规范的项目进行参考。
线上问题
部署系统后,多观察有问题的数据;保证数据正常。
https://blog.csdn.net/A_BlackMoon/article/details/117327627
版本更新时必须用SQL语句更新出错的数据;禁止私自写接口更新线上数据,否则新来的人无法理解该接口的操作。
理解设计模式
理解设计模式
数据库
索引
ALTER TABLE d_car_plate_number ADD UNIQUE INDEX(plate_number)
INNODB
外键
软件
1
接口
账户请求入口
https://doc.mandao.com/docs/bct/unionGw
https://www.joinpay.com/open-platform/pages/document.html?apiName=%E8%81%9A%E5%90%88%E6%94%AF%E4%BB%98&id=6
接口命名规范
基础操作CRUD语句,根据mybatis-plus的原有格式封装,只有一条语句,而且其他接口也尽量命名保持一致,入订单、商品、库存都用deleteOne语句标识删除一条记录。其他的业务删除都不能单独使用该命名,可以用描述型接口名称。
findListPage 分页查询
findListAll 查询所有
findOne 单一查询,单表实体类,查主表
findDetail 单一查询,单表详情数据
接口参数
关键字 searchKeywords
接口null判断
要加 “null”.equals(orderNo)
list 接收参数
wechatUserList.get(0).getId();
写成
WechatUser wechatUser = wechatUserList.get(0);
wechatUser.getId();
boolean 参数在Service端传递 接口只需 if(result){ return “ok” }
登录
拦截器
静态资源的过滤,白名单
//忽略部分接口请求安全检查,方法级注解
HandlerMethod handlerMethod = (HandlerMethod) handler;
Method method = handlerMethod.getMethod();
if(method.isAnnotationPresent(IgnoreSecurity.class)){
return true;
}
关于Token JWT
if(JwtUtils.isExpired(token)){
redisService.delUserInfoByToken(token);
response.getWriter().print(JSONObject.toJSONString(Res.fail(ResEntity.Err.TOKEN_EXPIRED)));
return false;
}
缓存用户基本信息
redis
接口参数注入 HandlerMethodArgumentResolver
缓存用户基本信息,没有则从数据库中获取
创建CurrentUserArgumentResolver
public class CurrentUserMethodArgumentResolver implements HandlerMethodArgumentResolver {
@Override
public boolean supportsParameter(MethodParameter parameter) {
return parameter.getParameterAnnotation(CurrentUser.class) != null && parameter.getParameterType() == com.java.dcompany.pojo.MerchantEmp.class;
}
@Override
public Object resolveArgument(MethodParameter parameter, ModelAndViewContainer mavContainer, NativeWebRequest webRequest, WebDataBinderFactory binderFactory) throws Exception {
HttpServletRequest request = (HttpServletRequest) webRequest.getNativeRequest();//注入参数值
return request.getAttribute("currentUser");
}
}
在拦截器中设置 request.setAttribute("currentUser", userInfo);
String userId = redisService.getKey(token);
if(userId == null){
redisService.delUserInfoByToken(token);
response.getWriter().print(JSONObject.toJSONString(Res.fail(ResEntity.Err.TOKEN_EXPIRED)));
return false;
}
SysUser userInfo = redisService.getUserInfo(userId);
if(userInfo == null){
userInfo = userService.findOne(userId); // 从数据库中获取
if(userInfo == null){
response.getWriter().print(JSONObject.toJSONString(Res.fail(ResEntity.Err.TOKEN_EXPIRED)));
return false;
}
redisService.setUserInfo(userInfo);
}
request.setAttribute("currentUser", userInfo);
Controller
参数
方法传参中,多个参数之间要有空格。
id 和 orderId
参数尽量保持一致,方便回参。
BeanUtils.copyProperties(obj, vo) ,否则id 和 orderId 中间要转换一下
父表 nameCertifiedRuleDefault 和子表 nameCertifiedRule
返回实体
接口返回值中Long类型超过17位导致前端js在调用时出现丢失精度问题
字段要紧挨着:userType userTypeName
字段根据重要放置在前:
VO
接口中 Entity、POJO 和 VO分开
查询实体类数据后,返回的是VO数据,VO可以包含自定义的数据。
不使用Map处理VO数据。
返回参数要全部写到实体VO
/**
* 保存更新用户信息
*
* @param currentUser
* @param sysUser SysUser 设置用户信息
* @return
*/
@PostMapping("/updateUser")
public ResEntity addUser(SysUser sysUser) {
User u = userService.findOneById(sysUser.getId());
if (u == null) {
u = new User();
u .setCreateUser(sysUser.getId());
u add = userService.add(u);
if (!add) {
return Res.fail("设置失败");
}
}
u.setUpdateUser(currentUser.getId());
boolean update = occupyRuleService.update(occupyRule);
if (!update) {
return Res.fail("设置失败");
}
UserVo vo = new UserVo();
vo.setId(rule1.getId());
return Res.ok("设置成功", vo);
}
tips: 返回参数要全部写到实体VO——因为如果是返回字符串devId1,devId2字符串这种,返回接口会显示msg上,除非是ResEntity返回完整的消息 return Res.ok(ResEntity.Err.SUCCESS, "设置成功", vo)
才可以
日志记录
日志记录和功能操作记录的区别:操作记录应该只有成功时才记录。
/**
* 卡作废
*
* @param param
* @return ResponseResult
*/
@PostMapping("/setCardRepeal")
@Operation(summary = "卡作废")
@SaCheckEOPPermission(value = "monthlycar:monthlycarCard:edit")
@NoRepeatSubmit
@ApiResponse(responseCode = "200", description = "操作成功")
//@Log(title = "monthlycar", speL = "#param.id", businessType = BusinessType.UPDATE)
public ResponseResult<?> setCardRepeal(@RequestBody Card param) {
return api.setCardRepeal(param.getCardNo());
}
账户管理
accountId | accountName | bankName | dispositBankName | bankCardNo | userId |
---|---|---|---|---|---|
账户id | 账户名称 | 银行名称 | 开户行 | 银行卡卡号 | 用户id |