Browse Source

外来接口获取扫码数据及其配置

LIVE_YE 2 năm trước cách đây
mục cha
commit
f67130018b

+ 13 - 0
ruoyi-admin/src/main/java/com/ruoyi/web/controller/info/AkmDataController.java

@@ -1,6 +1,7 @@
 package com.ruoyi.web.controller.info;
 
 import java.util.List;
+import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
 import org.springframework.security.access.prepost.PreAuthorize;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -46,6 +47,18 @@ public class AkmDataController extends BaseController
         return getDataTable(list);
     }
 
+
+    /**
+     * 查询安康码扫码地点列表(对外)
+     */
+    @GetMapping("/foreign/list")
+    public AjaxResult foreignList(HttpServletRequest request, String secretKey, AkmData akmData)
+    {
+
+        return akmDataService.getForeignList(request,secretKey,akmData);
+    }
+
+
     /**
      * 导出安康码扫码地点列表
      */

+ 104 - 0
ruoyi-admin/src/main/java/com/ruoyi/web/controller/info/SysInterfaceForeignController.java

@@ -0,0 +1,104 @@
+package com.ruoyi.web.controller.info;
+
+import java.util.List;
+import javax.servlet.http.HttpServletResponse;
+import org.springframework.security.access.prepost.PreAuthorize;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.PostMapping;
+import org.springframework.web.bind.annotation.PutMapping;
+import org.springframework.web.bind.annotation.DeleteMapping;
+import org.springframework.web.bind.annotation.PathVariable;
+import org.springframework.web.bind.annotation.RequestBody;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RestController;
+import com.ruoyi.common.annotation.Log;
+import com.ruoyi.common.core.controller.BaseController;
+import com.ruoyi.common.core.domain.AjaxResult;
+import com.ruoyi.common.enums.BusinessType;
+import com.ruoyi.system.domain.SysInterfaceForeign;
+import com.ruoyi.system.service.ISysInterfaceForeignService;
+import com.ruoyi.common.utils.poi.ExcelUtil;
+import com.ruoyi.common.core.page.TableDataInfo;
+
+/**
+ * 对外接口调用配置Controller
+ * 
+ * @author ruoyi
+ * @date 2022-10-31
+ */
+@RestController
+@RequestMapping("/system/foreign")
+public class SysInterfaceForeignController extends BaseController
+{
+    @Autowired
+    private ISysInterfaceForeignService sysInterfaceForeignService;
+
+    /**
+     * 查询对外接口调用配置列表
+     */
+    @PreAuthorize("@ss.hasPermi('system:foreign:list')")
+    @GetMapping("/list")
+    public TableDataInfo list(SysInterfaceForeign sysInterfaceForeign)
+    {
+        startPage();
+        List<SysInterfaceForeign> list = sysInterfaceForeignService.selectSysInterfaceForeignList(sysInterfaceForeign);
+        return getDataTable(list);
+    }
+
+    /**
+     * 导出对外接口调用配置列表
+     */
+    @PreAuthorize("@ss.hasPermi('system:foreign:export')")
+    @Log(title = "对外接口调用配置", businessType = BusinessType.EXPORT)
+    @PostMapping("/export")
+    public void export(HttpServletResponse response, SysInterfaceForeign sysInterfaceForeign)
+    {
+        List<SysInterfaceForeign> list = sysInterfaceForeignService.selectSysInterfaceForeignList(sysInterfaceForeign);
+        ExcelUtil<SysInterfaceForeign> util = new ExcelUtil<SysInterfaceForeign>(SysInterfaceForeign.class);
+        util.exportExcel(response, list, "对外接口调用配置数据");
+    }
+
+    /**
+     * 获取对外接口调用配置详细信息
+     */
+    @PreAuthorize("@ss.hasPermi('system:foreign:query')")
+    @GetMapping(value = "/{id}")
+    public AjaxResult getInfo(@PathVariable("id") Long id)
+    {
+        return AjaxResult.success(sysInterfaceForeignService.selectSysInterfaceForeignById(id));
+    }
+
+    /**
+     * 新增对外接口调用配置
+     */
+    @PreAuthorize("@ss.hasPermi('system:foreign:add')")
+    @Log(title = "对外接口调用配置", businessType = BusinessType.INSERT)
+    @PostMapping
+    public AjaxResult add(@RequestBody SysInterfaceForeign sysInterfaceForeign)
+    {
+        return toAjax(sysInterfaceForeignService.insertSysInterfaceForeign(sysInterfaceForeign));
+    }
+
+    /**
+     * 修改对外接口调用配置
+     */
+    @PreAuthorize("@ss.hasPermi('system:foreign:edit')")
+    @Log(title = "对外接口调用配置", businessType = BusinessType.UPDATE)
+    @PutMapping
+    public AjaxResult edit(@RequestBody SysInterfaceForeign sysInterfaceForeign)
+    {
+        return toAjax(sysInterfaceForeignService.updateSysInterfaceForeign(sysInterfaceForeign));
+    }
+
+    /**
+     * 删除对外接口调用配置
+     */
+    @PreAuthorize("@ss.hasPermi('system:foreign:remove')")
+    @Log(title = "对外接口调用配置", businessType = BusinessType.DELETE)
+	@DeleteMapping("/{ids}")
+    public AjaxResult remove(@PathVariable Long[] ids)
+    {
+        return toAjax(sysInterfaceForeignService.deleteSysInterfaceForeignByIds(ids));
+    }
+}

