wangming 1 Minggu lalu
induk
melakukan
28f515f380

+ 32 - 0
yami-shop-bean/src/main/java/com/yami/shop/bean/po/EnterpriseUserErrExcelInfo.java

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

+ 13 - 1
yami-shop-bean/src/main/java/com/yami/shop/bean/po/EnterpriseUserLogPo.java

@@ -15,6 +15,8 @@ public class EnterpriseUserLogPo {
 
     private String operator;
 
+    private String batchNo;
+
     private String taskName;
 
     @DateTimeFormat(pattern="yyyy-MM-dd HH:mm:ss")
@@ -23,6 +25,16 @@ public class EnterpriseUserLogPo {
     @DateTimeFormat(pattern="yyyy-MM-dd HH:mm:ss")
     private String completeTime;
 
-    private String result;
+    private Integer total;
+
+    private Integer success;
+
+    private Integer error;
+
+    private String channel;
+
+    private String realName;
+
+    private String phone;
 
 }

+ 4 - 6
yami-shop-platform/src/main/java/com/yami/shop/platform/config/SwaggerConfiguration.java

@@ -11,7 +11,6 @@
 package com.yami.shop.platform.config;
 
 import com.github.xiaoymin.knife4j.spring.annotations.EnableKnife4j;
-import com.google.common.collect.Lists;
 import org.springframework.context.annotation.Bean;
 import org.springframework.context.annotation.Configuration;
 import springfox.documentation.builders.ApiInfoBuilder;
@@ -21,13 +20,10 @@ import springfox.documentation.builders.RequestHandlerSelectors;
 import springfox.documentation.schema.ModelRef;
 import springfox.documentation.service.ApiInfo;
 import springfox.documentation.service.Contact;
+import springfox.documentation.service.Parameter;
 import springfox.documentation.spi.DocumentationType;
 import springfox.documentation.spring.web.plugins.Docket;
 import springfox.documentation.swagger2.annotations.EnableSwagger2;
-import springfox.documentation.service.*;
-import springfox.documentation.spi.service.contexts.SecurityContext;
-import static java.util.Collections.singletonList;
-import static org.springframework.boot.actuate.trace.http.Include.AUTHORIZATION_HEADER;
 
 import java.util.ArrayList;
 import java.util.List;
@@ -50,9 +46,11 @@ public class SwaggerConfiguration {
 		 ticketPar.name("authorization").description("authorization 拼接: bearer")//Token 以及Authorization 为自定义的参数,session保存的名字是哪个就可以写成那个
 				 .modelRef(new ModelRef("string")).parameterType("header")
 				 .required(false).build(); //header中的ticket参数非必填,传空也可以
+
 		 t.name("t").description("时间戳")//Token 以及Authorization 为自定义的参数,session保存的名字是哪个就可以写成那个
 				 .modelRef(new ModelRef("string")).parameterType("query")
-				 .required(true).build(); //header中的ticket参数非必填,传空也可以
+				 .required(false).build(); //header中的ticket参数非必填,传空也可以
+
 		 pars.add(ticketPar.build());
 		 pars.add(t.build());
 		 return new Docket(DocumentationType.SWAGGER_2)

+ 9 - 1
yami-shop-platform/src/main/java/com/yami/shop/platform/controller/UserEnterpriseController.java

@@ -25,11 +25,19 @@ public class UserEnterpriseController {
     @Autowired
     private UserService userService;
 
+    @GetMapping("/downloadErrorExcel")
+    @ApiOperation("导出失败记录")
+    public R<Void> downloadErrorExcel(HttpServletResponse response,String batchNo) {
+        userService.downloadErrorExcel(response,batchNo);
+        return R.SUCCESS();
+    }
+
+
     @SneakyThrows
     @GetMapping("/downloadXlsx")
     @ApiOperation("下载导入企业员工模板(示例版)")
     public R<Void> downloadZip(HttpServletResponse response) {
-        response.sendRedirect("https://zswl-shop.oss-cn-chengdu.aliyuncs.com/2025/10/e24a324deb414ba4b46e1928b6d55483.xlsx");
+        response.sendRedirect("https://zswl-shop.oss-cn-chengdu.aliyuncs.com/2025/10/da9bf7eb40ad4cd6ba2566c13b5ba8d4.xlsx");
         return R.SUCCESS();
     }
 

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

@@ -59,6 +59,9 @@ public class ResourceServerConfiguration extends ResourceServerConfigurerAdapter
 
 //                    "/admin/enterprise/**",
 //                    "/admin/file/upload/img",
+                    "/admin/enterprise/downloadXlsx",
+                    "/admin/enterprise/downloadExcel",
+                    "/admin/enterprise/downloadErrorExcel",
 
                     "/captcha.jpg").permitAll()
             .and()

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

@@ -41,10 +41,13 @@ 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("result") String result);
+    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);
 
     IPage<EnterpriseUserLogPo> enterpriseUserLogList(@Param("page") PageParam<EnterpriseUserLogPo> page);
 
     IPage<User> userList(@Param("page") PageParam<User> page, @Param("user") User user);
 
+    List<EnterpriseUserLogPo> enterpriseUserLogErrList(String batchNo);
+
 }

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

@@ -60,4 +60,6 @@ public interface UserService extends IService<User> {
     IPage<EnterpriseUserLogPo> enterpriseUserLogList(PageParam<EnterpriseUserLogPo> page);
 
     IPage<User> userList(PageParam<User> page, User user);
+
+    void downloadErrorExcel(HttpServletResponse response, String batchNo);
 }

