'提交代码'

dev-discount
199901012 4 years ago
parent 5834b713bb
commit ecc1c80682
  1. 109
      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. 39
      hai-service/src/main/java/com/hai/service/impl/HighMerchantStoreServiceImpl.java

@ -56,30 +56,90 @@ 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 -> 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("HighMerchantStoreController --> insertMerchantStore() error!", "请输入正确的电话号码");
log.error("HighMerchantController -> editMerchant() 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 -> insertMerchantStore() error!","参数错误");
throw ErrorHelp.genException(SysCode.System, ErrorCode.REQ_PARAMS_ERROR, ""); throw ErrorHelp.genException(SysCode.System, ErrorCode.REQ_PARAMS_ERROR, "");
} }
@ -89,8 +149,16 @@ public class HighMerchantStoreController {
throw ErrorHelp.genException(SysCode.System, ErrorCode.PHONE_NUM_IS_ERROR, ""); throw ErrorHelp.genException(SysCode.System, ErrorCode.PHONE_NUM_IS_ERROR, "");
} }
// 查询门店
HighMerchantStoreModel store = highMerchantStoreService.getMerchantStoreById(highMerchantStore.getId());
if (store == null) {
log.error("BsStudentController --> addStudent() 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())
&& secUserService.findByPhone(highMerchantStore.getSecUser().getTelephone()) != null) {
log.error("BsStudentController --> addStudent() error!", "电话号码已被使用"); log.error("BsStudentController --> addStudent() error!", "电话号码已被使用");
throw ErrorHelp.genException(SysCode.System, ErrorCode.PHONE_NUM_EXISTED, ""); throw ErrorHelp.genException(SysCode.System, ErrorCode.PHONE_NUM_EXISTED, "");
} }
@ -101,18 +169,11 @@ public class HighMerchantStoreController {
log.error("HighMerchantStoreController -> editMerchantStore() error!","未找到商户"); log.error("HighMerchantStoreController -> editMerchantStore() error!","未找到商户");
throw ErrorHelp.genException(SysCode.System, ErrorCode.MERCHANT_NOF_FOUND, ""); 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,11 +34,9 @@ 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.updateByPrimaryKey(highMerchantStore);
} else {
highMerchantStoreMapper.insert(highMerchantStore); highMerchantStoreMapper.insert(highMerchantStore);
highMerchantStore.getSecUser().setUserName(highMerchantStore.getStoreName()); highMerchantStore.getSecUser().setUserName(highMerchantStore.getStoreName());
highMerchantStore.getSecUser().setLoginName(highMerchantStore.getSecUser().getTelephone()); highMerchantStore.getSecUser().setLoginName(highMerchantStore.getSecUser().getTelephone());
highMerchantStore.getSecUser().setPassword(MD5Util.encode(highMerchantStore.getSecUser().getPassword().getBytes())); highMerchantStore.getSecUser().setPassword(MD5Util.encode(highMerchantStore.getSecUser().getPassword().getBytes()));
@ -50,6 +49,22 @@ public class HighMerchantStoreServiceImpl implements HighMerchantStoreService {
highMerchantStore.getSecUser().setUpdateTime(new Date()); highMerchantStore.getSecUser().setUpdateTime(new Date());
secUserService.addUser(highMerchantStore.getSecUser()); 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);
}
} }
@Override @Override
@ -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