浏览代码

新增字典有关接口和用户信息接口bug修改

‘xugp 3 年之前
父节点
当前提交
42435010bb

+ 60 - 8
warning-web/src/main/java/com/gyee/wisdom/alarm/sharding/controller/DatadictionaryController.java

@@ -1,11 +1,13 @@
 package com.gyee.wisdom.alarm.sharding.controller;
 
+import com.baomidou.mybatisplus.core.metadata.IPage;
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.gyee.wisdom.alarm.sharding.entity.Datadictionary;
-import com.gyee.wisdom.alarm.sharding.entity.Equipmentmodel;
-import com.gyee.wisdom.alarm.sharding.entity.WindPowerStation;
-import com.gyee.wisdom.alarm.sharding.mapper.DatadictionaryMapper;
-import com.gyee.wisdom.alarm.sharding.service.EquipmentmodelService;
-import com.gyee.wisdom.alarm.sharding.service.WindpowerstationService;
+import com.gyee.wisdom.alarm.sharding.service.DatadictionaryService;
+import com.gyee.wisdom.alarm.sharding.util.ResponseWrapper;
+import io.swagger.annotations.Api;
+import io.swagger.annotations.ApiOperation;
+import io.swagger.annotations.ApiParam;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.web.bind.annotation.*;
@@ -13,19 +15,69 @@ import org.springframework.web.bind.annotation.*;
 import java.util.List;
 
 /**
- * 字典接口
+ * @descrition:
+ * @author:Xugp
+ * @date:2022-05-12
  */
 @Slf4j
 @RestController
 @RequestMapping("/datadictionary")
 @CrossOrigin
+@Api(tags = {"字典接口"})
 public class DatadictionaryController {
+
     @Autowired
-    private DatadictionaryMapper datadictionaryMapper;
+    private DatadictionaryService datadictionaryService;
 
     @GetMapping()
     public List<Datadictionary> getAllDatadictionary() {
-        List<Datadictionary> datadictionaries = datadictionaryMapper.getAllDatadictionary();
+        List<Datadictionary> datadictionaries = datadictionaryService.getAllDatadictionary();
         return datadictionaries;
     }
+
+    @ApiOperation("分页查询字典")
+    @GetMapping(value = "/page")
+    public ResponseWrapper queryByPage(
+            @ApiParam(value = "当前页") @RequestParam(value = "pagenum") Integer pageNum,
+            @ApiParam(value = "分页大小") @RequestParam(value = "pagesize") Integer pageSize,
+            @ApiParam(value = "字典名称") @RequestParam(value = "name", required = false) String name,
+            @ApiParam(value = "字典类型") @RequestParam(value = "category", required = false) String category
+    ) {
+        Page<Datadictionary> page = new Page(pageNum, pageSize);
+        IPage<Datadictionary> pageResult = datadictionaryService.pageQueryAll(page, name,category);
+
+        return ResponseWrapper.success("请求成功",pageResult);
+    }
+
+    @ApiOperation("新增或修改字典")
+    @PostMapping(value = "/saveorupdate")
+    @ResponseBody
+    public ResponseWrapper saveDatadictionary(@ApiParam(value = "字典对象") @RequestBody Datadictionary datadictionary){
+        ResponseWrapper<Datadictionary> wrapper = null;
+        int result = datadictionaryService.saveOrUpdateDatadictionary(datadictionary);
+        if (result <= 0) {
+            wrapper = ResponseWrapper.error("操作数据库失败");
+        }
+        else {
+            wrapper = ResponseWrapper.success("操作数据库成功");
+        }
+        return wrapper;
+    }
+
+    @ApiOperation("删除字典")
+    @DeleteMapping(value = "/{id}")
+    @ResponseBody
+    public ResponseWrapper deleteDatadictionary(
+            @ApiParam(value = "字典编号") @PathVariable("id") String id) {
+        ResponseWrapper wrapper = null;
+        int s = datadictionaryService.deleteDatadictionary(id);
+        if (s > 0) {
+            wrapper = ResponseWrapper.success("删除成功!", s);
+            return wrapper;
+        } else {
+            wrapper = ResponseWrapper.error("删除失败!");
+            return wrapper;
+        }
+
+    }
 }

+ 10 - 3
warning-web/src/main/java/com/gyee/wisdom/alarm/sharding/service/AlarmUserService.java

@@ -89,9 +89,16 @@ public class AlarmUserService {
 
     public int updateUser(AlarmUser newData){
         String newpassword = newData.getNewPassWord();
-        //md5加密,加密盐为gdnxfd
-        String md5str = DigestUtils.md5Hex(newpassword + "gdnxfd");
-        newData.setPassWord(md5str);
+        if(newpassword == null || newpassword.length() == 0){
+            AlarmUser alarmUser = alarmUserMapper.selectById(newData.getId());
+            newpassword = alarmUser.getPassWord();
+            newData.setPassWord(newpassword);
+        }
+        else {
+            //md5加密,加密盐为gdnxfd
+            String md5str = DigestUtils.md5Hex(newpassword + "gdnxfd");
+            newData.setPassWord(md5str);
+        }
         int result = alarmUserMapper.updateById(newData);
         return result;
     }

+ 59 - 0
warning-web/src/main/java/com/gyee/wisdom/alarm/sharding/service/DatadictionaryService.java

@@ -0,0 +1,59 @@
+package com.gyee.wisdom.alarm.sharding.service;
+
+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.gyee.wisdom.alarm.sharding.entity.Datadictionary;
+import com.gyee.wisdom.alarm.sharding.mapper.DatadictionaryMapper;
+import com.gyee.wisdom.alarm.sharding.util.StringUtil;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+import java.util.List;
+
+
+@Service
+@Slf4j
+public class DatadictionaryService {
+
+    @Autowired
+    private DatadictionaryMapper datadictionaryMapper;
+
+    public IPage<Datadictionary> pageQueryAll(Page<Datadictionary> page, String name, String category) {
+        QueryWrapper<Datadictionary> wrapper = new QueryWrapper<>();
+        if (StringUtil.isNotBlank(name))
+            wrapper.like("name", name);
+        if (StringUtil.isNotBlank(category))
+            wrapper.eq("category", category);
+        return datadictionaryMapper.selectPage(page, wrapper);
+    }
+
+    public List<Datadictionary> getAllDatadictionary() {
+        return datadictionaryMapper.getAllDatadictionary();
+    }
+
+    public int saveOrUpdateDatadictionary(Datadictionary datadictionary) {
+        int result = 0;
+        if(datadictionary.getId()<=0){
+            QueryWrapper<Datadictionary> wrapper = new QueryWrapper<>();
+            wrapper.orderByDesc("id");
+            List<Datadictionary> datadictionaries = datadictionaryMapper.selectList(wrapper);
+            datadictionary.setId(datadictionaries.get(0).getId()+1);
+            result = datadictionaryMapper.insert(datadictionary);
+        }else {
+            Datadictionary datadictionary1 = datadictionaryMapper.selectById(datadictionary.getId());
+            if (datadictionary1!=null){
+                result = datadictionaryMapper.updateById(datadictionary);
+            }
+            else {
+                result = datadictionaryMapper.insert(datadictionary);
+            }
+        }
+        return result;
+    }
+
+    public int deleteDatadictionary(String id) {
+        return datadictionaryMapper.deleteById(id);
+    }
+}