|
@@ -1,11 +1,34 @@
|
|
|
package com.winhc.repal.service.impl;
|
|
|
|
|
|
+import cn.hutool.core.collection.CollUtil;
|
|
|
+import cn.hutool.core.util.ObjectUtil;
|
|
|
+import cn.hutool.core.util.StrUtil;
|
|
|
+import com.alibaba.fastjson.JSON;
|
|
|
+import com.winhc.common.enums.CodeMsg;
|
|
|
+import com.winhc.common.exception.CommonException;
|
|
|
+import com.winhc.repal.entity.RepalBill;
|
|
|
import com.winhc.repal.entity.RepalDynamic;
|
|
|
+import com.winhc.repal.enums.*;
|
|
|
+import com.winhc.repal.model.bo.UserContextBO;
|
|
|
+import com.winhc.repal.model.dto.DynamicContentDTO;
|
|
|
+import com.winhc.repal.model.dto.RepalSmsDTO;
|
|
|
+import com.winhc.repal.model.vo.RepalLinkVO;
|
|
|
+import com.winhc.repal.model.vo.RepalSmsTemplateVO;
|
|
|
import com.winhc.repal.repository.RepalDynamicMapper;
|
|
|
+import com.winhc.repal.service.MessageNoticeService;
|
|
|
+import com.winhc.repal.service.RepalBillService;
|
|
|
import com.winhc.repal.service.RepalDynamicService;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
+import com.winhc.repal.service.RepalRolePermissionService;
|
|
|
+import com.winhc.repal.util.UserContextUtil;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
+import java.text.DecimalFormat;
|
|
|
+import java.time.LocalDate;
|
|
|
+import java.time.format.DateTimeFormatter;
|
|
|
+import java.util.*;
|
|
|
+
|
|
|
/**
|
|
|
* @description RepalDynamic 接口实现类
|
|
|
* @author Generator
|
|
@@ -13,5 +36,91 @@ import org.springframework.stereotype.Service;
|
|
|
*/
|
|
|
@Service
|
|
|
public class RepalDynamicServiceImpl extends ServiceImpl<RepalDynamicMapper, RepalDynamic> implements RepalDynamicService {
|
|
|
+ @Autowired
|
|
|
+ private RepalBillService repalBillService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private RepalRolePermissionService repalRolePermissionService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private MessageNoticeService messageNoticeService;
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Boolean addDynamic(DynamicContentDTO dto) {
|
|
|
+ UserContextBO userContextBO = UserContextUtil.getUser();
|
|
|
+ RepalDynamic dynamic = new RepalDynamic();
|
|
|
+ dynamic.setRepalBillId(dto.getRepalBillId());
|
|
|
+ dynamic.setDynamicDesc(dto.getDynamicDesc());
|
|
|
+ dynamic.setDynamicType(RepalDynamicTypeEnum.其他.getCode());
|
|
|
+ dynamic.setMemberId(userContextBO.getUserId());
|
|
|
+ save(dynamic);
|
|
|
+ return Boolean.TRUE;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public List<RepalSmsTemplateVO> getSmsTemplate(Long repalBillId) {
|
|
|
+ RepalBill repalBill = repalBillService.getById(repalBillId);
|
|
|
+ if(ObjectUtil.isNull(repalBill)){
|
|
|
+ throw new CommonException(CodeMsg.VALIDATE_PARAMETER,"账款不存在");
|
|
|
+ }
|
|
|
+ //目前只有一个,估计也只有一个
|
|
|
+ RepalSmsTemplateVO result = new RepalSmsTemplateVO();
|
|
|
+ DecimalFormat df = new DecimalFormat("#,###.00");
|
|
|
+ long dayBetween = Math.abs(LocalDate.now().toEpochDay() - repalBill.getEndDate().toEpochDay());
|
|
|
+ String overdueStr = RepalBillStatusEnum.PROGRESSING.getCode().equals(repalBill.getRepalBillStatus()) ? "还有"+dayBetween+"天即将逾期":"已逾期"+dayBetween+"天";
|
|
|
+ String content = StrUtil.format(RepalMsgTemplateEnum.短信模板一.getContent(),
|
|
|
+ repalBill.getCustomerName(),
|
|
|
+ df.format(repalBill.getTotalMoney()),
|
|
|
+ df.format(repalBill.getReceivable()),
|
|
|
+ repalBill.getEndDate().format(DateTimeFormatter.ISO_LOCAL_DATE),
|
|
|
+ overdueStr);
|
|
|
+ result.setSmsCode(RepalMsgTemplateEnum.短信模板一.getCode());
|
|
|
+ result.setContent(content);
|
|
|
+ return Collections.singletonList(result);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Boolean urgeBySms(RepalSmsDTO dto) {
|
|
|
+ //校验权限
|
|
|
+ UserContextBO userContextBO = UserContextUtil.getUser();
|
|
|
+ boolean allFlag = repalRolePermissionService.checkUserPermission(userContextBO.getUserId(),PermissionEnum.URGE_BILL.getCode());
|
|
|
+ if(!allFlag){
|
|
|
+ throw new CommonException(CodeMsg.FORBIDDEN,"暂无此权限,可联系超级管理员在我的-成员管理页面开通");
|
|
|
+ }
|
|
|
+ if(CollUtil.isEmpty(dto.getLinks())){
|
|
|
+ throw new CommonException(CodeMsg.FAILED,"请至少选择一个联系人");
|
|
|
+ }
|
|
|
+ if(ObjectUtil.isNull(dto.getSmsCode())){
|
|
|
+ throw new CommonException(CodeMsg.FAILED,"请选择发送模板");
|
|
|
+ }
|
|
|
+ List<RepalSmsTemplateVO> templates = getSmsTemplate(dto.getRepalBillId());
|
|
|
+ if(CollUtil.isEmpty(templates)){
|
|
|
+ throw new CommonException(CodeMsg.FAILED,"发送失败");
|
|
|
+ }
|
|
|
|
|
|
+ for(RepalSmsTemplateVO template:templates){
|
|
|
+ if(template.getSmsCode().equals(dto.getSmsCode())){
|
|
|
+ Map<String,String> paraMap = new HashMap<>();
|
|
|
+ paraMap.put("content",template.getContent());
|
|
|
+ List<String> names = new ArrayList<>();
|
|
|
+ for(RepalLinkVO link: dto.getLinks()){
|
|
|
+ if(StrUtil.isNotBlank(link.getMobileNo())) {
|
|
|
+ messageNoticeService.sendSms(link.getMobileNo(), MsgNameEnum.回款宝短信催款, paraMap);
|
|
|
+ names.add(link.getName());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //记录催款动态
|
|
|
+ String dynamicDesc = "接收人:"+String.join("、",names)+"\n\r";
|
|
|
+ dynamicDesc+="信息内容:"+template.getContent();
|
|
|
+ RepalDynamic dynamic = new RepalDynamic();
|
|
|
+ dynamic.setRepalBillId(dto.getRepalBillId());
|
|
|
+ dynamic.setDynamicDesc(dynamicDesc);
|
|
|
+ dynamic.setDynamicType(RepalDynamicTypeEnum.短信.getCode());
|
|
|
+ dynamic.setMemberId(userContextBO.getUserId());
|
|
|
+ dynamic.setLinkMan(JSON.toJSONString(dto.getLinks()));
|
|
|
+ save(dynamic);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return Boolean.TRUE;
|
|
|
+ }
|
|
|
}
|