+ 3 - 3
ruoyi-admin/src/main/resources/application.yml

@@ -29,8 +29,8 @@ spring:
     # 国际化资源文件路径
     basename: i18n/messages
   profiles:
-    active: druid
-    #active: prod
+    #active: druid
+    active: prod
   # 文件上传
   servlet:
     multipart:
@@ -81,6 +81,6 @@ xss:
   # 过滤开关
   enabled: true
   # 排除链接(多个用逗号分隔)
-  excludes: /system/notice,/system/merchants,/system/guide,/system/use,/system/welfare,/system/data
+  excludes: /system/notice,/system/merchants,/system/guide,/system/use,/system/welfare,/system/data,/system/foreign
   # 匹配链接
   urlPatterns: /system/*,/monitor/*,/tool/*

+ 1 - 1
ruoyi-framework/src/main/java/com/ruoyi/framework/config/SecurityConfig.java

@@ -109,7 +109,7 @@ public class SecurityConfig extends WebSecurityConfigurerAdapter
                 // 过滤请求
                 .authorizeRequests()
                 // 对于登录login 注册register 验证码captchaImage 允许匿名访问
-                .antMatchers("/login", "/register", "/captchaImage","/system/data","/system/user/updateAll").anonymous()
+                .antMatchers("/login", "/register", "/captchaImage","/system/data","/system/user/updateAll","/system/data/foreign/list").anonymous()
                 // 静态资源,可匿名访问
                 .antMatchers(HttpMethod.GET, "/", "/*.html", "/**/*.html", "/**/*.css", "/**/*.js", "/profile/**").permitAll()
                 .antMatchers("/swagger-ui.html", "/swagger-resources/**", "/webjars/**", "/*/api-docs", "/druid/**").permitAll()

+ 28 - 0
ruoyi-system/src/main/java/com/ruoyi/system/domain/AkmData.java

@@ -74,6 +74,18 @@ public class AkmData extends BaseEntity
     @Excel(name = "所属用户")
     private String belongsUser;
 
+    private String startTime;
+    private String endTime;
+    private List<String> equipIdList;
+
+    public List<String> getEquipIdList() {
+        return equipIdList;
+    }
+
+    public void setEquipIdList(List<String> equipIdList) {
+        this.equipIdList = equipIdList;
+    }
+
     private List<AkmData> akmDataList;
 
     public List<AkmData> getAkmDataList() {
@@ -84,6 +96,22 @@ public class AkmData extends BaseEntity
         this.akmDataList = akmDataList;
     }
 
+    public String getStartTime() {
+        return startTime;
+    }
+
+    public String getEndTime() {
+        return endTime;
+    }
+
+    public void setStartTime(String startTime) {
+        this.startTime = startTime;
+    }
+
+    public void setEndTime(String endTime) {
+        this.endTime = endTime;
+    }
+
     public Long getId() {
         return id;
     }

+ 149 - 0
ruoyi-system/src/main/java/com/ruoyi/system/domain/SysInterfaceForeign.java

@@ -0,0 +1,149 @@
+package com.ruoyi.system.domain;
+
+import org.apache.commons.lang3.builder.ToStringBuilder;
+import org.apache.commons.lang3.builder.ToStringStyle;
+import com.ruoyi.common.annotation.Excel;
+import com.ruoyi.common.core.domain.BaseEntity;
+
+import java.util.List;
+import java.util.Map;
+
+/**
+ * 对外接口调用配置对象 sys_interface_foreign
+ * 
+ * @author ruoyi
+ * @date 2022-10-31
+ */
+public class SysInterfaceForeign extends BaseEntity
+{
+    private static final long serialVersionUID = 1L;
+
+    /**  */
+    private Long id;
+
+    /** 单位名称 */
+    @Excel(name = "单位名称")
+    private String name;
+
+    /** 秘钥 */
+    @Excel(name = "秘钥")
+    private String secretKey;
+
+
+    /** 放行IP */
+    private List<Map<Object,String>> ipList;
+
+    /** 放行IP */
+    @Excel(name = "放行IP")
+    private String ip;
+
+    /** 能获取的设备数据id */
+    private List<Map<Object,String>> equipIdList;
+
+    /** 能获取的设备数据id */
+    @Excel(name = "能获取的设备数据id")
+    private String equipId;
+
+
+
+    /** 每天可调用次数(-1时为不限次数) */
+    @Excel(name = "每天可调用次数(-1时为不限次数)")
+    private Long number;
+
+    /** 每天调用剩余次数 */
+    @Excel(name = "每天调用剩余次数")
+    private Long remainingNumber;
+
+    public void setId(Long id) 
+    {
+        this.id = id;
+    }
+
+    public Long getId() 
+    {
+        return id;
+    }
+    public void setName(String name) 
+    {
+        this.name = name;
+    }
+
+    public String getName() 
+    {
+        return name;
+    }
+    public void setSecretKey(String secretKey) 
+    {
+        this.secretKey = secretKey;
+    }
+
+    public String getSecretKey() 
+    {
+        return secretKey;
+    }
+    public void setIp(String ip) 
+    {
+        this.ip = ip;
+    }
+
+    public String getIp() 
+    {
+        return ip;
+    }
+    public void setEquipId(String equipId) 
+    {
+        this.equipId = equipId;
+    }
+
+    public String getEquipId() 
+    {
+        return equipId;
+    }
+    public void setNumber(Long number) 
+    {
+        this.number = number;
+    }
+
+    public Long getNumber() 
+    {
+        return number;
+    }
+    public void setRemainingNumber(Long remainingNumber) 
+    {
+        this.remainingNumber = remainingNumber;
+    }
+
+    public Long getRemainingNumber() 
+    {
+        return remainingNumber;
+    }
+
+    public List<Map<Object,String>> getIpList() {
+        return ipList;
+    }
+
+    public List<Map<Object,String>> getEquipIdList() {
+        return equipIdList;
+    }
+
+    public void setIpList(List<Map<Object,String>> ipList) {
+        this.ipList = ipList;
+    }
+
+    public void setEquipIdList(List<Map<Object,String>> equipIdList) {
+        this.equipIdList = equipIdList;
+    }
+
+    @Override
+    public String toString() {
+        return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE)
+            .append("id", getId())
+            .append("name", getName())
+            .append("secretKey", getSecretKey())
+            .append("ip", getIp())
+            .append("equipId", getEquipId())
+            .append("number", getNumber())
+            .append("remainingNumber", getRemainingNumber())
+            .toString();
+    }
+}

