| | |
| | | <version>1.5.10.RELEASE</version> |
| | | <relativePath/> <!-- lookup parent from repository --> |
| | | </parent> |
| | | |
| | | <properties> |
| | | <project.build.sourceEncoding>GBK</project.build.sourceEncoding> |
| | | <project.reporting.outputEncoding>GBK</project.reporting.outputEncoding> |
| | | <!-- 与1.8配置在一起,设置编码集--> |
| | | <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> |
| | | <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding> |
| | | <java.version>1.8</java.version> |
| | | </properties> |
| | | <repositories> |
| | |
| | | <version>1.2</version> |
| | | </dependency> |
| | | |
| | | <!-- 华为云OBS依赖/--> |
| | | <dependency> |
| | | <groupId>com.huaweicloud</groupId> |
| | | <artifactId>esdk-obs-java</artifactId> |
| | | <version>3.20.6.1</version> |
| | | </dependency> |
| | | |
| | | <!-- <dependency>--> |
| | | <!-- <groupId>com.huaweicloud</groupId>--> |
| | | <!-- <artifactId>esdk-obs-java-bundle</artifactId>--> |
| | | <!-- <version>[3.21.11,)</version>--> |
| | | <!-- </dependency>--> |
| | | <!-- 引入lombok/--> |
| | | <dependency> |
| | | <groupId>org.projectlombok</groupId> |
| | | <artifactId>lombok</artifactId> |
| | | <version>1.18.4</version> |
| | | <scope>provided</scope> |
| | | </dependency> |
| | | <!-- 引入hutool工具/--> |
| | | <!-- <dependency>--> |
| | | <!-- <groupId>cn.hutool</groupId>--> |
| | | <!-- <artifactId>hutool-all</artifactId>--> |
| | | <!-- <version>5.8.0.M4</version>--> |
| | | <!-- </dependency>--> |
| | | <dependency> |
| | | <groupId>cn.hutool</groupId> |
| | | <artifactId>hutool-core</artifactId> |
| | | <version>5.6.5</version> |
| | | </dependency> |
| | | <dependency> |
| | | <groupId>com.alibaba</groupId> |
| | | <artifactId>druid</artifactId> |
New file |
| | |
| | | package com.qxueyou.scc.config; |
| | | |
| | | import com.obs.services.ObsClient; |
| | | import com.obs.services.exception.ObsException; |
| | | import com.qxueyou.scc.teach.res.service.impl.HweiYunOBSServiceImpl; |
| | | import lombok.Data; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.apache.logging.log4j.LogManager; |
| | | import org.apache.logging.log4j.Logger; |
| | | import org.springframework.beans.factory.annotation.Value; |
| | | import org.springframework.context.annotation.Configuration; |
| | | |
| | | import java.text.SimpleDateFormat; |
| | | import java.util.Date; |
| | | |
| | | /** |
| | | * @ClassName: HweiOBSConfig |
| | | * @Description: 华为云OBS配置类 |
| | | * @Author: wuhuiju |
| | | * @Date: 2021-12-21 15:56 |
| | | * @Version: 1.0 |
| | | */ |
| | | //@Data |
| | | //@Slf4j |
| | | @Configuration |
| | | public class HweiOBSConfig { |
| | | |
| | | private final Logger log = LogManager.getLogger(HweiOBSConfig.class); |
| | | public HweiOBSConfig() { |
| | | } |
| | | |
| | | public HweiOBSConfig(String accessKey, String securityKey, String endPoint, String bucketName) { |
| | | this.accessKey = accessKey; |
| | | this.securityKey = securityKey; |
| | | this.endPoint = endPoint; |
| | | this.bucketName = bucketName; |
| | | } |
| | | |
| | | public String getAccessKey() { |
| | | return accessKey; |
| | | } |
| | | |
| | | public void setAccessKey(String accessKey) { |
| | | this.accessKey = accessKey; |
| | | } |
| | | |
| | | public String getSecurityKey() { |
| | | return securityKey; |
| | | } |
| | | |
| | | public void setSecurityKey(String securityKey) { |
| | | this.securityKey = securityKey; |
| | | } |
| | | |
| | | public String getEndPoint() { |
| | | return endPoint; |
| | | } |
| | | |
| | | public void setEndPoint(String endPoint) { |
| | | this.endPoint = endPoint; |
| | | } |
| | | |
| | | public String getBucketName() { |
| | | return bucketName; |
| | | } |
| | | |
| | | public void setBucketName(String bucketName) { |
| | | this.bucketName = bucketName; |
| | | } |
| | | |
| | | /** |
| | | * 访问密钥AK |
| | | */ |
| | | @Value("${hwyun.obs.accessKey}") |
| | | private String accessKey; |
| | | |
| | | /** |
| | | * 访问密钥SK |
| | | */ |
| | | @Value("${hwyun.obs.securityKey}") |
| | | private String securityKey; |
| | | |
| | | /** |
| | | * 终端节点 |
| | | */ |
| | | @Value("${hwyun.obs.endPoint}") |
| | | private String endPoint; |
| | | |
| | | /** |
| | | * 桶 |
| | | */ |
| | | @Value("${hwyun.obs.bucketName}") |
| | | private String bucketName; |
| | | |
| | | /** |
| | | * @Description 获取OBS客户端实例 |
| | | * @author wuhuiju |
| | | * @date 2022/12/2 15:57 |
| | | * @return |
| | | * @return: com.obs.services.ObsClient |
| | | */ |
| | | public ObsClient getInstance() { |
| | | return new ObsClient(accessKey, securityKey, endPoint); |
| | | } |
| | | |
| | | |
| | | /** |
| | | * @Description 销毁OBS客户端实例 |
| | | * @author wuhuiju |
| | | * @date 2022/12/2 17:32 |
| | | * @param: obsClient |
| | | * @return |
| | | */ |
| | | public void destroy(ObsClient obsClient){ |
| | | try { |
| | | obsClient.close(); |
| | | } catch (ObsException e) { |
| | | log.error("obs执行失败", e); |
| | | } catch (Exception e) { |
| | | log.error("执行失败", e); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * @Description 微服务文件存放路径 |
| | | * @author wuhuiju |
| | | * @date 2022/12/2 15:57 |
| | | * @return |
| | | * @return: java.lang.String |
| | | */ |
| | | public static String getObjectKey() { |
| | | // 项目或者服务名称 + 日期存储方式 |
| | | return "Hwei" + "/" + new SimpleDateFormat("yyyy-MM-dd").format(new Date() )+ "/"; |
| | | } |
| | | } |
New file |
| | |
| | | package com.qxueyou.scc.controller; |
| | | |
| | | import cn.hutool.core.io.FileUtil; |
| | | import cn.hutool.core.io.IoUtil; |
| | | import cn.hutool.core.util.ArrayUtil; |
| | | import cn.hutool.core.util.StrUtil; |
| | | |
| | | //import cn.hutool.core.io.FileUtil; |
| | | import com.obs.services.exception.ObsException; |
| | | import com.qxueyou.scc.base.model.Result; |
| | | import com.qxueyou.scc.teach.res.service.HweiYunOBSService; |
| | | import org.springframework.util.ObjectUtils; |
| | | import org.springframework.web.bind.annotation.*; |
| | | import org.springframework.web.multipart.MultipartFile; |
| | | |
| | | import javax.annotation.Resource; |
| | | import javax.servlet.http.HttpServletRequest; |
| | | import javax.servlet.http.HttpServletResponse; |
| | | import java.io.BufferedOutputStream; |
| | | import java.io.IOException; |
| | | import java.io.InputStream; |
| | | import java.net.URLEncoder; |
| | | import java.util.List; |
| | | |
| | | /** |
| | | * @ClassName: ObsController |
| | | * @Description: OBS服务器Controller |
| | | * @Author: wuhuiju |
| | | * @Date: 2021-12-21 15:20 |
| | | * @Version: 1.0 |
| | | */ |
| | | @RestController |
| | | @RequestMapping({ "file" })// @RequestMapping("/file") |
| | | public class HweiYunOBSController { |
| | | |
| | | @Resource |
| | | private HweiYunOBSService hweiYunOBSService; |
| | | |
| | | @RequestMapping(value = "upload", method = RequestMethod.POST) |
| | | public Result save(@RequestParam(value = "file", required = false) MultipartFile file) { |
| | | |
| | | if (ObjectUtils.isEmpty(file) || file.getSize() <= 0) { |
| | | return new Result(false,"文件为空"); |
| | | } |
| | | // if (FileUtil.isEmpty(file)) { |
| | | // return new Result(false,"文件为空"); |
| | | // } |
| | | final String test = hweiYunOBSService.fileUpload(file, file.getOriginalFilename()); |
| | | // return ResponseVO.ok("执行成功",test); |
| | | return new Result(true,"success",test); |
| | | } |
| | | |
| | | @RequestMapping(value = "delete", method = RequestMethod.POST) |
| | | public Result delete(@RequestParam(value = "fileName", required = false) String fileName) { |
| | | if (StrUtil.isEmpty(fileName)) { |
| | | return new Result(false,"删除文件为空"); |
| | | } |
| | | final boolean delete = hweiYunOBSService.delete(fileName); |
| | | return delete?new Result(true,"success"):new Result(false,"删除失败"); |
| | | } |
| | | |
| | | @RequestMapping(value = "deletes", method = RequestMethod.POST) |
| | | //@RequestParam 获取List,数组则不需要 |
| | | public Result delete(@RequestParam("fileNames") List<String> fileNames) { |
| | | if (ArrayUtil.isEmpty(fileNames)) { |
| | | return new Result(false,"删除文件为空"); |
| | | } |
| | | final boolean delete = hweiYunOBSService.delete(fileNames); |
| | | return delete?new Result(true,"success"):new Result(false,"删除失败"); |
| | | } |
| | | |
| | | |
| | | @RequestMapping(value = "download", method = RequestMethod.POST) |
| | | public Result download(HttpServletRequest request, HttpServletResponse response, @RequestParam(value = "fileName", required = false) String fileName) { |
| | | if (StrUtil.isEmpty(fileName)) { |
| | | return new Result(false,"下载文件为空"); |
| | | } |
| | | try ( |
| | | InputStream inputStream = hweiYunOBSService.fileDownload(fileName); |
| | | BufferedOutputStream outputStream = new BufferedOutputStream(response.getOutputStream())){ |
| | | if(inputStream == null) { |
| | | return new Result(false); |
| | | } |
| | | // 为防止 文件名出现乱码 |
| | | final String userAgent = request.getHeader("USER-AGENT"); |
| | | // IE浏览器 |
| | | if (StrUtil.contains(userAgent, "MSIE")) { |
| | | fileName = URLEncoder.encode(fileName, "UTF-8"); |
| | | } else { |
| | | // google,火狐浏览器 |
| | | if (StrUtil.contains(userAgent, "Mozilla")) { |
| | | fileName = new String(fileName.getBytes(), "ISO8859-1"); |
| | | } else { |
| | | // 其他浏览器 |
| | | fileName = URLEncoder.encode(fileName, "UTF-8"); |
| | | } |
| | | } |
| | | response.setContentType("application/x-download"); |
| | | // 设置让浏览器弹出下载提示框,而不是直接在浏览器中打开 |
| | | response.addHeader("Content-Disposition", "attachment;filename=" + fileName); |
| | | IoUtil.copy(inputStream, outputStream); |
| | | return null; |
| | | } catch (IOException | ObsException e) { |
| | | return new Result(false); |
| | | } |
| | | } |
| | | } |
New file |
| | |
| | | package com.qxueyou.scc.portal.expert.controller; |
| | | |
| | | |
| | | import com.qxueyou.scc.base.model.Result; |
| | | import com.qxueyou.scc.portal.expert.service.IExpertService; |
| | | import com.qxueyou.scc.portal.expert.vo.ExpertVO; |
| | | import com.qxueyou.scc.portal.information.service.IInformationService; |
| | | import com.qxueyou.scc.portal.information.vo.ListArticleVO; |
| | | import com.qxueyou.scc.portal.information.vo.SaveArticleVO; |
| | | import com.qxueyou.scc.portal.information.vo.UpdateArticleVO; |
| | | import io.swagger.annotations.Api; |
| | | import io.swagger.annotations.ApiImplicitParam; |
| | | import io.swagger.annotations.ApiOperation; |
| | | import org.apache.commons.lang3.StringUtils; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.web.bind.annotation.*; |
| | | |
| | | /** |
| | | * 专家控制器 |
| | | * |
| | | * @author angy |
| | | * @created by 2021/3/1 |
| | | */ |
| | | @RestController |
| | | @RequestMapping("/expert") |
| | | @Api(tags = "专家控制器") |
| | | public class ExpertController { |
| | | |
| | | @Autowired |
| | | private IExpertService iExpertService; |
| | | |
| | | |
| | | @GetMapping("/list") |
| | | @ApiOperation("获取专家列表") |
| | | public Result listExpert(@RequestBody ExpertVO vo) { |
| | | return iExpertService.listExpert(vo); |
| | | } |
| | | // |
| | | @PostMapping("/add") |
| | | @ApiOperation("新增") |
| | | public Result save(@RequestBody ExpertVO vo) { |
| | | return iExpertService.save(vo); |
| | | } |
| | | |
| | | @DeleteMapping("/delete") |
| | | @ApiOperation("删除") |
| | | @ApiImplicitParam(name = "ids", value = "专家id", dataType = "string", required = true) |
| | | public Result delete( String ids) { |
| | | |
| | | if (StringUtils.isBlank(ids)) { |
| | | return new Result(false, "id is not blank!"); |
| | | } |
| | | return iExpertService.delete(ids); |
| | | } |
| | | // |
| | | @PutMapping("/update") |
| | | @ApiOperation("更新") |
| | | public Result update(@RequestBody ExpertVO vo) { |
| | | return iExpertService.update(vo); |
| | | } |
| | | // |
| | | @GetMapping("/getArticleById") |
| | | @ApiOperation("获取专家详情") |
| | | @ApiImplicitParam(name = "id", value = "文章id", dataType = "string", required = true) |
| | | public Result getExpertById( String id) { |
| | | if (StringUtils.isBlank(id)) { |
| | | return new Result(false, "id is not blank!"); |
| | | } |
| | | return iExpertService.getExpertById(id); |
| | | } |
| | | } |
New file |
| | |
| | | package com.qxueyou.scc.portal.expert.model; |
| | | |
| | | |
| | | //sa_information |
| | | |
| | | |
| | | import com.fasterxml.jackson.annotation.JsonIgnore; |
| | | import org.hibernate.annotations.GenericGenerator; |
| | | import org.springframework.format.annotation.DateTimeFormat; |
| | | |
| | | import javax.persistence.*; |
| | | import java.io.Serializable; |
| | | import java.util.Date; |
| | | |
| | | //@Proxy(lazy = false) |
| | | @Entity |
| | | @Table( name = "sa_expert") |
| | | public class Expert implements Serializable { |
| | | |
| | | private static final long serialVersionUID = 1L; |
| | | |
| | | public Expert() { |
| | | |
| | | } |
| | | |
| | | |
| | | private String id; |
| | | public void setId(String id) { |
| | | this.id = id; |
| | | } |
| | | |
| | | @Id |
| | | @GeneratedValue(generator = "hibernate-uuid") |
| | | @GenericGenerator(name = "hibernate-uuid", strategy = "uuid") |
| | | @Column(name = "ID", unique = true, nullable = false, length = 32) |
| | | public String getId() { |
| | | return id; |
| | | } |
| | | |
| | | private String nameExpert; |
| | | private String job; |
| | | private String domesticUnit; |
| | | private String dispatchedUnit; |
| | | private String expertImg; |
| | | private String personalInformation; |
| | | private Date createTime; |
| | | private Date updateTime; |
| | | private Integer deleteFlag; |
| | | |
| | | |
| | | public Expert(String id, String nameExpert, String job, String domesticUnit, String dispatchedUnit, String expertImg, Date createTime, Date updateTime, Integer deleteFlag) { |
| | | this.id = id; |
| | | this.nameExpert = nameExpert; |
| | | this.job = job; |
| | | this.domesticUnit = domesticUnit; |
| | | this.dispatchedUnit = dispatchedUnit; |
| | | this.expertImg = expertImg; |
| | | this.createTime = createTime; |
| | | this.updateTime = updateTime; |
| | | this.deleteFlag = deleteFlag; |
| | | } |
| | | |
| | | @Column(name = "PERSONAL_INFORMATION", nullable = false) |
| | | public String getPersonalInformation() { |
| | | return personalInformation; |
| | | } |
| | | |
| | | public void setPersonalInformation(String personalInformation) { |
| | | this.personalInformation = personalInformation; |
| | | } |
| | | @Column(name = "NAME_EXPERT", nullable = false, length = 20) |
| | | public String getNameExpert() { |
| | | return nameExpert; |
| | | } |
| | | |
| | | public void setNameExpert(String nameExpert) { |
| | | this.nameExpert = nameExpert; |
| | | } |
| | | @Column(name = "JOB", nullable = false, length = 20) |
| | | public String getJob() { |
| | | return job; |
| | | } |
| | | |
| | | public void setJob(String job) { |
| | | this.job = job; |
| | | } |
| | | @Column(name = "DOMESTIC_UNIT", nullable = false, length = 20) |
| | | public String getDomesticUnit() { |
| | | return domesticUnit; |
| | | } |
| | | |
| | | public void setDomesticUnit(String domesticUnit) { |
| | | this.domesticUnit = domesticUnit; |
| | | } |
| | | |
| | | @Column(name = "DISPATCHED_UNIT", nullable = false, length = 20) |
| | | public String getDispatchedUnit() { |
| | | return dispatchedUnit; |
| | | } |
| | | |
| | | public void setDispatchedUnit(String dispatchedUnit) { |
| | | this.dispatchedUnit = dispatchedUnit; |
| | | } |
| | | |
| | | @Column(name = "EXPERT_IMG", nullable = false, length = 50) |
| | | public String getExpertImg() { |
| | | return expertImg; |
| | | } |
| | | |
| | | public void setExpertImg(String expertImg) { |
| | | this.expertImg = expertImg; |
| | | } |
| | | |
| | | @Column(name = "CREATE_TIME") |
| | | @Temporal(TemporalType.TIMESTAMP) |
| | | @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") |
| | | @JsonIgnore |
| | | public Date getCreateTime() { |
| | | return createTime; |
| | | } |
| | | |
| | | |
| | | public void setCreateTime(Date createTime) { |
| | | this.createTime = createTime; |
| | | } |
| | | |
| | | @Column(name = "UPDATE_TIME") |
| | | @Temporal(TemporalType.TIMESTAMP) |
| | | @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") |
| | | @JsonIgnore |
| | | public Date getUpdateTime() { |
| | | return updateTime; |
| | | } |
| | | |
| | | public void setUpdateTime(Date updateTime) { |
| | | this.updateTime = updateTime; |
| | | } |
| | | |
| | | @Column(name = "DELTE_FLAG" ) |
| | | public Integer getDeleteFlag() { |
| | | return deleteFlag; |
| | | } |
| | | public void setDeleteFlag(Integer deleteFlag) { |
| | | this.deleteFlag = deleteFlag; |
| | | } |
| | | |
| | | |
| | | } |
New file |
| | |
| | | package com.qxueyou.scc.portal.expert.service; |
| | | |
| | | import com.qxueyou.scc.base.model.Result; |
| | | import com.qxueyou.scc.portal.expert.vo.ExpertVO; |
| | | import com.qxueyou.scc.portal.information.vo.ListArticleVO; |
| | | import com.qxueyou.scc.portal.information.vo.SaveArticleVO; |
| | | import com.qxueyou.scc.portal.information.vo.UpdateArticleVO; |
| | | |
| | | public interface IExpertService { |
| | | |
| | | |
| | | /** |
| | | * 查询专家列表 |
| | | */ |
| | | |
| | | Result listExpert(ExpertVO vo); |
| | | |
| | | /** |
| | | *获取专家总条数 |
| | | * @param |
| | | * @return |
| | | */ |
| | | int findExpertCount(ExpertVO vo) ; |
| | | /** |
| | | * 添加专家 |
| | | * |
| | | * @param vo |
| | | * @return |
| | | */ |
| | | Result save(ExpertVO vo); |
| | | /** |
| | | * 删除专家 |
| | | * |
| | | * @param ids |
| | | * @return |
| | | */ |
| | | Result delete(String ids); |
| | | /** |
| | | * 更新专家信息 |
| | | * |
| | | * @param vo |
| | | * @return |
| | | */ |
| | | Result update(ExpertVO vo); |
| | | /** |
| | | * 获取专家信息 |
| | | * |
| | | * @param id |
| | | * @return |
| | | */ |
| | | Result getExpertById(String id); |
| | | } |
New file |
| | |
| | | package com.qxueyou.scc.portal.expert.service.imp; |
| | | |
| | | import com.qxueyou.scc.base.model.Pager; |
| | | import com.qxueyou.scc.base.model.Result; |
| | | import com.qxueyou.scc.base.service.impl.CommonAppService; |
| | | import com.qxueyou.scc.base.util.CollectionUtils; |
| | | import com.qxueyou.scc.portal.expert.model.Expert; |
| | | import com.qxueyou.scc.portal.expert.service.IExpertService; |
| | | import com.qxueyou.scc.portal.expert.vo.ExpertVO; |
| | | import com.qxueyou.scc.portal.information.dto.ArticleInfoDTO; |
| | | import com.qxueyou.scc.portal.information.model.Information; |
| | | import com.qxueyou.scc.portal.information.service.IInformationService; |
| | | import org.springframework.beans.BeanUtils; |
| | | import org.springframework.stereotype.Service; |
| | | |
| | | import java.util.Date; |
| | | import java.util.List; |
| | | |
| | | @Service |
| | | public class ExpertService extends CommonAppService implements IExpertService { |
| | | |
| | | |
| | | |
| | | @Override |
| | | public Result listExpert(ExpertVO vo) { |
| | | |
| | | String hql = "from Expert where deleteFlag=0 and nameExpert like ? order by createTime desc"; |
| | | int count =findExpertCount( vo);//专家总条数 |
| | | List<Expert> list = findList(hql, new Pager(vo.getSize(), vo.getPage()), CollectionUtils.newList(vo.getKeyword().concat("%")), Expert.class); |
| | | return new Result(true,"success", CollectionUtils.newObjectMap("list", list, "count", count)); |
| | | } |
| | | |
| | | @Override |
| | | public int findExpertCount(ExpertVO vo) { |
| | | String hql = "from Expert where deleteFlag=0 and nameExpert like :nameExpert"; |
| | | return findCountByComplexHql(hql, CollectionUtils.newObjectMap("nameExpert",vo.getKeyword().concat("%"))); |
| | | } |
| | | |
| | | @Override |
| | | public Result save(ExpertVO vo) { |
| | | Expert expert = new Expert(); |
| | | BeanUtils.copyProperties(vo, expert); |
| | | expert.setDeleteFlag(0); |
| | | expert.setCreateTime(new Date()); |
| | | expert.setUpdateTime(new Date()); |
| | | save(expert); |
| | | return Result.SUCCESS; |
| | | } |
| | | |
| | | @Override |
| | | public Result delete(String ids) { |
| | | |
| | | Result result = new Result(true); |
| | | String[] arrStr = ids.split(","); |
| | | if (arrStr != null && arrStr.length > 0) { |
| | | String hql = "update Expert set deleteFlag = 1 where Id=?"; |
| | | result = bulkUpdateInLoop(hql, arrStr); |
| | | } |
| | | return result; |
| | | } |
| | | |
| | | @Override |
| | | public Result update(ExpertVO vo) { |
| | | Expert expert = read(Expert.class, vo.getId()); |
| | | BeanUtils.copyProperties(vo, expert); |
| | | save(expert); |
| | | return Result.SUCCESS; |
| | | } |
| | | |
| | | @Override |
| | | public Result getExpertById(String id) { |
| | | Expert expert = read(Expert.class, id); |
| | | return new Result(true, "expertDTO",expert); |
| | | } |
| | | } |
New file |
| | |
| | | package com.qxueyou.scc.portal.expert.vo; |
| | | |
| | | import io.swagger.annotations.ApiModel; |
| | | import io.swagger.annotations.ApiModelProperty; |
| | | import org.hibernate.validator.constraints.NotBlank; |
| | | |
| | | import javax.validation.constraints.NotNull; |
| | | |
| | | /** |
| | | * @author angy |
| | | * @created by 2021/3/1 |
| | | */ |
| | | @ApiModel("ExpertVO") |
| | | public class ExpertVO { |
| | | @NotBlank(message = "专家ID不能为空!") |
| | | @ApiModelProperty(name = "id", value = "专家Id", dataType = "string", required = true) |
| | | private String id; |
| | | |
| | | public String getId() { |
| | | return id; |
| | | } |
| | | |
| | | public void setId(String id) { |
| | | this.id = id; |
| | | } |
| | | |
| | | //页码 |
| | | @NotNull(message = "页码不能为空!") |
| | | @ApiModelProperty(value = "页码", name = "page", dataType = "integer", required = true) |
| | | private Integer page; |
| | | |
| | | //页数 |
| | | @NotNull(message = "页数不能为空!") |
| | | @ApiModelProperty(value = "页数", name = "size", dataType = "integer", required = true) |
| | | private Integer size; |
| | | |
| | | //关键字 |
| | | @ApiModelProperty(value = "搜索关键字", name = "keyword", dataType = "string") |
| | | private String keyword; |
| | | @ApiModelProperty(value = "专家名称", name = "nameExpert", dataType = "string") |
| | | private String nameExpert; |
| | | @ApiModelProperty(value = "职务", name = "job", dataType = "string") |
| | | private String job; |
| | | @ApiModelProperty(value = "国内单位", name = "domesticUnit", dataType = "string") |
| | | private String domesticUnit; |
| | | @ApiModelProperty(value = "外派单位", name = "dispatchedUnit", dataType = "string") |
| | | private String dispatchedUnit; |
| | | @ApiModelProperty(value = "专家照片", name = "expertImg", dataType = "string") |
| | | private String expertImg; |
| | | @ApiModelProperty(value = "个人简介", name = "personalInformation", dataType = "string") |
| | | private String personalInformation; |
| | | |
| | | public Integer getPage() { |
| | | return page; |
| | | } |
| | | |
| | | public void setPage(Integer page) { |
| | | this.page = page; |
| | | } |
| | | |
| | | public Integer getSize() { |
| | | return size; |
| | | } |
| | | |
| | | public void setSize(Integer size) { |
| | | this.size = size; |
| | | } |
| | | |
| | | public String getKeyword() { |
| | | return keyword; |
| | | } |
| | | |
| | | public void setKeyword(String keyword) { |
| | | this.keyword = keyword; |
| | | } |
| | | |
| | | public String getNameExpert() { |
| | | return nameExpert; |
| | | } |
| | | |
| | | public void setNameExpert(String nameExpert) { |
| | | this.nameExpert = nameExpert; |
| | | } |
| | | |
| | | public String getJob() { |
| | | return job; |
| | | } |
| | | |
| | | public void setJob(String job) { |
| | | this.job = job; |
| | | } |
| | | |
| | | public String getDomesticUnit() { |
| | | return domesticUnit; |
| | | } |
| | | |
| | | public void setDomesticUnit(String domesticUnit) { |
| | | this.domesticUnit = domesticUnit; |
| | | } |
| | | |
| | | public String getDispatchedUnit() { |
| | | return dispatchedUnit; |
| | | } |
| | | |
| | | public void setDispatchedUnit(String dispatchedUnit) { |
| | | this.dispatchedUnit = dispatchedUnit; |
| | | } |
| | | |
| | | public String getExpertImg() { |
| | | return expertImg; |
| | | } |
| | | |
| | | public void setExpertImg(String expertImg) { |
| | | this.expertImg = expertImg; |
| | | } |
| | | |
| | | public String getPersonalInformation() { |
| | | return personalInformation; |
| | | } |
| | | |
| | | public void setPersonalInformation(String personalInformation) { |
| | | this.personalInformation = personalInformation; |
| | | } |
| | | } |
New file |
| | |
| | | package com.qxueyou.scc.portal.homepage.controller; |
| | | |
| | | //import com.qxueyou.appraisal.web.homepage.serivce.IHomepageService; |
| | | //import com.qxueyou.model.Result; |
| | | import com.qxueyou.scc.base.model.Result; |
| | | import com.qxueyou.scc.portal.homepage.serivce.IHomepageService; |
| | | import io.swagger.annotations.Api; |
| | | import io.swagger.annotations.ApiOperation; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.web.bind.annotation.GetMapping; |
| | | import org.springframework.web.bind.annotation.RequestMapping; |
| | | import org.springframework.web.bind.annotation.RestController; |
| | | |
| | | /** |
| | | * @author ZERO 2021-03-03 09:06 |
| | | */ |
| | | @RestController |
| | | @RequestMapping("/homepage") |
| | | @Api(tags = "首页相关接口") |
| | | public class HomepageController { |
| | | |
| | | @Autowired |
| | | private IHomepageService homepageService; |
| | | |
| | | @GetMapping(value = "/tab",produces = "application/json;charset=utf-8") |
| | | @ApiOperation("获取标签") |
| | | public Result getTabs() { |
| | | |
| | | return new Result(true, "tab",homepageService.getTabs()); |
| | | } |
| | | |
| | | // @GetMapping |
| | | // @ApiOperation("获取列表") |
| | | // public Result getIndexDetail() { |
| | | //// System.err.println("=====>获取列表"); |
| | | // return new Result(true,"", homepageService.getIndexDetail()); |
| | | // } |
| | | |
| | | @GetMapping("/article") |
| | | @ApiOperation("获取文章列表") |
| | | public Result getArticle(String type, String subColumn, String numbers, int page, int size, String keyword) { |
| | | System.err.println("=====>获取文章列表"); |
| | | return new Result(true, "article",homepageService.getArticle(type, subColumn, numbers, page, size, keyword)); |
| | | } |
| | | |
| | | @GetMapping("/article/detail") |
| | | @ApiOperation("获取文章详情") |
| | | public Result getArticleDetail(String id) { |
| | | |
| | | return new Result(true,"detail", homepageService.getArticleDetail(id)); |
| | | } |
| | | |
| | | @GetMapping("/getArticle") |
| | | @ApiOperation("获取文章") |
| | | public Result getGetArticle(String type, String subColumn) { |
| | | return new Result(true,"getArticle", homepageService.getArticlesType(type, subColumn)); |
| | | } |
| | | |
| | | @GetMapping("/video") |
| | | public Result getVideo(String type, String subColumn, int page, int size) { |
| | | return new Result(true, "video",homepageService.getVideo(type, subColumn, page, size)); |
| | | } |
| | | } |
New file |
| | |
| | | package com.qxueyou.scc.portal.homepage.dao; |
| | | |
| | | //import com.qxueyou.entity.article.ArticleDO; |
| | | //import com.qxueyou.service.MongoService; |
| | | //import com.qxueyou.util.CollectionUtils; |
| | | import com.qxueyou.scc.base.dao.BaseDAO; |
| | | import com.qxueyou.scc.base.model.Pager; |
| | | import com.qxueyou.scc.base.util.ClientUtils; |
| | | import com.qxueyou.scc.base.util.CollectionUtils; |
| | | import com.qxueyou.scc.portal.information.model.Information; |
| | | import org.apache.commons.lang3.StringUtils; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.data.domain.PageRequest; |
| | | import org.springframework.data.domain.Sort; |
| | | //import org.springframework.data.mongodb.core.query.Criteria; |
| | | //import org.springframework.data.mongodb.core.query.Query; |
| | | //import org.springframework.data.mongodb.core.query.Update; |
| | | import org.springframework.stereotype.Repository; |
| | | |
| | | import javax.annotation.PostConstruct; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | import java.util.stream.Collectors; |
| | | |
| | | /** |
| | | * @author ZERO 2021-03-03 16:36 |
| | | */ |
| | | @Repository |
| | | public class ArticleDao extends BaseDAO { |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | public Map<String, Object> moreOccupation(String type, String subColumn, String numbers,int page, int size, String keyword) { |
| | | |
| | | StringBuffer hql = new StringBuffer(500); |
| | | hql.append( "from Information where deleteFlag=0 and type = ? and status= ?"); |
| | | List<Object> params = CollectionUtils.newList(type, Information.UP_STATUS); |
| | | |
| | | // Map<String, Object> condition = CollectionUtils.newObjectMap("type", type, "status", Information.UP_STATUS); |
| | | if(StringUtils.isNotEmpty(keyword)){ |
| | | hql.append( " and title = ? "); |
| | | params.add(keyword); |
| | | } |
| | | if (type.equals("examBriefing")) { |
| | | hql.append( "and subColumn = ? "); |
| | | params.add( subColumn); |
| | | } |
| | | // if(subColumn!=null) { |
| | | // if (subColumn.equals("previousContest")) { |
| | | // condition.put("numbers", numbers); |
| | | // } |
| | | // } |
| | | |
| | | |
| | | long totalCount = findCount(hql.toString(),params); |
| | | hql.append( "order by dateTime desc"); |
| | | |
| | | List<Information> articleList = findList(hql.toString(),new Pager(page,size),params,Information.class); |
| | | |
| | | |
| | | List<Map<String, Object>> data = articleList |
| | | .stream() |
| | | .map(article -> CollectionUtils.newObjectMap( |
| | | "id", article.getId(), |
| | | "content", article.getContent(), |
| | | "title", article.getTitle(), |
| | | "attachment", article.getAttachment(), |
| | | "browseCount", article.getBrowseCount(), |
| | | "status", article.getStatus(), |
| | | "thumbnailUrl", article.getThumbnailUrl(), |
| | | "type", article.getType(), |
| | | "dateTime", article.getDateTime(), |
| | | "competition",article.getCompetition())) |
| | | .collect(Collectors.toList()); |
| | | |
| | | return CollectionUtils.newObjectMap("totalCount", totalCount, "data", data); |
| | | } |
| | | |
| | | public Map<String, Object> getVideoList(String type, String subColumn,int page, int size){ |
| | | StringBuffer hql = new StringBuffer(500); |
| | | hql.append( "from Information where deleteFlag=0 and type = ? and status= ? "); |
| | | List<Object> params = CollectionUtils.newList(type, Information.UP_STATUS); |
| | | // Map<String, Object> condition = CollectionUtils.newObjectMap("type", type, "status", Information.UP_STATUS); |
| | | |
| | | if (type.equals("examBriefing")) { |
| | | hql.append( "and subColumn = ? "); |
| | | params.add( subColumn); |
| | | } |
| | | long totalCount = findCount(hql.toString(),params); |
| | | hql.append( "order by dateTime desc"); |
| | | |
| | | |
| | | List<Information> articleList =findList(hql.toString(),new Pager(page,size),params,Information.class); |
| | | List<Map<String, Object>> data = articleList |
| | | .stream() |
| | | .map(article -> CollectionUtils.newObjectMap( |
| | | "title", article.getTitle(), |
| | | "type", article.getType(), |
| | | "dateTime", article.getDateTime(), |
| | | "videoUrl",article.getVideoUrl(), |
| | | "name",article.getNumbers())) |
| | | .collect(Collectors.toList()); |
| | | |
| | | return CollectionUtils.newObjectMap("totalCount", totalCount, "data", data); |
| | | } |
| | | // |
| | | public boolean exist(String type) { |
| | | String hql= "from Information where deleteFlag=0 and type = ? and status= ? "; |
| | | long totalCount = findCount(hql,CollectionUtils.newList(type, Information.UP_STATUS)); |
| | | return totalCount>0?true:false; |
| | | } |
| | | // |
| | | public boolean existsubColumn(String type, String subColumn) { |
| | | |
| | | |
| | | String hql= "from Information where deleteFlag=0 and type = ? and status= ? and subColumn=?"; |
| | | long totalCount = findCount(hql,CollectionUtils.newList(type, Information.UP_STATUS,subColumn)); |
| | | return totalCount>0?true:false; |
| | | } |
| | | |
| | | public Map<String, Object> getPreAndBehindArticle(String currentArticleId, String type) { |
| | | StringBuffer hql = new StringBuffer(500); |
| | | hql.append("from Information where deleteFlag=0 and type = ? and status= ? order by updateTime desc"); |
| | | List<Object> params = CollectionUtils.newList(type, Information.UP_STATUS); |
| | | // Query query = Query.query(Criteria.where("type").is(type) |
| | | // .and("status").is(ArticleDO.UP_STATUS) |
| | | // .and("deleteFlag").is(false)) |
| | | // .with(Sort.by(Sort.Direction.DESC, "updateTime")); |
| | | // query.fields().include("id"); |
| | | // List<Information> articleList =find(hql.toString(),params,Information.class); |
| | | List<String> articleIdList = find(hql.toString(),params,Information.class) |
| | | .stream() |
| | | .map(Information::getId) |
| | | .collect(Collectors.toList()); |
| | | |
| | | int currentIndex = articleIdList.indexOf(currentArticleId); |
| | | |
| | | Map<String, Object> data = CollectionUtils.newObjectMap("previous", null, "behind", null); |
| | | |
| | | if (currentIndex != 0) { |
| | | Information preArticle = read(Information.class,articleIdList.get(currentIndex - 1)); |
| | | data.put("previous", CollectionUtils.newObjectMap( |
| | | "id", preArticle.getId(), |
| | | "title", preArticle.getTitle(), |
| | | "type", preArticle.getType())); |
| | | } |
| | | |
| | | if (currentIndex != articleIdList.size() - 1) { |
| | | Information behindArticle = read(Information.class,articleIdList.get(currentIndex + 1)); |
| | | data.put("previous", CollectionUtils.newObjectMap( |
| | | "id", behindArticle.getId(), |
| | | "title", behindArticle.getTitle(), |
| | | "type", behindArticle.getType())); |
| | | } |
| | | |
| | | return data; |
| | | } |
| | | // |
| | | public void incBrowseCount(String id) { |
| | | // Query query = Query.query(Criteria.where("id").is(id)); |
| | | // Update update = new Update(); |
| | | // update.inc("browseCount", 1); |
| | | // template.updateFirst(query, update, clz); |
| | | Information behindArticle = read(Information.class,id); |
| | | behindArticle.setBrowseCount(behindArticle.getBrowseCount()+1); |
| | | saveOrUpdate(behindArticle); |
| | | } |
| | | |
| | | public Information getArticle(String type,String subColumn) |
| | | { |
| | | StringBuffer hql = new StringBuffer(500); |
| | | hql.append( "from Information where deleteFlag=0 and type = ? and status= ? order by updateTime desc"); |
| | | List<Object> params = CollectionUtils.newList(type, Information.UP_STATUS); |
| | | |
| | | if (type.equals("examBriefing")) { |
| | | hql.append( "and subColumn = ? "); |
| | | params.add( subColumn); |
| | | } |
| | | // Query query = Query.query(Criteria.where("type").is(type) |
| | | // .and("status").is(ArticleDO.UP_STATUS) |
| | | // .and("deleteFlag").is(false)) |
| | | // .with(Sort.by(Sort.Direction.DESC, "updateTime")); |
| | | // System.out.println(type); |
| | | // if (type.equals("examBriefing")) { |
| | | // query.addCriteria(Criteria.where("subColumn").is(subColumn)); |
| | | // } |
| | | Information articleDO = findUnique(hql.toString(), params, Information.class); |
| | | // ArticleDO articleDO =findOne(query,ArticleDO.class); |
| | | return articleDO; |
| | | } |
| | | } |
New file |
| | |
| | | package com.qxueyou.scc.portal.homepage.serivce; |
| | | |
| | | import com.qxueyou.scc.portal.information.model.Information; |
| | | |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | |
| | | /** |
| | | * @author ZERO 2021-03-03 09:16 |
| | | */ |
| | | public interface IHomepageService { |
| | | |
| | | /** |
| | | * 获取首页数据 |
| | | // */ |
| | | // Map<String, Object> getIndexDetail(); |
| | | |
| | | /** |
| | | * 获取首页标签 |
| | | */ |
| | | List<Map<String, Object>> getTabs(); |
| | | |
| | | /** |
| | | * 获取文章列表 |
| | | */ |
| | | Map<String, Object> getArticle(String type,String subColumn,String numbers, int page, int size, String keyword); |
| | | |
| | | Map<String, Object> getArticleDetail(String id); |
| | | |
| | | Information getArticlesType(String type, String subColumn); |
| | | |
| | | Map<String,Object> getVideo(String type,String subColumn,int page, int size); |
| | | |
| | | } |
New file |
| | |
| | | package com.qxueyou.scc.portal.homepage.serivce.imp; |
| | | |
| | | //import com.qxueyou.appraisal.web.homepage.dao.AppraisalBatchDao; |
| | | |
| | | //import com.qxueyou.appraisal.web.homepage.dao.ArticleDao; |
| | | //import com.qxueyou.appraisal.web.homepage.dao.ContestsBatchDao; |
| | | //import com.qxueyou.appraisal.web.homepage.dao.OccupationDao; |
| | | //import com.qxueyou.appraisal.web.homepage.serivce.IHomepageService; |
| | | //import com.qxueyou.entity.article.ArticleDO; |
| | | //import com.qxueyou.util.CollectionUtils; |
| | | import com.qxueyou.scc.base.util.CollectionUtils; |
| | | import com.qxueyou.scc.portal.homepage.dao.ArticleDao; |
| | | import com.qxueyou.scc.portal.homepage.serivce.IHomepageService; |
| | | import com.qxueyou.scc.portal.information.model.Information; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.data.domain.Sort; |
| | | import org.springframework.stereotype.Service; |
| | | |
| | | import java.util.ArrayList; |
| | | import java.util.HashMap; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | |
| | | /** |
| | | * @author ZERO 2021-03-03 09:16 |
| | | */ |
| | | @Service |
| | | public class HomepageService implements IHomepageService { |
| | | |
| | | @Autowired |
| | | private ArticleDao articleDao; |
| | | |
| | | // @Autowired |
| | | // private AppraisalBatchDao batchDao; |
| | | |
| | | // @Autowired |
| | | // private ContestsBatchDao batchDao; |
| | | |
| | | // @Autowired |
| | | // private OccupationDao occupationDao; |
| | | |
| | | /** |
| | | * 获取首页数据 |
| | | */ |
| | | // @Override |
| | | // public Map<String, Object> getIndexDetail() { |
| | | //// System.err.println("================>获取首页数据"); |
| | | // return CollectionUtils.newObjectMap( |
| | | // "appraisalBatchInfo", batchDao.findBatches(1, 24, null).get("data"), // createTime browseCount dateTime |
| | | // "occupationInfo", articleDao.findPage(CollectionUtils.newObjectMap("type", "qualifiedSet", "status", ArticleDO.UP_STATUS), 1, 8, "dateTime", Sort.Direction.DESC).get("data"), |
| | | // "news", articleDao.findPage(CollectionUtils.newObjectMap("type", "policiesRegulations", "status", ArticleDO.UP_STATUS), 1, 8, "dateTime", Sort.Direction.DESC).get("data")); |
| | | // } |
| | | |
| | | |
| | | /** |
| | | * 获取首页标签 |
| | | */ |
| | | @Override |
| | | public List<Map<String, Object>> getTabs() { |
| | | |
| | | boolean exist; |
| | | List<Map<String, Object>> tabs = new ArrayList<>(); |
| | | |
| | | List<Map<String,String>> sub=new ArrayList<>(); |
| | | |
| | | |
| | | exist = articleDao.exist("examBriefing"); |
| | | if (exist) tabs.add(CollectionUtils.newObjectMap("name", "媒体聚焦", "type", "examBriefing","list",sub)); |
| | | |
| | | exist = articleDao.exist("qualifiedSet"); |
| | | if (exist) tabs.add(CollectionUtils.newObjectMap("name", "华教新鲜事", "type", "qualifiedSet")); |
| | | |
| | | exist = articleDao.exist("policiesRegulations"); |
| | | if (exist) tabs.add(CollectionUtils.newObjectMap("name", "新闻中心", "type", "policiesRegulations")); |
| | | |
| | | exist = articleDao.exist("examinationGuide"); |
| | | if (exist) tabs.add(CollectionUtils.newObjectMap("name", "专家风采", "type", "examinationGuide")); |
| | | |
| | | exist = articleDao.exist("popularInformation"); |
| | | if (exist) tabs.add(CollectionUtils.newObjectMap("name", "联系我们", "type", "popularInformation")); |
| | | |
| | | exist =articleDao.existsubColumn("examBriefing","introduce"); |
| | | if(exist) sub.add(CollectionUtils.newStringMap("name", "海外资讯", "subColumn", "introduce") ); |
| | | |
| | | exist =articleDao.existsubColumn("examBriefing","contestFile"); |
| | | if(exist) sub.add(CollectionUtils.newStringMap("name", "海外资讯", "subColumn", "contestFile")); |
| | | |
| | | exist =articleDao.existsubColumn("examBriefing","previousContest"); |
| | | if(exist) sub.add(CollectionUtils.newStringMap("name", "往届大赛", "subColumn", "previousContest")); |
| | | |
| | | return tabs; |
| | | } |
| | | |
| | | /** |
| | | * 获取文章列表 |
| | | */ |
| | | @Override |
| | | public Map<String, Object> getArticle(String type,String subColumn,String numbers,int page, int size, String keyword) { |
| | | return articleDao.moreOccupation(type,subColumn,numbers,page, size, keyword); |
| | | } |
| | | |
| | | |
| | | /** |
| | | * @param id |
| | | * @return |
| | | */ |
| | | |
| | | @Override |
| | | public Map<String, Object> getArticleDetail(String id) { |
| | | |
| | | //inc浏览数 |
| | | articleDao.incBrowseCount(id); |
| | | |
| | | Information article = articleDao.read(Information.class,id); |
| | | |
| | | Map<String, Object> data = CollectionUtils.newObjectMap( |
| | | "title", article.getTitle(), |
| | | "dateTime", article.getDateTime(), |
| | | "browseCount", article.getBrowseCount(), |
| | | "content", article.getContent(), |
| | | "attachment", article.getAttachment()); |
| | | |
| | | Map<String, Object> preAndBehindArticle = articleDao.getPreAndBehindArticle(id, article.getType()); |
| | | |
| | | |
| | | data.putAll(preAndBehindArticle); |
| | | |
| | | return data; |
| | | } |
| | | |
| | | public Information getArticlesType(String type,String subColumn) { |
| | | Information articleDO=articleDao.getArticle(type,subColumn); |
| | | return articleDO; |
| | | } |
| | | |
| | | @Override |
| | | public Map<String, Object> getVideo(String type, String subColumn, int page, int size) { |
| | | return articleDao.getVideoList(type,subColumn,page, size); |
| | | } |
| | | } |
New file |
| | |
| | | package com.qxueyou.scc.teach.res.service; |
| | | |
| | | import org.springframework.web.multipart.MultipartFile; |
| | | |
| | | import java.io.InputStream; |
| | | import java.util.List; |
| | | |
| | | /** |
| | | * @Description 华为云OBS服务接口 |
| | | * @author wuhuiju |
| | | * @date 2022/12/2 17:01 |
| | | */ |
| | | public interface HweiYunOBSService { |
| | | |
| | | /** |
| | | * @Description 删除文件 |
| | | * @author wuhuiju |
| | | * @date 2022/12/2 17:02 |
| | | * @param: objectKey 文件名 |
| | | * @return: boolean 执行结果 |
| | | */ |
| | | boolean delete(String objectKey); |
| | | |
| | | /** |
| | | * @Description 批量删除文件 |
| | | * @author wuhuiju |
| | | * @date 2022/12/2 17:02 |
| | | * @param: objectKeys 文件名集合 |
| | | * @return: boolean 执行结果 |
| | | */ |
| | | boolean delete(List<String> objectKeys); |
| | | |
| | | /** |
| | | * @Description 上传文件 |
| | | * @author wuhuiju |
| | | * @date 2022/12/2 17:03 |
| | | * @param: uploadFile 上传文件 |
| | | * @param: objectKey 文件名称 |
| | | * @return: java.lang.String url访问路径 |
| | | */ |
| | | String fileUpload(MultipartFile uploadFile, String objectKey); |
| | | |
| | | /** |
| | | * @Description 文件下载 |
| | | * @author wuhuiju |
| | | * @date 2022/12/2 17:04 |
| | | * @param: objectKey |
| | | * @return: java.io.InputStream |
| | | */ |
| | | InputStream fileDownload(String objectKey); |
| | | } |
| | | |
New file |
| | |
| | | package com.qxueyou.scc.teach.res.service.impl; |
| | | |
| | | //import com.example.study.springboot.background.service.HweiYunOBSService; |
| | | //import com.example.study.springboot.config.HweiOBSConfig; |
| | | import com.obs.services.ObsClient; |
| | | import com.obs.services.exception.ObsException; |
| | | import com.obs.services.model.*; |
| | | import com.qxueyou.scc.base.util.CollectionUtils; |
| | | import com.qxueyou.scc.base.util.QFileUtils; |
| | | import com.qxueyou.scc.base.util.UUIDUtils; |
| | | import com.qxueyou.scc.config.HweiOBSConfig; |
| | | import com.qxueyou.scc.teach.res.service.HweiYunOBSService; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.apache.commons.lang3.StringUtils; |
| | | import org.apache.logging.log4j.LogManager; |
| | | import org.apache.logging.log4j.Logger; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.web.multipart.MultipartFile; |
| | | |
| | | import java.io.IOException; |
| | | import java.io.InputStream; |
| | | import java.util.Calendar; |
| | | import java.util.GregorianCalendar; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | |
| | | /** |
| | | * @ClassName: HweiYunOBSServiceImpl |
| | | * @Description: 华为云OBS服务业务层 |
| | | * @Author: wuhuiju |
| | | * @Date: 2021-12-21 17:05 |
| | | * @Version: 1.0 |
| | | */ |
| | | @Slf4j |
| | | @Service |
| | | public class HweiYunOBSServiceImpl implements HweiYunOBSService { |
| | | |
| | | private final Logger log = LogManager.getLogger(HweiYunOBSServiceImpl.class); |
| | | @Autowired |
| | | private HweiOBSConfig hweiOBSConfig; |
| | | |
| | | public final static String FILE_TYPE_VIDEO = "video"; |
| | | |
| | | public final static String FILE_TYPE_DOC = "doc"; |
| | | |
| | | public final static String FILE_TYPE_AUDIO = "audio"; |
| | | |
| | | public final static String FILE_TYPE_DATA = "data"; |
| | | |
| | | public final static String FILE_TYPE_IMG = "img"; |
| | | |
| | | private static final Map<String, String> fileFormatMap = CollectionUtils.newStringMap("MPEG", FILE_TYPE_VIDEO, |
| | | "AVI", FILE_TYPE_VIDEO, "MOV", FILE_TYPE_VIDEO, "ASF", FILE_TYPE_VIDEO, "WMV", FILE_TYPE_VIDEO, "NAVI", |
| | | FILE_TYPE_VIDEO, "3GP", FILE_TYPE_VIDEO, "RAM", FILE_TYPE_VIDEO, "RA", FILE_TYPE_VIDEO, "MKV", |
| | | FILE_TYPE_VIDEO, "F4V", FILE_TYPE_VIDEO, "RMVB", FILE_TYPE_VIDEO, "MP4", FILE_TYPE_VIDEO, |
| | | |
| | | "DOC", FILE_TYPE_DOC, "DOCX", FILE_TYPE_DOC, "PDF", FILE_TYPE_DOC, "PPT", FILE_TYPE_DOC, "PPTX", |
| | | FILE_TYPE_DOC, "XLS", FILE_TYPE_DOC, "XLSX", FILE_TYPE_DOC, |
| | | |
| | | "MP3", FILE_TYPE_AUDIO, "WMA", FILE_TYPE_AUDIO, "WAV", FILE_TYPE_AUDIO, |
| | | |
| | | "DATA", FILE_TYPE_DATA, |
| | | |
| | | "JPG", FILE_TYPE_IMG,"JPEG", FILE_TYPE_IMG, "GIF", FILE_TYPE_IMG, "BMP", FILE_TYPE_IMG, "PNG", FILE_TYPE_IMG |
| | | |
| | | ); |
| | | |
| | | @Override |
| | | public boolean delete(String objectKey) { |
| | | ObsClient obsClient = null; |
| | | try { |
| | | // 创建ObsClient实例 |
| | | obsClient = hweiOBSConfig.getInstance(); |
| | | // obs删除 |
| | | obsClient.deleteObject(hweiOBSConfig.getBucketName(),objectKey); |
| | | } catch (ObsException e) { |
| | | log.error("obs删除保存失败", e); |
| | | } finally { |
| | | hweiOBSConfig.destroy(obsClient); |
| | | } |
| | | return true; |
| | | } |
| | | |
| | | @Override |
| | | public boolean delete(List<String> objectKeys) { |
| | | ObsClient obsClient = null; |
| | | try { |
| | | obsClient = hweiOBSConfig.getInstance(); |
| | | DeleteObjectsRequest deleteObjectsRequest = new DeleteObjectsRequest(hweiOBSConfig.getBucketName()); |
| | | objectKeys.forEach(x -> deleteObjectsRequest.addKeyAndVersion(x)); |
| | | // 批量删除请求 |
| | | obsClient.deleteObjects(deleteObjectsRequest); |
| | | return true; |
| | | } catch (ObsException e) { |
| | | log.error("obs删除保存失败", e); |
| | | } finally { |
| | | hweiOBSConfig.destroy(obsClient); |
| | | } |
| | | return false; |
| | | } |
| | | |
| | | @Override |
| | | public String fileUpload(MultipartFile uploadFile, String objectKey) { |
| | | ObsClient obsClient = null; |
| | | try { |
| | | String destPath = getDestPath(objectKey); |
| | | String bucketName = hweiOBSConfig.getBucketName(); |
| | | obsClient = hweiOBSConfig.getInstance(); |
| | | |
| | | // 判断桶是否存在 |
| | | boolean exists = obsClient.headBucket(bucketName); |
| | | |
| | | if(!exists){ |
| | | // 若不存在,则创建桶 |
| | | HeaderResponse response = obsClient.createBucket(bucketName); |
| | | log.info("创建桶成功" + response.getRequestId()); |
| | | } |
| | | InputStream inputStream = uploadFile.getInputStream(); |
| | | long available = inputStream.available(); |
| | | // PutObjectRequest request = new PutObjectRequest(bucketName,objectKey,inputStream); |
| | | PutObjectRequest request = new PutObjectRequest(bucketName,destPath,inputStream); |
| | | ObjectMetadata objectMetadata = new ObjectMetadata(); |
| | | objectMetadata.setContentLength(available); |
| | | request.setMetadata(objectMetadata); |
| | | // request. |
| | | // 设置对象访问权限为公共读 |
| | | request.setAcl(AccessControlList.REST_CANNED_PUBLIC_READ); |
| | | PutObjectResult result = obsClient.putObject(request); |
| | | |
| | | // 读取该已上传对象的URL |
| | | log.info("已上传对象的URL" + result.getObjectUrl()); |
| | | return result.getObjectUrl(); |
| | | } catch (ObsException e) { |
| | | log.error("obs上传失败", e); |
| | | } catch (IOException e) { |
| | | log.error("上传失败", e); |
| | | } finally { |
| | | hweiOBSConfig.destroy(obsClient); |
| | | } |
| | | return null; |
| | | } |
| | | |
| | | private String getDestPath(String name) { |
| | | String fileType = getFileType(name); |
| | | |
| | | StringBuffer path = new StringBuffer(128); |
| | | path.append(fileType); |
| | | |
| | | Calendar now = new GregorianCalendar(); |
| | | |
| | | path.append('/'); |
| | | path.append(now.get(Calendar.YEAR)); |
| | | path.append(StringUtils.leftPad(String.valueOf(now.get(Calendar.MONTH)), 2, '0')); |
| | | path.append('/'); |
| | | path.append(now.get(Calendar.DAY_OF_MONTH)); |
| | | path.append('/'); |
| | | path.append(UUIDUtils.UUID()); |
| | | path.append('.'); |
| | | path.append(QFileUtils.getFileFormat(name)); |
| | | |
| | | return path.toString(); |
| | | |
| | | } |
| | | private String getFileType(String name) { |
| | | String fileType = fileFormatMap.get(QFileUtils.getFileFormat(name)); |
| | | return StringUtils.isEmpty(fileType) ? FILE_TYPE_DATA : fileType; |
| | | } |
| | | |
| | | @Override |
| | | public InputStream fileDownload(String objectKey) { |
| | | ObsClient obsClient = null; |
| | | try { |
| | | String bucketName = hweiOBSConfig.getBucketName(); |
| | | obsClient = hweiOBSConfig.getInstance(); |
| | | ObsObject obsObject = obsClient.getObject(bucketName, objectKey); |
| | | return obsObject.getObjectContent(); |
| | | } catch (ObsException e) { |
| | | log.error("obs文件下载失败", e); |
| | | } finally { |
| | | hweiOBSConfig.destroy(obsClient); |
| | | } |
| | | return null; |
| | | } |
| | | } |