wangming vor 1 Woche
Ursprung
Commit
6c9c131d1a

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

@@ -155,4 +155,6 @@ public class User implements Serializable {
      * 1铜仁移动(企业用户) 2夫妻店(B端) 3 市民请集合(C端)
      */
     private Integer platform;
+
+    private Long channelId;
 }

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

@@ -0,0 +1,24 @@
+package com.yami.shop.bean.po;
+
+import com.alibaba.excel.annotation.ExcelProperty;
+import io.swagger.annotations.ApiModel;
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+
+@Data
+@ApiModel(value = "企业用户模板po")
+public class EnterpriseUserExcelInfo {
+
+    @ExcelProperty("所属企业")
+    @ApiModelProperty(value = "所属企业")
+    private String channel;
+
+    @ApiModelProperty(value = "员工姓名")
+    @ExcelProperty("员工姓名")
+    private String realName;
+
+    @ApiModelProperty(value = "员工手机号")
+    @ExcelProperty("员工手机号")
+    private String phone;
+
+}

+ 5 - 1
yami-shop-bean/src/main/java/com/yami/shop/bean/po/EnterpriseUserPo.java

@@ -1,12 +1,16 @@
 
 package com.yami.shop.bean.po;
 
+import lombok.AllArgsConstructor;
 import lombok.Data;
+import lombok.NoArgsConstructor;
 
 @Data
+@NoArgsConstructor
+@AllArgsConstructor
 public class EnterpriseUserPo {
 
-    private Integer channelId;
+    private Long channelId;
 
     private String realName;
 

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

@@ -0,0 +1,94 @@
+package com.yami.shop.platform.controller;
+
+import com.baomidou.mybatisplus.core.metadata.IPage;
+import com.yami.shop.bean.model.User;
+import com.yami.shop.bean.po.EnterpriseUserPo;
+import com.yami.shop.bean.vo.EnterpriseUserVo;
+import com.yami.shop.common.util.PageParam;
+import com.yami.shop.common.util.R;
+import com.yami.shop.service.UserService;
+import io.swagger.annotations.ApiOperation;
+import lombok.SneakyThrows;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.security.access.prepost.PreAuthorize;
+import org.springframework.web.bind.annotation.*;
+import org.springframework.web.multipart.MultipartFile;
+
+import javax.servlet.http.HttpServletResponse;
+import java.util.Date;
+
+@RestController
+@RequestMapping("/admin/enterprise")
+public class UserEnterpriseController {
+
+    @Autowired
+    private UserService userService;
+
+
+    @GetMapping("/downloadXlsx")
+    @ApiOperation("下载导入企业员工模板(示例版)")
+    @SneakyThrows
+    public R<Void> downloadZip(HttpServletResponse response) {
+        response.sendRedirect("https://zswl-shop.oss-cn-chengdu.aliyuncs.com/2025/10/e24a324deb414ba4b46e1928b6d55483.xlsx");
+        return R.SUCCESS();
+    }
+
+    @GetMapping("/downloadExcel")
+    @ApiOperation("下载导入企业员工模板(无示例版)")
+    public R<Void> downloadExcelGoods(HttpServletResponse response) {
+        userService.downloadExcelGoods(response);
+        return R.SUCCESS();
+    }
+
+    @PostMapping("/uploadExcelGoods")
+    @ApiOperation("导入企业员工")
+    public R<Void> downloadExcelGoods(MultipartFile file) {
+        userService.uploadExcelGoods(file);
+        return R.SUCCESS();
+    }
+
+
+    @GetMapping("/enterpriseUserList")
+    @ApiOperation("员工列表")
+    public R<IPage<EnterpriseUserVo>> enterpriseUserList(EnterpriseUserPo po, PageParam<EnterpriseUserPo> page) {
+        IPage<EnterpriseUserVo> userPage =  userService.enterpriseUserList(page,po);
+        return R.SUCCESS(userPage);
+    }
+
+    @PostMapping("/addUser")
+    @ApiOperation("新增企业员工")
+    public R<Void> addUser(@RequestBody EnterpriseUserPo po) {
+        userService.addUser(po);
+        return R.SUCCESS();
+    }
+
+    @DeleteMapping("/deleteUserById")
+    @ApiOperation("删除员工")
+    public R<Void> deleteUserById(String userId) {
+        userService.removeById(userId);
+        return R.SUCCESS();
+    }
+
+    @GetMapping("/info/{userId}")
+    @PreAuthorize("@pms.hasPermission('plateform:user:info')")
+    public R<User> info(@PathVariable("userId") String userId) {
+        User user = userService.getById(userId);
+        user.setNickName(user.getNickName());
+        return R.SUCCESS(user);
+    }
+
+    @PutMapping
+    @PreAuthorize("@pms.hasPermission('plateform:user:update')")
+    public R<Void> update(@RequestBody User user) {
+        User updateUser = new User();
+        updateUser.setModifyTime(new Date());
+        updateUser.setRealName(user.getRealName());
+        updateUser.setUserName(user.getUserMobile());
+        updateUser.setUserMobile(user.getUserMobile());
+        updateUser.setChannelId(user.getChannelId());
+        updateUser.setPlatform(Integer.valueOf(user.getChannelId().toString()));
+        updateUser.setUserId(user.getUserId());
+        userService.updateById(updateUser);
+        return R.SUCCESS();
+    }
+}

+ 2 - 2
yami-shop-platform/src/main/resources/application.yml

@@ -1,8 +1,8 @@
 spring:
   # 环境 dev|prod|docker quartz定时任务
   profiles:
-#    active: dev
-    active: prod
+    active: dev
+#    active: prod
   #文件上传设置
   servlet:
     multipart:

+ 4 - 0
yami-shop-security/yami-shop-security-platform/src/main/java/com/yami/shop/security/platform/config/ResourceServerConfiguration.java

@@ -56,6 +56,10 @@ public class ResourceServerConfiguration extends ResourceServerConfigurerAdapter
                     "/doc.html",
                     "/swagger-ui.html",
                     "/swagger-resources/**",
+
+                    "/admin/enterprise/**",
+                    "/admin/file/upload/img",
+
                     "/captcha.jpg").permitAll()
             .and()
             .authorizeRequests()