+ 63 - 0
ruoyi-system/src/main/java/com/ruoyi/system/mapper/SysInterfaceForeignMapper.java

@@ -0,0 +1,63 @@
+package com.ruoyi.system.mapper;
+
+import java.util.List;
+import com.ruoyi.system.domain.SysInterfaceForeign;
+
+/**
+ * 对外接口调用配置Mapper接口
+ * 
+ * @author ruoyi
+ * @date 2022-10-31
+ */
+public interface SysInterfaceForeignMapper 
+{
+    /**
+     * 查询对外接口调用配置
+     * 
+     * @param id 对外接口调用配置主键
+     * @return 对外接口调用配置
+     */
+    public SysInterfaceForeign selectSysInterfaceForeignById(Long id);
+
+    /**
+     * 查询对外接口调用配置列表
+     * 
+     * @param sysInterfaceForeign 对外接口调用配置
+     * @return 对外接口调用配置集合
+     */
+    public List<SysInterfaceForeign> selectSysInterfaceForeignList(SysInterfaceForeign sysInterfaceForeign);
+
+    /**
+     * 新增对外接口调用配置
+     * 
+     * @param sysInterfaceForeign 对外接口调用配置
+     * @return 结果
+     */
+    public int insertSysInterfaceForeign(SysInterfaceForeign sysInterfaceForeign);
+
+    /**
+     * 修改对外接口调用配置
+     * 
+     * @param sysInterfaceForeign 对外接口调用配置
+     * @return 结果
+     */
+    public int updateSysInterfaceForeign(SysInterfaceForeign sysInterfaceForeign);
+
+    /**
+     * 删除对外接口调用配置
+     * 
+     * @param id 对外接口调用配置主键
+     * @return 结果
+     */
+    public int deleteSysInterfaceForeignById(Long id);
+
+    /**
+     * 批量删除对外接口调用配置
+     * 
+     * @param ids 需要删除的数据主键集合
+     * @return 结果
+     */
+    public int deleteSysInterfaceForeignByIds(Long[] ids);
+
+    SysInterfaceForeign getForeignByKey(String secretKey);
+}

