浏览代码

品牌授权part2

Aslee 4 年之前
父节点
当前提交
f89497ea9a

+ 6 - 0
src/main/java/com/caimei/modules/zplm/dao/CmBrandAuthDao.java

@@ -50,4 +50,10 @@ public interface CmBrandAuthDao extends CrudDao<CmBrandAuth> {
      * @param authLogo
      */
     void updateBrandAuthLogo(@Param("brandId") Integer brandId,@Param("authLogo") String authLogo);
+
+    /**
+     * 查找同种授权数量
+     * @param cmBrandAuth
+     */
+    CmBrandAuth findSameAuth(CmBrandAuth cmBrandAuth);
 }

+ 7 - 0
src/main/java/com/caimei/modules/zplm/dao/CmBrandAuthProductDao.java

@@ -33,4 +33,11 @@ public interface CmBrandAuthProductDao extends CrudDao<CmBrandAuthProduct> {
      * @return
      */
     List<CmBrandProductParam> findParamsByProductId(String productId);
+
+    /**
+     * 查找品牌授权下相同名称/SN码的商品
+     * @param cmBrandAuthProduct
+     * @return
+     */
+    CmBrandAuthProduct findSameProduct(CmBrandAuthProduct cmBrandAuthProduct);
 }

+ 4 - 2
src/main/java/com/caimei/modules/zplm/service/CmBrandAuthProductService.java

@@ -72,8 +72,10 @@ public class CmBrandAuthProductService extends CrudService<CmBrandAuthProductDao
 		List<CmBrandProductParam> paramList = cmBrandAuthProduct.getParamList();
 		if (paramList != null && paramList.size() > 0) {
 			paramList.forEach(param->{
-				param.setProductId(Integer.parseInt(cmBrandAuthProduct.getId()));
-				cmBrandAuthProductDao.insertParam(param);
+				if (StringUtils.isNotBlank(param.getName()) && StringUtils.isNotBlank(param.getContent())) {
+					param.setProductId(Integer.parseInt(cmBrandAuthProduct.getId()));
+					cmBrandAuthProductDao.insertParam(param);
+				}
 			});
 		}
 	}

+ 5 - 0
src/main/java/com/caimei/modules/zplm/web/CmBrandAuthController.java

@@ -95,6 +95,11 @@ public class CmBrandAuthController extends BaseController {
 			model.addAttribute("errorMsg", "请上传品牌logo!");
 			return true;
 		}
+		CmBrandAuth sameAuth = cmBrandAuthDao.findSameAuth(cmBrandAuth);
+		if (null != sameAuth) {
+			model.addAttribute("errorMsg", sameAuth.getBrandName() + "品牌" + (sameAuth.getAgentFlag() == 1 ? "-" + sameAuth.getAgentName() + "代理" : "") + "下的" + sameAuth.getAuthParty() + "已存在,请勿重复添加");
+			return true;
+		}
 		return false;
 	}
 }

+ 13 - 0
src/main/java/com/caimei/modules/zplm/web/CmBrandAuthProductController.java

@@ -1,9 +1,11 @@
 package com.caimei.modules.zplm.web;
 
+import javax.annotation.Resource;
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
 
 import com.caimei.modules.live.entity.NewPageLive;
+import com.caimei.modules.zplm.dao.CmBrandAuthProductDao;
 import com.caimei.modules.zplm.entity.CmBrandProductParam;
 import org.apache.shiro.authz.annotation.RequiresPermissions;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -34,6 +36,8 @@ public class CmBrandAuthProductController extends BaseController {
 
 	@Autowired
 	private CmBrandAuthProductService cmBrandAuthProductService;
+	@Resource
+	private CmBrandAuthProductDao cmBrandAuthProductDao;
 	
 	@ModelAttribute
 	public CmBrandAuthProduct get(@RequestParam(required=false) String id) {
@@ -87,6 +91,15 @@ public class CmBrandAuthProductController extends BaseController {
 			model.addAttribute("errorMsg", "请上传商品图片!");
 			return true;
 		}
+		CmBrandAuthProduct sameProduct = cmBrandAuthProductDao.findSameProduct(cmBrandAuthProduct);
+		if (null != sameProduct) {
+			if (cmBrandAuthProduct.getName().equals(sameProduct.getName())) {
+				model.addAttribute("errorMsg", "该品牌授权下的"+sameProduct.getName()+"商品名称已存在,请勿重复添加");
+			}else if (cmBrandAuthProduct.getSnCode().equals(sameProduct.getSnCode())) {
+				model.addAttribute("errorMsg", "该品牌授权下的"+sameProduct.getSnCode()+"商品SN码已存在,请勿重复添加");
+			}
+			return true;
+		}
 		return false;
 	}
 }

