From b9d975185c8720729c8482cc033182dbe7b6ef8e Mon Sep 17 00:00:00 2001 From: gongbiao Date: Tue, 14 Aug 2018 15:59:14 +0800 Subject: [PATCH] =?UTF-8?q?[=E5=95=86=E9=93=BA=E5=95=86=E6=88=B7][?= =?UTF-8?q?=E4=BF=AE=E6=94=B9]:=E6=96=B0=E5=A2=9E=E6=88=96=E7=BC=96?= =?UTF-8?q?=E8=BE=91=E5=95=86=E6=88=B7=E6=97=B6=EF=BC=8C=E6=B7=BB=E5=8A=A0?= =?UTF-8?q?=E5=95=86=E9=93=BA=E5=95=86=E6=88=B7=E5=85=B3=E8=81=94=E5=85=B3?= =?UTF-8?q?=E7=B3=BB=E5=92=8C=E5=95=86=E6=88=B7=E7=AE=A1=E7=90=86=E5=91=98?= =?UTF-8?q?=E4=BF=A1=E6=81=AF=E7=9A=84=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/WxMerchantBUserController.java | 10 +- .../controller/WxMerchantController.java | 14 +- .../java/com/simple/domain/po/WxMerchant.java | 23 ++- .../com/simple/service/WxMerchantService.java | 10 +- .../service/impl/WxMerchantServiceImpl.java | 151 ++++++++++++++++-- .../service/impl/WxShopServiceImpl.java | 7 +- .../resources/mapper/WxMerchantMapper.xml | 12 +- 7 files changed, 184 insertions(+), 43 deletions(-) diff --git a/mallinkAdmin/src/main/java/com/simple/controller/WxMerchantBUserController.java b/mallinkAdmin/src/main/java/com/simple/controller/WxMerchantBUserController.java index 5b7ec6a03..0f1d79678 100644 --- a/mallinkAdmin/src/main/java/com/simple/controller/WxMerchantBUserController.java +++ b/mallinkAdmin/src/main/java/com/simple/controller/WxMerchantBUserController.java @@ -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(); } diff --git a/mallinkAdmin/src/main/java/com/simple/controller/WxMerchantController.java b/mallinkAdmin/src/main/java/com/simple/controller/WxMerchantController.java index 91e177f88..37034ab3e 100644 --- a/mallinkAdmin/src/main/java/com/simple/controller/WxMerchantController.java +++ b/mallinkAdmin/src/main/java/com/simple/controller/WxMerchantController.java @@ -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(); } diff --git a/mallinkService/src/main/java/com/simple/domain/po/WxMerchant.java b/mallinkService/src/main/java/com/simple/domain/po/WxMerchant.java index bc01d2a9e..19f28ca54 100644 --- a/mallinkService/src/main/java/com/simple/domain/po/WxMerchant.java +++ b/mallinkService/src/main/java/com/simple/domain/po/WxMerchant.java @@ -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; diff --git a/mallinkService/src/main/java/com/simple/service/WxMerchantService.java b/mallinkService/src/main/java/com/simple/service/WxMerchantService.java index d59b7e2b7..c5e2f6645 100644 --- a/mallinkService/src/main/java/com/simple/service/WxMerchantService.java +++ b/mallinkService/src/main/java/com/simple/service/WxMerchantService.java @@ -37,12 +37,8 @@ public interface WxMerchantService { * @param id */ void deleteById(Long id); - - - - - - - + + void saveOrUpdate(WxMerchant wxMerchant, String shopids, String userids); + } diff --git a/mallinkService/src/main/java/com/simple/service/impl/WxMerchantServiceImpl.java b/mallinkService/src/main/java/com/simple/service/impl/WxMerchantServiceImpl.java index 76129ab48..3264ac35f 100644 --- a/mallinkService/src/main/java/com/simple/service/impl/WxMerchantServiceImpl.java +++ b/mallinkService/src/main/java/com/simple/service/impl/WxMerchantServiceImpl.java @@ -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 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 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 useridlist = JSONArray.parseArray(userids, Long.class); + for(Long userid:useridlist){ + WxMerchantBUser wxMerchantBUser = new WxMerchantBUser(); + wxMerchantBUser.setId(userid); + List 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 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 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 useridlist = JSONArray.parseArray(userids, Long.class); + for(Long userid:useridlist){ + WxMerchantBUser wxMerchantBUser = new WxMerchantBUser(); + wxMerchantBUser.setId(userid); + List buserlist = wxMerchantBUserMapper.findList(wxMerchantBUser); + if(buserlist.size()>0){ + wxMerchantBUser = buserlist.get(0); + wxMerchantBUser.setMerchantId(wxMerchant.getId()); + wxMerchantBUser.setUpdateDate(new Date()); + wxMerchantBUserMapper.updateByPrimaryKey(wxMerchantBUser); + } + } + + + } + + + } + + } diff --git a/mallinkService/src/main/java/com/simple/service/impl/WxShopServiceImpl.java b/mallinkService/src/main/java/com/simple/service/impl/WxShopServiceImpl.java index d676075d7..a431bbdf8 100644 --- a/mallinkService/src/main/java/com/simple/service/impl/WxShopServiceImpl.java +++ b/mallinkService/src/main/java/com/simple/service/impl/WxShopServiceImpl.java @@ -30,15 +30,14 @@ public class WxShopServiceImpl implements WxShopService { @Override public void saveOrUpdate(WxShop record) { - List 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()); diff --git a/mallinkService/src/main/resources/mapper/WxMerchantMapper.xml b/mallinkService/src/main/resources/mapper/WxMerchantMapper.xml index 4a75e1787..0f4808105 100644 --- a/mallinkService/src/main/resources/mapper/WxMerchantMapper.xml +++ b/mallinkService/src/main/resources/mapper/WxMerchantMapper.xml @@ -14,10 +14,12 @@ + + - `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` @@ -81,7 +83,13 @@ and `car_params` like concat('%', #{carParams},'%') - + + + + + and `status` = #{status} + + and id in