+ 4 - 0
ruoyi-system/src/main/java/com/ruoyi/system/service/IAkmDataService.java

@@ -5,6 +5,8 @@ import java.util.List;
 import com.ruoyi.common.core.domain.AjaxResult;
 import com.ruoyi.system.domain.AkmData;
 
+import javax.servlet.http.HttpServletRequest;
+
 /**
  * 安康码扫码地点Service接口
  * 
@@ -60,4 +62,6 @@ public interface IAkmDataService
      * @return 结果
      */
     public int deleteAkmDataById(Long id);
+
+    AjaxResult getForeignList(HttpServletRequest request,String secretKey, AkmData akmData);
 }

+ 61 - 0
ruoyi-system/src/main/java/com/ruoyi/system/service/ISysInterfaceForeignService.java

@@ -0,0 +1,61 @@
+package com.ruoyi.system.service;
+
+import java.util.List;
+import com.ruoyi.system.domain.SysInterfaceForeign;
+
+/**
+ * 对外接口调用配置Service接口
+ * 
+ * @author ruoyi
+ * @date 2022-10-31
+ */
+public interface ISysInterfaceForeignService 
+{
+    /**
+     * 查询对外接口调用配置
+     * 
+     * @param id 对外接口调用配置主键
+     * @return 对外接口调用配置
+     */
+    public SysInterfaceForeign selectSysInterfaceForeignById(Long id);
+
+    /**
+     * 查询对外接口调用配置列表
+     * 
+     * @param sysInterfaceForeign 对外接口调用配置
+     * @return 对外接口调用配置集合
+     */
+    public List<SysInterfaceForeign> selectSysInterfaceForeignList(SysInterfaceForeign sysInterfaceForeign);
+
+    /**
+     * 新增对外接口调用配置
+     * 
+     * @param sysInterfaceForeign 对外接口调用配置
+     * @return 结果
+     */
+    public int insertSysInterfaceForeign(SysInterfaceForeign sysInterfaceForeign);
+
+    /**
+     * 修改对外接口调用配置
+     * 
+     * @param sysInterfaceForeign 对外接口调用配置
+     * @return 结果
+     */
+    public int updateSysInterfaceForeign(SysInterfaceForeign sysInterfaceForeign);
+
+    /**
+     * 批量删除对外接口调用配置
+     * 
+     * @param ids 需要删除的对外接口调用配置主键集合
+     * @return 结果
+     */
+    public int deleteSysInterfaceForeignByIds(Long[] ids);
+
+    /**
+     * 删除对外接口调用配置信息
+     * 
+     * @param id 对外接口调用配置主键
+     * @return 结果
+     */
+    public int deleteSysInterfaceForeignById(Long id);
+}

+ 19 - 4
ruoyi-system/src/main/java/com/ruoyi/system/service/Task.java

@@ -11,6 +11,7 @@ import com.ruoyi.system.domain.*;
 import com.ruoyi.system.mapper.AkmDataMapper;
 import com.ruoyi.system.mapper.KeyPeopleInfoMapper;
 import com.ruoyi.system.mapper.SysDeptMapper;
+import com.ruoyi.system.mapper.SysInterfaceForeignMapper;
 import com.ruoyi.system.utils.ExcelUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.scheduling.annotation.Scheduled;
@@ -34,6 +35,8 @@ public class Task {
     private KeyPeopleInfoMapper keyPeopleInfoMapper;
     @Resource
     private AkmDataMapper akmDataMapper;
+    @Resource
+    private SysInterfaceForeignMapper sysInterfaceForeignMapper;
 
     /***
      * 邮件发送(定时比对数据后发送邮件)
@@ -210,15 +213,15 @@ public class Task {
                         "15156696045@139.com");*/
                 MailUtil.send(tos2, "会员积分实时变动通知", sb.toString(), true);
             }
-            if(b1){
+            /*if(b1){
                 ArrayList<String> tos1 = CollUtil.newArrayList(
                         "qsxzhb@126.com",
                         "731020@qq.com","1176443192@qq.com");
-                /*ArrayList<String> tos1 = CollUtil.newArrayList(
+                *//*ArrayList<String> tos1 = CollUtil.newArrayList(
                         "1434899932@qq.com",
-                        "1434745622@qq.com");*/
+                        "1434745622@qq.com");*//*
                 MailUtil.send(tos1, "会员积分实时变动通知", sb1.toString(), true);
