Browse Source

[商铺商户][修改]:新增或编辑商户时,添加商铺商户关联关系和商户管理员信息的逻辑

release_toaliyun_real
gongbiao 7 years ago
parent
commit
b9d975185c
7 changed files with 184 additions and 43 deletions
  1. +4
    -6
      mallinkAdmin/src/main/java/com/simple/controller/WxMerchantBUserController.java
  2. +6
    -8
      mallinkAdmin/src/main/java/com/simple/controller/WxMerchantController.java
  3. +17
    -6
      mallinkService/src/main/java/com/simple/domain/po/WxMerchant.java
  4. +3
    -7
      mallinkService/src/main/java/com/simple/service/WxMerchantService.java
  5. +141
    -10
      mallinkService/src/main/java/com/simple/service/impl/WxMerchantServiceImpl.java
  6. +3
    -4
      mallinkService/src/main/java/com/simple/service/impl/WxShopServiceImpl.java
  7. +10
    -2
      mallinkService/src/main/resources/mapper/WxMerchantMapper.xml

+ 4
- 6
mallinkAdmin/src/main/java/com/simple/controller/WxMerchantBUserController.java View File

@@ -1,19 +1,16 @@
package com.simple.controller;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.Assert;
import org.springframework.web.bind.annotation.*;

import com.github.pagehelper.PageInfo;
import com.simple.common.Result;
import com.simple.common.ResultData;

import com.simple.domain.po.WxMerchantBUser;
import com.simple.service.WxMerchantBUserService;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("wxMerchantBUser")
@@ -40,6 +37,7 @@ public class WxMerchantBUserController extends BaseController
public ResultData add(@RequestBody WxMerchantBUser wxMerchantBUser) {
//Assert.notNull(wxMerchantBUser.getName(), "角色名不能为空");
//Assert.isTrue(!checkUnique(sysRole.getName(), null), "重复的角色名");
wxMerchantBUser.setTenantId(getTenantId());
wxMerchantBUserService.saveOrUpdate(wxMerchantBUser);
return new ResultData();
}


+ 6
- 8
mallinkAdmin/src/main/java/com/simple/controller/WxMerchantController.java View File

@@ -1,19 +1,16 @@
package com.simple.controller;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.Assert;
import org.springframework.web.bind.annotation.*;

import com.github.pagehelper.PageInfo;
import com.simple.common.Result;
import com.simple.common.ResultData;

import com.simple.domain.po.WxMerchant;
import com.simple.service.WxMerchantService;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("wxMerchant")
@@ -37,10 +34,11 @@ public class WxMerchantController extends BaseController

