|
|
@@ -8,16 +8,18 @@ import com.td.boss.game.complayerprofit.pojo.ComPlayerProfit;
|
|
|
import com.td.boss.game.complayerprofit.vo.ComPlayerProfitVo;
|
|
|
import com.td.boss.game.complayerprofit.repository.ComPlayerProfitRepository;
|
|
|
import com.td.boss.util.CopyUtil;
|
|
|
+import com.td.boss.util.DoubleUtil;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
+
|
|
|
import javax.persistence.EntityManager;
|
|
|
import javax.persistence.PersistenceContext;
|
|
|
import java.util.List;
|
|
|
|
|
|
@Service
|
|
|
@Transactional
|
|
|
-public class ComPlayerProfitServiceImpl extends CommonServiceImpl<ComPlayerProfitVo, ComPlayerProfit, String> implements ComPlayerProfitService{
|
|
|
+public class ComPlayerProfitServiceImpl extends CommonServiceImpl<ComPlayerProfitVo, ComPlayerProfit, String> implements ComPlayerProfitService {
|
|
|
|
|
|
@PersistenceContext
|
|
|
private EntityManager em;
|
|
|
@@ -29,39 +31,43 @@ public class ComPlayerProfitServiceImpl extends CommonServiceImpl<ComPlayerProfi
|
|
|
|
|
|
@Override
|
|
|
public List<ComPlayerProfit> findByUserIdAndPlantFlagAndLandId(String userId, String plantFlag, Integer landId) {
|
|
|
- return comPlayerProfitRepository.findByTargetIdAndPlantFlagAndLandId(userId,plantFlag,landId);
|
|
|
+ return comPlayerProfitRepository.findByTargetIdAndPlantFlagAndLandId(userId, plantFlag, landId);
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public ComPlayerProfit findByUserIdAndPlantFlag(String userId,String plantFlag) {
|
|
|
- return comPlayerProfitRepository.findByUserIdAndPlantFlag(userId,plantFlag).orElse(null);
|
|
|
+ public ComPlayerProfit findByUserIdAndPlantFlag(String userId, String plantFlag) {
|
|
|
+ return comPlayerProfitRepository.findByUserIdAndPlantFlag(userId, plantFlag).orElse(null);
|
|
|
}
|
|
|
+
|
|
|
@Override
|
|
|
- public ComPlayerProfit findByUserIdAndOtherUserIdAndPlantFlag(String userId,String otherUserId, String plantFlag) {
|
|
|
- return comPlayerProfitRepository.findByUserIdAndTargetIdAndPlantFlag(userId,otherUserId,plantFlag).orElse(null);
|
|
|
+ public ComPlayerProfit findByUserIdAndOtherUserIdAndPlantFlag(String userId, String otherUserId, String plantFlag) {
|
|
|
+ return comPlayerProfitRepository.findByUserIdAndTargetIdAndPlantFlag(userId, otherUserId, plantFlag).orElse(null);
|
|
|
}
|
|
|
|
|
|
|
|
|
@Override
|
|
|
- public ComPlayerProfit findByUserIdAndTargetIdAndLandIdAndPlantFlag(String userId,String targetId, Integer configLandId, String plantFlag) {
|
|
|
- return comPlayerProfitRepository.findByUserIdAndTargetIdAndLandIdAndPlantFlag(userId,targetId,configLandId,plantFlag).orElse(null);
|
|
|
+ public ComPlayerProfit findByUserIdAndTargetIdAndLandIdAndPlantFlag(String userId, String targetId, Integer configLandId, String plantFlag) {
|
|
|
+ return comPlayerProfitRepository.findByUserIdAndTargetIdAndLandIdAndPlantFlag(userId, targetId, configLandId, plantFlag).orElse(null);
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public ComPlayerProfit findByPlantFlagAndLossType(String plantFlag, Integer lossType){
|
|
|
- return comPlayerProfitRepository.findByPlantFlagAndLossType(plantFlag, lossType).orElse(null);
|
|
|
+ public ComPlayerProfit findByPlantFlagAndLossType(String plantFlag, Integer lossType) {
|
|
|
+ return comPlayerProfitRepository.findByPlantFlagAndLossType(plantFlag, lossType).orElse(null);
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public Double getStolenSumByOtherUserIdAndPlantFlag(String otherUserId, String plantFlag) {
|
|
|
- return comPlayerProfitRepository.getStolenSumByTargetIdAndPlantFlag(otherUserId,plantFlag);
|
|
|
+ return comPlayerProfitRepository.getStolenSumByTargetIdAndPlantFlag(otherUserId, plantFlag);
|
|
|
}
|
|
|
|
|
|
|
|
|
@Override
|
|
|
- public ComPlayerProfitVo addDisasterAndLoss(ComPlayerLand comPlayerLand, ComMallSeedVo comMallSeedVo,Integer lossType) {
|
|
|
-
|
|
|
+ public ComPlayerProfitVo addFirstDisasterAndLoss(ComPlayerLand comPlayerLand, ComMallSeedVo comMallSeedVo, Integer lossType, Double allLossProfit) {
|
|
|
|
|
|
+ //对应土地灾害损失
|
|
|
+ ComPlayerProfit comPlayerProfit = new ComPlayerProfit();
|
|
|
+ //最终减扣的利润
|
|
|
+ Double _endReduceProfit = 0d;
|
|
|
//计算一个偷取的收获量, 租赁倍数* 租赁日期下的产量
|
|
|
Integer _otherAmount = 0;
|
|
|
if (comPlayerLand.getLeaseDate().equals(1)) {
|
|
|
@@ -71,10 +77,80 @@ public class ComPlayerProfitServiceImpl extends CommonServiceImpl<ComPlayerProfi
|
|
|
} else if (comPlayerLand.getLeaseDate().equals(3)) {
|
|
|
_otherAmount = comPlayerLand.getLeaseMultiple() * comMallSeedVo.getHarvest3();
|
|
|
}
|
|
|
- //todo 拿出计算利润,收获量减去种子的成本(snb)后的百分之30 ,后面需要后台可调整
|
|
|
+ //todo 拿出全部利润
|
|
|
Integer _profit = _otherAmount - comPlayerLand.getLeaseMultiple() * comMallSeedVo.getPriceSnb();
|
|
|
+ //todo 计算减产,第一次灾难按利润的 50% 减产,两次就是减到 0 了。
|
|
|
+
|
|
|
+ //必然发生的灾难,减产50%
|
|
|
+ Double _reduceProfit = DoubleUtil.mul(_profit.doubleValue(), 0.5);
|
|
|
+ // 100 - 80 = 20
|
|
|
+ Double _residualProfit = DoubleUtil.sub(_profit.doubleValue(), allLossProfit);
|
|
|
+ //剩余利润减去当前需要减产的利润值
|
|
|
+ Double _tempProfit = DoubleUtil.sub(_residualProfit, _reduceProfit);
|
|
|
+ if (DoubleUtil.compare(_tempProfit, 0.0).equals(1)) {
|
|
|
+ //还有利润,
|
|
|
+ _endReduceProfit = _reduceProfit;
|
|
|
+ }
|
|
|
+
|
|
|
+ comPlayerProfit.setUserId(comPlayerLand.getUserId()); //损失记录的用户id
|
|
|
+ comPlayerProfit.setTargetId(comPlayerLand.getUserId()); //目标是自己
|
|
|
+ comPlayerProfit.setPlantFlag(comPlayerLand.getPlantFlag());
|
|
|
+ comPlayerProfit.setLandId(comPlayerLand.getConfigLandId());
|
|
|
+ comPlayerProfit.setLeaseMultiple(comPlayerLand.getLeaseMultiple());
|
|
|
+ comPlayerProfit.setLeaseDate(comPlayerLand.getLeaseDate());
|
|
|
+ comPlayerProfit.setHarvest(_otherAmount); // todo
|
|
|
+ comPlayerProfit.setProfit(_profit.doubleValue());//todo 目标用户可偷的初始利润值
|
|
|
+ comPlayerProfit.setStolen(_endReduceProfit);//todo 目标用户被灾害减产对应的数量
|
|
|
+ comPlayerProfit.setFinalSteal(_endReduceProfit);//
|
|
|
+ comPlayerProfit.setProfitAfter(DoubleUtil.add(allLossProfit, _endReduceProfit)); //当前损失的利润加上当前扣减的
|
|
|
+
|
|
|
+ //记录相关比例,损失利润的百分之50
|
|
|
+ comPlayerProfit.setProfitRatio(0.5);
|
|
|
+ comPlayerProfit.setStealRatio(0.5);
|
|
|
+ comPlayerProfit.setFinalRatio(1.0);
|
|
|
+ comPlayerProfit.setLossType(lossType);
|
|
|
+ ComPlayerProfitVo comPlayerProfitVo = CopyUtil.copy(comPlayerProfit, ComPlayerProfitVo.class);
|
|
|
+ comPlayerProfitService.save(comPlayerProfitVo);
|
|
|
+
|
|
|
+ return comPlayerProfitVo;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public ComPlayerProfitVo addOtherDisasterAndLoss(ComPlayerLand comPlayerLand, ComMallSeedVo comMallSeedVo, Integer lossType, Double allLossProfit, Integer disasterCount) {
|
|
|
+
|
|
|
//对应土地灾害损失
|
|
|
ComPlayerProfit comPlayerProfit = new ComPlayerProfit();
|
|
|
+ //最终减扣的利润
|
|
|
+ Double _endReduceProfit = 0d;
|
|
|
+ //计算一个偷取的收获量, 租赁倍数* 租赁日期下的产量
|
|
|
+ Integer _otherAmount = 0;
|
|
|
+ if (comPlayerLand.getLeaseDate().equals(1)) {
|
|
|
+ _otherAmount = comPlayerLand.getLeaseMultiple() * comMallSeedVo.getHarvest1();
|
|
|
+ } else if (comPlayerLand.getLeaseDate().equals(2)) {
|
|
|
+ _otherAmount = comPlayerLand.getLeaseMultiple() * comMallSeedVo.getHarvest2();
|
|
|
+ } else if (comPlayerLand.getLeaseDate().equals(3)) {
|
|
|
+ _otherAmount = comPlayerLand.getLeaseMultiple() * comMallSeedVo.getHarvest3();
|
|
|
+ }
|
|
|
+ //todo 拿出全部利润
|
|
|
+ Integer _profit = _otherAmount - comPlayerLand.getLeaseMultiple() * comMallSeedVo.getPriceSnb();
|
|
|
+ //todo 计算减产,第一次灾难按利润的 50% 减产,两次就是减到 0 了。
|
|
|
+
|
|
|
+ //额外发生的灾难,按照次数计算减产 50% 发生已经发生1次计算后当次等于 25%,
|
|
|
+ double _startRatio = 1.0;
|
|
|
+ for(int i = disasterCount;i>0;i--){
|
|
|
+ _startRatio = DoubleUtil.mul(_startRatio,0.5);
|
|
|
+ }
|
|
|
+ Double _reduceProfit = DoubleUtil.mul(_profit.doubleValue(), _startRatio);
|
|
|
+ // 100 - 80 = 20
|
|
|
+ Double _residualProfit = DoubleUtil.sub(_profit.doubleValue(), allLossProfit);
|
|
|
+ //剩余利润减去当前需要减产的利润值
|
|
|
+ Double _tempProfit = DoubleUtil.sub(_residualProfit, _reduceProfit);
|
|
|
+ if (DoubleUtil.compare(_tempProfit, 0.0).equals(1)) {
|
|
|
+ //还有利润,
|
|
|
+ _endReduceProfit = _reduceProfit;
|
|
|
+ }
|
|
|
+
|
|
|
comPlayerProfit.setUserId(comPlayerLand.getUserId()); //损失记录的用户id
|
|
|
comPlayerProfit.setTargetId(comPlayerLand.getUserId()); //目标是自己
|
|
|
comPlayerProfit.setPlantFlag(comPlayerLand.getPlantFlag());
|
|
|
@@ -83,13 +159,14 @@ public class ComPlayerProfitServiceImpl extends CommonServiceImpl<ComPlayerProfi
|
|
|
comPlayerProfit.setLeaseDate(comPlayerLand.getLeaseDate());
|
|
|
comPlayerProfit.setHarvest(_otherAmount); // todo
|
|
|
comPlayerProfit.setProfit(_profit.doubleValue());//todo 目标用户可偷的初始利润值
|
|
|
- comPlayerProfit.setStolen(0d);//todo 目标用户被灾害减产对应的数量
|
|
|
- comPlayerProfit.setFinalSteal(0d);//
|
|
|
- comPlayerProfit.setProfitAfter(0d); //可偷的减去被偷的
|
|
|
- //记录相关比例
|
|
|
- comPlayerProfit.setProfitRatio(0d);
|
|
|
- comPlayerProfit.setStealRatio(0d);
|
|
|
- comPlayerProfit.setFinalRatio(0d);
|
|
|
+ comPlayerProfit.setStolen(_endReduceProfit);//todo 目标用户被灾害减产对应的数量
|
|
|
+ comPlayerProfit.setFinalSteal(_endReduceProfit);//
|
|
|
+ comPlayerProfit.setProfitAfter(DoubleUtil.add(allLossProfit, _endReduceProfit)); //当前损失的利润加上当前扣减的
|
|
|
+
|
|
|
+ //记录相关比例,损失利润的 _startRatio 相关比例
|
|
|
+ comPlayerProfit.setProfitRatio(_startRatio);
|
|
|
+ comPlayerProfit.setStealRatio(_startRatio);
|
|
|
+ comPlayerProfit.setFinalRatio(1.0);
|
|
|
comPlayerProfit.setLossType(lossType);
|
|
|
ComPlayerProfitVo comPlayerProfitVo = CopyUtil.copy(comPlayerProfit, ComPlayerProfitVo.class);
|
|
|
comPlayerProfitService.save(comPlayerProfitVo);
|