Browse Source

add function

hlf 1 year ago
parent
commit
ef575896ba

+ 18 - 16
src/main/java/com/gyee/table/config/WebMvcConfig.java

@@ -8,24 +8,26 @@ import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
  * 拦截器
  */
 @Configuration
-public class WebMvcConfig implements  WebMvcConfigurer  {
+public class WebMvcConfig implements WebMvcConfigurer {
 
-	/** 解决跨域问题 **/
-	@Override
-	public void addCorsMappings(CorsRegistry registry){
-		// 设置允许跨域的路由
+    /**
+     * 解决跨域问题
+     **/
+    @Override
+    public void addCorsMappings(CorsRegistry registry) {
+        // 设置允许跨域的路由
         registry.addMapping("/**")
-			// 设置允许跨域请求的域名
-			.allowedOriginPatterns("*")
-			// 是否允许证书
-			.allowCredentials(true)
-			// 设置允许的方法
-			.allowedMethods("GET", "POST", "DELETE", "PUT")
-			// 设置允许的header属性
-			.allowedHeaders("*")
-				// 跨域允许时间
-			.maxAge(3600);
-	}
+                // 设置允许跨域请求的域名
+                .allowedOriginPatterns("*")
+                // 是否允许证书
+                .allowCredentials(true)
+                // 设置允许的方法
+                .allowedMethods("GET", "POST", "DELETE", "PUT")
+                // 设置允许的header属性
+                .allowedHeaders("*")
+                // 跨域允许时间
+                .maxAge(3600);
+    }
 
 	/*@Override
 	public void configureMessageConverters(List<HttpMessageConverter<?>> converters) {

+ 9 - 9
src/main/java/com/gyee/table/controller/ComponentInformationController.java

@@ -1,5 +1,6 @@
 package com.gyee.table.controller;
 
+import cn.hutool.core.util.IdUtil;
 import com.alibaba.fastjson2.JSONObject;
 import com.github.pagehelper.PageHelper;
 import com.github.pagehelper.PageInfo;
@@ -8,8 +9,7 @@ import com.gyee.table.entity.Configurationinfo;
 import com.gyee.table.result.Result;
 import com.gyee.table.service.IComponentModificationRecordService;
 import com.gyee.table.service.IConfigurationinfoService;
-import com.gyee.table.utils.SnowflakeIdUtils;
-import com.gyee.table.utils.TableDataInfo;
+import com.gyee.table.vo.TableDataInfo;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.web.bind.annotation.*;
 
@@ -19,7 +19,7 @@ import java.util.List;
 /**
  * @author hlf
  * @date 2023/3/20 10:03
- * 文件说明:
+ * 文件说明:组件管理操作接口
  */
 @Slf4j
 @RestController
@@ -33,8 +33,9 @@ public class ComponentInformationController {
     private IComponentModificationRecordService componentModificationRecordService;
 
     /**
-     * 查询组件信息列表
+     * 获取组件管理信息列表
      *
+     * @param configurationinfo
      * @return
      */
     @GetMapping("/componentList")
@@ -52,7 +53,7 @@ public class ComponentInformationController {
      */
     @PostMapping("/addComponent")
     public JSONObject addComponent(@RequestBody Configurationinfo configurationinfo) {
-        configurationinfo.setId(Long.toString(new SnowflakeIdUtils(1, 3).nextId()));
+        configurationinfo.setId(Long.toString(IdUtil.getSnowflake(1, 1).nextId()));
         configurationinfoService.save(configurationinfo);
         return Result.success();
     }
@@ -77,7 +78,7 @@ public class ComponentInformationController {
     /**
      * 删除组件信息
      *
-     * @param id
+     * @param id 组件ID
      * @return
      */
     @DeleteMapping("/deleteComponent/{id}")
@@ -89,9 +90,8 @@ public class ComponentInformationController {
     /**
      * 响应请求分页数据
      */
-    @SuppressWarnings({ "rawtypes", "unchecked" })
-    protected TableDataInfo getDataTable(List<?> list)
-    {
+    @SuppressWarnings({"rawtypes", "unchecked"})
+    protected TableDataInfo getDataTable(List<?> list) {
         TableDataInfo rspData = new TableDataInfo();
         rspData.setCode(200);
         rspData.setRows(list);

+ 3 - 2
src/main/java/com/gyee/table/controller/ElectricalTestingPointController.java

@@ -14,6 +14,7 @@ import java.util.List;
 @RequestMapping("/electrical")
 @CrossOrigin
 public class ElectricalTestingPointController {
+
     @Autowired
     protected ElectricalTestingPointService electricalTestingPointService;
 
@@ -28,8 +29,8 @@ public class ElectricalTestingPointController {
      */
     @GetMapping("/electricaltestingpoint")
     public List<ElectricalDto> getElectricalTestingPoint(
-//            @RequestParam(value = "pagenum",required = true) Integer pageNum,
-//            @RequestParam(value = "pagesize",required = true) Integer pageSize,
+            //@RequestParam(value = "pagenum",required = true) Integer pageNum,
+            //@RequestParam(value = "pagesize",required = true) Integer pageSize,
             @RequestParam(value = "windpowerstationid", required = true) String windpowerstationid,
             @RequestParam(value = "name", required = false) String name,
             @RequestParam(value = "uniformcode", required = false) String uniformcode,

+ 7 - 1
src/main/java/com/gyee/table/controller/LoginController.java

@@ -15,7 +15,7 @@ import javax.annotation.Resource;
 /**
  * @author hlf
  * @date 2023/3/28 14:55
- * 文件说明:
+ * 文件说明:用户登录操作接口
  */
 @Controller
 public class LoginController {
@@ -23,6 +23,12 @@ public class LoginController {
     @Resource
     private ISysUserService userService;
 
+    /**
+     * 登录
+     * @param username 用户名
+     * @param password 密码
+     * @return
+     */
     @PostMapping("/toLogin")
     @ResponseBody
     public AjaxResult jwtLogin(String username, String password) {

+ 49 - 0
src/main/java/com/gyee/table/controller/SysUserController.java

@@ -0,0 +1,49 @@
+package com.gyee.table.controller;
+
+import com.alibaba.fastjson2.JSONObject;
+import com.gyee.table.entity.SysUser;
+import com.gyee.table.result.Result;
+import com.gyee.table.service.ISysUserService;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.web.bind.annotation.PostMapping;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RequestParam;
+import org.springframework.web.bind.annotation.RestController;
+
+import javax.annotation.Resource;
+
+/**
+ * @author hlf
+ * @date 2023/3/29 15:58
+ * 文件说明:用户管理操作接口
+ */
+@Slf4j
+@RestController
+@RequestMapping("/suc")
+public class SysUserController {
+
+    @Resource
+    private ISysUserService userService;
+
+    /**
+     * 修改密码
+     *
+     * @param id 用户ID
+     * @param originalPassword 旧密码
+     * @param newPassword 新密码
+     * @return
+     */
+    @PostMapping("/changePassword")
+    public JSONObject changePassword(@RequestParam(value = "id") String id,
+                                     @RequestParam(value = "originalPassword") String originalPassword,
+                                     @RequestParam(value = "newPassword") String newPassword) {
+        SysUser user = userService.getById(id);
+        if (!originalPassword.equals(user.getPassword())){
+            return Result.error();
+        }
+        user.setPassword(newPassword);
+        userService.updateById(user);
+        return Result.success();
+    }
+
+}

+ 22 - 0
src/main/java/com/gyee/table/entity/Configurationinfo.java

@@ -18,24 +18,46 @@ public class Configurationinfo {
 
     @Id
     private String id;
+    //组件名称
     private String name;
+    //是否需要支持修改背景色
     private String needBg;
+    //是否需要支持修改线条颜色
     private String needColor;
+    //是否需要支持修改线条宽度
     private String needLw;
+    //是否需要支持值映射
     private String needMap;
+    //仅查看已禁用
     private String needMapDone;
+    //组件状态的其他补充描述
     private String otherDesc;
+    //组件状态的其他客制化需求描述
     private String otherNeed;
+    //组件状态描述
     private String stateDesc;
+    //组件的Svg字符串
     private String svg;
+    //是否转换Svg
     private String trSvg;
+    //是否转换Svg
     private String type;
+    //组件上传日期
     private String uploadDate;
+    //上传用户ID
     private String uploadUser;
+    //组件更新日期
     private String updataDate;
+    //修改用户ID
     private String changeUser;
+    //页码
     private Integer pageNum;
+    //每页显示数量
     private Integer pageSize;
+    //上传用户昵称
     private String uploadUserStr;
+    //修改用户昵称
     private String changeUserStr;
+    //权限等级
+    private Integer userAuthority;
 }

+ 6 - 1
src/main/java/com/gyee/table/entity/SysUser.java

@@ -18,10 +18,15 @@ public class SysUser {
 
     @Id
     private String id;
+    //用户名
     private String loginName;
+    //密码
     private String password;
+    //用户昵称
     private String userName;
-    private String userAuthority;
+    //用户权限
+    private Integer userAuthority;
+    //最后登录时间
     private String lastLoginTime;
 
 }

+ 1 - 6
src/main/java/com/gyee/table/service/impl/TableHeaderServiceImpl.java

@@ -7,10 +7,8 @@ import com.gyee.table.entity.TableHeader;
 import com.gyee.table.entity.TableHeaderColumn;
 import com.gyee.table.mapper.TableHeaderMapper;
 import com.gyee.table.service.ITableHeaderService;
-import com.gyee.table.utils.IdWorker;
 import org.springframework.stereotype.Service;
 
-import javax.annotation.Resource;
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.List;
@@ -39,16 +37,13 @@ public class TableHeaderServiceImpl extends ServiceImpl<TableHeaderMapper, Table
     private String[] kun = {};
     private String[] glc = {"过滤词"};
 
-    @Resource
-    private IdWorker idWorker;
-
     @Override
     public List<TableHeaderColumn> getHeader(String headername) {
         List<TableHeaderColumn> tableHeaderColumns = new ArrayList<>();
         int j = random.nextInt(15) + 3;
         for (int i = 0; i < j; i++) {
             TableHeaderColumn thc = new TableHeaderColumn();
-            //thc.setId(idWorker.nextIdStr());
+            //thc.setId(Long.toString(IdUtil.getSnowflake(1, 1).nextId()));
             thc.setType(llx[random.nextInt(3)]);
             thc.setLabel("新表头");
             thc.setWidth("");

+ 0 - 151
src/main/java/com/gyee/table/utils/IdWorker.java

@@ -1,151 +0,0 @@
-package com.gyee.table.utils;
-
-import org.springframework.stereotype.Component;
-
-import java.lang.management.ManagementFactory;
-import java.net.InetAddress;
-import java.net.NetworkInterface;
-
-//雪花算法代码实现
-@Component
-public class IdWorker {
-    // 时间起始标记点,作为基准,一般取系统的最近时间(一旦确定不能变动)
-    private final static long twepoch = 1673490532716L;
-    // 机器标识位数
-    private final static long workerIdBits = 5L;
-    // 数据中心标识位数
-    private final static long datacenterIdBits = 5L;
-    // 机器ID最大值
-    private final static long maxWorkerId = -1L ^ (-1L << workerIdBits);
-    // 数据中心ID最大值
-    private final static long maxDatacenterId = -1L ^ (-1L << datacenterIdBits);
-    // 毫秒内自增位
-    private final static long sequenceBits = 12L;
-    // 机器ID偏左移12位
-    private final static long workerIdShift = sequenceBits;
-    // 数据中心ID左移17位
-    private final static long datacenterIdShift = sequenceBits + workerIdBits;
-    // 时间毫秒左移22位
-    private final static long timestampLeftShift = sequenceBits + workerIdBits + datacenterIdBits;
-
-    private final static long sequenceMask = -1L ^ (-1L << sequenceBits);
-    /* 上次生产id时间戳 */
-    private static long lastTimestamp = -1L;
-    // 0,并发控制
-    private long sequence = 0L;
-
-    private final long workerId;
-    // 数据标识id部分
-    private final long datacenterId;
-
-    public IdWorker(){
-        this.datacenterId = getDatacenterId(maxDatacenterId);
-        this.workerId = getMaxWorkerId(datacenterId, maxWorkerId);
-    }
-    /**
-     * @param workerId
-     *            工作机器ID
-     * @param datacenterId
-     *            序列号
-     */
-    public IdWorker(long workerId, long datacenterId) {
-        if (workerId > maxWorkerId || workerId < 0) {
-            throw new IllegalArgumentException(String.format("worker Id can't be greater than %d or less than 0", maxWorkerId));
-        }
-        if (datacenterId > maxDatacenterId || datacenterId < 0) {
-            throw new IllegalArgumentException(String.format("datacenter Id can't be greater than %d or less than 0", maxDatacenterId));
-        }
-        this.workerId = workerId;
-        this.datacenterId = datacenterId;
-    }
-    /**
-     * 获取下一个ID
-     *
-     * @return
-     */
-    public synchronized long nextId() {
-        long timestamp = timeGen();
-        if (timestamp < lastTimestamp) {
-            throw new RuntimeException(String.format("Clock moved backwards.  Refusing to generate id for %d milliseconds", lastTimestamp - timestamp));
-        }
-
-        if (lastTimestamp == timestamp) {
-            // 当前毫秒内,则+1
-            sequence = (sequence + 1) & sequenceMask;
-            if (sequence == 0) {
-                // 当前毫秒内计数满了,则等待下一秒
-                timestamp = tilNextMillis(lastTimestamp);
-            }
-        } else {
-            sequence = 0L;
-        }
-        lastTimestamp = timestamp;
-        // ID偏移组合生成最终的ID,并返回ID
-        long nextId = ((timestamp - twepoch) << timestampLeftShift)
-                | (datacenterId << datacenterIdShift)
-                | (workerId << workerIdShift) | sequence;
-
-        return nextId;
-    }
-
-    public String nextIdStr(){
-        return String.valueOf(this.nextId());
-    }
-
-    private long tilNextMillis(final long lastTimestamp) {
-        long timestamp = this.timeGen();
-        while (timestamp <= lastTimestamp) {
-            timestamp = this.timeGen();
-        }
-        return timestamp;
-    }
-
-    private long timeGen() {
-        return System.currentTimeMillis();
-    }
-
-    /**
-     * <p>
-     * 获取 maxWorkerId
-     * </p>
-     */
-    protected static long getMaxWorkerId(long datacenterId, long maxWorkerId) {
-        StringBuffer mpid = new StringBuffer();
-        mpid.append(datacenterId);
-        String name = ManagementFactory.getRuntimeMXBean().getName();
-        if (!name.isEmpty()) {
-            /*
-             * GET jvmPid
-             */
-            mpid.append(name.split("@")[0]);
-        }
-        /*
-         * MAC + PID 的 hashcode 获取16个低位
-         */
-        return (mpid.toString().hashCode() & 0xffff) % (maxWorkerId + 1);
-    }
-
-    /**
-     * <p>
-     * 数据标识id部分
-     * </p>
-     */
-    protected static long getDatacenterId(long maxDatacenterId) {
-        long id = 0L;
-        try {
-            InetAddress ip = InetAddress.getLocalHost();
-            NetworkInterface network = NetworkInterface.getByInetAddress(ip);
-            if (network == null) {
-                id = 1L;
-            } else {
-                byte[] mac = network.getHardwareAddress();
-                id = ((0x000000FF & (long) mac[mac.length - 1])
-                        | (0x0000FF00 & (((long) mac[mac.length - 2]) << 8))) >> 6;
-                id = id % (maxDatacenterId + 1);
-            }
-        } catch (Exception e) {
-            System.out.println(" getDatacenterId: " + e.getMessage());
-        }
-        return id;
-    }
-}

+ 0 - 178
src/main/java/com/gyee/table/utils/SnowflakeIdUtils.java

@@ -1,178 +0,0 @@
-package com.gyee.table.utils;
-
-/**
- * @author hlf
- * @date 2023/3/23 14:15
- * 文件说明:自动生成雪花唯一ID
- */
-public class SnowflakeIdUtils {
-
-    /**
-     * 开始时间截 (2015-01-01)
-     */
-    private final long twepoch = 1420041600000L;
-
-    /**
-     * 机器id所占的位数
-     */
-    private final long workerIdBits = 5L;
-
-    /**
-     * 数据标识id所占的位数
-     */
-    private final long datacenterIdBits = 5L;
-
-    /**
-     * 支持的最大机器id,结果是31 (这个移位算法可以很快的计算出几位二进制数所能表示的最大十进制数)
-     */
-    private final long maxWorkerId = -1L ^ (-1L << workerIdBits);
-
-    /**
-     * 支持的最大数据标识id,结果是31
-     */
-    private final long maxDatacenterId = -1L ^ (-1L << datacenterIdBits);
-
-    /**
-     * 序列在id中占的位数
-     */
-    private final long sequenceBits = 12L;
-
-    /**
-     * 机器ID向左移12位
-     */
-    private final long workerIdShift = sequenceBits;
-
-    /**
-     * 数据标识id向左移17位(12+5)
-     */
-    private final long datacenterIdShift = sequenceBits + workerIdBits;
-
-    /**
-     * 时间截向左移22位(5+5+12)
-     */
-    private final long timestampLeftShift = sequenceBits + workerIdBits + datacenterIdBits;
-
-    /**
-     * 生成序列的掩码,这里为4095 (0b111111111111=0xfff=4095)
-     */
-    private final long sequenceMask = -1L ^ (-1L << sequenceBits);
-
-    /**
-     * 工作机器ID(0~31)
-     */
-    private long workerId;
-
-    /**
-     * 数据中心ID(0~31)
-     */
-    private long datacenterId;
-
-    /**
-     * 毫秒内序列(0~4095)
-     */
-    private long sequence = 0L;
-
-    /**
-     * 上次生成ID的时间截
-     */
-    private long lastTimestamp = -1L;
-
-    //==============================Constructors=====================================
-
-    /**
-     * 构造函数
-     *
-     * @param workerId     工作ID (0~31)
-     * @param datacenterId 数据中心ID (0~31)
-     */
-    public SnowflakeIdUtils(long workerId, long datacenterId) {
-        if (workerId > maxWorkerId || workerId < 0) {
-            throw new IllegalArgumentException(String.format("worker Id can't be greater than %d or less than 0", maxWorkerId));
-        }
-        if (datacenterId > maxDatacenterId || datacenterId < 0) {
-            throw new IllegalArgumentException(String.format("datacenter Id can't be greater than %d or less than 0", maxDatacenterId));
-        }
-        this.workerId = workerId;
-        this.datacenterId = datacenterId;
-    }
-
-    // ==============================Methods==========================================
-
-    /**
-     * 获得下一个ID (该方法是线程安全的)
-     *
-     * @return SnowflakeId
-     */
-    public synchronized long nextId() {
-        long timestamp = timeGen();
-
-        //如果当前时间小于上一次ID生成的时间戳,说明系统时钟回退过这个时候应当抛出异常
-        if (timestamp < lastTimestamp) {
-            throw new RuntimeException(
-                    String.format("Clock moved backwards.  Refusing to generate id for %d milliseconds", lastTimestamp - timestamp));
-        }
-
-        //如果是同一时间生成的,则进行毫秒内序列
-        if (lastTimestamp == timestamp) {
-            sequence = (sequence + 1) & sequenceMask;
-            //毫秒内序列溢出
-            if (sequence == 0) {
-                //阻塞到下一个毫秒,获得新的时间戳
-                timestamp = tilNextMillis(lastTimestamp);
-            }
-        }
-        //时间戳改变,毫秒内序列重置
-        else {
-            sequence = 0L;
-        }
-
-        //上次生成ID的时间截
-        lastTimestamp = timestamp;
-
-        //移位并通过或运算拼到一起组成64位的ID
-        return ((timestamp - twepoch) << timestampLeftShift) //
-                | (datacenterId << datacenterIdShift) //
-                | (workerId << workerIdShift) //
-                | sequence;
-    }
-
-    /**
-     * 阻塞到下一个毫秒,直到获得新的时间戳
-     *
-     * @param lastTimestamp 上次生成ID的时间截
-     * @return 当前时间戳
-     */
-    protected long tilNextMillis(long lastTimestamp) {
-        long timestamp = timeGen();
-        while (timestamp <= lastTimestamp) {
-            timestamp = timeGen();
-        }
-        return timestamp;
-    }
-
-    /**
-     * 返回以毫秒为单位的当前时间
-     *
-     * @return 当前时间(毫秒)
-     */
-    protected long timeGen() {
-        return System.currentTimeMillis();
-    }
-
-    /**
-     * 测试
-     */
-    public static void main(String[] args) {
-        long start = System.currentTimeMillis();
-        SnowflakeIdUtils idWorker = new SnowflakeIdUtils(1, 3);
-        for (int i = 0; i < 50; i++) {
-            long id = idWorker.nextId();
-            System.out.println(Long.toBinaryString(id));
-            System.out.println(id);
-        }
-        long end = System.currentTimeMillis();
-        System.out.println(end - start);
-
-    }
-
-}

+ 1 - 1
src/main/java/com/gyee/table/utils/TableDataInfo.java

@@ -1,4 +1,4 @@
-package com.gyee.table.utils;
+package com.gyee.table.vo;
 
 import java.io.Serializable;
 import java.util.List;

+ 5 - 4
src/main/resources/mappers/Configurationinfo.xml

@@ -32,10 +32,11 @@
         left join sys_user u1 on u1.id = c.upload_user
         left join sys_user u2 on u2.id = c.change_user
         <where>
-            <if test="name != null and name != ''">and name = #{name}</if>
-            <if test="uploadUser != null and uploadUser != ''">and upload_user = #{uploadUser}</if>
-            <if test="changeUser != null and changeUser != ''">and changeUser = #{changeUser}</if>
-            <if test="needMapDone != null">and needMapDone = #{needMapDone}</if>
+            <if test="name != null and name != ''">and c.name = #{name}</if>
+            <if test="uploadUser != null and uploadUser != ''">and c.upload_user = #{uploadUser}</if>
+            <if test="changeUser != null and changeUser != ''">and c.changeUser = #{changeUser}</if>
+            <if test="needMapDone != null">and c.needMapDone = #{needMapDone}</if>
+            <if test="userAuthority != null and userAuthority != ''">and u1.user_authority &lt;= #{userAuthority}</if>
         </where>
     </select>
 </mapper>