+ 9 - 0
yami-shop-service/src/main/java/com/yami/shop/service/UserService.java

@@ -18,6 +18,9 @@ import com.yami.shop.bean.po.EnterpriseUserPo;
 import com.yami.shop.bean.vo.EnterpriseUserVo;
 import com.yami.shop.bean.vo.UserPointsVO;
 import com.yami.shop.common.util.PageParam;
+import org.springframework.web.multipart.MultipartFile;
+
+import javax.servlet.http.HttpServletResponse;
 
 /**
  *
@@ -44,4 +47,10 @@ public interface UserService extends IService<User> {
     IPage<UserPointsVO> statisticsList(PageParam<User> pageParam, User user);
 
     IPage<EnterpriseUserVo> enterpriseUserList(PageParam<EnterpriseUserPo> page, EnterpriseUserPo po);
+
+    void downloadExcelGoods(HttpServletResponse response);
+
+    void uploadExcelGoods(MultipartFile file);
+
+    void addUser(EnterpriseUserPo po);
 }

+ 87 - 5
yami-shop-service/src/main/java/com/yami/shop/service/impl/UserServiceImpl.java

@@ -10,23 +10,43 @@
 
 package com.yami.shop.service.impl;
 
+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.style.column.LongestMatchColumnWidthStyleStrategy;
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.baomidou.mybatisplus.core.metadata.IPage;
+import com.baomidou.mybatisplus.core.toolkit.Wrappers;
 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.User;
+import com.yami.shop.bean.po.EnterpriseUserExcelInfo;
 import com.yami.shop.bean.po.EnterpriseUserPo;
 import com.yami.shop.bean.vo.EnterpriseUserVo;
 import com.yami.shop.bean.vo.UserPointsVO;
 import com.yami.shop.common.exception.GlobalException;
+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.UserMapper;
 import com.yami.shop.service.UserExtensionService;
 import com.yami.shop.service.UserService;
+import com.yami.shop.utils.CullenUtils;
 import lombok.AllArgsConstructor;
+import lombok.SneakyThrows;
 import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
+import org.springframework.web.multipart.MultipartFile;
 
+import javax.servlet.http.HttpServletResponse;
+import java.io.IOException;
+import java.net.URLEncoder;
+import java.util.Date;
+import java.util.List;
 import java.util.Objects;
 
 /**
@@ -37,6 +57,7 @@ import java.util.Objects;
 public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements UserService {
 
     private final UserMapper userMapper;
+    private final ChannelMapper channelMapper;
     private final UserExtensionService userExtensionService;
 
 
@@ -53,13 +74,14 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements Us
 
     @Override
     public void setUserLevelByGrowth(Integer level, Integer minNeedGrowth, Integer maxNeedGrowth) {
-        userMapper.setMaxUserLevelBylevelId(level,minNeedGrowth ,maxNeedGrowth);
-        userExtensionService.setMaxUserLevelByLevelId(level,minNeedGrowth ,maxNeedGrowth);
+        userMapper.setMaxUserLevelBylevelId(level, minNeedGrowth, maxNeedGrowth);
+        userExtensionService.setMaxUserLevelByLevelId(level, minNeedGrowth, maxNeedGrowth);
     }
 
 
     /**
      * 看看有没有校验验证码成功的标识
+     *
      * @param userRegisterParam
      * @param checkRegisterSmsFlag
      */