-            }
+            }*/
 
             //String path = ExcelUtils.getInstance().createExcel(mapList, "核酸对比数据", "对比数据");
             /*MailUtil.send("qsxzhb@126.com", "会员积分实时变动通知", "时间:"+startTime+"--"+endTime, true,
@@ -235,5 +238,17 @@ public class Task {
         }
     }
 
+    /**
+     * 定时重置查询次数
+     */
+    @Scheduled(cron = "0 1 0 * * ? ")
+    public void reset() {
+        List<SysInterfaceForeign> interfaceForeignList = sysInterfaceForeignMapper.selectSysInterfaceForeignList(new SysInterfaceForeign());
+        for (SysInterfaceForeign sysInterfaceForeign : interfaceForeignList) {
+            sysInterfaceForeign.setRemainingNumber(sysInterfaceForeign.getNumber());
+            sysInterfaceForeignMapper.updateSysInterfaceForeign(sysInterfaceForeign);
+        }
+    }
+
 
 }

+ 48 - 2
ruoyi-system/src/main/java/com/ruoyi/system/service/impl/AkmDataServiceImpl.java

@@ -1,9 +1,13 @@
 package com.ruoyi.system.service.impl;
 
+import java.util.Arrays;
 import java.util.List;
 
 import com.ruoyi.common.core.domain.AjaxResult;
 import com.ruoyi.common.utils.StringUtils;
+import com.ruoyi.system.domain.SysInterfaceForeign;
+import com.ruoyi.system.mapper.SysInterfaceForeignMapper;
+import com.ruoyi.system.utils.IpUtils;
 import org.apache.ibatis.session.ExecutorType;
 import org.apache.ibatis.session.SqlSession;
 import org.apache.ibatis.session.SqlSessionFactory;
@@ -14,6 +18,7 @@ import com.ruoyi.system.domain.AkmData;
 import com.ruoyi.system.service.IAkmDataService;
 
 import javax.annotation.Resource;
