|
|
|
@@ -197,18 +197,17 @@ public class WxMerchantServiceImpl implements WxMerchantService { |
|
|
|
long merchantId = idWorker.nextId(); |
|
|
|
//保存商户商铺的关联 |
|
|
|
List<Long> shopidlist = wxMerchant.getShopids(); |
|
|
|
for (Long shopid : shopidlist) { |
|
|
|
if(null!=shopidlist && !shopidlist.isEmpty()){ |
|
|
|
Long shopid = shopidlist.get(0); |
|
|
|
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.setIsDel(EnumDelStatus.NOT_DEL.getCode()); |
|
|
|
long count = wxMerchantShopMapper.findList(wxMerchantShop).size(); |
|
|
|
if(count>0){ |
|
|
|
return new ResultData(ErrorCode.SHOP_IS_RENT); |
|
|
|
} |
|
|
|
//更新商铺状态 |
|
|
|
WxShop wxShop = new WxShop(); |
|
|
|
wxShop.setTenantId(wxMerchant.getTenantId()); |
|
|
|
wxShop.setId(shopid); |
|
|
|
//已出租 |
|
|
|
WxShop shop = wxShopMapper.selectByPrimaryKey(shopid); |
|
|
|
@@ -218,11 +217,17 @@ public class WxMerchantServiceImpl implements WxMerchantService { |
|
|
|
if (shop.getStatus().equals(EnumShopStatus.RENT.getCode())) { |
|
|
|
return new ResultData(ErrorCode.SHOP_IS_RENT); |
|
|
|
} |
|
|
|
wxMerchantShop.setId(idWorker.nextId()); |
|
|
|
wxMerchantShop.setMerchantId(merchantId); |
|
|
|
wxMerchantShop.setTenantId(wxMerchant.getTenantId()); |
|
|
|
Date shopdate = new Date(); |
|
|
|
wxMerchantShop.setUpdateDate(shopdate); |
|
|
|
wxMerchantShop.setCreateDate(shopdate); |
|
|
|
wxMerchantShopMapper.insertSelective(wxMerchantShop); |
|
|
|
wxShop.setStatus(EnumShopStatus.RENT.getCode()); |
|
|
|
wxShopMapper.updateByPrimaryKeySelective(wxShop); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
wxMerchant.setId(merchantId); |
|
|
|
Date date = new Date(); |
|
|
|
wxMerchant.setStatus(EnumMerchantStatus.VALID.getCode()); |
|
|
|
@@ -288,7 +293,7 @@ public class WxMerchantServiceImpl implements WxMerchantService { |
|
|
|
wxMerchantShop.setTenantId(wxMerchant.getTenantId()); |
|
|
|
wxMerchantShop.setShopId(shopid); |
|
|
|
wxMerchantShop.setIsDel(EnumDelStatus.NOT_DEL.getCode()); |
|
|
|
long count = wxMerchantShopMapper.findList(wxMerchantShop).stream().filter(ms -> !ms.getMerchantId().equals(wxMerchant.getId())).count(); |
|
|
|
long count = wxMerchantShopMapper.findList(wxMerchantShop).size(); |
|
|
|
if(count>0){ |
|
|
|
return new ResultData(ErrorCode.SHOP_IS_RENT); |
|
|
|
} |
|
|
|
@@ -410,193 +415,6 @@ public class WxMerchantServiceImpl implements WxMerchantService { |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Transactional(rollbackFor = {Exception.class}) |
|
|
|
@Override |
|
|
|
public void saveOrUpdate(WxMerchant wxMerchant) { |
|
|
|
|
|
|
|
WxAppinfo wxAppinfo = new WxAppinfo(); |
|
|
|
wxAppinfo.setTenantId(wxMerchant.getTenantId()); |
|
|
|
wxAppinfo.setType(EnumAppType.B.getCode()); |
|
|
|
wxAppinfo = wxAppinfoMapper.findList(wxAppinfo).get(0); |
|
|
|
|
|
|
|
final IdWorker idWorker = IdWorker.get(); |
|
|
|
|
|
|
|
if (wxMerchant.getId() == null) { |
|
|
|
long merchantid = idWorker.nextId(); |
|
|
|
wxMerchant.setId(merchantid); |
|
|
|
Date date = new Date(); |
|
|
|
wxMerchant.setStatus(EnumMerchantStatus.VALID.getCode()); |
|
|
|
wxMerchant.setUpdateDate(date); |
|
|
|
wxMerchant.setCreateDate(date); |
|
|
|
wxMerchantMapper.insertSelective(wxMerchant); |
|
|
|
|
|
|
|
//保存商户商铺的关联 |
|
|
|
List<Long> shopidlist = wxMerchant.getShopids(); |
|
|
|
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.setIsDel(EnumDelStatus.NOT_DEL.getCode()); |
|
|
|
wxMerchantShopMapper.insertSelective(wxMerchantShop); |
|
|
|
|
|
|
|
//更新商铺状态 |
|
|
|
WxShop wxShop = new WxShop(); |
|
|
|
wxShop.setId(shopid); |
|
|
|
//已出租 |
|
|
|
wxShop.setStatus(EnumShopStatus.RENT.getCode()); |
|
|
|
wxShopMapper.updateByPrimaryKeySelective(wxShop); |
|
|
|
} |
|
|
|
|
|
|
|
List<WxMerchantBUser> bUsers = wxMerchant.getbUsers(); |
|
|
|
|
|
|
|
//保存商户关联用户 |
|
|
|
for (WxMerchantBUser user : bUsers) { |
|
|
|
long id = idWorker.nextId(); |
|
|
|
user.setId(id); |
|
|
|
user.setbUserId(id); |
|
|
|
user.setMerchantId(merchantid); |
|
|
|
user.setTenantId(wxMerchant.getTenantId()); |
|
|
|
user.setAppId(wxAppinfo.getAppId()); |
|
|
|
date = new Date(); |
|
|
|
user.setCreateDate(date); |
|
|
|
user.setUpdateDate(date); |
|
|
|
user.setStatus(EnumMerchantBUserStatus.VALID.getCode()); |
|
|
|
wxMerchantBUserMapper.insertSelective(user); |
|
|
|
|
|
|
|
} //添加商户的分账账户(不是必选) |
|
|
|
if (wxMerchant.getAccountId() != null && wxMerchant.getAccountName() != null) { |
|
|
|
WxProfitSharingReceiver receiver = new WxProfitSharingReceiver(); |
|
|
|
receiver.setReceiverAccount(wxMerchant.getAccountId()); |
|
|
|
receiver.setReceiverComments(wxMerchant.getName()); |
|
|
|
receiver.setReceiverType(wxMerchant.getAccountTypeValue()); |
|
|
|
receiver.setTrueName(wxMerchant.getAccountName()); |
|
|
|
wxProfitSharingReceiverService.addReceiver(wxMerchant, receiver); |
|
|
|
} |
|
|
|
|
|
|
|
//关联合同 |
|
|
|
if (wxMerchant.getRentContractId() != null) { |
|
|
|
WxRentContract wxRentContract = wxRentContractMapper.selectByPrimaryKey(wxMerchant.getRentContractId()); |
|
|
|
wxRentContract.setMerchantId(merchantid); |
|
|
|
wxRentContract.setUpdatetime(new Date()); |
|
|
|
wxRentContract.setStatus(EnumRentContractStatus.SIGNED_RENT_UNPAID.getCode()); |
|
|
|
wxRentContractMapper.updateByPrimaryKeySelective(wxRentContract); |
|
|
|
//创建账单 |
|
|
|
buildRent(wxMerchant); |
|
|
|
//创建押金 |
|
|
|
buildDeposit(wxMerchant); |
|
|
|
} |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
//更新商户 |
|
|
|
Date date = new Date(); |
|
|
|
wxMerchant.setUpdateDate(date); |
|
|
|
wxMerchantMapper.updateByPrimaryKeySelective(wxMerchant); |
|
|
|
|
|
|
|
WxShop wxShopP = new WxShop(); |
|
|
|
wxShopP.setId(wxMerchant.getShopids().get(0)); |
|
|
|
|
|
|
|
//删除当前商户关联的所有商铺然后再插入 |
|
|
|
WxMerchantShop wxMerchantShopQuery = new WxMerchantShop(); |
|
|
|
wxMerchantShopQuery.setTenantId(wxMerchant.getTenantId()); |
|
|
|
wxMerchantShopQuery.setMerchantId(wxMerchant.getId()); |
|
|
|
List<WxMerchantShop> wxMerchantShopList = wxMerchantShopMapper.findList(wxMerchantShopQuery); |
|
|
|
for (WxMerchantShop merchantShop : wxMerchantShopList) { |
|
|
|
merchantShop.setIsDel(EnumDelStatus.DEL.getCode()); |
|
|
|
wxMerchantShopMapper.updateByPrimaryKeySelective(merchantShop); |
|
|
|
|
|
|
|
//更新商铺状态 |
|
|
|
WxShop wxShop = new WxShop(); |
|
|
|
wxShop.setId(merchantShop.getShopId()); |
|
|
|
//未出租 |
|
|
|
wxShop.setStatus(EnumShopStatus.NOT_RENT.getCode()); |
|
|
|
wxShopMapper.updateByPrimaryKeySelective(wxShop); |
|
|
|
} |
|
|
|
|
|
|
|
//保存商户商铺的关联 |
|
|
|
List<Long> shopidlist = wxMerchant.getShopids(); |
|
|
|
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.setRentalStartDate(wxMerchant.getRentalStartDate()); |
|
|
|
wxMerchantShop.setRentalEndDate(wxMerchant.getRentalEndDate()); |
|
|
|
wxMerchantShop.setIsDel(EnumDelStatus.NOT_DEL.getCode()); |
|
|
|
wxMerchantShopMapper.insertSelective(wxMerchantShop); |
|
|
|
|
|
|
|
//更新商铺状态 |
|
|
|
WxShop wxShop = new WxShop(); |
|
|
|
wxShop.setId(shopid); |
|
|
|
wxShop.setStatus(EnumShopStatus.RENT.getCode());//已出租 |
|
|
|
wxShopMapper.updateByPrimaryKeySelective(wxShop); |
|
|
|
} |
|
|
|
|
|
|
|
List<WxMerchantBUser> bUsers = wxMerchant.getbUsers(); |
|
|
|
|
|
|
|
//删除之前的关联用户 |
|
|
|
WxMerchantBUser bUser = new WxMerchantBUser(); |
|
|
|
bUser.setMerchantId(wxMerchant.getId()); |
|
|
|
List<WxMerchantBUser> wxMerchantBUserMapperList = wxMerchantBUserMapper.findList(bUser); |
|
|
|
for (WxMerchantBUser wxMerchantBUser : wxMerchantBUserMapperList) { |
|
|
|
wxMerchantBUser.setStatus(EnumMerchantBUserStatus.INVALID.getCode()); |
|
|
|
wxMerchantBUserMapper.updateByPrimaryKeySelective(wxMerchantBUser); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
//保存商户关联用户 |
|
|
|
for (WxMerchantBUser user : bUsers) { |
|
|
|
if (user.getId() == null) {//没有id的新增 |
|
|
|
long id = idWorker.nextId(); |
|
|
|
user.setId(id); |
|
|
|
user.setbUserId(id); |
|
|
|
user.setMerchantId(wxMerchant.getId()); |
|
|
|
user.setTenantId(wxMerchant.getTenantId()); |
|
|
|
user.setAppId(wxAppinfo.getAppId()); |
|
|
|
date = new Date(); |
|
|
|
user.setCreateDate(date); |
|
|
|
user.setUpdateDate(date); |
|
|
|
user.setStatus(EnumMerchantBUserStatus.VALID.getCode()); |
|
|
|
wxMerchantBUserMapper.insertSelective(user); |
|
|
|
} else {//有id的更新 |
|
|
|
user.setbUserId(user.getId()); |
|
|
|
user.setMerchantId(wxMerchant.getId()); |
|
|
|
user.setTenantId(wxMerchant.getTenantId()); |
|
|
|
user.setAppId(wxAppinfo.getAppId()); |
|
|
|
date = new Date(); |
|
|
|
user.setUpdateDate(date); |
|
|
|
user.setStatus(EnumMerchantBUserStatus.VALID.getCode()); |
|
|
|
wxMerchantBUserMapper.updateByPrimaryKeySelective(user); |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
//添加商户的分账账户(不是必选) |
|
|
|
if (wxMerchant.getAccountId() != null && wxMerchant.getAccountName() != null |
|
|
|
&& !wxMerchant.getAccountId().isEmpty() && !wxMerchant.getAccountName().isEmpty()) { |
|
|
|
WxProfitSharingReceiver receiver = new WxProfitSharingReceiver(); |
|
|
|
receiver.setReceiverAccount(wxMerchant.getAccountId()); |
|
|
|
receiver.setReceiverComments(wxMerchant.getName()); |
|
|
|
receiver.setReceiverType(wxMerchant.getAccountTypeValue()); |
|
|
|
receiver.setTrueName(wxMerchant.getAccountName()); |
|
|
|
wxProfitSharingReceiverService.updateReceiver(wxMerchant, receiver); |
|
|
|
} else { |
|
|
|
wxProfitSharingReceiverService.delReceiver(wxMerchant); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
@Transactional(rollbackFor = {Exception.class}) |
|
|
|
public void buildDeposit(WxMerchant wxMerchant) { |
|
|
|
MallUserInfo user = (MallUserInfo) SecurityUtils.getSubject().getSession().getAttribute("userSession"); |
|
|
|
|