|
|
@@ -4,8 +4,8 @@ import cn.com.taiji.common.manager.ManagerException; |
|
|
|
import cn.com.taiji.common.model.dao.Pagination; |
|
|
|
import cn.com.taiji.common.pub.StringTools; |
|
|
|
import cn.com.taiji.core.entity.bill.BillTitleInfo; |
|
|
|
import cn.com.taiji.core.repo.jpa.basic.QtkCustomerInfoRepo; |
|
|
|
import cn.com.taiji.core.repo.jpa.bill.BillTitleInfoRepo; |
|
|
|
import cn.com.taiji.core.repo.jpa.user.AccountInfoRepo; |
|
|
|
import cn.com.taiji.managew.dto.bill.title.BillTitleInfoDeleteRequestDTO; |
|
|
|
import cn.com.taiji.managew.dto.bill.title.BillTitleInfoDetailRequestDTO; |
|
|
|
import cn.com.taiji.managew.dto.bill.title.BillTitleInfoEditRequestDTO; |
|
|
@@ -16,6 +16,8 @@ import org.springframework.beans.factory.annotation.Autowired; |
|
|
|
import org.springframework.stereotype.Service; |
|
|
|
|
|
|
|
import java.time.LocalDateTime; |
|
|
|
import java.util.ArrayList; |
|
|
|
import java.util.Collections; |
|
|
|
import java.util.List; |
|
|
|
|
|
|
|
import static org.aspectj.util.LangUtil.isEmpty; |
|
|
@@ -27,14 +29,15 @@ public class BillTitleInfoManagerImpl implements BillTitleInfoManager { |
|
|
|
private BillTitleInfoRepo billTitleInfoRepo; |
|
|
|
|
|
|
|
@Autowired |
|
|
|
private QtkCustomerInfoRepo customerInfoRepo; |
|
|
|
private AccountInfoRepo accountInfoRepo; |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
public Pagination page(BillTitleInfoPageRequestDTO request) throws ManagerException { |
|
|
|
BillTitleInfoPageRequest req = new BillTitleInfoPageRequest(); |
|
|
|
if (StringTools.hasText(request.getCustomerNo())) { |
|
|
|
List<String> customerIds = customerInfoRepo.findCustomerIdByIdNum(request.getCustomerNo()); |
|
|
|
if (!isEmpty(customerIds)) req.setCustomerIds(customerIds); |
|
|
|
List<String> openIds = accountInfoRepo.findByIdNum(request.getCustomerNo()); |
|
|
|
if (!isEmpty(openIds)) req.setOpenIds(openIds); |
|
|
|
} |
|
|
|
BeanUtils.copyProperties(request, req); |
|
|
|
return billTitleInfoRepo.page(req); |
|
|
@@ -53,26 +56,45 @@ public class BillTitleInfoManagerImpl implements BillTitleInfoManager { |
|
|
|
if (billTitleInfo == null) throw new ManagerException("抬头不存在"); |
|
|
|
|
|
|
|
// 查询当前客户是否有默认抬头 |
|
|
|
List<BillTitleInfo> titles = billTitleInfoRepo.findByCIdAndIsDefaultAndTitleType(req.getCustomerId(), 1, billTitleInfo.getTitleType()); |
|
|
|
List<BillTitleInfo> titles = billTitleInfoRepo.findByCIdAndIsDefault(req.getOpenId(), 1); |
|
|
|
if (isEmpty(titles)) { |
|
|
|
// 没有默认抬头,则设置当前抬头为默认 |
|
|
|
billTitleInfo.setIsDefault(1); |
|
|
|
}else if (req.getIsDefault() == 1) { |
|
|
|
// 如果已经有默认抬头且修改为默认抬头,则取消其他默认抬头 |
|
|
|
billTitleInfoRepo.updateIsDefault(req.getCustomerId(), billTitleInfo.getTitleType()); |
|
|
|
billTitleInfoRepo.updateIsDefault(req.getOpenId()); |
|
|
|
billTitleInfo.setIsDefault(1); |
|
|
|
} |
|
|
|
// 拷贝参数 |
|
|
|
BeanUtils.copyProperties(req, billTitleInfo, "id", "isDefault", "customerinfoId"); |
|
|
|
BeanUtils.copyProperties(req, billTitleInfo, "id", "isDefault", "openId"); |
|
|
|
billTitleInfo.setUpdateTime(LocalDateTime.now()); |
|
|
|
billTitleInfoRepo.saveAndFlush(billTitleInfo); |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public void delete(BillTitleInfoDeleteRequestDTO req) throws ManagerException { |
|
|
|
BillTitleInfo billTitleInfo = billTitleInfoRepo.findById(req.getId()).orElse(null); |
|
|
|
if (billTitleInfo == null) throw new ManagerException("抬头不存在"); |
|
|
|
billTitleInfo.setValid(false); |
|
|
|
billTitleInfoRepo.saveAndFlush(billTitleInfo); |
|
|
|
BillTitleInfo titleInfo = billTitleInfoRepo.findById(req.getId()).orElse(null); |
|
|
|
if (titleInfo == null) throw new ManagerException("抬头不存在"); |
|
|
|
//处理是否默认 |
|
|
|
if (titleInfo.getIsDefault() == 1) { |
|
|
|
BillTitleInfoPageRequest request = new BillTitleInfoPageRequest(); |
|
|
|
request.setOpenIds(new ArrayList<>(Collections.singleton(titleInfo.getOpenId()))); |
|
|
|
List<BillTitleInfo> list = billTitleInfoRepo.list(request); |
|
|
|
if (!list.isEmpty()) { |
|
|
|
// 找到最新一条,并且id不是titleInfo的id |
|
|
|
BillTitleInfo newDefaultTitle = list.stream() |
|
|
|
.filter(t -> !t.getId().equals(titleInfo.getId())) |
|
|
|
.findFirst().orElse( null); // 取第一个,如果没有就取null |
|
|
|
if(newDefaultTitle != null) { |
|
|
|
newDefaultTitle.setIsDefault(1); |
|
|
|
newDefaultTitle.setUpdateTime(LocalDateTime.now()); |
|
|
|
billTitleInfoRepo.saveAndFlush(newDefaultTitle); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
titleInfo.setValid(false); |
|
|
|
titleInfo.setIsDefault(0); |
|
|
|
titleInfo.setUpdateTime(LocalDateTime.now()); |
|
|
|
billTitleInfoRepo.saveAndFlush(titleInfo); |
|
|
|
} |
|
|
|
} |