Browse Source

新增配送规则查找名称是否重复的方法

hulh 8 years ago
parent
commit
27ebbecbdc

+ 14 - 1
src/main/java/com/uas/platform/b2c/logistics/controller/DistributionRuleController.java

@@ -45,7 +45,7 @@ public class DistributionRuleController {
 	 * 保存配送规则
 	 * @param isActive
 	 * @param json
-	 * @param isAdd true-新增,false-另存
+	 * @param isAdd true-保存,false-另存
 	 * @return
 	 */
 	@RequestMapping(value = "/save", method = RequestMethod.POST)
@@ -72,4 +72,17 @@ public class DistributionRuleController {
 	public ResultMap findRuleCount(){
 		return distributionRuleService.findCountRule();
 	}
+
+	/**
+	 * 查找配送规则名是否存在
+	 * @param id
+	 * @param ruleName
+	 * @param newSave 是否为另存为
+	 * @return
+	 */
+	@RequestMapping(value = "/checkName", method = RequestMethod.GET)
+	public ResultMap checkRuleName(@RequestParam(required = false) Long id, String ruleName, Boolean newSave){
+		System.out.println("id=" + id + "=ruleName=" + "newSave");
+		return distributionRuleService.containsName(id, ruleName, newSave);
+	}
 }

+ 3 - 0
src/main/java/com/uas/platform/b2c/logistics/dao/DistributionRuleDao.java

@@ -48,4 +48,7 @@ public interface DistributionRuleDao extends JpaSpecificationExecutor<Distributi
 	 */
 	@Query(value = "select d.ruleName from DistributionRule d where d.enuu = :enuu")
 	List<String> findAllRuleNameByEnuu(@Param("enuu") Long enuu);
+
+	@Query(value = "select count(1) from DistributionRule d where d.enuu = :enuu and d.ruleName = :ruleName")
+	int findCountRuleName(@Param("enuu") Long enuu, @Param("ruleName") String ruleName);
 }

+ 5 - 0
src/main/java/com/uas/platform/b2c/logistics/service/DistributionRuleService.java

@@ -41,6 +41,11 @@ public interface DistributionRuleService {
 	 */
 	List<String> findAllRuleName();
 
+	/**
+	 * 返回当前enuu下配送规则总数
+	 * @return
+	 */
 	ResultMap findCountRule();
 
+	ResultMap containsName(Long id, String ruleName, Boolean newSave);
 }

+ 41 - 0
src/main/java/com/uas/platform/b2c/logistics/service/impl/DistributionRuleServiceImpl.java

@@ -151,4 +151,45 @@ public class DistributionRuleServiceImpl implements DistributionRuleService{
 		int count = distributionRuleDao.findCountByEnuu(enuu);
 		return ResultMap.success(count);
 	}
+
+	@Override
+	public ResultMap containsName(Long id, String ruleName, Boolean newSave) {
+		Long enuu = SystemSession.getUser().getEnterprise().getUu();
+		Boolean repeat = null;
+		System.out.println("id=" + id);
+		if (id != null){
+			//修改配送规则情况,分保存和另存为两种
+			if (newSave){ //另存为
+				int count = distributionRuleDao.findCountRuleName(enuu, ruleName);
+				System.out.println("count=" + count);
+				if (count != 0){
+					repeat = true;
+				}else {
+					repeat = false;
+				}
+			}else { //保存
+				DistributionRule rule = distributionRuleDao.findOne(id);
+				if (ruleName.equals(rule.getRuleName())){
+					repeat = false;
+				}else {
+					int count = distributionRuleDao.findCountRuleName(enuu, ruleName);
+					System.out.println("count=" + count);
+					if (count != 0){
+						repeat = true;
+					}else {
+						repeat = false;
+					}
+				}
+			}
+		}else { //新增配送规则情况
+			int count = distributionRuleDao.findCountRuleName(enuu, ruleName);
+			System.out.println("count=" + count);
+			if (count != 0){
+				repeat = true;
+			}else {
+				repeat = false;
+			}
+		}
+		return ResultMap.success(repeat);
+	}
 }

+ 4 - 0
src/main/webapp/resources/js/common/query/logisticsPort.js

@@ -99,6 +99,10 @@ define([ 'ngResource' ], function() {
 			findCountOfRule : {
 				url: 'trade/distributionRule/count',
 				method: 'GET'
+			},
+			checkRuleName : {
+				url: 'trade/distributionRule/checkName',
+				method: 'GET'
 			}
 		})
 	}]);