Quellcode durchsuchen

用户列表相关人员属性修改

zhangxin vor 2 Wochen
Ursprung
Commit
51f791a027

+ 6 - 0
yami-shop-bean/src/main/java/com/yami/shop/bean/model/User.java

@@ -156,4 +156,10 @@ public class User implements Serializable {
      * 渠道ID
      */
     private Long channelId;
+
+    /**
+     * 20251203 v1.1.3
+     * 人员属性 0-全部 1-正常人员 2-测试人员
+     */
+    private String userAttrType;
 }

+ 5 - 0
yami-shop-bean/src/main/java/com/yami/shop/bean/param/BackendOrderParam.java

@@ -86,5 +86,10 @@ public class BackendOrderParam {
      * 企业ID列表
      */
     private List<Long> channelIdList;
+    /**
+     * 20251203 v1.1.3
+     * 人员属性 0-全部 1-正常人员 2-测试人员
+     */
+    private Integer userAttrType;
 
 }

+ 10 - 0
yami-shop-bean/src/main/java/com/yami/shop/bean/po/EnterpriseUserExcelInfo.java

@@ -17,8 +17,18 @@ public class EnterpriseUserExcelInfo {
     @ExcelProperty("员工姓名")
     private String realName;
 
+    /**
+     * 20251203 v1.1.3
+     * 人员属性 0-全部 1-正常人员 2-测试人员
+     */
+    @ApiModelProperty(value = "人员属性")
+    @ExcelProperty("人员属性")
+    private String userAttrName;
+
     @ApiModelProperty(value = "员工手机号")
     @ExcelProperty("员工手机号")
     private String phone;
 
+
+
 }

+ 12 - 0
yami-shop-bean/src/main/java/com/yami/shop/bean/po/EnterpriseUserPo.java

@@ -23,10 +23,22 @@ public class EnterpriseUserPo {
      */
     private List<Long> channelIdList;
 
+    /**
+     * 20251203 v1.1.3
+     * 人员属性 0-全部 1-正常人员 2-测试人员
+     */
+    private String userAttrType;
 
     public EnterpriseUserPo(Long channelId, String realName, String userMobile) {
         this.channelId = channelId;
         this.realName = realName;
         this.userMobile = userMobile;
     }
+
+    public EnterpriseUserPo(Long channelId, String realName, String userMobile, String userAttrType) {
+        this.channelId = channelId;
+        this.realName = realName;
+        this.userMobile = userMobile;
+        this.userAttrType = userAttrType;
+    }
 }

+ 6 - 0
yami-shop-bean/src/main/java/com/yami/shop/bean/vo/EnterpriseUserVo.java

@@ -34,4 +34,10 @@ public class EnterpriseUserVo {
     private Double expired;
 
     private Double used;
+
+    /**
+     * 20251203 v1.1.3
+     * 人员属性 0-全部 1-正常人员 2-测试人员
+     */
+    private String userAttrType;
 }

+ 8 - 0
yami-shop-platform/src/main/java/com/yami/shop/platform/controller/UserEnterpriseController.java

@@ -1,5 +1,6 @@
 package com.yami.shop.platform.controller;
 
+import cn.hutool.core.util.ObjectUtil;
 import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.yami.shop.bean.model.User;
 import com.yami.shop.bean.param.OrderRefundStaisticsParam;
