Browse Source

Merge branch '业务串连' into develop

lgs 11 tháng trước cách đây
mục cha
commit
0a7140b88a

+ 10 - 0
src/main/java/com/kexun/mapper/FieldDefineMapper.java

@@ -31,4 +31,14 @@ public interface FieldDefineMapper extends BaseMapper<FieldDefineEntity> {
     List<FieldDefineEntity> selectBase(String info);
 
     List<FieldDefineEntity> selectDerive(String info);
+
+    /**
+     * 根据产品编号和类别查询字段定义
+     * @param productNum
+     * @param oneLevel
+     * @param category
+     * @return
+     */
+    List<FieldDefineEntity> queryFieldDefineByProd(@Param("productNum") String productNum,@Param("oneLevel") String oneLevel,@Param("category") String category);
+
 }

+ 5 - 0
src/main/java/com/kexun/model/dto/ReportParseDTO.java

@@ -42,4 +42,9 @@ public class ReportParseDTO implements Serializable {
      * 解析出来的json串
      */
     private String parseJson;
+
+    /**
+     * 产品配置出来的JSON串
+     */
+    private String prdJson;
 }

+ 13 - 2
src/main/java/com/kexun/service/FieldDefineService.java

@@ -50,10 +50,21 @@ public interface FieldDefineService extends IService<FieldDefineEntity> {
 
     /**
      * 获取所有的衍生字段信息列表
-     * @param category
+     * @param category 类别
+     * @param productNum 产品编号
+     * @return
+     */
+    List<FieldDefineEntity> listFieldDevidPrdField(String productNum, String category);
+
+    /**
+     * 根据产品编号字段类别查询字段定义
+     * @param productNum 产品编号
+     * @param oneLevel   字段定义节点
+     * @param category   类别
      * @return
      */
-    List<FieldDefineEntity> listFieldInfoByCategory(String category);
+    List<FieldDefineEntity> queryFieldDefineByProd(String productNum,String oneLevel,String category);
+
 
     FieldDefineEntity findByID(long id);
 

+ 75 - 34
src/main/java/com/kexun/service/field/BaseFieldPackageJsonService.java

@@ -1,6 +1,5 @@
 package com.kexun.service.field;
 
-import com.alibaba.fastjson.JSON;
 import com.alibaba.fastjson.JSONObject;
 import com.kexun.constant.BaseConsts;
 import com.kexun.entity.FieldDefineEntity;
@@ -33,16 +32,17 @@ public class BaseFieldPackageJsonService implements IBaseFieldPackageJsonService
     /**
      * 基础字段组装JSON处理方法
      *
-     * @param reportInfo 报文信息
-     * @param jsonMap  汇总各定义字段的计算结果
-     * @param json     原始的xml报文
-     * @param oneLevel 各个信息段配置的字段定义表标识
-     * @param nodeType 节点类型
+     * @param reportInfo   报文信息
+     * @param jsonMap      汇总各定义字段的计算结果
+     * @param fieldJsonMap 字段定义的Json Map
+     * @param json         原始的xml报文
+     * @param oneLevel     各个信息段配置的字段定义表标识
+     * @param nodeType     节点类型
      */
     @Override
-    public void packageJson(ReportInfo reportInfo,Map jsonMap, String json, String oneLevel, String nodeType) throws Exception {
+    public void packageJson(ReportInfo reportInfo, Map jsonMap, Map fieldJsonMap, String json, String oneLevel, String nodeType) throws Exception {
         //根据oneLevel定义表示,获取数据库里定义的所有的基础字段
-        List<FieldDefineEntity> fieldDefineEntities = fieldDefineService.listFieldInfoByLevel(oneLevel,"1");
+        List<FieldDefineEntity> fieldDefineEntities = fieldDefineService.listFieldInfoByLevel(oneLevel, "1");
         //根据List聚合出该信息段的json的key
         Set<String> jsonSet = fieldDefineEntities.stream()
                 .map(FieldDefineEntity::getJsonKey)
@@ -53,8 +53,10 @@ public class BaseFieldPackageJsonService implements IBaseFieldPackageJsonService
         String jsonKey = jsonSet.iterator().next();
         JSONObject jsonObject = JSONObject.parseObject(json);
         //查询出来和合作产品关联的基础字段,然后从整个的基础字段里取出来放到合作产品对应的信息段中去
-
-
+        List<FieldDefineEntity> fieldDefineEntityList = fieldDefineService.queryFieldDefineByProd(reportInfo.getProductNum(), oneLevel,"1");
+        List<String> prodFieldDefineList = fieldDefineEntityList.stream()
+                .map(FieldDefineEntity::getName)
+                .collect(Collectors.toList());
         //节点类型是正常类型,直接循环各个定义字段
         if (BaseConsts.NODE_TYPE_NORMAL.equals(nodeType)) {
             //定义子Map的集合
@@ -66,7 +68,7 @@ public class BaseFieldPackageJsonService implements IBaseFieldPackageJsonService
                 String name = fieldDefineEntity.getName();
                 //字段类型
                 String type = fieldDefineEntity.getType();
-                String value = BaseUtils.getValueByType(jsonObject.get(fieldDefineEntity.getPath()),type);
+                String value = BaseUtils.getValueByType(jsonObject.get(fieldDefineEntity.getPath()), type);
                 infoMap.put(name, value);
             }
             if (jsonMap.containsKey(jsonKey)) {
@@ -77,14 +79,35 @@ public class BaseFieldPackageJsonService implements IBaseFieldPackageJsonService
                 subJsonMap.put(jsonKey, infoMap);
                 jsonMap.putAll(subJsonMap);
             }
+            //处理和产品关联的字段信息
+            /***
+             * 处理思路:循环prodFieldDefineList,然后从infoMap获取对应的值
+             */
+            Map<String, String> prdDefinMap = new HashMap<>();
+            Map<String, Object> subPrdJsonMap = new HashMap<>();
+            for (String s : prodFieldDefineList) {
+                String value = infoMap.get(s);
+                prdDefinMap.put(s, value);
+            }
+            if (fieldJsonMap.containsKey(jsonKey)) {
+                Map map = (Map) fieldJsonMap.get(jsonKey);
+                map.putAll(prdDefinMap);
+                fieldJsonMap.put(jsonKey, map);
+            } else {
+                subPrdJsonMap.put(jsonKey, infoMap);
+                fieldJsonMap.putAll(subPrdJsonMap);
+            }
             //节点类型是列表,需要统计各个字段,那么计算用同一个函数,一块进行计算,获取一个计算结果
         } else if (BaseConsts.NODE_TYPE_LIST.equals(nodeType) || BaseConsts.NODE_TYPE_COMPOSE.equals(nodeType)) {
             //定义子Map的集合
-            Map<String, Object> subJsonMap = new HashMap<>();
+            Map<String, Object> subJsonMap = new HashMap<>(16);
+            Map<String, Object> prdSubJsonMap = new HashMap<>(16);
             //定义方法返回的Map
-            Map<String, String> infoMap = new HashMap<>();
+            Map<String, String> infoMap = new HashMap<>(16);
+            Map<String, String> prdInfoMap = new HashMap<>(16);
             //定义方法返回的List
             List<Map> infoList = new ArrayList<>();
+            List<Map> prdInfoList = new ArrayList<>();
             //获取算法类和方法,然后进行统一的计算
             Set<String> formulaClassSet = fieldDefineEntities.stream().map(FieldDefineEntity::getFormulaClass)
                     .collect(Collectors.toSet());
@@ -103,29 +126,47 @@ public class BaseFieldPackageJsonService implements IBaseFieldPackageJsonService
             Class<?> aClass = object.getClass();
             Method method = aClass.getMethod(formulaMethod, JSONObject.class, List.class);
             Object invoke = method.invoke(object, jsonObject, fieldDefineEntities);
-            if (invoke instanceof Map) {
-                infoMap = (Map) invoke;
-                if (jsonMap.containsKey(jsonKey)) {
-                    Map map = (Map) jsonMap.get(jsonKey);
-                    map.putAll(infoMap);
-                    jsonMap.put(jsonKey, map);
-                } else {
-                    subJsonMap.put(jsonKey, infoMap);
-                    jsonMap.putAll(subJsonMap);
-                }
+            handleBaseField(invoke,infoMap,jsonMap,jsonKey,subJsonMap,infoList);
+            //计算和产品关联的信息
+            if(fieldDefineEntityList!=null && fieldDefineEntityList.size()>0){
+                Object prdInvoke = method.invoke(object, jsonObject, fieldDefineEntityList);
+                //处理和产品相关联的产品信息
+                handleBaseField(prdInvoke,prdInfoMap,fieldJsonMap,jsonKey,prdSubJsonMap,prdInfoList);
+            }
+        }
+    }
 
-            }else if (invoke instanceof List){
-                infoList = (List) invoke;
-                if (jsonMap.containsKey(jsonKey)) {
-                    List list = (List) jsonMap.get(jsonKey);
-                    list.addAll(infoList);
-                    jsonMap.put(jsonKey, list);
-                } else {
-                    subJsonMap.put(jsonKey, infoList);
-                    jsonMap.putAll(subJsonMap);
-                }
+    /**
+     * 处理计算结果后的Map
+     * @param invoke
+     * @param infoMap
+     * @param jsonMap
+     * @param jsonKey
+     * @param subJsonMap
+     * @param infoList
+     */
+    private void handleBaseField(Object invoke,Map infoMap,Map jsonMap,String jsonKey,Map subJsonMap,List<Map> infoList){
+        //处理基础字段
+        if (invoke instanceof Map) {
+            infoMap = (Map) invoke;
+            if (jsonMap.containsKey(jsonKey)) {
+                Map map = (Map) jsonMap.get(jsonKey);
+                map.putAll(infoMap);
+                jsonMap.put(jsonKey, map);
+            } else {
+                subJsonMap.put(jsonKey, infoMap);
+                jsonMap.putAll(subJsonMap);
+            }
+        } else if (invoke instanceof List) {
+            infoList = (List) invoke;
+            if (jsonMap.containsKey(jsonKey)) {
+                List list = (List) jsonMap.get(jsonKey);
+                list.addAll(infoList);
+                jsonMap.put(jsonKey, list);
+            } else {
+                subJsonMap.put(jsonKey, infoList);
+                jsonMap.putAll(subJsonMap);
             }
         }
-        String jsonString = JSON.toJSONString(jsonMap);
     }
 }

+ 2 - 1
src/main/java/com/kexun/service/field/IBaseFieldPackageJsonService.java

@@ -16,11 +16,12 @@ public interface IBaseFieldPackageJsonService {
      * 基础字段组装JSON处理方法
      *
      * @param jsonMap 汇总各定义字段的计算结果
+     * @param fieldJsonMap 和产品关联的字计算结果
      * @param json 原始的xml报文
      * @param oneLevel 各个信息段配置的字段定义表标识
      * @param nodeType 节点类型
      */
-    void packageJson(ReportInfo reportInfo, Map jsonMap, String json, String oneLevel, String nodeType) throws Exception;
+    void packageJson(ReportInfo reportInfo, Map jsonMap,Map fieldJsonMap, String json, String oneLevel, String nodeType) throws Exception;
 
 
 }

+ 34 - 12
src/main/java/com/kexun/service/impl/FieldDefineServiceImpl.java

@@ -64,12 +64,13 @@ public class FieldDefineServiceImpl extends ServiceImpl<FieldDefineMapper, Field
 
     /**
      * 根据一级分类查询字段定义信息
+     *
      * @param oneLevel
      * @param category
      * @return
      */
     @Override
-    public List<FieldDefineEntity> listFieldInfoByLevel(String oneLevel,String category){
+    public List<FieldDefineEntity> listFieldInfoByLevel(String oneLevel, String category) {
         QueryWrapper queryWrapper = new QueryWrapper();
         if (!StringUtils.isEmpty(oneLevel)) {
             queryWrapper.eq("one_level", oneLevel);
@@ -82,39 +83,58 @@ public class FieldDefineServiceImpl extends ServiceImpl<FieldDefineMapper, Field
     }
 
     /**
-     * 获取所有的衍生字段,定义的衍生字段
+     * 获取衍生字段,和产品挂钩的衍生字段
+     *
      * @param category
      * @return
      */
     @Override
-    public List<FieldDefineEntity> listFieldInfoByCategory(String category){
+    public List<FieldDefineEntity> listFieldDevidPrdField(String productNum, String category) {
         QueryWrapper queryWrapper = new QueryWrapper();
         if (!StringUtils.isEmpty(category)) {
             queryWrapper.eq("category", category);
         }
+        if (!StringUtils.isEmpty(category)) {
+            queryWrapper.eq("category", category);
+        }
         List<FieldDefineEntity> list = super.list(queryWrapper);
         return list;
     }
 
+    /**
+     * 根据产品编号字段类别查询字段定义
+     *
+     * @param productNum
+     * @param oneLevel
+     * @param category
+     * @return
+     */
+    @Override
+    public List<FieldDefineEntity> queryFieldDefineByProd(String productNum, String oneLevel,String category) {
+        return fieldDefineMapper.queryFieldDefineByProd(productNum, oneLevel,category);
+    }
+
+    @Override
     public List<FieldDefineEntity> selectPage() {
-//        System.out.println("aaa");
         String cat = "1";
         List<FieldDefineEntity> l = fieldDefineMapper.selectAll(cat);
         return l;
     }
 
+    @Override
     public List<FieldDefineEntity> selectBase(String info) {
         List<FieldDefineEntity> l = fieldDefineMapper.selectBase(info);
         return l;
     }
 
+    @Override
     public List<FieldDefineEntity> selectPage2() {
-//        System.out.println("aaa");
         String cat = "2";
         List<FieldDefineEntity> l = fieldDefineMapper.selectAll(cat);
         return l;
     }
 
+    @Override
     public List<FieldDefineEntity> selectDerive(String info) {
         List<FieldDefineEntity> l = fieldDefineMapper.selectDerive(info);
         return l;
@@ -122,6 +142,7 @@ public class FieldDefineServiceImpl extends ServiceImpl<FieldDefineMapper, Field
 
     /**
      * 保存或者修改字段定义
+     *
      * @param filedUpdateRO
      */
     @Override
@@ -131,31 +152,32 @@ public class FieldDefineServiceImpl extends ServiceImpl<FieldDefineMapper, Field
         FieldDefineEntity fieldDefineEntity = new FieldDefineEntity();
 
         if (null != defineEntity) {
-            BeanUtils.copyProperties(filedUpdateRO,fieldDefineEntity);
+            BeanUtils.copyProperties(filedUpdateRO, fieldDefineEntity);
 
             updateById(fieldDefineEntity);
-        }else {
+        } else {
             filedUpdateRO.setCategory("2");
             long time1 = System.currentTimeMillis();
             filedUpdateRO.setFieldNo(Long.toString(time1));
-            BeanUtils.copyProperties(filedUpdateRO,fieldDefineEntity);
+            BeanUtils.copyProperties(filedUpdateRO, fieldDefineEntity);
             save(fieldDefineEntity);
         }
     }
 
     /**
      * 修改状态
-     * @param id 主键
+     *
+     * @param id     主键
      * @param status 状态
      */
     @Override
-    public void updateOnOff(Long id,String status){
-        fieldDefineMapper.updateStatus(id,status);
+    public void updateOnOff(Long id, String status) {
+        fieldDefineMapper.updateStatus(id, status);
     }
 
     @Override
     public FieldDefineEntity findByID(long id) {
-        QueryWrapper<FieldDefineEntity> wrapper=new QueryWrapper<FieldDefineEntity>().eq("id",id);
+        QueryWrapper<FieldDefineEntity> wrapper = new QueryWrapper<FieldDefineEntity>().eq("id", id);
         return getOne(wrapper);
     }
 

+ 41 - 11
src/main/java/com/kexun/service/xml/ParseHandleService.java

@@ -3,6 +3,7 @@ package com.kexun.service.xml;
 import com.alibaba.fastjson.JSONArray;
 import com.alibaba.fastjson.JSONObject;
 import com.alibaba.fastjson.annotation.JSONField;
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.kexun.constant.BaseConsts;
 import com.kexun.constant.XmlNodeConsts;
 import com.kexun.entity.FieldDefineEntity;
@@ -15,7 +16,9 @@ import com.kexun.model.dto.CommonParam;
 import com.kexun.model.dto.ReportParseDTO;
 import com.kexun.model.xml.HeadInfo;
 import com.kexun.model.xml.IXmlBase;
-import com.kexun.service.*;
+import com.kexun.service.CrHeadInfService;
+import com.kexun.service.FieldDefineService;
+import com.kexun.service.FieldParamService;
 import com.kexun.utils.ParseXmlUtils;
 import com.kexun.utils.SpringContextUtil;
 import lombok.extern.slf4j.Slf4j;
@@ -26,7 +29,10 @@ import org.springframework.util.StringUtils;
 
 import java.lang.reflect.Field;
 import java.lang.reflect.Method;
-import java.util.*;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
 import java.util.stream.Collectors;
 
 /**
@@ -60,6 +66,8 @@ public class ParseHandleService {
         JSONObject jsonObject = ParseXmlUtils.xmlToJson(xmlContent);
         //定义Map 存放JSON
         Map<String, Object> jsonMap = new HashMap<>(16);
+        //定义产品关联字段的存放JSON
+        Map<String, Object> fieldJsonMap = new HashMap<>(16);
         log.info("转出json后={}", jsonObject.toJSONString());
         ReportParseDTO reportParseDTO = new ReportParseDTO();
         /**
@@ -108,11 +116,31 @@ public class ParseHandleService {
                                 commonParam.setNodeMap(paramMap);
                                 factoryBean.getSpecService().handleXmlSpec(commonParam, jsonBean, iBaseEntity);
                             }
+                            //先查询,根据rpt_no查询是否存在
+
+                            QueryWrapper queryWrapper = new QueryWrapper();
+                            queryWrapper.eq("rpt_no", commonParam.getRptNo());
+                            //根据rpt_no查询是否存在,如果存在则更新
+                            Object obj = factoryBean.getService().getOne(queryWrapper);
+                            if (obj!=null){
+                                Class<?> aClass = obj.getClass();
+                                Class<?> superclass = aClass.getSuperclass();
+                                Field field = superclass.getDeclaredField("id");
+                                field.setAccessible(true);
+                                Object id = field.get(obj);
+
+                                Class<? extends IBaseEntity> aClass1 = iBaseEntity.getClass();
+                                Class<?> superclass1 = aClass1.getSuperclass();
+                                Field idField = superclass1.getDeclaredField("id");
+                                idField.setAccessible(true);
+                                // 设置name字段的新值
+                                idField.set(iBaseEntity, id);
+                            }
                             //保存
-                            factoryBean.getService().save(iBaseEntity);
+                            factoryBean.getService().saveOrUpdate(iBaseEntity);
                             //构建json
                             if (factoryBean.getBaseFieldPackageJsonService() != null) {
-                                factoryBean.getBaseFieldPackageJsonService().packageJson(reportInfo,jsonMap, json, factoryBean.getXmlNodeName(), factoryBean.getNodeType());
+                                factoryBean.getBaseFieldPackageJsonService().packageJson(reportInfo,jsonMap,fieldJsonMap, json, factoryBean.getXmlNodeName(), factoryBean.getNodeType());
                             }
                         } else if (BaseConsts.NODE_TYPE_COMPOSE.equals(factoryBean.getNodeType())) {
                             //处理复杂类型
@@ -121,7 +149,7 @@ public class ParseHandleService {
                             reportXmlBaseService.handleXmlSgmt(commonParam, jsonBean);
                             //构建json
                             if (factoryBean.getBaseFieldPackageJsonService() != null) {
-                                factoryBean.getBaseFieldPackageJsonService().packageJson(reportInfo,jsonMap, json, factoryBean.getXmlNodeName(), factoryBean.getNodeType());
+                                factoryBean.getBaseFieldPackageJsonService().packageJson(reportInfo,jsonMap,fieldJsonMap, json, factoryBean.getXmlNodeName(), factoryBean.getNodeType());
                             }
                         } else if (BaseConsts.NODE_TYPE_LIST.equals(factoryBean.getNodeType())) {
                             Map<String, String> paramMap = factoryBean.getParamMap();
@@ -150,7 +178,7 @@ public class ParseHandleService {
                                         }
                                         factoryBean.getService().saveBatch(iBaseEntities);
                                         if (factoryBean.getBaseFieldPackageJsonService() != null) {
-                                            factoryBean.getBaseFieldPackageJsonService().packageJson(reportInfo,jsonMap, json, factoryBean.getXmlNodeName(), factoryBean.getNodeType());
+                                            factoryBean.getBaseFieldPackageJsonService().packageJson(reportInfo,jsonMap,fieldJsonMap, json, factoryBean.getXmlNodeName(), factoryBean.getNodeType());
                                         }
                                     }
                                 }
@@ -169,7 +197,7 @@ public class ParseHandleService {
              * 1、直接从数据库里获取配置的衍生字段,按照json的key值去做分组,然后进行循环。
              * 2、通过配置和参数,进行计算,放到配置对应的位置去。
              */
-            List<FieldDefineEntity> fieldList = fieldDefineService.listFieldInfoByCategory("2");
+            List<FieldDefineEntity> fieldList = fieldDefineService.queryFieldDefineByProd(reportInfo.getProductNum(),"","2");
             //按照Jsonkey进行分组
             Map<String, List<FieldDefineEntity>> jsonKeyMap = fieldList.stream()
                     .filter((e)->!StringUtils.isEmpty(e.getJsonKey()))
@@ -221,14 +249,14 @@ public class ParseHandleService {
                     }
                     if (invokeResult != null) {
                         fieldMap.put(name, invokeResult);
-                        if (jsonMap.containsKey(jsonKey)) {
-                            Map map = (Map) jsonMap.get(jsonKey);
+                        if (fieldJsonMap.containsKey(jsonKey)) {
+                            Map map = (Map) fieldJsonMap.get(jsonKey);
                             map.putAll(fieldMap);
-                            jsonMap.put(jsonKey, map);
+                            fieldJsonMap.put(jsonKey, map);
                         } else {
                             Map<String, Object> subJsonMap = new HashMap<>();
                             subJsonMap.put(jsonKey, fieldMap);
-                            jsonMap.putAll(subJsonMap);
+                            fieldJsonMap.putAll(subJsonMap);
                         }
                     }
                 }
@@ -238,7 +266,9 @@ public class ParseHandleService {
         } else {
             log.error("xml转Json得到的JSONObject为空");
         }
+        //基础字段的JSON
         reportParseDTO.setParseJson(JSONObject.toJSONString(jsonMap));
+        reportParseDTO.setPrdJson(JSONObject.toJSONString(fieldJsonMap));
         return reportParseDTO;
     }
 

+ 1 - 1
src/main/java/com/kexun/task/ReportParseJobHandler.java

@@ -84,7 +84,7 @@ public class ReportParseJobHandler {
                     fileName = fileName.substring(0, fileName.indexOf("."));
                     ReportParseDTO reportParseDTO = parseHandleService.parseHandle(reportInfo,xmlContext);
                     //保存xml文件和解析文件
-                    fileService.saveAndWriteFile(reportInfo,xmlContext,reportParseDTO.getParseJson(),fileName);
+                    fileService.saveAndWriteFile(reportInfo,xmlContext,reportParseDTO.getPrdJson(),fileName);
                     //修改解析报文信息的状态
                     reportInfoDTO.setStatus(ReportStatusEnum.PRASE_FINISH.getValue());
                     //解析成功 状态为已解析

+ 55 - 15
src/main/resources/mapper/FieldDefineMapper.xml

@@ -36,36 +36,60 @@
 
     <!-- 通用查询结果列 -->
     <sql id="Base_Column_List">
+        d
+        .
         id
         ,
-        revison,
-        tenant_id,
-        create_by,
-        create_time,
-        update_by,
-        update_time,
-        is_deleted,
-        remarks,
-        field_no, name, name_zh, category, type, fetch_logic, formula_expr, formula_class, formula_method, formula_desc, three_level, three_level_zh, two_level, two_level_zh, one_level, one_level_zh, json_key, type_no, status
+        d.revison,
+        d.tenant_id,
+        d.create_by,
+        d.create_time,
+        d.update_by,
+        d.update_time,
+        d.is_deleted,
+        d.remarks,
+        d.field_no,
+        d.name,
+        d.name_zh,
+        d.category,
+        d.type,
+        d.fetch_logic,
+        d.formula_expr,
+        d.formula_class,
+        d.formula_method,
+        d.formula_desc,
+        d.three_level,
+        d.three_level_zh,
+        d.two_level,
+        d.two_level_zh,
+        d.one_level,
+        d.one_level_zh,
+        d.json_key,
+        d.type_no,
+        d.status
     </sql>
 
     <select id="selectAll" resultType="com.kexun.entity.FieldDefineEntity">
-        select * from field_define
-        where category=#{cat} and is_deleted = 0
+        select *
+        from field_define
+        where category = #{cat}
+          and is_deleted = 0
 
 
     </select>
 
     <select id="selectBase" resultType="com.kexun.entity.FieldDefineEntity">
-        select * from field_define
-        WHERE name_zh LIKE concat('%',#{info},'%')
+        select *
+        from field_define
+        WHERE name_zh LIKE concat('%', #{info}, '%')
           and is_deleted = 0
 
     </select>
 
     <select id="selectDerive" resultType="com.kexun.entity.FieldDefineEntity">
-        select * from field_define
-        WHERE name_zh LIKE concat('%',#{info},'%')
+        select *
+        from field_define
+        WHERE name_zh LIKE concat('%', #{info}, '%')
           and is_deleted = 0
         order by create_time desc
 
@@ -76,4 +100,20 @@
         set status = #{status}
         where id = #{id}
     </update>
+
+    <select id="queryFieldDefineByProd" resultType="com.kexun.entity.FieldDefineEntity">
+        SELECT
+        <include refid="Base_Column_List"></include>
+        from field_define d
+        LEFT JOIN product_field_ref r on d.field_no = r.field_no
+        where r.product_num = #{productNum}
+        <if test="oneLevel!=null">
+            and d.one_level = #{oneLevel}
+        </if>
+        <if test="category!=null">
+            and d.category = #{category}
+        </if>
+        and r.is_deleted = '0'
+        and d.is_deleted = '0'
+    </select>
 </mapper>