소스 검색

Merge remote-tracking branch 'origin/master' into test

limin 7 년 전
부모
커밋
aeb7a1ee87

+ 3 - 9
src/main/java/com/goafanti/business/controller/AdminJtBusinessController.java

@@ -85,15 +85,9 @@ public class AdminJtBusinessController extends CertifyApiController{
 	@RequestMapping(value="/category/update",method=RequestMethod.POST)
 	private Result updateCategory(JtBusinessCategory jtBusinessCategory, Integer nextModule) {
 		Result result=new Result();
-		//只允许修改3种字段
-		JtBusinessCategory jtBusinessCategory2=new JtBusinessCategory();   
-		jtBusinessCategory2.setId(jtBusinessCategory.getId());
-		jtBusinessCategory2.setImgUrl(jtBusinessCategory.getImgUrl());
-		jtBusinessCategory2.setName(jtBusinessCategory.getName());
-		jtBusinessCategory2.setSummary(jtBusinessCategory.getSummary());
-		//jtBusinessCategory.setModule(nextModule);
-		 result.setData(jtBusinessService.updateCategory(jtBusinessCategory));
-		 return result;
+		int re = jtBusinessService.updateCategory(jtBusinessCategory);
+		result.setData(re);
+		return result;
 	}
 	
 	/*

+ 50 - 50
src/main/java/com/goafanti/business/service/impl/JtBusinessServiceImpl.java

@@ -146,7 +146,8 @@ public class JtBusinessServiceImpl  extends BaseMybatisDao<JtBusinessProjectMapp
 		// TODO Auto-generated method stub
 //		jtBusinessCategoryMapper.autoIncreaseSort(jtBusinessCategory.getLayer(),jtBusinessCategory.getSort()); 
 		if(jtBusinessCategory.getSuperId()!=null && jtBusinessCategory.getLayer().intValue()==1 && jtBusinessCategory.getSuperId().length()>0)return -2;
-		String number="BC";
+		//String number="BC";
+		String number=BusinessCategoryModule.getStatus(jtBusinessCategory.getModule()).toString();
 		if(jtBusinessCategory.getLayer().intValue()==2) {
 			//2层,先加第一层
 			//找到当前品类父级品类
@@ -224,67 +225,66 @@ public class JtBusinessServiceImpl  extends BaseMybatisDao<JtBusinessProjectMapp
 		boolean moduleChange = null != jtBusinessCategory.getModule() ? !jtBusinessCategory.getModule().equals(jtBusinessCategory.getNextModule()) : false;
 		//是否有上级id
 		boolean existSuperId = StringUtils.isNotBlank(jtBusinessCategory.getSuperId());
+		//获得更改前的自己的number
+		String oldNumber = jtBusinessCategoryMapper.selectByPrimaryKey(jtBusinessCategory.getId()).getNumber();
+		String number = null;
 		//一级更换模块
 		if(moduleChange && !existSuperId){
+			jtBusinessCategory.setLayer(1);
 			//根据模块获得字母前缀
 			String prefix = BusinessCategoryModule.getStatus(jtBusinessCategory.getNextModule()).toString();
-			//获得当前更改后模块的最大值
-			
-			//将最大值加一
-			//得到sort
-			//将模块前面字母替换
+			jtBusinessCategory.setNumber(prefix + "__");
+			number = prefix;
+			category.setModule(jtBusinessCategory.getNextModule());
+			jtBusinessCategory.setModule(jtBusinessCategory.getNextModule());
 		}
 		//存在上级说明是二级修改到不同模块的某品类中
 		if(existSuperId){
+			JtBusinessCategory b = jtBusinessCategoryMapper.selectByPrimaryKey(jtBusinessCategory.getSuperId());
+			category.setModule(b.getModule());
+			jtBusinessCategory.setLayer(2);
+			jtBusinessCategory.setModule(b.getModule());
 			
-			//根据更改后的上级id获得模块,得到对应的字母
-			//获得当前更改后模块的最大值
-			//将最大值加一
-			//得到sort
-			//将模块前面字母替换
+			number = b.getNumber();
+			//获得前缀
+			String prefix = BusinessCategoryModule.getStatus(b.getModule()).toString();
+			number = prefix + number.substring(prefix.length()) ;
+			jtBusinessCategory.setNumber(number + "__");
+			category.setSuperId(jtBusinessCategory.getSuperId());//上级id也要修改
 		}
-		
-		
-		
-		
-		//获得上级id
-		//只修改基本数据
-		//jtBusinessCategoryMapper.updateByPrimaryKeySelective(jtBusinessCategory);
-		if(StringUtils.isNotBlank(jtBusinessCategory.getSuperId()) && StringUtils.isNotBlank(jtBusinessCategory.getOldSuperId())){
-			//获得修改前品类id
-			//获得修改后品类id
-			//修改前后id不相等执行以下操作
-			if(!jtBusinessCategory.getSuperId().equals(jtBusinessCategory.getOldSuperId())){
-				//获得修改前品类number1
-				String oldNumber = jtBusinessCategoryMapper.selectByPrimaryKey(jtBusinessCategory.getOldSuperId()).getNumber();
-				//获得修改后品类number2
-				String number = jtBusinessCategoryMapper.selectByPrimaryKey(jtBusinessCategory.getSuperId()).getNumber();
-				//根据修改后的品类id获得最大同级number
-				String newNumber = jtBusinessCategoryMapper.getCurrentMaxNumber(number);
-				Integer n = null != newNumber ? Integer.valueOf(newNumber.substring(newNumber.length() - 2)) : 0;
-				if(n < 99){
-					n += 1;
-					newNumber = newNumber.substring(0,newNumber.length() - 3) + (n<10? "0"+ n : n);
-				} else {
-					newNumber = jtBusinessCategoryMapper.getCurrentMinNumber(number);
-					n = Integer.valueOf(newNumber.substring(newNumber.length() - 2));
-					if(n == 1 || n == 01){
-						return -1;
-					}
-					n -= 1;
-					newNumber = newNumber.substring(0,newNumber.length() - 3) + (n<10? "0"+ n : n);
-					
-				}  
-				//更新数据
-				jtBusinessCategory.setNumber(oldNumber);
-				jtBusinessCategory.setSort(number.length() + 1);
-				jtBusinessCategory.setName(newNumber);
-				//jtBusinessCategoryMapper.updateNumberPrefix(jtBusinessCategory);
+		if((!moduleChange && !existSuperId) && !existSuperId){
+			return 1;
+		}
+		//获得当前更改后模块的最大值
+		String newNumber = jtBusinessCategoryMapper.getCurrentMaxNumber(jtBusinessCategory);
+		Integer n = null != newNumber ? Integer.valueOf(newNumber.substring(newNumber.length() - 2)) : 0;
+		if(n < 99){
+			//将最大值加一
+			n += 1;
+			newNumber = number + (n<10? "0"+ n : n);
+		} else {
+			newNumber = jtBusinessCategoryMapper.getCurrentMaxNumber(jtBusinessCategory);
+			n = Integer.valueOf(newNumber.substring(newNumber.length() - 2));
+			if(n == 1 || n == 01){
+				return -1;
 			}
-			
+			//将最小值减一
+			n -= 1;
+			newNumber = number + (n<10? "0"+ n : n);
 		}
 		
-		
+		//修改自己和自己下级的前缀
+		jtBusinessCategory.setLayer(newNumber.length() + 1);//截取前缀的长度位置
+		jtBusinessCategory.setNumber(oldNumber + "%");
+		jtBusinessCategory.setName(newNumber );
+		//将模块前面字母替换
+		jtBusinessCategoryMapper.updateNumberPrefix(jtBusinessCategory);
+		//得到sort
+		category.setSort(n);
+		//修改自己的number
+		category.setNumber(newNumber);
+		//修改自己的模块
+		jtBusinessCategoryMapper.updateByPrimaryKeySelective(category);
 		return 1;//jtBusinessCategoryMapper.updateByPrimaryKeySelective(jtBusinessCategory);
 	}
 

+ 2 - 2
src/main/java/com/goafanti/common/dao/JtBusinessCategoryMapper.java

@@ -90,8 +90,8 @@ public interface JtBusinessCategoryMapper {
     
     int autoIncreaseSort(Integer layer,Integer sort);
     
-    String getCurrentMaxNumber(String number);
-    String getCurrentMinNumber(String number);
+    String getCurrentMaxNumber(JtBusinessCategory jtBusinessCategory);
+    String getCurrentMinNumber(JtBusinessCategory jtBusinessCategory);
     
     Integer updateNumberPrefix(JtBusinessCategory jtBusinessCategory);
     

+ 14 - 9
src/main/java/com/goafanti/common/mapper/JtBusinessCategoryMapper.xml

@@ -490,21 +490,26 @@ and layer=#{0}
     </select>
     
     <!-- 根据修改后的品类id获得最大同级number -->
-    <select id="getCurrentMaxNumber" resultType="java.lang.String" parameterType="java.lang.String">
-    	<bind name="n" value="_parameter + '__'"/>
-    	select max(`number`) maxnum from jt_business_category where `number` like #{n, jdbcType=VARCHAR}
+    <select id="getCurrentMaxNumber" resultType="java.lang.String" parameterType="com.goafanti.common.model.JtBusinessCategory">
+    	select max(`number`) from jt_business_category 
+    	where `number` like #{number, jdbcType=VARCHAR} 
+    	<!-- and module = #{module,jdbcType=INTEGER}  -->
+    	and layer = #{layer,jdbcType=INTEGER}  
     </select>
     <!-- 根据修改后的品类id获得最小同级number -->
-    <select id="getCurrentMinNumber" resultType="java.lang.String" parameterType="java.lang.String">
-    	<bind name="n" value="_parameter + '__'"/>
-    	select min(`number`) minnum from jt_business_category where `number` like #{n, jdbcType=VARCHAR}
+    <select id="getCurrentMinNumber" resultType="java.lang.String" parameterType="com.goafanti.common.model.JtBusinessCategory">
+    	select min(`number`) from jt_business_category 
+    	where `number` like #{number, jdbcType=VARCHAR} 
+    	<!-- and module = #{module,jdbcType=INTEGER}  -->
+    	and layer = #{layer,jdbcType=INTEGER}  
     </select>
     
     <!-- 修改品类前缀  -->
     <update id="updateNumberPrefix" parameterType="com.goafanti.common.model.JtBusinessCategory">
-    	<bind name="n" value="number + '__%'"/>
     	update jt_business_category 
-		set `number` = concat(#{name, jdbcType=VARCHAR},substring(`number`,#{sort, jdbcType=INTEGER}))
-		where `number` like "#{n, jdbcType=VARCHAR}
+		set 
+		`number` = concat(#{name, jdbcType=VARCHAR}, substring(`number`,#{layer, jdbcType=INTEGER})) ,
+		module = #{module,jdbcType=INTEGER}
+		where `number` like #{number, jdbcType=VARCHAR}
     </update>
 </mapper>

+ 9 - 9
src/main/java/com/goafanti/common/mapper/JtBusinessProjectMapper.xml

@@ -643,12 +643,12 @@
   and y.id= #{tag,jdbcType=VARCHAR}
   </if>
   <if test="module == 0">
-  and jtbc1.module !=1
+  and jtbc1.module &gt; 1
   </if>
-  <if test="module == 1">
+  <!-- <if test="module == 1">
   and jtbc1.module =1
-  </if>
-  <if test="module !=null and module !=1">
+  </if> -->
+  <if test="module !=null and module !=0">
   and jtbc1.module=#{module,jdbcType=INTEGER}
   </if>
   <if test="secondId!=null">
@@ -701,12 +701,12 @@
   and y.id= #{tag,jdbcType=VARCHAR}
   </if> 
  <if test="module == 0">
-  and jtbc1.module !=1
+  and jtbc1.module &gt; 1
   </if>
-  <if test="module == 1">
+ <!--  <if test="module == 1">
   and jtbc1.module =1
-  </if>
-  <if test="module !=null and module !=1">
+  </if> -->
+  <if test="module !=null and module !=0">
   and jtbc1.module=#{module,jdbcType=INTEGER}
   </if>
 	  <if test="secondId!=null">
@@ -832,4 +832,4 @@
   	and b.module = 5 
   	</if>
   </select>
-</mapper>
+</mapper>