1
0
Pārlūkot izejas kodu

Merge branch 'master' of dq/kmall-pt into master

黄亚琴 6 gadi atpakaļ
vecāks
revīzija
229cd9a8dc
25 mainītis faili ar 269 papildinājumiem un 57 dzēšanām
  1. 17 1
      kmall-admin/src/main/java/com/kmall/admin/service/impl/AttributeServiceImpl.java
  2. 20 1
      kmall-admin/src/main/java/com/kmall/admin/service/impl/BrandServiceImpl.java
  3. 24 0
      kmall-admin/src/main/java/com/kmall/admin/service/impl/OrderServiceImpl.java
  4. 7 1
      kmall-admin/src/main/resources/mybatis/mapper/GoodsAttributeDao.xml
  5. 6 0
      kmall-admin/src/main/resources/mybatis/mapper/GoodsDao.xml
  6. 12 4
      kmall-admin/src/main/webapp/WEB-INF/page/shop/goods.html
  7. 6 6
      kmall-admin/src/main/webapp/WEB-INF/page/sys/role.html
  8. 6 6
      kmall-admin/src/main/webapp/WEB-INF/page/sys/user.html
  9. 19 1
      kmall-admin/src/main/webapp/js/shop/goods.js
  10. 1 1
      kmall-admin/src/main/webapp/js/sys/role.js
  11. 4 4
      kmall-admin/src/main/webapp/js/sys/user.js
  12. 2 2
      kmall-common/src/main/java/com/kmall/common/controller/SysRoleController.java
  13. 3 4
      kmall-common/src/main/java/com/kmall/common/controller/SysUserController.java
  14. 2 0
      kmall-common/src/main/java/com/kmall/common/dao/SysUserRoleDao.java
  15. 10 0
      kmall-common/src/main/java/com/kmall/common/entity/SysUserEntity.java
  16. 2 0
      kmall-common/src/main/java/com/kmall/common/service/SysRoleMenuService.java
  17. 2 0
      kmall-common/src/main/java/com/kmall/common/service/SysRoleService.java
  18. 1 1
      kmall-common/src/main/java/com/kmall/common/service/SysUserRoleService.java
  19. 5 0
      kmall-common/src/main/java/com/kmall/common/service/impl/SysRoleMenuServiceImpl.java
  20. 34 3
      kmall-common/src/main/java/com/kmall/common/service/impl/SysRoleServiceImpl.java
  21. 2 5
      kmall-common/src/main/java/com/kmall/common/service/impl/SysUserRoleServiceImpl.java
  22. 62 4
      kmall-common/src/main/java/com/kmall/common/service/impl/SysUserServiceImpl.java
  23. 1 7
      kmall-common/src/main/java/com/kmall/common/shiro/UserRealm.java
  24. 13 3
      kmall-common/src/main/resources/mybatis/mapper/SysUserDao.xml
  25. 8 3
      kmall-common/src/main/resources/mybatis/mapper/SysUserRoleDao.xml

+ 17 - 1
kmall-admin/src/main/java/com/kmall/admin/service/impl/AttributeServiceImpl.java

@@ -1,11 +1,15 @@
 package com.kmall.admin.service.impl;
 
 import com.kmall.admin.dao.AttributeDao;
+import com.kmall.admin.dao.GoodsAttributeDao;
 import com.kmall.admin.entity.AttributeEntity;
+import com.kmall.admin.entity.GoodsAttributeEntity;
 import com.kmall.admin.service.AttributeService;
+import com.kmall.common.utils.RRException;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
+import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
 
