diff --git a/src/main/java/com/sztzjy/linkCommerce/controller/stu/CptfController.java b/src/main/java/com/sztzjy/linkCommerce/controller/stu/CptfController.java index f61b682..93223a4 100644 --- a/src/main/java/com/sztzjy/linkCommerce/controller/stu/CptfController.java +++ b/src/main/java/com/sztzjy/linkCommerce/controller/stu/CptfController.java @@ -1,9 +1,12 @@ package com.sztzjy.linkCommerce.controller.stu; import cn.hutool.core.util.IdUtil; +import com.alibaba.fastjson.JSON; import com.sztzjy.linkCommerce.annotation.AnonymousAccess; import com.sztzjy.linkCommerce.config.Constant; import com.sztzjy.linkCommerce.entity.*; +import com.sztzjy.linkCommerce.entity.dto.FbqdDTO; +import com.sztzjy.linkCommerce.entity.dto.FbqdStuAnswerDTO; import com.sztzjy.linkCommerce.mapper.*; import com.sztzjy.linkCommerce.service.ScoreService; import com.sztzjy.linkCommerce.util.CompareListsUtil; @@ -22,9 +25,11 @@ import org.springframework.web.multipart.MultipartFile; import javax.annotation.Resource; import java.math.BigDecimal; +import java.util.ArrayList; import java.util.Date; import java.util.List; import java.util.UUID; +import java.util.stream.Collectors; /** * @author 17803 @@ -59,73 +64,58 @@ public class CptfController { @PostMapping("/commitCpdjAnswer") @ApiOperation("发布渠道-提交") @AnonymousAccess - public ResultEntity commitFbqdAnswer(@RequestBody FbqdStuAnswer stuAnswer) { +// public ResultEntity commitFbqdAnswer(@RequestBody FbqdStuAnswer stuAnswer,FbqdStuAnswerDTO fbqdStuAnswerDTO) { + public ResultEntity commitCpdjAnswer(@RequestBody FbqdStuAnswerDTO fbqdStuAnswerDTO) { //先查询是否提交过 StuGradeExample stuGradeExample = new StuGradeExample(); - stuGradeExample.createCriteria().andUserIdEqualTo(stuAnswer.getUserId()).andProjectEqualTo(Constant.PRO_CPTFCS).andModuleEqualTo(Constant.MODULE_CPDJ); + stuGradeExample.createCriteria().andUserIdEqualTo(fbqdStuAnswerDTO.getUserId()).andProjectEqualTo(Constant.PRO_CPTFCS).andModuleEqualTo(Constant.MODULE_CPDJ); List stuGradeList = stuGradeMapper.selectByExampleWithBLOBs(stuGradeExample); if(CollectionUtils.isEmpty(stuGradeList)){ - FbqdAnswer answer = fbqdAnswerMapper.selectByExampleWithBLOBs(new FbqdAnswerExample()).get(0); +// FbqdAnswer answer = fbqdAnswerMapper.selectByExampleWithBLOBs(new FbqdAnswerExample()).get(0); int count = 0; - //1.数据标准化结果 - String stuExposureData = stuAnswer.getExposureData(); + //1. + List dataInfoList = fbqdStuAnswerDTO.getDataInfoList(); + String oneAnswer = "1,1,1,1,0,0,0.1965,0.3565,0.3767,0.9430,0,0"; + int count1 = calculte(dataInfoList,1,oneAnswer); - String exposureData = answer.getExposureData(); - //数据标准化结果 校验 - - //错误次数 - int monthlyDataErrorCount =compareListsUtil.compareErrorCount(stuExposureData, exposureData).getErrorCount(); - count = count + monthlyDataErrorCount; - - - //2.渠道中的比重 - String stuAnswerClickData = stuAnswer.getClickData(); - - String clickData = answer.getClickData(); - //错误次数 - int cheapSumCount =compareListsUtil.compareErrorCount(stuAnswerClickData, clickData).getErrorCount(); - count = count + cheapSumCount; + //2. + List radioInfoList = fbqdStuAnswerDTO.getRadioInfoList(); + String twoAnswer = "0.7264,0.5147,0.8358,0.7372,0,0,0.1642,0.2628,0.2736,0.4853,0,0"; + int count2 = calculte(radioInfoList,2,twoAnswer); - //3.信息滴 - String stuAnswerAdCost = stuAnswer.getAdCost(); + //3. + List messageInfoList = fbqdStuAnswerDTO.getMessageInfoList(); + String threeAnswer = "0.6305,0.5342,0.4066,0.5243"; + int count3 =calculte(messageInfoList,3,threeAnswer); - String adCost = answer.getAdCost(); - //错误次数 - int cheapPercentageCount =compareListsUtil.compareErrorCount(stuAnswerAdCost, adCost).getErrorCount(); - count = count + cheapPercentageCount; + //4. + List eventInfoList = fbqdStuAnswerDTO.getEventInfoList(); + String fourAnswer = "0.1940,0.2446,0.3116,0.2498"; + int count4 = calculte(eventInfoList,4,fourAnswer); + //5.综合评分 + String fiveAnswer = "1,0.1503,0.2751"; - //每个指标的权重 - String stuAnswerOrderAmount = stuAnswer.getOrderAmount(); - - String orderAmount = answer.getOrderAmount(); - //错误次数 - int costEffectiveSumCount =compareListsUtil.compareErrorCount(stuAnswerOrderAmount, orderAmount).getErrorCount(); - count = count + costEffectiveSumCount; + int fiveCount = compareListsUtil.compareErrorCount(fbqdStuAnswerDTO.getKeywords(), fiveAnswer).getErrorCount(); - - //综合评分 - String stuAnswerKeywords = stuAnswer.getKeywords(); - - String keywords = answer.getKeywords(); - //错误次数 - int costEffectivePercentageCount =compareListsUtil.compareErrorCount(stuAnswerKeywords, keywords).getErrorCount(); - count = count + costEffectivePercentageCount; + //主观题 + int i = compareListsUtil.calculateLengthPenaltyEnhanced(fbqdStuAnswerDTO.getScenePromotion()); + count= count1 + count2+count3+count4+i + fiveCount; - //主观题 - int i = compareListsUtil.calculateLengthPenaltyEnhanced(stuAnswer.getScenePromotion()); - count = count + i; - stuAnswer.setId(IdUtil.simpleUUID()); + FbqdStuAnswer fbqdStuAnswer = new FbqdStuAnswer(); + fbqdStuAnswer.setId(IdUtil.simpleUUID()); + fbqdStuAnswer.setUserId(fbqdStuAnswerDTO.getUserId()); - fbqdStuAnswerMapper.insertSelective(stuAnswer); + fbqdStuAnswer.setCrowdPromotion( JSON.toJSONString(fbqdStuAnswerDTO)); + fbqdStuAnswerMapper.insertSelective(fbqdStuAnswer); - Boolean aBoolean = scoreService.insertScore(stuAnswer.getUserId(), Constant.PRO_CPTFCS, Constant.MODULE_FBQDPG, BigDecimal.valueOf(100 - count), stuAnswer.getScenePromotion()); + Boolean aBoolean = scoreService.insertScore(fbqdStuAnswerDTO.getUserId(), Constant.PRO_CPTFCS, Constant.MODULE_FBQDPG, BigDecimal.valueOf(100 - count), fbqdStuAnswerDTO.getScenePromotion()); if(aBoolean){ return new ResultEntity<>(HttpStatus.OK, "提交成功"); }else { @@ -151,7 +141,10 @@ public class CptfController { if (CollectionUtils.isEmpty(stuAnswerList)) { return new ResultEntity<>(HttpStatus.OK); } else { - return new ResultEntity<>(HttpStatus.OK, stuAnswerList.get(0)); + String crowdPromotion = stuAnswerList.get(0).getCrowdPromotion(); + // 从字符串解析回对象 + FbqdStuAnswerDTO parsedDTO = JSON.parseObject(crowdPromotion, FbqdStuAnswerDTO.class); + return new ResultEntity<>(HttpStatus.OK, parsedDTO); } } @@ -411,5 +404,41 @@ public class CptfController { +public Integer calculte( List dataInfoList,Integer ser,String answer ) { + int count = 0; + if (CollectionUtils.isEmpty(dataInfoList)) { + if (ser==1) + { + return 12; + } + if (ser==2) + { + return 12; + } + if (ser==3) + { + return 4; + } + if (ser==4) + { + return 4; + } + return 0; + } else { + List array = new ArrayList<>(); // 确保使用 List 并初始化 + + for (FbqdDTO fbqdDTO : dataInfoList) { + array.add(fbqdDTO.getExposureData()); + array.add(fbqdDTO.getClickData()); + array.add(fbqdDTO.getAdCost()); + array.add(fbqdDTO.getOrderAmount()); + } + String[] array1 = array.toArray(new String[0]); // 正确转换为 String[] + String result = String.join(",", array1); + int monthlyDataErrorCount = compareListsUtil.compareErrorCount(result, answer).getErrorCount(); + count = count + monthlyDataErrorCount; + return count; + } + } } diff --git a/src/main/java/com/sztzjy/linkCommerce/entity/FbqdStuAnswer.java b/src/main/java/com/sztzjy/linkCommerce/entity/FbqdStuAnswer.java index 60741ca..c8110cb 100644 --- a/src/main/java/com/sztzjy/linkCommerce/entity/FbqdStuAnswer.java +++ b/src/main/java/com/sztzjy/linkCommerce/entity/FbqdStuAnswer.java @@ -1,6 +1,9 @@ package com.sztzjy.linkCommerce.entity; import io.swagger.annotations.ApiModelProperty; + +import java.util.List; + /** * 发布渠道分析结果表(含多维度投放数据) * @@ -17,16 +20,16 @@ public class FbqdStuAnswer { @ApiModelProperty(notes = "用户ID(关联userinfo表)") private String userId; - @ApiModelProperty(notes = "1.数据标准化结果(以逗号隔开,没做就为空)") + @ApiModelProperty(notes = "曝光量") private String exposureData; - @ApiModelProperty(notes = "2.每个渠道中的比重(以逗号隔开,没做就为空)") + @ApiModelProperty(notes = "点击量") private String clickData; - @ApiModelProperty(notes = "3.每个指标的信息熵(以逗号隔开,没做就为空)") + @ApiModelProperty(notes = "花费") private String adCost; - @ApiModelProperty(notes = "4.计算每个指标的权重(以逗号隔开,没做就为空)") + @ApiModelProperty(notes = "订单金额") private String orderAmount; @ApiModelProperty(notes = "5.综合评分(以逗号隔开,没做就为空)") diff --git a/src/main/java/com/sztzjy/linkCommerce/entity/dto/FbqdDTO.java b/src/main/java/com/sztzjy/linkCommerce/entity/dto/FbqdDTO.java new file mode 100644 index 0000000..4b828c0 --- /dev/null +++ b/src/main/java/com/sztzjy/linkCommerce/entity/dto/FbqdDTO.java @@ -0,0 +1,25 @@ +package com.sztzjy.linkCommerce.entity.dto; + +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +/** + * @author 17803 + * @date 2025-05-01 15:57 + */ +@Data +public class FbqdDTO { + + @ApiModelProperty(notes = "曝光量") + private String exposureData; + + @ApiModelProperty(notes = "点击量") + private String clickData; + + @ApiModelProperty(notes = "花费") + private String adCost; + + @ApiModelProperty(notes = "订单金额") + private String orderAmount; + +} diff --git a/src/main/java/com/sztzjy/linkCommerce/entity/dto/FbqdStuAnswerDTO.java b/src/main/java/com/sztzjy/linkCommerce/entity/dto/FbqdStuAnswerDTO.java new file mode 100644 index 0000000..ecd1007 --- /dev/null +++ b/src/main/java/com/sztzjy/linkCommerce/entity/dto/FbqdStuAnswerDTO.java @@ -0,0 +1,42 @@ +package com.sztzjy.linkCommerce.entity.dto; + +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +import java.util.List; + +/** + * @author 17803 + * @date 2025-05-01 15:56 + */ +@Data +public class FbqdStuAnswerDTO { + + + + @ApiModelProperty(notes = "1.数据标准化结果") + private List dataInfoList; + + + @ApiModelProperty(notes = "2.每个渠道中的比重") + private List radioInfoList; + + @ApiModelProperty(notes = "3.计算每个指标的信息熵") + private List messageInfoList; + + + @ApiModelProperty(notes = "4.计算每个指标的权重") + private List eventInfoList; + + + @ApiModelProperty(notes = "5.综合评分(以逗号隔开,没做就为空)") + private String keywords; + + @ApiModelProperty(notes = "6.主观题") + private String scenePromotion; + + @ApiModelProperty(notes = "用户ID(关联userinfo表)") + private String userId; + + +}