소스 검색

模块更改(部分)

limin 7 년 전
부모
커밋
122625b5b4

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

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

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

@@ -22,7 +22,9 @@ import com.goafanti.common.dao.JtBusinessCategoryMapper;
 import com.goafanti.common.dao.JtBusinessProjectMapper;
 import com.goafanti.common.dao.JtCommodityCommentMapper;
 import com.goafanti.common.dao.JtTagMapper;
+import com.goafanti.common.enums.BusinessCategoryModule;
 import com.goafanti.common.enums.ProjectAuditStatus;
+import com.goafanti.common.enums.UserAuthentication;
 import com.goafanti.common.model.JtBusinessCategory;
 import com.goafanti.common.model.JtBusinessProject;
 import com.goafanti.common.model.JtTag;
@@ -209,8 +211,81 @@ public class JtBusinessServiceImpl  extends BaseMybatisDao<JtBusinessProjectMapp
 
 	@Override
 	public int updateCategory(JtBusinessCategory jtBusinessCategory) {
+		// 层级不会变
 		// TODO Auto-generated method stub
-		return jtBusinessCategoryMapper.updateByPrimaryKeySelective(jtBusinessCategory);
+		//修改不影响结构的数据
+		JtBusinessCategory category = new JtBusinessCategory();
+		category.setId(jtBusinessCategory.getId());
+		category.setImgUrl(jtBusinessCategory.getImgUrl());
+		category.setName(jtBusinessCategory.getName());
+		category.setSummary(jtBusinessCategory.getSummary());
+		jtBusinessCategoryMapper.updateByPrimaryKeySelective(category);
+		//是否修改了模块类别
+		boolean moduleChange = null != jtBusinessCategory.getModule() ? !jtBusinessCategory.getModule().equals(jtBusinessCategory.getNextModule()) : false;
+		//是否有上级id
+		boolean existSuperId = StringUtils.isNotBlank(jtBusinessCategory.getSuperId());
+		//一级更换模块
+		if(moduleChange && !existSuperId){
+			//根据模块获得字母前缀
+			String prefix = BusinessCategoryModule.getStatus(jtBusinessCategory.getNextModule()).toString();
+			//获得当前更改后模块的最大值
+			
+			//将最大值加一
+			//得到sort
+			//将模块前面字母替换
+		}
+		//存在上级说明是二级修改到不同模块的某品类中
+		if(existSuperId){
+			
+			//根据更改后的上级id获得模块,得到对应的字母
+			//获得当前更改后模块的最大值
+			//将最大值加一
+			//得到sort
+			//将模块前面字母替换
+		}
+		
+		
+		
+		
+		//获得上级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);
+			}
+			
+		}
+		
+		
+		return 1;//jtBusinessCategoryMapper.updateByPrimaryKeySelective(jtBusinessCategory);
 	}
 
 	

+ 1 - 1
src/main/java/com/goafanti/common/controller/WebpageController.java

@@ -1193,7 +1193,7 @@ public class WebpageController extends BaseController {
 	 */
 	@RequestMapping(value = "/portal/service/serviceDetailPreview", method = RequestMethod.GET)
 	public ModelAndView portalServiceServiceDetailPreview(HttpServletRequest request, ModelAndView modelview, String id) {
-		modelview.setViewName("redirect:/portal/service/serviceDetails");
+		modelview.setViewName("/portal/service/serviceDetails");
 		JtBusinessProject jtBusinessProject = jtBusinessService.getBusinessProjectDetail(id);
 		if (jtBusinessProject != null) {
 			if (jtBusinessProject.getMaxImgUrl() != null && jtBusinessProject.getMaxImgUrl().length() <= 0)

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

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

+ 19 - 0
src/main/java/com/goafanti/common/mapper/JtBusinessCategoryMapper.xml

@@ -488,4 +488,23 @@ and layer=#{0}
     and bc1.module =#{module,jdbcType=INTEGER}
     </if>
     </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获得最小同级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>
+    
+    <!-- 修改品类前缀  -->
+    <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}
+    </update>
 </mapper>

+ 19 - 0
src/main/java/com/goafanti/common/model/JtBusinessCategory.java

@@ -234,4 +234,23 @@ public class JtBusinessCategory {
 	public void setModule(Integer module) {
 		this.module = module;
 	}
+	
+	private String oldSuperId; //修改前的上级id
+	private Integer nextModule; //修改后的模块
+
+	public String getOldSuperId() {
+		return oldSuperId;
+	}
+
+	public void setOldSuperId(String oldSuperId) {
+		this.oldSuperId = oldSuperId;
+	}
+
+	public Integer getNextModule() {
+		return nextModule;
+	}
+
+	public void setNextModule(Integer nextModule) {
+		this.nextModule = nextModule;
+	}
 }