@@ -14,6 +18,8 @@ import java.util.Map;
 public class AttributeServiceImpl implements AttributeService {
 	@Autowired
 	private AttributeDao attributeDao;
+	@Autowired
+	private GoodsAttributeDao goodsAttributeDao;
 	
 	@Override
 	public AttributeEntity queryObject(Integer id){
@@ -47,7 +53,17 @@ public class AttributeServiceImpl implements AttributeService {
 	
 	@Override
 	public void deleteBatch(Integer[] ids){
-		attributeDao.deleteBatch(ids);
+		for (Integer id : ids) {
+			AttributeEntity attribute = queryObject(id);
+			Map<String, Object> map = new HashMap<>();
+			map.put("attributeId", id);
+			List<GoodsAttributeEntity> goodsAttributeEntityList = goodsAttributeDao.queryList(map);
+
+			if (goodsAttributeEntityList != null && goodsAttributeEntityList.size() > 0) {
+				throw new RRException("商品参数【" + attribute.getName() + "】还有【" + goodsAttributeEntityList.size() + "】个商品在使用,删除失败!");
+			}
+			delete(id);
+		}
 	}
 	
 }

+ 20 - 1
kmall-admin/src/main/java/com/kmall/admin/service/impl/BrandServiceImpl.java

@@ -1,11 +1,15 @@
 package com.kmall.admin.service.impl;
 
 import com.kmall.admin.dao.BrandDao;
+import com.kmall.admin.dao.GoodsDao;
 import com.kmall.admin.entity.BrandEntity;
+import com.kmall.admin.entity.GoodsEntity;
 import com.kmall.admin.service.BrandService;
+import com.kmall.common.utils.RRException;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
+import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
 
@@ -20,6 +24,8 @@ import java.util.Map;
 public class BrandServiceImpl implements BrandService {
     @Autowired
     private BrandDao brandDao;
+    @Autowired
+    private GoodsDao goodsDao;
 
     @Override
     public BrandEntity queryObject(Integer id) {
@@ -53,6 +59,19 @@ public class BrandServiceImpl implements BrandService {
 
     @Override
     public int deleteBatch(Integer[] ids) {
-        return brandDao.deleteBatch(ids);
+        for (Integer id : ids) {
+            BrandEntity brand = queryObject(id);
+
+            Map<String, Object> map = new HashMap<>();
+            map.put("brandId", id);
+            List<GoodsEntity> goodsList = goodsDao.queryList(map);
+
+            if (goodsList != null && goodsList.size() > 0) {
+                throw new RRException("品牌【" + brand.getName() + "】下还存在【" + goodsList.size() + "】个商品,删除失败!");
+            }
+            delete(id);
+        }
+
+        return 1;
     }
 }

+ 24 - 0
kmall-admin/src/main/java/com/kmall/admin/service/impl/OrderServiceImpl.java

@@ -143,6 +143,30 @@ public class OrderServiceImpl implements OrderService {
         if (0 == shippingStatus) {
             throw new RRException("此订单未发货,不能确认收货!");
         }
+        if (orderEntity.getOrderStatus() == Integer.valueOf(Dict.orderStatus.item_301.getItem())) {
+            throw new RRException("此订单已完成!");
+        }
+        if (orderEntity.getOrderStatus() == Integer.valueOf(Dict.orderStatus.item_0.getItem())) {
+            throw new RRException("此订单待付款!");
+        }
+        if (orderEntity.getOrderStatus() == Integer.valueOf(Dict.orderStatus.item_100.getItem())) {
+            throw new RRException("此订单付款中!");
+        }
+        if (orderEntity.getOrderStatus() == Integer.valueOf(Dict.orderStatus.item_101.getItem())) {
+            throw new RRException("此订单已取消!");
+        }
+        if (orderEntity.getOrderStatus() == Integer.valueOf(Dict.orderStatus.item_102.getItem())) {
+            throw new RRException("此订单已删除!");
+        }
+        if (orderEntity.getOrderStatus() == Integer.valueOf(Dict.orderStatus.item_201.getItem())) {
+            throw new RRException("此订单还未发货!");
+        }
+        if (orderEntity.getOrderStatus() == Integer.valueOf(Dict.orderStatus.item_401.getItem())) {
+            throw new RRException("此订单已退款!");
+        }
+        if (orderEntity.getOrderStatus() == Integer.valueOf(Dict.orderStatus.item_402.getItem())) {
+            throw new RRException("此订单已退款!");
+        }
         orderEntity.setShippingStatus(2);
         orderEntity.setOrderStatus(301);
         orderEntity.setConfirmTime(new Date());

+ 7 - 1
kmall-admin/src/main/resources/mybatis/mapper/GoodsAttributeDao.xml

@@ -36,6 +36,9 @@
         <if test="goodsId != null and goodsId != ''">
             AND mall_goods_attribute.goods_id = #{goodsId}
         </if>
+        <if test="attributeId != null and attributeId != ''">
+            AND mall_goods_attribute.attribute_id = #{attributeId}
+        </if>
         <choose>
             <when test="sidx != null and sidx.trim() != ''">
                 order by ${sidx} ${order}
@@ -53,7 +56,10 @@
         select count(*) from mall_goods_attribute
         WHERE 1=1
         <if test="goodsId != null and goodsId != ''">
-            AND mall_goods_attribute.goods_id = #{goodsId}
+            AND goods_id = #{goodsId}
+        </if>
+        <if test="attributeId != null and attributeId != ''">
+            AND attribute_id = #{attributeId}
         </if>
     </select>
 

+ 6 - 0
kmall-admin/src/main/resources/mybatis/mapper/GoodsDao.xml

@@ -101,6 +101,9 @@
         <if test="freightId != null and freightId != ''">
             AND mall_goods.freight_id = #{freightId}
         </if>
+        <if test="brandId != null and brandId != ''">
+            AND mall_goods.brand_id = #{brandId}
+        </if>
         <if test="categoryId != null and categoryId != ''">
             AND mall_goods.category_id = #{categoryId}
         </if>
@@ -176,6 +179,9 @@
         <if test="freightId != null and freightId != ''">
             AND mall_goods.freight_id = #{freightId}
         </if>
+        <if test="brandId != null and brandId != ''">
+            AND mall_goods.brand_id = #{brandId}
+        </if>
         <if test="categoryId != null and categoryId != ''">
             AND mall_goods.category_id = #{categoryId}
         </if>

+ 12 - 4
kmall-admin/src/main/webapp/WEB-INF/page/shop/goods.html

@@ -227,8 +227,12 @@
                     <Form-item label="海关备案编号" prop="cusRecCode">
                         <i-input v-model="goods.cusRecCode" placeholder="海关备案编号"/>
                     </Form-item>
-                    <Form-item label="计量单位代码" prop="unitCode">
-                        <i-input v-model="goods.unitCode" placeholder="计量单位代码"/>
+                    <Form-item label="计量单位" prop="unitCode">
+                        <i-select v-model="goods.unitCode" filterable placeholder="计量单位"
+                                  label-in-value>
+                            <i-option v-for="cusUnitCode in cusUnitCodeList" :value="cusUnitCode.code" :key="cusUnitCode.sn">{{cusUnitCode.name}}
+                            </i-option>
+                        </i-select>
                     </Form-item>
                     <Form-item label="海关商品编码" prop="cusGoodsCode">
                         <i-input v-model="goods.cusGoodsCode" placeholder="海关商品编码"/>
@@ -236,8 +240,12 @@
                     <Form-item label="国检规格型号" prop="ciqProdModel" >
                         <i-input v-model="goods.ciqProdModel" placeholder="国检规格型号"/>
                     </Form-item>
-                    <Form-item label="原产国代码" prop="oriCntCode">
-                        <i-input v-model="goods.oriCntCode" placeholder="原产国代码"/>
+                    <Form-item label="原产国" prop="oriCntCode">
+                        <i-select v-model="goods.oriCntCode" filterable placeholder="原产国"
+                                  label-in-value>
+                            <i-option v-for="cusNationCode in cusNationCodeList" :value="cusNationCode.code" :key="cusNationCode.sn">{{cusNationCode.name}}
+                            </i-option>
+                        </i-select>
                     </Form-item>
                     <Form-item label="海关申报要素" prop="cusDeclEle">
                         <i-input v-model="goods.cusDeclEle" placeholder="海关申报要素"/>

+ 6 - 6
kmall-admin/src/main/webapp/WEB-INF/page/sys/role.html

@@ -36,23 +36,23 @@
             <Form-item label="角色名称" prop="roleName">
                 <i-input v-model="role.roleName" placeholder="角色名称"/>
             </Form-item>
-            <Form-item label="所属部门" prop="deptName">
+            <!--<Form-item label="所属部门" prop="deptName">
                 <i-input type="text" v-model="role.deptName" icon="eye" readonly="readonly"
                          @on-click="deptTree" readonly="readonly" placeholder="所属部门"/>
-            </Form-item>
+            </Form-item>-->
             <Form-item label="备注" prop="remark">
                 <i-input type="textarea" v-model="role.remark" placeholder="备注"/>
             </Form-item>
             <Form-item label="功能权限">
-                <div style="overflow-y: auto;max-height: 250px">
+                <div style="overflow-y: auto; max-height: 250px; border: 1px solid #cccccc;">
                     <ul id="menuTree" class="ztree"></ul>
                 </div>
             </Form-item>
-            <Form-item label="数据权限">
-                <div style="overflow-y: auto;max-height: 250px">
+            <!--<Form-item label="数据权限">
+                <div style="overflow-y: auto; max-height: 250px; border: 1px solid #cccccc;">
                     <ul id="dataTree" class="ztree"></ul>
                 </div>
-            </Form-item>
+            </Form-item>-->
             <Form-item>
                 <i-button type="primary" @click="handleSubmit('formValidate')">提交</i-button>
                 <i-button type="warning" @click="reload" style="margin-left: 8px">返回</i-button>

+ 6 - 6
kmall-admin/src/main/webapp/WEB-INF/page/sys/user.html

@@ -36,20 +36,20 @@
             <Form-item label="用户名" prop="username">
                 <i-input v-model="user.username" placeholder="登录账号"/>
             </Form-item>
-            <Form-item label="所属部门" prop="deptName">
+            <!--<Form-item label="所属部门" prop="deptName">
                 <i-input type="text" v-model="user.deptName" icon="eye" readonly="readonly"
                          @on-click="deptTree" readonly="readonly" placeholder="所属部门"/>
-            </Form-item>
+            </Form-item>-->
             <Form-item label="邮箱" prop="email">
                 <i-input v-model="user.email" placeholder="邮箱"/>
             </Form-item>
             <Form-item label="手机号" prop="mobile">
                 <i-input v-model="user.mobile" placeholder="手机号"/>
             </Form-item>
-            <Form-item label="角色" prop="roleIdList">
-                <Checkbox-group v-model="user.roleIdList">
-                    <Checkbox :label="role.roleId" v-for="role in roleList">{{role.roleName}}</Checkbox>
-                </Checkbox-group>
+            <Form-item label="角色" prop="roleId">
+                <i-select v-model="user.roleId" filterable placeholder="角色" label-in-value>
+                    <i-option v-for="role in roleList" :value="role.roleId" :key="role.roleId">{{role.roleName}}</i-option>
+                </i-select>
             </Form-item>
             <Form-item label="数据角色类型" prop="roleType">
                 <Radio-group v-model="user.roleType">

+ 19 - 1
kmall-admin/src/main/webapp/js/shop/goods.js

@@ -135,7 +135,9 @@ var vm = new Vue({
         brands: [],
         freights: [],
         showInput: true,
-        categoryId: ''
+        categoryId: '',
+        cusUnitCodeList: [],
+        cusNationCodeList: []
     },
     methods: {
         delSpeRow: function (index) {
@@ -187,10 +189,14 @@ var vm = new Vue({
             vm.macros = [];
             vm.brands = [];
             vm.freights = [];
+            vm.cusUnitCodeList = [];
+            vm.cusNationCodeList = [];
             vm.attributeEntityList = [{'id': '', 'goodsId': '', 'attributeId': '', 'value': '', 'isDelete': 0}];
             vm.getMacro();
             vm.getBrand();
             vm.getFreights();
+            vm.getCusUnitCodeList();
+            vm.getCusNationCode();
             vm.showInput = true;
         },
         update: function (event) {
@@ -208,6 +214,8 @@ var vm = new Vue({
             vm.getAttributes(opt);
             vm.getMacro();
             vm.getBrand();
+            vm.getCusUnitCodeList();
+            vm.getCusNationCode();
             vm.getFreights();
             vm.getGoodsGallery(id);
             vm.showInput = true;
@@ -226,6 +234,16 @@ var vm = new Vue({
                 vm.brands = r.list;
             });
         },
+        getCusUnitCodeList: function () {
+            $.get("../syscusunitcode/queryAll", function (r) {
+                vm.cusUnitCodeList = r.list;
+            });
+        },
+        getCusNationCode: function () {
+            $.get("../syscusnationcode/queryAll", function (r) {
+                vm.cusNationCodeList = r.list;
+            });
+        },
         getFreights: function() {
             $.get("../freight/queryAll", function (r) {
                 vm.freights = r.list;

+ 1 - 1
kmall-admin/src/main/webapp/js/sys/role.js

@@ -5,7 +5,7 @@ $(function () {
         colModel: [
             {label: '角色ID', name: 'roleId', index: "role_id", key: true, hidden: true},
             {label: '角色名称', name: 'roleName', index: "role_name", width: 75},
-            {label: '所属部门', name: 'deptName', width: 75},
+            // {label: '所属部门', name: 'deptName', width: 75},
             {label: '备注', name: 'remark', width: 100},
             {
                 label: '创建时间', name: 'createTime', index: "create_time", width: 80, formatter: function (value) {

+ 4 - 4
kmall-admin/src/main/webapp/js/sys/user.js

@@ -5,7 +5,7 @@ $(function () {
         colModel: [
             {label: '用户ID', name: 'userId', index: "user_id", key: true, hidden: true},
             {label: '用户名', name: 'username', width: 75},
-            {label: '所属部门', name: 'deptName', width: 75},
+            // {label: '所属部门', name: 'deptName', width: 75},
             {label: '邮箱', name: 'email', width: 90},
             {label: '手机号', name: 'mobile', width: 100},
             {
@@ -77,7 +77,7 @@ var vm = new Vue({
             roleIdList: []
         },
         ruleValidate: {
-            username: [
+            /*username: [
                 {required: true, message: '姓名不能为空', trigger: 'blur'}
             ],
             email: [
@@ -86,7 +86,7 @@ var vm = new Vue({
             ],
             mobile: [
                 {required: true, message: '手机号不能为空', trigger: 'blur'}
-            ]
+            ]*/
         },
         storeList: []
     },
@@ -98,7 +98,7 @@ var vm = new Vue({
             vm.showList = false;
             vm.title = "新增(默认密码:111111)";
             vm.roleList = {};
-            vm.user = {status: 1, roleIdList: [], deptId: '', deptName: '', storeId: ''};
+            vm.user = {status: 1, roleIdList: [], deptId: '', deptName: '', storeId: '', roleType: 2};
             vm.storeList = [];
             //获取角色信息
             this.getRoleList();

+ 2 - 2
kmall-common/src/main/java/com/kmall/common/controller/SysRoleController.java

@@ -99,8 +99,8 @@ public class SysRoleController extends AbstractController {
     @RequestMapping("/save")
     @RequiresPermissions("sys:role:save")
     public R save(@RequestBody SysRoleEntity role) {
-        ValidatorUtils.validateEntity(role);
-
+        // 非空检验
+        // ValidatorUtils.validateEntity(role);
         role.setCreateUserId(getUserId());
         sysRoleService.save(role);
 

+ 3 - 4
kmall-common/src/main/java/com/kmall/common/controller/SysUserController.java

@@ -68,6 +68,7 @@ public class SysUserController extends AbstractController {
     @SysLog("修改密码")
     @RequestMapping("/password")
     public R password(String password, String newPassword) {
+        Assert.isBlank(password, "原密码不为能空");
         Assert.isBlank(newPassword, "新密码不为能空");
 
         //sha256加密
@@ -109,8 +110,7 @@ public class SysUserController extends AbstractController {
     @RequestMapping("/save")
     @RequiresPermissions("sys:user:save")
     public R save(@RequestBody SysUserEntity user) {
-        ValidatorUtils.validateEntity(user, AddGroup.class);
-
+        //ValidatorUtils.validateEntity(user);
         user.setCreateUserId(getUserId());
         sysUserService.save(user);
 
@@ -124,8 +124,7 @@ public class SysUserController extends AbstractController {
     @RequestMapping("/update")
     @RequiresPermissions("sys:user:update")
     public R update(@RequestBody SysUserEntity user) {
-        ValidatorUtils.validateEntity(user, UpdateGroup.class);
-
+        //ValidatorUtils.validateEntity(user);
         user.setCreateUserId(getUserId());
         sysUserService.update(user);
 

+ 2 - 0
kmall-common/src/main/java/com/kmall/common/dao/SysUserRoleDao.java

@@ -17,4 +17,6 @@ public interface SysUserRoleDao extends BaseDao<SysUserRoleEntity> {
      * 根据用户ID,获取角色ID列表
      */
     List<Long> queryRoleIdList(Long userId);
+
+    int deleteByRoleId(Long roleId);
 }

+ 10 - 0
kmall-common/src/main/java/com/kmall/common/entity/SysUserEntity.java

@@ -75,6 +75,8 @@ public class SysUserEntity implements Serializable {
      */
     private String deptName;
 
+    private Long roleId;
+
     private Integer storeId;
 
     private String roleType;
@@ -99,6 +101,14 @@ public class SysUserEntity implements Serializable {
         return userId;
     }
 
+    public Long getRoleId() {
+        return roleId;
+    }
+
+    public void setRoleId(Long roleId) {
+        this.roleId = roleId;
+    }
+
     /**
      * 设置:用户名
      *

+ 2 - 0
kmall-common/src/main/java/com/kmall/common/service/SysRoleMenuService.java

@@ -19,4 +19,6 @@ public interface SysRoleMenuService {
      */
     List<Long> queryMenuIdList(Long roleId);
 
+    int delete(Long roleId);
+
 }

+ 2 - 0
kmall-common/src/main/java/com/kmall/common/service/SysRoleService.java

@@ -27,6 +27,8 @@ public interface SysRoleService {
 
     void deleteBatch(Long[] roleIds);
 
+    void delete(Long roleId);
+
     /**
      * 查询用户创建的角色ID列表
      */

+ 1 - 1
kmall-common/src/main/java/com/kmall/common/service/SysUserRoleService.java

@@ -12,7 +12,7 @@ import java.util.List;
  */
 public interface SysUserRoleService {
 
-    void saveOrUpdate(Long userId, List<Long> roleIdList);
+    void saveOrUpdate(Long userId, Long roleId);
 
     /**
      * 根据用户ID,获取角色ID列表

+ 5 - 0
kmall-common/src/main/java/com/kmall/common/service/impl/SysRoleMenuServiceImpl.java

@@ -44,4 +44,9 @@ public class SysRoleMenuServiceImpl implements SysRoleMenuService {
         return sysRoleMenuDao.queryMenuIdList(roleId);
     }
 
+    @Override
+    public int delete(Long roleId) {
+        return sysRoleMenuDao.delete(roleId);
+    }
+
 }

+ 34 - 3
kmall-common/src/main/java/com/kmall/common/service/impl/SysRoleServiceImpl.java

@@ -1,7 +1,9 @@
 package com.kmall.common.service.impl;
 
 import com.kmall.common.dao.SysRoleDao;
+import com.kmall.common.dao.SysUserRoleDao;
 import com.kmall.common.entity.SysRoleEntity;
+import com.kmall.common.entity.SysUserRoleEntity;
 import com.kmall.common.service.SysRoleDeptService;
 import com.kmall.common.service.SysRoleMenuService;
 import com.kmall.common.service.SysRoleService;
@@ -13,6 +15,7 @@ import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
 
 import java.util.Date;
+import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
 
@@ -29,6 +32,8 @@ public class SysRoleServiceImpl implements SysRoleService {
     @Autowired
     private SysRoleDao sysRoleDao;
     @Autowired
+    private SysUserRoleDao sysUserRoleDao;
+    @Autowired
     private SysRoleMenuService sysRoleMenuService;
     @Autowired
     private SysUserService sysUserService;
@@ -53,6 +58,10 @@ public class SysRoleServiceImpl implements SysRoleService {
     @Override
     @Transactional
     public void save(SysRoleEntity role) {
+        if (role.getMenuIdList() == null || role.getMenuIdList().size() <= 0) {
+            throw new RRException("功能权不能为空!");
+        }
+
         role.setCreateTime(new Date());
         sysRoleDao.save(role);
 
@@ -63,12 +72,16 @@ public class SysRoleServiceImpl implements SysRoleService {
         sysRoleMenuService.saveOrUpdate(role.getRoleId(), role.getMenuIdList());
 
         //保存角色与部门关系
-        sysRoleDeptService.saveOrUpdate(role.getRoleId(), role.getDeptIdList());
+        //sysRoleDeptService.saveOrUpdate(role.getRoleId(), role.getDeptIdList());
     }
 
     @Override
     @Transactional
     public void update(SysRoleEntity role) {
+        if (role.getMenuIdList() == null || role.getMenuIdList().size() <= 0) {
+            throw new RRException("功能权不能为空!");
+        }
+
         sysRoleDao.update(role);
 
         //检查权限是否越权
@@ -77,13 +90,31 @@ public class SysRoleServiceImpl implements SysRoleService {
         //更新角色与菜单关系
         sysRoleMenuService.saveOrUpdate(role.getRoleId(), role.getMenuIdList());
         //保存角色与部门关系
-        sysRoleDeptService.saveOrUpdate(role.getRoleId(), role.getDeptIdList());
+        //sysRoleDeptService.saveOrUpdate(role.getRoleId(), role.getDeptIdList());
     }
 
     @Override
     @Transactional
     public void deleteBatch(Long[] roleIds) {
-        sysRoleDao.deleteBatch(roleIds);
+        for (Long id : roleIds) {
+            SysRoleEntity role = queryObject(id);
+
+            Map<String, Object> map = new HashMap<>();
+            map.put("roleId", id);
+            List<SysUserRoleEntity> userEntityList = sysUserRoleDao.queryList(map);
+
+            if (userEntityList != null && userEntityList.size() > 0) {
+                throw new RRException("角色【" + role.getRoleName() + "】还有【" + userEntityList.size() + "】个管理员正在使用,删除失败!");
+            }
+            sysUserRoleDao.deleteByRoleId(id);
+            sysRoleMenuService.delete(id);
+            delete(id);
+        }
+    }
+
+    @Override
+    public void delete(Long roleId) {
+        sysRoleDao.delete(roleId);
     }
 
     @Override

+ 2 - 5
kmall-common/src/main/java/com/kmall/common/service/impl/SysUserRoleServiceImpl.java

@@ -23,10 +23,7 @@ public class SysUserRoleServiceImpl implements SysUserRoleService {
     private SysUserRoleDao sysUserRoleDao;
 
     @Override
-    public void saveOrUpdate(Long userId, List<Long> roleIdList) {
-        if (roleIdList.size() == 0) {
-            return;
-        }
+    public void saveOrUpdate(Long userId, Long roleId) {
 
         //先删除用户与角色关系
         sysUserRoleDao.delete(userId);
@@ -34,7 +31,7 @@ public class SysUserRoleServiceImpl implements SysUserRoleService {
         //保存用户与角色关系
         Map<String, Object> map = new HashMap<>();
         map.put("userId", userId);
-        map.put("roleIdList", roleIdList);
+        map.put("roleId", roleId);
         sysUserRoleDao.save(map);
     }
 

+ 62 - 4
kmall-common/src/main/java/com/kmall/common/service/impl/SysUserServiceImpl.java

@@ -1,13 +1,13 @@
 package com.kmall.common.service.impl;
 
+import com.google.common.collect.ImmutableBiMap;
 import com.kmall.common.Global;
 import com.kmall.common.dao.SysUserDao;
 import com.kmall.common.entity.SysUserEntity;
 import com.kmall.common.service.SysRoleService;
 import com.kmall.common.service.SysUserRoleService;
 import com.kmall.common.service.SysUserService;
-import com.kmall.common.utils.Constant;
-import com.kmall.common.utils.RRException;
+import com.kmall.common.utils.*;
 import org.apache.commons.lang.StringUtils;
 import org.apache.shiro.crypto.hash.Sha256Hash;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -70,6 +70,35 @@ public class SysUserServiceImpl implements SysUserService {
     @Override
     @Transactional
     public void save(SysUserEntity user) {
+        Map<String, Object> valideDate = MapBeanUtil.fromObject(user);
+        ImmutableBiMap.Builder builder = new ImmutableBiMap.Builder();
+        builder.put("username", "用户名");
+        builder.put("email", "邮箱");
+        builder.put("mobile", "手机号");
+        builder.put("roleType", "数据角色类型");
+        builder.put("status", "状态");
+        builder.put("roleId", "角色");
+
+        R r = ValidatorUtil.isEmpty(builder.build(), valideDate);
+        if (Integer.valueOf(r.get("code").toString()) != 0) {
+            throw new RRException(r.get("msg").toString());
+        } else {
+            if (!"1".equals(user.getRoleType())) {
+                builder.put("storeId", "门店");
+            }
+            r = ValidatorUtil.isEmpty(builder.build(), valideDate);
+            if (Integer.valueOf(r.get("code").toString()) != 0) {
+                throw new RRException(r.get("msg").toString());
+            }
+        }
+
+        if (!user.getEmail().matches("^[a-z0-9A-Z]+[- | a-z0-9A-Z . _]+@([a-z0-9A-Z]+(-[a-z0-9A-Z]+)?\\.)+[a-z]{2,}$")) {
+            throw new RRException("邮箱格式错误!");
+        }
+        if (!PhoneFormatCheckUtils.isPhoneLegal(user.getMobile())) {
+            throw new RRException("手机号格式错误!");
+        }
+
         user.setCreateTime(new Date());
         //sha256加密
         user.setPassword(new Sha256Hash(Global.DEFAULT_PASS_WORD).toHex());
@@ -79,12 +108,41 @@ public class SysUserServiceImpl implements SysUserService {
         checkRole(user);
 
         //保存用户与角色关系
-        sysUserRoleService.saveOrUpdate(user.getUserId(), user.getRoleIdList());
+        sysUserRoleService.saveOrUpdate(user.getUserId(), user.getRoleId());
     }
 
     @Override
     @Transactional
     public void update(SysUserEntity user) {
+        Map<String, Object> valideDate = MapBeanUtil.fromObject(user);
+        ImmutableBiMap.Builder builder = new ImmutableBiMap.Builder();
+        builder.put("username", "用户名");
+        builder.put("email", "邮箱");
+        builder.put("mobile", "手机号");
+        builder.put("roleType", "数据角色类型");
+        builder.put("status", "状态");
+        builder.put("roleId", "角色");
+
+        R r = ValidatorUtil.isEmpty(builder.build(), valideDate);
+        if (Integer.valueOf(r.get("code").toString()) != 0) {
+            throw new RRException(r.get("msg").toString());
+        } else {
+            if (!"1".equals(user.getRoleType())) {
+                builder.put("storeId", "门店");
+            }
+            r = ValidatorUtil.isEmpty(builder.build(), valideDate);
+            if (Integer.valueOf(r.get("code").toString()) != 0) {
+                throw new RRException(r.get("msg").toString());
+            }
+        }
+
+        if (!user.getEmail().matches("^[a-z0-9A-Z]+[- | a-z0-9A-Z . _]+@([a-z0-9A-Z]+(-[a-z0-9A-Z]+)?\\.)+[a-z]{2,}$")) {
+            throw new RRException("邮箱格式错误!");
+        }
+        if (!PhoneFormatCheckUtils.isPhoneLegal(user.getMobile())) {
+            throw new RRException("手机号格式错误!");
+        }
+
         if (StringUtils.isBlank(user.getPassword())) {
             user.setPassword(new Sha256Hash(Global.DEFAULT_PASS_WORD).toHex());
         } else {
@@ -96,7 +154,7 @@ public class SysUserServiceImpl implements SysUserService {
         checkRole(user);
 
         //保存用户与角色关系
-        sysUserRoleService.saveOrUpdate(user.getUserId(), user.getRoleIdList());
+        sysUserRoleService.saveOrUpdate(user.getUserId(), user.getRoleId());
     }
 
     @Override

+ 1 - 7
kmall-common/src/main/java/com/kmall/common/shiro/UserRealm.java

@@ -68,13 +68,7 @@ public class UserRealm extends AuthorizingRealm {
         Long userId = user.getUserId();
         //系统管理员,拥有最高权限
         List<String> permsList = null;
-        if (userId == 1) {
-            List<SysMenuEntity> menuList = sysMenuDao.queryList(new HashMap<String, Object>());
-            permsList = new ArrayList<>(menuList.size());
-            for (SysMenuEntity menu : menuList) {
-                permsList.add(menu.getPerms());
-            }
-        } else {
+        if (userId != null) {
             permsList = sysUserDao.queryAllPerms(userId);
         }
         //用户权限列表

+ 13 - 3
kmall-common/src/main/resources/mybatis/mapper/SysUserDao.xml

@@ -3,11 +3,22 @@
 
 <mapper namespace="com.kmall.common.dao.SysUserDao">
 	<select id="queryObject" resultType="com.kmall.common.entity.SysUserEntity">
-		select * from sys_user where user_id = #{value}
+		SELECT
+		u.*, ( SELECT d.NAME FROM sys_dept d WHERE d.dept_id = u.dept_id ) deptName, ur.role_id
+		FROM
+		sys_user u
+		LEFT JOIN sys_user_role ur ON u.user_id = ur.user_id
+		where u.user_id = #{value}
 	</select>
 	
 	<select id="queryList" resultType="com.kmall.common.entity.SysUserEntity">
-		select u.*, (select d.name from sys_dept d where d.dept_id = u.dept_id) deptName from sys_user u
+		SELECT
+		u.*,
+		( SELECT d.NAME FROM sys_dept d WHERE d.dept_id = u.dept_id ) deptName,
+		ur.role_id
+		FROM
+		sys_user u
+		LEFT JOIN sys_user_role ur ON u.user_id = ur.user_id
 		<where>
 			<if test="createUserId != null">
 				and `create_user_id` = #{createUserId} 
@@ -98,7 +109,6 @@
 		update sys_user 
 		<set> 
 			<if test="username != null">`username` = #{username}, </if>
-			<if test="password != null">`password` = #{password}, </if>
 			<if test="email != null">`email` = #{email}, </if>
 			<if test="mobile != null">`mobile` = #{mobile}, </if>
 			<if test="status != null">`status` = #{status}, </if>

+ 8 - 3
kmall-common/src/main/resources/mybatis/mapper/SysUserRoleDao.xml

@@ -9,6 +9,9 @@
 			<if test="userId != null">
 				user_id = #{userId}
 			</if>
+			<if test="roleId != null">
+				role_id = #{roleId}
+			</if>
 		</where>
 	</select>
  
@@ -19,17 +22,19 @@
 			`role_id`
 		)
 		values
-		<foreach collection="roleIdList" item="item" index="index" separator="," >
 		(
 			#{userId}, 
-			#{item}
+			#{roleId}
 		)
-		</foreach>
 	</insert>
 	
 	<delete id="delete">
 		delete from sys_user_role where user_id = #{value}
 	</delete>
+
+	<delete id="deleteByRoleId">
+		delete from sys_user_role where role_id = #{value}
+	</delete>
 	
 	<select id="queryRoleIdList" resultType="long">
 		select role_id from sys_user_role where user_id = #{value}