+import javax.servlet.http.HttpServletRequest;
 
 /**
  * 安康码扫码地点Service业务层处理
@@ -27,8 +32,8 @@ public class AkmDataServiceImpl implements IAkmDataService
     @Autowired
     private AkmDataMapper akmDataMapper;
 
-    @Resource
-    private SqlSessionFactory sqlSessionFactory;
+    @Autowired
+    private SysInterfaceForeignMapper sysInterfaceForeignMapper;
 
     /**
      * 查询安康码扫码地点
@@ -42,6 +47,7 @@ public class AkmDataServiceImpl implements IAkmDataService
         return akmDataMapper.selectAkmDataById(id);
     }
 
+
     /**
      * 查询安康码扫码地点列表
      * 
@@ -54,6 +60,45 @@ public class AkmDataServiceImpl implements IAkmDataService
         return akmDataMapper.selectAkmDataList(akmData);
     }
 
+    @Override
+    public AjaxResult getForeignList(HttpServletRequest request, String secretKey, AkmData akmData) {
+
+        //根据秘钥查询配置信息
+        SysInterfaceForeign sysInterfaceForeign = sysInterfaceForeignMapper.getForeignByKey(secretKey);
+        if(sysInterfaceForeign==null){
+            return AjaxResult.error("秘钥错误");
+        }
+
+
+        //获取客户端ip
+        System.out.println("访问接口ip--------------------------------------------------------");
+        String ip = IpUtils.getIp2(request);
+        System.out.println("访问接口ip---"+ip);
+        if(!sysInterfaceForeign.getIp().contains(ip)){
+            return AjaxResult.error("未授权ip");
+        }
+
+
+        //获取授权的设备id
+        List<String> equipIdList = Arrays.asList(sysInterfaceForeign.getEquipId().split(","));
+        if(equipIdList==null || equipIdList.size()<=0){
+            return AjaxResult.success("无授权设备");
+        }
+
+        //判断是否还有次数
+        if(sysInterfaceForeign.getRemainingNumber()==0){
+            return AjaxResult.success("当天查询次数已用完");
+        }
+        akmData.setEquipIdList(equipIdList);
+        List<AkmData> akmDataList = akmDataMapper.selectAkmDataList(akmData);
+
+        if(sysInterfaceForeign.getRemainingNumber()>0){
+            sysInterfaceForeign.setRemainingNumber(sysInterfaceForeign.getRemainingNumber()-1);
+            sysInterfaceForeignMapper.updateSysInterfaceForeign(sysInterfaceForeign);
+        }
+        return AjaxResult.success(akmDataList);
+    }
+
     /**
      * 新增安康码扫码地点
      * 
@@ -120,4 +165,5 @@ public class AkmDataServiceImpl implements IAkmDataService
     {
         return akmDataMapper.deleteAkmDataById(id);
     }
+
 }

+ 190 - 0
ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysInterfaceForeignServiceImpl.java

@@ -0,0 +1,190 @@
+package com.ruoyi.system.service.impl;
+
+import java.util.*;
+
+import com.alibaba.fastjson2.JSON;
+import com.alibaba.fastjson2.JSONArray;
+import com.alibaba.fastjson2.JSONObject;
+import com.ruoyi.common.utils.StringUtils;
+import com.ruoyi.common.utils.uuid.IdUtils;
+import org.apache.poi.ss.formula.functions.T;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+import com.ruoyi.system.mapper.SysInterfaceForeignMapper;
+import com.ruoyi.system.domain.SysInterfaceForeign;
+import com.ruoyi.system.service.ISysInterfaceForeignService;
+
+/**
+ * 对外接口调用配置Service业务层处理
+ *
+ * @author ruoyi
+ * @date 2022-10-31
+ */
+@Service
+public class SysInterfaceForeignServiceImpl implements ISysInterfaceForeignService {
+    @Autowired
+    private SysInterfaceForeignMapper sysInterfaceForeignMapper;
+
+    /**
+     * 查询对外接口调用配置
+     *
+     * @param id 对外接口调用配置主键
+     * @return 对外接口调用配置
+     */
+    @Override
+    public SysInterfaceForeign selectSysInterfaceForeignById(Long id) {
+        SysInterfaceForeign interfaceForeign = sysInterfaceForeignMapper.selectSysInterfaceForeignById(id);
+        List<String> ipLis = Arrays.asList(interfaceForeign.getIp().split(","));
+        List<Map<Object,String>> ipList = new ArrayList<>();
+        for (String ipLi : ipLis) {
+            Map<Object,String> map = new HashMap<>();
+            map.put("ip",ipLi);
+            ipList.add(map);
+        }
+        interfaceForeign.setIpList(ipList);
+
+        List<String> equipIds = Arrays.asList(interfaceForeign.getEquipId().split(","));
+        List<Map<Object,String>> equipIdList = new ArrayList<>();
+        for (String equip : equipIds) {
+            Map<Object,String> map = new HashMap<>();
+            map.put("equipId",equip);
+            equipIdList.add(map);
+        }
+        interfaceForeign.setEquipIdList(equipIdList);
+
+        return interfaceForeign;
+    }
+
+    /**
+     * 查询对外接口调用配置列表
+     *
+     * @param sysInterfaceForeign 对外接口调用配置
+     * @return 对外接口调用配置
+     */
+    @Override
+    public List<SysInterfaceForeign> selectSysInterfaceForeignList(SysInterfaceForeign sysInterfaceForeign) {
+        List<SysInterfaceForeign> sysInterfaceForeignList = sysInterfaceForeignMapper.selectSysInterfaceForeignList(sysInterfaceForeign);
+        for (SysInterfaceForeign interfaceForeign : sysInterfaceForeignList) {
+            List<String> ipLis = Arrays.asList(interfaceForeign.getIp().split(","));
+            List<Map<Object,String>> ipList = new ArrayList<>();
+            for (String ipLi : ipLis) {
+                Map<Object,String> map = new HashMap<>();
+                map.put("ip",ipLi);
+                ipList.add(map);
+            }
+            interfaceForeign.setIpList(ipList);
+
+            List<String> equipIds = Arrays.asList(interfaceForeign.getEquipId().split(","));
+            List<Map<Object,String>> equipIdList = new ArrayList<>();
+            for (String equip : equipIds) {
+                Map<Object,String> map = new HashMap<>();
+                map.put("equipId",equip);
+                equipIdList.add(map);
+            }
+            interfaceForeign.setEquipIdList(equipIdList);
+        }
+        return sysInterfaceForeignList;
+    }
+
+    /**
+     * 新增对外接口调用配置
+     *
+     * @param sysInterfaceForeign 对外接口调用配置
+     * @return 结果
+     */
+    @Override
+    public int insertSysInterfaceForeign(SysInterfaceForeign sysInterfaceForeign) {
+        if (sysInterfaceForeign.getEquipIdList() != null && sysInterfaceForeign.getEquipIdList().size() > 0) {
+            StringBuilder sb = new StringBuilder();
+
+            for (int i = 0; i < sysInterfaceForeign.getEquipIdList().size(); i++) {
+                String equipId = sysInterfaceForeign.getEquipIdList().get(i).toString();
+                if (i == 0) {
+                    sb.append(equipId.substring(equipId.indexOf("=") + 1, equipId.length() - 1));
+                } else {
+                    sb.append(",").append(equipId.substring(equipId.indexOf("=") + 1, equipId.length() - 1));
+                }
+            }
+
+            sysInterfaceForeign.setEquipId(sb.toString());
+        }
+
+        if (sysInterfaceForeign.getIpList() != null && sysInterfaceForeign.getEquipIdList().size() > 0) {
+
+            StringBuilder sb = new StringBuilder();
+            for (int i = 0; i < sysInterfaceForeign.getIpList().size(); i++) {
+                String ip = sysInterfaceForeign.getIpList().get(i).toString();
+                if (i == 0) {
+                    sb.append(ip.substring(ip.indexOf("=") + 1, ip.length() - 1));
+                } else {
+                    sb.append(",").append(ip.substring(ip.indexOf("=") + 1, ip.length() - 1));
+                }
+            }
+            sysInterfaceForeign.setIp(sb.toString());
+        }
+
+        //生成秘钥(32位UUID)
+        sysInterfaceForeign.setSecretKey(IdUtils.simpleUUID());
+        return sysInterfaceForeignMapper.insertSysInterfaceForeign(sysInterfaceForeign);
+    }
+
+    /**
+     * 修改对外接口调用配置
+     *
+     * @param sysInterfaceForeign 对外接口调用配置
+     * @return 结果
+     */
+    @Override
+    public int updateSysInterfaceForeign(SysInterfaceForeign sysInterfaceForeign) {
+        if (sysInterfaceForeign.getEquipIdList() != null && sysInterfaceForeign.getEquipIdList().size() > 0) {
+            StringBuilder sb = new StringBuilder();
+            for (int i = 0; i < sysInterfaceForeign.getEquipIdList().size(); i++) {
+                String equipId = sysInterfaceForeign.getEquipIdList().get(i).toString();
+                if (i == 0) {
+                    sb.append(equipId.substring(equipId.indexOf("=") + 1, equipId.length() - 1));
+                } else {
+                    sb.append(",").append(equipId.substring(equipId.indexOf("=") + 1, equipId.length() - 1));
+                }
+            }
+
+            sysInterfaceForeign.setEquipId(sb.toString());
+        }
+
+        if (sysInterfaceForeign.getIpList() != null && sysInterfaceForeign.getEquipIdList().size() > 0) {
+
+            StringBuilder sb = new StringBuilder();
+            for (int i = 0; i < sysInterfaceForeign.getIpList().size(); i++) {
+                String ip = sysInterfaceForeign.getIpList().get(i).toString();
+                if (i == 0) {
+                    sb.append(ip.substring(ip.indexOf("=") + 1, ip.length() - 1));
+                } else {
+                    sb.append(",").append(ip.substring(ip.indexOf("=") + 1, ip.length() - 1));
+                }
+            }
+            sysInterfaceForeign.setIp(sb.toString());
+        }
+        return sysInterfaceForeignMapper.updateSysInterfaceForeign(sysInterfaceForeign);
+    }
+
+    /**
+     * 批量删除对外接口调用配置
+     *
+     * @param ids 需要删除的对外接口调用配置主键
+     * @return 结果
+     */
+    @Override
+    public int deleteSysInterfaceForeignByIds(Long[] ids) {
+        return sysInterfaceForeignMapper.deleteSysInterfaceForeignByIds(ids);
+    }
+
+    /**
+     * 删除对外接口调用配置信息
+     *
+     * @param id 对外接口调用配置主键
+     * @return 结果
+     */
+    @Override
+    public int deleteSysInterfaceForeignById(Long id) {
+        return sysInterfaceForeignMapper.deleteSysInterfaceForeignById(id);
+    }
+}