@@ -69,6 +70,9 @@ public class UserEnterpriseController {
         if (po.getChannelIdList()==null||po.getChannelIdList().isEmpty()){
             throw new GlobalException("请求参数-所属企业不允许为空");
         }
+        if (ObjectUtil.isEmpty(po.getUserAttrType())){
+            po.setUserAttrType("1");//默认查询正常人员属性
+        }
         if (po.getChannelIdList().contains(0L)){
             Long userId = SecurityUtils.getSysUser().getUserId();
            List<Long> channelIdList =  sysUserService.findByUserIdListId(userId);
@@ -119,6 +123,7 @@ public class UserEnterpriseController {
         updateUser.setChannelId(user.getChannelId());
         updateUser.setUserId(user.getUserId());
         updateUser.setStatus(user.getStatus());
+        updateUser.setUserAttrType(user.getUserAttrType());
         userService.updateById(updateUser);
         return R.SUCCESS();
     }
@@ -135,6 +140,9 @@ public class UserEnterpriseController {
         if (po.getChannelIdList()==null||po.getChannelIdList().isEmpty()){
             throw new GlobalException("请求参数-所属企业不允许为空");
         }
+        if (ObjectUtil.isEmpty(po.getUserAttrType())){
+            po.setUserAttrType("1");//默认查询正常人员属性
+        }
         if (po.getChannelIdList().contains(0L)){
             Long userId = null;
             try {

+ 1 - 1
yami-shop-service/src/main/java/com/yami/shop/dao/UserMapper.java

@@ -42,7 +42,7 @@ public interface UserMapper extends BaseMapper<User> {
     IPage<EnterpriseUserVo> enterpriseUserList(@Param("page") PageParam<EnterpriseUserPo> page, @Param("po") EnterpriseUserPo po);
 
     void addUserLog(@Param("operator") String operator, @Param("batchNo") String batchNo,@Param("status") String status,
-                    @Param("channel") String channel,@Param("realName") String realName,@Param("phone") String phone);
+                    @Param("channel") String channel,@Param("realName") String realName,@Param("phone") String phone,@Param("userAttrType") String userAttrType );
 
     IPage<EnterpriseUserLogPo> enterpriseUserLogList(@Param("page") PageParam<EnterpriseUserLogPo> page);
 

+ 75 - 8
yami-shop-service/src/main/java/com/yami/shop/service/impl/UserServiceImpl.java

@@ -14,6 +14,8 @@ import cn.hutool.core.util.IdUtil;
 import cn.hutool.core.util.StrUtil;
 import com.alibaba.excel.EasyExcel;
 import com.alibaba.excel.read.listener.PageReadListener;
+import com.alibaba.excel.write.handler.CellWriteHandler;
+import com.alibaba.excel.write.handler.context.CellWriteHandlerContext;
 import com.alibaba.excel.write.style.column.LongestMatchColumnWidthStyleStrategy;
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.baomidou.mybatisplus.core.metadata.IPage;
@@ -22,6 +24,7 @@ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import com.google.common.collect.Lists;
 import com.yami.shop.bean.app.param.UserRegisterParam;
 import com.yami.shop.bean.model.Channel;
+import com.yami.shop.bean.model.SysDictData;
 import com.yami.shop.bean.model.User;
 import com.yami.shop.bean.po.EnterpriseUserErrExcelInfo;
 import com.yami.shop.bean.po.EnterpriseUserExcelInfo;
@@ -34,6 +37,8 @@ import com.yami.shop.common.util.IPHelper;
 import com.yami.shop.common.util.PageParam;
 import com.yami.shop.common.util.RedisUtil;
 import com.yami.shop.dao.ChannelMapper;
+import com.yami.shop.dao.SysDictDataMapper;
+import com.yami.shop.dao.SysDictTypeMapper;
 import com.yami.shop.dao.UserMapper;
 import com.yami.shop.service.UserExtensionService;
 import com.yami.shop.service.UserService;
@@ -42,11 +47,10 @@ import com.yami.shop.utils.ExportUtils;
 import lombok.AllArgsConstructor;
 import lombok.SneakyThrows;
 import lombok.extern.slf4j.Slf4j;
-import org.apache.poi.ss.usermodel.CellStyle;
-import org.apache.poi.ss.usermodel.Row;
-import org.apache.poi.ss.usermodel.Sheet;
-import org.apache.poi.ss.usermodel.Workbook;
+import org.apache.commons.lang3.StringUtils;
+import org.apache.poi.ss.usermodel.*;
 import org.apache.poi.xssf.usermodel.XSSFWorkbook;
+import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
 import org.springframework.web.multipart.MultipartFile;
@@ -70,6 +74,9 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements Us
     private final ChannelMapper channelMapper;
     private final UserExtensionService userExtensionService;
 
+    @Autowired
+    private SysDictDataMapper dictDataMapper;
+
 
     @Override
     public User getUserByUserId(String userId) {
@@ -125,12 +132,48 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements Us
     @Override
     public void downloadExcelGoods(HttpServletResponse response) {
         try {
+            List<SysDictData> userAttrTypeList = dictDataMapper.selectDictDataByType("user_attr_type");//查询人员属性
+            String userAttrName =null;
+            if (userAttrTypeList!=null&&!userAttrTypeList.isEmpty()){
+                userAttrName="";
+                for (SysDictData sysDictData : userAttrTypeList) {
+                    userAttrName=userAttrName+sysDictData.getDictLabel()+";";
+                }
+            }
+
             List<EnterpriseUserExcelInfo> list = Lists.newArrayList();
+            //添加实例行
+            EnterpriseUserExcelInfo enterpriseUserExcelInfo = new EnterpriseUserExcelInfo();
+            enterpriseUserExcelInfo.setChannel("必填!");
+            enterpriseUserExcelInfo.setRealName("必填!");
+            if (StringUtils.isNotEmpty(userAttrName)){
+                enterpriseUserExcelInfo.setUserAttrName("必填!"+userAttrName);
+            }else {
+                enterpriseUserExcelInfo.setUserAttrName("必填!且值为1");
+            }
+
+            enterpriseUserExcelInfo.setPhone("必填!可必须输入真实手机号,且该手机号码有微信");
+            list.add(enterpriseUserExcelInfo);
             response.setCharacterEncoding("utf-8");
             String fileName = URLEncoder.encode("企业员工导入模板", "UTF-8").replaceAll("\\+", "%20");
             response.setHeader("Content-disposition", "attachment;filename*=utf-8''" + fileName + ".xlsx");
             EasyExcel.write(response.getOutputStream(), EnterpriseUserExcelInfo.class)
                     .registerWriteHandler(new LongestMatchColumnWidthStyleStrategy())
+                    .registerWriteHandler(new CellWriteHandler() {
+                        @Override
+                        public void afterCellDispose(CellWriteHandlerContext context) {
+                            // 为第一行(示例行)设置特殊样式
+                            if (context.getRowIndex() == 0) {
+                                Cell cell = context.getCell();
+                                CellStyle cellStyle = cell.getSheet().getWorkbook().createCellStyle();
+                                Font font = cell.getSheet().getWorkbook().createFont();
+                                font.setColor(IndexedColors.RED.getIndex()); // 红色字体
+                                font.setBold(true); // 加粗
+                                cellStyle.setFont(font);
+                                cell.setCellStyle(cellStyle);
+                            }
+                        }
+                    })
                     .sheet("列表").doWrite(list);
         } catch (IOException e) {
             throw new GlobalException("文件下载异常");
@@ -141,6 +184,7 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements Us
     @SneakyThrows
     @Transactional(rollbackFor = Exception.class)
     public void uploadExcelGoods(MultipartFile file,String username) {
+        List<SysDictData> userAttrTypeList = dictDataMapper.selectDictDataByType("user_attr_type");//查询人员属性
         List<EnterpriseUserExcelInfo> goodsInfoList = Lists.newArrayList();
         String batchNo = String.valueOf(System.currentTimeMillis());
         EasyExcel.read(file.getInputStream(), EnterpriseUserExcelInfo.class, new PageReadListener<EnterpriseUserExcelInfo>(goodsInfoList::addAll)).sheet().doRead();
@@ -150,12 +194,14 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements Us
             CullenUtils.validateDataThrowException(c.getPhone()==null,"手机号不能为空...");
             CullenUtils.validateDataThrowException(c.getChannel()==null,"渠道不能为空...");
             CullenUtils.validateDataThrowException(c.getRealName()==null,"姓名不能为空...");
+            CullenUtils.validateDataThrowException(c.getUserAttrName()==null,"人员属性不能为空...");
+            String userAttrType = getUserAttrType(c.getUserAttrName().replaceAll("\\s+", ""), userAttrTypeList);
             String phone = c.getPhone().replaceAll("\\s+", "");
-            if (phone.length()!=11||!CullenUtils.isNumeric(phone)) {
-                userMapper.addUserLog(username,batchNo,"0",c.getChannel(),c.getRealName(),c.getPhone());
+            if (phone.length()!=11||!CullenUtils.isNumeric(phone)||"0".equals(userAttrType)) {
+                userMapper.addUserLog(username,batchNo,"0",c.getChannel(),c.getRealName(),c.getPhone(),userAttrType);
             }else {
-                addUser(new EnterpriseUserPo(getChannel(c.getChannel()), c.getRealName(), c.getPhone()));
-                userMapper.addUserLog(username,batchNo,"1",c.getChannel(),c.getRealName(),c.getPhone());
+                addUser(new EnterpriseUserPo(getChannel(c.getChannel()), c.getRealName(), c.getPhone(),userAttrType));
+                userMapper.addUserLog(username,batchNo,"1",c.getChannel(),c.getRealName(),c.getPhone(),userAttrType);
             }
         });
     }
@@ -208,6 +254,7 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements Us
             user.setStatus(1);
             user.setLevel(1);
             user.setLevelType(0);
+            user.setUserAttrType(po.getUserAttrType());
             user.setChannelId(po.getChannelId());
             user.setChannelId(po.getChannelId());
             user.setUserId(IdUtil.simpleUUID());
@@ -221,6 +268,7 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements Us
                 user.setRealName(po.getRealName());
                 user.setChannelId(po.getChannelId());
                 user.setUserId(userInfo.getUserId());
+                user.setUserAttrType(po.getUserAttrType());
                 userMapper.updateById(user);
             }else {
                 if (userInfo.getChannelId().equals(po.getChannelId())){
@@ -232,6 +280,7 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements Us
                     user.setRealName(po.getRealName());
                     user.setChannelId(po.getChannelId());
                     user.setUserId(userInfo.getUserId());
+                    user.setUserAttrType(po.getUserAttrType());
                     userMapper.updateById(user);
                 }
             }
@@ -403,4 +452,22 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements Us
         // 已消耗积分
         ExportUtils.createCell(sheet,row, 7,0,0, orderRefundVo.getUsed(), numberStyle);
     }
+
+    private String getUserAttrType(String userAttrName,List<SysDictData> sysDictDataList){
+        if (StringUtils.isNotEmpty(userAttrName)){
+            if (!sysDictDataList.isEmpty()){
+                for (SysDictData sysDictData : sysDictDataList) {
+                    if (sysDictData.getDictLabel().equals(userAttrName)){
+                        return sysDictData.getDictValue();
+                    }
+                }
+                return "0";
+            }else if (userAttrName.equals("1")){
+                return userAttrName;
+            }else {
+                return "0";
+            }
+        }
+        return "0";
+    }
 }

+ 2 - 2
yami-shop-service/src/main/resources/mapper/OrderMapper.xml

@@ -498,8 +498,8 @@
             <if test="orderParam.dvyType != null and orderParam.dvyType != ''">
                 and d.dvy_type = #{orderParam.dvyType}
             </if>
-            <if test="orderParam.personnelType != null">
-                and a.personnel_type = #{orderParam.personnelType}
+            <if test="orderParam.userAttrType != null and orderParam.userAttrType != 0">
+                AND d.user_attr_type = #{userAttrType}
             </if>
             <if test="orderParam.shopId != null">
                 and a.shop_id = #{orderParam.shopId}

+ 9 - 3
yami-shop-service/src/main/resources/mapper/UserMapper.xml

@@ -105,7 +105,7 @@
 
 
     <select id="enterpriseUserList" resultType="com.yami.shop.bean.vo.EnterpriseUserVo">
-        SELECT a.user_id,a.`status`,a.real_name,a.user_mobile,a.channel_id,
+        SELECT a.user_id,a.`status`,a.real_name,a.user_mobile,a.channel_id,a.user_attr_type,
         (SELECT channel_name FROM tz_channel WHERE id= a.channel_id) channelName,
         IFNULL((SELECT SUM(points) FROM tz_points_recharge WHERE user_id=a.user_id),0) total, -- 总积分
 
@@ -144,6 +144,9 @@
                     #{channelId}
                 </foreach>
             </if>
+            <if test="po.userAttrType != null and po.userAttrType != '' and po.userAttrType != 0">
+                AND a.user_attr_type = #{po.userAttrType}
+            </if>
             <if test="po.realName != null and po.realName != ''">
                 AND a.real_name LIKE CONCAT("%",#{po.realName},"%")
             </if>
@@ -154,8 +157,8 @@
     </select>
 
     <insert id="addUserLog" parameterType="string">
-        insert into tz_user_add_log(operator, batch_no, task_name, create_time, complete_time, `status`, channel,real_name, phone)
-        values (#{operator}, #{batchNo}, "员工导入", NOW(), NOW(), #{status}, #{channel}, #{realName}, #{phone})
+        insert into tz_user_add_log(operator, batch_no, task_name, create_time, complete_time, `status`, channel,real_name, user_attr_type,)
+        values (#{operator}, #{batchNo}, "员工导入", NOW(), NOW(), #{status}, #{channel}, #{realName}, #{phone},#{userAttrType})
     </insert>
 
     <select id="enterpriseUserLogList" resultType="com.yami.shop.bean.po.EnterpriseUserLogPo">
@@ -237,6 +240,9 @@
                     #{channelId}
                 </foreach>
             </if>
+            <if test="po.userAttrType != null and po.userAttrType != '' and po.userAttrType != 0">
+                AND a.user_attr_type = #{po.userAttrType}
+            </if>
             <if test="po.realName != null and po.realName != ''">
                 AND a.real_name LIKE CONCAT("%",#{po.realName},"%")
             </if>

+ 6 - 0
yami-shop-sys/src/main/java/com/yami/shop/sys/controller/SysDictTypeController.java

@@ -61,6 +61,9 @@ public class SysDictTypeController{
      */
     @PutMapping
     public R<Void> edit(@Validated @RequestBody SysDictType dict) {
+        if (dict.getDictId()==1){
+            return R.FAIL("修改字典人员属性失败,字典类型人员属性不允许修改");
+        }
         if (!dictTypeService.checkDictTypeUnique(dict)) {
             return R.FAIL("修改字典'" + dict.getDictName() + "'失败,字典类型已存在");
         }
@@ -75,6 +78,9 @@ public class SysDictTypeController{
      */
     @DeleteMapping("/{dictIds}")
     public R<Void> remove(@PathVariable Long[] dictIds) {
+        if (dictIds != null && Arrays.asList(dictIds).contains(1L)){
+            return R.FAIL("修改字典人员属性失败,字典类型人员属性不允许修改");
+        }
         dictTypeService.deleteDictTypeByIds(dictIds);
         return R.SUCCESS();
     }