+ 31 - 2
yami-shop-service/src/main/java/com/yami/shop/service/impl/UserServiceImpl.java

@@ -23,6 +23,7 @@ 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.EnterpriseUserErrExcelInfo;
 import com.yami.shop.bean.po.EnterpriseUserExcelInfo;
 import com.yami.shop.bean.po.EnterpriseUserLogPo;
 import com.yami.shop.bean.po.EnterpriseUserPo;
@@ -133,13 +134,22 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements Us
     @Transactional(rollbackFor = Exception.class)
     public void uploadExcelGoods(MultipartFile file,String username) {
         List<EnterpriseUserExcelInfo> goodsInfoList = Lists.newArrayList();
+        String batchNo = String.valueOf(System.currentTimeMillis());
         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()));
+            CullenUtils.validateDataThrowException(c.getPhone()==null,"手机号不能为空...");
+            CullenUtils.validateDataThrowException(c.getChannel()==null,"渠道不能为空...");
+            CullenUtils.validateDataThrowException(c.getRealName()==null,"姓名不能为空...");
+            String phone = c.getPhone().replaceAll("\\s+", "");
+            if (phone.length()!=11||!CullenUtils.isNumeric(phone)) {
+                userMapper.addUserLog(username,batchNo,"0",c.getChannel(),c.getRealName(),c.getPhone());
+            }else {
+                addUser(new EnterpriseUserPo(getChannel(c.getChannel()), c.getRealName(), c.getPhone()));
+                userMapper.addUserLog(username,batchNo,"1",c.getChannel(),c.getRealName(),c.getPhone());
+            }
         });
-        userMapper.addUserLog(username,String.format("共%d条,成功%d条,失败%d条",goodsInfoList.size(),goodsInfoList.size(),0));
     }
 
     @Override
@@ -201,6 +211,25 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements Us
         return userMapper.userList(page, user);
     }
 
+    @Override
+    public void downloadErrorExcel(HttpServletResponse response, String batchNo) {
+        try {
+            System.out.println(batchNo);
+            List<EnterpriseUserLogPo> userLogErrList = userMapper.enterpriseUserLogErrList(batchNo);
+            CullenUtils.validateDataThrowException(userLogErrList.isEmpty(),"该记录暂无错误日志...");
+            List<EnterpriseUserErrExcelInfo> list = Lists.newArrayList();
+            userLogErrList.forEach(c-> list.add(new EnterpriseUserErrExcelInfo("手机号格式错误",c.getChannel(),c.getRealName(),c.getPhone())));
+            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(), EnterpriseUserErrExcelInfo.class)
+                    .registerWriteHandler(new LongestMatchColumnWidthStyleStrategy())
+                    .sheet("列表").doWrite(list);
+        } catch (IOException e) {
+            throw new GlobalException("文件下载异常");
+        }
+    }
+
     private Long getChannel(String channel) {
         List<Channel> channelList = channelMapper.selectList(new LambdaQueryWrapper<Channel>().like(Channel::getChannelName, channel));
         CullenUtils.validateDataThrowException(channelList.isEmpty(), "没有该渠道,请检查后重试...");

+ 28 - 7
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.channel,a.real_name,a.phone,
         (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,
@@ -123,29 +123,50 @@
                 AND a.real_name LIKE CONCAT("%",#{po.realName},"%")
             </if>
             <if test="po.userMobile != null and po.userMobile != ''">
-                AND a.user_mobile LIKE CONCAT("%",#{phone},"%")
+                AND a.user_mobile LIKE CONCAT("%",#{po.userMobile},"%")
             </if>
         </where>
     </select>
 
     <insert id="addUserLog" parameterType="string">
-        insert into tz_user_add_log(operator, task_name, create_time, complete_time, result)
-        values (#{operator}, "员工导入", NOW(), NOW(), #{result})
+        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>
 
 
     <select id="enterpriseUserLogList" resultType="com.yami.shop.bean.po.EnterpriseUserLogPo">
-        SELECT * FROM `tz_user_add_log` ORDER BY complete_time desc
+        SELECT a.operator,
+               a.task_name,
+               a.batch_no,
+               MIN(a.create_time)   create_time,
+               MAX(a.complete_time) complete_time,
+               COUNT(1) 'total', IFNULL(
+                (SELECT COUNT(1) FROM tz_user_add_log WHERE `status` = 1 and batch_no = a.batch_no GROUP BY batch_no),
+                0) 'success', IFNULL(
+                (SELECT COUNT(1) FROM tz_user_add_log WHERE `status` = 0 and batch_no = a.batch_no GROUP BY batch_no),
+                0) 'error'
+        FROM tz_user_add_log a
+        GROUP BY a.batch_no
+        ORDER BY a.complete_time desc
     </select>
 
 
     <select id="userList" resultType="com.yami.shop.bean.model.User">
         select * from tz_user
         <where>
-            <if test="nickName != null and nickName != ''">
-                AND nick_name LIKE CONCAT("%",#{nickName},"%")
+            <if test="user.nickName != null and user.nickName != ''">
+                AND nick_name LIKE CONCAT("%",#{user.nickName},"%")
             </if>
         </where>
     </select>
 
+    <select id="enterpriseUserLogErrList" resultType="com.yami.shop.bean.po.EnterpriseUserLogPo">
+        SELECT *
+        FROM tz_user_add_log
+        WHERE batch_no = #{batchNo}
+          and `status` = 0
+        ORDER BY create_time
+    </select>
+
+
 </mapper>