فهرست منبع

@Dict注解不生效:1-添加注解的切点;2-只在返回类型为IPage时生效,添加返回类型为pageInfo时注解同样生效.

yangzian 4 سال پیش
والد
کامیت
84946416b7

+ 40 - 2
jeecg-boot-base/jeecg-boot-base-core/src/main/java/org/jeecg/common/aspect/DictAspect.java

@@ -5,6 +5,7 @@ import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.fasterxml.jackson.annotation.JsonFormat;
 import com.fasterxml.jackson.core.JsonProcessingException;
 import com.fasterxml.jackson.databind.ObjectMapper;
+import com.github.pagehelper.PageInfo;
 import lombok.extern.slf4j.Slf4j;
 import org.aspectj.lang.ProceedingJoinPoint;
 import org.aspectj.lang.annotation.Around;
@@ -42,7 +43,7 @@ public class DictAspect {
     /**
      * 定义切点Pointcut
      */
-    @Pointcut("execution(public * org.jeecg.modules..*.*Controller.*(..))||execution(public * cn.com.ctop..*.*Controller.*(..))||execution(public * ctop.bytedane.ad..*.*Controller.*(..))")
+    @Pointcut("execution(public * org.jeecg.modules..*.*Controller.*(..))||execution(public * ctop.bytedance.ad..*.*Controller.*(..)) ||execution(public * org.jeecg.ctop.finance..*.*Controller.*(..))")
     public void excudeService() {
     }
 
@@ -128,8 +129,45 @@ public class DictAspect {
                     items.add(item);
                 }
                 ((IPage) ((Result) result).getResult()).setRecords(items);
+            }else{
+                //返回类型为 pageInfo  list
+               /* if (((Result) result).getResult() instanceof List) {
+                    return;
+                }*/
+                List<JSONObject> items = new ArrayList<>();
+                for (Object record : ((Result<PageInfo>) result).getResult().getList()){
+                    ObjectMapper mapper = new ObjectMapper();
+                    String json="{}";
+                    try {
+                        //解决@JsonFormat注解解析不了的问题详见SysAnnouncement类的@JsonFormat
+                        json = mapper.writeValueAsString(record);
+                    } catch (JsonProcessingException e) {
+                        log.error("json解析失败"+e.getMessage(),e);
+                    }
+                    JSONObject item = JSONObject.parseObject(json);
+                    //for (Field field : record.getClass().getDeclaredFields()) {
+                    for (Field field : oConvertUtils.getAllFields(record)) {
+                        if (field.getAnnotation(Dict.class) != null) {
+                            String code = field.getAnnotation(Dict.class).dicCode();
+                            String text = field.getAnnotation(Dict.class).dicText();
+                            String table = field.getAnnotation(Dict.class).dictTable();
+                            String key = String.valueOf(item.get(field.getName()));
+                            //翻译字典值对应的txt
+                            String textValue = translateDictValue(code, text, table, key,null,null);
+                            log.debug(" 字典Val : "+ textValue);
+                            log.debug(" __翻译字典字段__ "+field.getName() + CommonConstant.DICT_TEXT_SUFFIX+": "+ textValue);
+                            item.put(field.getName() + CommonConstant.DICT_TEXT_SUFFIX, textValue);
+                        }
+                        //date类型默认转换string格式化日期
+                        if (field.getType().getName().equals("java.util.Date")&&field.getAnnotation(JsonFormat.class)==null&&item.get(field.getName())!=null){
+                            SimpleDateFormat aDate=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
+                            item.put(field.getName(), aDate.format(new Date((Long) item.get(field.getName()))));
+                        }
+                    }
+                    items.add(item);
+                }
+                ((Result) result).setResult(items);
             }
-
         }
     }
 

+ 63 - 0
jeecg-boot-finance/src/main/java/org/jeecg/ctop/finance/policy/controller/DemoController.java

@@ -1,13 +1,27 @@
 package org.jeecg.ctop.finance.policy.controller;
 
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
+import com.baomidou.mybatisplus.core.metadata.IPage;
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
+import com.github.pagehelper.PageHelper;
+import com.github.pagehelper.PageInfo;
 import io.swagger.annotations.Api;
 import io.swagger.annotations.ApiOperation;
 import lombok.extern.slf4j.Slf4j;
+import org.jeecg.common.api.vo.Result;
+import org.jeecg.common.system.query.QueryGenerator;
+import org.jeecg.ctop.finance.settlement.entity.pojo.ctopCwjsSettlementInfo;
+import org.jeecg.ctop.finance.settlement.service.ISettlementInfoService;
+import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.web.bind.annotation.GetMapping;
 import org.springframework.web.bind.annotation.RequestMapping;
 
+import org.springframework.web.bind.annotation.RequestParam;
 import org.springframework.web.bind.annotation.RestController;
 
