| @@ -189,41 +189,53 @@ public class WxMerchantServiceImpl implements WxMerchantService { | |||||
| @Override | @Override | ||||
| public ResultData addMerchant(WxMerchant wxMerchant) { | public ResultData addMerchant(WxMerchant wxMerchant) { | ||||
| try { | try { | ||||
| final IdWorker idWorker = IdWorker.get(); | 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(); | List<Long> shopidlist = wxMerchant.getShopids(); | ||||
| for (Long shopid : shopidlist) { | for (Long shopid : shopidlist) { | ||||
| WxMerchantShop wxMerchantShop = new WxMerchantShop(); | WxMerchantShop wxMerchantShop = new WxMerchantShop(); | ||||
| wxMerchantShop.setId(idWorker.nextId()); | wxMerchantShop.setId(idWorker.nextId()); | ||||
| wxMerchantShop.setMerchantId(merchantid); | |||||
| wxMerchantShop.setMerchantId(merchantId); | |||||
| wxMerchantShop.setShopId(shopid); | wxMerchantShop.setShopId(shopid); | ||||
| wxMerchantShop.setTenantId(wxMerchant.getTenantId()); | wxMerchantShop.setTenantId(wxMerchant.getTenantId()); | ||||
| Date shopdate = new Date(); | Date shopdate = new Date(); | ||||
| wxMerchantShop.setUpdateDate(shopdate); | wxMerchantShop.setUpdateDate(shopdate); | ||||
| wxMerchantShop.setCreateDate(shopdate); | wxMerchantShop.setCreateDate(shopdate); | ||||
| wxMerchantShop.setIsDel(EnumDelStatus.NOT_DEL.getCode()); | wxMerchantShop.setIsDel(EnumDelStatus.NOT_DEL.getCode()); | ||||
| wxMerchantShopMapper.insertSelective(wxMerchantShop); | |||||
| //更新商铺状态 | //更新商铺状态 | ||||
| WxShop wxShop = new WxShop(); | WxShop wxShop = new WxShop(); | ||||
| wxShop.setId(shopid); | 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); | 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) { | if (wxMerchant.getRentContractId() != null) { | ||||
| WxRentContract wxRentContract = wxRentContractMapper.selectByPrimaryKey(wxMerchant.getRentContractId()); | WxRentContract wxRentContract = wxRentContractMapper.selectByPrimaryKey(wxMerchant.getRentContractId()); | ||||
| if (wxRentContract == null) { | if (wxRentContract == null) { | ||||
| return new ResultData(ErrorCode.RENT_CONTRACT_IS_NOT_FOUND); | 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.setUpdatetime(new Date()); | ||||
| wxRentContract.setStatus(EnumRentContractStatus.SIGNED_RENT_UNPAID.getCode()); | wxRentContract.setStatus(EnumRentContractStatus.SIGNED_RENT_UNPAID.getCode()); | ||||
| wxRentContractMapper.updateByPrimaryKeySelective(wxRentContract); | wxRentContractMapper.updateByPrimaryKeySelective(wxRentContract); | ||||
| @@ -232,7 +244,7 @@ public class WxMerchantServiceImpl implements WxMerchantService { | |||||
| //创建押金 | //创建押金 | ||||
| buildDeposit(wxMerchant); | buildDeposit(wxMerchant); | ||||
| } | } | ||||
| return new ResultData(Result.SUCCESS, "商户创建成功", merchantid); | |||||
| return new ResultData(Result.SUCCESS, "商户创建成功", merchantId); | |||||
| } catch (Exception e) { | } catch (Exception e) { | ||||
| logger.error("db failed: 商户创建失败, e:" + e.getMessage()); | logger.error("db failed: 商户创建失败, e:" + e.getMessage()); | ||||
| throw new MallinkException(ErrorCode.DB_FAIL.getCode(), "DB FAILD " + 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) { | if (wxMerchant.getId() == null) { | ||||
| return new ResultData(ErrorCode.MERCHANT_INFO_NOT_FOUND); | 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(); | WxMerchantShop wxMerchantShopQuery = new WxMerchantShop(); | ||||
| wxMerchantShopQuery.setTenantId(wxMerchant.getTenantId()); | 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); | List<WxMerchantShop> wxMerchantShopList = wxMerchantShopMapper.findList(wxMerchantShopQuery); | ||||
| for (WxMerchantShop merchantShop : wxMerchantShopList) { | for (WxMerchantShop merchantShop : wxMerchantShopList) { | ||||
| merchantShop.setIsDel(EnumDelStatus.DEL.getCode()); | merchantShop.setIsDel(EnumDelStatus.DEL.getCode()); | ||||
| @@ -265,7 +273,6 @@ public class WxMerchantServiceImpl implements WxMerchantService { | |||||
| //更新商铺状态 | //更新商铺状态 | ||||
| WxShop wxShop = new WxShop(); | WxShop wxShop = new WxShop(); | ||||
| wxShop.setId(merchantShop.getShopId()); | wxShop.setId(merchantShop.getShopId()); | ||||
| //未出租 | |||||
| wxShop.setStatus(EnumShopStatus.NOT_RENT.getCode()); | wxShop.setStatus(EnumShopStatus.NOT_RENT.getCode()); | ||||
| wxShopMapper.updateByPrimaryKeySelective(wxShop); | wxShopMapper.updateByPrimaryKeySelective(wxShop); | ||||
| } | } | ||||
| @@ -274,23 +281,39 @@ public class WxMerchantServiceImpl implements WxMerchantService { | |||||
| List<Long> shopidlist = wxMerchant.getShopids(); | List<Long> shopidlist = wxMerchant.getShopids(); | ||||
| for (Long shopid : shopidlist) { | for (Long shopid : shopidlist) { | ||||
| WxMerchantShop wxMerchantShop = new WxMerchantShop(); | 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.setId(idWorker.nextId()); | ||||
| wxMerchantShop.setMerchantId(wxMerchant.getId()); | wxMerchantShop.setMerchantId(wxMerchant.getId()); | ||||
| wxMerchantShop.setShopId(shopid); | |||||
| wxMerchantShop.setTenantId(wxMerchant.getTenantId()); | |||||
| Date shopdate = new Date(); | Date shopdate = new Date(); | ||||
| wxMerchantShop.setUpdateDate(shopdate); | wxMerchantShop.setUpdateDate(shopdate); | ||||
| wxMerchantShop.setCreateDate(shopdate); | wxMerchantShop.setCreateDate(shopdate); | ||||
| wxMerchantShop.setRentalStartDate(wxMerchant.getRentalStartDate()); | wxMerchantShop.setRentalStartDate(wxMerchant.getRentalStartDate()); | ||||
| wxMerchantShop.setRentalEndDate(wxMerchant.getRentalEndDate()); | wxMerchantShop.setRentalEndDate(wxMerchant.getRentalEndDate()); | ||||
| wxMerchantShop.setIsDel(EnumDelStatus.NOT_DEL.getCode()); | |||||
| wxMerchantShopMapper.insertSelective(wxMerchantShop); | |||||
| //更新商铺状态 | //更新商铺状态 | ||||
| WxShop wxShop = new WxShop(); | WxShop wxShop = new WxShop(); | ||||
| wxShop.setId(shopid); | wxShop.setId(shopid); | ||||
| wxShop.setStatus(EnumShopStatus.RENT.getCode()); | wxShop.setStatus(EnumShopStatus.RENT.getCode()); | ||||
| wxMerchantShopMapper.insertSelective(wxMerchantShop); | |||||
| wxShopMapper.updateByPrimaryKeySelective(wxShop); | wxShopMapper.updateByPrimaryKeySelective(wxShop); | ||||
| } | } | ||||
| //更新商户 | |||||
| Date date = new Date(); | |||||
| wxMerchant.setUpdateDate(date); | |||||
| wxMerchantMapper.updateByPrimaryKeySelective(wxMerchant); | |||||
| return new ResultData(Result.SUCCESS, "商户更新成功"); | return new ResultData(Result.SUCCESS, "商户更新成功"); | ||||
| } catch (Exception e) { | } catch (Exception e) { | ||||
| logger.error("db failed: 商户更新失败, e:" + e.getMessage()); | logger.error("db failed: 商户更新失败, e:" + e.getMessage()); | ||||