+ 26 - 0
ruoyi-system/src/main/java/com/ruoyi/system/utils/IpUtils.java

@@ -0,0 +1,26 @@
+package com.ruoyi.system.utils;
+
+import com.ruoyi.common.utils.StringUtils;
+
+import javax.servlet.http.HttpServletRequest;
+
+public class IpUtils {
+
+    public static String getIp2(HttpServletRequest request) {
+        String ip = request.getHeader("X-Forwarded-For");
+        if(StringUtils.isNotEmpty(ip) && !"unKnown".equalsIgnoreCase(ip)){
+            //多次反向代理后会有多个ip值,第一个ip才是真实ip
+            int index = ip.indexOf(",");
+            if(index != -1){
+                return ip.substring(0,index);
+            }else{
+                return ip;
+            }
+        }
+        ip = request.getHeader("X-Real-IP");
+        if(StringUtils.isNotEmpty(ip) && !"unKnown".equalsIgnoreCase(ip)){
+            return ip;
+        }
+        return request.getRemoteAddr();
+    }
+}

+ 13 - 0
ruoyi-system/src/main/resources/mapper/system/AkmDataMapper.xml

@@ -43,6 +43,19 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
             <if test="state != null  and state != ''"> and state = #{state}</if>
             <if test="temperature != null  and temperature != ''"> and temperature = #{temperature}</if>
             <if test="belongsUser != null  and belongsUser != ''"> and belongs_user = #{belongsUser}</if>