@@ -77,16 +99,76 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements Us
 
     @Override
     public IPage<User> getUserPage(PageParam<User> page, User user) {
-        return  userMapper.getUserPage(page,user);
+        return userMapper.getUserPage(page, user);
     }
 
     @Override
     public IPage<UserPointsVO> statisticsList(PageParam<User> pageParam, User user) {
-        return userMapper.statisticsList(pageParam,user);
+        return userMapper.statisticsList(pageParam, user);
     }
 
     @Override
     public IPage<EnterpriseUserVo> enterpriseUserList(PageParam<EnterpriseUserPo> page, EnterpriseUserPo po) {
-        return  userMapper.enterpriseUserList(page,po);
+        return userMapper.enterpriseUserList(page, po);
+    }
+
+    @Override
+    public void downloadExcelGoods(HttpServletResponse response) {
+        try {
+            List<EnterpriseUserExcelInfo> list = Lists.newArrayList();
+            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())
+                    .sheet("列表").doWrite(list);
+        } catch (IOException e) {
+            throw new GlobalException("文件下载异常");
+        }
+    }
+
+    @Override
+    @SneakyThrows
+    @Transactional(rollbackFor = Exception.class)
+    public void uploadExcelGoods(MultipartFile file) {
+        List<EnterpriseUserExcelInfo> goodsInfoList = Lists.newArrayList();
+        EasyExcel.read(file.getInputStream(), EnterpriseUserExcelInfo.class, new PageReadListener<EnterpriseUserExcelInfo>(goodsInfoList::addAll)).sheet().doRead();
+        CullenUtils.validateDataThrowException(goodsInfoList.isEmpty(), "请上传企业用户信息...");
+        goodsInfoList.forEach(c -> {
+            CullenUtils.validateDataThrowException(c.getChannel().contains("必填"), "请删除示例后重试...");
+            addUser(new EnterpriseUserPo(getChannel(c.getChannel()), c.getRealName(), c.getPhone()));
+        });
+    }
+
+    @Override
+    public void addUser(EnterpriseUserPo po) {
+        if (userMapper.selectCount(Wrappers.<User>lambdaQuery().eq(User::getUserMobile, po.getPhone())) == 0) {
+            User user = new User();
+            user.setUserName(po.getPhone());
+            user.setNickName("企业用户");
+            user.setRealName(po.getRealName());
+            user.setUserMobile(po.getPhone());
+            user.setModifyTime(new Date());
+            user.setUserRegtime(new Date());
+            user.setUserRegip(IPHelper.getIpAddr());
+            user.setPic("https://thirdwx.qlogo.cn/mmopen/vi_32/POgEwh4mIHO4nibH0KlMECNjjGxQUq24ZEaGT4poC6icRiccVGKSyXwibcPq4BWmiaIGuG1icwxaQX6grC9VemZoJ8rg/132");
+            user.setStatus(1);
+            user.setLevel(1);
+            user.setLevelType(0);
+            user.setPlatform(0);
+            user.setChannelId(po.getChannelId());
+            user.setPlatform(Integer.valueOf(po.getChannelId().toString()));
+            user.setUserId(IdUtil.simpleUUID());
+            save(user);
+        }else {
+            System.out.println("已存在...");
+        }
+    }
+
+    private Long getChannel(String channel) {
+        List<Channel> channelList = channelMapper.selectList(new LambdaQueryWrapper<Channel>().like(Channel::getChannelName, channel));
+        CullenUtils.validateDataThrowException(channelList.isEmpty(), "没有该渠道,请检查后重试...");
+        CullenUtils.validateDataThrowException(channelList.size() > 1, "查询到多条渠道,请检查后重试...");
+        return channelList.get(0).getId();
     }
 }

