Просмотр исходного кода

[商户管理][修改][关联商铺时查询]

release_toaliyun_real
gongbiao 7 лет назад
Родитель
Сommit
1823747ac6
1 измененных файлов: 47 добавлений и 24 удалений
  1. +47
    -24
      mallinkService/src/main/java/com/iformall/service/impl/WxMerchantServiceImpl.java

+ 47
- 24
mallinkService/src/main/java/com/iformall/service/impl/WxMerchantServiceImpl.java Просмотреть файл

@@ -189,41 +189,53 @@ public class WxMerchantServiceImpl implements WxMerchantService {
@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);
long merchantId = idWorker.nextId();
//保存商户商铺的关联
List<Long> shopidlist = wxMerchant.getShopids();
for (Long shopid : shopidlist) {
WxMerchantShop wxMerchantShop = new WxMerchantShop();
wxMerchantShop.setId(idWorker.nextId());
wxMerchantShop.setMerchantId(merchantid);
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());
WxShop shop = wxShopMapper.selectByPrimaryKey(shopid);
if (shop == null) {
return new ResultData(ErrorCode.SHOP_IS_NOT_FOUND);
}
if (shop.getStatus().equals(EnumShopStatus.RENT.getCode())) {
return new ResultData(ErrorCode.SHOP_IS_RENT);
}
wxMerchantShopMapper.insertSelective(wxMerchantShop);
wxShopMapper.updateByPrimaryKeySelective(wxShop);

}
wxMerchant.setId(merchantId);
Date date = new Date();
wxMerchant.setStatus(EnumMerchantStatus.VALID.getCode());
wxMerchant.setUpdateDate(date);
wxMerchant.setCreateDate(date);
wxMerchantMapper.insertSelective(wxMerchant);

//关联合同
if (wxMerchant.getRentContractId() != null) {
WxRentContract wxRentContract = wxRentContractMapper.selectByPrimaryKey(wxMerchant.getRentContractId());
if (wxRentContract == null) {
return new ResultData(ErrorCode.RENT_CONTRACT_IS_NOT_FOUND);
}
wxRentContract.setMerchantId(merchantid);
if (wxRentContract.getStatus().equals(EnumRentContractStatus.CONTRACT_TERMINATE)) {
return new ResultData(ErrorCode.RENT_CONTRACT_IS_TERMINATED);
}
wxRentContract.setMerchantId(merchantId);
wxRentContract.setUpdatetime(new Date());
wxRentContract.setStatus(EnumRentContractStatus.SIGNED_RENT_UNPAID.getCode());
wxRentContractMapper.updateByPrimaryKeySelective(wxRentContract);
@@ -232,7 +244,7 @@ public class WxMerchantServiceImpl implements WxMerchantService {
//创建押金
buildDeposit(wxMerchant);
}
return new ResultData(Result.SUCCESS, "商户创建成功", merchantid);
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());
@@ -248,16 +260,12 @@ public class WxMerchantServiceImpl implements WxMerchantService {
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);
wxMerchantShopQuery.setMerchantId(wxMerchant.getId());
wxMerchantShopQuery.setIsDel(EnumDelStatus.NOT_DEL.getCode());
List<WxMerchantShop> wxMerchantShopList = wxMerchantShopMapper.findList(wxMerchantShopQuery);
for (WxMerchantShop merchantShop : wxMerchantShopList) {
merchantShop.setIsDel(EnumDelStatus.DEL.getCode());
@@ -265,7 +273,6 @@ public class WxMerchantServiceImpl implements WxMerchantService {
//更新商铺状态
WxShop wxShop = new WxShop();
wxShop.setId(merchantShop.getShopId());
//未出租
wxShop.setStatus(EnumShopStatus.NOT_RENT.getCode());
wxShopMapper.updateByPrimaryKeySelective(wxShop);
}
@@ -274,23 +281,39 @@ public class WxMerchantServiceImpl implements WxMerchantService {
List<Long> shopidlist = wxMerchant.getShopids();
for (Long shopid : shopidlist) {
WxMerchantShop wxMerchantShop = new WxMerchantShop();
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();
if(count>0){
return new ResultData(ErrorCode.SHOP_IS_RENT);
}

WxShop shop = wxShopMapper.selectByPrimaryKey(shopid);
if (shop == null) {
return new ResultData(ErrorCode.SHOP_IS_NOT_FOUND);
}
if (shop.getStatus().equals(EnumShopStatus.RENT.getCode())) {
return new ResultData(ErrorCode.SHOP_IS_RENT);
}
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());
wxMerchantShopMapper.insertSelective(wxMerchantShop);
wxShopMapper.updateByPrimaryKeySelective(wxShop);
}
//更新商户
Date date = new Date();
wxMerchant.setUpdateDate(date);
wxMerchantMapper.updateByPrimaryKeySelective(wxMerchant);
return new ResultData(Result.SUCCESS, "商户更新成功");
} catch (Exception e) {
logger.error("db failed: 商户更新失败, e:" + e.getMessage());


Загрузка…
Отмена
Сохранить