+            <if test="startTime != null  and startTime != '' and startTime != 'null'">and
+                DATE_FORMAT(collect_time,'%Y-%m-%d %H:%i:%s') &gt;= DATE_FORMAT(#{startTime},'%Y-%m-%d %H:%i:%s')
+            </if>
+            <if test="endTime != null  and endTime != ''  and endTime != 'null'">and
+                DATE_FORMAT(collect_time,'%Y-%m-%d %H:%i:%s') &lt;= DATE_FORMAT(#{endTime},'%Y-%m-%d %H:%i:%s')
+            </if>
+            <if test="equipIdList != null">
+            and equip_id in
+            <foreach item="equipId" collection="equipIdList" open="(" separator="," close=")">
+                #{equipId}
+            </foreach>
+            </if>
+
         </where>
     </select>
     

+ 82 - 0
ruoyi-system/src/main/resources/mapper/system/SysInterfaceForeignMapper.xml

@@ -0,0 +1,82 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<!DOCTYPE mapper
+PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
+"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
+<mapper namespace="com.ruoyi.system.mapper.SysInterfaceForeignMapper">
+    
+    <resultMap type="SysInterfaceForeign" id="SysInterfaceForeignResult">
+        <result property="id"    column="id"    />
+        <result property="name"    column="name"    />
+        <result property="secretKey"    column="secret_key"    />
+        <result property="ip"    column="ip"    />
+        <result property="equipId"    column="equip_id"    />
+        <result property="number"    column="number"    />
+        <result property="remainingNumber"    column="remaining_number"    />
+    </resultMap>
+
+    <sql id="selectSysInterfaceForeignVo">
+        select id, name, secret_key, ip, equip_id, number, remaining_number from sys_interface_foreign
+    </sql>
+
+    <select id="selectSysInterfaceForeignList" parameterType="SysInterfaceForeign" resultMap="SysInterfaceForeignResult">
+        <include refid="selectSysInterfaceForeignVo"/>
+        <where>  
+            <if test="name != null  and name != ''"> and name like concat('%', #{name}, '%')</if>
+        </where>
+    </select>
+    
+    <select id="selectSysInterfaceForeignById" parameterType="Long" resultMap="SysInterfaceForeignResult">
+        <include refid="selectSysInterfaceForeignVo"/>
+        where id = #{id}
+    </select>
+    <select id="getForeignByKey" resultMap="SysInterfaceForeignResult">
+        <include refid="selectSysInterfaceForeignVo"/>
+        where secret_key = #{secretKey}
+    </select>
+
+    <insert id="insertSysInterfaceForeign" parameterType="SysInterfaceForeign">
+        insert into sys_interface_foreign
+        <trim prefix="(" suffix=")" suffixOverrides=",">
+            <if test="id != null">id,</if>
+            <if test="name != null">name,</if>
+            <if test="secretKey != null">secret_key,</if>
+            <if test="ip != null">ip,</if>
+            <if test="equipId != null">equip_id,</if>
+            <if test="number != null">number,</if>
+            <if test="remainingNumber != null">remaining_number,</if>
+         </trim>
+        <trim prefix="values (" suffix=")" suffixOverrides=",">
+            <if test="id != null">#{id},</if>
+            <if test="name != null">#{name},</if>
+            <if test="secretKey != null">#{secretKey},</if>
+            <if test="ip != null">#{ip},</if>
+            <if test="equipId != null">#{equipId},</if>
+            <if test="number != null">#{number},</if>
+            <if test="remainingNumber != null">#{remainingNumber},</if>
+         </trim>
+    </insert>
+
+    <update id="updateSysInterfaceForeign" parameterType="SysInterfaceForeign">
+        update sys_interface_foreign
+        <trim prefix="SET" suffixOverrides=",">
+            <if test="name != null">name = #{name},</if>
+            <if test="secretKey != null">secret_key = #{secretKey},</if>
+            <if test="ip != null">ip = #{ip},</if>
+            <if test="equipId != null">equip_id = #{equipId},</if>
+            <if test="number != null">number = #{number},</if>
+            <if test="remainingNumber != null">remaining_number = #{remainingNumber},</if>
+        </trim>
+        where id = #{id}
+    </update>
+
+    <delete id="deleteSysInterfaceForeignById" parameterType="Long">
+        delete from sys_interface_foreign where id = #{id}
+    </delete>
+
+    <delete id="deleteSysInterfaceForeignByIds" parameterType="String">
+        delete from sys_interface_foreign where id in 
+        <foreach item="id" collection="array" open="(" separator="," close=")">
+            #{id}
+        </foreach>
+    </delete>
+</mapper>