|
|
@@ -0,0 +1,476 @@
|
|
|
+package com.sckw.contract.service.impl;
|
|
|
+
|
|
|
+import java.math.BigDecimal;
|
|
|
+import java.util.*;
|
|
|
+import java.util.stream.Collectors;
|
|
|
+
|
|
|
+import com.baomidou.mybatisplus.extension.toolkit.SqlHelper;
|
|
|
+import com.github.pagehelper.Page;
|
|
|
+import com.github.pagehelper.PageInfo;
|
|
|
+import com.sckw.contract.api.model.dto.req.LogisticsScoreDetailFeignDto;
|
|
|
+import com.sckw.contract.dao.KwcContractLogisticsScoreDetailMapper;
|
|
|
+import com.sckw.contract.model.dto.req.LogisticsScoreApprovalDto;
|
|
|
+import com.sckw.contract.model.dto.req.LogisticsScoreDetailQueryDto;
|
|
|
+import com.sckw.contract.model.dto.req.LogisticsScoreQueryDto;
|
|
|
+import com.sckw.contract.model.dto.req.LogisticsScoreDetailAddDto;
|
|
|
+import com.sckw.contract.model.entity.KwcContractLogistics;
|
|
|
+import com.sckw.contract.model.entity.KwcContractLogisticsScoreDetail;
|
|
|
+import com.sckw.contract.model.entity.KwcContractLogisticsUnit;
|
|
|
+import com.sckw.contract.model.vo.req.LogisticListReq;
|
|
|
+import com.sckw.contract.model.vo.res.LogisticsScoreDetailResVo;
|
|
|
+import com.sckw.contract.model.vo.res.LogisticsScoreResVo;
|
|
|
+import com.sckw.contract.repository.KwcContractLogisticsRepository;
|
|
|
+import com.sckw.contract.repository.KwcContractLogisticsUnitRepository;
|
|
|
+import com.sckw.core.exception.BusinessException;
|
|
|
+import com.sckw.core.model.constant.NumberConstant;
|
|
|
+import com.sckw.core.model.enums.EntTypeEnum;
|
|
|
+import com.sckw.core.utils.BeanUtils;
|
|
|
+import com.sckw.core.utils.CollectionUtils;
|
|
|
+import com.sckw.core.utils.IdWorker;
|
|
|
+import com.sckw.core.utils.PageUtils;
|
|
|
+import com.sckw.core.web.config.CustomConfig;
|
|
|
+import com.sckw.core.web.context.LoginUserHolder;
|
|
|
+import com.sckw.redis.constant.RedisConstant;
|
|
|
+import com.sckw.redis.utils.RedissonUtils;
|
|
|
+import com.sckw.system.api.model.dto.res.EntCacheResDto;
|
|
|
+import org.apache.commons.collections4.MapUtils;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+import com.sckw.contract.dao.KwcContractLogisticsScoreMapper;
|
|
|
+import com.sckw.contract.model.entity.KwcContractLogisticsScore;
|
|
|
+import com.sckw.contract.service.IKwcContractLogisticsScoreService;
|
|
|
+import org.springframework.transaction.annotation.Transactional;
|
|
|
+
|
|
|
+/**
|
|
|
+ * 物流企业评分Service业务层处理
|
|
|
+ *
|
|
|
+ * @author tangyishan
|
|
|
+ * @date 2025-12-05
|
|
|
+ */
|
|
|
+@Service
|
|
|
+public class KwcContractLogisticsScoreServiceImpl implements IKwcContractLogisticsScoreService
|
|
|
+{
|
|
|
+ @Autowired
|
|
|
+ private KwcContractLogisticsScoreMapper kwcContractLogisticsScoreMapper;
|
|
|
+ @Autowired
|
|
|
+ private KwcContractLogisticsRepository kwcContractLogisticsRepository;
|
|
|
+ @Autowired
|
|
|
+ private KwcContractLogisticsUnitRepository kwcContractLogisticsUnitRepository;
|
|
|
+ @Autowired
|
|
|
+ private KwcContractLogisticsScoreDetailMapper kwcContractLogisticsScoreDetailMapper;
|
|
|
+ @Autowired
|
|
|
+ private CustomConfig customConfig;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 查询物流企业评分列表
|
|
|
+ * providerEntId 供应商企业id
|
|
|
+ * isPage 是否是分页查询
|
|
|
+ * @return 物流企业评分
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public PageInfo<LogisticsScoreResVo> selectLogisticsScoreWithPendingSocreList(Long providerEntId)
|
|
|
+ {
|
|
|
+ //查询评分列表
|
|
|
+ PageInfo<LogisticsScoreResVo> pageInfo = new PageInfo<>(new ArrayList<>());
|
|
|
+ List<KwcContractLogisticsScore> logisticsScores = selectLogisticsScoreList(providerEntId, true);
|
|
|
+ List<Long> logisticsScoreIds = logisticsScores.stream().map(KwcContractLogisticsScore::getId).toList();
|
|
|
+ if(CollectionUtils.isNotEmpty(logisticsScoreIds)){
|
|
|
+ //查询待审评分
|
|
|
+ LogisticsScoreDetailQueryDto detailReqDto = new LogisticsScoreDetailQueryDto();
|
|
|
+ detailReqDto.setScoreIds(logisticsScoreIds);
|
|
|
+ detailReqDto.setStatus(NumberConstant.ZERO);
|
|
|
+ List<KwcContractLogisticsScoreDetail> logisticsScoreDetails = kwcContractLogisticsScoreDetailMapper.selectKwcContractLogisticsScoreDetailList(detailReqDto);
|
|
|
+ if(CollectionUtils.isNotEmpty(logisticsScoreDetails)){
|
|
|
+ Map<Long, BigDecimal> scoreChangeMap = logisticsScoreDetails.stream().collect(Collectors.toMap(KwcContractLogisticsScoreDetail::getScoreId, KwcContractLogisticsScoreDetail::getScoreChange, (v1, v2) -> v1));
|
|
|
+ for (KwcContractLogisticsScore logisticsScore : logisticsScores) {
|
|
|
+ logisticsScore.setPendingScore(scoreChangeMap.getOrDefault(logisticsScore.getId(), null));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ pageInfo = ((Page<KwcContractLogisticsScore>) logisticsScores).toPageInfo(e -> {
|
|
|
+ LogisticsScoreResVo logisticsScoreResVo = new LogisticsScoreResVo();
|
|
|
+ BeanUtils.copyProperties(e, logisticsScoreResVo);
|
|
|
+ if(e.getPendingScore()!=null && e.getPendingScore().compareTo(BigDecimal.ZERO) > 0){
|
|
|
+ logisticsScoreResVo.setPendingScore("+"+e.getPendingScore());
|
|
|
+ }else if(e.getPendingScore()==null){
|
|
|
+ logisticsScoreResVo.setPendingScore("");
|
|
|
+ }
|
|
|
+ return logisticsScoreResVo;
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ return pageInfo;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 查询物流企业评分明细列表
|
|
|
+ *
|
|
|
+ * @param detailReqDto 物流企业评分明细
|
|
|
+ * @param providerEntId 供应商企业id
|
|
|
+ * @return 物流企业评分明细
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public PageInfo<LogisticsScoreDetailResVo> selectKwcContractLogisticsScoreDetailList(LogisticsScoreDetailQueryDto detailReqDto, Long providerEntId)
|
|
|
+ {
|
|
|
+ //校验评分权限
|
|
|
+ KwcContractLogisticsScore logisticsScore = checkLogisticsScoreAuth(providerEntId, detailReqDto.getScoreId());
|
|
|
+ PageInfo<LogisticsScoreDetailResVo> pageInfo = new PageInfo<>(new ArrayList<>());
|
|
|
+ PageUtils.startPage();
|
|
|
+ detailReqDto.setScoreIds(Collections.singletonList(detailReqDto.getScoreId()));
|
|
|
+ List<KwcContractLogisticsScoreDetail> logisticsScoreDetails = kwcContractLogisticsScoreDetailMapper.selectKwcContractLogisticsScoreDetailList(detailReqDto);
|
|
|
+ if(CollectionUtils.isNotEmpty(logisticsScoreDetails)){
|
|
|
+ pageInfo = ((Page<KwcContractLogisticsScoreDetail>) logisticsScoreDetails).toPageInfo(e -> {
|
|
|
+ LogisticsScoreDetailResVo logisticsScoreDetailResVo = new LogisticsScoreDetailResVo();
|
|
|
+ BeanUtils.copyProperties(e, logisticsScoreDetailResVo);
|
|
|
+ if(e.getScoreChange()!=null && e.getScoreChange().compareTo(BigDecimal.ZERO) > 0){
|
|
|
+ logisticsScoreDetailResVo.setScoreChange("+"+e.getScoreChange());
|
|
|
+ }else if(e.getScoreChange() == null){
|
|
|
+ logisticsScoreDetailResVo.setScoreChange("");
|
|
|
+ }
|
|
|
+ if(e.getScore() == null){
|
|
|
+ logisticsScoreDetailResVo.setScore("");
|
|
|
+ }
|
|
|
+ logisticsScoreDetailResVo.setLogisticsEntName(logisticsScore.getLogisticsEntName());
|
|
|
+ return logisticsScoreDetailResVo;
|
|
|
+ });
|
|
|
+ }
|
|
|
+ return pageInfo;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 查询物流企业待审评分
|
|
|
+ *
|
|
|
+ * @param scoreId 物流企业评分id
|
|
|
+ * @param providerEntId 供应商企业id
|
|
|
+ * @return 物流企业评分明细
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public LogisticsScoreDetailResVo selectLogisticsPendingScoreDetail(Long scoreId, Long providerEntId)
|
|
|
+ {
|
|
|
+ //校验评分权限
|
|
|
+ KwcContractLogisticsScore logisticsScore = checkLogisticsScoreAuth(providerEntId,scoreId);
|
|
|
+ KwcContractLogisticsScoreDetail logisticsScoreDetail = kwcContractLogisticsScoreDetailMapper.selectLogisticsPendingScoreDetail(scoreId);
|
|
|
+ if(logisticsScoreDetail == null){
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ logisticsScoreDetail.setLogisticsEntName(logisticsScore.getLogisticsEntName());
|
|
|
+ LogisticsScoreDetailResVo logisticsScoreDetailResVo = new LogisticsScoreDetailResVo();
|
|
|
+ BeanUtils.copyProperties(logisticsScoreDetail,logisticsScoreDetailResVo);
|
|
|
+ logisticsScoreDetailResVo.setScore(logisticsScore.getScore().toString());
|
|
|
+ return logisticsScoreDetailResVo;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 查询物流企业评分列表
|
|
|
+ * providerEntId 供应商企业id
|
|
|
+ * isPage 是否是分页查询
|
|
|
+ * @return 物流企业评分
|
|
|
+ */
|
|
|
+ private List<KwcContractLogisticsScore> selectLogisticsScoreList(Long providerEntId, boolean isPage)
|
|
|
+ {
|
|
|
+ LogisticsScoreQueryDto scoreReqDto = new LogisticsScoreQueryDto();
|
|
|
+ providerEntId = providerEntId !=null ? providerEntId : LoginUserHolder.getEntId();
|
|
|
+ //1.查询当前供应商企业有效的物流合同
|
|
|
+ List<KwcContractLogistics> logisticsContracts = kwcContractLogisticsRepository.queryValidByEntId(providerEntId);
|
|
|
+ List<Long> contractIds = logisticsContracts.stream().map(KwcContractLogistics::getId).toList();
|
|
|
+ if(CollectionUtils.isNotEmpty(contractIds)){
|
|
|
+ //2.根据物流合同id列表和托运商类型查询物流企业列表并得到物流企业id列表
|
|
|
+ List<KwcContractLogisticsUnit> logisticsUnits = kwcContractLogisticsUnitRepository.queryByContractIds(contractIds, EntTypeEnum.LOGISTICS4.getCode());
|
|
|
+ List<Long> logisticsEntIds = logisticsUnits.stream().map(KwcContractLogisticsUnit::getEntId).toList();
|
|
|
+ if(CollectionUtils.isNotEmpty(logisticsEntIds)){
|
|
|
+ //3.根据物流企业id列表和供应商企业id查询物流企业评分列表
|
|
|
+ scoreReqDto.setProviderEntId(providerEntId);
|
|
|
+ scoreReqDto.setLogisticsEntIds(logisticsEntIds);
|
|
|
+ if (isPage){
|
|
|
+ PageUtils.startPage();
|
|
|
+ }
|
|
|
+ return kwcContractLogisticsScoreMapper.selectKwcContractLogisticsScoreList(scoreReqDto);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return Collections.emptyList();
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 校验供应商企业评分权限
|
|
|
+ * @param providerEntId 供应商企业id
|
|
|
+ * @param scoreId 评分id
|
|
|
+ * @return 评分id集合
|
|
|
+ */
|
|
|
+ private KwcContractLogisticsScore checkLogisticsScoreAuth(Long providerEntId,Long scoreId){
|
|
|
+ KwcContractLogisticsScore logisticsScore = kwcContractLogisticsScoreMapper.selectLogisticsScoreByEntIdAndScoreId(providerEntId,scoreId);
|
|
|
+ if(logisticsScore == null){
|
|
|
+ throw new BusinessException("无当前评分记录权限");
|
|
|
+ }
|
|
|
+ return logisticsScore;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
+ @Override
|
|
|
+ public void initLogisticsScore(LogisticListReq.TradeBaseInfo baseInfo,Map<Long, EntCacheResDto> entCacheResDtoMap) {
|
|
|
+ KwcContractLogisticsScore logisticsScore = new KwcContractLogisticsScore();
|
|
|
+
|
|
|
+ long scoreId = new IdWorker(1L).nextId();
|
|
|
+ logisticsScore.setId(scoreId);
|
|
|
+ //自动派单合同的托运单位等于当前登陆企业
|
|
|
+ logisticsScore.setProviderEntId(baseInfo.getProvideEntId());
|
|
|
+ logisticsScore.setLogisticsEntId(baseInfo.getPurchaseEntId());
|
|
|
+ EntCacheResDto logisticsEnt = entCacheResDtoMap.get(baseInfo.getPurchaseEntId());
|
|
|
+ logisticsScore.setLogisticsEntName(logisticsEnt != null ? logisticsEnt.getFirmName() : null);
|
|
|
+ logisticsScore.setScore(new BigDecimal(customConfig.getLogisticsInitScore()));
|
|
|
+ logisticsScore.setCreateBy(LoginUserHolder.getUserId());
|
|
|
+ Date date = new Date();
|
|
|
+ logisticsScore.setCreateTime(date);
|
|
|
+ logisticsScore.setUpdateBy(LoginUserHolder.getUserId());
|
|
|
+ logisticsScore.setUpdateTime(date);
|
|
|
+ //判断是否存在,存在则不创建
|
|
|
+ String lockKey = String.format(RedisConstant.LOGISTICS_SCORE_RECORD_INIT_KEY,logisticsScore.getProviderEntId(),logisticsScore.getLogisticsEntId());
|
|
|
+ if (Boolean.FALSE.equals(RedissonUtils.tryLock(lockKey, 5L, 10L))) {
|
|
|
+ throw new BusinessException("业务繁忙,请稍后再试!");
|
|
|
+ }
|
|
|
+ try {
|
|
|
+ if(kwcContractLogisticsScoreMapper.selectLogisticsScoreByEntId(baseInfo.getPurchaseEntId(),baseInfo.getPurchaseEntId())==null){
|
|
|
+ //初始化物流企业评分记录
|
|
|
+ kwcContractLogisticsScoreMapper.insertKwcContractLogisticsScore(logisticsScore);
|
|
|
+ //初始化物流企业评分明细
|
|
|
+ LogisticsScoreDetailAddDto detailDto = new LogisticsScoreDetailAddDto();
|
|
|
+ detailDto.setScoreId(scoreId);
|
|
|
+ detailDto.setInfluenceBy(LoginUserHolder.getUserId());
|
|
|
+ detailDto.setInfluenceByName(LoginUserHolder.getUserName());
|
|
|
+ detailDto.setAction("物流企业评分初始化");
|
|
|
+ detailDto.setScoreChange(logisticsScore.getScore());
|
|
|
+ detailDto.setScore(logisticsScore.getScore());
|
|
|
+ detailDto.setStatus(NumberConstant.ONE);
|
|
|
+ initLogisticsScoreDetail(detailDto);
|
|
|
+
|
|
|
+ //todo tys初始化司机评分,需要传参供应企业id,物流企业id,评分变动,变动原因
|
|
|
+ logisticsScore.getProviderEntId();
|
|
|
+ logisticsScore.getLogisticsEntId();
|
|
|
+ logisticsScore.getScore();
|
|
|
+ detailDto.getAction();
|
|
|
+ }
|
|
|
+ } finally {
|
|
|
+ RedissonUtils.unlock(lockKey);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void initLogisticsScoreDetail(LogisticsScoreDetailAddDto detailDto) {
|
|
|
+ KwcContractLogisticsScoreDetail logisticsScoreDetail = buildLogisticsScoreDetail(detailDto);
|
|
|
+ logisticsScoreDetail.setScore(logisticsScoreDetail.getScoreChange());
|
|
|
+ kwcContractLogisticsScoreDetailMapper.insertKwcContractLogisticsScoreDetail(logisticsScoreDetail);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 审批物流企业评分明细
|
|
|
+ *
|
|
|
+ * @param approvalDto 审批参数
|
|
|
+ * @param providerEntId 供应商企业id
|
|
|
+ * @return 结果
|
|
|
+ */
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
+ @Override
|
|
|
+ public void approvalLogisticsScoreDetail(LogisticsScoreApprovalDto approvalDto, Long providerEntId)
|
|
|
+ {
|
|
|
+ String lockKey = String.format(RedisConstant.LOGISTICS_SCORE_RECORD_APPROVAL_KEY,approvalDto.getScoreId());
|
|
|
+ if (Boolean.FALSE.equals(RedissonUtils.tryLock(lockKey, 5L, 10L))) {
|
|
|
+ throw new BusinessException("业务繁忙,请稍后再试!");
|
|
|
+ }
|
|
|
+ try {
|
|
|
+ //校验评分权限
|
|
|
+ KwcContractLogisticsScore logisticsScore = checkLogisticsScoreAuth(providerEntId,approvalDto.getScoreId());
|
|
|
+ KwcContractLogisticsScoreDetail logisticsScoreDetail = kwcContractLogisticsScoreDetailMapper.selectLogisticsPendingScoreDetail(approvalDto.getScoreId());
|
|
|
+ if(logisticsScoreDetail != null && Objects.equals(logisticsScoreDetail.getStatus(),NumberConstant.ZERO)){
|
|
|
+ if(approvalDto.getApproval()==0){
|
|
|
+ //驳回,清除待审核评分
|
|
|
+ kwcContractLogisticsScoreDetailMapper.deleteKwcContractLogisticsScoreDetailById(logisticsScoreDetail.getId(),NumberConstant.ZERO);
|
|
|
+ }else{
|
|
|
+ //通过
|
|
|
+ //校验分数扣减是否会超过上下限
|
|
|
+ BigDecimal score = logisticsScore.getScore();
|
|
|
+ BigDecimal resultScore = score.add(logisticsScoreDetail.getScoreChange());
|
|
|
+ double scoreDouble = resultScore.doubleValue();
|
|
|
+ if (scoreDouble < 0 || scoreDouble > 100) {
|
|
|
+ throw new BusinessException("通过后企业评分将超过100或小于0,请驳回");
|
|
|
+ }
|
|
|
+ //1、更新企业评分
|
|
|
+ logisticsScore.setScore(resultScore);
|
|
|
+ logisticsScore.setUpdateBy(LoginUserHolder.getUserId());
|
|
|
+ logisticsScore.setUpdateTime(new Date());
|
|
|
+ kwcContractLogisticsScoreMapper.updateKwcContractLogisticsScore(logisticsScore);
|
|
|
+ //2、修改待审评分状态
|
|
|
+ logisticsScoreDetail.setStatus(NumberConstant.ONE);
|
|
|
+ logisticsScoreDetail.setScore(resultScore);
|
|
|
+ logisticsScoreDetail.setUpdateBy(LoginUserHolder.getUserId());
|
|
|
+ logisticsScoreDetail.setUpdateTime(new Date());
|
|
|
+ kwcContractLogisticsScoreDetailMapper.updateKwcContractLogisticsScoreDetail(logisticsScoreDetail);
|
|
|
+ // todo tys更新司机评分 需要传参供应企业id,物流企业id,评分变动,变动原因
|
|
|
+ logisticsScore.getProviderEntId();
|
|
|
+ logisticsScore.getLogisticsEntId();
|
|
|
+ logisticsScoreDetail.getScoreChange();
|
|
|
+ logisticsScoreDetail.getAction();
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
+ }else{
|
|
|
+ throw new BusinessException("该评分已审批完成");
|
|
|
+ }
|
|
|
+ } finally {
|
|
|
+ RedissonUtils.unlock(lockKey);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 用户修改物流企业评分
|
|
|
+ *
|
|
|
+ * @param detailDto 物流企业评分
|
|
|
+ * @return 结果
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public boolean insertLogisticsScoreDetailByUser(LogisticsScoreDetailAddDto detailDto,Long providerEntId)
|
|
|
+ {
|
|
|
+ //校验评分权限
|
|
|
+ KwcContractLogisticsScore logisticsScore = checkLogisticsScoreAuth(providerEntId, detailDto.getScoreId());
|
|
|
+ String lockKey = String.format(RedisConstant.LOGISTICS_SCORE_RECORD_UPDATE_KEY,detailDto.getScoreId());
|
|
|
+ if (Boolean.FALSE.equals(RedissonUtils.tryLock(lockKey, 5L, 10L))) {
|
|
|
+ throw new BusinessException("业务繁忙,请稍后再试!");
|
|
|
+ }
|
|
|
+ try {
|
|
|
+ //校验是否已存在待审核评分
|
|
|
+ KwcContractLogisticsScoreDetail dbScoreDetail = kwcContractLogisticsScoreDetailMapper.selectLogisticsPendingScoreDetail(detailDto.getScoreId());
|
|
|
+ if(dbScoreDetail != null){
|
|
|
+ throw new BusinessException("修改评分失败,存在待审核评分未处理");
|
|
|
+ }
|
|
|
+ //校验分数扣减是否会超过上下限
|
|
|
+ BigDecimal score = logisticsScore.getScore();
|
|
|
+ double scoreDouble = score.add(detailDto.getScoreChange()).doubleValue();
|
|
|
+ if (scoreDouble < 0 || scoreDouble > 100) {
|
|
|
+ throw new BusinessException("修改评分失败,评分不能低于0分或超过100分");
|
|
|
+ }
|
|
|
+ //用户修改评分
|
|
|
+ detailDto.setInfluenceBy(LoginUserHolder.getUserId());
|
|
|
+ detailDto.setInfluenceByName(LoginUserHolder.getUserName());
|
|
|
+ detailDto.setStatus(NumberConstant.ZERO);
|
|
|
+ detailDto.setAction("修改企业评分,原因:"+detailDto.getAction());
|
|
|
+ KwcContractLogisticsScoreDetail logisticsScoreDetail = buildLogisticsScoreDetail(detailDto);
|
|
|
+ return SqlHelper.retBool(kwcContractLogisticsScoreDetailMapper.insertKwcContractLogisticsScoreDetail(logisticsScoreDetail));
|
|
|
+ } finally {
|
|
|
+ RedissonUtils.unlock(lockKey);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 系统修改物流企业评分
|
|
|
+ *
|
|
|
+ * @param detailDto 物流企业评分
|
|
|
+ * @return 结果
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public boolean updateLogisticsScoreBySystem(LogisticsScoreDetailFeignDto detailDto)
|
|
|
+ {
|
|
|
+ //1.根据供应商企业id和物流企业查询物流企业评分
|
|
|
+ KwcContractLogisticsScore logisticsScore = kwcContractLogisticsScoreMapper.selectLogisticsScoreByEntId(detailDto.getProviderEntId(),detailDto.getLogisticsEntId());
|
|
|
+ //1、更新企业评分
|
|
|
+ BigDecimal score = logisticsScore.getScore();
|
|
|
+ BigDecimal resultScore = score.add(detailDto.getScoreChange());
|
|
|
+ logisticsScore.setScore(resultScore);
|
|
|
+ logisticsScore.setUpdateBy(LoginUserHolder.getUserId());
|
|
|
+ logisticsScore.setUpdateTime(new Date());
|
|
|
+ kwcContractLogisticsScoreMapper.updateKwcContractLogisticsScore(logisticsScore);
|
|
|
+ //2.插入评分明细记录
|
|
|
+ LogisticsScoreDetailAddDto detailAddDto = new LogisticsScoreDetailAddDto();
|
|
|
+ detailAddDto.setScoreId(logisticsScore.getId());
|
|
|
+ detailAddDto.setInfluenceBy(detailDto.getInfluenceBy());
|
|
|
+ detailAddDto.setInfluenceByName(detailDto.getInfluenceByName());
|
|
|
+ detailAddDto.setAction(detailDto.getAction());
|
|
|
+ detailAddDto.setScoreChange(detailDto.getScoreChange());
|
|
|
+ detailAddDto.setScore(resultScore);
|
|
|
+ //2.设置评分状态为通过
|
|
|
+ detailAddDto.setStatus(NumberConstant.ONE);
|
|
|
+ //3.构建评分明细记录
|
|
|
+ KwcContractLogisticsScoreDetail logisticsScoreDetail = buildLogisticsScoreDetail(detailAddDto);
|
|
|
+ //4.插入数据
|
|
|
+ return SqlHelper.retBool(kwcContractLogisticsScoreDetailMapper.insertKwcContractLogisticsScoreDetail(logisticsScoreDetail));
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
+ @Override
|
|
|
+ public void resetLogisticsScore(Long scoreId, Long providerEntId)
|
|
|
+ {
|
|
|
+ //1.校验供应商企业评分权限
|
|
|
+ KwcContractLogisticsScore logisticsScore = checkLogisticsScoreAuth(providerEntId, scoreId);
|
|
|
+ String lockKey = String.format(RedisConstant.LOGISTICS_SCORE_RECORD_RESET_KEY,scoreId);
|
|
|
+ if (Boolean.FALSE.equals(RedissonUtils.tryLock(lockKey, 5L, 10L))) {
|
|
|
+ throw new BusinessException("业务繁忙,请稍后再试!");
|
|
|
+ }
|
|
|
+ try {
|
|
|
+ //2.修改企业评分为初始化分
|
|
|
+ logisticsScore.setScore(new BigDecimal(customConfig.getLogisticsInitScore()));
|
|
|
+ logisticsScore.setUpdateBy(LoginUserHolder.getUserId());
|
|
|
+ logisticsScore.setUpdateTime(new Date());
|
|
|
+ kwcContractLogisticsScoreMapper.updateKwcContractLogisticsScore(logisticsScore);
|
|
|
+ //3.评分明细中插入重置记录
|
|
|
+ KwcContractLogisticsScoreDetail resetLogisticsScoreDetail = buildResetLogisticsScoreDetail(scoreId);
|
|
|
+ kwcContractLogisticsScoreDetailMapper.insertKwcContractLogisticsScoreDetail(resetLogisticsScoreDetail);
|
|
|
+ //4.清除待审核评分
|
|
|
+ kwcContractLogisticsScoreDetailMapper.deleteKwcContractLogisticsScoreDetailByScoreId(logisticsScore.getId(),NumberConstant.ZERO);
|
|
|
+ //4.todo tys重置司机评分需要传参供应商企业id,物流企业id,重置评分,原因
|
|
|
+
|
|
|
+ } finally {
|
|
|
+ RedissonUtils.unlock(lockKey);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 构建重置评分记录明细
|
|
|
+ *
|
|
|
+ * @param scoreId 评分id
|
|
|
+ * @return 评分记录
|
|
|
+ */
|
|
|
+ private KwcContractLogisticsScoreDetail buildResetLogisticsScoreDetail(Long scoreId) {
|
|
|
+ KwcContractLogisticsScoreDetail logisticsScoreDetail = new KwcContractLogisticsScoreDetail();
|
|
|
+ long scoreDetailId = new IdWorker(1L).nextId();
|
|
|
+ logisticsScoreDetail.setId(scoreDetailId);
|
|
|
+ logisticsScoreDetail.setScoreId(scoreId);
|
|
|
+ logisticsScoreDetail.setInfluenceBy(LoginUserHolder.getUserId());
|
|
|
+ logisticsScoreDetail.setInfluenceByName(LoginUserHolder.getUserName());
|
|
|
+ logisticsScoreDetail.setAction("重置企业评分");
|
|
|
+ logisticsScoreDetail.setScore(new BigDecimal(customConfig.getLogisticsInitScore()));
|
|
|
+ logisticsScoreDetail.setScoreChange(null);
|
|
|
+ logisticsScoreDetail.setStatus(NumberConstant.ONE);
|
|
|
+ logisticsScoreDetail.setCreateBy(LoginUserHolder.getUserId());
|
|
|
+ logisticsScoreDetail.setCreateTime(new Date());
|
|
|
+ logisticsScoreDetail.setUpdateBy(LoginUserHolder.getUserId());
|
|
|
+ logisticsScoreDetail.setUpdateTime(new Date());
|
|
|
+ return logisticsScoreDetail;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ private KwcContractLogisticsScoreDetail buildLogisticsScoreDetail(LogisticsScoreDetailAddDto detailDto) {
|
|
|
+ KwcContractLogisticsScoreDetail logisticsScoreDetail = new KwcContractLogisticsScoreDetail();
|
|
|
+ long scoreDetailId = new IdWorker(1L).nextId();
|
|
|
+ logisticsScoreDetail.setId(scoreDetailId);
|
|
|
+ logisticsScoreDetail.setScoreId(detailDto.getScoreId());
|
|
|
+ logisticsScoreDetail.setInfluenceBy(detailDto.getInfluenceBy());
|
|
|
+ logisticsScoreDetail.setInfluenceByName(detailDto.getInfluenceByName());
|
|
|
+ logisticsScoreDetail.setAction(detailDto.getAction());
|
|
|
+ logisticsScoreDetail.setScoreChange(detailDto.getScoreChange());
|
|
|
+ logisticsScoreDetail.setScore(detailDto.getScore());
|
|
|
+ logisticsScoreDetail.setStatus(detailDto.getStatus());
|
|
|
+ logisticsScoreDetail.setCreateBy(LoginUserHolder.getUserId());
|
|
|
+ logisticsScoreDetail.setCreateTime(new Date());
|
|
|
+ logisticsScoreDetail.setUpdateBy(LoginUserHolder.getUserId());
|
|
|
+ logisticsScoreDetail.setUpdateTime(new Date());
|
|
|
+ return logisticsScoreDetail;
|
|
|
+ }
|
|
|
+}
|