diff --git a/hai-bweb/src/main/java/com/bweb/controller/HighCouponController.java b/hai-bweb/src/main/java/com/bweb/controller/HighCouponController.java index 2da77f62..c77cde84 100644 --- a/hai-bweb/src/main/java/com/bweb/controller/HighCouponController.java +++ b/hai-bweb/src/main/java/com/bweb/controller/HighCouponController.java @@ -364,11 +364,11 @@ public class HighCouponController { SessionObject sessionObject = userCenter.getSessionObject(request); UserInfoModel userInfoModel = (UserInfoModel) sessionObject.getObject(); - // 查找商户 + // 查找卡卷 HighCouponModel coupon = highCouponService.getCouponById(couponId); if (coupon == null) { - log.error("HighCouponController -> writeStock() error!","未找到商户"); - throw ErrorHelp.genException(SysCode.System, ErrorCode.MERCHANT_NOF_FOUND, ""); + log.error("HighCouponController -> writeStock() error!","未找到卡卷信息"); + throw ErrorHelp.genException(SysCode.System, ErrorCode.NOT_FOUND_COUPON, ""); } if (coupon.getCouponType() != 2) { log.error("HighCouponController -> writeStock() error!","卡卷类型错误"); diff --git a/hai-bweb/src/main/java/com/bweb/controller/HighMerchantStoreController.java b/hai-bweb/src/main/java/com/bweb/controller/HighMerchantStoreController.java index 1aeac46b..e1386933 100644 --- a/hai-bweb/src/main/java/com/bweb/controller/HighMerchantStoreController.java +++ b/hai-bweb/src/main/java/com/bweb/controller/HighMerchantStoreController.java @@ -1,6 +1,11 @@ package com.bweb.controller; +import com.alibaba.excel.EasyExcel; import com.alibaba.fastjson.JSON; +import com.bweb.excelListener.ImportCouponListener; +import com.bweb.excelListener.ImportStoreListener; +import com.bweb.model.ImportCouponModel; +import com.bweb.model.ImportStoreModel; import com.github.pagehelper.PageHelper; import com.github.pagehelper.PageInfo; import com.hai.common.exception.ErrorCode; @@ -13,9 +18,7 @@ import com.hai.common.utils.ResponseMsgUtil; import com.hai.entity.HighMerchant; import com.hai.entity.HighMerchantStore; import com.hai.entity.SecRegion; -import com.hai.model.HighMerchantStoreModel; -import com.hai.model.ResponseData; -import com.hai.model.UserInfoModel; +import com.hai.model.*; import com.hai.service.CommonService; import com.hai.service.HighMerchantService; import com.hai.service.HighMerchantStoreService; @@ -28,6 +31,7 @@ import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.*; +import org.springframework.web.multipart.MultipartFile; import javax.annotation.Resource; import javax.servlet.http.HttpServletRequest; @@ -90,16 +94,10 @@ public class HighMerchantStoreController { throw ErrorHelp.genException(SysCode.System, ErrorCode.REQ_PARAMS_ERROR, ""); } - // 校验账户手机号 - if (!MemberValidateUtil.validatePhone(highMerchantStore.getSecUser().getTelephone())) { - log.error("HighMerchantStoreController --> insertMerchantStore() error!", "请输入正确的电话号码"); - throw ErrorHelp.genException(SysCode.System, ErrorCode.PHONE_NUM_IS_ERROR, ""); - } - // 校验账号手机号是否存在 if (secUserService.findByPhone(highMerchantStore.getSecUser().getTelephone()) != null) { - log.error("HighMerchantStoreController --> insertMerchantStore() error!", "电话号码已被使用"); - throw ErrorHelp.genException(SysCode.System, ErrorCode.PHONE_NUM_EXISTED, ""); + log.error("HighMerchantStoreController --> insertMerchantStore() error!", "联系方式已被使用"); + throw ErrorHelp.genException(SysCode.System, ErrorCode.TEL_EXISTED, ""); } // 校验商户 @@ -126,7 +124,7 @@ public class HighMerchantStoreController { highMerchantStore.setMerchantId(merchant.getId()); highMerchantStore.setOperatorId(userInfoModel.getSecUser().getId()); highMerchantStore.setOperatorName(userInfoModel.getSecUser().getUserName()); - // highMerchantStoreService.insertMerchantStore(highMerchantStore); + highMerchantStoreService.insertMerchantStore(highMerchantStore); return ResponseMsgUtil.success(highMerchantStore); } catch (Exception e) { @@ -135,6 +133,43 @@ public class HighMerchantStoreController { } } + + @RequestMapping(value="/importMerchantStore",method = RequestMethod.POST) + @ResponseBody + @ApiOperation(value = "导入商户门店") + public ResponseData importMerchantStore( @RequestParam(value = "file" , required = true) MultipartFile files, + HttpServletRequest request) { + try { + //发布人员 + SessionObject sessionObject = userCenter.getSessionObject(request); + UserInfoModel userInfoModel = (UserInfoModel) sessionObject.getObject(); + if (userInfoModel.getMerchant() == null) { + log.error("HighMerchantController -> insertMerchantStore() error!","该主角色没有权限"); + throw ErrorHelp.genException(SysCode.System, ErrorCode.MENU_TREE_HAS_NOT_ERROR, ""); + } + + // 查找商户 + HighMerchantModel merchant = highMerchantService.getMerchantById(userInfoModel.getMerchant().getId()); + if(merchant == null) { + log.error("HighMerchantStoreController -> importMerchantStore() error!","未找到卡卷信息"); + throw ErrorHelp.genException(SysCode.System, ErrorCode.NOT_FOUND_COUPON, ""); + } + + ImportStoreListener importStoreListener = new ImportStoreListener(); + importStoreListener.initData(merchant,userInfoModel, highMerchantStoreService, commonService); + EasyExcel.read(files.getInputStream(), ImportStoreModel.class, importStoreListener).sheet().doRead(); + + Map map = new HashMap<>(); + map.put("errorData", importStoreListener.getErrorData()); + map.put("errorTotal", importStoreListener.getErrorData().size()); + + return ResponseMsgUtil.success(map); + } catch (Exception e) { + log.error("HighMerchantStoreController -> insertMerchantStore() error!",e); + return ResponseMsgUtil.exception(e); + } + } + @RequestMapping(value="/updateMerchantStore",method = RequestMethod.POST) @ResponseBody @ApiOperation(value = "修改商户门店") @@ -162,12 +197,6 @@ public class HighMerchantStoreController { throw ErrorHelp.genException(SysCode.System, ErrorCode.REQ_PARAMS_ERROR, ""); } - // 校验账户手机号 - if (!MemberValidateUtil.validatePhone(highMerchantStore.getSecUser().getTelephone())) { - log.error("BsStudentController --> addStudent() error!", "请输入正确的电话号码"); - throw ErrorHelp.genException(SysCode.System, ErrorCode.PHONE_NUM_IS_ERROR, ""); - } - // 查询门店 HighMerchantStoreModel store = highMerchantStoreService.getMerchantStoreById(highMerchantStore.getId()); if (store == null) { @@ -179,7 +208,7 @@ public class HighMerchantStoreController { if (!store.getSecUser().getTelephone().equals(highMerchantStore.getSecUser().getTelephone()) && secUserService.findByPhone(highMerchantStore.getSecUser().getTelephone()) != null) { log.error("BsStudentController --> addStudent() error!", "电话号码已被使用"); - throw ErrorHelp.genException(SysCode.System, ErrorCode.PHONE_NUM_EXISTED, ""); + throw ErrorHelp.genException(SysCode.System, ErrorCode.TEL_EXISTED, ""); } // 校验商户 diff --git a/hai-bweb/src/main/java/com/bweb/excelListener/ImportStoreListener.java b/hai-bweb/src/main/java/com/bweb/excelListener/ImportStoreListener.java new file mode 100644 index 00000000..036ceb36 --- /dev/null +++ b/hai-bweb/src/main/java/com/bweb/excelListener/ImportStoreListener.java @@ -0,0 +1,126 @@ +package com.bweb.excelListener; + +import com.alibaba.excel.context.AnalysisContext; +import com.alibaba.excel.event.AnalysisEventListener; +import com.bweb.model.ImportCouponModel; +import com.bweb.model.ImportStoreModel; +import com.hai.common.utils.DateUtil; +import com.hai.common.utils.MemberValidateUtil; +import com.hai.entity.*; +import com.hai.model.HighMerchantStoreModel; +import com.hai.model.UserInfoModel; +import com.hai.service.CommonService; +import com.hai.service.HighCouponCodeService; +import com.hai.service.HighMerchantStoreService; +import org.apache.commons.lang3.StringUtils; + +import java.util.*; +import java.util.stream.Collectors; + +/** + * @Auther: 胡锐 + * @Description: + * @Date: 2021/3/26 19:28 + */ +public class ImportStoreListener extends AnalysisEventListener { + + List errorData = new ArrayList<>(); + List successData = new ArrayList<>(); + List allStoreData = new ArrayList<>(); + + HighMerchantStoreModel highMerchantStore; + HighMerchant highMerchant; + UserInfoModel userInfoModel; + + private HighMerchantStoreService highMerchantStoreService; + private CommonService commonService; + + /** + * @Author 胡锐 + * @Description 解析到的每一条数据都会调用此方法 + * @Date 2021/3/20 21:08 + **/ + @Override + public void invoke(ImportStoreModel importStoreModel, AnalysisContext analysisContext) { + if (StringUtils.isBlank(importStoreModel.getStoreName()) + || StringUtils.isBlank(importStoreModel.getStoreKey()) + || StringUtils.isBlank(importStoreModel.getRegionId()) + || StringUtils.isBlank(importStoreModel.getAddress()) + || StringUtils.isBlank(importStoreModel.getLatitude()) + || StringUtils.isBlank(importStoreModel.getLongitude()) + ) { + importStoreModel.setErrorMessage("有必填项未填写"); + errorData.add(importStoreModel); + return; + } + + // 查询区域信息 + String regionName = this.commonService.getRegionName(Long.parseLong(importStoreModel.getRegionId())); + if (StringUtils.isBlank(regionName)) { + importStoreModel.setErrorMessage("【"+importStoreModel.getRegionId()+"】,未知的区域id"); + errorData.add(importStoreModel); + return; + } + + // 根据门店编码进行校验 + List collect = allStoreData.stream().filter(o -> o.getStoreKey().equals(importStoreModel.getStoreKey())).collect(Collectors.toList()); + if (collect != null && collect.size() > 0) { + importStoreModel.setErrorMessage("门店编号已存在"); + errorData.add(importStoreModel); + return; + } + + highMerchantStore = new HighMerchantStoreModel(); + highMerchantStore.setStoreName(importStoreModel.getStoreName()); + highMerchantStore.setStoreKey(importStoreModel.getStoreKey()); + highMerchantStore.setAddress(importStoreModel.getAddress()); + highMerchantStore.setLatitude(importStoreModel.getLatitude()); + highMerchantStore.setLongitude(importStoreModel.getLongitude()); + highMerchantStore.setRegionId(Long.parseLong(importStoreModel.getRegionId())); + + highMerchantStore.setRegionName(regionName); + highMerchantStore.setCompanyId(highMerchant.getCompanyId()); + highMerchantStore.setMerchantId(highMerchant.getId()); + highMerchantStore.setOperatorId(userInfoModel.getSecUser().getId()); + highMerchantStore.setOperatorName(userInfoModel.getSecUser().getUserName()); + highMerchantStore.setStatus(1); + highMerchantStore.setCreateTime(new Date()); + highMerchantStore.setUpdateTime(new Date()); + + successData.add(highMerchantStore); + allStoreData.add(highMerchantStore); + + + } + + /** + * @Author 胡锐 + * @Description 所有数据解析完成了 都会来调用此方法 + * @Date 2021/3/20 21:08 + **/ + @Override + public void doAfterAllAnalysed(AnalysisContext analysisContext) { + if (successData.size() > 0) { + try { + highMerchantStoreService.insertMerchantStoreList(successData); + } catch (Exception e) { + e.printStackTrace(); + } + } + this.successData.clear(); + this.allStoreData.clear(); + } + + public List getErrorData() { + return errorData; + } + + public void initData(HighMerchant highMerchant, UserInfoModel userInfoModel, HighMerchantStoreService highMerchantStoreService, CommonService commonService){ + this.highMerchant = highMerchant; + this.userInfoModel = userInfoModel; + this.highMerchantStoreService = highMerchantStoreService; + this.commonService = commonService; + this.allStoreData = this.highMerchantStoreService.getMerchantStoreList(new HashMap<>()); + } + +} diff --git a/hai-bweb/src/main/java/com/bweb/model/ImportStoreModel.java b/hai-bweb/src/main/java/com/bweb/model/ImportStoreModel.java new file mode 100644 index 00000000..bb18791f --- /dev/null +++ b/hai-bweb/src/main/java/com/bweb/model/ImportStoreModel.java @@ -0,0 +1,89 @@ +package com.bweb.model; + +import com.alibaba.excel.annotation.ExcelProperty; +import com.alibaba.excel.annotation.format.DateTimeFormat; + +/** + * @Author 胡锐 + * @Description 导入门店 + * @Date 2021/3/26 19:23 + **/ +public class ImportStoreModel { + + @ExcelProperty("门店名称") + private String storeName; + + @ExcelProperty("门店编号") + private String storeKey; + + @ExcelProperty("区域Id") + private String regionId; + + @ExcelProperty("地址") + private String address; + + @ExcelProperty("经度") + private String longitude; + + @ExcelProperty("纬度") + private String latitude; + + // 错误消息 + private String errorMessage; + + public String getStoreName() { + return storeName; + } + + public void setStoreName(String storeName) { + this.storeName = storeName; + } + + public String getStoreKey() { + return storeKey; + } + + public void setStoreKey(String storeKey) { + this.storeKey = storeKey; + } + + public String getRegionId() { + return regionId; + } + + public void setRegionId(String regionId) { + this.regionId = regionId; + } + + public String getAddress() { + return address; + } + + public void setAddress(String address) { + this.address = address; + } + + public String getLongitude() { + return longitude; + } + + public void setLongitude(String longitude) { + this.longitude = longitude; + } + + public String getLatitude() { + return latitude; + } + + public void setLatitude(String latitude) { + this.latitude = latitude; + } + + public String getErrorMessage() { + return errorMessage; + } + + public void setErrorMessage(String errorMessage) { + this.errorMessage = errorMessage; + } +} diff --git a/hai-service/src/main/java/com/hai/common/exception/ErrorCode.java b/hai-service/src/main/java/com/hai/common/exception/ErrorCode.java index ca20027f..8a33512f 100644 --- a/hai-service/src/main/java/com/hai/common/exception/ErrorCode.java +++ b/hai-service/src/main/java/com/hai/common/exception/ErrorCode.java @@ -95,6 +95,7 @@ public enum ErrorCode { NEED_WRITE_NEW_SALE_PRICE("2123","请填写正确的新销售价格"), NEED_WRITE_DISCOUNT_PRICE("2124","请填写正确的折扣数,折扣数范围【0】 ~ 【10】"), DISCOUNT_PRICE_RANGE("2125","请输入正确的"), + TEL_EXISTED("2126","联系方式已被使用"), STATUS_ERROR("3000","状态错误"), ADD_DATA_ERROR("3001","增加数据失败"), diff --git a/hai-service/src/main/java/com/hai/dao/SecUserMapperExt.java b/hai-service/src/main/java/com/hai/dao/SecUserMapperExt.java index b50a44c2..f97ffcd8 100644 --- a/hai-service/src/main/java/com/hai/dao/SecUserMapperExt.java +++ b/hai-service/src/main/java/com/hai/dao/SecUserMapperExt.java @@ -1,5 +1,6 @@ package com.hai.dao; +import com.hai.entity.SecUser; import com.hai.model.SecUserModel; import org.apache.ibatis.annotations.Param; import org.apache.ibatis.annotations.Result; @@ -53,4 +54,38 @@ public interface SecUserMapperExt { }) List findPage(@Param("companyId") Long companyId, @Param("organizationId") Long organizationId, @Param("userName") String userName, @Param("phone") String phone); + @Select({ + "" + }) + @Results({ + @Result(column="id", property="id", jdbcType= JdbcType.BIGINT, id=true), + @Result(column="avatar", property="avatar", jdbcType=JdbcType.VARCHAR), + @Result(column="user_name", property="userName", jdbcType=JdbcType.VARCHAR), + @Result(column="login_name", property="loginName", jdbcType=JdbcType.VARCHAR), + @Result(column="password", property="password", jdbcType=JdbcType.VARCHAR), + @Result(column="telephone", property="telephone", jdbcType=JdbcType.VARCHAR), + @Result(column="admin_flag", property="adminFlag", jdbcType=JdbcType.INTEGER), + @Result(column="company_id", property="companyId", jdbcType=JdbcType.BIGINT), + @Result(column="organization_id", property="organizationId", jdbcType=JdbcType.BIGINT), + @Result(column="object_type", property="objectType", jdbcType=JdbcType.INTEGER), + @Result(column="object_id", property="objectId", jdbcType=JdbcType.BIGINT), + @Result(column="status", property="status", jdbcType=JdbcType.INTEGER), + @Result(column="create_time", property="createTime", jdbcType=JdbcType.TIMESTAMP), + @Result(column="update_time", property="updateTime", jdbcType=JdbcType.TIMESTAMP), + @Result(column="organization_name", property="organizationName", jdbcType=JdbcType.VARCHAR), + @Result(column="ext_1", property="ext1", jdbcType=JdbcType.VARCHAR), + @Result(column="ext_2", property="ext2", jdbcType=JdbcType.VARCHAR), + @Result(column="ext_3", property="ext3", jdbcType=JdbcType.VARCHAR) + }) + SecUser login(@Param("loginName") String loginName,@Param("password") String password); } diff --git a/hai-service/src/main/java/com/hai/service/HighMerchantStoreService.java b/hai-service/src/main/java/com/hai/service/HighMerchantStoreService.java index 444fc9b7..5d542d25 100644 --- a/hai-service/src/main/java/com/hai/service/HighMerchantStoreService.java +++ b/hai-service/src/main/java/com/hai/service/HighMerchantStoreService.java @@ -20,6 +20,13 @@ public interface HighMerchantStoreService { **/ void insertMerchantStore(HighMerchantStoreModel highMerchantStore) throws Exception; + /** + * @Author 胡锐 + * @Description 批量增加门店 + * @Date 2021/3/26 20:20 + **/ + void insertMerchantStoreList(List highMerchantStoreList) throws Exception; + /** * @Author 胡锐 * @Description 修改门店 diff --git a/hai-service/src/main/java/com/hai/service/impl/HighMerchantStoreServiceImpl.java b/hai-service/src/main/java/com/hai/service/impl/HighMerchantStoreServiceImpl.java index 6a02ff6c..fcfca6ed 100644 --- a/hai-service/src/main/java/com/hai/service/impl/HighMerchantStoreServiceImpl.java +++ b/hai-service/src/main/java/com/hai/service/impl/HighMerchantStoreServiceImpl.java @@ -16,6 +16,7 @@ import org.apache.commons.collections4.MapUtils; import org.apache.commons.lang3.StringUtils; import org.springframework.beans.BeanUtils; import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Propagation; import org.springframework.transaction.annotation.Transactional; import javax.annotation.Resource; @@ -33,13 +34,21 @@ public class HighMerchantStoreServiceImpl implements HighMerchantStoreService { private SecUserService secUserService; @Override - @Transactional + @Transactional(propagation= Propagation.REQUIRES_NEW) public void insertMerchantStore(HighMerchantStoreModel highMerchantStore) throws Exception { highMerchantStoreMapper.insert(highMerchantStore); + if (highMerchantStore.getSecUser() == null) { + highMerchantStore.setSecUser(new SecUser()); + } highMerchantStore.getSecUser().setUserName(highMerchantStore.getStoreName()); - highMerchantStore.getSecUser().setLoginName(highMerchantStore.getSecUser().getTelephone()); - highMerchantStore.getSecUser().setPassword(MD5Util.encode(highMerchantStore.getSecUser().getPassword().getBytes())); + if (StringUtils.isNotBlank(highMerchantStore.getSecUser().getTelephone())) { + highMerchantStore.getSecUser().setLoginName(highMerchantStore.getSecUser().getTelephone()); + highMerchantStore.getSecUser().setPassword(MD5Util.encode(highMerchantStore.getSecUser().getPassword().getBytes())); + } else { + highMerchantStore.getSecUser().setLoginName(highMerchantStore.getStoreKey()); + highMerchantStore.getSecUser().setPassword(MD5Util.encode("123456".getBytes())); + } highMerchantStore.getSecUser().setAdminFlag(1); highMerchantStore.getSecUser().setStatus(1); highMerchantStore.getSecUser().setRoleId(4L); @@ -50,6 +59,14 @@ public class HighMerchantStoreServiceImpl implements HighMerchantStoreService { secUserService.addUser(highMerchantStore.getSecUser()); } + @Override + @Transactional(propagation= Propagation.REQUIRES_NEW) + public void insertMerchantStoreList(List highMerchantStoreList) throws Exception { + for (HighMerchantStoreModel highMerchantStore : highMerchantStoreList) { + insertMerchantStore(highMerchantStore); + } + } + @Override @Transactional public void updateMerchantStore(HighMerchantStoreModel highMerchantStore) throws Exception { diff --git a/hai-service/src/main/java/com/hai/service/impl/SecUserServiceImpl.java b/hai-service/src/main/java/com/hai/service/impl/SecUserServiceImpl.java index 0c732993..7fa343c9 100644 --- a/hai-service/src/main/java/com/hai/service/impl/SecUserServiceImpl.java +++ b/hai-service/src/main/java/com/hai/service/impl/SecUserServiceImpl.java @@ -4,6 +4,7 @@ import com.github.pagehelper.PageHelper; import com.github.pagehelper.PageInfo; import com.hai.dao.BsOrganizationMapper; import com.hai.dao.SecUserMapper; +import com.hai.dao.SecUserMapperExt; import com.hai.dao.SecUserRoleRelMapper; import com.hai.entity.*; import com.hai.model.SecUserModel; @@ -23,6 +24,9 @@ public class SecUserServiceImpl implements SecUserService { @Resource private SecUserMapper secUserMapper; + @Resource + private SecUserMapperExt secUserMapperExt; + @Resource private BsOrganizationMapper bsOrganizationMapper; @@ -74,13 +78,7 @@ public class SecUserServiceImpl implements SecUserService { @Override public SecUser userLogin(String loginName, String password) { - SecUserExample example = new SecUserExample(); - example.createCriteria().andLoginNameEqualTo(loginName).andPasswordEqualTo(password).andStatusEqualTo(1); - List users = secUserMapper.selectByExample(example); - if (users != null && users.size() != 0) { - return users.get(0); - } - return null; + return secUserMapperExt.login(loginName,password); } @Override