|
|
@ -3,22 +3,29 @@ package com.epmet.modules.partymember.service.impl; |
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
|
|
|
import com.baomidou.mybatisplus.core.metadata.IPage; |
|
|
|
import com.epmet.commons.mybatis.service.impl.BaseServiceImpl; |
|
|
|
import com.epmet.commons.tools.exception.RenException; |
|
|
|
import com.epmet.commons.tools.page.PageData; |
|
|
|
import com.epmet.commons.tools.utils.ConvertUtils; |
|
|
|
import com.epmet.commons.tools.constant.FieldConstant; |
|
|
|
import com.epmet.commons.tools.utils.Result; |
|
|
|
import com.epmet.modules.partymember.dao.IcPartyMemberPayRecordDao; |
|
|
|
import com.epmet.modules.partymember.dao.IcPartyMemberPayRecordDetailDao; |
|
|
|
import com.epmet.modules.partymember.entity.IcPartyMemberPayRecordDetailEntity; |
|
|
|
import com.epmet.modules.partymember.entity.IcPartyMemberPayRecordEntity; |
|
|
|
import com.epmet.modules.partymember.redis.IcPartyMemberPayRecordRedis; |
|
|
|
import com.epmet.modules.partymember.service.IcPartyMemberPayRecordDetailService; |
|
|
|
import com.epmet.modules.partymember.service.IcPartyMemberPayRecordService; |
|
|
|
import com.epmet.resi.partymember.dto.partymember.IcPartyMemberPayRecordDTO; |
|
|
|
import com.epmet.resi.partymember.dto.partymember.IcPartyMemberPayRecordDetailDTO; |
|
|
|
import org.apache.commons.lang3.StringUtils; |
|
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
|
import org.springframework.stereotype.Service; |
|
|
|
import org.springframework.transaction.annotation.Transactional; |
|
|
|
|
|
|
|
import java.util.Arrays; |
|
|
|
import java.util.List; |
|
|
|
import java.util.Map; |
|
|
|
import java.math.BigDecimal; |
|
|
|
import java.text.ParseException; |
|
|
|
import java.text.SimpleDateFormat; |
|
|
|
import java.util.*; |
|
|
|
|
|
|
|
/** |
|
|
|
* 党员缴费记录表 |
|
|
@ -32,6 +39,12 @@ public class IcPartyMemberPayRecordServiceImpl extends BaseServiceImpl<IcPartyMe |
|
|
|
@Autowired |
|
|
|
private IcPartyMemberPayRecordRedis icPartyMemberPayRecordRedis; |
|
|
|
|
|
|
|
@Autowired |
|
|
|
private IcPartyMemberPayRecordDetailService icPartyMemberPayRecordDetailService; |
|
|
|
|
|
|
|
@Autowired |
|
|
|
private IcPartyMemberPayRecordDetailDao icPartyMemberPayRecordDetailDao; |
|
|
|
|
|
|
|
@Override |
|
|
|
public PageData<IcPartyMemberPayRecordDTO> page(Map<String, Object> params) { |
|
|
|
IPage<IcPartyMemberPayRecordEntity> page = baseDao.selectPage( |
|
|
@ -41,6 +54,23 @@ public class IcPartyMemberPayRecordServiceImpl extends BaseServiceImpl<IcPartyMe |
|
|
|
return getPageData(page, IcPartyMemberPayRecordDTO.class); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 条件查询 |
|
|
|
* @param params |
|
|
|
* @return |
|
|
|
*/ |
|
|
|
@Override |
|
|
|
public PageData<IcPartyMemberPayRecordDTO> getPhrasePage(Map<String, Object> params) { |
|
|
|
String partyMemberId = params.get("partyMemberId") == null ? "" : params.get("partyMemberId").toString(); |
|
|
|
if(StringUtils.isBlank(partyMemberId)){ |
|
|
|
throw new RenException("党员ID不能为空"); |
|
|
|
} |
|
|
|
IPage<IcPartyMemberPayRecordDTO> page = getPage(params); |
|
|
|
List<IcPartyMemberPayRecordDTO> list = baseDao.selectListInfo(params); |
|
|
|
return new PageData<>(list, page.getTotal()); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
public List<IcPartyMemberPayRecordDTO> list(Map<String, Object> params) { |
|
|
|
List<IcPartyMemberPayRecordEntity> entityList = baseDao.selectList(getWrapper(params)); |
|
|
@ -65,16 +95,50 @@ public class IcPartyMemberPayRecordServiceImpl extends BaseServiceImpl<IcPartyMe |
|
|
|
|
|
|
|
@Override |
|
|
|
@Transactional(rollbackFor = Exception.class) |
|
|
|
public void save(IcPartyMemberPayRecordDTO dto) { |
|
|
|
public Result save(IcPartyMemberPayRecordDTO dto) { |
|
|
|
// 根据起始时间转月份列表
|
|
|
|
List<String> monthList = getMonthList(dto.getStartDate(),dto.getEndDate()); |
|
|
|
|
|
|
|
// 校验是否有月份已缴费
|
|
|
|
List<IcPartyMemberPayRecordDetailDTO> payedList = icPartyMemberPayRecordDetailDao.getpayedList(monthList,dto.getPartyMemberId(),""); |
|
|
|
if(payedList.size() > 0){ |
|
|
|
return new Result().error("存在已缴费月份,请重新录入"); |
|
|
|
} |
|
|
|
|
|
|
|
// 保存党员缴费记录表信息
|
|
|
|
IcPartyMemberPayRecordEntity entity = ConvertUtils.sourceToTarget(dto, IcPartyMemberPayRecordEntity.class); |
|
|
|
insert(entity); |
|
|
|
|
|
|
|
// 保存党员缴费记录明细
|
|
|
|
saveDetailInfo(monthList,entity); |
|
|
|
|
|
|
|
return new Result(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
@Transactional(rollbackFor = Exception.class) |
|
|
|
public void update(IcPartyMemberPayRecordDTO dto) { |
|
|
|
public Result update(IcPartyMemberPayRecordDTO dto) { |
|
|
|
// 根据起始时间转月份列表
|
|
|
|
List<String> monthList = getMonthList(dto.getStartDate(),dto.getEndDate()); |
|
|
|
|
|
|
|
// 校验本次修改是否有月份已缴费(除该主键下的月份)
|
|
|
|
List<IcPartyMemberPayRecordDetailDTO> payedList = icPartyMemberPayRecordDetailDao.getpayedList(monthList,dto.getPartyMemberId(),dto.getId()); |
|
|
|
if(payedList.size() > 0){ |
|
|
|
return new Result().error("存在已缴费月份,请重新录入"); |
|
|
|
} |
|
|
|
|
|
|
|
// 更新党员缴费记录表信息
|
|
|
|
IcPartyMemberPayRecordEntity entity = ConvertUtils.sourceToTarget(dto, IcPartyMemberPayRecordEntity.class); |
|
|
|
updateById(entity); |
|
|
|
|
|
|
|
// 清空该记录表主键下的党员缴费记录明细
|
|
|
|
icPartyMemberPayRecordDetailDao.deletePayDetailByRecordId(dto.getId()); |
|
|
|
|
|
|
|
// 保存党员缴费记录明细
|
|
|
|
saveDetailInfo(monthList,entity); |
|
|
|
|
|
|
|
return new Result(); |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
@ -82,6 +146,67 @@ public class IcPartyMemberPayRecordServiceImpl extends BaseServiceImpl<IcPartyMe |
|
|
|
public void delete(String[] ids) { |
|
|
|
// 逻辑删除(@TableLogic 注解)
|
|
|
|
baseDao.deleteBatchIds(Arrays.asList(ids)); |
|
|
|
|
|
|
|
// 删除党员缴费记录明细
|
|
|
|
icPartyMemberPayRecordDetailDao.deletePayDetailByRecordId(ids[0]); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 根据起始时间获取该时间段所包含的所有月份,返回list |
|
|
|
* |
|
|
|
* @param startTime |
|
|
|
* @param endTime |
|
|
|
* @return |
|
|
|
*/ |
|
|
|
public List<String> getMonthList(String startTime, String endTime){ |
|
|
|
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM"); |
|
|
|
// 声明保存日期集合
|
|
|
|
List<String> list = new ArrayList<String>(); |
|
|
|
try { |
|
|
|
// 转化成日期类型
|
|
|
|
Date startDate = sdf.parse(startTime); |
|
|
|
Date endDate = sdf.parse(endTime); |
|
|
|
|
|
|
|
//用Calendar 进行日期比较判断
|
|
|
|
Calendar calendar = Calendar.getInstance(); |
|
|
|
while (startDate.getTime()<=endDate.getTime()){ |
|
|
|
// 把日期添加到集合
|
|
|
|
list.add(sdf.format(startDate)); |
|
|
|
// 设置日期
|
|
|
|
calendar.setTime(startDate); |
|
|
|
//把日期增加一天
|
|
|
|
calendar.add(Calendar.MONTH, 1); |
|
|
|
// 获取增加后的日期
|
|
|
|
startDate=calendar.getTime(); |
|
|
|
} |
|
|
|
} catch (ParseException e) { |
|
|
|
e.printStackTrace(); |
|
|
|
} |
|
|
|
return list; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
public void saveDetailInfo(List<String> monthList,IcPartyMemberPayRecordEntity entity){ |
|
|
|
// 组装党员缴费记录明细实体
|
|
|
|
BigDecimal money = entity.getMoney(); |
|
|
|
// 求本次缴费的月份平均缴费金额
|
|
|
|
BigDecimal moneyDivide = money.divide(new BigDecimal(monthList.size()),2,BigDecimal.ROUND_HALF_UP); |
|
|
|
List<IcPartyMemberPayRecordDetailEntity> detailList = new ArrayList<IcPartyMemberPayRecordDetailEntity>(); |
|
|
|
for(int i = 0 ; i < monthList.size() ; i++){ |
|
|
|
IcPartyMemberPayRecordDetailEntity detailEntity = new IcPartyMemberPayRecordDetailEntity(); |
|
|
|
detailEntity.setCustomerId(entity.getCustomerId()); |
|
|
|
detailEntity.setRecordId(entity.getId()); |
|
|
|
detailEntity.setMoney(moneyDivide); |
|
|
|
detailEntity.setPartyMemberId(entity.getPartyMemberId()); |
|
|
|
String year = monthList.get(i).substring(0,4); |
|
|
|
String month = monthList.get(i).substring(5,7); |
|
|
|
detailEntity.setYear(year); |
|
|
|
detailEntity.setMonth(month); |
|
|
|
detailList.add(detailEntity); |
|
|
|
} |
|
|
|
|
|
|
|
// 保存党员缴费记录明细表信息
|
|
|
|
icPartyMemberPayRecordDetailService.insertBatch(detailList); |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|