Commit 51d0241b by zhanghj

V1.5.0--完善标准接口派单,自动帮用户创建商户功能

git-svn-id: svn://192.168.3.233/frms/code/car-service/trunk/car-service@24567 aeb6102e-e053-11e5-9fec-f9ebc45caf4b
1 parent e2042fbf
......@@ -216,6 +216,21 @@ public interface Constants {
*/
public static final String DEVICE_TYPE_700F = "sys_order_service_item_gps_GT700F";
/**
* 商户服务类型:1:上门
*/
public static final int MERCHANT_SERVICE_TYPE = 1;
/**
* 服务项目字典类型
*/
public static final String SYS_ORDER_SERVICE_ITEM = "sys_order_service_item";
/**
* 自动创建商户默认密码
*/
public static final String MERCHANT_DAFAULT_PASSWORD = "123456";
final static String DEFAULT_PASSWORD = "123456";
}
......@@ -10,6 +10,7 @@ import org.springframework.web.bind.annotation.RequestParam;
import com.alibaba.fastjson.JSONObject;
import com.glsx.common.config.FeignConfig;
import com.glsx.common.pojo.MerchantReq;
import com.glsx.common.pojo.OderReceivingReq;
......@@ -187,4 +188,17 @@ public interface UserClient {
@RequestMapping(method = RequestMethod.POST, value = "/carservice/usercenter/user/autoRegisterAndLogin")
JSONObject autoRegisterAndLogin(@RequestBody OderReceivingReq orderReceivingReq);
/**
*
* @author zhanghj
* @Title: saveSysMerchant
* @Description: TODO 创建商户
* @param merchantReq
* @return
* JSONObject
* @version
*/
@RequestMapping(method = RequestMethod.POST, value = "/carservice/usercenter/user/saveSysMerchant")
JSONObject saveSysMerchant( @RequestBody MerchantReq merchantReq);
}
package com.glsx.common.pojo;
import java.util.ArrayList;
import java.util.List;
/**
*
* @Title MerchantReq.java
* @Package com.glsx.ordercenter.dto
* @Description TODO 商户请求实体
* @author zhanghj
* @date 2019年11月1日 下午3:16:16
* @version 1.0.0
*/
public class MerchantReq {
/**
* 用户登录名
*/
private String username;
/**
* 用户密码
*/
private String password;
/**
* 店面联系人
*/
private String name;
/**
* 手机号
*/
private String phoneNumber;
/**
* 门店所在省市区
*/
private String district;
/**
* 门店详细地址
*/
private String address;
/**
* 店面名称
*/
private String shopName;
/**
* 所属组织id
*/
private Integer orgId;
/**
* 服务类型
*/
private Integer serviceType;
/**
* 服务项key
*/
private List<String> serviceKeyList = new ArrayList<>();
public String getDistrict() {
return district;
}
public void setDistrict(String district) {
this.district = district;
}
public String getAddress() {
return address;
}
public void setAddress(String address) {
this.address = address;
}
public String getShopName() {
return shopName;
}
public void setShopName(String shopName) {
this.shopName = shopName;
}
public Integer getServiceType() {
return serviceType;
}
public void setServiceType(Integer serviceType) {
this.serviceType = serviceType;
}
public List<String> getServiceKeyList() {
return serviceKeyList;
}
public void setServiceKeyList(List<String> serviceKeyList) {
this.serviceKeyList = serviceKeyList;
}
public Integer getOrgId() {
return orgId;
}
public void setOrgId(Integer orgId) {
this.orgId = orgId;
}
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getPhoneNumber() {
return phoneNumber;
}
public void setPhoneNumber(String phoneNumber) {
this.phoneNumber = phoneNumber;
}
}
......@@ -18,6 +18,7 @@ import com.alibaba.fastjson.JSONObject;
import com.glsx.common.constants.Constants;
import com.glsx.common.constants.ResultObject;
import com.glsx.common.feign.client.UserClient;
import com.glsx.common.pojo.MerchantReq;
import com.glsx.common.utils.DateUtil;
import com.glsx.common.utils.HttpUtils;
import com.glsx.common.utils.PropertiesUtil;
......@@ -34,6 +35,7 @@ import com.glsx.ordercenter.exception.BusinessException;
import com.glsx.ordercenter.mapper.DictionaryDataMapper;
import com.glsx.ordercenter.mapper.SysOrderMapper;
import com.glsx.ordercenter.mapper.SysOrderStatusMapper;
import com.glsx.ordercenter.pojo.DictionaryData;
import com.glsx.ordercenter.pojo.SysChannelOrg;
import com.glsx.ordercenter.pojo.SysOrder;
import com.glsx.ordercenter.pojo.SysOrderExample;
......@@ -293,7 +295,7 @@ public class StandardOrderServiceImpl implements StandardOrderService {
int size = array.size();
if (size == 0) {
//自动帮订单创建商户
merchantId = saveMerchant(sysOrder, district, groupId);
} else if (size == 1) {
JSONObject data = array.getJSONObject(0);
serviceType = data.getString("serviceType");
......@@ -360,6 +362,57 @@ public class StandardOrderServiceImpl implements StandardOrderService {
}
/**
*
* @author zhanghj
* @Title: saveMerchant
* @Description: TODO 创建商户
* @param sysOrder
* @param district
* @param groupId
* @return
* Integer
* @version
*/
private Integer saveMerchant(SysOrder sysOrder, Integer district,
Integer groupId) {
// TODO Auto-generated method stub
Integer merchantId = null;
try{
String merchantName = sysOrder.getMerchantName();
String address = sysOrder.getAddress();
MerchantReq merchantReq = new MerchantReq();
merchantReq.setUsername(merchantName);
merchantReq.setPassword(Constants.MERCHANT_DAFAULT_PASSWORD);
merchantReq.setName(sysOrder.getContact());
merchantReq.setPhoneNumber(sysOrder.getPhoneNumber());
merchantReq.setShopName(merchantName);
merchantReq.setDistrict(String.valueOf(district));
merchantReq.setAddress(address);
merchantReq.setOrgId(groupId);
merchantReq.setServiceType(Constants.MERCHANT_SERVICE_TYPE);
DictionaryData dictionaryData = new DictionaryData();
dictionaryData.setDictType(Constants.SYS_ORDER_SERVICE_ITEM);
List<String> serviceKeyList = new ArrayList<String>();
List<DictionaryData> dictionaryDataList= dictionaryDataMapper.list(dictionaryData);
for(DictionaryData dictData : dictionaryDataList) {
serviceKeyList.add(dictData.getDataKey());
}
merchantReq.setServiceKeyList(serviceKeyList);
JSONObject merchantObject = userClient.saveSysMerchant(merchantReq);
if (merchantObject != null && merchantObject.getIntValue("code") == ResultCodeEnum.SUCCESS.getCode()) {
merchantId = merchantObject.getInteger("data");
if (merchantId == 0) {
merchantId = null;
}
}
} catch (Exception e) {
logger.error("标准接口派单,自动创建商户异常", e);
}
return merchantId;
}
@Override
@Transactional(rollbackFor=Exception.class)
public ResultObject update(SysOrder sysOrder) {
......@@ -423,7 +476,10 @@ public class StandardOrderServiceImpl implements StandardOrderService {
if (obj != null && obj.getIntValue("code") == ResultCodeEnum.SUCCESS.getCode()) {
JSONArray array = obj.getJSONArray("data");
int size = array.size();
if (size == 1) {
if (size == 0) {
//自动帮订单创建商户
merchantId = saveMerchant(sysOrder, district, groupId);
} else if (size == 1) {
JSONObject data = array.getJSONObject(0);
serviceType = data.getString("serviceType");
merchantId = data.getInteger("id");
......@@ -463,7 +519,7 @@ public class StandardOrderServiceImpl implements StandardOrderService {
order.setUpdateBy(merchantId);
order.setMerchantName(merchantName);
order.setNewWorkOrderNo(sysOrder.getNewWorkOrderNo());
if (!oldMerchantId.equals(merchantId)) {
if (oldMerchantId != null && !oldMerchantId.equals(merchantId)) {
order.setShopId(merchantId);
order.setMerchantId(serviceId);
order.setMechanicId(mechanicId);
......
......@@ -4,6 +4,9 @@ import static org.junit.Assert.assertTrue;
import org.junit.Test;
import com.alibaba.druid.util.StringUtils;
/**
* Unit test for simple App.
*/
......@@ -16,5 +19,9 @@ public class AppTest
public void shouldAnswerWithTrue()
{
assertTrue( true );
String s = null;
if (!StringUtils.isEmpty(s) && StringUtils.isNumber(s)) {
System.out.println(StringUtils.isNumber(s));
}
}
}
......@@ -132,6 +132,8 @@ public class ShiroConfig {
filterChainDefinitionMap.put("/user/wxLogin", "anon");
//获取在线管理员列表
filterChainDefinitionMap.put("/user/getOnlineManagerList", "anon");
//创建商户
filterChainDefinitionMap.put("/user/saveSysMerchant", "anon");
//退出
// filterChainDefinitionMap.put("/user/logout", "logout");
// filterChainDefinitionMap.put("/**", "authc");
......
......@@ -37,10 +37,12 @@ import com.glsx.common.constants.Constants;
import com.glsx.common.constants.ResultObject;
import com.glsx.common.feign.client.CommonClient;
import com.glsx.common.feign.client.OrderClient;
import com.glsx.common.pojo.MerchantReq;
import com.glsx.common.pojo.OderReceivingReq;
import com.glsx.common.utils.DateUtil;
import com.glsx.common.utils.Page;
import com.glsx.common.utils.StringUtils;
import com.glsx.common.utils.bean.BeanUtils;
import com.glsx.common.utils.wehcat.WechatMiniUtils;
import com.glsx.common.utils.wehcat.WechatUtils;
import com.glsx.usercenter.constants.LoginType;
......@@ -252,11 +254,15 @@ public class UserController extends BaseController {
@Log(menuName = "商户管理", operateType = com.glsx.common.constants.Constants.SYS_LOG_OPERATE_TYPE_SAVE)
@RequestMapping(value = "/saveSysMerchant", method = {RequestMethod.GET, RequestMethod.POST})
@ResponseBody
public ResultObject saveSysMerchant(@Validated(value = {Default.class}) SysMerchant sysMerchant, BindingResult bindingResult) {
public ResultObject saveSysMerchant(@Validated(value = {Default.class})SysMerchant sysMerchant, BindingResult bindingResult, @RequestBody MerchantReq merchantReq) {
logger.info("(新增, 编辑)商户传入的参数为" + sysMerchant.toString());
if (bindingResult.hasErrors()) {
Map<String, String> errorMap = getErrors(bindingResult);
return new ResultObject(ResultCodeEnum.PARAM_ERROR.getCode(), ResultCodeEnum.PARAM_ERROR.getMsg(), errorMap);
logger.info("派单自动创建商户通过feign接口调用merchantReq===" + merchantReq.toString());
if (merchantReq != null) {
BeanUtils.copyBeanProp(sysMerchant, merchantReq);
}
Map<String, String> errorMap = getErrors(sysMerchant);
if (errorMap.size() >0) {
return new ResultObject(ResultCodeEnum.PARAM_ERROR.getCode(), ResultCodeEnum.PARAM_ERROR.getMsg(), errorMap);
}
if (StringUtils.isEmpty(sysMerchant.getPassword())) {
return new ResultObject(ResultCodeEnum.PARAM_ERROR.getCode(), ResultCodeEnum.PARAM_ERROR.getMsg());
......@@ -280,6 +286,9 @@ public class UserController extends BaseController {
if (merchants != null && merchants.size() == 1) {
merchant = merchants.get(0);
}
//标准接口派单,用户是未登录状态
Integer currentUserId = ShiroUtil.getUserId();
currentUserId = currentUserId == null ? -1 : currentUserId;
if (sysMerchant.getId() == null) {
// 新增商户
if (!sysUserService.findByUserName(sysMerchant.getUsername()).isEmpty()) {
......@@ -293,7 +302,7 @@ public class UserController extends BaseController {
sysMerchant.setPassword(sysUserService.encryptPassword(sysMerchant.getPassword()));
sysMerchant.setCreateTime(DateUtil.getCurrentTime());
sysMerchant.setCreateBy(ShiroUtil.getUserId());
sysMerchant.setCreateBy(currentUserId);
//设置默认商户角色
// Integer roleId = sysRoleMapper.getIdByCharacter("sys_default_merchant");
List<Integer> roleIds = new ArrayList<>();
......@@ -333,7 +342,7 @@ public class UserController extends BaseController {
}
sysMerchant.setUserType(Constants.USER_TYPE_MERCHANT);
sysMerchant.setUpdateBy(ShiroUtil.getUserId());
sysMerchant.setUpdateBy(currentUserId);
sysMerchant.setUpdateTime(DateUtil.getCurrentTime());
return new ResultObject(ResultCodeEnum.SUCCESS.getCode(), ResultCodeEnum.SUCCESS.getMsg(), sysUserService.saveSysMerchant(sysMerchant, orderClient));
}
......
......@@ -381,13 +381,18 @@ public class SysUserServiceImpl implements SysUserService {
sysUserMapper.insertSysMerchant(sysMerchant);
userId = sysMerchant.getUserId();
//当前用户获取该商户组织的数据权限
SysUserOrg sysUserOrg = new SysUserOrg();
sysUserOrg.setUserId(ShiroUtil.getUserId());
sysUserOrg.setOrgId(orgId);
sysUserOrgMapper.insertSelective(sysUserOrg);
//后台管理系统用户添加商户时候,当前用户获取该商户组织的数据权限
Integer currentUserId = ShiroUtil.getUserId();
if (currentUserId != null) {
SysUserOrg sysUserOrg = new SysUserOrg();
sysUserOrg.setUserId(currentUserId);
sysUserOrg.setOrgId(orgId);
sysUserOrgMapper.insertSelective(sysUserOrg);
}
//新增商户获取该商户组织的数据权限
SysUserOrg sysUserOrg = new SysUserOrg();
sysUserOrg.setOrgId(orgId);
sysUserOrg.setUserId(userId);
sysUserOrgMapper.insertSelective(sysUserOrg);
......
......@@ -70,11 +70,21 @@ public class ShiroUtil {
}
public static Integer getUserId() {
return getUser().getId().intValue();
SysUser user = getUser();
Integer userId = null;
if (user != null) {
userId = user.getId().intValue();
}
return userId;
}
public static String getUsername() {
return getUser().getUsername();
SysUser user = getUser();
String username = null;
if (user != null) {
username = user.getUsername();
}
return username;
}
public static String getIp() {
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!