| @@ -6,18 +6,18 @@ import com.iformall.common.ErrorCode; | |||||
| import com.iformall.common.IdWorker; | import com.iformall.common.IdWorker; | ||||
| import com.iformall.common.Result; | import com.iformall.common.Result; | ||||
| import com.iformall.common.ResultData; | import com.iformall.common.ResultData; | ||||
| import com.iformall.domain.po.WxMerchant; | |||||
| import com.iformall.domain.po.WxRentContract; | |||||
| import com.iformall.domain.po.WxShop; | |||||
| import com.iformall.domain.po.*; | |||||
| import com.iformall.enums.EnumBillRentStatus; | |||||
| import com.iformall.enums.EnumRentContractStatus; | import com.iformall.enums.EnumRentContractStatus; | ||||
| import com.iformall.enums.EnumShopStatus; | import com.iformall.enums.EnumShopStatus; | ||||
| import com.iformall.exception.MallinkException; | import com.iformall.exception.MallinkException; | ||||
| import com.iformall.mapper.WxBillRentMapper; | |||||
| import com.iformall.mapper.WxRentContractMapper; | import com.iformall.mapper.WxRentContractMapper; | ||||
| import com.iformall.mapper.WxShopMapper; | import com.iformall.mapper.WxShopMapper; | ||||
| import com.iformall.service.WxMerchantService; | import com.iformall.service.WxMerchantService; | ||||
| import com.iformall.service.WxRentContractService; | import com.iformall.service.WxRentContractService; | ||||
| import com.iformall.utils.Constant; | import com.iformall.utils.Constant; | ||||
| import org.apache.commons.io.FileUtils; | |||||
| import org.apache.shiro.SecurityUtils; | |||||
| import org.slf4j.Logger; | import org.slf4j.Logger; | ||||
| import org.slf4j.LoggerFactory; | import org.slf4j.LoggerFactory; | ||||
| import org.springframework.beans.factory.annotation.Autowired; | import org.springframework.beans.factory.annotation.Autowired; | ||||
| @@ -31,8 +31,6 @@ import java.net.HttpURLConnection; | |||||
| import java.net.URL; | import java.net.URL; | ||||
| import java.util.*; | import java.util.*; | ||||
| import static org.springframework.core.io.buffer.DataBufferUtils.readInputStream; | |||||
| /** | /** | ||||
| * @author gongbiao | * @author gongbiao | ||||
| */ | */ | ||||
| @@ -49,6 +47,9 @@ public class WxRentContractServiceImpl implements WxRentContractService { | |||||
| @Autowired | @Autowired | ||||
| WxMerchantService wxMerchantService; | WxMerchantService wxMerchantService; | ||||
| @Autowired | |||||
| WxBillRentMapper wxBillRentMapper; | |||||
| @Override | @Override | ||||
| public Map<String, Object> listAsPage(WxRentContract record, Integer pageIndex, Integer pageSize) { | public Map<String, Object> listAsPage(WxRentContract record, Integer pageIndex, Integer pageSize) { | ||||
| Object rentContractStatusInfo = getRentContractStatusInfo(record.getTenantId()); | Object rentContractStatusInfo = getRentContractStatusInfo(record.getTenantId()); | ||||
| @@ -98,6 +99,12 @@ public class WxRentContractServiceImpl implements WxRentContractService { | |||||
| record.setUpdatetime(date); | record.setUpdatetime(date); | ||||
| try { | try { | ||||
| wxRentContractMapper.insertSelective(record); | wxRentContractMapper.insertSelective(record); | ||||
| if(record.getMerchantId()!=null){ | |||||
| WxMerchant wxMerchant = new WxMerchant(); | |||||
| wxMerchant.setId(record.getMerchantId()); | |||||
| wxMerchant.setTenantId(record.getTenantId()); | |||||
| buildRent(wxMerchant); | |||||
| } | |||||
| } catch (Exception e) { | } catch (Exception e) { | ||||
| logger.error("保存租赁合同信息失败,e:" + e.getMessage()); | logger.error("保存租赁合同信息失败,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()); | ||||
| @@ -116,6 +123,81 @@ public class WxRentContractServiceImpl implements WxRentContractService { | |||||
| } | } | ||||
| @Transactional(rollbackFor = {Exception.class}) | |||||
| public void buildRent(WxMerchant wxMerchant) { | |||||
| //获取用户 | |||||
| MallUserInfo user = (MallUserInfo) SecurityUtils.getSubject().getSession().getAttribute("userSession"); | |||||
| //根据商户ID找出合同 | |||||
| WxRentContract wxRentContract = new WxRentContract(); | |||||
| wxRentContract.setMerchantId(wxMerchant.getId()); | |||||
| List<WxRentContract> list = wxRentContractMapper.findList(wxRentContract); | |||||
| if (list.size() > 0) { | |||||
| wxRentContract = list.get(0); | |||||
| Integer receivePeriod = wxRentContract.getReceivePeriod(); | |||||
| int paycount = 12 / receivePeriod.intValue(); | |||||
| final IdWorker idWorker = IdWorker.get(); | |||||
| for (int i = 0; i < paycount; i++) { | |||||
| WxBillRent wxBillRent = new WxBillRent(); | |||||
| wxBillRent.setId(idWorker.nextId()); | |||||
| wxBillRent.setRentContractId(wxRentContract.getId()); | |||||
| wxBillRent.setReceivePay(0); | |||||
| wxBillRent.setPay(0); | |||||
| int needpay = wxRentContract.getPrice() * i; | |||||
| wxBillRent.setNeedPay(needpay); | |||||
| wxBillRent.setOwe(needpay); | |||||
| Date date = new Date(); | |||||
| Calendar instance = Calendar.getInstance(); | |||||
| instance.setTime(wxRentContract.getRentalStartDate()); | |||||
| instance.add(Calendar.MONTH, receivePeriod.intValue() * i); | |||||
| instance.add(Calendar.DAY_OF_MONTH, -1); | |||||
| Date time = instance.getTime(); | |||||
| wxBillRent.setReceiveDate(time); | |||||
| //截止收租日在当前时间之前 | |||||
| if (wxBillRent.getReceiveDate().before(date)) { | |||||
| long day = (time.getTime() - date.getTime()) / (24 * 60 * 60 * 1000); | |||||
| wxBillRent.setStatus(EnumBillRentStatus.NOT_PAID.getCode()); | |||||
| wxBillRent.setExpiredDay(day); | |||||
| wxBillRent.setReceiveDate(time); | |||||
| } else {//截止收租日在当前时间之后 | |||||
| Calendar now = Calendar.getInstance(); | |||||
| now.add(Calendar.MONTH, receivePeriod.intValue() * i); | |||||
| now.add(Calendar.DAY_OF_MONTH, -1); | |||||
| Date currenttime = now.getTime(); | |||||
| //当前日期加上周期后小于截止收租日就是没有到期,否则当前待缴 | |||||
| if(currenttime.before(wxBillRent.getReceiveDate())){ | |||||
| wxBillRent.setStatus(EnumBillRentStatus.NOT_EXPIRED.getCode()); | |||||
| wxBillRent.setExpiredDay(0L); | |||||
| wxBillRent.setReceiveDate(time); | |||||
| }else{ | |||||
| wxBillRent.setStatus(EnumBillRentStatus.WAIT_PAY.getCode()); | |||||
| wxBillRent.setExpiredDay(0L); | |||||
| wxBillRent.setReceiveDate(time); | |||||
| } | |||||
| } | |||||
| wxBillRent.setTenantId(wxMerchant.getTenantId()); | |||||
| wxBillRent.setIsDel(0); | |||||
| wxBillRent.setMerchantId(wxMerchant.getId()); | |||||
| wxBillRent.setUserId(user.getId()); | |||||
| wxBillRent.setShopId(wxRentContract.getShopId()); | |||||
| wxBillRent.setCreatetime(date); | |||||
| wxBillRent.setUpdatetime(date); | |||||
| try{ | |||||
| wxBillRentMapper.insertSelective(wxBillRent); | |||||
| }catch (Exception e){ | |||||
| logger.error("添加租赁账单失败,e:" + e.getMessage()); | |||||
| throw new MallinkException(ErrorCode.DB_FAIL.getCode(), "DB FAILD " + e.getMessage()); | |||||
| } | |||||
| } | |||||
| } | |||||
| } | |||||
| @Transactional(rollbackFor = {Exception.class}) | @Transactional(rollbackFor = {Exception.class}) | ||||
| @Override | @Override | ||||
| public ResultData deleteById(String id) { | public ResultData deleteById(String id) { | ||||