+import javax.servlet.http.HttpServletRequest;
+import java.util.List;
+
 /**
  *
  * @description: demo
@@ -21,6 +35,11 @@ import org.springframework.web.bind.annotation.RestController;
 @Slf4j
 public class DemoController {
 
+
+    @Autowired
+    private ISettlementInfoService settlementInfoService;
+
+
     @ApiOperation(value="demo", notes="demo")
     @GetMapping(value = "/demo")
     public String queryPageList() {
@@ -29,4 +48,48 @@ public class DemoController {
     }
 
 
+
+    /**
+     * @description:测试 注解 @Dict  返回类型 为 IPage
+     *
+     * @return: org.jeecg.common.api.vo.Result<com.baomidou.mybatisplus.core.metadata.IPage<org.jeecg.ctop.finance.settlement.entity.pojo.ctopCwjsSettlementInfo>>
+     * @author: zianY
+     * @time: 2021/7/28 18:36
+     */
+    @ApiOperation(value="test", notes="test")
+    @GetMapping(value = "/test")
+    public Result<IPage<ctopCwjsSettlementInfo>> test(ctopCwjsSettlementInfo SettlementInfoPojo,
+                                                      @RequestParam(name="pageNo", defaultValue="1") Integer pageNo,
+                                                      @RequestParam(name="pageSize", defaultValue="10") Integer pageSize,
+                                                      HttpServletRequest req) {
+        QueryWrapper<ctopCwjsSettlementInfo> queryWrapper = QueryGenerator.initQueryWrapper(SettlementInfoPojo, req.getParameterMap());
+        Page<ctopCwjsSettlementInfo> page = new Page<>(pageNo, pageSize);
+        IPage<ctopCwjsSettlementInfo> list = settlementInfoService.page(page, queryWrapper);
+        return Result.successMsg("chenggong.",list);
+    }
+
+
+    /**
+     *
+     * @description:  注解 @Dict 返回类型 为 PageInfo
+
+     * @return: org.jeecg.common.api.vo.Result<com.github.pagehelper.PageInfo<org.jeecg.ctop.finance.settlement.entity.pojo.ctopCwjsSettlementInfo>>
+     * @author: zianY
+     * @time: 2021/7/28 20:35
+     */
+    @ApiOperation(value="test2", notes="test2")
+    @GetMapping(value = "/test2")
+    public Result<PageInfo<ctopCwjsSettlementInfo>> test2(@RequestParam(name="pageNo", defaultValue="1") Integer pageNo,
+                        @RequestParam(name="pageSize", defaultValue="10") Integer pageSize) {
+        PageHelper.startPage(pageNo,pageSize);
+        List<ctopCwjsSettlementInfo> list = settlementInfoService.getList();
+        PageInfo<ctopCwjsSettlementInfo> pageInfo = new PageInfo<>(list);
+        return Result.successMsg("chenggong.",pageInfo);
+    }
+
+
+
+
+
+
 }

+ 1 - 30
jeecg-boot-finance/src/main/java/org/jeecg/ctop/finance/settlement/controller/SettlementController.java

@@ -3,14 +3,9 @@ package org.jeecg.ctop.finance.settlement.controller;
 import cn.afterturn.easypoi.excel.ExcelImportUtil;
 import cn.afterturn.easypoi.excel.entity.ImportParams;
 import cn.afterturn.easypoi.excel.entity.result.ExcelImportResult;
-import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
-import com.github.pagehelper.PageHelper;
-import com.github.pagehelper.PageInfo;
-import io.swagger.annotations.ApiOperation;
+
 import lombok.extern.slf4j.Slf4j;
 import org.jeecg.common.api.vo.Result;
-import org.jeecg.common.system.query.QueryGenerator;
-import org.jeecg.ctop.finance.settlement.entity.pojo.SettlementInfoPojo;
 import org.jeecg.ctop.finance.settlement.entity.vo.BytedanceAccountImportVo;
 
 
@@ -19,9 +14,6 @@ import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.web.bind.annotation.*;
 import org.springframework.web.multipart.MultipartFile;
 
-import javax.servlet.http.HttpServletRequest;
-import java.util.List;
-import java.util.Map;
 
 
 /**
@@ -39,27 +31,6 @@ public class SettlementController {
 
 
 
-    @ApiOperation(value="test", notes="test")
-    @GetMapping(value = "/test")
-    public Result test(
-                                                                   @RequestParam(name="pageNo", defaultValue="1") Integer pageNo,
-                                                                   @RequestParam(name="pageSize", defaultValue="10") Integer pageSize,
-                                                                   HttpServletRequest req) {
-        PageHelper.startPage(pageNo,pageSize);
-        List<SettlementInfoPojo> list = settlementInfoService.getList();
-        PageInfo<SettlementInfoPojo> pageInfo = new PageInfo<SettlementInfoPojo>(list);
-        return Result.successMsg("chenggong.",pageInfo);
-    }
-
-
-
-
-
-
-
-
-
-
     @PostMapping("/import")
     public Result getProjects(@RequestParam("files") MultipartFile[] files) {
 

+ 3 - 1
jeecg-boot-finance/src/main/java/org/jeecg/ctop/finance/settlement/entity/pojo/SettlementInfoPojo.java

@@ -3,6 +3,7 @@ package org.jeecg.ctop.finance.settlement.entity.pojo;
 import com.baomidou.mybatisplus.annotation.IdType;
 import com.baomidou.mybatisplus.annotation.TableId;
 import lombok.Data;
+import org.jeecg.common.aspect.annotation.Dict;
 
 import java.io.Serializable;
 import java.util.Date;
@@ -14,7 +15,7 @@ import java.util.Date;
  **/
 
 @Data
