| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341 |
- package com.ydtech.modules.fnc.service.impl;
- import cn.dev33.satoken.stp.StpUtil;
- import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
- import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
- import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
- import com.github.pagehelper.PageHelper;
- import com.github.pagehelper.PageInfo;
- import com.ydtech.core.page.HttpResult;
- import com.ydtech.exception.SystemException;
- import com.ydtech.modules.admin.model.SysUser;
- import com.ydtech.modules.esm.model.EsmInsCompany;
- import com.ydtech.modules.esm.service.EsmInsCompanyService;
- import com.ydtech.modules.fnc.dao.InsPlyIncomeMapper;
- import com.ydtech.modules.fnc.dao.InsPlySettleDetailMapper;
- import com.ydtech.modules.fnc.dao.InsPlySettleHxMapper;
- import com.ydtech.modules.fnc.entity.InsPlyIncome;
- import com.ydtech.modules.fnc.entity.InsPlySettle;
- import com.ydtech.modules.fnc.dao.InsPlySettleMapper;
- import com.ydtech.modules.fnc.entity.InsPlySettleDetail;
- import com.ydtech.modules.fnc.entity.InsPlySettleHx;
- import com.ydtech.modules.fnc.service.InsPlySettleService;
- import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
- import com.ydtech.modules.fnc.vo.GenerateSettleVo;
- import com.ydtech.modules.fnc.vo.InsPlyIncomeVo;
- import com.ydtech.modules.fnc.vo.InsPlySettleVo;
- import com.ydtech.modules.inv.utils.EasyExcelUtils;
- import com.ydtech.modules.order.entity.BasePageResult;
- import com.ydtech.modules.order.entity.InsOrders;
- import com.ydtech.modules.order.entity.vo.PolicyInsuranceReportReqVo;
- import com.ydtech.modules.order.entity.vo.PolicyInsuranceReportResVo;
- import com.ydtech.modules.report.model.vo.InsPlySettleReportReqVo;
- import com.ydtech.modules.report.model.vo.InsPlySettleReportResVo;
- import com.ydtech.modules.report.model.vo.InsPlySettleStatisticsListResVo;
- import com.ydtech.utils.DateUtil;
- import com.ydtech.utils.StringUtils;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.beans.factory.annotation.Value;
- import org.springframework.stereotype.Service;
- import org.springframework.transaction.annotation.Transactional;
- import java.math.BigDecimal;
- import java.sql.Wrapper;
- import java.time.LocalDate;
- import java.time.LocalDateTime;
- import java.time.YearMonth;
- import java.util.ArrayList;
- import java.util.Date;
- import java.util.List;
- /**
- * <p>
- * 月度结算单汇总表 服务实现类
- * </p>
- *
- * @author gws
- * @since 2024-01-10
- */
- @Service
- public class InsPlySettleServiceImpl extends ServiceImpl<InsPlySettleMapper, InsPlySettle> implements InsPlySettleService {
- @Value("${upload.file.path}")
- private String uploadFilePath;
- @Autowired
- private InsPlySettleDetailMapper insPlySettleDetailMapper;
- @Autowired
- private InsPlyIncomeMapper insPlyIncomeMapper;
- @Autowired
- private InsPlySettleHxMapper insPlySettleHxMapper;
- @Autowired
- private EsmInsCompanyService esmInsCompanyService;
- @Override
- @Transactional
- public HttpResult generateSettleAndDetail(GenerateSettleVo generateSettleVo) {
- List<String> plyNoList= generateSettleVo.getPlyNoList();
- String companyId=generateSettleVo.getCompanyId();
- String deptId =generateSettleVo.getDeptId();
- String settleMonth=generateSettleVo.getSettleMonth();
- if(StringUtils.isNullOrEmpty(companyId)
- ||StringUtils.isNullOrEmpty(deptId)
- ||StringUtils.isNullOrEmpty(settleMonth)){
- return HttpResult.error("保险公司、机构、结算月份不能为空");
- }
- String settleno = "";
- BigDecimal commissionFeevalue=new BigDecimal(0);
- BigDecimal otherFeevalue=new BigDecimal(0);
- BigDecimal allFeeValue=new BigDecimal(0);
- if(plyNoList==null || plyNoList.size()==0){
- return HttpResult.error("结算清单不能传空");
- }
- // 生成结算单号
- // InsPlyIncome insPlyIncome_t=insPlyIncomeMapper.selectByPlyno(plyNoList.get(0));
- settleno = companyId+ DateUtil.yyyyMMddHHmmss(new Date());
- for(String plyNo:plyNoList){
- InsPlyIncome insPlyIncome=insPlyIncomeMapper.selectByPlyno(plyNo);
- InsPlySettleDetail insPlySettleDetail =new InsPlySettleDetail();
- insPlySettleDetail.setSettleno(settleno);
- insPlySettleDetail.setOrderno(insPlyIncome.getOrderno());
- insPlySettleDetail.setPolicyno(insPlyIncome.getPolicyno());
- insPlySettleDetail.setDeptId(insPlyIncome.getDeptId());
- insPlySettleDetail.setCommissionFeevalue(insPlyIncome.getCommissionFeevalue());
- insPlySettleDetail.setOtherFeevalue(insPlyIncome.getOtherFeevalue());
- insPlySettleDetail.setAllFeeValue(insPlyIncome.getAllFeeValue());
- insPlySettleDetail.setCreateTime(LocalDateTime.now());
- insPlySettleDetailMapper.insert(insPlySettleDetail);
- //修改ins_ply_income
- insPlyIncome.setFinalFeeValue(insPlyIncome.getAllFeeValue());
- LambdaQueryWrapper<InsPlyIncome> queryWrapper=new LambdaQueryWrapper();
- queryWrapper.eq(InsPlyIncome::getPolicyno,plyNo);
- insPlyIncomeMapper.update(insPlyIncome,queryWrapper);
- commissionFeevalue=commissionFeevalue.add(insPlyIncome.getCommissionFeevalue());
- otherFeevalue=otherFeevalue.add(insPlyIncome.getOtherFeevalue());
- allFeeValue=allFeeValue.add(insPlyIncome.getAllFeeValue());
- }
- InsPlySettle insPlySettle =new InsPlySettle();
- insPlySettle.setSettleno(settleno);
- insPlySettle.setCompanyId(companyId);
- insPlySettle.setDeptId(deptId);
- insPlySettle.setSettleMonth(settleMonth);
- String settleBatch =this.baseMapper.getMaxBatch(insPlySettle);
- if(StringUtils.isNullOrEmpty(settleBatch)){
- settleBatch="1";
- }else{
- settleBatch=String.valueOf(Integer.parseInt(settleBatch)+1);
- }
- insPlySettle.setSettleBatch(settleBatch);
- insPlySettle.setCommissionFeevalue(commissionFeevalue);
- insPlySettle.setOtherFeevalue(otherFeevalue);
- insPlySettle.setAllFeeValue(allFeeValue);
- insPlySettle.setOperator(StpUtil.getLoginId().toString());
- insPlySettle.setCreateTime(LocalDateTime.now());
- insPlySettle.setStatus("0");
- this.baseMapper.insert(insPlySettle);
- return HttpResult.ok(settleno);
- }
- @Override
- public HttpResult<BasePageResult<InsPlySettle>> selectSettle(InsPlySettleVo insPlySettleVo) {
- try{
- Page<InsOrders> page = new Page<>(insPlySettleVo.getPageNum(), insPlySettleVo.getPageSize());
- PageInfo<List<InsPlyIncome>> pageHelper = null;
- PageHelper.startPage(insPlySettleVo.getPageNum(),insPlySettleVo.getPageSize());
- List<InsPlySettle> list= this.baseMapper.selectByCondition(insPlySettleVo);
- pageHelper=new PageInfo(list);
- BasePageResult<InsPlySettle> pageResult=new BasePageResult<InsPlySettle>(insPlySettleVo.getPageNum(), insPlySettleVo.getPageSize(), pageHelper.getTotal(), pageHelper.getPages(), list);
- return HttpResult.ok(pageResult);
- }catch (Exception e){
- e.printStackTrace();
- return HttpResult.error("查询异常");
- }
- }
- @Override
- public HttpResult<BasePageResult<InsPlyIncome>> selectSettleDetail(InsPlySettleVo insPlySettleVo) {
- try{
- Page<InsOrders> page = new Page<>(insPlySettleVo.getPageNum(), insPlySettleVo.getPageSize());
- PageInfo<List<InsPlyIncome>> pageHelper = null;
- PageHelper.startPage(insPlySettleVo.getPageNum(),insPlySettleVo.getPageSize());
- List<InsPlyIncome> list= insPlyIncomeMapper.selectSettleByCondition(insPlySettleVo);
- pageHelper=new PageInfo(list);
- BasePageResult<InsPlyIncome> pageResult=new BasePageResult(insPlySettleVo.getPageNum(), insPlySettleVo.getPageSize(), pageHelper.getTotal(), pageHelper.getPages(), list);
- return HttpResult.ok(pageResult);
- }catch (Exception e){
- e.printStackTrace();
- return HttpResult.error("查询异常");
- }
- }
- @Override
- public HttpResult hxSettle(InsPlySettleHx insPlySettleHx) {
- //必填校验
- if(StringUtils.isNullOrEmpty(insPlySettleHx.getSettleno())
- ||StringUtils.isNullOrEmpty(insPlySettleHx.getFeeType())
- ||StringUtils.isNullOrEmpty(insPlySettleHx.getCheckno())
- ||StringUtils.isNullOrEmpty(insPlySettleHx.getAmount())){
- return HttpResult.error("结算单号、费用类型、核销金额、发票号不能为空");
- }
- //核销金额不能超总费用
- InsPlySettle insPlySettle=this.baseMapper.selectBySettleno(insPlySettleHx.getSettleno());
- insPlySettle.setHxamount(insPlySettle.getHxamount() ==null ? BigDecimal.ZERO:insPlySettle.getHxamount());
- insPlySettle.setCommissionHxamount(insPlySettle.getCommissionHxamount() ==null ? BigDecimal.ZERO:insPlySettle.getCommissionHxamount());
- insPlySettle.setOtherHxamount(insPlySettle.getOtherHxamount() ==null ? BigDecimal.ZERO:insPlySettle.getOtherHxamount());
- if(insPlySettleHx.getFeeType().equals("S")
- &&insPlySettle.getCommissionHxamount().add(insPlySettleHx.getAmount()).compareTo(insPlySettle.getCommissionFeevalue())>0){
- return HttpResult.error("核销手续费金额已超过结算单手续费,请修改");
- }
- if(insPlySettleHx.getFeeType().equals("O")
- &&insPlySettle.getOtherHxamount().add(insPlySettleHx.getAmount()).compareTo(insPlySettle.getOtherFeevalue())>0){
- return HttpResult.error("核销其他费用金额已超过结算单其他费用,请修改");
- }
- //1.插入核销记录表
- insPlySettleHx.setOperator(StpUtil.getLoginId().toString());
- insPlySettleHx.setCreateTime(LocalDateTime.now());
- insPlySettleHxMapper.insert(insPlySettleHx);
- //2.修改核销状态 状态(0-未核销 1-部分核销 2-已核销)
- InsPlySettle insPlySettle_status=new InsPlySettle();
- if(insPlySettle.getHxamount().add(insPlySettleHx.getAmount()).compareTo(insPlySettle.getAllFeeValue())==0){
- insPlySettle_status.setStatus("2");
- }else{
- insPlySettle_status.setStatus("1");
- }
- this.baseMapper.update(insPlySettle_status,new QueryWrapper<InsPlySettle>().eq("settleno",insPlySettleHx.getSettleno()));
- return HttpResult.ok("核销成功");
- }
- @Override
- public HttpResult queryHxDetail(String settleno) {
- LambdaQueryWrapper<InsPlySettleHx> queryWrapper=new LambdaQueryWrapper();
- queryWrapper.eq(InsPlySettleHx::getSettleno,settleno);
- List<InsPlySettleHx> list=insPlySettleHxMapper.selectList(queryWrapper);
- return HttpResult.ok(list);
- }
- @Override
- public BasePageResult<InsPlySettleReportResVo> getInsPlySettleReport( InsPlySettleReportReqVo insPlySettleReportReqVo) {
- Page<InsOrders> page = new Page<>(insPlySettleReportReqVo.getPageNum(), insPlySettleReportReqVo.getPageSize());
- page.setSearchCount(false).setOptimizeCountSql(false);//关闭count查询
- if(StringUtils.isNotEmpty(insPlySettleReportReqVo.getIsReturnBack())&&"1".equals(insPlySettleReportReqVo.getIsReturnBack())){
- //如果是返回上级时,找上级的上级往下找
- LambdaQueryWrapper<EsmInsCompany> lqw1 = new LambdaQueryWrapper<>();
- lqw1.eq(EsmInsCompany::getId, insPlySettleReportReqVo.getCompanyId());
- EsmInsCompany esmInsCompany1=esmInsCompanyService.getOne(lqw1);
- if(esmInsCompany1==null){
- throw new SystemException("已经是最顶层机构,无法继续返回!");
- }
- LambdaQueryWrapper<EsmInsCompany> lqw2 = new LambdaQueryWrapper<>();
- lqw2.eq(EsmInsCompany::getId, esmInsCompany1.getParentId());
- EsmInsCompany esmInsCompany2=esmInsCompanyService.getOne(lqw2);
- if(esmInsCompany2==null){
- insPlySettleReportReqVo.setCompanyId(esmInsCompany1.getParentId());
- }else{
- insPlySettleReportReqVo.setCompanyId(esmInsCompany2.getParentId());
- }
- }
- //正常查询,下钻查询时调整
- List<String> companyArr=esmInsCompanyService.getInsCompanyNextLevel(insPlySettleReportReqVo.getCompanyId());
- if(!(companyArr!=null&&companyArr.size()>0)){
- throw new SystemException("已经是最底层机构,无法继续下钻!");
- }
- insPlySettleReportReqVo.setGroupInsCompanyArr(companyArr);
- Page<InsPlySettleReportResVo> policyInsuranceReportResVoPage = baseMapper.getInsPlySettleReport(page,
- insPlySettleReportReqVo);
- if(policyInsuranceReportResVoPage.getRecords().size()==0){
- if(StringUtils.isNotEmpty(insPlySettleReportReqVo.getIsDrilling())&&"1".equals(insPlySettleReportReqVo.getIsDrilling())){
- throw new SystemException("已经是最底层机构,无法继续下钻!");
- }
- }
- policyInsuranceReportResVoPage.getRecords().stream().forEach(item->{
- EsmInsCompany esmInsCompany =esmInsCompanyService.getById(item.getCompanyId());
- item.setCompanyName(esmInsCompany.getName());
- if(StringUtils.isEmpty(item.getStatus())){
- item.setStatus("全部");
- }else{
- if("0".equals(item.getStatus())){
- item.setStatus("未核销");
- }else if("1".equals(item.getStatus())){
- item.setStatus("部分核销");
- }else if ("2".equals(item.getStatus())){
- item.setStatus("已核销");
- }
- }
- });
- Long total = baseMapper.getInsPlySettleReportCount(insPlySettleReportReqVo);
- policyInsuranceReportResVoPage.setTotal(total);
- return new BasePageResult<>(insPlySettleReportReqVo.getPageNum(), insPlySettleReportReqVo.getPageSize(),
- policyInsuranceReportResVoPage.getTotal(), policyInsuranceReportResVoPage.getPages()
- , policyInsuranceReportResVoPage.getRecords());
- }
- @Override
- public HttpResult<String> exportInsPlySettleReport(InsPlySettleReportReqVo insPlySettleReportReqVo) {
- if(StringUtils.isNotEmpty(insPlySettleReportReqVo.getIsReturnBack())&&"1".equals(insPlySettleReportReqVo.getIsReturnBack())){
- //如果是返回上级时,找上级的上级往下找
- LambdaQueryWrapper<EsmInsCompany> lqw1 = new LambdaQueryWrapper<>();
- lqw1.eq(EsmInsCompany::getId, insPlySettleReportReqVo.getCompanyId());
- EsmInsCompany esmInsCompany1=esmInsCompanyService.getOne(lqw1);
- if(esmInsCompany1==null){
- throw new SystemException("已经是最顶层机构,无法继续返回!");
- }
- LambdaQueryWrapper<EsmInsCompany> lqw2 = new LambdaQueryWrapper<>();
- lqw2.eq(EsmInsCompany::getId, esmInsCompany1.getParentId());
- EsmInsCompany esmInsCompany2=esmInsCompanyService.getOne(lqw2);
- if(esmInsCompany2==null){
- insPlySettleReportReqVo.setCompanyId(esmInsCompany1.getParentId());
- }else{
- insPlySettleReportReqVo.setCompanyId(esmInsCompany2.getParentId());
- }
- }
- //正常查询,下钻查询时调整
- List<String> companyArr=esmInsCompanyService.getInsCompanyNextLevel(insPlySettleReportReqVo.getCompanyId());
- if(!(companyArr!=null&&companyArr.size()>0)){
- throw new SystemException("已经是最底层机构,无法继续下钻!");
- }
- insPlySettleReportReqVo.setGroupInsCompanyArr(companyArr);
- List<InsPlySettleReportResVo> insPlySettleReportResVoList = baseMapper.getInsPlySettleReport(insPlySettleReportReqVo);
- if(insPlySettleReportResVoList.size()==0){
- if(StringUtils.isNotEmpty(insPlySettleReportReqVo.getIsDrilling())&&"1".equals(insPlySettleReportReqVo.getIsDrilling())){
- throw new SystemException("已经是最底层机构,无法继续下钻!");
- }
- }
- insPlySettleReportResVoList.stream().forEach(item->{
- EsmInsCompany esmInsCompany =esmInsCompanyService.getById(item.getCompanyId());
- item.setCompanyName(esmInsCompany.getName());
- if(StringUtils.isEmpty(item.getStatus())){
- item.setStatus("全部");
- }else{
- if("0".equals(item.getStatus())){
- item.setStatus("未核销");
- }else if("1".equals(item.getStatus())){
- item.setStatus("部分核销");
- }else if ("2".equals(item.getStatus())){
- item.setStatus("已核销");
- }
- }
- });
- String s = EasyExcelUtils.downExcel(uploadFilePath, InsPlySettleReportResVo.class, insPlySettleReportResVoList);
- return HttpResult.ok("", s);
- }
- @Override
- public HttpResult<String> exportInsPlySettleReportList(InsPlySettleReportReqVo insPlySettleReportReqVo) {
- List<InsPlySettleStatisticsListResVo> insPlySettleReportList = baseMapper.getInsPlySettleReportList(insPlySettleReportReqVo);
- insPlySettleReportList.stream().forEach(item->{
- if("0".equals(item.getStatus())){
- item.setStatus("未核销");
- }else if("1".equals(item.getStatus())){
- item.setStatus("部分核销");
- }else if ("2".equals(item.getStatus())){
- item.setStatus("已核销");
- }
- });
- String s = EasyExcelUtils.downExcel(uploadFilePath, InsPlySettleStatisticsListResVo.class, insPlySettleReportList);
- return HttpResult.ok("", s);
- }
- }
|