本文主要是介绍TYC项目开发记录,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
TYC 开发文档
开发需求
- 数据库新增字段,日志表web_log存储查询公司,部门,公司id等字段做时实存储
- 新增数据库表,做消费次数统计
- 查询分页需求,默认自动分页
- 重复调用接口,删除之前所查询公司的信息内容
新增工具
<dependency><groupId>cn.hutool</groupId><artifactId>hutool-all</artifactId><version>5.0.6</version>
</dependency>
HUtoolAPI开发文档
日志信息存储新增内容
- 新增表字段内容
- 代码说明:
- 日志信息监听,获取:
- 项目代码使用AOP切面编程
- @Aspect注解标注切面程序,做日志统一处理。
- @Pointcut注解标注切面的作用范围为所有controller(接口)。
- @Around注解标注为环绕通知。
- 日志信息存储:
Object result = joinPoint.proceed();Signature signature = joinPoint.getSignature();MethodSignature methodSignature = (MethodSignature) signature;Method method = methodSignature.getMethod();if (method.isAnnotationPresent(ApiOperation.class)) {ApiOperation apiOperation = method.getAnnotation(ApiOperation.class);hxWebLog.setDescription(apiOperation.value());}long endTime = System.currentTimeMillis();String urlStr = request.getRequestURL().toString();hxWebLog.setBasePath(StrUtil.removeSuffix(urlStr, URLUtil.url(urlStr).getPath()));hxWebLog.setIp(request.getRemoteAddr());hxWebLog.setMethod(request.getMethod());hxWebLog.setParameter(getParameter(method, joinPoint.getArgs()).toString());hxWebLog.setResult(result.toString());hxWebLog.setSpendTime((int)(endTime - startTime));hxWebLog.setStartTime(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(startTime));hxWebLog.setUri(request.getRequestURI());hxWebLog.setUrl(request.getRequestURL().toString());hxWebLog.setUsername(token);if (StrUtil.isNotBlank(request.getParameter("fileName"))) {hxWebLog.setCompanyName(request.getParameter("fileName"));}if (StrUtil.isNotBlank(request.getParameter("filePathId"))) {hxWebLog.setCompanyId(Integer.parseInt(request.getParameter("filePathId")));}if (StrUtil.isNotBlank(request.getParameter("dept"))) {hxWebLog.setDept(request.getParameter("dept"));}if (StrUtil.isNotBlank(request.getParameter("fillingName"))) {hxWebLog.setFillingName(request.getParameter("fillingName"));}if (StrUtil.isNotBlank(request.getParameter("fillingTime"))) {hxWebLog.setFillingTime(request.getParameter("fillingTime"));}LOGGER.info("{}", JSONUtil.parse(hxWebLog));hxWebLogMapper.insert(hxWebLog);
- 新增储存信息做统一字符串不为空校验(HUTOOL工具类)
消费次数统计
- 数据库新增表
CREATE TABLE [dbo].[hx_api_log] ([uid] bigint IDENTITY(1,1) NOT NULL,[time_stamp] bigint NULL,[open_id] nvarchar(50) COLLATE Chinese_PRC_CI_AS NULL,[url] nvarchar(max) COLLATE Chinese_PRC_CI_AS NULL,[result] nvarchar(max) COLLATE Chinese_PRC_CI_AS NULL,[count] int NULL,CONSTRAINT [PK_hx_api_log] PRIMARY KEY CLUSTERED ([uid])
WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON)
ON [PRIMARY]
)
ON [PRIMARY]
TEXTIMAGE_ON [PRIMARY]
GOALTER TABLE [dbo].[hx_api_log] SET (LOCK_ESCALATION = TABLE)
GO
- 代码说明:
- 消费次数分为无分页,默认有分页两种情况。
@ApiOperation(value = "查询经营异常")@RequestMapping(value = "/api/v1/abnormal", method = RequestMethod.POST)public BaseResult<Map<String, Integer>> saveAbnormal(@RequestParam Long id, @RequestParam String name, @RequestParam(required = false)Integer pageNum) {return ResultUtil.success(abnormalOperationService.saveAbnormal(id, name, pageNum));}
- 根据不叠加冗余的消费次数和代码整体变动内容更改。
if(BeanUtil.isEmpty(pageNum)){// pageNum 为null 查询全部//记录页码int count = 1;while(true){resultMap = getData(id, name, count, paramNum,timeStamp);if(BeanUtil.isNotEmpty(resultMap)){paramNum = resultMap.get("HxTycAbnormalOperation");count +=1;consumptionCount +=1;}else{break;}}if(consumptionCount!=0){hxApiLog.setCount(consumptionCount);hxApiLogMapper.insert(hxApiLog);}}else{//查询指定页码resultMap = getData(id, name, pageNum, paramNum,timeStamp);if(BeanUtil.isNotEmpty(resultMap)){consumptionCount +=1;}else{return resultMap;}hxApiLog.setCount(consumptionCount);hxApiLogMapper.insert(hxApiLog);}
- 所有叠加消费次数,都会根据天眼查所返回的信息是否消费成功来进行叠加。
public static boolean isNotError(String paramStr) {boolean isNotError = true;JSONObject result = JSON.parseObject(paramStr);Integer error_code = result.getInteger("error_code");if (error_code == 0){//throw new BaseException(CodeEnum.SUCCESS, result.toString());if(result.getJSONObject("result").getJSONArray("items") != null){if(BeanUtil.isEmpty(result.getJSONObject("result").getJSONArray("items"))){isNotError = false;}}} else {isNotError = false;}System.out.println(isNotError);return isNotError;}
分页需求,默认自动分页查询全部
- 代码说明:
- 天眼查不提供查询所有页面,做逻辑页码循环,并且记录消费次数
- 根据天眼查返回查询信息作为标识,校验是否数据已经查询完成
- 循环体内,页码叠加,消费次数叠加
二次调用接口,删除之前信息内容
- 代码说明:
- 二次调用信息重复,会产生过多冗余数据,每次调用返回最新数据内容,删除上次数据。
public void delDataBefore(long id,String name ){Map<String,Object> delParam = new HashMap<>();delParam.put("company_id",id);delParam.put("company_name",name);hxTycAbnormalOperationMapper.deleteByMap(delParam);}
这篇关于TYC项目开发记录的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!