+ 14 - 8
src/main/resources/mappings/modules/zplm/CmBrandAuthDao.xml → src/main/resources/mappings/modules/zplm/CmBrandAuthMapper.xml

@@ -56,13 +56,7 @@
 					<if test="dbName == 'mysql'">concat('%',#{authParty},'%')</if>
 			</if>
 		</where>
-		<choose>
-			<when test="page !=null and page.orderBy != null and page.orderBy != ''">
-				ORDER BY ${page.orderBy}
-			</when>
-			<otherwise>
-			</otherwise>
-		</choose>
+		order by a.id desc
 	</select>
 	
 	<select id="findAllList" resultType="CmBrandAuth">
@@ -87,8 +81,20 @@
 	<select id="findCountryList" resultType="com.caimei.modules.common.entity.Country">
 		select countryId, name from country;
 	</select>
+	<select id="findSameAuth" resultType="com.caimei.modules.zplm.entity.CmBrandAuth">
+		select b.name as brandName,ba.agentFlag, ba.agentName,ba.authParty
+		from cm_brand_auth ba
+		left join cm_brand b on ba.brandId = b.id
+		<where>
+			brandId = #{brandId} and authParty = #{authParty} and agentFlag = #{agentFlag}
+			<if test="agentFlag == 1">
+				and agentName = #{agentName}
+			</if>
+		</where>
+		limit 1
+	</select>
 
-    <insert id="insert" parameterType="CmBrandAuth"  keyProperty="id" useGeneratedKeys="true">
+	<insert id="insert" parameterType="CmBrandAuth"  keyProperty="id" useGeneratedKeys="true">
 		INSERT INTO cm_brand_auth(
 			brandId,
 			countryId,

+ 9 - 7
src/main/resources/mappings/modules/zplm/CmBrandAuthProductMapper.xml

@@ -48,13 +48,7 @@
 					<if test="dbName == 'mysql'">concat('%',#{snCode},'%')</if>
 			</if>
 		</where>
-		<choose>
-			<when test="page !=null and page.orderBy != null and page.orderBy != ''">
-				ORDER BY ${page.orderBy}
-			</when>
-			<otherwise>
-			</otherwise>
-		</choose>
+		order by a.id desc
 	</select>
 	
 	<select id="findAllList" resultType="CmBrandAuthProduct">
@@ -76,6 +70,14 @@
 	<select id="findParamsByProductId" resultType="com.caimei.modules.zplm.entity.CmBrandProductParam">
 		select name,content from cm_brand_product_param where productId = #{productId}
 	</select>
+	<select id="findSameProduct" resultType="com.caimei.modules.zplm.entity.CmBrandAuthProduct">
+		select name,snCode from cm_brand_auth_product
+		where (name = #{name} or snCode = #{snCode}) and authId = #{authId}
+		<if test="id != null and id != ''">
+			and id != #{id}
+		</if>
+		limit 1
+	</select>
 
 	<insert id="insert" parameterType="CmBrandAuthProduct"  keyProperty="id" useGeneratedKeys="true">
 		INSERT INTO cm_brand_auth_product(

+ 14 - 13
src/main/webapp/WEB-INF/views/modules/zplm/cmBrandAuthForm.jsp

@@ -35,9 +35,6 @@
         .conList .btn:nth-of-type(1){
             margin-left: 25px;
         }
-        .select2-choice{
-            width: 100px;
-        }
         .upload-content {
             margin-top: -70px;
         }
@@ -97,7 +94,7 @@
 		<div class="control-group">
 			<label class="control-label">*品牌:</label>
 			<div class="controls">
-				<form:select path="brandId" class="input-medium required" onchange="changeBrand()">
+				<form:select path="brandId" class="input-large required" onchange="changeBrand()">
 					<form:option value="" label="请选择"/>
 					<form:options items="${brandList}" itemLabel="name" itemValue="id"/>
 				</form:select>
@@ -106,7 +103,7 @@
 		<div class="control-group">
 			<label class="control-label">*产地:</label>
 			<div class="controls">
-				<form:select path="countryId" class="input-medium required">
+				<form:select path="countryId" class="input-large required">
 					<form:option value="" label="请选择"/>
                     <form:options items="${countryList}" itemLabel="name" itemValue="countryId"/>
 				</form:select>
@@ -266,6 +263,7 @@
 	
 	//修改品牌,品牌logo跟着修改
 	function changeBrand() {
+    	debugger
 		var brandId = $("#brandId").val();
     	var url;
 		<c:forEach items="${brandList}" var="brand">
@@ -287,15 +285,18 @@
 				$("#authLogoPreview a").attr('href', url);
 				$("#authLogoPreview img").attr('src', url);
 				$("#authLogoPreview img").attr('url', url);
+				clearLogoImage()
+			}else {
+				var wrapper = $("#authLogoBox .conList");
+				var nextEle = wrapper.next();
+				wrapper.find('li').css('z-index', 99);
+				wrapper.find('.cancel-upload').show();
+				if (nextEle.hasClass('hide-pic')) {
+					nextEle.removeClass('hide-pic');
+				}
+				$("#authLogo").val($("#authLogoPreview a").attr('href'));
 			}
-			var wrapper = $("#authLogoBox .conList");
-			var nextEle = wrapper.next();
-			wrapper.find('li').css('z-index', 99);
-			wrapper.find('.cancel-upload').show();
-			if (nextEle.hasClass('hide-pic')) {
-				nextEle.removeClass('hide-pic');
-			}
-			$("#authLogo").val($("#authLogoPreview a").attr('href'));
+
 		}
 	}
 

+ 105 - 109
src/main/webapp/WEB-INF/views/modules/zplm/cmBrandAuthProductForm.jsp

@@ -35,9 +35,6 @@
 		.conList .btn:nth-of-type(1){
 			margin-left: 25px;
 		}
-		.select2-choice{
-			width: 100px;
-		}
 		.upload-content {
 			margin-top: -70px;
 		}
@@ -95,6 +92,7 @@
 		<li class="active"><a href="${ctx}/zplm/cmBrandAuthProduct/form?id=${cmBrandAuthProduct.id}&authId=${cmBrandAuthProduct.authId}">商品${not empty cmBrandAuthProduct.id?'编辑':'添加'}</a></li>
 	</ul><br/>
 	<form:form id="inputForm" modelAttribute="cmBrandAuthProduct" action="${ctx}/zplm/cmBrandAuthProduct/save" method="post" class="form-horizontal">
+		<form:hidden path="id"/>
 		<form:hidden path="authId"/>
 		<sys:message content="${message}"/>
 		<div class="control-group">
@@ -137,128 +135,126 @@
 			<div class="controls paramRow" id="paramRow3">
 				<input name="paramList[3].name" htmlEscape="false" class="input-small required" maxlength="10" value="重量" placeholder="参数名称">
 				<input name="paramList[3].content" htmlEscape="false" class="input-xlarge required" maxlength="50" placeholder="输入参数信息">
-            </div>
-			<div class="controls paramRow" id="paramRow4">
-				<input name="paramList[4].name" htmlEscape="false" class="input-small required" maxlength="10" placeholder="参数名称">
-				<input name="paramList[4].content" htmlEscape="false" class="input-xlarge required" maxlength="50" placeholder="输入参数信息">
-				<a onclick="deleteParam(4)" style="cursor: pointer">删除</a>
             </div>
         </div>
 		<div class="form-actions">
 			<input id="btnSubmit" class="btn btn-primary" type="submit" value="保 存"/>
 			<input id="btnCancel" class="btn" type="button" value="返 回" onclick="history.go(-1)"/>
 		</div>
-		<script type = text/javascript>
-			$(function () {
-				$('.upload-content .conList .btn:nth-of-type(1)').html('<div><span>+</span><h5>选择图片</h5></div>');
-				$('.upload-content .conList .btn:nth-of-type(2)').after('<img class="cancel-upload" src="/static/images/close-btn1.png">').remove();
-				$('.upload-content .conList').find('.cancel-upload').hide();
-				var observeEle = document.getElementsByClassName('upload-content')[0];
-				var MutationObserver = window.MutationObserver || window.WebKitMutationObserver;
-				var MutationObserverConfig = {
-					childList: true,
-					subtree: true,
-					characterData: true
-				};
-				var observer = new MutationObserver(function (mutations) {
-					$.each(mutations, function (index, item) {
-						if (item.type === 'childList') {
-							// 在创建新的 element 时调用
-							var target = $(item.target),
-									thisWrapper = target.closest('.conList'),
-									nextEle = thisWrapper.next();
-							thisWrapper.find('li').css('z-index', 99);
-							thisWrapper.find('.cancel-upload').show();
-							if (nextEle.hasClass('hide-pic')) {
-								nextEle.removeClass('hide-pic');
-							}
+	</form:form>
+	<script type = text/javascript>
+		//参数索引
+		var paramIndex = 4;
+		$(function () {
+			$('.upload-content .conList .btn:nth-of-type(1)').html('<div><span>+</span><h5>选择图片</h5></div>');
+			$('.upload-content .conList .btn:nth-of-type(2)').after('<img class="cancel-upload" src="/static/images/close-btn1.png">').remove();
+			$('.upload-content .conList').find('.cancel-upload').hide();
+			var observeEle = document.getElementsByClassName('upload-content')[0];
+			var MutationObserver = window.MutationObserver || window.WebKitMutationObserver;
+			var MutationObserverConfig = {
+				childList: true,
+				subtree: true,
+				characterData: true
+			};
+			var observer = new MutationObserver(function (mutations) {
+				$.each(mutations, function (index, item) {
+					if (item.type === 'childList') {
+						// 在创建新的 element 时调用
+						var target = $(item.target),
+								thisWrapper = target.closest('.conList'),
+								nextEle = thisWrapper.next();
+						thisWrapper.find('li').css('z-index', 99);
+						thisWrapper.find('.cancel-upload').show();
+						if (nextEle.hasClass('hide-pic')) {
+							nextEle.removeClass('hide-pic');
 						}
-					})
-				});
-				observer.observe(observeEle, MutationObserverConfig);
+					}
+				})
+			});
+			observer.observe(observeEle, MutationObserverConfig);
 
-				$('body').on('click', '.cancel-upload', function () {
-					var wrapper = $(this).closest('.conList');
-					wrapper.find('li').css('z-index', '-1');
-					wrapper.find('input').val('');
-					$(this).hide();
-					wrapper.removeClass("hide-pic");
-					wrapper.parent().append(wrapper.clone());
-					wrapper.remove();
-					$(".conList").each(function (i, ele) {
-						if ($(ele).find("input.input-xlarge").val()) {
-							$(ele).next().removeClass("hide-pic")
+			$('body').on('click', '.cancel-upload', function () {
+				var wrapper = $(this).closest('.conList');
+				wrapper.find('li').css('z-index', '-1');
+				wrapper.find('input').val('');
+				$(this).hide();
+				wrapper.removeClass("hide-pic");
+				wrapper.parent().append(wrapper.clone());
+				wrapper.remove();
+				$(".conList").each(function (i, ele) {
+					if ($(ele).find("input.input-xlarge").val()) {
+						$(ele).next().removeClass("hide-pic")
+					}
+				})
+			});
+			$(window).on("load", function () {
+				setTimeout(function () {
+					$("#imageBox").find("input.input-xlarge").each(function (i, ele) {
+						if ($(ele).val()) {
+							$(ele).next().find("li").css("z-index", "99");
+							$(ele).parents(".conList").find(".cancel-upload").show();
+							$(ele).parents(".conList").next().removeClass("hide-pic")
 						}
 					})
-				});
-				$(window).on("load", function () {
-					setTimeout(function () {
-						$("#imageBox").find("input.input-xlarge").each(function (i, ele) {
-							if ($(ele).val()) {
-								$(ele).next().find("li").css("z-index", "99");
-								$(ele).parents(".conList").find(".cancel-upload").show();
-								$(ele).parents(".conList").next().removeClass("hide-pic")
-							}
-						})
-					}, 200);
-				});
-				var productId = ${empty cmBrandAuthProduct.id?'null':cmBrandAuthProduct.id};
-				if (productId != null) {
-					var paramListSize = ${cmBrandAuthProduct.paramList.size()} ;
-					if (paramListSize == 4){
-						$("#paramRow4").remove();
-					}else if (paramListSize > 5) {
-						var index = 5;
-						while (index < paramListSize) {
-							$(".paramList").append("<div class=\"controls paramRow\" id=\"paramRow"+index+"\">\n" +
-									"\t\t\t\t<input name=\"paramList["+index+"].name\" htmlEscape=\"false\" class=\"input-small required\" maxlength=\"10\" placeholder=\"参数名称\">\n" +
-									"\t\t\t\t<input name=\"paramList["+index+"].content\" htmlEscape=\"false\" class=\"input-xlarge required\" maxlength=\"50\" placeholder=\"输入参数信息\">\n" +
-									"\t\t\t\t<a onclick=\"deleteParam("+index+")\" style=\"cursor: pointer\">删除</a>\n" +
-									"            </div>");
-							index = index + 1;
-						}
-					}
-					var nameArray = new Array();
-					var contentArray = new Array();
-					<c:forEach items="${cmBrandAuthProduct.paramList}" var="item">
-                        nameArray.push('${item.name}')
-                        contentArray.push('${item.content}')
-                    </c:forEach>
-                    for (var i = 0; i < nameArray.length; i++) {
-                        var nameInput = "paramList["+i+"].name";
-                        var contentInput = "paramList["+i+"].content";
-                        $('input[name="' + nameInput + '"]').val(nameArray[i]);
-                        $('input[name="' + contentInput + '"]').val(contentArray[i]);
-                    }
-				}
+				}, 200);
 			});
 
-			//参数索引
-			var paramIndex = 5;
-
-			//删除参数
-			function deleteParam(index){
-				$("#paramRow" + index).remove();
-				paramIndex = paramIndex -1;
+			var productId = ${empty cmBrandAuthProduct.id?'null':cmBrandAuthProduct.id};
+			if (productId != null) {
+				var paramListSize = ${cmBrandAuthProduct.paramList.size()} ;
+				paramIndex = paramListSize;
+				if (paramListSize > 4) {
+					var index = 4;
+					while (index < paramListSize) {
+						$(".paramList").append("<div class=\"controls paramRow\" id=\"paramRow"+index+"\">\n" +
+								"\t\t\t\t<input name=\"paramList["+index+"].name\" htmlEscape=\"false\" class=\"input-small required\" maxlength=\"10\" placeholder=\"参数名称\">\n" +
+								"\t\t\t\t<input name=\"paramList["+index+"].content\" htmlEscape=\"false\" class=\"input-xlarge required\" maxlength=\"50\" placeholder=\"输入参数信息\">\n" +
+								"\t\t\t\t<a onclick=\"deleteParam("+index+")\" style=\"cursor: pointer\">删除</a>\n" +
+								"            </div>");
+						index = index + 1;
+					}
+				}
+				var nameArray = new Array();
+				var contentArray = new Array();
+				<c:forEach items="${cmBrandAuthProduct.paramList}" var="item">
+					nameArray.push('${item.name}')
+					contentArray.push('${item.content}')
+				</c:forEach>
+				for (var i = 0; i < nameArray.length; i++) {
+					var nameInput = "paramList["+i+"].name";
+					var contentInput = "paramList["+i+"].content";
+					$('input[name="' + nameInput + '"]').val(nameArray[i]);
+					$('input[name="' + contentInput + '"]').val(contentArray[i]);
+				}
 			}
+		});
 
-			//添加参数
-			function addParam() {
-				$(".paramList").append("<div class=\"controls paramRow\" id=\"paramRow"+paramIndex+"\">\n" +
-						"\t\t\t\t<input name=\"paramList["+paramIndex+"].name\" htmlEscape=\"false\" class=\"input-small required\" maxlength=\"10\" placeholder=\"参数名称\">\n" +
-						"\t\t\t\t<input name=\"paramList["+paramIndex+"].content\" htmlEscape=\"false\" class=\"input-xlarge required\" maxlength=\"50\" placeholder=\"输入参数信息\">\n" +
-						"\t\t\t\t<a onclick=\"deleteParam("+paramIndex+")\" style=\"cursor: pointer\">删除</a>\n" +
-						"            </div>")
-				paramIndex = paramIndex +1;
-			}
+		//删除参数
+		function deleteParam(index){
+			$("#paramRow" + index).remove();
+		}
 
+		//添加参数
+		function addParam() {
+			$(".paramList").append("<div class=\"controls paramRow\" id=\"paramRow"+paramIndex+"\">\n" +
+					"\t\t\t\t<input name=\"paramList["+paramIndex+"].name\" htmlEscape=\"false\" class=\"input-small required\" maxlength=\"10\" placeholder=\"参数名称\">\n" +
+					"\t\t\t\t<input name=\"paramList["+paramIndex+"].content\" htmlEscape=\"false\" class=\"input-xlarge required\" maxlength=\"50\" placeholder=\"输入参数信息\">\n" +
+					"\t\t\t\t<a onclick=\"deleteParam("+paramIndex+")\" style=\"cursor: pointer\">删除</a>\n" +
+					"            </div>")
+			paramIndex = paramIndex +1;
+		}
 
-			//限制只能输入数字和英文
-            function inputnum(obj, val) {
-                obj.value = obj.value.replace(/[^\w.\/]/ig, ""); //清除"数字"和"英文"以外的字符
-            }
 
-		</script>
-	</form:form>
+		//限制只能输入数字和英文
+		function inputnum(obj, val) {
+			obj.value = obj.value.replace(/[^\w.\/]/ig, ""); //清除"数字"和"英文"以外的字符
+		}
+
+		//错误提示
+		var errorMsg  = "${errorMsg}";
+		if(errorMsg){
+			alertx(errorMsg);
+		}
+	</script>
 </body>
 </html>