@ApiOperation("新增接口")
@PostMapping("add")
public ResultData add(@RequestBody WxMerchant wxMerchant) {
public ResultData add(@ModelAttribute WxMerchant wxMerchant,String shopids, String userids) {
//Assert.notNull(wxMerchant.getName(), "角色名不能为空");
//Assert.isTrue(!checkUnique(sysRole.getName(), null), "重复的角色名");
wxMerchantService.saveOrUpdate(wxMerchant);
wxMerchant.setTenantId(getTenantId());
wxMerchantService.saveOrUpdate(wxMerchant,shopids,userids);
return new ResultData();
}



+ 17
- 6
mallinkService/src/main/java/com/simple/domain/po/WxMerchant.java View File

@@ -1,12 +1,11 @@
package com.simple.domain.po;

import javax.persistence.*;
import java.util.*;
import java.math.*;
import javax.persistence.Transient;
import java.util.List;
import javax.persistence.Id;
import javax.persistence.Table;
import javax.persistence.Transient;
import java.io.Serializable;
import java.util.Date;
import java.util.List;

@Table(name = "wx_merchant")
public class WxMerchant implements Serializable {
@@ -74,6 +73,10 @@ public class WxMerchant implements Serializable {
/*停车厂商参数**/
@io.swagger.annotations.ApiModelProperty(value="停车厂商参数",name="carParams")
private String carParams;

@io.swagger.annotations.ApiModelProperty(value="状态1可用0停用",name="status")
private Integer status;

public String getTenantId() {
return tenantId;
}
@@ -141,7 +144,13 @@ public class WxMerchant implements Serializable {
carParams = _carParams;
}

public Integer getStatus() {
return status;
}

public void setStatus(Integer status) {
this.status = status;
}

public static enum Field
{
@@ -157,7 +166,9 @@ public class WxMerchant implements Serializable {
,UpdateDate_ASC("`updateDate` ASC"),UpdateDate_DESC("`updateDate` DESC")
,CarVendorType_ASC("`carVendorType` ASC"),CarVendorType_DESC("`carVendorType` DESC")
,CarParams_ASC("`carParams` ASC"),CarParams_DESC("`carParams` DESC")
;
,Status_ASC("`status` ASC"),Status_DESC("`status` DESC")

;
private String value;
Field(String value){
this.value = value;


+ 3
- 7
mallinkService/src/main/java/com/simple/service/WxMerchantService.java View File

@@ -37,12 +37,8 @@ public interface WxMerchantService {
* @param id
*/
void deleteById(Long id);


void saveOrUpdate(WxMerchant wxMerchant, String shopids, String userids);

}

+ 141
- 10
mallinkService/src/main/java/com/simple/service/impl/WxMerchantServiceImpl.java View File

@@ -1,14 +1,24 @@
package com.simple.service.impl;

import java.util.*;
import com.alibaba.fastjson.JSONArray;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.simple.common.IdWorker;
import com.simple.domain.po.WxMerchant;
import com.simple.domain.po.WxMerchantBUser;
import com.simple.domain.po.WxMerchantShop;
import com.simple.domain.po.WxShop;
import com.simple.mapper.WxMerchantBUserMapper;
import com.simple.mapper.WxMerchantMapper;
import com.simple.mapper.WxMerchantShopMapper;
import com.simple.mapper.WxShopMapper;
import com.simple.service.WxMerchantService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.simple.common.IdWorker;
import org.springframework.transaction.annotation.Transactional;

import java.util.Date;
import java.util.List;

@Service
public class WxMerchantServiceImpl implements WxMerchantService {
@@ -16,6 +26,14 @@ public class WxMerchantServiceImpl implements WxMerchantService {
@Autowired
WxMerchantMapper wxMerchantMapper;

@Autowired
WxShopMapper WxShopMapper;

@Autowired
WxMerchantShopMapper wxMerchantShopMapper;

@Autowired
WxMerchantBUserMapper wxMerchantBUserMapper;

@Override
public PageInfo<WxMerchant> listAsPage(WxMerchant record, Integer pageIndex, Integer pageSize) {
@@ -33,6 +51,8 @@ public class WxMerchantServiceImpl implements WxMerchantService {
//record.setId(UUID.randomUUID().toString().replaceAll("-", ""));
final IdWorker idWorker = IdWorker.get();
record.setId(idWorker.nextId());
record.setCreateDate(new Date());

wxMerchantMapper.insertSelective(record);
} else {
wxMerchantMapper.updateByPrimaryKeySelective(record);
@@ -43,12 +63,123 @@ public class WxMerchantServiceImpl implements WxMerchantService {
public void deleteById(Long id) {
wxMerchantMapper.deleteByPrimaryKey(id);
}

@Transactional
@Override
public void saveOrUpdate(WxMerchant wxMerchant, String shopids, String userids) {


if (wxMerchant.getId() == null) {
final IdWorker idWorker = IdWorker.get();
long merchantid = idWorker.nextId();
wxMerchant.setId(merchantid);
Date date = new Date();
wxMerchant.setUpdateDate(date);
wxMerchant.setCreateDate(date);
wxMerchantMapper.insertSelective(wxMerchant);

//保存商户商铺的关联
List<Long> shopidlist = JSONArray.parseArray(shopids, Long.class);
for(Long shopid:shopidlist){
WxMerchantShop wxMerchantShop = new WxMerchantShop();
wxMerchantShop.setId(idWorker.nextId());
wxMerchantShop.setMerchantId(merchantid);
wxMerchantShop.setShopId(shopid);
wxMerchantShop.setTenantId(wxMerchant.getTenantId());
Date shopdate = new Date();
wxMerchantShop.setUpdateDate(shopdate);
wxMerchantShop.setCreateDate(shopdate);
wxMerchantShop.setRentalEndDate(shopdate);
wxMerchantShop.setRentalStartDate(shopdate);
wxMerchantShopMapper.insertSelective(wxMerchantShop);

//更新商铺状态
WxShop wxShop = new WxShop();
wxShop.setId(shopid);
wxShop.setStatus(1);//已出租
WxShopMapper.updateByPrimaryKeySelective(wxShop);
}

//保存商户关联用户
List<Long> useridlist = JSONArray.parseArray(userids, Long.class);
for(Long userid:useridlist){
WxMerchantBUser wxMerchantBUser = new WxMerchantBUser();
wxMerchantBUser.setId(userid);
List<WxMerchantBUser> buserlist = wxMerchantBUserMapper.findList(wxMerchantBUser);
if(buserlist.size()>0){
wxMerchantBUser = buserlist.get(0);
wxMerchantBUser.setMerchantId(merchantid);
wxMerchantBUser.setUpdateDate(new Date());
wxMerchantBUserMapper.updateByPrimaryKey(wxMerchantBUser);
}
}


} else {

//更新商户
Date date = new Date();
wxMerchant.setUpdateDate(date);
wxMerchantMapper.updateByPrimaryKeySelective(wxMerchant);

//删除当前商户关联的所有商铺然后再插入
WxMerchantShop wxMerchantShopQuery = new WxMerchantShop();
wxMerchantShopQuery.setTenantId(wxMerchant.getTenantId());
wxMerchantShopQuery.setMerchantId(wxMerchant.getId());
List<WxMerchantShop> wxMerchantShopList = wxMerchantShopMapper.findList(wxMerchantShopQuery);
for(WxMerchantShop merchantShop:wxMerchantShopList){
wxMerchantShopMapper.delete(merchantShop);

//更新商铺状态
WxShop wxShop = new WxShop();
wxShop.setId(merchantShop.getShopId());
wxShop.setStatus(0);//已出租
WxShopMapper.updateByPrimaryKeySelective(wxShop);
}

final IdWorker idWorker = IdWorker.get();
//保存商户商铺的关联
List<Long> shopidlist = JSONArray.parseArray(shopids, Long.class);
for(Long shopid:shopidlist){
WxMerchantShop wxMerchantShop = new WxMerchantShop();
wxMerchantShop.setId(idWorker.nextId());
wxMerchantShop.setMerchantId(wxMerchant.getId());
wxMerchantShop.setShopId(shopid);
wxMerchantShop.setTenantId(wxMerchant.getTenantId());
Date shopdate = new Date();
wxMerchantShop.setUpdateDate(shopdate);
wxMerchantShop.setCreateDate(shopdate);
wxMerchantShop.setRentalEndDate(shopdate);
wxMerchantShop.setRentalStartDate(shopdate);
wxMerchantShopMapper.insertSelective(wxMerchantShop);

//更新商铺状态
WxShop wxShop = new WxShop();
wxShop.setId(shopid);
wxShop.setStatus(1);//已出租
WxShopMapper.updateByPrimaryKeySelective(wxShop);
}


//保存商户关联用户
List<Long> useridlist = JSONArray.parseArray(userids, Long.class);
for(Long userid:useridlist){
WxMerchantBUser wxMerchantBUser = new WxMerchantBUser();
wxMerchantBUser.setId(userid);
List<WxMerchantBUser> buserlist = wxMerchantBUserMapper.findList(wxMerchantBUser);
if(buserlist.size()>0){
wxMerchantBUser = buserlist.get(0);
wxMerchantBUser.setMerchantId(wxMerchant.getId());
wxMerchantBUser.setUpdateDate(new Date());
wxMerchantBUserMapper.updateByPrimaryKey(wxMerchantBUser);
}
}


}


}


}

+ 3
- 4
mallinkService/src/main/java/com/simple/service/impl/WxShopServiceImpl.java View File

@@ -30,15 +30,14 @@ public class WxShopServiceImpl implements WxShopService {
@Override
public void saveOrUpdate(WxShop record) {

List<WxShop> list = wxShopMapper.findList(record);
if (record.getId() == null) {
//record.setId(UUID.randomUUID().toString().replaceAll("-", ""));
final IdWorker idWorker = IdWorker.get();
record.setId(idWorker.nextId());
record.setStatus(0);
record.setUpdateDate(new Date());
record.setCreateDate(new Date());
Date date = new Date();
record.setUpdateDate(date);
record.setCreateDate(date);
wxShopMapper.insertSelective(record);
} else {
record.setUpdateDate(new Date());


+ 10
- 2
mallinkService/src/main/resources/mapper/WxMerchantMapper.xml View File

@@ -14,10 +14,12 @@
<result column="update_date" jdbcType="TIMESTAMP" property="updateDate" />
<result column="car_vendor_type" jdbcType="INTEGER" property="carVendorType" />
<result column="car_params" jdbcType="VARCHAR" property="carParams" />
<result column="status" jdbcType="INTEGER" property="status" />

</resultMap>
<sql id="allColumns">
`id`,`tenant_id`,`img_url`,`name`,`link_phone`,`bank_card`,`bank_name`,`pay_id`,`create_date`,`update_date`,`car_vendor_type`,`car_params`
`id`,`tenant_id`,`img_url`,`name`,`link_phone`,`bank_card`,`bank_name`,`wxchat_account`,`create_date`,`update_date`,`car_vendor_type`,`car_params`,`status`
</sql>

<sql id="dynamicWhereConditions">
@@ -81,7 +83,13 @@
<if test=" null != carParams ">
and `car_params` like concat('%', #{carParams},'%')
</if>
</if>


<if test=" null != status ">
and `status` = #{status}

</if>
<if test=" null != ids ">
and id in
<foreach collection="ids" index="index" item="idItem" open="(" separator="," close=")">


Loading…
Cancel
Save