|
@@ -24,6 +24,7 @@ import cn.hutool.core.date.DateTime;
|
|
|
import cn.hutool.core.date.DateUtil;
|
|
|
import cn.hutool.core.img.ImgUtil;
|
|
|
import cn.hutool.core.io.FileUtil;
|
|
|
+import cn.hutool.core.io.IoUtil;
|
|
|
import cn.hutool.core.lang.tree.Tree;
|
|
|
import cn.hutool.core.lang.tree.TreeNode;
|
|
|
import cn.hutool.core.lang.tree.TreeUtil;
|
|
@@ -31,6 +32,7 @@ import cn.hutool.core.util.ObjectUtil;
|
|
|
import cn.hutool.core.util.PhoneUtil;
|
|
|
import cn.hutool.core.util.RandomUtil;
|
|
|
import cn.hutool.core.util.StrUtil;
|
|
|
+import cn.hutool.json.JSONArray;
|
|
|
import cn.hutool.json.JSONObject;
|
|
|
import cn.hutool.json.JSONUtil;
|
|
|
import com.alibaba.excel.EasyExcel;
|
|
@@ -48,6 +50,7 @@ import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
import com.fhs.trans.service.impl.TransService;
|
|
|
+import com.google.common.collect.Maps;
|
|
|
import jakarta.annotation.Resource;
|
|
|
import jakarta.servlet.http.HttpServletResponse;
|
|
|
import org.apache.commons.compress.utils.Lists;
|
|
@@ -56,13 +59,21 @@ import org.apache.poi.ss.usermodel.*;
|
|
|
import org.apache.poi.xwpf.usermodel.XWPFDocument;
|
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
+import org.springframework.transaction.annotation.Propagation;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
+import org.springframework.transaction.interceptor.TransactionAspectSupport;
|
|
|
+import org.springframework.web.multipart.MultipartFile;
|
|
|
import vip.xiaonuo.auth.core.util.StpLoginUserUtil;
|
|
|
import vip.xiaonuo.biz.core.enums.BizBuildInEnum;
|
|
|
import vip.xiaonuo.biz.core.enums.BizDataTypeEnum;
|
|
|
import vip.xiaonuo.biz.modular.consumptionrecord.entity.ConsumptionRecord;
|
|
|
import vip.xiaonuo.biz.modular.consumptionrecord.service.ConsumptionRecordService;
|
|
|
import vip.xiaonuo.biz.modular.consumptionrecord.service.impl.ConsumptionRecordServiceImpl;
|
|
|
+import vip.xiaonuo.biz.modular.couponrecord.entity.BizCouponRecord;
|
|
|
+import vip.xiaonuo.biz.modular.couponrecord.param.BizCouponRecordPageParam;
|
|
|
+import vip.xiaonuo.biz.modular.couponrecord.service.BizCouponRecordService;
|
|
|
+import vip.xiaonuo.biz.modular.disablerecord.entity.BizDisableRecord;
|
|
|
+import vip.xiaonuo.biz.modular.disablerecord.service.BizDisableRecordService;
|
|
|
import vip.xiaonuo.biz.modular.org.entity.BizOrg;
|
|
|
import vip.xiaonuo.biz.modular.org.service.BizOrgService;
|
|
|
import vip.xiaonuo.biz.modular.position.entity.BizPosition;
|
|
@@ -92,10 +103,8 @@ import vip.xiaonuo.dev.api.DevSmsApi;
|
|
|
import vip.xiaonuo.sys.api.SysRoleApi;
|
|
|
import vip.xiaonuo.sys.api.SysUserApi;
|
|
|
|
|
|
-import java.io.BufferedOutputStream;
|
|
|
-import java.io.File;
|
|
|
-import java.io.IOException;
|
|
|
-import java.io.InputStream;
|
|
|
+import java.io.*;
|
|
|
+import java.math.BigDecimal;
|
|
|
import java.util.Comparator;
|
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
@@ -141,6 +150,10 @@ public class BizUserServiceImpl extends ServiceImpl<BizUserMapper, BizUser> impl
|
|
|
private BizRecommendRecordMapper bizRecommendRecordMapper;
|
|
|
@Resource
|
|
|
private ConsumptionRecordService consumptionRecordService;
|
|
|
+ @Resource
|
|
|
+ private BizDisableRecordService bizDisableRecordService;
|
|
|
+ @Resource
|
|
|
+ private BizCouponRecordService bizCouponRecordService;
|
|
|
|
|
|
|
|
|
@Override
|
|
@@ -236,12 +249,19 @@ public class BizUserServiceImpl extends ServiceImpl<BizUserMapper, BizUser> impl
|
|
|
bizUser.setPassword(CommonCryptogramUtil.doHashValue(devConfigApi.getValueByKey(SNOWY_SYS_DEFAULT_PASSWORD_KEY)));
|
|
|
// 设置状态
|
|
|
bizUser.setUserStatus(BizUserStatusEnum.ENABLE.getValue());
|
|
|
+ bizUser.setUserReferralCode(DateUtil.format(DateUtil.date(), DatePattern.PURE_DATETIME_PATTERN) + RandomUtil.randomNumbers(4));
|
|
|
this.save(bizUser);
|
|
|
|
|
|
// 发布增加事件
|
|
|
CommonDataChangeEventCenter.doAddWithData(BizDataTypeEnum.USER.getValue(), JSONUtil.createArray().put(bizUser));
|
|
|
}
|
|
|
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
+ @Override
|
|
|
+ public void addUser(BizUserAddParam bizUserAddParam) {
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
private void checkParam(BizUserAddParam bizUserAddParam) {
|
|
|
// 校验数据范围
|
|
|
List<String> loginUserDataScope = StpLoginUserUtil.getLoginUserDataScope();
|
|
@@ -407,6 +427,49 @@ public class BizUserServiceImpl extends ServiceImpl<BizUserMapper, BizUser> impl
|
|
|
bizUserIdParam.getId()).set(BizUser::getUserStatus, BizUserStatusEnum.DISABLED.getValue()));
|
|
|
}
|
|
|
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
+ @Override
|
|
|
+ public void disableCustomer(BizUserIdParam bizUserIdParam) {
|
|
|
+ BizUser bizUser = this.detail(bizUserIdParam);
|
|
|
+ BigDecimal accountBalance = bizUser.getAccountBalance();
|
|
|
+ BigDecimal voucherBalance = bizUser.getVoucherBalance();
|
|
|
+ // 校验数据范围
|
|
|
+ List<String> loginUserDataScope = StpLoginUserUtil.getLoginUserDataScope();
|
|
|
+ if (ObjectUtil.isNotEmpty(loginUserDataScope)) {
|
|
|
+ if (!loginUserDataScope.contains(bizUser.getOrgId())) {
|
|
|
+ throw new CommonException("您没有权限禁用该机构下的人员:{},机构id:{}", bizUser.getName(), bizUser.getOrgId());
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ if (!bizUser.getId().equals(StpUtil.getLoginIdAsString())) {
|
|
|
+ throw new CommonException("您没有权限禁用该机构下的人员:{},机构id:{}", bizUser.getName(), bizUser.getOrgId());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //账户余额和代金券金额清0
|
|
|
+ this.update(new LambdaUpdateWrapper<BizUser>().eq(BizUser::getId,
|
|
|
+ bizUserIdParam.getId()).set(BizUser::getUserStatus, BizUserStatusEnum.DISABLED.getValue())
|
|
|
+ .set(BizUser::getAccountBalance,new BigDecimal(0)).set(BizUser::getVoucherBalance,new BigDecimal(0)));
|
|
|
+
|
|
|
+ BizDisableRecord bizDisableRecord = new BizDisableRecord();
|
|
|
+ bizDisableRecord.setUserId(bizUser.getId());
|
|
|
+ bizDisableRecord.setAccountBalance(accountBalance);
|
|
|
+ bizDisableRecord.setVoucherBalance(voucherBalance);
|
|
|
+ BizCouponRecordPageParam bizCouponRecordPageParam = new BizCouponRecordPageParam();
|
|
|
+ bizCouponRecordPageParam.setUserId(bizUser.getId());
|
|
|
+ StringBuffer buffer = new StringBuffer();
|
|
|
+ List<BizCouponRecord> couponNoList = bizCouponRecordService.getList(bizCouponRecordPageParam);
|
|
|
+ //所有未核销的蛋糕券都核销掉
|
|
|
+ for(BizCouponRecord bizCouponRecord : couponNoList){
|
|
|
+ bizCouponRecord.setCouponStatus("1");
|
|
|
+ bizCouponRecord.setDestroyStatus(1);
|
|
|
+ buffer.append(bizCouponRecord.getCouponNo()+",");
|
|
|
+ bizCouponRecordService.updateById(bizCouponRecord);
|
|
|
+ }
|
|
|
+ if(ObjectUtil.isNotEmpty(buffer)){
|
|
|
+ bizDisableRecord.setCouponCode(buffer.substring(0,buffer.length()-1));
|
|
|
+ }
|
|
|
+ bizDisableRecordService.save(bizDisableRecord);
|
|
|
+ }
|
|
|
+
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
@Override
|
|
|
public void enableUser(BizUserIdParam bizUserIdParam) {
|
|
@@ -937,4 +1000,134 @@ public class BizUserServiceImpl extends ServiceImpl<BizUserMapper, BizUser> impl
|
|
|
//保存5分钟
|
|
|
commonCacheOperator.put(smsSendParam.getPhone(), code, 300);
|
|
|
}
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void downloadImportTemplate(HttpServletResponse response) throws IOException {
|
|
|
+ try {
|
|
|
+ InputStream inputStream = POICacheManager.getFile("user.xlsx");
|
|
|
+ byte[] bytes = IoUtil.readBytes(inputStream);
|
|
|
+ CommonDownloadUtil.download("会员信息导入模板.xlsx", bytes, response);
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error(">>> 下载会员信息导入模板失败:", e);
|
|
|
+ CommonResponseUtil.renderError(response, "下载会员信息导入模板失败");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
+ @Override
|
|
|
+ public JSONObject importItem(MultipartFile file) {
|
|
|
+ try {
|
|
|
+ int successCount = 0;
|
|
|
+ int errorCount = 0;
|
|
|
+ JSONArray errorDetail = JSONUtil.createArray();
|
|
|
+ String fileName = file.getOriginalFilename();
|
|
|
+ // 创建临时文件
|
|
|
+ File tempFile = null;
|
|
|
+ if (fileName.endsWith(".xlsx")) {
|
|
|
+ tempFile = FileUtil.writeBytes(file.getBytes(), FileUtil.file(FileUtil.getTmpDir() + FileUtil.FILE_SEPARATOR + "user.xlsx"));
|
|
|
+ } else if (fileName.endsWith(".xls")) {
|
|
|
+ tempFile = FileUtil.writeBytes(file.getBytes(), FileUtil.file(FileUtil.getTmpDir() + FileUtil.FILE_SEPARATOR + "user.xlsx"));
|
|
|
+ } else {
|
|
|
+ throw new CommonException("导入文件格式不正确!");
|
|
|
+ }
|
|
|
+ // 读取excel
|
|
|
+ Integer excelRow = this.getExcelRow(tempFile);
|
|
|
+ List<BizUserImport> itemImportParamList = EasyExcel.read(tempFile).head(BizUserImport.class).sheet()
|
|
|
+ .headRowNumber(excelRow).doReadSync();
|
|
|
+ for (int i = 0; i < itemImportParamList.size(); i++) {
|
|
|
+ JSONObject jsonObject = this.doImport(itemImportParamList.get(i), i);
|
|
|
+ if (jsonObject.getBool("success")) {
|
|
|
+ successCount += 1;
|
|
|
+ } else {
|
|
|
+ errorCount += 1;
|
|
|
+ errorDetail.add(jsonObject);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return JSONUtil.createObj()
|
|
|
+ .set("totalCount", itemImportParamList.size())
|
|
|
+ .set("successCount", successCount).set("errorCount", errorCount).set("errorDetail", errorDetail);
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error(">>> 物资需求单导入失败:", e);
|
|
|
+ throw new CommonException("物资需求单导入失败");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ //表头校验,获取读取的数据行数
|
|
|
+ private Integer getExcelRow(File file) {
|
|
|
+ FileInputStream input = null;
|
|
|
+
|
|
|
+ try {
|
|
|
+ input = new FileInputStream(file);
|
|
|
+ Workbook workbook = WorkbookFactory.create(input);
|
|
|
+ Sheet sheet = workbook.getSheetAt(0);
|
|
|
+
|
|
|
+ String headName = sheet.getRow(0).getCell(0).getStringCellValue();
|
|
|
+ //关闭流
|
|
|
+ input.close();
|
|
|
+ if ("日期".equals(headName)) {
|
|
|
+ return 1;
|
|
|
+ }
|
|
|
+ } catch (IOException e) {
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ return 2;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Transactional(rollbackFor = Exception.class, propagation = Propagation.REQUIRES_NEW)
|
|
|
+ public JSONObject doImport(BizUserImport bizUserImport, int i) {
|
|
|
+ //姓名
|
|
|
+ String name = bizUserImport.getName();
|
|
|
+ //手机号码
|
|
|
+ String phone = bizUserImport.getPhone();
|
|
|
+ //糕点
|
|
|
+ String accountBalance = bizUserImport.getAccountBalance();
|
|
|
+ //积分
|
|
|
+ String voucherBalance = bizUserImport.getVoucherBalance();
|
|
|
+ if (ObjectUtil.hasEmpty(name,phone)) {
|
|
|
+ return JSONUtil.createObj().set("index", i + 1).set("success", false).set("msg", "必填字段存在空值");
|
|
|
+ }else{
|
|
|
+ try {
|
|
|
+ if (!PhoneUtil.isMobile(phone)) {
|
|
|
+ return JSONUtil.createObj().set("index", i + 1).set("success", false).set("msg", "手机号码:"+phone+"格式错误");
|
|
|
+ }
|
|
|
+ if (this.count(new LambdaQueryWrapper<BizUser>()
|
|
|
+ .eq(BizUser::getPhone, CommonCryptogramUtil.doSm4CbcEncrypt(phone))) > 0) {
|
|
|
+ return JSONUtil.createObj().set("index", i + 1).set("success", false).set("msg", "存在重复的手机号,手机号为:"+phone);
|
|
|
+ }
|
|
|
+ if(!isNonNegativeInteger(accountBalance)){
|
|
|
+ return JSONUtil.createObj().set("index", i + 1).set("success", false).set("msg", "糕点填写大于等于0的数字");
|
|
|
+ }
|
|
|
+ if(!isNonNegativeInteger(voucherBalance)){
|
|
|
+ return JSONUtil.createObj().set("index", i + 1).set("success", false).set("msg", "积分填写大于等于0的数字");
|
|
|
+ }
|
|
|
+
|
|
|
+ BizUser bizUser = new BizUser();
|
|
|
+ BeanUtil.copyProperties(bizUserImport, bizUser);
|
|
|
+ bizUser.setAccount(phone);
|
|
|
+ bizUser.setOrgId("1543842934270394368");
|
|
|
+ bizUser.setUserType(3);
|
|
|
+ bizUser.setAccountBalance(new BigDecimal(accountBalance));
|
|
|
+ bizUser.setVoucherBalance(new BigDecimal(voucherBalance));
|
|
|
+ // 设置默认头像
|
|
|
+ bizUser.setAvatar(CommonAvatarUtil.generateImg(bizUser.getName()));
|
|
|
+ // 设置密码
|
|
|
+ bizUser.setPassword(CommonCryptogramUtil.doHashValue(devConfigApi.getValueByKey(SNOWY_SYS_DEFAULT_PASSWORD_KEY)));
|
|
|
+ // 设置状态
|
|
|
+ bizUser.setUserStatus(BizUserStatusEnum.ENABLE.getValue());
|
|
|
+ bizUser.setUserReferralCode(DateUtil.format(DateUtil.date(), DatePattern.PURE_DATETIME_PATTERN) + RandomUtil.randomNumbers(4));
|
|
|
+ this.save(bizUser);
|
|
|
+ // 返回成功
|
|
|
+ return JSONUtil.createObj().set("success", true);
|
|
|
+ } catch (Exception e) {
|
|
|
+ TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
|
|
|
+ log.error(">>> 数据导入异常:", e);
|
|
|
+ return JSONUtil.createObj().set("success", false).set("index", i + 1).set("msg", "数据导入异常:" + e);
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+ public static boolean isNonNegativeInteger(String str) {
|
|
|
+ return str != null && str.matches("^\\d*\\.?\\d+$");
|
|
|
+ }
|
|
|
}
|