'提交代码'

dev-discount
199901012 4 years ago
parent 5834b713bb
commit ecc1c80682
  1. 149
      hai-bweb/src/main/java/com/bweb/controller/HighMerchantStoreController.java
  2. 13
      hai-service/src/main/java/com/hai/service/HighMerchantStoreService.java
  3. 12
      hai-service/src/main/java/com/hai/service/impl/HighMerchantServiceImpl.java
  4. 63
      hai-service/src/main/java/com/hai/service/impl/HighMerchantStoreServiceImpl.java

@ -56,63 +56,124 @@ public class HighMerchantStoreController {
@Resource @Resource
private SecUserService secUserService; private SecUserService secUserService;
@RequestMapping(value="/editHighMerchantStore",method = RequestMethod.POST) @RequestMapping(value="/insertMerchantStore",method = RequestMethod.POST)
@ResponseBody @ResponseBody
@ApiOperation(value = "编辑商户门店") @ApiOperation(value = "增加商户门店")
public ResponseData editMerchantStore(@RequestBody HighMerchantStoreModel highMerchantStore, HttpServletRequest request) { public ResponseData insertMerchantStore(@RequestBody HighMerchantStoreModel highMerchantStore, HttpServletRequest request) {
try { try {
//发布人员 //发布人员
SessionObject sessionObject = userCenter.getSessionObject(request); SessionObject sessionObject = userCenter.getSessionObject(request);
UserInfoModel userInfoModel = (UserInfoModel) sessionObject.getObject(); UserInfoModel userInfoModel = (UserInfoModel) sessionObject.getObject();
if (highMerchantStore.getMerchantId() == null if (userInfoModel.getMerchant() == null) {
|| StringUtils.isNotBlank(highMerchantStore.getStoreKey()) log.error("HighMerchantController -> insertMerchantStore() error!","该主角色没有权限");
|| StringUtils.isNotBlank(highMerchantStore.getStoreName()) throw ErrorHelp.genException(SysCode.System, ErrorCode.MENU_TREE_HAS_NOT_ERROR, "");
|| StringUtils.isNotBlank(highMerchantStore.getTelephone()) }
|| StringUtils.isNotBlank(highMerchantStore.getAddress())
|| StringUtils.isNotBlank(highMerchantStore.getLatitude()) if (StringUtils.isBlank(highMerchantStore.getStoreKey())
|| StringUtils.isNotBlank(highMerchantStore.getLongitude()) || StringUtils.isBlank(highMerchantStore.getStoreName())
|| StringUtils.isBlank(highMerchantStore.getTelephone())
|| StringUtils.isBlank(highMerchantStore.getAddress())
|| StringUtils.isBlank(highMerchantStore.getLatitude())
|| StringUtils.isBlank(highMerchantStore.getLongitude())
|| StringUtils.isBlank(highMerchantStore.getSecUser().getPassword())
|| StringUtils.isBlank(highMerchantStore.getSecUser().getTelephone())
) {
log.error("HighMerchantStoreController -> insertMerchantStore() error!","参数错误");
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, "");
}
// 校验商户
HighMerchant merchant = highMerchantService.getMerchantById(userInfoModel.getMerchant().getId());
if (merchant != null) {
log.error("HighMerchantStoreController -> insertMerchantStore() error!","未找到商户");
throw ErrorHelp.genException(SysCode.System, ErrorCode.MERCHANT_NOF_FOUND, "");
}
highMerchantStore.setCreateTime(new Date());
highMerchantStore.setUpdateTime(new Date());
highMerchantStore.setStatus(1); // 状态:0:删除,1:正常
highMerchantStore.setCompanyId(merchant.getCompanyId());
highMerchantStore.setMerchantId(merchant.getId());
highMerchantStore.setOperatorId(userInfoModel.getSecUser().getId());
highMerchantStore.setOperatorName(userInfoModel.getSecUser().getUserName());
highMerchantStoreService.insertMerchantStore(highMerchantStore);
return ResponseMsgUtil.success(highMerchantStore);
} catch (Exception e) {
log.error("HighMerchantStoreController -> insertMerchantStore() error!",e);
return ResponseMsgUtil.exception(e);
}
}
@RequestMapping(value="/updateMerchantStore",method = RequestMethod.POST)
@ResponseBody
@ApiOperation(value = "修改商户门店")
public ResponseData updateMerchantStore(@RequestBody HighMerchantStoreModel highMerchantStore, 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, "");
}
if (highMerchantStore.getId() == null
|| StringUtils.isBlank(highMerchantStore.getStoreKey())
|| StringUtils.isBlank(highMerchantStore.getStoreName())
|| StringUtils.isBlank(highMerchantStore.getTelephone())
|| StringUtils.isBlank(highMerchantStore.getAddress())
|| StringUtils.isBlank(highMerchantStore.getLatitude())
|| StringUtils.isBlank(highMerchantStore.getLongitude())
|| StringUtils.isBlank(highMerchantStore.getSecUser().getTelephone())
) { ) {
log.error("HighMerchantStoreController -> editMerchantStore() error!","参数错误"); log.error("HighMerchantStoreController -> insertMerchantStore() error!","参数错误");
throw ErrorHelp.genException(SysCode.System, ErrorCode.REQ_PARAMS_ERROR, ""); throw ErrorHelp.genException(SysCode.System, ErrorCode.REQ_PARAMS_ERROR, "");
} }
// id为空 就是增加门店,需要校验账号是否填写 // 校验账户手机号
if (highMerchantStore.getId() == null) { if (!MemberValidateUtil.validatePhone(highMerchantStore.getSecUser().getTelephone())) {
if (StringUtils.isBlank(highMerchantStore.getSecUser().getPassword()) || StringUtils.isBlank(highMerchantStore.getSecUser().getTelephone())) { log.error("BsStudentController --> addStudent() error!", "请输入正确的电话号码");
log.error("HighMerchantController -> editMerchant() error!","参数错误"); throw ErrorHelp.genException(SysCode.System, ErrorCode.PHONE_NUM_IS_ERROR, "");
throw ErrorHelp.genException(SysCode.System, ErrorCode.REQ_PARAMS_ERROR, ""); }
}
// 查询门店
// 校验账户手机号 HighMerchantStoreModel store = highMerchantStoreService.getMerchantStoreById(highMerchantStore.getId());
if (!MemberValidateUtil.validatePhone(highMerchantStore.getSecUser().getTelephone())) { if (store == null) {
log.error("BsStudentController --> addStudent() error!", "请输入正确的电话号码"); log.error("BsStudentController --> addStudent() error!", "请输入正确的电话号码");
throw ErrorHelp.genException(SysCode.System, ErrorCode.PHONE_NUM_IS_ERROR, ""); throw ErrorHelp.genException(SysCode.System, ErrorCode.PHONE_NUM_IS_ERROR, "");
} }
// 校验账号手机号是否存在 // 校验账号手机号是否存在
if (secUserService.findByPhone(highMerchantStore.getSecUser().getTelephone()) != null) { if (!store.getSecUser().getTelephone().equals(highMerchantStore.getSecUser().getTelephone())
log.error("BsStudentController --> addStudent() error!", "电话号码已被使用"); && secUserService.findByPhone(highMerchantStore.getSecUser().getTelephone()) != null) {
throw ErrorHelp.genException(SysCode.System, ErrorCode.PHONE_NUM_EXISTED, ""); log.error("BsStudentController --> addStudent() error!", "电话号码已被使用");
} throw ErrorHelp.genException(SysCode.System, ErrorCode.PHONE_NUM_EXISTED, "");
}
// 校验商户
HighMerchant merchant = highMerchantService.getMerchantById(highMerchantStore.getMerchantId()); // 校验商户
if (merchant != null) { HighMerchant merchant = highMerchantService.getMerchantById(highMerchantStore.getMerchantId());
log.error("HighMerchantStoreController -> editMerchantStore() error!","未找到商户"); if (merchant != null) {
throw ErrorHelp.genException(SysCode.System, ErrorCode.MERCHANT_NOF_FOUND, ""); log.error("HighMerchantStoreController -> editMerchantStore() error!","未找到商户");
} throw ErrorHelp.genException(SysCode.System, ErrorCode.MERCHANT_NOF_FOUND, "");
highMerchantStore.setCompanyId(merchant.getCompanyId());
highMerchantStore.setCreateTime(new Date());
highMerchantStore.setUpdateTime(new Date());
highMerchantStore.setStatus(1); // 状态:0:删除,1:正常
} else {
highMerchantStore.setUpdateTime(new Date());
} }
highMerchantStore.setUpdateTime(new Date());
highMerchantStore.setOperatorId(userInfoModel.getSecUser().getId()); highMerchantStore.setOperatorId(userInfoModel.getSecUser().getId());
highMerchantStore.setOperatorName(userInfoModel.getSecUser().getUserName()); highMerchantStore.setOperatorName(userInfoModel.getSecUser().getUserName());
highMerchantStoreService.editMerchantStore(highMerchantStore); highMerchantStoreService.updateMerchantStore(highMerchantStore);
return ResponseMsgUtil.success(highMerchantStore); return ResponseMsgUtil.success(highMerchantStore);
} catch (Exception e) { } catch (Exception e) {

@ -15,10 +15,17 @@ public interface HighMerchantStoreService {
/** /**
* @Author 胡锐 * @Author 胡锐
* @Description 编辑门店 * @Description 增加门店
* @Date 2021/3/9 20:26 * @Date 2021/3/9 20:26
**/ **/
void editMerchantStore(HighMerchantStoreModel highMerchantStore) throws Exception; void insertMerchantStore(HighMerchantStoreModel highMerchantStore) throws Exception;
/**
* @Author 胡锐
* @Description 修改门店
* @Date 2021/3/12 22:15
**/
void updateMerchantStore(HighMerchantStoreModel highMerchantStore) throws Exception;
/** /**
* @Author 胡锐 * @Author 胡锐
@ -32,7 +39,7 @@ public interface HighMerchantStoreService {
* @Description 根据id查询 * @Description 根据id查询
* @Date 2021/3/9 20:26 * @Date 2021/3/9 20:26
**/ **/
HighMerchantStore getMerchantStoreById(Long id); HighMerchantStoreModel getMerchantStoreById(Long id);
/** /**
* @Author 胡锐 * @Author 胡锐

@ -54,10 +54,16 @@ public class HighMerchantServiceImpl implements HighMerchantService {
public void updateMerchant(HighMerchantModel highMerchant) throws Exception { public void updateMerchant(HighMerchantModel highMerchant) throws Exception {
highMerchantMapper.updateByPrimaryKey(highMerchant); highMerchantMapper.updateByPrimaryKey(highMerchant);
if (StringUtils.isNotBlank(highMerchant.getSecUser().getPassword())) { // 查询主账号
highMerchant.getSecUser().setPassword(MD5Util.encode(highMerchant.getSecUser().getPassword().getBytes())); SecUser mainAccount = secUserService.getMainAccount(2, highMerchant.getId());
if (mainAccount != null) {
String userPass = MD5Util.encode(highMerchant.getSecUser().getPassword().getBytes());
if (!mainAccount.getPassword().equals(userPass)) {
mainAccount.setPassword(userPass);
}
mainAccount.setTelephone(highMerchant.getTelephone());
secUserService.updateUser(mainAccount);
} }
secUserService.updateUser(highMerchant.getSecUser());
} }
@Override @Override

@ -14,6 +14,7 @@ import com.hai.service.HighMerchantStoreService;
import com.hai.service.SecUserService; import com.hai.service.SecUserService;
import org.apache.commons.collections4.MapUtils; import org.apache.commons.collections4.MapUtils;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
@ -33,22 +34,36 @@ public class HighMerchantStoreServiceImpl implements HighMerchantStoreService {
@Override @Override
@Transactional @Transactional
public void editMerchantStore(HighMerchantStoreModel highMerchantStore) throws Exception { public void insertMerchantStore(HighMerchantStoreModel highMerchantStore) throws Exception {
if (highMerchantStore.getId() != null) { highMerchantStoreMapper.insert(highMerchantStore);
highMerchantStoreMapper.updateByPrimaryKey(highMerchantStore);
} else { highMerchantStore.getSecUser().setUserName(highMerchantStore.getStoreName());
highMerchantStoreMapper.insert(highMerchantStore); highMerchantStore.getSecUser().setLoginName(highMerchantStore.getSecUser().getTelephone());
highMerchantStore.getSecUser().setUserName(highMerchantStore.getStoreName()); highMerchantStore.getSecUser().setPassword(MD5Util.encode(highMerchantStore.getSecUser().getPassword().getBytes()));
highMerchantStore.getSecUser().setLoginName(highMerchantStore.getSecUser().getTelephone()); highMerchantStore.getSecUser().setAdminFlag(1);
highMerchantStore.getSecUser().setPassword(MD5Util.encode(highMerchantStore.getSecUser().getPassword().getBytes())); highMerchantStore.getSecUser().setStatus(1);
highMerchantStore.getSecUser().setAdminFlag(1); highMerchantStore.getSecUser().setRoleId(3L);
highMerchantStore.getSecUser().setStatus(1); highMerchantStore.getSecUser().setObjectType(3);
highMerchantStore.getSecUser().setRoleId(3L); highMerchantStore.getSecUser().setObjectId(highMerchantStore.getId());
highMerchantStore.getSecUser().setObjectType(3); highMerchantStore.getSecUser().setCreateTime(new Date());
highMerchantStore.getSecUser().setObjectId(highMerchantStore.getId()); highMerchantStore.getSecUser().setUpdateTime(new Date());
highMerchantStore.getSecUser().setCreateTime(new Date()); secUserService.addUser(highMerchantStore.getSecUser());
highMerchantStore.getSecUser().setUpdateTime(new Date()); }
secUserService.addUser(highMerchantStore.getSecUser());
@Override
@Transactional
public void updateMerchantStore(HighMerchantStoreModel highMerchantStore) throws Exception {
highMerchantStoreMapper.updateByPrimaryKey(highMerchantStore);
// 查询主账号
SecUser mainAccount = secUserService.getMainAccount(3, highMerchantStore.getId());
if (mainAccount != null) {
String userPass = MD5Util.encode(highMerchantStore.getSecUser().getPassword().getBytes());
if (!mainAccount.getPassword().equals(userPass)) {
mainAccount.setPassword(userPass);
}
mainAccount.setTelephone(highMerchantStore.getTelephone());
secUserService.updateUser(mainAccount);
} }
} }
@ -73,8 +88,20 @@ public class HighMerchantStoreServiceImpl implements HighMerchantStoreService {
} }
@Override @Override
public HighMerchantStore getMerchantStoreById(Long id) { public HighMerchantStoreModel getMerchantStoreById(Long id) {
return highMerchantStoreMapper.selectByPrimaryKey(id); HighMerchantStore merchantStore = highMerchantStoreMapper.selectByPrimaryKey(id);
if (merchantStore == null) {
return null;
}
HighMerchantStoreModel model = new HighMerchantStoreModel();
BeanUtils.copyProperties(merchantStore, model);
// 查询主账号
SecUser mainAccount = secUserService.getMainAccount(3, merchantStore.getId());
if (mainAccount != null) {
model.setSecUser(mainAccount);
}
return model;
} }
@Override @Override

Loading…
Cancel
Save