diff --git a/jeecg-module-main/src/main/java/org/jeecg/modules/kc/grab/SynchronizationService/WjxDjTask.java b/jeecg-module-main/src/main/java/org/jeecg/modules/kc/grab/SynchronizationService/WjxDjTask.java new file mode 100644 index 00000000..758ab24a --- /dev/null +++ b/jeecg-module-main/src/main/java/org/jeecg/modules/kc/grab/SynchronizationService/WjxDjTask.java @@ -0,0 +1,55 @@ +package org.jeecg.modules.kc.grab.SynchronizationService; + +import cn.hutool.core.date.DateUtil; +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; +import lombok.extern.slf4j.Slf4j; +import org.jeecg.modules.kc.grab.SynchronizationService.base.BaseSync; +import org.jeecg.modules.kc.kcGongkaike.entity.KcGongkaike; +import org.jeecg.modules.kc.kcGongkaike.service.IKcGongkaikeService; +import org.jeecg.modules.kc.wjxDjxx.service.IWjxDjxxService; +import org.quartz.JobExecutionContext; +import org.springframework.beans.factory.annotation.Autowired; + +import java.util.Calendar; +import java.util.Date; +import java.util.List; +import java.util.Map; + +/** + * 问卷星-答卷查询定时任务 + */ +@Slf4j +public class WjxDjTask extends BaseSync { + + @Autowired + private IWjxDjxxService wjxDjxxService; + + /** + * 若参数变量名修改 QuartzJobController中也需对应修改 + */ + + @Override + public void execute(JobExecutionContext jobExecutionContext) { + start(); + run(getParamMap()); + end(); + } + + + /** + * 有参定时任务实现 + * @param param + */ + public void run(Map param){ + //答卷查询 + wjxDjxxService.doDjSelect(); + } + + /** + * 无参定时任务实现 + */ + public void run(){ + run(null); + } + +} diff --git a/jeecg-module-main/src/main/java/org/jeecg/modules/kc/wjxDjxx/controller/WjxDjxxController.java b/jeecg-module-main/src/main/java/org/jeecg/modules/kc/wjxDjxx/controller/WjxDjxxController.java new file mode 100644 index 00000000..0182f58f --- /dev/null +++ b/jeecg-module-main/src/main/java/org/jeecg/modules/kc/wjxDjxx/controller/WjxDjxxController.java @@ -0,0 +1,51 @@ +package org.jeecg.modules.kc.wjxDjxx.controller; + +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiOperation; +import lombok.extern.slf4j.Slf4j; +import org.apache.shiro.SecurityUtils; +import org.jeecg.common.api.vo.Result; +import org.jeecg.common.system.base.controller.JeecgController; +import org.jeecg.common.system.vo.LoginUser; +import org.jeecg.modules.kc.wjxDjxx.entity.WjxDjxx; +import org.jeecg.modules.kc.wjxDjxx.entity.WjxDjxxTmlbPage; +import org.jeecg.modules.kc.wjxDjxx.service.IWjxDjxxService; +import org.jeecg.modules.kc.wjxWjxxTmlb.entity.WjxWjxxTmlb; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.*; + +import java.util.Date; +import java.util.List; + +/** +* @Description: 答卷信息 +* @Author: jeecg-boot +* @Date: 2024-05-07 +* @Version: V1.0 +*/ +@Api(tags="答卷信息") +@RestController +@RequestMapping("/wjxDjxx") +@Slf4j +public class WjxDjxxController extends JeecgController { + @Autowired + private IWjxDjxxService wjxDjxxService; + + @ApiOperation(value="答卷提交", notes="答卷提交") + @PostMapping(value = "/djtj") + public Result djtj(@RequestBody List list) { + String res = "提交成功!"; + if(list.size()>0) { + res = wjxDjxxService.djtj(list); + } + return Result.OK(res); + } + + @ApiOperation(value="选项信息主表ID查询", notes="选项信息-通主表ID查询") + @GetMapping(value = "/queryByMainId") + public Result queryByMainId(@RequestParam(name="id",required=true) String id) { + WjxDjxx wjxDjxx = wjxDjxxService.queryByMainId(id); + return Result.OK(wjxDjxx); + } + +} diff --git a/jeecg-module-main/src/main/java/org/jeecg/modules/kc/wjxDjxx/entity/WjxDjxx.java b/jeecg-module-main/src/main/java/org/jeecg/modules/kc/wjxDjxx/entity/WjxDjxx.java new file mode 100644 index 00000000..a64455ae --- /dev/null +++ b/jeecg-module-main/src/main/java/org/jeecg/modules/kc/wjxDjxx/entity/WjxDjxx.java @@ -0,0 +1,84 @@ +package org.jeecg.modules.kc.wjxDjxx.entity; + +import com.baomidou.mybatisplus.annotation.IdType; +import com.baomidou.mybatisplus.annotation.TableField; +import com.baomidou.mybatisplus.annotation.TableId; +import com.fasterxml.jackson.annotation.JsonFormat; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; +import org.jeecgframework.poi.excel.annotation.Excel; +import org.springframework.format.annotation.DateTimeFormat; + +import java.util.Date; +import java.util.List; + +/** + * @Description: 学生答卷信息 + * @Author: jeecg-boot + * @Date: 2024-05-7 + * @Version: V1.0 + */ +@Data +@ApiModel(value="wjx_djxx对象", description="学生答卷信息") +public class WjxDjxx { + private static final long serialVersionUID = 1L; + @TableId(type = IdType.ASSIGN_ID) + @ApiModelProperty(value = "id") + private java.lang.String id; + @ApiModelProperty(value = "创建人") + private String createBy; + @JsonFormat(timezone = "GMT+8",pattern = "yyyy-MM-dd HH:mm:ss") + @DateTimeFormat(pattern="yyyy-MM-dd HH:mm:ss") + @ApiModelProperty(value = "创建时间") + private Date createTime; + @ApiModelProperty(value = "修改人") + private String updateBy; + @JsonFormat(timezone = "GMT+8",pattern = "yyyy-MM-dd HH:mm:ss") + @DateTimeFormat(pattern="yyyy-MM-dd HH:mm:ss") + @ApiModelProperty(value = "修改时间") + private Date updateTime; + @ApiModelProperty(value = "vid") + private String vid; + @ApiModelProperty(value = "答卷人ID") + private String userId; + @ApiModelProperty(value = "答卷人姓名") + private String userName; + @JsonFormat(timezone = "GMT+8",pattern = "yyyy-MM-dd HH:mm:ss") + @DateTimeFormat(pattern="yyyy-MM-dd HH:mm:ss") + @ApiModelProperty(value = "打开时间") + private Date openTime; + @JsonFormat(timezone = "GMT+8",pattern = "yyyy-MM-dd HH:mm:ss") + @DateTimeFormat(pattern="yyyy-MM-dd HH:mm:ss") + @ApiModelProperty(value = "提交时间") + private Date commitTime; + @Excel(name = "提交内容", width = 15) + @ApiModelProperty(value = "提交内容") + private String submitData; + @Excel(name = "答卷编号", width = 15) + @ApiModelProperty(value = "答卷编号") + private String jid; + @Excel(name = "考试分数", width = 15) + @ApiModelProperty(value = "考试分数") + private double score; + @Excel(name = "考卷总分", width = 15) + @ApiModelProperty(value = "考卷总分") + private double totalScore; + @Excel(name = "问卷作答用时", width = 15) + @ApiModelProperty(value = "问卷作答用时") + private int answerSeconds; + @Excel(name = "问卷类型", width = 15) + @ApiModelProperty(value = "问卷类型") + @TableField(exist = false) + private String atype; + @Excel(name = "问卷名称", width = 15) + @ApiModelProperty(value = "问卷名称") + @TableField(exist = false) + private String title; + @ApiModelProperty(value = "问卷作答用时时分秒") + private String answerSfm; + + @TableField(exist = false) + private List wjxDjxxTmxxList; + +} diff --git a/jeecg-module-main/src/main/java/org/jeecg/modules/kc/wjxDjxx/entity/WjxDjxxTmlbPage.java b/jeecg-module-main/src/main/java/org/jeecg/modules/kc/wjxDjxx/entity/WjxDjxxTmlbPage.java new file mode 100644 index 00000000..4becc665 --- /dev/null +++ b/jeecg-module-main/src/main/java/org/jeecg/modules/kc/wjxDjxx/entity/WjxDjxxTmlbPage.java @@ -0,0 +1,50 @@ +package org.jeecg.modules.kc.wjxDjxx.entity; + +import com.fasterxml.jackson.annotation.JsonFormat; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; +import org.jeecg.modules.kc.wjxWjxxTmlb.entity.WjxWjxxTmxx; +import org.jeecgframework.poi.excel.annotation.Excel; +import org.jeecgframework.poi.excel.annotation.ExcelCollection; +import org.springframework.format.annotation.DateTimeFormat; + +import java.util.Date; +import java.util.List; + +/** + * @Description: 题目信息 + * @Author: jeecg-boot + * @Date: 2024-04-26 + * @Version: V1.0 + */ +@Data +@ApiModel(value="wjx_wjxx_tmlbPage对象", description="题目信息") +public class WjxDjxxTmlbPage { + + /**id*/ + @ApiModelProperty(value = "vid") + private String vid; + /**创建时间*/ + @JsonFormat(timezone = "GMT+8",pattern = "yyyy-MM-dd HH:mm:ss") + @DateTimeFormat(pattern="yyyy-MM-dd HH:mm:ss") + @ApiModelProperty(value = "打开时间") + private Date openTime; + /**题目编号*/ + @Excel(name = "题目编号", width = 15) + @ApiModelProperty(value = "题目编号") + private Integer wjIndex; + /**题目类型*/ + @Excel(name = "题目类型", width = 15) + @ApiModelProperty(value = "题目类型") + private java.lang.Integer wjType; + /**选择项*/ + private String itemSelected; + /**提交内容*/ + @Excel(name = "提交内容", width = 15) + @ApiModelProperty(value = "提交内容") + private Integer submitData; + + private String mainId; + +} diff --git a/jeecg-module-main/src/main/java/org/jeecg/modules/kc/wjxDjxx/entity/WjxDjxxTmxx.java b/jeecg-module-main/src/main/java/org/jeecg/modules/kc/wjxDjxx/entity/WjxDjxxTmxx.java new file mode 100644 index 00000000..8fe14391 --- /dev/null +++ b/jeecg-module-main/src/main/java/org/jeecg/modules/kc/wjxDjxx/entity/WjxDjxxTmxx.java @@ -0,0 +1,74 @@ +package org.jeecg.modules.kc.wjxDjxx.entity; + +import com.baomidou.mybatisplus.annotation.IdType; +import com.baomidou.mybatisplus.annotation.TableField; +import com.baomidou.mybatisplus.annotation.TableId; +import com.baomidou.mybatisplus.annotation.TableName; +import com.fasterxml.jackson.annotation.JsonFormat; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; +import org.jeecg.modules.kc.wjxWjxxTmlb.entity.WjxWjxxTmxx; +import org.jeecgframework.poi.excel.annotation.Excel; +import org.springframework.format.annotation.DateTimeFormat; + +import java.io.Serializable; +import java.util.Date; +import java.util.List; + +/** + * @Description: 答卷选项信息 + * @Author: jeecg-boot + * @Date: 2024-04-26 + * @Version: V1.0 + */ +@ApiModel(value="wjx_djxx_tmxx对象", description="答卷选项信息") +@Data +@TableName("wjx_djxx_tmxx") +public class WjxDjxxTmxx implements Serializable { + private static final long serialVersionUID = 1L; + @TableId(type = IdType.ASSIGN_ID) + @ApiModelProperty(value = "id") + private String id; + @ApiModelProperty(value = "创建人") + private String createBy; + @JsonFormat(timezone = "GMT+8",pattern = "yyyy-MM-dd HH:mm:ss") + @DateTimeFormat(pattern="yyyy-MM-dd HH:mm:ss") + @ApiModelProperty(value = "创建时间") + private Date createTime; + @ApiModelProperty(value = "修改人") + private String updateBy; + @JsonFormat(timezone = "GMT+8",pattern = "yyyy-MM-dd HH:mm:ss") + @DateTimeFormat(pattern="yyyy-MM-dd HH:mm:ss") + @ApiModelProperty(value = "修改时间") + private Date updateTime; + @ApiModelProperty(value = "题目编号") + private Integer wjIndex; + @ApiModelProperty(value = "题目标题") + private String wjTitle; + @ApiModelProperty(value = "题目选项") + private Integer itemIndex; + @ApiModelProperty(value = "题目文本答案") + private String answerText; + @ApiModelProperty(value = "选项分值") + private Double itemScore; + @ApiModelProperty(value = "vid") + private String vid; + @ApiModelProperty(value = "答卷编号") + private String jid; + @ApiModelProperty(value = "答卷人ID") + private String userId; + + @ApiModelProperty(value = "题目类型") + @TableField(exist = false) + private String wjType; + @ApiModelProperty(value = "问题分值") + @TableField(exist = false) + private Double wjScore; + @ApiModelProperty(value = "选中选项") + @TableField(exist = false) + private String itemSelected; + + @TableField(exist = false) + private List wjxWjxxTmxxList; +} diff --git a/jeecg-module-main/src/main/java/org/jeecg/modules/kc/wjxDjxx/mapper/WjxDjxxMapper.java b/jeecg-module-main/src/main/java/org/jeecg/modules/kc/wjxDjxx/mapper/WjxDjxxMapper.java new file mode 100644 index 00000000..21c8ef82 --- /dev/null +++ b/jeecg-module-main/src/main/java/org/jeecg/modules/kc/wjxDjxx/mapper/WjxDjxxMapper.java @@ -0,0 +1,29 @@ +package org.jeecg.modules.kc.wjxDjxx.mapper; + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import org.apache.ibatis.annotations.Param; +import org.jeecg.modules.kc.wjxDjxx.entity.WjxDjxx; +import org.jeecg.modules.kc.wjxDjxx.entity.WjxDjxxTmxx; + +import java.util.List; + + +/** + * @Description: 答卷信息 + * @Author: jeecg-boot + * @Date: 2024-05-07 + * @Version: V1.0 + */ +public interface WjxDjxxMapper extends BaseMapper { + void deleteDj(WjxDjxx wjxDjxx); + String findVid(@Param("mainId")String mainId); + List findUnSelect(); + void updateJid(@Param("userId")String userId,@Param("vid")String vid,@Param("jid")String jid); + void updateErrMsg(@Param("userId")String userId,@Param("vid")String vid,@Param("errorMsg")String errorMsg); + void updateAnswer(WjxDjxx wjxDjxx); + void deleteDjItem(WjxDjxx wjxDjxx); + void addDjTmxx(WjxDjxxTmxx wjxDjxxTmxx); + WjxDjxx findDjxx(@Param("id")String id,@Param("userId")String userId); + List findDjtmxx(@Param("vid")String vid,@Param("jid")String jid); + +} diff --git a/jeecg-module-main/src/main/java/org/jeecg/modules/kc/wjxDjxx/mapper/xml/WjxDjxxMapper.xml b/jeecg-module-main/src/main/java/org/jeecg/modules/kc/wjxDjxx/mapper/xml/WjxDjxxMapper.xml new file mode 100644 index 00000000..1d0d6353 --- /dev/null +++ b/jeecg-module-main/src/main/java/org/jeecg/modules/kc/wjxDjxx/mapper/xml/WjxDjxxMapper.xml @@ -0,0 +1,117 @@ + + + + + + delete from wjx_djxx + where vid = #{vid} + and user_id = #{userId} + + + + + + + + update wjx_djxx + set flag = '0', + jid = #{jid} + where vid = #{vid} + and user_id = #{userId} + + + + update wjx_djxx + set flag = '0', + error_msg = #{errorMsg}, + error_cn = error_cn + 1 + where vid = #{vid} + and user_id = #{userId} + + + + update wjx_djxx + set flag = '1', + error_msg = '', + answer_seconds = #{answerSeconds}, + score = #{score}, + total_score = #{totalScore} + where vid = #{vid} + and jid = #{jid} + + + + delete from wjx_djxx_tmxx + where vid = #{vid} + and jid = #{jid} + + + + insert into wjx_djxx_tmxx( + id, + create_by, + create_time, + vid, + jid, + user_id, + wj_index, + wj_title, + item_index, + answer_text, + item_score + ) + value( + #{id}, + #{createBy}, + #{createTime}, + #{vid}, + #{jid}, + #{userId}, + #{wjIndex}, + #{wjTitle}, + #{itemIndex}, + #{answerText}, + #{itemScore} + ) + + + + + + + \ No newline at end of file diff --git a/jeecg-module-main/src/main/java/org/jeecg/modules/kc/wjxDjxx/service/IWjxDjxxService.java b/jeecg-module-main/src/main/java/org/jeecg/modules/kc/wjxDjxx/service/IWjxDjxxService.java new file mode 100644 index 00000000..3de07c61 --- /dev/null +++ b/jeecg-module-main/src/main/java/org/jeecg/modules/kc/wjxDjxx/service/IWjxDjxxService.java @@ -0,0 +1,21 @@ +package org.jeecg.modules.kc.wjxDjxx.service; + +import com.baomidou.mybatisplus.extension.service.IService; +import org.jeecg.modules.kc.wjxDjxx.entity.WjxDjxx; +import org.jeecg.modules.kc.wjxDjxx.entity.WjxDjxxTmlbPage; +import org.jeecg.modules.kc.wjxWjxx.entity.WjxWjxx; +import org.jeecg.modules.kc.wjxWjxxTmlb.entity.WjxWjxxTmlb; + +import java.util.List; + +/** + * @Description: 答卷信息 + * @Author: jeecg-boot + * @Date: 2024-05-07 + * @Version: V1.0 + */ +public interface IWjxDjxxService extends IService { + String djtj(List list); + void doDjSelect(); + WjxDjxx queryByMainId(String id); +} diff --git a/jeecg-module-main/src/main/java/org/jeecg/modules/kc/wjxDjxx/service/impl/WjxDjxxServiceImpl.java b/jeecg-module-main/src/main/java/org/jeecg/modules/kc/wjxDjxx/service/impl/WjxDjxxServiceImpl.java new file mode 100644 index 00000000..27ee27d6 --- /dev/null +++ b/jeecg-module-main/src/main/java/org/jeecg/modules/kc/wjxDjxx/service/impl/WjxDjxxServiceImpl.java @@ -0,0 +1,302 @@ +package org.jeecg.modules.kc.wjxDjxx.service.impl; + +import com.alibaba.fastjson.JSONArray; +import com.alibaba.fastjson.JSONObject; +import com.baomidou.mybatisplus.core.incrementer.DefaultIdentifierGenerator; +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import org.apache.shiro.SecurityUtils; +import org.jeecg.common.system.vo.LoginUser; +import org.jeecg.modules.kc.wjxDjxx.entity.WjxDjxx; +import org.jeecg.modules.kc.wjxDjxx.entity.WjxDjxxTmlbPage; +import org.jeecg.modules.kc.wjxDjxx.entity.WjxDjxxTmxx; +import org.jeecg.modules.kc.wjxDjxx.mapper.WjxDjxxMapper; +import org.jeecg.modules.kc.wjxDjxx.service.IWjxDjxxService; +import org.jeecg.modules.kc.wjxWjxx.utils.WjxUtil; +import org.jeecg.modules.kc.wjxWjxxTmlb.entity.WjxWjxxTmlb; +import org.jeecg.modules.kc.wjxWjxxTmlb.entity.WjxWjxxTmxx; +import org.jeecg.modules.kc.wjxWjxxTmlb.mapper.WjxWjxxTmlbMapper; +import org.jeecg.modules.kc.wjxWjxxTmlb.mapper.WjxWjxxTmxxMapper; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import java.time.temporal.ChronoUnit; +import java.util.*; +import java.util.concurrent.TimeUnit; + + +/** + * @Description: 答卷信息 + * @Author: jeecg-boot + * @Date: 2024-05-07 + * @Version: V1.0 + */ +@Service +public class WjxDjxxServiceImpl extends ServiceImpl implements IWjxDjxxService { + + @Autowired + private WjxUtil wjxUtil; + @Autowired + private WjxWjxxTmlbMapper wjxWjxxTmlbMapper; + @Autowired + private WjxWjxxTmxxMapper wjxWjxxTmxxMapper; + + /** + * 提交问卷,并查询答卷 + * @param list + */ + public String djtj(List list){ + LoginUser user = (LoginUser) SecurityUtils.getSubject().getPrincipal(); + String vid = list.get(0).getVid(); + if(vid==null || vid.equals("")){ + String mainId = list.get(0).getMainId(); + vid = baseMapper.findVid(mainId); + } + if(vid ==null || vid.equals("")){ + return "此试卷错误,无法提交!"; + } + Date date = new Date(); + Date openTime = list.get(0).getOpenTime(); + if(openTime == null){ + Calendar c = Calendar.getInstance(); + c.add(Calendar.MINUTE,-2); + openTime = c.getTime(); + } + WjxDjxx wds = new WjxDjxx(); + wds.setVid(vid); + wds.setUserId(user.getUsername()); + wds.setUserName(user.getRealname()); + wds.setOpenTime(openTime); + wds.setCommitTime(date); + wds.setCreateBy(user.getUsername()); + wds.setCreateTime(date); + StringBuffer submitDataSb = new StringBuffer(); + for(WjxDjxxTmlbPage wjxDjxxTmlbPage:list){ + Integer WjIndex = wjxDjxxTmlbPage.getWjIndex(); + String itemSelected = wjxDjxxTmlbPage.getItemSelected().replaceAll(",","|").trim(); + if(itemSelected == null || itemSelected.equals("null") || itemSelected.equals("")){ + if(wjxDjxxTmlbPage.getWjType().equals("5")){ + itemSelected = "(跳过)"; + }else{ + itemSelected = "-3"; + } + } + submitDataSb.append(WjIndex); + submitDataSb.append("$"); + submitDataSb.append(itemSelected); + submitDataSb.append("}"); + } + String submitData = submitDataSb.toString(); + submitData = submitData.substring(0,submitData.length()-1); + wds.setSubmitData(submitData); + baseMapper.deleteDj(wds); + this.save(wds); + + Map map = new HashMap<>(); + map.put("vid",Integer.valueOf(vid)); + map.put("inputcosttime",ChronoUnit.SECONDS.between(openTime.toInstant(),date.toInstant())); + map.put("submitdata",submitData); + map.put("sojumpparm",user.getUsername());//自定义链接参数,用来透传用户ID + //调用接口,提交 + String result = wjxUtil.openapi(map,"1001001"); + if(!result.equals("")){ + JSONObject jsonResult = JSONObject.parseObject(result); + if(jsonResult.getBoolean("result")){ + JSONObject dataJson = jsonResult.getJSONObject("data"); + String vidRes = dataJson.getString("vid"); + String jidRes = dataJson.getString("jid"); + String sojumpparmRes = dataJson.getString("sojumpparm"); + baseMapper.updateJid(sojumpparmRes,vidRes,jidRes); + //调用接口,答卷查询 + Map selMap = new HashMap<>(); + selMap.put("vid",Integer.valueOf(vid)); + selMap.put("jid",Long.valueOf(jidRes)); + //调用接口,提交 + String answerStr = wjxUtil.openapi(selMap,"1001002"); + if(!answerStr.equals("")){ + JSONObject ansJsonResult = JSONObject.parseObject(answerStr); + if(ansJsonResult.getBoolean("result")){ + JSONObject ansDataJson = ansJsonResult.getJSONObject("data"); + String answerVid = ansDataJson.getString("vid"); + JSONObject answerJsonArray = ansDataJson.getJSONObject("answers"); + for(String key1 : answerJsonArray.keySet()){ + JSONObject answer = answerJsonArray.getJSONObject(key1); + String jidAns = answer.getString("jid"); + Integer answerSeconds = answer.getInteger("answer_seconds"); + Double score = answer.getDouble("score"); + Double totalScore = answer.getDouble("total_score"); + WjxDjxx wjxDjxx = new WjxDjxx(); + wjxDjxx.setVid(answerVid); + wjxDjxx.setJid(jidAns); + wjxDjxx.setAnswerSeconds(answerSeconds); + wjxDjxx.setScore(score); + wjxDjxx.setTotalScore(totalScore); + //删除选项信息 + baseMapper.deleteDjItem(wjxDjxx); + //处理选项 + JSONObject answerItemJson = answer.getJSONObject("answer_items"); + for(String key2 : answerItemJson.keySet()){ + JSONObject answerItem = answerItemJson.getJSONObject(key2); + Integer wjIndex = answerItem.getInteger("q_index"); + String wjTitle = answerItem.getString("title"); + JSONArray itemIndex = answerItem.getJSONArray("item_index"); + Double itemScore = answerItem.getDouble("item_value"); + String answerText = answerItem.getString("answer_text"); + WjxDjxxTmxx wjxDjxxTmxx = new WjxDjxxTmxx(); + wjxDjxxTmxx.setVid(answerVid); + wjxDjxxTmxx.setJid(jidAns); + wjxDjxxTmxx.setUserId(user.getUsername()); + wjxDjxxTmxx.setCreateBy(user.getUsername()); + wjxDjxxTmxx.setCreateTime(new Date()); + wjxDjxxTmxx.setWjIndex(wjIndex); + wjxDjxxTmxx.setWjTitle(wjTitle); + wjxDjxxTmxx.setItemScore(itemScore); + wjxDjxxTmxx.setAnswerText(answerText); + for(Object index : itemIndex){ + Integer ti = (Integer) index; + wjxDjxxTmxx.setItemIndex(ti); + String id = new DefaultIdentifierGenerator().nextId(new WjxDjxxTmxx()).toString(); + wjxDjxxTmxx.setId(id); + baseMapper.addDjTmxx(wjxDjxxTmxx); + } + } + //修改答卷信息 + baseMapper.updateAnswer(wjxDjxx); + } + }else{ + baseMapper.updateErrMsg(user.getUsername(),vid,ansJsonResult.getString("errormsg")); + return ansJsonResult.getString("errormsg"); + } + } + }else{ + baseMapper.updateErrMsg(user.getUsername(),vid,jsonResult.getString("errormsg")); + return jsonResult.getString("errormsg"); + } + } + return "提交成功!"; + } + + /** + * 获取未进行答卷查询操作的数据,如数据未提交问卷操作则先提交问卷,再查询答卷 + */ + public void doDjSelect(){ + List list = baseMapper.findUnSelect(); + for(int i=0;i map = new HashMap<>(); + map.put("vid",Integer.valueOf(wjxDjxx.getVid())); + map.put("inputcosttime",ChronoUnit.SECONDS.between(wjxDjxx.getOpenTime().toInstant(),wjxDjxx.getCommitTime().toInstant())); + map.put("submitdata",wjxDjxx.getSubmitData()); + map.put("sojumpparm",wjxDjxx.getUserId());//自定义链接参数,用来透传用户ID + //调用接口,提交 + String result = wjxUtil.openapi(map,"1001001"); + if(!result.equals("")) { + JSONObject jsonResult = JSONObject.parseObject(result); + if (jsonResult.getBoolean("result")) { + JSONObject dataJson = jsonResult.getJSONObject("data"); + String vidRes = dataJson.getString("vid"); + jid = dataJson.getString("jid"); + String sojumpparmRes = dataJson.getString("sojumpparm"); + baseMapper.updateJid(sojumpparmRes,vidRes,jid); + wjxDjxx.setJid(jid); + }else{ + baseMapper.updateErrMsg(wjxDjxx.getUserId(),wjxDjxx.getVid(),jsonResult.getString("errormsg")); + continue; + } + } + } + //调用接口,答卷查询 + Map selMap = new HashMap<>(); + selMap.put("vid",Integer.valueOf(vid)); + selMap.put("jid",Long.valueOf(jid)); + //调用接口,提交 + String answerStr = wjxUtil.openapi(selMap,"1001002"); + if(!answerStr.equals("")){ + JSONObject ansJsonResult = JSONObject.parseObject(answerStr); + if(ansJsonResult.getBoolean("result")){ + JSONObject ansDataJson = ansJsonResult.getJSONObject("data"); + String answerVid = ansDataJson.getString("vid"); + JSONObject answerJsonArray = ansDataJson.getJSONObject("answers"); + for(String key1 : answerJsonArray.keySet()){ + JSONObject answer = answerJsonArray.getJSONObject(key1); + String jidAns = answer.getString("jid"); + Integer answerSeconds = answer.getInteger("answer_seconds"); + Double score = answer.getDouble("score"); + Double totalScore = answer.getDouble("total_score"); + WjxDjxx wjxDjxx2 = new WjxDjxx(); + wjxDjxx2.setVid(answerVid); + wjxDjxx2.setJid(jidAns); + wjxDjxx2.setAnswerSeconds(answerSeconds); + wjxDjxx2.setScore(score); + wjxDjxx2.setTotalScore(totalScore); + //删除选项信息 + baseMapper.deleteDjItem(wjxDjxx2); + //处理选项 + JSONObject answerItemJson = answer.getJSONObject("answer_items"); + for(String key2 : answerItemJson.keySet()){ + JSONObject answerItem = answerItemJson.getJSONObject(key2); + Integer wjIndex = answerItem.getInteger("q_index"); + String wjTitle = answerItem.getString("title"); + JSONArray itemIndex = answerItem.getJSONArray("item_index"); + Double itemScore = answerItem.getDouble("item_value"); + String answerText = answerItem.getString("answer_text"); + WjxDjxxTmxx wjxDjxxTmxx = new WjxDjxxTmxx(); + wjxDjxxTmxx.setVid(answerVid); + wjxDjxxTmxx.setJid(jidAns); + wjxDjxxTmxx.setUserId(userId); + wjxDjxxTmxx.setCreateBy(userId); + wjxDjxxTmxx.setCreateTime(new Date()); + wjxDjxxTmxx.setWjIndex(wjIndex); + wjxDjxxTmxx.setWjTitle(wjTitle); + wjxDjxxTmxx.setItemScore(itemScore); + wjxDjxxTmxx.setAnswerText(answerText); + for(Object index : itemIndex){ + Integer ti = (Integer) index; + wjxDjxxTmxx.setItemIndex(ti); + String id = new DefaultIdentifierGenerator().nextId(new WjxDjxxTmxx()).toString(); + wjxDjxxTmxx.setId(id); + baseMapper.addDjTmxx(wjxDjxxTmxx); + } + } + //修改答卷信息 + baseMapper.updateAnswer(wjxDjxx2); + } + }else{ + baseMapper.updateErrMsg(wjxDjxx.getUserId(),wjxDjxx.getVid(),ansJsonResult.getString("errormsg")); + continue; + } + } + } + } + + @Override + public WjxDjxx queryByMainId(String id) { + LoginUser user = (LoginUser) SecurityUtils.getSubject().getPrincipal(); + WjxDjxx djxx = baseMapper.findDjxx(id,user.getUsername()); + djxx.setAnswerSfm(convertSecondsToHMS(djxx.getAnswerSeconds())); + List list = baseMapper.findDjtmxx(djxx.getVid(),djxx.getJid()); + for(WjxDjxxTmxx wjxDjxxTmxx:list){ + List list2= wjxWjxxTmxxMapper.selectByMainId(wjxDjxxTmxx.getId()); + wjxDjxxTmxx.setWjxWjxxTmxxList(list2); + } + djxx.setWjxDjxxTmxxList(list); + return djxx; + } + + /** + * 秒数转时分秒 + * @param seconds + * @return + */ + String convertSecondsToHMS(long seconds) { + long hours = TimeUnit.SECONDS.toHours(seconds); + long remainingSeconds = seconds - TimeUnit.HOURS.toSeconds(hours); + long minutes = TimeUnit.SECONDS.toMinutes(remainingSeconds); + remainingSeconds = remainingSeconds - TimeUnit.MINUTES.toSeconds(minutes); + return String.format("%02d:%02d:%02d", hours, minutes, remainingSeconds); + } + +} diff --git a/jeecg-module-main/src/main/java/org/jeecg/modules/kc/wjxWjxx/controller/WjxWjxxController.java b/jeecg-module-main/src/main/java/org/jeecg/modules/kc/wjxWjxx/controller/WjxWjxxController.java index 0d02a81b..ab0a5d12 100644 --- a/jeecg-module-main/src/main/java/org/jeecg/modules/kc/wjxWjxx/controller/WjxWjxxController.java +++ b/jeecg-module-main/src/main/java/org/jeecg/modules/kc/wjxWjxx/controller/WjxWjxxController.java @@ -1,18 +1,11 @@ package org.jeecg.modules.kc.wjxWjxx.controller; -import java.net.URLEncoder; import java.util.Arrays; -import java.util.List; -import java.util.Map; -import java.util.stream.Collectors; -import java.io.IOException; -import java.io.UnsupportedEncodingException; -import java.net.URLDecoder; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; + import org.jeecg.common.api.vo.Result; import org.jeecg.common.system.query.QueryGenerator; -import org.jeecg.common.util.oConvertUtils; import org.jeecg.modules.kc.wjxWjxx.entity.WjxWjxx; import org.jeecg.modules.kc.wjxWjxx.service.IWjxWjxxService; @@ -21,23 +14,11 @@ import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import lombok.extern.slf4j.Slf4j; -import org.jeecg.modules.tools.AuthService; import org.jeecg.modules.tools.WjxAuthService; -import org.jeecg.modules.tools.baidu.Base64Util; -import org.jeecg.modules.tools.baidu.FileUtil; -import org.jeecg.modules.tools.baidu.HttpUtil; -import org.jeecgframework.poi.excel.ExcelImportUtil; -import org.jeecgframework.poi.excel.def.NormalExcelConstants; -import org.jeecgframework.poi.excel.entity.ExportParams; -import org.jeecgframework.poi.excel.entity.ImportParams; -import org.jeecgframework.poi.excel.view.JeecgEntityExcelView; import org.jeecg.common.system.base.controller.JeecgController; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.*; -import org.springframework.web.multipart.MultipartFile; -import org.springframework.web.multipart.MultipartHttpServletRequest; import org.springframework.web.servlet.ModelAndView; -import com.alibaba.fastjson.JSON; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import org.jeecg.common.aspect.annotation.AutoLog; @@ -180,24 +161,23 @@ public class WjxWjxxController extends JeecgController return super.importExcel(request, response, WjxWjxx.class); } - @ApiOperation(value="问卷信息-通过id查询", notes="问卷信息-通过id查询") - @GetMapping(value = "/getWjxLogin") - public Result getWjxLogin() { - try { - // 注意这里仅为了简化编码每一次请求都去获取access_token,线上环境access_token有过期时间, 客户端可自行缓存,过期后重新获取。 - String accessToken = wjxAuthService.getAuth(); - System.out.println(accessToken); - } catch (Exception e) { - e.printStackTrace(); - } - return Result.OK(null); - } + @ApiOperation(value="问卷信息-通过id查询", notes="问卷信息-通过id查询") + @GetMapping(value = "/getWjxLogin") + public Result getWjxLogin() { + try { + // 注意这里仅为了简化编码每一次请求都去获取access_token,线上环境access_token有过期时间, 客户端可自行缓存,过期后重新获取。 + String accessToken = wjxAuthService.getAuth(); + System.out.println(accessToken); + } catch (Exception e) { + e.printStackTrace(); + } + return Result.OK(null); + } - - @ApiOperation(value="发布问卷", notes="发布问卷") - @GetMapping(value = "/fbwj") - public Result fbwj(@RequestParam(name="id",required=true) String id) { - WjxWjxx wjxWjxx = wjxWjxxService.fbwj(id); - return Result.OK(wjxWjxx); - } + @ApiOperation(value="发布问卷", notes="发布问卷") + @GetMapping(value = "/fbwj") + public Result fbwj(@RequestParam(name="id",required=true) String id) { + String res = wjxWjxxService.fbwj(id); + return Result.OK(res); + } } diff --git a/jeecg-module-main/src/main/java/org/jeecg/modules/kc/wjxWjxx/entity/WjxWjxx.java b/jeecg-module-main/src/main/java/org/jeecg/modules/kc/wjxWjxx/entity/WjxWjxx.java index d7de6bd7..81e403d9 100644 --- a/jeecg-module-main/src/main/java/org/jeecg/modules/kc/wjxWjxx/entity/WjxWjxx.java +++ b/jeecg-module-main/src/main/java/org/jeecg/modules/kc/wjxWjxx/entity/WjxWjxx.java @@ -59,7 +59,7 @@ public class WjxWjxx implements Serializable { /**问卷类型*/ @Excel(name = "问卷类型", width = 15) @ApiModelProperty(value = "问卷类型") - private java.lang.Integer atype; + private java.lang.String atype; /**问卷名称*/ @Excel(name = "问卷名称", width = 15) @ApiModelProperty(value = "问卷名称") diff --git a/jeecg-module-main/src/main/java/org/jeecg/modules/kc/wjxWjxx/mapper/WjxWjxxMapper.java b/jeecg-module-main/src/main/java/org/jeecg/modules/kc/wjxWjxx/mapper/WjxWjxxMapper.java index 718528b0..a4177a6f 100644 --- a/jeecg-module-main/src/main/java/org/jeecg/modules/kc/wjxWjxx/mapper/WjxWjxxMapper.java +++ b/jeecg-module-main/src/main/java/org/jeecg/modules/kc/wjxWjxx/mapper/WjxWjxxMapper.java @@ -13,5 +13,5 @@ import com.baomidou.mybatisplus.core.mapper.BaseMapper; * @Version: V1.0 */ public interface WjxWjxxMapper extends BaseMapper { - + void updateVid(@Param("id")String id,@Param("vid")String vid); } diff --git a/jeecg-module-main/src/main/java/org/jeecg/modules/kc/wjxWjxx/mapper/xml/WjxWjxxMapper.xml b/jeecg-module-main/src/main/java/org/jeecg/modules/kc/wjxWjxx/mapper/xml/WjxWjxxMapper.xml index 94de8554..49b2d22d 100644 --- a/jeecg-module-main/src/main/java/org/jeecg/modules/kc/wjxWjxx/mapper/xml/WjxWjxxMapper.xml +++ b/jeecg-module-main/src/main/java/org/jeecg/modules/kc/wjxWjxx/mapper/xml/WjxWjxxMapper.xml @@ -1,5 +1,10 @@ - + + update wjx_wjxx + set vid = #{vid}, + qpublish = '1' + where id = #{id} + \ No newline at end of file diff --git a/jeecg-module-main/src/main/java/org/jeecg/modules/kc/wjxWjxx/service/IWjxWjxxService.java b/jeecg-module-main/src/main/java/org/jeecg/modules/kc/wjxWjxx/service/IWjxWjxxService.java index e7005fb7..a14dda89 100644 --- a/jeecg-module-main/src/main/java/org/jeecg/modules/kc/wjxWjxx/service/IWjxWjxxService.java +++ b/jeecg-module-main/src/main/java/org/jeecg/modules/kc/wjxWjxx/service/IWjxWjxxService.java @@ -11,5 +11,5 @@ import com.baomidou.mybatisplus.extension.service.IService; */ public interface IWjxWjxxService extends IService { - WjxWjxx fbwj(String id); + String fbwj(String id); } diff --git a/jeecg-module-main/src/main/java/org/jeecg/modules/kc/wjxWjxx/service/impl/WjxWjxxServiceImpl.java b/jeecg-module-main/src/main/java/org/jeecg/modules/kc/wjxWjxx/service/impl/WjxWjxxServiceImpl.java index 9d7cf5b5..f75f69d4 100644 --- a/jeecg-module-main/src/main/java/org/jeecg/modules/kc/wjxWjxx/service/impl/WjxWjxxServiceImpl.java +++ b/jeecg-module-main/src/main/java/org/jeecg/modules/kc/wjxWjxx/service/impl/WjxWjxxServiceImpl.java @@ -11,6 +11,7 @@ import org.jeecg.common.util.DateUtils; import org.jeecg.modules.kc.wjxWjxx.entity.WjxWjxx; import org.jeecg.modules.kc.wjxWjxx.mapper.WjxWjxxMapper; import org.jeecg.modules.kc.wjxWjxx.service.IWjxWjxxService; +import org.jeecg.modules.kc.wjxWjxx.utils.WjxUtil; import org.jeecg.modules.kc.wjxWjxxTmlb.entity.WjxWjxxTmlb; import org.jeecg.modules.kc.wjxWjxxTmlb.entity.WjxWjxxTmxx; import org.jeecg.modules.kc.wjxWjxxTmlb.mapper.WjxWjxxTmlbMapper; @@ -35,14 +36,177 @@ import static cn.hutool.crypto.digest.DigestUtil.sha1; @Service public class WjxWjxxServiceImpl extends ServiceImpl implements IWjxWjxxService { - @Autowired private WjxWjxxTmlbMapper wjxWjxxTmlbMapper; @Autowired private WjxWjxxTmxxMapper wjxWjxxTmxxMapper; + @Autowired + private WjxUtil wjxUtil; + + +// @Override +// public WjxWjxx fbwj(String id) { +// +// WjxWjxx wjxWjxx = baseMapper.selectById(id); +// +// QueryWrapper wjxWjxxTmlbQueryWrapper = new QueryWrapper<>(); +// wjxWjxxTmlbQueryWrapper.eq("main_id", id); +// List wjxWjxxTmlbList =wjxWjxxTmlbMapper.selectList(wjxWjxxTmlbQueryWrapper); +// +//// Map questionsMap = new HashMap<>(); +//// questionsMap.put("q_index","1"); +//// questionsMap.put("q_type","3"); +//// questionsMap.put("q_title",wjxWjxx.getTitle()); +//// questionsMap.put("q_score","0"); +//// questionsMap.put("is_requir","true"); +//// questionsMap.put("q_subtype","3"); +//// questionsMap.put("q_ceshi","false"); +//// questionsMap.put("is_zhenbie","false"); +//// questionsMap.put("min_time","0"); +//// questionsMap.put("max_time","0"); +// List> questionsList = new ArrayList<>(); +// for(WjxWjxxTmlb wWjxWjxxTmlb:wjxWjxxTmlbList){ +// Map map = new HashMap<>(); +// map.put("q_index",wWjxWjxxTmlb.getWjIndex()); +// map.put("q_type",wWjxWjxxTmlb.getWjType()); +// map.put("q_title",wWjxWjxxTmlb.getWjTitle()); +// map.put("is_requir",true); +//// map.put("q_score",0); +// +// //---------------没用的参数------------------ +//// map.put("q_subtype",3); +//// map.put("q_ceshi","false"); +//// map.put("q_parsing","解析测试"); +//// map.put("prompt","提示测试"); +// +//// map.put("is_zhenbie","false"); +//// map.put("min_time","0"); +//// map.put("max_time","0"); +// //---------------没用的参数------------------ +// +// +// List> itemsList = new ArrayList<>(); +// List tmxxList = wjxWjxxTmxxMapper.selectByMainId(wWjxWjxxTmlb.getId()); +// for(WjxWjxxTmxx wjxWjxxTmxx:tmxxList){ +// Map tmxxMap = new HashMap<>(); +// tmxxMap.put("q_index",wjxWjxxTmxx.getWjIndex()); +// tmxxMap.put("item_index",wjxWjxxTmxx.getItemIndex()); +// tmxxMap.put("item_title",wjxWjxxTmxx.getItemTitle()); +// tmxxMap.put("item_selected",Boolean.parseBoolean(wjxWjxxTmxx.getItemSelected())); +// tmxxMap.put("item_score",0); +// JSONObject json = new JSONObject(tmxxMap); +// itemsList.add(json); +// } +// map.put("items",itemsList); +// JSONObject json = new JSONObject(map); +// questionsList.add(json); +// } +// +// +// +// Map map = new HashMap<>(); +// //-----------题目必穿参数------------- +// map.put("atype",1); +// map.put("title",wjxWjxx.getTitle()); +// map.put("desc",wjxWjxx.getContent()); +// map.put("publish",true); +// map.put("questions",questionsList.toString()); +// //-----------题目必穿参数------------- +// //-----------题目没用参数------------- +//// map.put("creater","jwctest"); +//// map.put("compress_img","false"); +// //-----------题目没用参数------------- +// +// +// //----------固定传参--------------- +// map.put("appid","1321039"); +// map.put("ts",ts); +// map.put("action","1000101"); +// //----------固定传参--------------- +// //---------------没用的参数------------------ +//// map.put("encode","SHA1"); +//// map.put("nocache","0"); +// //---------------没用的参数------------------ +// +// +// System.out.println("---->"+map); +// +// String appkey = "55328ebd11964fc8b40c10011bcb425d"; +//// StringBuilder toSign = new StringBuilder(); +//// for (Map.Entry entry:map.entrySet()) { +//// if(StringUtils.isNotBlank(entry.getValue().toString())){ +//// toSign.append(entry.getValue().toString()); +//// } +//// } +// String sign = ""; +// try { +// sign = generateSignature(map, appkey,"SHA1"); +// }catch (Exception e) { +// e.printStackTrace(); +// } +// System.out.println("sign: "+sign); +// map.put("sign",sign); +// System.out.println("map:"+map.toString()); +// String url = "https://www.wjx.cn/openapi/default.aspx"; +// try { +// JSONObject json = new JSONObject(map); +// System.out.println("json:"+json.toString()); +// String result = HttpUtil.post(url, "" , "application/json", json.toString()); +// System.out.println(result); +// }catch (Exception e) { +// e.printStackTrace(); +// } +// +// +// return null; +// } +// +//// public void cjwj(){ +//// String appkey = "": +//// String appid = "": +//// String ts= "": +//// String acction = "": +//// Map map = new HashMap(); +//// map.put("appid",appid); +//// map.put("ts", ts); +//// map.put("action",acction); +//// String sign = generateSignature(map, appkey,"SHA1"); +//// } +// +// public String generateSignature(final Map data, String key, String signType) throws Exception { +// Set keySet = data.keySet(); +// String[] keyArray = keySet.toArray(new String[keySet.size()]); +// Arrays.sort(keyArray); +// StringBuilder sb = new StringBuilder(); +// for (String k : keyArray) { +// if (data.get(k).toString().length() > 0) // 参数值为空,则不参与签名 +// sb.append(data.get(k).toString()); +// } +// sb.append(key); +// if ("SHA1".equals(signType)) { +// return getSHA1(sb.toString()).toUpperCase(); +// } +// else { +// throw new Exception(String.format("Invalid sign_type: %s", signType)); +// } +// } +// +// public String getSHA1(String input) { +// try { +// MessageDigest sha1 = MessageDigest.getInstance("SHA-1"); +// byte[] bytes = sha1.digest(input.getBytes()); +// StringBuilder sb = new StringBuilder(); +// for (byte b : bytes) { +// sb.append(String.format("%02x", b));//十六进制 +// } +// return sb.toString(); +// } catch (NoSuchAlgorithmException e) { +// throw new RuntimeException(e); +// } +// } @Override - public WjxWjxx fbwj(String id) { + public String fbwj(String id) { WjxWjxx wjxWjxx = baseMapper.selectById(id); @@ -50,17 +214,6 @@ public class WjxWjxxServiceImpl extends ServiceImpl impl wjxWjxxTmlbQueryWrapper.eq("main_id", id); List wjxWjxxTmlbList =wjxWjxxTmlbMapper.selectList(wjxWjxxTmlbQueryWrapper); -// Map questionsMap = new HashMap<>(); -// questionsMap.put("q_index","1"); -// questionsMap.put("q_type","3"); -// questionsMap.put("q_title",wjxWjxx.getTitle()); -// questionsMap.put("q_score","0"); -// questionsMap.put("is_requir","true"); -// questionsMap.put("q_subtype","3"); -// questionsMap.put("q_ceshi","false"); -// questionsMap.put("is_zhenbie","false"); -// questionsMap.put("min_time","0"); -// questionsMap.put("max_time","0"); List> questionsList = new ArrayList<>(); for(WjxWjxxTmlb wWjxWjxxTmlb:wjxWjxxTmlbList){ Map map = new HashMap<>(); @@ -68,20 +221,9 @@ public class WjxWjxxServiceImpl extends ServiceImpl impl map.put("q_type",wWjxWjxxTmlb.getWjType()); map.put("q_title",wWjxWjxxTmlb.getWjTitle()); map.put("is_requir",true); -// map.put("q_score",0); - - //---------------没用的参数------------------ -// map.put("q_subtype",3); -// map.put("q_ceshi","false"); -// map.put("q_parsing","解析测试"); -// map.put("prompt","提示测试"); - -// map.put("is_zhenbie","false"); -// map.put("min_time","0"); -// map.put("max_time","0"); - //---------------没用的参数------------------ - - + if(wWjxWjxxTmlb.getWjScore()!=null){ + map.put("is_requir",wWjxWjxxTmlb.getWjScore()); + } List> itemsList = new ArrayList<>(); List tmxxList = wjxWjxxTmxxMapper.selectByMainId(wWjxWjxxTmlb.getId()); for(WjxWjxxTmxx wjxWjxxTmxx:tmxxList){ @@ -99,108 +241,26 @@ public class WjxWjxxServiceImpl extends ServiceImpl impl questionsList.add(json); } - - Long unixTimestamp = Instant.now().getEpochSecond(); - String ts = unixTimestamp.toString(); Map map = new HashMap<>(); //-----------题目必穿参数------------- - map.put("atype",1); + map.put("atype",wjxWjxx.getAtype()); map.put("title",wjxWjxx.getTitle()); map.put("desc",wjxWjxx.getContent()); map.put("publish",true); map.put("questions",questionsList.toString()); - //-----------题目必穿参数------------- - //-----------题目没用参数------------- -// map.put("creater","jwctest"); -// map.put("compress_img","false"); - //-----------题目没用参数------------- - - - //----------固定传参--------------- - map.put("appid","1321039"); - map.put("ts",ts); - map.put("action","1000101"); - //----------固定传参--------------- - //---------------没用的参数------------------ -// map.put("encode","SHA1"); -// map.put("nocache","0"); - //---------------没用的参数------------------ - - - System.out.println("---->"+map); - - String appkey = "55328ebd11964fc8b40c10011bcb425d"; -// StringBuilder toSign = new StringBuilder(); -// for (Map.Entry entry:map.entrySet()) { -// if(StringUtils.isNotBlank(entry.getValue().toString())){ -// toSign.append(entry.getValue().toString()); -// } -// } - String sign = ""; - try { - sign = generateSignature(map, appkey,"SHA1"); - }catch (Exception e) { - e.printStackTrace(); - } - System.out.println("sign: "+sign); - map.put("sign",sign); - System.out.println("map:"+map.toString()); - String url = "https://www.wjx.cn/openapi/default.aspx"; - try { - JSONObject json = new JSONObject(map); - System.out.println("json:"+json.toString()); - String result = HttpUtil.post(url, "" , "application/json", json.toString()); - System.out.println(result); - }catch (Exception e) { - e.printStackTrace(); - } - - - return null; - } - -// public void cjwj(){ -// String appkey = "": -// String appid = "": -// String ts= "": -// String acction = "": -// Map map = new HashMap(); -// map.put("appid",appid); -// map.put("ts", ts); -// map.put("action",acction); -// String sign = generateSignature(map, appkey,"SHA1"); -// } - - public String generateSignature(final Map data, String key, String signType) throws Exception { - Set keySet = data.keySet(); - String[] keyArray = keySet.toArray(new String[keySet.size()]); - Arrays.sort(keyArray); - StringBuilder sb = new StringBuilder(); - for (String k : keyArray) { - if (data.get(k).toString().length() > 0) // 参数值为空,则不参与签名 - sb.append(data.get(k).toString()); - } - sb.append(key); - if ("SHA1".equals(signType)) { - return getSHA1(sb.toString()).toUpperCase(); - } - else { - throw new Exception(String.format("Invalid sign_type: %s", signType)); - } - } - - public String getSHA1(String input) { - try { - MessageDigest sha1 = MessageDigest.getInstance("SHA-1"); - byte[] bytes = sha1.digest(input.getBytes()); - StringBuilder sb = new StringBuilder(); - for (byte b : bytes) { - sb.append(String.format("%02x", b));//十六进制 + String result = wjxUtil.openapi(map,"1000101"); + System.out.println(result); + if(!result.equals("")){ + JSONObject jsonResult = JSONObject.parseObject(result); + if(jsonResult.getBoolean("result")){ + JSONObject dataJson = jsonResult.getJSONObject("data"); + String vid = dataJson.getString("vid"); + baseMapper.updateVid(id,vid); + }else{ + return jsonResult.getString("errormsg"); } - return sb.toString(); - } catch (NoSuchAlgorithmException e) { - throw new RuntimeException(e); } + return "发布成功!"; } diff --git a/jeecg-module-main/src/main/java/org/jeecg/modules/kc/wjxWjxx/utils/WjxConfig.java b/jeecg-module-main/src/main/java/org/jeecg/modules/kc/wjxWjxx/utils/WjxConfig.java new file mode 100644 index 00000000..5841e92b --- /dev/null +++ b/jeecg-module-main/src/main/java/org/jeecg/modules/kc/wjxWjxx/utils/WjxConfig.java @@ -0,0 +1,16 @@ +package org.jeecg.modules.kc.wjxWjxx.utils; + +import lombok.Data; +import org.springframework.boot.context.properties.ConfigurationProperties; +import org.springframework.stereotype.Component; + +@Component +@ConfigurationProperties(prefix = "wjx") +@Data +public class WjxConfig { + private String appid; + private String appkey; + private String url; + + public WjxConfig(){} +} diff --git a/jeecg-module-main/src/main/java/org/jeecg/modules/kc/wjxWjxx/utils/WjxUtil.java b/jeecg-module-main/src/main/java/org/jeecg/modules/kc/wjxWjxx/utils/WjxUtil.java new file mode 100644 index 00000000..541ee330 --- /dev/null +++ b/jeecg-module-main/src/main/java/org/jeecg/modules/kc/wjxWjxx/utils/WjxUtil.java @@ -0,0 +1,82 @@ +package org.jeecg.modules.kc.wjxWjxx.utils; + +import com.alibaba.fastjson.JSONObject; +import org.jeecg.modules.tools.baidu.HttpUtil; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import java.security.MessageDigest; +import java.security.NoSuchAlgorithmException; +import java.time.Instant; +import java.util.Arrays; +import java.util.Map; +import java.util.Set; + +@Service +public class WjxUtil { + + private static final Logger logger = LoggerFactory.getLogger(WjxUtil.class); + + @Autowired + private WjxConfig wjxConfig; + + public String openapi(final Map data,String anction){ + String result = ""; + String sign = ""; + Long unixTimestamp = Instant.now().getEpochSecond(); + String ts = unixTimestamp.toString(); + data.put("appid",wjxConfig.getAppid()); + data.put("ts",ts); + data.put("action",anction); + data.put("encode","sha1"); + try { + sign = generateSignature(data); + }catch (Exception e) { + e.printStackTrace(); + } +// System.out.println("sign: "+sign); + data.put("sign",sign); +// System.out.println("map:"+data.toString()); + String url = "https://www.wjx.cn/openapi/default.aspx"; + try { + JSONObject json = new JSONObject(data); + System.out.println("json:"+json.toString()); + result = HttpUtil.post(url, "" , "application/json", json.toString()); +// System.out.println(result); + }catch (Exception e) { + e.printStackTrace(); + } + return result; + } + + public String generateSignature(final Map data) throws Exception{ + String key = wjxConfig.getAppkey(); + Set keySet = data.keySet(); + String[] keyArray = keySet.toArray(new String[keySet.size()]); + Arrays.sort(keyArray); + StringBuilder sb = new StringBuilder(); + for (String k : keyArray) { + if (data.get(k).toString().length() > 0) // 参数值为空,则不参与签名 + sb.append(data.get(k).toString()); + } + sb.append(key); + return getSHA1(sb.toString()).toUpperCase(); + } + + public String getSHA1(String input) { + try { + MessageDigest sha1 = MessageDigest.getInstance("SHA-1"); + byte[] bytes = sha1.digest(input.getBytes()); + StringBuilder sb = new StringBuilder(); + for (byte b : bytes) { + sb.append(String.format("%02x", b));//十六进制 + } + return sb.toString(); + } catch (NoSuchAlgorithmException e) { + throw new RuntimeException(e); + } + } + +} diff --git a/jeecg-module-system/jeecg-system-start/src/main/resources/application-dev.yml b/jeecg-module-system/jeecg-system-start/src/main/resources/application-dev.yml index 447a046c..4b4bd828 100644 --- a/jeecg-module-system/jeecg-system-start/src/main/resources/application-dev.yml +++ b/jeecg-module-system/jeecg-system-start/src/main/resources/application-dev.yml @@ -331,4 +331,18 @@ ffmpeg: # 维普检测接口 weipu: userId: 765996 - userKey: 330ed91f6c7e4600a454a6a5216723bf \ No newline at end of file + userKey: 330ed91f6c7e4600a454a6a5216723bf + +#SFTP +#sftp: +# hostname: 210.47.29.18 +# port: 22 +# uername: nenujwc18 +# password: hFvxJG%yRNZQ +# timeout: 1000 +# uploadpath: / +#问卷星 +wjx: + appid: 1321039 + appkey: 55328ebd11964fc8b40c10011bcb425d + url: https://www.wjx.cn/openapi/default.aspx \ No newline at end of file