package com.by4cloud.platformx.business.service.impl;
|
|
import cn.hutool.core.collection.CollUtil;
|
import cn.hutool.core.date.DatePattern;
|
import cn.hutool.core.date.DateUtil;
|
import cn.hutool.core.util.ObjUtil;
|
import cn.hutool.core.util.StrUtil;
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
import com.by4cloud.platformx.business.dto.ZBJTStatisticDTO;
|
import com.by4cloud.platformx.business.entity.AnnualPlanKey;
|
import com.by4cloud.platformx.business.entity.ZbStatisticZdgz;
|
import com.by4cloud.platformx.business.mapper.AnnualPlanKeyMapper;
|
import com.by4cloud.platformx.business.mapper.ContractSubjectMatterMapper;
|
import com.by4cloud.platformx.business.mapper.ZbStatisticZdgzMapper;
|
import com.by4cloud.platformx.business.service.ZbStatisticZdgzService;
|
import com.by4cloud.platformx.business.vo.GcpbkwcqkItemVo;
|
import com.by4cloud.platformx.business.vo.SckfzdgzwcqkVo;
|
import com.by4cloud.platformx.common.core.util.R;
|
import lombok.RequiredArgsConstructor;
|
import org.springframework.stereotype.Service;
|
|
import java.math.BigDecimal;
|
import java.math.RoundingMode;
|
import java.time.YearMonth;
|
import java.util.ArrayList;
|
import java.util.Date;
|
import java.util.List;
|
|
/**
|
* 重点工作
|
*
|
* @author syt
|
* @date 2026-11-12 10:28:35
|
*/
|
@Service
|
@RequiredArgsConstructor
|
public class ZbStatisticZdgzServiceImpl extends ServiceImpl<ZbStatisticZdgzMapper, ZbStatisticZdgz> implements ZbStatisticZdgzService {
|
|
private final ContractSubjectMatterMapper contractSubjectMatterMapper;
|
private final AnnualPlanKeyMapper annualPlanKeyMapper;
|
|
|
@Override
|
public R genZdgzwcqk(ZBJTStatisticDTO queryDTO) {
|
if (StrUtil.isBlank(queryDTO.getYearMonth())) {
|
queryDTO.setYearMonth(DateUtil.format(new Date(), DatePattern.NORM_MONTH_PATTERN));
|
}
|
List<SckfzdgzwcqkVo> list = new ArrayList<>();
|
Date monstart = DateUtil.parseDateTime(queryDTO.getYearMonth() + "-01 00:00:00");
|
Date monend = DateUtil.parseDateTime(queryDTO.getYearMonth() + "-31 23:59:59");
|
Date monstartLastYear = DateUtil.offsetYear(DateUtil.parseDateTime(queryDTO.getYearMonth() + "-01 00:00:00"), -1);
|
Date monendLastYear = DateUtil.offsetYear(DateUtil.parseDateTime(queryDTO.getYearMonth() + "-31 23:59:59"), -1);
|
Date yearstart = DateUtil.parseDateTime(queryDTO.getYearMonth().substring(0, 4) + "-01-01 00:00:00");
|
Date yearend = DateUtil.parseDateTime(queryDTO.getYearMonth() + "-31 23:59:59");
|
Date yearstartLastYear = DateUtil.offsetYear(DateUtil.parseDateTime(queryDTO.getYearMonth().substring(0, 4) + "-01-01 00:00:00"), -1);
|
Date yearendLastYear = DateUtil.offsetYear(DateUtil.parseDateTime(queryDTO.getYearMonth() + "-31 23:59:59"), -1);
|
String curYear = queryDTO.getYearMonth().substring(0, 4);
|
String curMonth = queryDTO.getYearMonth().substring(5);
|
YearMonth qndy = YearMonth.of(Integer.valueOf(curYear), Integer.valueOf(curMonth)).minusYears(1);
|
YearMonth sy = YearMonth.of(Integer.valueOf(curYear), Integer.valueOf(curMonth)).minusMonths(1);
|
//新增合同
|
List<GcpbkwcqkItemVo> itemVoListMon = contractSubjectMatterMapper.sckfzdgzwcqk(monstart, monend);
|
if (CollUtil.isNotEmpty(itemVoListMon)) {
|
itemVoListMon.stream().forEach(item -> {
|
ZbStatisticZdgz vo = new ZbStatisticZdgz();
|
vo.setDw(item.getDw());
|
vo.setXm(item.getXm());
|
vo.setStatYm(queryDTO.getYearMonth());
|
Long compId = null;
|
if (StrUtil.equals(item.getDw(), "石煤机")) {
|
compId = 2089995177814495234L;
|
vo.setCompId(2089995177814495234L);
|
}
|
if (StrUtil.equals(item.getDw(), "石工泵")) {
|
compId = 2056556196124250113L;
|
vo.setCompId(2056556196124250113L);
|
}
|
if (StrUtil.equals(item.getDw(), "通方厂")) {
|
compId = 2056556317461270529L;
|
vo.setCompId(2056556317461270529L);
|
}
|
if (StrUtil.equals(item.getDw(), "邢台厂")) {
|
compId = 2056556421857497090L;
|
vo.setCompId(2056556421857497090L);
|
}
|
AnnualPlanKey plan = annualPlanKeyMapper.selectOne(Wrappers.<AnnualPlanKey>lambdaQuery()
|
.eq(AnnualPlanKey::getPlanYear, queryDTO.getYearMonth().substring(0, 4)).eq(AnnualPlanKey::getPlanType, item.getCode())
|
.eq(AnnualPlanKey::getCompId, compId).last("limit 1"));
|
ZbStatisticZdgz vo1 = baseMapper.selectOne(Wrappers.<ZbStatisticZdgz>lambdaQuery().eq(ZbStatisticZdgz::getDw, vo.getDw())
|
.eq(ZbStatisticZdgz::getXm, vo.getXm()).eq(ZbStatisticZdgz::getStatYm, vo.getStatYm()).last("limit 1"));
|
if (ObjUtil.isNotNull(vo1)) {
|
if (ObjUtil.isNotNull(plan)) {
|
vo1.setDywc(item.getWc());
|
vo1.setDyjh(plan.getMonthAmount(queryDTO.getYearMonth().substring(5)));
|
vo1.setLjjh(plan.getToMonTotalAmount(queryDTO.getYearMonth().substring(5)));
|
vo1.setNdjh(plan.getTotalAmount());
|
if (vo1.getDyjh().compareTo(new BigDecimal("0")) > 0) {
|
vo1.setYwcl(vo1.getDywc().divide(vo1.getDyjh(), 10, RoundingMode.HALF_UP).multiply(new BigDecimal("100"))
|
.setScale(2, RoundingMode.HALF_UP) + "%");
|
}
|
}
|
ZbStatisticZdgz voQndy = baseMapper.selectOne(Wrappers.<ZbStatisticZdgz>lambdaQuery().eq(ZbStatisticZdgz::getDw, vo.getDw())
|
.eq(ZbStatisticZdgz::getXm, vo.getXm()).eq(ZbStatisticZdgz::getStatYm, qndy).last("limit 1"));
|
ZbStatisticZdgz voSy = baseMapper.selectOne(Wrappers.<ZbStatisticZdgz>lambdaQuery().eq(ZbStatisticZdgz::getDw, vo.getDw())
|
.eq(ZbStatisticZdgz::getXm, vo.getXm()).eq(ZbStatisticZdgz::getStatYm, sy).last("limit 1"));
|
if (ObjUtil.isNotNull(voSy)) {
|
vo1.setLjwc(voSy.getLjwc().add(vo1.getDywc()));
|
if (ObjUtil.isNotNull(vo1.getLjjh()) && vo1.getLjjh().compareTo(new BigDecimal("0")) > 0) {
|
vo1.setLjwcl(vo1.getLjwc().divide(vo1.getLjjh(), 10, RoundingMode.HALF_UP).multiply(new BigDecimal("100"))
|
.setScale(2, RoundingMode.HALF_UP) + "%");
|
}
|
}
|
if (ObjUtil.isNotNull(voQndy) && voQndy.getLjwc().compareTo(new BigDecimal("0")) > 0) {
|
BigDecimal percent = vo1.getLjwc().subtract(voQndy.getLjwc()).divide(voQndy.getLjwc(), 10, RoundingMode.HALF_UP).multiply(new BigDecimal("100"));
|
vo1.setLjtb(percent.setScale(2, RoundingMode.HALF_UP) + "%");
|
}
|
baseMapper.updateById(vo1);
|
} else {
|
if (ObjUtil.isNotNull(plan)) {
|
vo.setDywc(item.getWc());
|
vo.setDyjh(plan.getMonthAmount(queryDTO.getYearMonth().substring(5)));
|
vo.setLjjh(plan.getToMonTotalAmount(queryDTO.getYearMonth().substring(5)));
|
vo.setNdjh(plan.getTotalAmount());
|
if (vo.getDyjh().compareTo(new BigDecimal("0")) > 0) {
|
vo.setYwcl(vo.getDywc().divide(vo.getDyjh(), 10, RoundingMode.HALF_UP).multiply(new BigDecimal("100"))
|
.setScale(2, RoundingMode.HALF_UP) + "%");
|
}
|
}
|
ZbStatisticZdgz voQndy = baseMapper.selectOne(Wrappers.<ZbStatisticZdgz>lambdaQuery().eq(ZbStatisticZdgz::getDw, vo.getDw())
|
.eq(ZbStatisticZdgz::getXm, vo.getXm()).eq(ZbStatisticZdgz::getStatYm, qndy).last("limit 1"));
|
ZbStatisticZdgz voSy = baseMapper.selectOne(Wrappers.<ZbStatisticZdgz>lambdaQuery().eq(ZbStatisticZdgz::getDw, vo.getDw())
|
.eq(ZbStatisticZdgz::getXm, vo.getXm()).eq(ZbStatisticZdgz::getStatYm, sy).last("limit 1"));
|
if (ObjUtil.isNotNull(voSy)) {
|
vo.setLjwc(voSy.getLjwc().add(vo.getDywc()== null ? BigDecimal.ZERO :vo.getDywc()));
|
if (ObjUtil.isNotNull(vo.getLjjh()) && vo.getLjjh().compareTo(new BigDecimal("0")) > 0) {
|
vo.setLjwcl(vo.getLjwc().divide(vo.getLjjh(), 10, RoundingMode.HALF_UP).multiply(new BigDecimal("100"))
|
.setScale(2, RoundingMode.HALF_UP) + "%");
|
}
|
}
|
if (ObjUtil.isNotNull(voQndy) && voQndy.getLjwc().compareTo(new BigDecimal("0")) > 0) {
|
BigDecimal percent = vo.getLjwc().subtract(voQndy.getLjwc()).divide(voQndy.getLjwc(), 10, RoundingMode.HALF_UP).multiply(new BigDecimal("100"));
|
vo.setLjtb(percent.setScale(2, RoundingMode.HALF_UP) + "%");
|
}
|
baseMapper.insert(vo);
|
}
|
|
});
|
}
|
// List<GcpbkwcqkItemVo> itemVoListYear = contractSubjectMatterMapper.sckfzdgzwcqk(yearstart, yearend);
|
// List<GcpbkwcqkItemVo> itemVoListYearLastYear = contractSubjectMatterMapper.sckfzdgzwcqk(yearstartLastYear, yearendLastYear);
|
// if (CollUtil.isNotEmpty(list) && CollUtil.isNotEmpty(itemVoListYear)) {
|
// for (GcpbkwcqkItemVo itemVo : itemVoListYear
|
// ) {
|
// ZbStatisticZdgz vo = baseMapper.selectOne(Wrappers.<ZbStatisticZdgz>lambdaQuery().eq(ZbStatisticZdgz::getDw, itemVo.getDw())
|
// .eq(ZbStatisticZdgz::getXm, itemVo.getXm()).eq(ZbStatisticZdgz::getStatYm, queryDTO.getYearMonth()).last("limit 1"));
|
// if (StrUtil.equals(vo.getDw(), itemVo.getDw()) && StrUtil.equals(vo.getXm(), itemVo.getXm())) {
|
// vo.setLjwc(itemVo.getWc());
|
// if (ObjUtil.isNotNull(vo.getLjjh()) && vo.getLjjh().compareTo(new BigDecimal("0")) > 0) {
|
// vo.setLjwcl(vo.getLjwc().divide(vo.getLjjh(), 10, RoundingMode.HALF_UP).multiply(new BigDecimal("100"))
|
// .setScale(2, RoundingMode.HALF_UP) + "%");
|
// }
|
// }
|
// if (CollUtil.isNotEmpty(itemVoListYearLastYear)) {
|
// itemVoListYearLastYear.stream().forEach(item1 -> {
|
// if (StrUtil.equals(vo.getDw(), item1.getDw()) && StrUtil.equals(vo.getXm(), itemVo.getXm()) &&
|
// item1.getWc().compareTo(new BigDecimal("0")) > 0) {
|
// BigDecimal percent = vo.getLjwc().subtract(item1.getWc()).divide(item1.getWc(), 10, RoundingMode.HALF_UP).multiply(new BigDecimal("100"));
|
// vo.setLjtb(percent.setScale(2, RoundingMode.HALF_UP) + "%");
|
// }
|
// });
|
// }
|
// baseMapper.updateById(vo);
|
// }
|
// }
|
return R.ok();
|
}
|
}
|