Bläddra i källkod

:zap: 优化代码

smallchill 7 år sedan
förälder
incheckning
b2993fac22

+ 1 - 1
src/main/java/org/springblade/modules/develop/controller/CodeController.java

@@ -88,7 +88,7 @@ public class CodeController extends BladeController {
 	 * 删除
 	 */
 	@PostMapping("/remove")
-	@ApiOperation(value = "物理删除", notes = "传入ids", position = 7)
+	@ApiOperation(value = "删除", notes = "传入ids", position = 7)
 	public R remove(@ApiParam(value = "主键集合", required = true) @RequestParam String ids) {
 		return R.status(codeService.removeByIds(Func.toIntList(ids)));
 	}

+ 1 - 1
src/main/java/org/springblade/modules/system/controller/DeptController.java

@@ -101,7 +101,7 @@ public class DeptController extends BladeController {
 	 * 删除
 	 */
 	@PostMapping("/remove")
-	@ApiOperation(value = "物理删除", notes = "传入ids", position = 7)
+	@ApiOperation(value = "删除", notes = "传入ids", position = 7)
 	public R remove(@ApiParam(value = "主键集合", required = true) @RequestParam String ids) {
 		return R.status(deptService.removeByIds(Func.toIntList(ids)));
 	}

+ 7 - 2
src/main/java/org/springblade/modules/system/controller/DictController.java

@@ -27,6 +27,7 @@ import org.springblade.modules.system.entity.Dict;
 import org.springblade.modules.system.service.IDictService;
 import org.springblade.modules.system.vo.DictVO;
 import org.springblade.modules.system.wrapper.DictWrapper;
+import org.springframework.cache.annotation.CacheEvict;
 import org.springframework.web.bind.annotation.*;
 import springfox.documentation.annotations.ApiIgnore;
 
@@ -34,6 +35,9 @@ import javax.validation.Valid;
 import java.util.List;
 import java.util.Map;
 
+import static org.springblade.common.cache.CacheNames.DICT_LIST;
+import static org.springblade.common.cache.CacheNames.DICT_VALUE;
+
 /**
  * 控制器
  *
@@ -94,7 +98,7 @@ public class DictController extends BladeController {
 	@PostMapping("/submit")
 	@ApiOperation(value = "新增或修改", notes = "传入dict", position = 6)
 	public R submit(@Valid @RequestBody Dict dict) {
-		return R.status(dictService.saveOrUpdate(dict));
+		return R.status(dictService.submit(dict));
 	}
 
 
@@ -102,7 +106,8 @@ public class DictController extends BladeController {
 	 * 删除
 	 */
 	@PostMapping("/remove")
-	@ApiOperation(value = "物理删除", notes = "传入ids", position = 7)
+	@CacheEvict(cacheNames = {DICT_LIST, DICT_VALUE})
+	@ApiOperation(value = "删除", notes = "传入ids", position = 7)
 	public R remove(@ApiParam(value = "主键集合", required = true) @RequestParam String ids) {
 		return R.status(dictService.removeByIds(Func.toIntList(ids)));
 	}

+ 1 - 1
src/main/java/org/springblade/modules/system/controller/MenuController.java

@@ -144,7 +144,7 @@ public class MenuController extends BladeController {
 	 * 删除
 	 */
 	@PostMapping("/remove")
-	@ApiOperation(value = "物理删除", notes = "传入ids", position = 9)
+	@ApiOperation(value = "删除", notes = "传入ids", position = 9)
 	public R remove(@ApiParam(value = "主键集合", required = true) @RequestParam String ids) {
 		return R.status(menuService.removeByIds(Func.toIntList(ids)));
 	}

+ 1 - 1
src/main/java/org/springblade/modules/system/controller/RoleController.java

@@ -99,7 +99,7 @@ public class RoleController extends BladeController {
 	 * 删除
 	 */
 	@PostMapping("/remove")
-	@ApiOperation(value = "物理删除", notes = "传入ids", position = 7)
+	@ApiOperation(value = "删除", notes = "传入ids", position = 7)
 	public R remove(@ApiParam(value = "主键集合", required = true) @RequestParam String ids) {
 		return R.status(roleService.removeByIds(Func.toIntList(ids)));
 	}

+ 7 - 0
src/main/java/org/springblade/modules/system/service/IDictService.java

@@ -64,4 +64,11 @@ public interface IDictService extends IService<Dict> {
 	 */
 	List<Dict> getList(String code);
 
+	/**
+	 * 新增或修改
+	 * @param dict
+	 * @return
+	 */
+	boolean submit(Dict dict);
+
 }

+ 16 - 2
src/main/java/org/springblade/modules/system/service/impl/DictServiceImpl.java

@@ -16,7 +16,10 @@
  */
 package org.springblade.modules.system.service.impl;
 
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.baomidou.mybatisplus.core.metadata.IPage;
+import com.baomidou.mybatisplus.core.toolkit.Wrappers;
+import com.baomidou.mybatisplus.extension.exceptions.ApiException;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import org.springblade.core.tool.node.ForestNodeMerger;
 import org.springblade.core.tool.utils.Func;
@@ -25,6 +28,7 @@ import org.springblade.modules.system.entity.Dict;
 import org.springblade.modules.system.mapper.DictMapper;
 import org.springblade.modules.system.service.IDictService;
 import org.springblade.modules.system.vo.DictVO;
+import org.springframework.cache.annotation.CacheEvict;
 import org.springframework.cache.annotation.Cacheable;
 import org.springframework.stereotype.Service;
 
@@ -55,8 +59,7 @@ public class DictServiceImpl extends ServiceImpl<DictMapper, Dict> implements ID
 	@Override
 	@Cacheable(cacheNames = DICT_VALUE, key = "#code+'_'+#dictKey")
 	public String getValue(String code, Integer dictKey) {
-		String value = Func.toStr(baseMapper.getValue(code, dictKey), StringPool.EMPTY);
-		return value;
+		return Func.toStr(baseMapper.getValue(code, dictKey), StringPool.EMPTY);
 	}
 
 	@Override
@@ -65,4 +68,15 @@ public class DictServiceImpl extends ServiceImpl<DictMapper, Dict> implements ID
 		return baseMapper.getList(code);
 	}
 
+	@Override
+	@CacheEvict(cacheNames = {DICT_LIST, DICT_VALUE})
+	public boolean submit(Dict dict) {
+		LambdaQueryWrapper<Dict> lqw = Wrappers.<Dict>query().lambda().eq(Dict::getCode, dict.getCode()).eq(Dict::getDictKey, dict.getDictKey());
+		Integer cnt = baseMapper.selectCount((Func.isEmpty(dict.getId())) ? lqw : lqw.notIn(Dict::getId, dict.getId()));
+		if (cnt > 0) {
+			throw new ApiException("当前字典键值已存在!");
+		}
+		return saveOrUpdate(dict);
+	}
+
 }

+ 1 - 1
src/main/resources/templates/controller.java.vm

@@ -140,7 +140,7 @@ public class $!{table.controllerName} {
 	* 删除 $!{table.comment}
 	*/
 	@PostMapping("/remove")
-	@ApiOperation(value = "物理删除", notes = "传入ids", position = 7)
+	@ApiOperation(value = "删除", notes = "传入ids", position = 7)
 	public R remove(@ApiParam(value = "主键集合", required = true) @RequestParam String ids) {
 		return R.status($!{table.entityPath}Service.removeByIds(Func.toIntList(ids)));
 	}

+ 1 - 1
src/test/resources/templates/controller.java.vm

@@ -140,7 +140,7 @@ public class $!{table.controllerName} {
 	* 删除 $!{table.comment}
 	*/
 	@PostMapping("/remove")
-	@ApiOperation(value = "物理删除", notes = "传入ids", position = 7)
+	@ApiOperation(value = "删除", notes = "传入ids", position = 7)
 	public R remove(@ApiParam(value = "主键集合", required = true) @RequestParam String ids) {
 		return R.status($!{table.entityPath}Service.removeByIds(Func.toIntList(ids)));
 	}