-public class SettlementInfoPojo implements Serializable {
+public class ctopCwjsSettlementInfo implements Serializable {
 
     @TableId(type = IdType.AUTO)
     /**
@@ -25,6 +26,7 @@ public class SettlementInfoPojo implements Serializable {
     /**
      * 广告主公司id
      */
+    @Dict(dicCode = "id", dictTable = "ctop_advertiser", dicText = "name")
     private String advertiserId;
 
     /**

+ 3 - 3
jeecg-boot-finance/src/main/java/org/jeecg/ctop/finance/settlement/mapper/SettlementInfoMapper.java

@@ -1,7 +1,7 @@
 package org.jeecg.ctop.finance.settlement.mapper;
 
 import com.baomidou.mybatisplus.core.mapper.BaseMapper;
-import org.jeecg.ctop.finance.settlement.entity.pojo.SettlementInfoPojo;
+import org.jeecg.ctop.finance.settlement.entity.pojo.ctopCwjsSettlementInfo;
 
 import java.util.List;
 
@@ -14,8 +14,8 @@ import java.util.List;
  * @author: zianY
  * @time: 2021/7/28 17:07
  */
-public interface SettlementInfoMapper extends BaseMapper<SettlementInfoPojo> {
+public interface SettlementInfoMapper extends BaseMapper<ctopCwjsSettlementInfo> {
 
-    List<SettlementInfoPojo> getList();
+    List<ctopCwjsSettlementInfo> getList();
 
 }

+ 1 - 1
jeecg-boot-finance/src/main/java/org/jeecg/ctop/finance/settlement/mapper/xml/SettlementInfoMapper.xml

@@ -2,7 +2,7 @@
 <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
 <mapper namespace="org.jeecg.ctop.finance.settlement.mapper.SettlementInfoMapper">
 
-    <select id="getList" resultType="org.jeecg.ctop.finance.settlement.entity.pojo.SettlementInfoPojo">
+    <select id="getList" resultType="org.jeecg.ctop.finance.settlement.entity.pojo.ctopCwjsSettlementInfo">
 
 select * from ctop_cwjs_settlement_info
 

+ 3 - 3
jeecg-boot-finance/src/main/java/org/jeecg/ctop/finance/settlement/service/ISettlementInfoService.java

@@ -1,12 +1,12 @@
 package org.jeecg.ctop.finance.settlement.service;
 
 import com.baomidou.mybatisplus.extension.service.IService;
-import org.jeecg.ctop.finance.settlement.entity.pojo.SettlementInfoPojo;
+import org.jeecg.ctop.finance.settlement.entity.pojo.ctopCwjsSettlementInfo;
 
 import java.util.List;
 
-public interface ISettlementInfoService extends IService<SettlementInfoPojo> {
+public interface ISettlementInfoService extends IService<ctopCwjsSettlementInfo> {
 
-    List<SettlementInfoPojo> getList();
+    List<ctopCwjsSettlementInfo> getList();
 
 }

+ 3 - 3
jeecg-boot-finance/src/main/java/org/jeecg/ctop/finance/settlement/service/serviceImpl/SettlementInfoServiceImpl.java

@@ -1,7 +1,7 @@
 package org.jeecg.ctop.finance.settlement.service.serviceImpl;
 
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
-import org.jeecg.ctop.finance.settlement.entity.pojo.SettlementInfoPojo;
+import org.jeecg.ctop.finance.settlement.entity.pojo.ctopCwjsSettlementInfo;
 import org.jeecg.ctop.finance.settlement.mapper.SettlementInfoMapper;
 import org.jeecg.ctop.finance.settlement.service.ISettlementInfoService;
 import org.springframework.stereotype.Service;
@@ -11,14 +11,14 @@ import java.util.List;
 
 
 @Service
-public class SettlementInfoServiceImpl extends ServiceImpl<SettlementInfoMapper, SettlementInfoPojo> implements ISettlementInfoService {
+public class SettlementInfoServiceImpl extends ServiceImpl<SettlementInfoMapper, ctopCwjsSettlementInfo> implements ISettlementInfoService {
 
     @Resource
     private SettlementInfoMapper settlementInfoMapper;
 
 
     @Override
-    public List<SettlementInfoPojo> getList() {
+    public List<ctopCwjsSettlementInfo> getList() {
         return settlementInfoMapper.getList();
     }
 }