|
|
|
@@ -4,6 +4,8 @@ import com.github.pagehelper.PageHelper; |
|
|
|
import com.github.pagehelper.PageInfo; |
|
|
|
import com.iformall.common.ErrorCode; |
|
|
|
import com.iformall.common.IdWorker; |
|
|
|
import com.iformall.common.Result; |
|
|
|
import com.iformall.common.ResultData; |
|
|
|
import com.iformall.domain.po.*; |
|
|
|
import com.iformall.enums.*; |
|
|
|
import com.iformall.exception.MallinkException; |
|
|
|
@@ -65,7 +67,6 @@ public class WxMerchantServiceImpl implements WxMerchantService { |
|
|
|
public PageInfo<WxMerchant> listAsPage(WxMerchant record, Integer pageIndex, Integer pageSize) { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
WxRentContract wxRentContract = new WxRentContract(); |
|
|
|
wxRentContract.setTenantId(record.getTenantId()); |
|
|
|
List<WxRentContract> list = wxRentContractMapper.findList(wxRentContract); |
|
|
|
@@ -73,8 +74,8 @@ public class WxMerchantServiceImpl implements WxMerchantService { |
|
|
|
PageHelper.startPage(pageIndex, pageSize); |
|
|
|
List<WxMerchant> merchants = wxMerchantMapper.findList(record); |
|
|
|
for (WxMerchant merchant : merchants) { |
|
|
|
List<WxRentContract> collect = list.stream().filter(ms -> ms.getMerchantId()!=null && ms.getMerchantId().equals(merchant.getId()) |
|
|
|
&& !ms.getStatus().equals(EnumRentContractStatus.WAIT_SIGN.getCode()) |
|
|
|
List<WxRentContract> collect = list.stream().filter(ms -> ms.getMerchantId() != null && ms.getMerchantId().equals(merchant.getId()) |
|
|
|
&& !ms.getStatus().equals(EnumRentContractStatus.WAIT_SIGN.getCode()) |
|
|
|
&& !ms.getStatus().equals(EnumRentContractStatus.CONTRACT_TERMINATE.getCode())).collect(Collectors.toList()); |
|
|
|
if (collect != null && collect.size() > 0) { |
|
|
|
merchant.setRentalStartDate(collect.get(0).getRentalStartDate()); |
|
|
|
@@ -122,7 +123,7 @@ public class WxMerchantServiceImpl implements WxMerchantService { |
|
|
|
|
|
|
|
//分账信息 |
|
|
|
WxProfitSharingReceiver receiver = wxProfitSharingReceiverService.findReceiver(wxMerchant); |
|
|
|
if(receiver!=null){ |
|
|
|
if (receiver != null) { |
|
|
|
wxMerchant.setAccountId(receiver.getReceiverAccount()); |
|
|
|
wxMerchant.setAccountName(receiver.getTrueName()); |
|
|
|
wxMerchant.setAccountTypeValue(receiver.getReceiverType()); |
|
|
|
@@ -157,11 +158,10 @@ public class WxMerchantServiceImpl implements WxMerchantService { |
|
|
|
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());//未出租 |
|
|
|
wxShop.setStatus(EnumShopStatus.NOT_RENT.getCode()); |
|
|
|
wxShopMapper.updateByPrimaryKeySelective(wxShop); |
|
|
|
} |
|
|
|
|
|
|
|
@@ -185,6 +185,198 @@ public class WxMerchantServiceImpl implements WxMerchantService { |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
@Transactional(rollbackFor = {Exception.class}) |
|
|
|
@Override |
|
|
|
public ResultData addMerchant(WxMerchant wxMerchant) { |
|
|
|
try { |
|
|
|
final IdWorker idWorker = IdWorker.get(); |
|
|
|
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); |
|
|
|
} |
|
|
|
//关联合同 |
|
|
|
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(wxRentContract); |
|
|
|
//创建押金 |
|
|
|
buildDeposit(wxMerchant); |
|
|
|
} |
|
|
|
return new ResultData(Result.SUCCESS, "商户创建成功", merchantid); |
|
|
|
} catch (Exception e) { |
|
|
|
logger.error("db failed: 商户创建失败, e:" + e.getMessage()); |
|
|
|
throw new MallinkException(ErrorCode.DB_FAIL.getCode(), "DB FAILD " + e.getMessage()); |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
@Transactional(rollbackFor = {Exception.class}) |
|
|
|
@Override |
|
|
|
public ResultData updateMerchant(WxMerchant wxMerchant) { |
|
|
|
|
|
|
|
try { |
|
|
|
if (wxMerchant.getId() == null) { |
|
|
|
return new ResultData(ErrorCode.MERCHANT_INFO_NOT_FOUND); |
|
|
|
} |
|
|
|
//更新商户 |
|
|
|
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() != null ? wxMerchant.getId() : 0); |
|
|
|
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); |
|
|
|
} |
|
|
|
//保存商户商铺的关联 |
|
|
|
final IdWorker idWorker = IdWorker.get(); |
|
|
|
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); |
|
|
|
} |
|
|
|
return new ResultData(Result.SUCCESS, "商户更新成功"); |
|
|
|
} catch (Exception e) { |
|
|
|
logger.error("db failed: 商户更新失败, e:" + e.getMessage()); |
|
|
|
throw new MallinkException(ErrorCode.DB_FAIL.getCode(), "DB FAILD " + e.getMessage()); |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
@Transactional(rollbackFor = {Exception.class}) |
|
|
|
@Override |
|
|
|
public ResultData updateMerchantAccount(WxMerchant wxMerchant) { |
|
|
|
try { |
|
|
|
if (wxMerchant.getId() == null) { |
|
|
|
return new ResultData(ErrorCode.MERCHANT_INFO_NOT_FOUND); |
|
|
|
} |
|
|
|
//添加商户的分账账户(不是必选) |
|
|
|
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); |
|
|
|
} |
|
|
|
return new ResultData(Result.SUCCESS, "账户操作成功"); |
|
|
|
} catch (Exception e) { |
|
|
|
logger.error("db failed: 账户操作失败, e:" + e.getMessage()); |
|
|
|
throw new MallinkException(ErrorCode.DB_FAIL.getCode(), "DB FAILD " + e.getMessage()); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
@Transactional(rollbackFor = {Exception.class}) |
|
|
|
@Override |
|
|
|
public ResultData updateMerchantAdmin(WxMerchant wxMerchant) { |
|
|
|
try { |
|
|
|
if (wxMerchant.getId() == null) { |
|
|
|
return new ResultData(ErrorCode.MERCHANT_INFO_NOT_FOUND); |
|
|
|
} |
|
|
|
WxAppinfo wxAppinfo = new WxAppinfo(); |
|
|
|
wxAppinfo.setTenantId(wxMerchant.getTenantId()); |
|
|
|
wxAppinfo.setType(EnumAppType.B.getCode()); |
|
|
|
wxAppinfo = wxAppinfoMapper.findList(wxAppinfo).get(0); |
|
|
|
List<WxMerchantBUser> bUsers = wxMerchant.getbUsers(); |
|
|
|
|
|
|
|
//删除之前的关联用户 |
|
|
|
WxMerchantBUser bUser = new WxMerchantBUser(); |
|
|
|
bUser.setMerchantId(wxMerchant.getId() != null ? wxMerchant.getId() : 0); |
|
|
|
List<WxMerchantBUser> wxMerchantBUserMapperList = wxMerchantBUserMapper.findList(bUser); |
|
|
|
for (WxMerchantBUser wxMerchantBUser : wxMerchantBUserMapperList) { |
|
|
|
wxMerchantBUser.setStatus(EnumMerchantBUserStatus.INVALID.getCode()); |
|
|
|
wxMerchantBUserMapper.updateByPrimaryKeySelective(wxMerchantBUser); |
|
|
|
} |
|
|
|
final IdWorker idWorker = IdWorker.get(); |
|
|
|
//保存商户关联用户 |
|
|
|
for (WxMerchantBUser user : bUsers) { |
|
|
|
if (user.getId() == null) { |
|
|
|
long id = idWorker.nextId(); |
|
|
|
user.setId(id); |
|
|
|
user.setBUserId(id); |
|
|
|
user.setMerchantId(wxMerchant.getId()); |
|
|
|
user.setTenantId(wxMerchant.getTenantId()); |
|
|
|
user.setAppId(wxAppinfo.getAppId()); |
|
|
|
Date 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 date = new Date(); |
|
|
|
user.setUpdateDate(date); |
|
|
|
user.setStatus(EnumMerchantBUserStatus.VALID.getCode()); |
|
|
|
wxMerchantBUserMapper.updateByPrimaryKeySelective(user); |
|
|
|
} |
|
|
|
} |
|
|
|
return new ResultData(Result.SUCCESS, "账号操作成功"); |
|
|
|
} catch (Exception e) { |
|
|
|
logger.error("db failed: 账号操作失败, e:" + e.getMessage()); |
|
|
|
throw new MallinkException(ErrorCode.DB_FAIL.getCode(), "DB FAILD " + e.getMessage()); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Transactional(rollbackFor = {Exception.class}) |
|
|
|
@Override |
|
|
|
public void saveOrUpdate(WxMerchant wxMerchant) { |
|
|
|
@@ -217,8 +409,6 @@ public class WxMerchantServiceImpl implements WxMerchantService { |
|
|
|
wxMerchantShop.setUpdateDate(shopdate); |
|
|
|
wxMerchantShop.setCreateDate(shopdate); |
|
|
|
wxMerchantShop.setIsDel(EnumDelStatus.NOT_DEL.getCode()); |
|
|
|
//wxMerchantShop.setRentalStartDate(wxMerchant.getRentalStartDate()); |
|
|
|
//wxMerchantShop.setRentalEndDate(wxMerchant.getRentalEndDate()); |
|
|
|
wxMerchantShopMapper.insertSelective(wxMerchantShop); |
|
|
|
|
|
|
|
//更新商铺状态 |
|
|
|
@@ -256,7 +446,7 @@ public class WxMerchantServiceImpl implements WxMerchantService { |
|
|
|
} |
|
|
|
|
|
|
|
//关联合同 |
|
|
|
if(wxMerchant.getRentContractId()!=null){ |
|
|
|
if (wxMerchant.getRentContractId() != null) { |
|
|
|
WxRentContract wxRentContract = wxRentContractMapper.selectByPrimaryKey(wxMerchant.getRentContractId()); |
|
|
|
wxRentContract.setMerchantId(merchantid); |
|
|
|
wxRentContract.setUpdatetime(new Date()); |
|
|
|
@@ -468,11 +658,11 @@ public class WxMerchantServiceImpl implements WxMerchantService { |
|
|
|
now.add(Calendar.MONTH, receivePeriod.intValue()); |
|
|
|
Date currenttime = now.getTime(); |
|
|
|
//当前日期加上周期后小于截止收租日就是没有到期,否则当前待缴 |
|
|
|
if(currenttime.before(wxBillRent.getReceiveDate())){ |
|
|
|
if (currenttime.before(wxBillRent.getReceiveDate())) { |
|
|
|
wxBillRent.setStatus(EnumBillRentStatus.NOT_EXPIRED.getCode()); |
|
|
|
wxBillRent.setExpiredDay(0L); |
|
|
|
wxBillRent.setReceiveDate(time); |
|
|
|
}else{ |
|
|
|
} else { |
|
|
|
wxBillRent.setStatus(EnumBillRentStatus.WAIT_PAY.getCode()); |
|
|
|
wxBillRent.setExpiredDay(0L); |
|
|
|
wxBillRent.setReceiveDate(time); |
|
|
|
@@ -486,9 +676,9 @@ public class WxMerchantServiceImpl implements WxMerchantService { |
|
|
|
wxBillRent.setShopId(wxRentContract.getShopId()); |
|
|
|
wxBillRent.setCreatetime(date); |
|
|
|
wxBillRent.setUpdatetime(date); |
|
|
|
try{ |
|
|
|
try { |
|
|
|
wxBillRentMapper.insertSelective(wxBillRent); |
|
|
|
}catch (Exception e){ |
|
|
|
} catch (Exception e) { |
|
|
|
logger.error("添加租赁账单失败,e:" + e.getMessage()); |
|
|
|
throw new MallinkException(ErrorCode.DB_FAIL.getCode(), "DB FAILD " + e.getMessage()); |
|
|
|
} |
|
|
|
|