+ 74 - 0
yami-shop-service/src/main/java/com/yami/shop/utils/CullenUtils.java

@@ -0,0 +1,74 @@
+package com.yami.shop.utils;
+
+import com.google.common.collect.Maps;
+import com.yami.shop.common.exception.GlobalException;
+
+import java.util.Map;
+
+/**
+ * @author Cullen
+ * @date 2015-12-12 00:00:00
+ */
+public class CullenUtils {
+
+    /**
+     * 校验参数是否满足表达式并抛出异常
+     *
+     * @param exp     表达式
+     * @param message 异常信息
+     */
+    public static void validateDataThrowException(Boolean exp, String message) {
+        if (exp) {
+            throw new GlobalException(message);
+        }
+    }
+
+
+    /**
+     * 校验参数是否满足表达式并抛出异常
+     *
+     * @param exp1    表达式
+     * @param exp2    表达式
+     * @param message 异常信息
+     */
+    public static void validateDataThrowException(Boolean exp1, Boolean exp2, String message) {
+        if (exp1) {
+            if (exp2) {
+                throw new GlobalException(message);
+            }
+        }
+    }
+
+    /**
+     * 例如:{auth=Kaur, enable=true, domain=www.hjx.org}
+     *
+     * @param input 文本
+     * @return map
+     */
+    public static Map<String, String> textToMap(String input) {
+        Map<String, String> map = Maps.newHashMap();
+        input = input.substring(1, input.length() - 1);
+        String[] keyValuePairs = input.split(", ");
+        for (String pair : keyValuePairs) {
+            String[] entry = pair.split("=");
+            String key = entry[0].trim();
+            String value = entry[1].trim();
+            if (value.startsWith("'") && value.endsWith("'")) {
+                value = value.substring(1, value.length() - 1);
+            }
+            map.put(key, value);
+        }
+        return map;
+    }
+
+    /**
+     * 判断是否是数字
+     *
+     * @param isNumeric isNumeric
+     * @return boolean
+     */
+    public static boolean isNumeric(String isNumeric) {
+        return isNumeric.matches("\\d+");
+    }
+
+}

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

@@ -104,17 +104,17 @@
 
 
     <select id="enterpriseUserList" resultType="com.yami.shop.bean.vo.EnterpriseUserVo">
-        SELECT a.user_id,a.`status`,b.channel_name,a.real_name,a.user_mobile,
-               IFNULL((SELECT SUM(points) FROM tz_points_recharge WHERE user_id=a.user_id),0) total,
-            IFNULL((SELECT SUM(points) FROM tz_points_recharge WHERE user_id=a.user_id and recharge_status=1),0) available,
-            IFNULL((SELECT SUM(points) FROM tz_points_recharge WHERE user_id=a.user_id and recharge_status=2),0) expired,
-            (SELECT(IFNULL((SELECT SUM(points) FROM tz_points_record WHERE user_id = a.user_id AND points_type = 2 AND points_audit IN (2,3)), 0)-
-                    IFNULL((SELECT SUM(points) FROM tz_points_record WHERE user_id = a.user_id  AND points_type = 3), 0))) used
+        SELECT a.user_id,a.`status`,a.real_name,a.user_mobile,
+        (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,
+        IFNULL((SELECT SUM(points) FROM tz_points_recharge WHERE user_id=a.user_id and recharge_status=1),0) available,
+        IFNULL((SELECT SUM(points) FROM tz_points_recharge WHERE user_id=a.user_id and recharge_status=2),0) expired,
+        (SELECT(IFNULL((SELECT SUM(points) FROM tz_points_record WHERE user_id = a.user_id AND points_type = 2 AND points_audit IN (2,3)), 0)-
+        IFNULL((SELECT SUM(points) FROM tz_points_record WHERE user_id = a.user_id  AND points_type = 3), 0))) used
         FROM tz_user a
-                 LEFT JOIN tz_channel b on a.channel_id=b.id
         <where>
             <if test="po.channelId != null">
-                AND a.channel_id=#{po.channelId}
+                AND a.channel_id = #{po.channelId}
             </if>
             <if test="po.realName != null and po.realName != ''">
                 AND a.real_name LIKE CONCAT("%",#{po.realName},"%")