Commit f7969c33 by liangkaiping

copy

parent 7aaf8235
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<dependencies>
<dependency>
<groupId>dom4j</groupId>
<artifactId>dom4j</artifactId>
<version>1.6.1</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>com.yizhi</groupId>
<artifactId>chat-practice-api</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
</dependencies>
<parent>
<artifactId>cloud-web</artifactId>
<groupId>com.yizhi</groupId>
<version>1.0-SNAPSHOT</version>
</parent>
<groupId>com.yizhi</groupId>
<artifactId>cloud-web-manage</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>
</project>
\ No newline at end of file
package com.yizhi.application;
import org.apache.commons.lang.StringUtils;
import org.springframework.core.convert.converter.Converter;
import org.springframework.stereotype.Component;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
/**
* 时间转换类
*
* @Author: shengchenglong
* @Date: 2018/3/6 14:30
*/
@Component
public class DateConvert implements Converter<String, Date> {
@Override
public Date convert(String stringDate) {
if (StringUtils.isBlank(stringDate)){
return null;
}
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
try {
return simpleDateFormat.parse(stringDate);
} catch (ParseException e) {
e.printStackTrace();
}
return null;
}
}
\ No newline at end of file
package com.yizhi.application;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;
/**
* @Author: shengchenglong
* @Date: 2018/3/6 14:30
*/
@Configuration
@EnableSwagger2
public class SwaggerConfig extends WebMvcConfigurerAdapter {
@Bean
public Docket createRestApi() {
return new Docket(DocumentationType.SWAGGER_2)
.groupName("后台管理端")
.apiInfo(apiInfo())
.select()
.apis(RequestHandlerSelectors.basePackage("com.yizhi"))
.paths(PathSelectors.any())
.build();
}
private ApiInfo apiInfo() {
return new ApiInfoBuilder()
.title("管理端接口")
//版本
.version("1.0")
.build();
}
@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
registry.addResourceHandler("swagger-ui.html").addResourceLocations("classpath:/META-INF/resources/");
registry.addResourceHandler("docs.html").addResourceLocations("classpath:/META-INF/resources/");
registry.addResourceHandler("/webjars/**").addResourceLocations("classpath:/META-INF/resources/webjars/");
}
}
package com.yizhi.application;
import feign.RequestInterceptor;
import feign.RequestTemplate;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.cloud.openfeign.EnableFeignClients;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;
import javax.servlet.http.HttpServletRequest;
import java.util.Enumeration;
/**
* @Author: shengchenglong
* @Date: 2018/3/12 11:50
*/
@SpringBootApplication(exclude = DataSourceAutoConfiguration.class)
@EnableDiscoveryClient
@EnableFeignClients(basePackages = {"com.yizhi"})
@ComponentScan(basePackages = {"com.yizhi"})
public class WebManageApplication {
public static void main(String[] args) {
SpringApplication.run(WebManageApplication.class, args);
}
@Bean
public RequestInterceptor headerInterceptor() {
return new RequestInterceptor() {
@Override
public void apply(RequestTemplate requestTemplate) {
ServletRequestAttributes attributes = (ServletRequestAttributes) RequestContextHolder
.getRequestAttributes();
if(attributes != null){
HttpServletRequest request = attributes.getRequest();
Enumeration<String> headerNames = request.getHeaderNames();
if (headerNames != null) {
while (headerNames.hasMoreElements()) {
String name = headerNames.nextElement();
String values = request.getHeader(name);
requestTemplate.header(name, values);
}
}
}
}
};
}
// /**
// *
// * attention:简单跨域就是GET,HEAD和POST请求,但是POST请求的"Content-Type"只能是application/x-www-form-urlencoded, multipart/form-data 或 text/plain
// * 反之,就是非简单跨域,此跨域有一个预检机制,说直白点,就是会发两次请求,一次OPTIONS请求,一次真正的请求
// */
// @Bean
// public CorsFilter corsFilter() {
// final UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
// final CorsConfiguration config = new CorsConfiguration();
// config.setAllowCredentials(true); // 允许cookies跨域
// config.addAllowedOrigin("*");// #允许向该服务器提交请求的URI,*表示全部允许,在SpringMVC中,如果设成*,会自动转成当前请求头中的Origin
// config.addAllowedHeader("*");// #允许访问的头信息,*表示全部
// config.setMaxAge(18000L);// 预检请求的缓存时间(秒),即在这个时间段里,对于相同的跨域请求不会再预检了
// config.addAllowedMethod("OPTIONS");// 允许提交请求的方法,*表示全部允许
// config.addAllowedMethod("HEAD");
// config.addAllowedMethod("GET");// 允许Get的请求方法
// config.addAllowedMethod("PUT");
// config.addAllowedMethod("POST");
// config.addAllowedMethod("DELETE");
// config.addAllowedMethod("PATCH");
// source.registerCorsConfiguration("/**", config);
// return new CorsFilter(source);
// }
}
package com.yizhi.application.accountUtil;
import com.yizhi.system.application.system.remote.AccountClient;
import com.yizhi.system.application.system.remote.OrganizationClient;
import com.yizhi.system.application.vo.AccountVO;
import com.yizhi.system.application.vo.OrgVO;
import com.yizhi.system.application.vo.UserInfoVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.util.CollectionUtils;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@Component
public class AuthorizeQueryAccount {
@Autowired
private AccountClient accountClient;
@Autowired
private OrganizationClient organizationClient;
/**
* 返回《accountId,account》的map
*
* @param accountIds
* @return
*/
public Map<Long, AccountVO> queryAccountByIds(List<Long> accountIds) {
if (!CollectionUtils.isEmpty(accountIds)) {
Map<Long, AccountVO> map = new HashMap<>(accountIds.size());
List<AccountVO> accountVOS = accountClient.findByIds(accountIds);
//组装map 以免双重循环
if (!CollectionUtils.isEmpty(accountVOS)) {
accountVOS.forEach(a -> {
if (!map.containsKey(a.getId())) {
map.put(a.getId(), a);
}
});
}
return map;
}
return null;
}
public Map<Long, OrgVO> queryOrgByIds(List<Long> orgIds) {
if (!CollectionUtils.isEmpty(orgIds)) {
Map<Long, OrgVO> map = new HashMap<>(orgIds.size());
List<OrgVO> orgVOS = null;
try {
orgVOS = organizationClient.listByOrgIds(orgIds);
} catch (Exception e) {
e.printStackTrace();
return null;
}
//组装map 以免双重循环
if (!CollectionUtils.isEmpty(orgVOS)) {
orgVOS.forEach(a -> {
if (!map.containsKey(a.getId())) {
map.put(a.getId(), a);
}
});
}
return map;
}
return null;
}
/**
* 根据用户名,姓名,或部门名称查询账号列表
*
* @param userInfoVO
* @return
*/
public Map<Long, UserInfoVO> selectUserInfo(@RequestBody UserInfoVO userInfoVO) {
return accountClient.selectUserInfo(userInfoVO);
}
}
package com.yizhi.application.album;
import com.yizhi.album.application.feign.AlThemeActivityClient;
import com.yizhi.album.application.feign.AlbumClassifyClient;
import com.yizhi.album.application.vo.AlbumVo;
import com.yizhi.album.application.vo.domain.AlThemeActivity;
import com.yizhi.util.application.domain.Response;
import com.yizhi.util.application.json.JsonUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import java.util.List;
@Api(tags = "管理端-专辑活动", description = "专辑活动接口")
@RestController
@RequestMapping("/manage/album/activity")
public class AlThemeAcitivityController {
private Logger logger = LoggerFactory.getLogger(AlThemeAcitivityController.class);
@Autowired
private AlThemeActivityClient alThemeActivityClient;
@Autowired
private AlbumClassifyClient albumClassifyClient;
@ApiOperation(value = "专辑活动保存", notes = "专辑活动保存")
@PostMapping("/save")
public Response<String> sava(@RequestBody AlbumVo vo) {
Boolean b = alThemeActivityClient.sava(vo);
if (!b) {
return Response.fail("专辑中主题名称不能重复");
}
return Response.ok();
}
@ApiOperation(value = "专辑活动删除", notes = "专辑活动删除")
@GetMapping("/delete")
public Response<String> delete(@ApiParam(name = "id",value = "专辑活动id")@RequestParam(name = "id")Long id) {
try {
return Response.ok(alThemeActivityClient.delete(id));
} catch (Exception e) {
logger.error("", e);
return Response.fail("删除失败");
}
}
@ApiOperation(value = "专辑活动拖动", notes = "专辑活动拖动排序")
@PostMapping("/sortActivity")
public Response<String> sortActivity(@RequestBody String list) {
List<AlThemeActivity> list1 = JsonUtil.json2List(list, AlThemeActivity.class);
try {
logger.info("web端传入要排序的ID列表----------:" + list);
return Response.ok(alThemeActivityClient.sortActivity(list1));
} catch (Exception e) {
logger.error("", e);
return Response.fail("排序失败");
}
}
@ApiOperation(value = "专辑活动定时解锁", notes = "专辑活动定时解锁")
@PostMapping("/unLock")
public Response<String> unLock(@RequestBody AlThemeActivity activity) {
try {
return Response.ok(alThemeActivityClient.unLock(activity));
} catch (Exception e) {
logger.error("", e);
return Response.fail("设置定时解锁失败");
}
}
@ApiOperation(value = "专辑活动列表", notes = "返回专辑活动列表",response = AlbumVo.class)
@GetMapping("/list")
public Response<AlbumVo> list(@ApiParam(name = "albumId",value = "专辑主键id")@RequestParam(name = "albumId")Long albumId) {
try {
AlbumVo vo = alThemeActivityClient.list(albumId);
String classifyName = albumClassifyClient.getClassifyName(vo.getClassifyId());
vo.setClassifyName(classifyName);
return Response.ok(vo);
} catch (Exception e) {
logger.error("", e);
return Response.fail("专辑活动列表查询失败");
}
}
}
package com.yizhi.application.album;
import java.util.List;
import com.yizhi.album.application.feign.AlThemeClient;
import com.yizhi.album.application.vo.domain.AlTheme;
import com.yizhi.core.application.enums.InternationalEnums;
import com.yizhi.util.application.domain.Response;
import com.yizhi.util.application.json.JsonUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiParam;
@Api(tags = "管理端-专辑主题", description = "专辑活动主题")
@RestController
@RequestMapping("/manage/album/theme")
public class AlThemeController {
private Logger logger = LoggerFactory.getLogger(AlThemeController.class);
@Autowired
private AlThemeClient alThemeClient;
@GetMapping("/delete")
public Response<String> delete(@ApiParam(name = "id",value = "主题id")@RequestParam(name = "id")Long id) {
try {
return Response.ok(alThemeClient.delete(id));
} catch (Exception e) {
logger.error("", e);
return Response.fail(InternationalEnums.DOCUMENTRELATIONCONTROLLER2.getName());
}
}
@PostMapping("/sortActivity")
public Response<String> sortTheme(@RequestBody String list) {
List<AlTheme> list1 = JsonUtil.json2List(list, AlTheme.class);
try {
logger.info("web端传入要排序的ID列表----------:" + list);
return Response.ok(alThemeClient.sortTheme(list1));
} catch (Exception e) {
logger.error("", e);
return Response.fail(InternationalEnums.CLASSIFYCONTROLLER8.getName());
}
}
@GetMapping("/updateName")
public Response<String> updateName(@ApiParam(name = "id",value = "主题id")@RequestParam(name = "id") Long id,@ApiParam(name = "albumId",value = "专辑id")@RequestParam(name = "albumId") Long albumId,@ApiParam(name = "name",value = "新的主题名称")@RequestParam(name = "name") String name) {
Boolean b = alThemeClient.updateName(id,albumId, name);
if (!b) {
return Response.fail(InternationalEnums.ALTHEMEACITICITYCONTROLLER3.getName());
}
return Response.ok();
}
}
package com.yizhi.application.album;
import java.util.Date;
import java.util.List;
import com.yizhi.album.application.feign.AlbumClient;
import com.yizhi.album.application.vo.AlbumVo;
import com.yizhi.album.application.vo.domain.Album;
import com.yizhi.album.application.vo.domain.AlbumVisibleRange;
import com.yizhi.core.application.enums.InternationalEnums;
import com.yizhi.core.application.context.ContextHolder;
import com.yizhi.core.application.context.RequestContext;
import com.yizhi.lecturer.application.enums.DeleteFlag;
import com.yizhi.site.application.feign.PortalManagePCFeignClients;
import com.yizhi.site.application.vo.domain.ProtalPlateVo;
import com.yizhi.util.application.constant.ReturnCode;
import com.yizhi.util.application.domain.Response;
import com.yizhi.util.application.enums.i18n.Constants;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import com.baomidou.mybatisplus.plugins.Page;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
@Api(tags = "管理端-专辑", description = "专辑接口")
@RestController
@RequestMapping("/manage/album")
public class AlbumController {
private Logger logger = LoggerFactory.getLogger(AlbumController.class);
@Autowired
private AlbumClient albumClient;
@Autowired
private PortalManagePCFeignClients portalManagePCFeignClient;
@GetMapping(value = "/list")
@ApiOperation(value = "专辑分页列表", notes = "返回带分页的专辑列表", response = Album.class)
public Response<Page<Album>> list(
@ApiParam(name = "name", value = "名称或者关键字 默认不传", required = false) @RequestParam(name = "name", required = false) String name,
@ApiParam(name = "alClassifyId", value = "分类id,未分类传0 默认不传", required = false) @RequestParam(name = "alClassifyId", required = false) Long alClassifyId,
@ApiParam(name = "status", value = "0 未上架 1 已上架 2 草稿 全部不传", required = false) @RequestParam(name = "status", required = false) Integer status,
@ApiParam(name = "overed", value = "0 连载中 1 已完结 全部不传", required = false) @RequestParam(name = "overed", required = false) Integer overed,
@ApiParam(name = "pageNo", value = "跳转页数,默认第一页", required = true) @RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo,
@ApiParam(name = "pageSize", value = "每页条数,默认10条", required = true) @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize) {
RequestContext context = ContextHolder.get();
Page<Album> page = albumClient.list(name, alClassifyId, status, overed, context.getCompanyId(),
context.getSiteId(), pageNo, pageSize);
return Response.ok(page);
}
@GetMapping("/get")
@ApiOperation(value = "专辑查看", notes = "专辑查看",response = Album.class)
public Response<Album> get(
@ApiParam(name = "id", value = "专辑id", required = true) @RequestParam(name = "id", required = true) Long id) {
Album album = albumClient.get(id);
return Response.ok(album);
}
@PostMapping("/save")
@ApiOperation(value = "新增专辑第一步", notes = "点击下一步保存",response = AlbumVo.class)
public Response<String> save(@ApiParam(name = "albumVo", value = "需要传入name,"
+ " classifyId,description,tags", required = true) @RequestBody AlbumVo albumVo) {
RequestContext requestContext = ContextHolder.get();
albumVo.setCreateById(requestContext.getAccountId());
albumVo.setCreateByName(requestContext.getAccountName());
albumVo.setCompanyId(requestContext.getCompanyId());
albumVo.setSiteId(requestContext.getSiteId());
albumVo.setCreateTime(new Date());
AlbumVo vo = albumClient.save(albumVo);
if (vo!=null) {
return Response.ok(vo);
}else {
return Response.fail(InternationalEnums.ALBUMCONTROLLER1.getCode());
}
}
@GetMapping("/up")
@ApiOperation(value = "上架", notes = "上架操作")
public Response<String> up(@ApiParam(value = "专辑id", required = true) @RequestParam(name = "id") Long id,@ApiParam(value = "保存类型", required = true)@RequestParam(name = "type")Integer type) {
try {
Integer f = albumClient.up2(id,type);
if (f==1) {
return Response.ok();
} else if (f==2){
return Response.fail(ReturnCode.SERVICE_UNAVAILABLE.getCode().toString(),ReturnCode.SERVICE_UNAVAILABLE.getMsg());
}else {
return Response.fail("4001", InternationalEnums.ALBUMCONTROLLER2.getCode());
}
} catch (Exception e) {
return Response.fail("", e.getLocalizedMessage());
}
}
@GetMapping("/down")
@ApiOperation(value = "下架", notes = "下架操作")
public Response<String> down(@ApiParam(value = "专辑id", required = true) @RequestParam(name = "id") Long id) {
//新增首页模块关联查询
ProtalPlateVo protalPlate = new ProtalPlateVo();
protalPlate.setLinkContent(id);
protalPlate.setState(DeleteFlag.YES.ordinal());
ProtalPlateVo plate = portalManagePCFeignClient.getPlate(protalPlate);
if (plate != null) {
logger.info("专辑下架失败;albumId={},专辑已经关联到首页配置模块;不能下架",id);
return Response.fail(InternationalEnums.OFFLINECOURSECONTROLLER5.getCode());
}
Boolean f = albumClient.down(id);
if (f) {
return Response.ok();
} else {
logger.info("专辑下架失败;albumId={},专辑下架失败.",id);
return Response.fail(InternationalEnums.OFFLINECOURSECONTROLLER5.getCode(),InternationalEnums.OFFLINECOURSECONTROLLER5.getName());
}
}
@PostMapping("/update")
@ApiOperation(value = "新增专辑第三步", notes = "点击下一步保存")
public Response<String> update(@ApiParam(name = "albumVo", value = "需要传入scope,"
+ "commentEnable,documentEnable,overed,display", required = true) @RequestBody AlbumVo albumVo) {
RequestContext requestContext = ContextHolder.get();
albumVo.setUpdateById(requestContext.getAccountId());
albumVo.setUpdateByName(requestContext.getAccountName());
albumVo.setUpdateTime(new Date());
Boolean b = albumClient.update(albumVo);
if (b) {
return Response.ok();
}else {
return Response.fail(InternationalEnums.ALBUMCONTROLLER1.getCode());
}
}
@PostMapping("/authorize/insert")
@ApiOperation(value = "专辑可见范围新增")
public Response<String> insertReportVisibleRanges(
@ApiParam(name = "专辑可见范围", value = "需传albumId、relationId、type") @RequestBody List<AlbumVisibleRange> albumVisableRanges) {
try {
boolean b = albumClient.insertAlbumVisibleRanges(albumVisableRanges);
if (b) {
return Response.ok();
} else {
return Response.fail(Constants.MSG_BIZ_FAIL);
}
} catch (Exception e) {
e.printStackTrace();
return Response.fail(Constants.MSG_BIZ_FAIL);
}
}
@GetMapping("/VisibleRange")
@ApiOperation(value = "指定专辑可见范围", response = AlbumVisibleRange.class)
public Response<List<AlbumVisibleRange>> VisibleRange(
@ApiParam(name = "albumId", value = "专辑id") @RequestParam("albumId") Long albumId) {
try {
List<AlbumVisibleRange> list = albumClient.VisibleRange(albumId);
return Response.ok(list);
} catch (Exception e) {
e.printStackTrace();
return Response.fail(Constants.MSG_BIZ_FAIL);
}
}
@GetMapping("/list/export")
@ApiOperation(value = "专辑课程清单导出")
public Response<String> listExport(@ApiParam(name = "albumId", value = "专辑id ", required = false) @RequestParam(name = "albumId", required = false) Long albumId) {
return Response.ok(albumClient.activityExport(albumId).get("result").toString());
}
@GetMapping("/list/search")
@ApiOperation(value = "专辑列表查询",response = Album.class)
public Response searchList(@ApiParam(name = "name", value = "专辑名称或关键字", required = false)@RequestParam(name = "name",required = false) String name,@ApiParam(name = "ids", value = "已关联的专辑id", required = false)@RequestParam(name = "ids",required = false) List<Long> ids) {
RequestContext context = ContextHolder.get();
return Response.ok(albumClient.searchList(name,ids, context.getCompanyId(), context.getSiteId()));
}
@PostMapping("/delete")
@ApiOperation(value = "专辑删除")
public Response<String> delete(
@ApiParam(name = "ids", value = "选中的专辑id") @RequestBody List<Long> ids) {
try {
Integer b = albumClient.delete(ids);
if (b.equals(0)) {
return Response.ok();
} else {
return Response.fail(InternationalEnums.ALBUMCONTROLLER3.getCode());
}
} catch (Exception e) {
e.printStackTrace();
return Response.fail(Constants.MSG_BIZ_FAIL);
}
}
}
package com.yizhi.application.assignment.controller;
import java.io.File;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.UUID;
import com.yizhi.assignment.application.feign.AssignmentClient;
import com.yizhi.assignment.application.vo.AnswersDownVO;
import com.yizhi.assignment.application.vo.DownloadAnswerVO;
import com.yizhi.assignment.application.vo.entity.AssignmentAnswerFile;
import com.yizhi.core.application.context.TaskContext;
import com.yizhi.core.application.file.constant.FileConstant;
import com.yizhi.core.application.file.task.AbstractDefaultTask;
import com.yizhi.core.application.file.util.OssUpload;
import com.yizhi.util.application.zip.ZipUtil;
import org.apache.commons.io.FileUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import com.yizhi.application.assignment.util.FileReadUtil;
@Component
public class AssignmentDownloadAnswerExport extends AbstractDefaultTask<String, Map<String,Object>> {
private static final Logger logger = LoggerFactory.getLogger(AssignmentDownloadAnswerExport.class);
@Autowired
private AssignmentClient assignmentClient;
@Autowired
private FileReadUtil fileReadUtil;
@Override
protected String execute(Map<String, Object> arg0) {
// TODO Auto-generated method stub
String upload=null;
/*
* 思路 1通过接口得到文件的url
* 2 通过阿里云的url下载到服务器
* 3将下载到服务器的文件打包
* 4将打包的zip 打成一个大的包
*/
DownloadAnswerVO vo=(DownloadAnswerVO) arg0.get("vo");
Long accountId=(Long) arg0.get("accountId");
Long siteId=(Long) arg0.get("siteId");
Long companyId=(Long) arg0.get("companyId");
Long taskId=(Long) arg0.get("taskId");
Date submitTime=(Date) arg0.get("submitTime");
String serialNo=(String) arg0.get("serialNo");
String taskName=(String) arg0.get("taskName");
/**
* 走异步消息
*/
TaskContext taskContext = new TaskContext(taskId, serialNo, taskName, accountId, submitTime, siteId, companyId);
working(taskContext);
List<AnswersDownVO> list=assignmentClient.exportAssignmentZip(vo);
String serverUrlName= FileConstant.SAVE_PATH; //服务器的路径
SimpleDateFormat dateFormate = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
/**
* 判断文件夹是否存在,如果不存在则创建
*/
File serverPathDir=new File(serverUrlName);
if(!serverPathDir.exists()) {
serverPathDir.mkdir();
}
Long downLoadTimeMs=submitTime.getTime();
String downLoadTime=dateFormate.format(submitTime);
//异步消息
String assignmentName=fileReadUtil.getSpecialCharacter(list.get(0).getAssignmentName());
//父文件夹的名字
//毫秒_线程名字
String parentDirName=assignmentName+"_"+downLoadTimeMs+"_"+Thread.currentThread().getName();
//父文件夹的完整路径
// 例子:/home/file/作业名字_毫秒_线程名字
String parentPathName=serverUrlName+File.separator+parentDirName;
//在服务器路径下创建父文件夹
File parentPathDir = new File(parentPathName);
//在服务器路径下创建 作业名字_日期 文件夹(父文件夹)
parentPathDir.mkdir();
for (int i = 0; i < list.size(); i++) {
AnswersDownVO answersDownVO=new AnswersDownVO();
answersDownVO=list.get(i);
String accountName=answersDownVO.getAccountName(); //用户名
Date commitTime=answersDownVO.getCommitTime(); //提交时间
Integer source=answersDownVO.getSource(); //来源为为本地上传
SimpleDateFormat df = new SimpleDateFormat("yyyyMMddHHmmss");
//子文件夹的路径
String childPathNameUUID = UUID.randomUUID().toString().replaceAll("-","");
String childPathName=parentPathName+File.separator+accountName+"-"+df.format(commitTime)+"_"+childPathNameUUID;
//子文件夹这个文件夹
File childDirFile=new File(childPathName);
//创建子文件夹
childDirFile.mkdir();
if(source==1) {
List<AssignmentAnswerFile> listAssignmentAnswerFile=answersDownVO.getList();
for (int j = 0; j < listAssignmentAnswerFile.size(); j++) {
String url=listAssignmentAnswerFile.get(j).getFileUrl(); //阿里云的地址
String fileName=listAssignmentAnswerFile.get(j).getFileName(); //文件名字和后缀 111.docx
String uuid = UUID.randomUUID().toString().replaceAll("-","");
fileReadUtil.read(url, childPathName, fileName); //1阿里云的文件流路径 2下载到服务器的存储路径 3文件名字 注释: 阿里云的文件下载到服务器的文件夹下
}
}
//子文件夹的zip的名字
String uuid = UUID.randomUUID().toString().replaceAll("-","");
String childDirZip=childPathName+".zip";
try {
ZipUtil.zip(childPathName, childDirZip);
FileUtils.deleteDirectory(childDirFile);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
logger.error("关于作业中学生答案打包过程中发生错误",e);
}
}
//父文件夹 压缩成 压缩包
String uuid = UUID.randomUUID().toString().replaceAll("-","");
String parentDirZipPath=parentPathName+".zip";
try {
ZipUtil.zip(parentPathName, parentDirZipPath);
FileUtils.deleteDirectory(parentPathDir);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
logger.error("关于作业打包过程中发生错误",e);
}
upload= OssUpload.upload(parentDirZipPath, assignmentName+"_"+downLoadTime+".zip");
success(taskContext,"成功", upload);
File pathZipFile=new File(parentDirZipPath);
try {
pathZipFile.delete();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return upload;
}
}
package com.yizhi.application.assignment.controller;
import com.baomidou.mybatisplus.plugins.Page;
import com.yizhi.assignment.application.feign.ManageAssignmentExerciseBookClient;
import com.yizhi.assignment.application.vo.TipoffAssignmentListVO;
import com.yizhi.assignment.application.vo.apivo.ApiAssignmentCommentVO;
import com.yizhi.assignment.application.vo.entity.AssignmentAnswerTipoff;
import com.yizhi.util.application.domain.Response;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.log4j.Log4j2;
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.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import java.util.HashMap;
import java.util.Map;
/**
* @ClassName AssignmentExpriceBookController
* @Description TODO
* @Author shengchenglong
* @DATE 2019-10-22 11:15
* @Version 1.0
*/
@Api("作业本--管理端")
@RestController
@RequestMapping("/manage/assignment/exerciseBook")
@Log4j2
public class ManageAssignmentExerciseBookController {
@Autowired
private ManageAssignmentExerciseBookClient manageAssignmentExerciseBookClient;
@GetMapping("/answer/down")
@ApiOperation(value = "作业上下架", response = Boolean.class)
public Response<Boolean> answerDown(
@ApiParam @RequestParam("answerId") Long answerId,
@ApiParam("是否是下架,0:否,1:是") @RequestParam("isDown") Integer isDown) {
try {
return Response.ok(manageAssignmentExerciseBookClient.answerDown(answerId, isDown));
} catch (Exception e) {
log.error(e);
return Response.fail();
}
}
@GetMapping("/answer/delete")
@ApiOperation(value = "删除作业", response = Boolean.class)
public Response<Boolean> answerDelete(@ApiParam @RequestParam("answerId") Long answerId) {
try {
return Response.ok(manageAssignmentExerciseBookClient.answerDelete(answerId));
} catch (Exception e) {
log.error(e);
return Response.fail();
}
}
@GetMapping("/comment/page")
@ApiOperation(value = "评论列表", response = ApiAssignmentCommentVO.class)
public Response<ApiAssignmentCommentVO> commentPage(
@ApiParam @RequestParam("assignmentAnswerId") Long assignmentAnswerId,
@ApiParam("要跳转的页数") @RequestParam(name = "pageNo", defaultValue = "1") int pageNo,
@ApiParam("每页条数,默认:10") @RequestParam(name = "pageSize", defaultValue = "10") int pageSize
) {
try {
Page<ApiAssignmentCommentVO> page = manageAssignmentExerciseBookClient.commentPage(assignmentAnswerId, pageNo, pageSize);
Map<String, Integer> pageMap = new HashMap<>();
pageMap.put("pageNo", pageNo);
pageMap.put("pageSize", pageSize);
pageMap.put("pageTotal", page.getTotal());
return Response.ok(page.getRecords(), pageMap);
} catch (Exception e) {
log.error(e);
return Response.fail();
}
}
@GetMapping("/comment/delete")
@ApiOperation(value = "评论删除", response = Boolean.class)
public Response<Boolean> commentDelete(@RequestParam("commentId") Long commentId) {
try {
return Response.ok(manageAssignmentExerciseBookClient.commentDelete(commentId));
} catch (Exception e) {
log.error(e);
return Response.fail();
}
}
@GetMapping("/comment/audit")
@ApiOperation(value = "评论上下架", response = Boolean.class)
public Response<Boolean> commentAudit(@RequestParam("commentId") Long commentId, @RequestParam("auditStatus") Integer auditStatus) {
try {
return Response.ok(manageAssignmentExerciseBookClient.commentAudit(commentId, auditStatus));
} catch (Exception e) {
log.error(e);
return Response.fail();
}
}
@GetMapping("/tipoff/answer/page")
@ApiOperation(value = "举报-作业列表页", response = TipoffAssignmentListVO.class)
public Response<TipoffAssignmentListVO> tipoffAnswerPage(
@ApiParam @RequestParam(name = "assignmentName", required = false) String assignmentName,
@ApiParam("要跳转的页数") @RequestParam(name = "pageNo", defaultValue = "1") int pageNo,
@ApiParam("每页条数,默认:10") @RequestParam(name = "pageSize", defaultValue = "10") int pageSize) {
try {
Page<TipoffAssignmentListVO> page = manageAssignmentExerciseBookClient.tipoffAnswerPage(assignmentName, pageNo, pageSize);
Map<String, Integer> pageMap = new HashMap<>();
pageMap.put("pageNo", pageNo);
pageMap.put("pageSize", pageSize);
pageMap.put("pageTotal", page.getTotal());
return Response.ok(page.getRecords(), pageMap);
} catch (Exception e) {
log.error(e);
return Response.fail();
}
}
@GetMapping("/tipoff/page")
@ApiOperation(value = "举报-列表页", response = AssignmentAnswerTipoff.class)
public Response<AssignmentAnswerTipoff> tipoffPage(
@ApiParam @RequestParam("answerId") Long answerId,
@ApiParam("要跳转的页数") @RequestParam(name = "pageNo", defaultValue = "1") int pageNo,
@ApiParam("每页条数,默认:10") @RequestParam(name = "pageSize", defaultValue = "10") int pageSize) {
try {
Page<AssignmentAnswerTipoff> page = manageAssignmentExerciseBookClient.tipoffPage(answerId, pageNo, pageSize);
Map<String, Integer> pageMap = new HashMap<>();
pageMap.put("pageNo", pageNo);
pageMap.put("pageSize", pageSize);
pageMap.put("pageTotal", page.getTotal());
return Response.ok(page.getRecords(), pageMap);
} catch (Exception e) {
log.error(e);
return Response.fail();
}
}
@GetMapping("/tipoff/remove")
@ApiOperation(value = "举报-移除", response = Boolean.class)
public Response<Boolean> tipoffPage(
@ApiParam @RequestParam("tipoffId") Long tipoffId) {
try {
return Response.ok(manageAssignmentExerciseBookClient.tipoffRemove(tipoffId));
} catch (Exception e) {
log.error(e);
return Response.fail();
}
}
@GetMapping("/comment/export")
@ApiOperation(value = "评论导出", response = String.class)
public Response<String> commentExport(
@ApiParam("答案id") @RequestParam("answerId") Long answerId
) {
try {
return Response.ok(manageAssignmentExerciseBookClient.commentExport(answerId));
} catch (Exception e) {
log.error(e);
return Response.fail();
}
}
}
package com.yizhi.application.assignment.util;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import com.yizhi.core.application.exception.FileReadException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;
@Component("fileReadUtil1")
public class FileReadUtil {
private static final Logger LOG = LoggerFactory.getLogger(FileReadUtil.class);
public File read(String urlStr, String savePath, String fileName) {
File fileInfo = null;
try {
URL url = new URL(urlStr);
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setRequestProperty("User-Agent", "Mozilla/4.0 (compatible; MSIE 5.0; Windows NT; DigExt)");
conn.setRequestProperty("Charsert", "UTF-8");
conn.setRequestProperty("Accept-Charset", "UTF-8");
//得到输入流
InputStream inputStream = conn.getInputStream();
//获取自己数组
byte[] buffer = new byte[1024];
int len = 0;
ByteArrayOutputStream bos = new ByteArrayOutputStream();
while ((len = inputStream.read(buffer)) != -1) {
bos.write(buffer, 0, len);
}
bos.close();
byte[] getData = bos.toByteArray();
//文件保存位置
File saveDir = new File(savePath);
if (!saveDir.exists()) {
saveDir.mkdir();
}
String fileName1 = saveDir + File.separator + fileName;
LOG.info("####################fileName:" + fileName1);
fileInfo = new File(new String(fileName1.getBytes("UTF-8")));
LOG.info("####################fileName,绝对路径:" + fileInfo.getAbsolutePath());
LOG.info("####################语言格式" + System.getProperty("sun.jnu.encoding"));
FileOutputStream fos = new FileOutputStream(fileInfo);
fos.write(getData);
if (fos != null) {
fos.close();
}
if (inputStream != null) {
inputStream.close();
}
} catch (Exception e) {
LOG.error("文件拉取失败", e);
throw new FileReadException();
}
return fileInfo;
}
/**
* 把特殊字符全替换成下划线
*
* @param character
* @return
*/
public String getSpecialCharacter(String character) {
String regEx = "[`~!@#$%^&*()+=|{}':;',\\[\\].<>/?~!@#¥%……&*()——+|{}【】‘;:”“’。,、?]";
Pattern p = Pattern.compile(regEx);
Matcher m = p.matcher(character);
return m.replaceAll("_").trim();
}
}
package com.yizhi.application.assignment.vo.manage;
import java.util.Date;
import java.util.List;
import com.yizhi.assignment.application.vo.entity.AssignmentAnswerFile;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
/**
* 显示老师布置的作业列表
* @author wangfeida
*
*/
@Data
@Api(tags = "AnswersDownVO", description = "批量下载的vo")
public class AnswersDownVO {
@ApiModelProperty(name="accountName",value="accountName")
private String accountName; //用户名
@ApiModelProperty(name="assignmentName",value="assignmentName")
private String assignmentName; //作业名字
@ApiModelProperty(name="作业来源(1本地2做课)",value="source")
private Integer source; //来源
@ApiModelProperty(name="答案提交时间",value="commitTime")
private Date commitTime;
@ApiModelProperty(name="accountId",value="accountId")
private List<AssignmentAnswerFile> list;
}
package com.yizhi.application.assignment.vo.manage;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
@Data
@Api(tags = "AuditorShowVo", description = "出参vo")
public class AuditorShowVo {
@ApiModelProperty("评阅人id")
private Long id;
@ApiModelProperty("评阅人用户名")
private String name;
@ApiModelProperty("评阅人真实姓名")
private String realName;
}
package com.yizhi.application.assignment.vo.manage;
import java.util.List;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
@Data
public class DownloadAnswerVO {
@ApiModelProperty("作业id")
private Long assignmentId;
@ApiModelProperty("答案ids")
private List<Long> answerIds;
}
package com.yizhi.application.assignment.vo.manage;
import java.util.List;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
@Data
@Api(tags = "RelationStudentListVo", description = "查看已关联的出参voList")
public class RelationStudentListVo {
/**
* 作业id
*/
@ApiModelProperty("作业id")
private Long assignmentId;
/**
* 多个学员信息
*/
@ApiModelProperty("多个学员信息")
private List<RelationStudentVo> listAccount;
}
package com.yizhi.application.assignment.vo.manage;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
@Data
public class RelationStudentVo {
@ApiModelProperty("学员id")
private Long id;
@ApiModelProperty("学员名字")
private String name;
@ApiModelProperty("类型")
private Integer type;
@ApiModelProperty(value = "用户名")
private String fullName;
@ApiModelProperty(value = "工号")
private String workNum;
}
package com.yizhi.application.assignment.vo.manage;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.util.Date;
/**
* 保存resrarch vo
*
* @Author: shengchenglong
* @Date: 2018/3/13 11:06
*/
@Data
@Api(tags = "ResearchVo", description = "后台保存调研vo")
public class ResearchVo {
@ApiModelProperty("调研编码,系统将自动生成调研编码;编码规则,按创建顺序累加,例如DY000001,DY000002")
private String researchNo;
@ApiModelProperty("积分,每次投票能获取到的积分,默认0")
private Integer point;
@ApiModelProperty("提醒设置,0否 1是,默认0")
private Integer remind;
@ApiModelProperty("调研名称")
private String name;
@ApiModelProperty("开始时间")
private Date startTime;
@ApiModelProperty("结束时间")
private Date endTime;
@ApiModelProperty("可见范围,1平台用户可见(企业下所有人员) 2指定学员可见")
private Integer visibleRange;
@ApiModelProperty("调研说明")
private String content;
@ApiModelProperty("状态,0删除 1上架 2下架")
private Integer state;
@ApiModelProperty("创建时间")
private Date createTime;
@ApiModelProperty("创建人ID")
private String createById;
@ApiModelProperty("创建人姓名")
private String createByName;
@ApiModelProperty("修改时间")
private Date updateTime;
@ApiModelProperty("修改人ID")
private String updateById;
@ApiModelProperty("修改人姓名")
private String updateByName;
@ApiModelProperty("发布时间")
private Date releaseTime;
@ApiModelProperty("发布人ID")
private Long releaseById;
@ApiModelProperty("发布人姓名")
private String releaseByName;
@ApiModelProperty("在培训项目中发起投票,保存对应关系")
private Long trainingProjectId;
@ApiModelProperty("企业_ID")
private Long companyId;
@ApiModelProperty("部门_ID")
private Long orgId;
@ApiModelProperty("站点_ID")
private Long siteId;
}
package com.yizhi.application.authorize;
import com.baomidou.mybatisplus.plugins.Page;
import com.yizhi.core.application.enums.InternationalEnums;
import com.yizhi.course.application.feign.AccreditClient;
import com.yizhi.course.application.feign.CourseClient;
import com.yizhi.course.application.vo.*;
import com.yizhi.util.application.domain.Response;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
/**
* <p>
* 投票 前端控制器
* </p>
*
* @author lilingye
* @since 2018-6-11 14:55:02
*/
@Api(tags = "授权/销售课程列表")
@RestController
@RequestMapping("/manage/authorize")
public class AuthorizeController {
private static final Logger LOGGER = LoggerFactory.getLogger(AuthorizeController.class);
@Autowired
private CourseClient courseClient;
@Autowired
private AccreditClient accreditClient;
/**
* 查询课程授权和课程销售的接口
* @param name
* @param classifyId
* @param companyId
* @param pageNo
* @param pageSize
* @return
*/
@ApiOperation(value = "查询课程授权/课程销售的接口")
@GetMapping(value = "/get/list")
public Response<PageCourseAuthorizeVO> queryeAuthorizeCoursesList(
@ApiParam(name = "name", value = "名称", required = false) @RequestParam(name = "name",required = false) String name,
@ApiParam(name = "companyId", value = "公司id") @RequestParam(name = "companyId",required = false) Long companyId,
@ApiParam(name = "csiteId", value = "站点名称(课程授权必传字段)", required = false) @RequestParam(name = "csiteId",required = false) Long csiteId,
@ApiParam(name = "classifyId", value = "分类id")@RequestParam(name = "classifyId",required = false) Long classifyId,
@ApiParam(name = "pageNo", value = "当前页", required = false) @RequestParam(name = "pageNo", defaultValue = "1", required = false) Integer pageNo,
@ApiParam(name = "pageSize", value = "每页的条数", required = false) @RequestParam(name = "pageSize", defaultValue = "20", required = false) Integer pageSize
) {
PageCourseAuthorizeVO pageCourseAuthorizeVO = courseClient.queryeAuthorizeCoursesList(name,companyId,csiteId,classifyId,pageNo,pageSize);
return Response.ok(pageCourseAuthorizeVO);
}
/**
* 提交保存授权课程的接口
* @return
*/
@ApiOperation(value = "保存授权")
@PostMapping(value = "/insert")
public Response<String> saveAuthorization(@RequestBody AuthorizeVO authorizeVO){
CourseRespVO courseRespVO = courseClient.saveAuthorization(authorizeVO);
if (courseRespVO!=null){
if (courseRespVO.getCode()==1){
return Response.ok();
} else {
return Response.fail(courseRespVO.getMsg());
}
}else {
return Response.ok();
}
}
/**
* 模糊查询授权后列表(销售授权和课程授权)
* @return
*/
@ApiOperation(value = "模糊查询授权后列表")
@GetMapping(value = "/get/authorizelist")
public Response<PageAuthorizeVO> queryAuthorizeCourse(@ApiParam(name = "type", value = "1课程授权 2 课程销售",required = true)@RequestParam(name = "type",required = true) String type,
@ApiParam(name = "siteName", value = "站点名称(课程授权字段)") @RequestParam(name = "siteName",required = false) String siteName,
@ApiParam(name = "companyName", value = "公司名称(销售授权字段)") @RequestParam(name = "companyName",required = false) String companyName,
@ApiParam(name = "pageNo", value = "当前页") @RequestParam(name = "pageNo", defaultValue = "1",required = false) Integer pageNo,
@ApiParam(name = "pageSize", value = "当前页条数") @RequestParam(name = "pageSize", defaultValue = "20",required = false) Integer pageSize){
// PageAuthorizeVO pageAuthorizeVO= accreditClient.queryAuthorizeCourse(type,siteName,companyName,pageNo,pageSize);
Page<AuthorizeCourseVO> page = accreditClient.queryAuthorizedCourseList(type, siteName, companyName, pageNo, pageSize);
PageAuthorizeVO pageAuthorizeVO = new PageAuthorizeVO();
pageAuthorizeVO.setRecords(page.getRecords());
pageAuthorizeVO.setPageNo(page.getCurrent());
pageAuthorizeVO.setPageSize(page.getSize());
pageAuthorizeVO.setPageRecords(page.getTotal());
pageAuthorizeVO.setPageTotal(page.getPages());
return Response.ok(pageAuthorizeVO);
}
/**
* 条件查询站点授权后的课程
* @return
*/
@ApiOperation(value = "站点查询站点授权后的课程")
@GetMapping(value = "/get/authorized")
public Response<PageAuthorizedVO> queryAuthorizedCourse(@ApiParam(name = "courseKeys", value = "站点名称") @RequestParam(name = "courseKeys",required = false) String courseKeys,
@ApiParam(name = "startTime", value = "开始时间") @RequestParam(name = "startTime",required = false) String startTime,
@ApiParam(name = "siteId",value = "站点id",required = true) @RequestParam(name = "siteId",required = true) Long siteId,
@ApiParam(name = "endTime", value = "结束时间") @RequestParam(name = "endTime",required = false) String endTime,
@ApiParam(name = "type",value = "1 课程授权 2课程销售") @RequestParam(name = "type") Integer type,
@ApiParam(name = "activeType",value = "活跃状态,0:活跃,1:已经到期") @RequestParam(name = "activeType",required = false) Integer activeType,
@ApiParam(name = "pageNo", value = "当前页") @RequestParam(name = "pageNo", defaultValue = "1",required = false) Integer pageNo,
@ApiParam(name = "pageSize", value = "当前页条数") @RequestParam(name = "pageSize", defaultValue = "20",required = false) Integer pageSize){
if ("".equals(activeType)) {
activeType = null;
}
PageAuthorizedVO pageAuthorizedVO = courseClient.getAuthorizedList(courseKeys,startTime,endTime,siteId,activeType,type,pageNo,pageSize);
return Response.ok(pageAuthorizedVO);
}
@ApiOperation(value = "修改课程的有效期")
@PostMapping(value = "/updateValidDate")
public Response<String> updateAuthorize(@RequestBody AuthorizeParamVO authorizeParamVO){
if(authorizeParamVO!=null){
for (AuthCourseVO authorizationCourseVO:authorizeParamVO.getAuthorizationCourseVOs()){
AccreditVO accreditVO = new AccreditVO();
accreditVO.setId(authorizationCourseVO.getCourseId());
accreditVO.setUseDuration(authorizationCourseVO.getValidDate());
accreditClient.updateAuthorize(accreditVO);
}
return Response.ok();
} else {
return Response.fail(InternationalEnums.SITEINFORMATIONMANAGECONTROLLER1.getName());
}
}
}
package com.yizhi.application.calendar;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import com.baomidou.mybatisplus.plugins.Page;
import com.yizhi.calendar.application.feign.CalendarStatisticClient;
import com.yizhi.calendar.application.vo.CalendarChartVO;
import com.yizhi.calendar.application.vo.CalendarStatisticVO;
import com.yizhi.util.application.constant.ReturnCode;
import com.yizhi.util.application.domain.Response;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
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.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
@Api(tags = "管理端-签到打卡报表接口")
@RestController
@RequestMapping("/report/calendar")
public class CalendarReportController {
private static final Logger LOG = LoggerFactory.getLogger(CalendarReportController.class);
@Autowired
private CalendarStatisticClient calendarStatisticClient;
@ApiOperation(value = "签到打卡折线图",response = CalendarChartVO.class)
@GetMapping(value = "/chart")
public Response<List<CalendarChartVO>> signChart(@RequestParam(name = "startDate", required = true) String startDate,
@RequestParam(name = "endDate", required = true) String endDate){
try {
if(StringUtils.isBlank(startDate) || StringUtils.isBlank(endDate)){
return Response.ok();
}
List<CalendarChartVO> list = calendarStatisticClient.signChart(startDate, endDate);
return Response.ok(list);
} catch (Exception e) {
LOG.error(""+e);
return Response.fail(ReturnCode.BIZ_FAIL.getCode(),ReturnCode.BIZ_FAIL.getMsg());
}
}
@ApiOperation(value = "统计数据",response = CalendarStatisticVO.class)
@GetMapping(value = "/list")
public Response<CalendarStatisticVO> list(@RequestParam(name = "startDate", required = true) String startDate,
@RequestParam(name = "endDate", required = true) String endDate,
@RequestParam(name = "kwd", required = false) String kwd,
@RequestParam(name = "pageSize", required = false, defaultValue = "10") Integer pageSize,
@RequestParam(name = "pageNo", required = false, defaultValue = "1") Integer pageNo){
if(StringUtils.isBlank(startDate) || StringUtils.isBlank(endDate)){
return Response.ok();
}
try {
Map<String,Integer> map = new HashMap<String, Integer>();
Page<CalendarStatisticVO> page = calendarStatisticClient.list(startDate, endDate, kwd, pageSize, pageNo);
map.put("pageSize", pageSize);
map.put("pageNo", pageNo);
map.put("pageTotal", page!=null&&page.getSize()>0?page.getTotal():null);
List<CalendarStatisticVO> ret = page!=null&&page.getSize()>0?page.getRecords():new ArrayList<CalendarStatisticVO>();
return Response.ok(ret, map);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
return Response.fail();
}
}
@ApiOperation(value = "导出下载统计数据")
@GetMapping(value = "/list/export")
public Response<String> listExport(@RequestParam(name = "startDate", required = true) String startDate,
@RequestParam(name = "endDate", required = true) String endDate,
@RequestParam(name = "kwd", required = false) String kwd){
Map<String, Object> map = calendarStatisticClient.listExport(startDate, endDate, kwd);
return Response.ok(map.get("result").toString());
}
@ApiOperation(value = "导出下载用户打卡记录数据")
@GetMapping(value = "/account/export")
public Response<String> accountExport(@RequestParam(name = "startDate", required = true) String startDate,
@RequestParam(name = "endDate", required = true) String endDate,
@RequestParam(name = "accountId", required = false) Long accountId){
Map<String, Object> map = calendarStatisticClient.accountExport(startDate, endDate, accountId);
return Response.ok(map.get("result").toString());
}
@ApiOperation(value = "导出下载签到明细数据")
@GetMapping(value = "/detail/export")
public Response<String> detailExport(@RequestParam(name = "startDate", required = true) String startDate,
@RequestParam(name = "endDate", required = true) String endDate,
@RequestParam(name = "kwd", required = false) String kwd){
Map<String, Object> map = calendarStatisticClient.detailExport(startDate, endDate, kwd);
return Response.ok(map.get("result").toString());
}
}
package com.yizhi.application.calendar;
import com.yizhi.calendar.application.feign.CalendarClient;
import com.yizhi.calendar.application.vo.CalendarParam;
import com.yizhi.calendar.application.vo.CalendarVO;
import com.yizhi.util.application.constant.ReturnCode;
import com.yizhi.util.application.domain.Response;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
@Api(tags = "管理端-签到打卡接口")
@RestController
@RequestMapping("/manage/calendar")
public class ManageCalendarController {
private static final Logger LOG = LoggerFactory.getLogger(ManageCalendarController.class);
@Autowired
private CalendarClient calendarClient;
@ApiOperation(value = "签到打卡规则回显接口",response = CalendarVO.class)
@GetMapping(value = "/get")
public Response<CalendarVO> get(){
try {
CalendarVO vo = calendarClient.getCalendar();
return Response.ok(vo);
} catch (Exception e) {
LOG.error("签到打卡规则查询失败!!!"+e);
return Response.fail(ReturnCode.BIZ_FAIL.getCode(),ReturnCode.BIZ_FAIL.getMsg());
}
}
@PostMapping(value = "/save")
public Response<Boolean> insert(@RequestBody CalendarParam calendarParam){
try {
Boolean b = calendarClient.insertCalendarPointSet(calendarParam);
if (b) {
return Response.ok(ReturnCode.SUCCESS);
}else {
return Response.fail(ReturnCode.SAVE_FAIL.getCode(),ReturnCode.SAVE_FAIL.getMsg());
}
} catch (Exception e) {
LOG.error("签到打卡入库失败!!!"+e);
return Response.fail(ReturnCode.BIZ_FAIL.getCode(),ReturnCode.BIZ_FAIL.getMsg());
}
}
}
package com.yizhi.application.caseLibrary.constant;
/**
* @author Ding
* @className Constant
* @description TODO
* @date 2019/7/22
**/
public interface Constant {
public final static Integer INSERT_CLASSIFY_SUCCESS = 1;
public final static Integer INSERT_CLASSIFY_FAIL = 2;
/**
* 最多只能有三个维度
*/
public final static Integer INSERT_CLASSIFY_INSUFFICIENT = 3;
public final static Integer INSERT_CLASSIFY_IDENTICAL_NAME = 4;
}
package com.yizhi.application.caseLibrary.controller;
import com.yizhi.application.caseLibrary.constant.Constant;
import com.yizhi.core.application.enums.InternationalEnums;
import com.yizhi.library.application.feign.CaseLibraryClassifyClient;
import com.yizhi.library.application.vo.ClassifyListVO;
import com.yizhi.library.application.vo.ClassifyVO;
import com.yizhi.util.application.domain.Response;
import com.yizhi.util.application.enums.i18n.Constants;
import io.swagger.annotations.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.List;
/**
* @author Ding
* @className CaseLibraryManageController
* @description TODO
* @date 2019/7/3
**/
@Api(tags = "案例库分类管理接口", description = "案例库分类管理接口")
@RestController
@RequestMapping("/manage/caseLibrary/classify")
public class CaseLibraryClassifyController {
private static final Logger LOGGER = LoggerFactory.getLogger(CaseLibraryClassifyController.class);
@Autowired
CaseLibraryClassifyClient caseLibraryClassifyClient;
@ApiOperation(value = "新建分类", notes = "新建分类")
@ApiImplicitParams({@ApiImplicitParam(name = "name", value = "课程名称", paramType = "body", required = false),
@ApiImplicitParam(name = "level", value = "0:维度, 1:一级分类 2:二级分类", paramType = "body", required = true),
@ApiImplicitParam(name = "name", value = "名称", paramType = "body", required = false),
@ApiImplicitParam(name = "parentId", value = "父级id 0为维度没有父级", paramType = "body", required = true),
@ApiImplicitParam(name = "description", value = "分类描述", paramType = "body", required = false)})
@PostMapping("/insert")
public Response<Object> classifyInsert(@RequestBody ClassifyVO classify) {
try {
Integer result = caseLibraryClassifyClient.insertClassify(classify);
if (result.equals(Constant.INSERT_CLASSIFY_SUCCESS)) {
return Response.ok();
} else if (result.equals(Constant.INSERT_CLASSIFY_INSUFFICIENT)) {
return Response.fail(InternationalEnums.CASELIBRARYCLASSIFYCONTROLLER.getCode());
} else if (result.equals(Constant.INSERT_CLASSIFY_IDENTICAL_NAME)) {
return Response.fail(InternationalEnums.CERTIFICATECONTROLLER2.getCode());
} else {
LOGGER.error("############插入数据过程中出现错误");
return Response.fail(Constants.MSG_BIZ_FAIL);
}
} catch (Exception e) {
LOGGER.error("############案例库服务调用出现异常", e);
return Response.fail(Constants.MSG_BIZ_FAIL);
}
}
@ApiOperation(value = "删除分类", notes = "删除分类")
@GetMapping("/delete")
public Response<Object> deleteClassify(@ApiParam(value = "分类id", required = true) @RequestParam("classifyId") Long classifyId) {
try {
if (caseLibraryClassifyClient.deleteClassify(classifyId)) {
return Response.ok();
} else {
LOGGER.error("############删除分类过程中出现错误");
return Response.fail(Constants.MSG_BIZ_FAIL);
}
} catch (Exception e) {
LOGGER.error("############案例库服务调用出现异常", e);
return Response.fail(Constants.MSG_BIZ_FAIL);
}
}
@ApiOperation(value = "分类下架", notes = "分类下架")
@GetMapping("/putDown")
public Response<Object> putDownClassify(@ApiParam(value = "分类id", required = true) @RequestParam("classifyId") Long classifyId) {
try {
return Response.ok(caseLibraryClassifyClient.putDownClassify(classifyId));
} catch (Exception e) {
LOGGER.error("############案例库服务调用出现异常", e);
return Response.fail(Constants.MSG_BIZ_FAIL);
}
}
@ApiOperation(value = "分类上架", notes = "分类上架")
@GetMapping("/release")
public Response<Object> releaseClassify(@ApiParam(value = "分类id", required = true) @RequestParam("classifyId") Long classifyId) {
try {
return Response.ok(caseLibraryClassifyClient.releaseClassify(classifyId));
} catch (Exception e) {
LOGGER.error("############案例库服务调用出现异常", e);
return Response.fail(Constants.MSG_BIZ_FAIL);
}
}
@ApiOperation(value = "获取分类列表", notes = "获取分类列表", response = ClassifyListVO.class)
@GetMapping("/list")
public Response<ClassifyListVO> getClassifyList() {
try {
List<ClassifyListVO> list = caseLibraryClassifyClient.getClassifyList();
// list = JSON.parseArray(JSON.toJSONString(list), ClassifyListVO.class);
// String s = JSON.toJSONString(list);
return Response.ok(list);
} catch (Exception e) {
LOGGER.error("############案例库服务调用出现异常", e);
return Response.fail(Constants.MSG_BIZ_FAIL);
}
}
@ApiOperation(value = "修改分类信息", notes = "修改分类信息")
@GetMapping("/update")
public Response<Object> updateClassify(@ApiParam(value = "分类id", required = true) @RequestParam("classifyId") Long classifyId,
@ApiParam(value = "分类名称") @RequestParam(name = "name", required = false) String name,
@ApiParam(value = "分类描述") @RequestParam(name = "description", required = false) String description) {
try {
if (caseLibraryClassifyClient.updateClassify(classifyId, name, description)) {
return Response.ok();
} else {
LOGGER.error("############修改分类信息过程中出现错误");
return Response.fail(InternationalEnums.CERTIFICATECONTROLLER2.getCode());
}
} catch (Exception e) {
LOGGER.error("############案例库服务调用出现异常", e);
return Response.fail(Constants.MSG_BIZ_FAIL);
}
}
@ApiOperation(value = "上移下移", notes = "上移下移")
@GetMapping("/move")
public Response<Object> moveClassify(@ApiParam(value = "分类id", required = true) @RequestParam("classifyId") Long classifyId,
@ApiParam(value = "上级分类id") @RequestParam(name = "parentId", required = false) Long parentId,
@ApiParam(value = "分类排序") @RequestParam(name = "sort", required = false) Integer sort,
@ApiParam(value = "上移/下移类型,1上移,2下移") @RequestParam(name = "type", required = true) Integer type
) {
try {
Integer result = caseLibraryClassifyClient.moveClassify(classifyId, parentId, sort, type);
if (result == 1) {
//操作成功
return Response.ok();
} else if (result == 3) {
return Response.fail("4002", InternationalEnums.MYITEMCONFIGMANAGECOMTROLLER2.getCode());
} else if (result == 4) {
return Response.fail("4003", InternationalEnums.MANAGEASSIGNMENTCONTROLLER3.getCode());
} else {
LOGGER.error("############上移下移过程中出现错误");
return Response.fail(Constants.MSG_BIZ_FAIL);
}
} catch (Exception e) {
LOGGER.error("############案例库服务调用出现异常", e);
return Response.fail(Constants.MSG_BIZ_FAIL);
}
}
}
package com.yizhi.application.caseLibrary.controller;
import com.baomidou.mybatisplus.plugins.Page;
import com.yizhi.library.application.feign.CommentManageClient;
import com.yizhi.library.application.vo.CommentReplyVO;
import com.yizhi.library.application.vo.CommentVO;
import com.yizhi.util.application.domain.Response;
import com.yizhi.util.application.enums.i18n.Constants;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
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.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import java.util.HashMap;
import java.util.Map;
/**
* @author Ding
* @className CommentManageController
* @description TODO
* @date 2019/7/15
**/
@Api(tags = "评分管理接口", description = "评分管理接口")
@RestController
@RequestMapping("/manage/caseLibrary/comment")
public class CommentManageController {
private static final Logger LOGGER = LoggerFactory.getLogger(CommentManageController.class);
@Autowired
private CommentManageClient commentManageClient;
@ApiOperation(value = "获取评论管理列表", notes = "获取评论管理列表", response = CommentVO.class)
@GetMapping("/list")
public Response<CommentVO> getCommentManageList(@ApiParam(value = "学员案例id", required = true) @RequestParam(name = "studentCaseId", required = true) Long studentCaseId,
@ApiParam(value = "评论人用户名或者姓名/需求改了不需要模糊查询了", required = false) @RequestParam(name = "name", required = false) String name,
@ApiParam(value = "状态/需求改了,不需要模糊查询了", required = false) @RequestParam(name = "state", required = false) Integer state,
@ApiParam(value = "当前第几页", required = true) @RequestParam(name = "pageNo", required = true) Integer pageNo,
@ApiParam(value = "每页条数", required = true) @RequestParam(name = "pageSize", required = true) Integer pageSize) {
try {
if (StringUtils.isNotBlank(name)) {
name = name.trim();
}
Page<CommentVO> page = commentManageClient.getCommentManageList(studentCaseId, name, state, pageNo, pageSize);
Map<String, Integer> pageMap = new HashMap<>(3);
pageMap.put("pageNo", pageNo);
pageMap.put("pageSize", pageSize);
if (null != page) {
pageMap.put("total", page.getTotal());
}
return Response.ok(page, pageMap);
} catch (Exception e) {
LOGGER.error("############案例库服务调用出现异常", e);
return Response.fail(Constants.MSG_BIZ_FAIL);
}
}
@ApiOperation(value = "下载评论信息", notes = "下载评论信息")
@GetMapping("/downloadList")
public Response<String> downloadList(@ApiParam(value = "学员案例id", required = true) @RequestParam(name = "studentCaseId", required = true) Long studentCaseId,
@ApiParam(value = "评论人用户名或者姓名", required = false) @RequestParam(name = "name", required = false) String name,
@ApiParam(value = "状态", required = false) @RequestParam(name = "state", required = false) Integer state) {
try {
if (StringUtils.isNotBlank(name)) {
name = name.trim();
}
String serialNo = commentManageClient.downloadList(studentCaseId, name, state);
return Response.ok("导入成功," + " " + "编号:" + serialNo);
} catch (Exception e) {
LOGGER.error("############案例库服务调用出现异常", e);
return Response.fail(Constants.MSG_BIZ_FAIL);
}
}
@ApiOperation(value = "获取评论回复列表", notes = "获取评论回复列表", response = CommentReplyVO.class)
@GetMapping("/replyList")
public Response<CommentReplyVO> getCommentReplyList(@ApiParam(value = "评论id", required = true) @RequestParam(name = "commentId", required = true) Long commentId,
@ApiParam(value = "评论人用户名或者姓名", required = false) @RequestParam(name = "name", required = false) String name,
@ApiParam(value = "状态", required = false) @RequestParam(name = "state", required = false) Integer state) {
try {
if (StringUtils.isNotBlank(name)) {
name = name.trim();
}
return Response.ok(commentManageClient.getCommentReplyList(name, state, commentId));
} catch (Exception e) {
LOGGER.error("############案例库服务调用出现异常", e);
return Response.fail(Constants.MSG_BIZ_FAIL);
}
}
@ApiOperation(value = "评论/回复下架", notes = "评论/回复下架")
@GetMapping("/putDown")
public Response<Object> putDown(@ApiParam(value = "评论/回复id", required = true) @RequestParam(name = "id", required = true) Long id,
@ApiParam(value = "类型 1:评论 2:回复", required = true) @RequestParam(name = "type", required = true) Integer type) {
try {
return Response.ok(commentManageClient.putDown(id, type));
} catch (Exception e) {
LOGGER.error("############案例库服务调用出现异常", e);
return Response.fail(Constants.MSG_BIZ_FAIL);
}
}
@ApiOperation(value = "评论/回复上架", notes = "评论/回复上架")
@GetMapping("/release")
public Response<Object> release(@ApiParam(value = "评论id", required = true) @RequestParam(name = "id", required = true) Long id,
@ApiParam(value = "类型 1:评论 2:回复", required = true) @RequestParam(name = "type", required = true) Integer type) {
try {
return Response.ok(commentManageClient.release(id, type));
} catch (Exception e) {
LOGGER.error("############案例库服务调用出现异常", e);
return Response.fail(Constants.MSG_BIZ_FAIL);
}
}
@ApiOperation(value = "评论/回复删除", notes = "评论/回复删除", response = CommentReplyVO.class)
@GetMapping("/delete")
public Response<CommentReplyVO> delete(@ApiParam(value = "评论/回复id", required = true) @RequestParam(name = "id", required = true) Long id,
@ApiParam(value = "类型 1:评论 2:回复", required = true) @RequestParam(name = "type", required = true) Integer type) {
try {
return Response.ok(commentManageClient.delete(id, type));
} catch (Exception e) {
LOGGER.error("############案例库服务调用出现异常", e);
return Response.fail(Constants.MSG_BIZ_FAIL);
}
}
}
package com.yizhi.application.caseLibrary.controller;
import java.util.HashMap;
import java.util.Map;
import com.yizhi.library.application.feign.StudentCaseReportClient;
import com.yizhi.library.application.vo.StatisticStudentCaseVO;
import com.yizhi.library.application.vo.StudentCaseAccountExportVO;
import com.yizhi.library.application.vo.StudentCaseOrgExportVO;
import com.yizhi.util.application.domain.Response;
import com.yizhi.util.application.enums.i18n.Constants;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
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.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import com.baomidou.mybatisplus.plugins.Page;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
@Api(tags = "管理端学员案例报表接口", description = "管理端学员案例报表接口")
@RestController
@RequestMapping("/statistic/studentCase")
public class StatisticStudentCaseController {
private static final Logger LOGGER = LoggerFactory.getLogger(StatisticStudentCaseController.class);
@Autowired
private StudentCaseReportClient studentCaseReportClient;
@ApiOperation(value = "学员案例报表按部门统计", notes = "学员案例报表", response = StudentCaseOrgExportVO.class)
@GetMapping("/list/org")
public Response<StudentCaseOrgExportVO> studentCaseListOrg(
@ApiParam(value = "案例名称模糊查询", required = false) @RequestParam(name = "kwd", required = false) String kwd,
@ApiParam(value = "每页条数,默认10", required = false) @RequestParam(name = "pageSize", required = false, defaultValue = "10") Integer pageSize,
@ApiParam(value = "当前页数", required = false) @RequestParam(name = "pageNo", required = false, defaultValue = "1") Integer pageNo) {
try {
Page<StudentCaseOrgExportVO> page = new Page<>(pageNo, pageSize);
//page = studentCaseReportClient.studentCaseByOrg(kwd, pageSize, pageNo);
page = studentCaseReportClient.studentCaseByOrg(kwd, pageSize, pageNo);
Map<String, Integer> pageMap = new HashMap<>(3);
pageMap.put("pageNo", pageNo);
pageMap.put("pageSize", pageSize);
if (null != page) {
pageMap.put("total", page.getTotal());
}
return Response.ok(page, pageMap);
} catch (Exception e) {
LOGGER.error("############案例库服务调用出现异常", e);
return Response.fail(Constants.MSG_BIZ_FAIL);
}
}
@ApiOperation(value = "学员案例报表按用户统计", notes = "学员案例报表", response = StudentCaseAccountExportVO.class)
@GetMapping("/list/account")
public Response<StudentCaseAccountExportVO> studentCaseListAccount(
@ApiParam(value = "案例名称模糊查询", required = false) @RequestParam(name = "kwd", required = false) String kwd,
@ApiParam(value = "每页条数,默认10", required = false) @RequestParam(name = "pageSize", required = false, defaultValue = "10") Integer pageSize,
@ApiParam(value = "当前页数", required = false) @RequestParam(name = "pageNo", required = false, defaultValue = "1") Integer pageNo) {
try {
Page<StudentCaseAccountExportVO> page = new Page<>(pageNo, pageSize);
page = studentCaseReportClient.studentCaseByAccount(kwd, pageSize, pageNo);
Map<String, Integer> pageMap = new HashMap<>(3);
pageMap.put("pageNo", pageNo);
pageMap.put("pageSize", pageSize);
if (null != page) {
pageMap.put("total", page.getTotal());
}
return Response.ok(page, pageMap);
} catch (Exception e) {
LOGGER.error("############案例库服务调用出现异常", e);
return Response.fail(Constants.MSG_BIZ_FAIL);
}
}
@ApiOperation(value = "学员案例报表按案例统计", notes = "学员案例报表", response = StatisticStudentCaseVO.class)
@GetMapping("/list")
public Response<StatisticStudentCaseVO> studentCaseList(
@ApiParam(value = "案例名称模糊查询", required = false) @RequestParam(name = "kwd", required = false) String kwd,
@ApiParam(value = "每页条数,默认10", required = false) @RequestParam(name = "pageSize", required = false, defaultValue = "10") Integer pageSize,
@ApiParam(value = "当前页数", required = false) @RequestParam(name = "pageNo", required = false, defaultValue = "1") Integer pageNo,
@ApiParam(value = "开始时间(yyyy-mm-dd)", required = false) @RequestParam(name = "startDate", required = false) String startDate,
@ApiParam(value = "结束时间(yyyy-mm-dd)", required = false) @RequestParam(name = "endDate", required = false) String endDate) {
try {
Page<StatisticStudentCaseVO> page = new Page<>(pageNo, pageSize);
page = studentCaseReportClient.studentCaseList(startDate, endDate, kwd, pageSize, pageNo);
Map<String, Integer> pageMap = new HashMap<>(3);
pageMap.put("pageNo", pageNo);
pageMap.put("pageSize", pageSize);
if (null != page) {
pageMap.put("total", page.getTotal());
}
return Response.ok(page, pageMap);
} catch (Exception e) {
LOGGER.error("############案例库服务调用出现异常", e);
return Response.fail(Constants.MSG_BIZ_FAIL);
}
}
@ApiOperation(value = "学员案例报表按部门统计下载报表", notes = "学员案例报表按部门统计下载报表")
@GetMapping("/list/org/export")
public Response<Object> studentCaseListOrgExport(
@ApiParam(value = "部门名称模糊查询", required = false) @RequestParam(name = "kwd", required = false) String kwd) {
try {
Map<String, Object> map = studentCaseReportClient.studentCaseExportByOrg(kwd);
return Response.ok(map.get("result").toString());
} catch (Exception e) {
LOGGER.error("############案例库服务调用出现异常", e);
return Response.fail(Constants.MSG_BIZ_FAIL);
}
}
@ApiOperation(value = "学员案例报表按用户统计下载报表", notes = "学员案例报表按用户统计下载报表")
@GetMapping("/list/account/export")
public Response<Object> studentCaseListAccountExport(
@ApiParam(value = "用户名称模糊查询", required = false) @RequestParam(name = "kwd", required = false) String kwd) {
try {
Map<String, Object> map = studentCaseReportClient.studentCaseExportByAccount(kwd);
return Response.ok(map.get("result").toString());
} catch (Exception e) {
LOGGER.error("############案例库服务调用出现异常", e);
return Response.fail(Constants.MSG_BIZ_FAIL);
}
}
@ApiOperation(value = "学员案例报表按部门统计下载报表", notes = "学员案例报表按部门统计下载报表")
@GetMapping("/list/export")
public Response<Object> studentCaseListExport( @ApiParam(value = "案例名称模糊查询", required = false) @RequestParam(name = "kwd", required = false) String kwd,
@ApiParam(value = "开始时间(yyyy-mm-dd)", required = false) @RequestParam(name = "startDate", required = false) String startDate,
@ApiParam(value = "结束时间(yyyy-mm-dd)", required = false) @RequestParam(name = "endDate", required = false) String endDate){
try {
Map<String, Object> map = studentCaseReportClient.studentCaseExport(startDate, endDate, kwd);
return Response.ok(map.get("result").toString());
} catch (Exception e) {
LOGGER.error("############案例库服务调用出现异常", e);
return Response.fail(Constants.MSG_BIZ_FAIL);
}
}
}
package com.yizhi.application.certificate.constant;
/**
* @author Ding
* @className Constant
* @description TODO
* @date 2019/12/23
**/
public interface CertificateConstant {
public final static Integer INSERT_CLASSIFY_SUCCESS = 1;
public final static Integer INSERT_CLASSIFY_FAIL = 2;
/**
* 同一个分类等级下分类名重复
*/
public final static Integer INSERT_CLASSIFY_IDENTICAL_NAME = 3;
public final static Integer DELETE_CLASSIFY_SUCCESS = 1;
/**
* 有子分类或者有分类证书不能删除
*/
public final static Integer DELETE_CLASSIFY_FAIL = 2;
}
/**
*
*/
package com.yizhi.application.certificate.constant;
public interface LogError {
final String LOG_SEARCH_ERROR ="LOG_SEARCH_ERROR";
final String LOG_SEARCH_ERROR_MSG ="日志搜索错误";
final String CERTIFICATE_ANALYSIS_ERROR ="CERTIFICATE_ANALYSIS_ERROR";
final String CERTIFICATE_ANALYSIS_ERROR_MSG ="自定义证书解析错误";
final String USER_CERTIFICATE_SEARCH_ERROR ="USER_CERTIFICATE_SEARCH_ERROR";
final String USER_CERTIFICATE_SEARCH_ERROR_MSG ="获取我的证书列表失败";
final String LOG_SEARCH_ERROR_ENABLECERTIFICATEMSG ="没有该证书";
final String LOG_SEARCH_ERROR_COPYCERTIFICATEMSG="没有该证书";
final String TEMPLATE_CREATE_ERROR ="TEMPLATE_CREATE_ERROR";
final String TEMPLATE_CREATE_ERROR_MAG ="自定义模板信息保存失败";
final String USER_GET_ERROR ="USER_GET_ERROR";
final String USER_GET_ERROR_MAG ="上下文用户获取失败";
final String LOG_UPDATECERTIFICATE_ERROR_SUBMSG = "修改证书错误";
final String LOG_UPDATECERTIFICATE_ERROR_SUBCODE = "CERTIFICATE_UPDATE_ERROR";
final String LOG_SEARCH_ERROR_SELECTTEMPLATE_SUBCODE = "USER_SERARCH_TEMPLATE_ERROR";
final String LOG_SEARCH_ERROR_SELECTTEMPLATE_SUBMSG = "查找证书模板失败";
final String LOG_ADDCERTIFICATE_ERROR_SUBMSG = "添加证书错误";
final String LOG_ADDCERTIFICATE_ERROR_SUBCODE = "ADD_CERTIFICATE_ERROR";
final String LOG_LIST_CERTIFICATE_ERROR_SUBMSG = "证书查找失败";
final String LOG_LIST_ERROR_SUBCODE = "LIST_CERTIFICATE_ERROR";
}
package com.yizhi.application.certificate.constant;
public class UtilConstants {
/**
* 证书自定义包下载保存路径,以及解压和解析后的图片
*/
// public static String CERTIFICATE_SAVE_PATH = "D://test";
public static String CERTIFICATE_SAVE_PATH = "/home/file/certificate";
}
package com.yizhi.application.certificate.util;
import com.yizhi.application.certificate.constant.LogError;
import com.yizhi.application.certificate.constant.UtilConstants;
import com.yizhi.application.course.util.OssUpload;
import com.yizhi.core.application.exception.FileReadException;
import com.yizhi.util.application.zip.ZipUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
import javax.imageio.ImageIO;
import java.awt.image.BufferedImage;
import java.io.*;
import java.net.HttpURLConnection;
import java.net.URL;
@Component
public class CertificateZipAnalysis {
@Value("${ACTIVE}")
public String active;
private static final Logger LOG = LoggerFactory.getLogger(CertificateZipAnalysis.class);
public String parseTemplate(File fileInfo) {
//fileInfo F:\home\file\certificate\完整竖版证书包1552529700331.zip
try {
// 证书模板 文件目录(解压后都放在这里面)
File templateBaseDir = new File(UtilConstants.CERTIFICATE_SAVE_PATH);
// 若 模板 文件夹不存在
if (!templateBaseDir.exists()) {
if (!templateBaseDir.mkdir()) {
LOG.error("证书文件夹新建失败!");
return LogError.CERTIFICATE_ANALYSIS_ERROR;
}
}
// 没有后缀的文件名
// 完整竖版证书包1552529700331
String fileNameWithoutSuffix = fileInfo.getName().substring(0, fileInfo.getName().lastIndexOf("."));
// 当前 模板 课件解压后的根目录
//F:\home\file\certificate\完整竖版证书包1552529700331
File templateDir = new File(templateBaseDir.getAbsolutePath() + File.separator + fileNameWithoutSuffix);
ZipUtil.unZip(fileInfo.getAbsolutePath(), templateDir.getAbsolutePath());
File tem=new File(templateDir.getAbsolutePath());
//去找index文件
//File indexFile = new File(templateDir.getAbsolutePath() + "/index.html");
String indexFilePath=pointFile(tem);
//index文件的全路径
File indexPath=new File(indexFilePath);
String fileIndexParentPath=indexPath.getParent();
templateDir=new File(fileIndexParentPath);
int height = 0;
int width = 0;
File imgFile = new File(templateDir.getAbsolutePath() + File.separator + "background.jpg");
if (imgFile.exists()) {
try {
BufferedImage bufferedImage = ImageIO.read(new FileInputStream(imgFile));
height = bufferedImage.getHeight();
width = bufferedImage.getWidth();
} catch (IOException e) {
LOG.info("获取图片信息异常{}",e);
}
}
HtmltopdfAndImage.convert(templateDir.getAbsolutePath() + "/index.html",
templateDir.getAbsolutePath() + "/" + fileNameWithoutSuffix + ".pdf",
1,height,width);
PdfToPng.pdfToPng(templateDir.getAbsolutePath() + "/" + fileNameWithoutSuffix + ".pdf",templateDir.getAbsolutePath(),500,1,fileNameWithoutSuffix);
String result = OssUpload.upload(templateDir.getAbsolutePath() + "/" + fileNameWithoutSuffix + ".png", fileNameWithoutSuffix + ".png",active);
return result;
} catch (Exception e) {
LOG.error("文件解析失败", e);
return LogError.CERTIFICATE_ANALYSIS_ERROR;
}
}
/**
* @param urlStr
* @param savePath
* @param fileName
* @return fileInfo 的 properties 中含有一个 absolutePath
*/
public static File read(String urlStr, String savePath, String fileName) {
File fileInfo = null;
try {
URL url = new URL(urlStr);
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
//防止屏蔽程序抓取而返回403错误
conn.setRequestProperty("User-Agent","Mozilla/4.0 (compatible; MSIE 5.0; Windows NT; DigExt)");
conn.setRequestProperty("Charsert", "UTF-8");
conn.setRequestProperty("Accept-Charset", "UTF-8");
//得到输入流
InputStream inputStream = conn.getInputStream();
//获取自己数组
byte[] buffer = new byte[1024];
int len = 0;
ByteArrayOutputStream bos = new ByteArrayOutputStream();
while ((len = inputStream.read(buffer)) != -1) {
bos.write(buffer, 0, len);
}
bos.close();
byte[] getData = bos.toByteArray();
//文件保存位置
File saveDir = new File(savePath);
if (!saveDir.exists()) {
saveDir.mkdir();
}
fileInfo = new File(saveDir + File.separator + fileName);
FileOutputStream fos = new FileOutputStream(fileInfo);
fos.write(getData);
if (fos != null) {
fos.close();
}
if (inputStream != null) {
inputStream.close();
}
} catch (Exception e) {
LOG.error("文件拉取失败", e);
throw new FileReadException();
}
return fileInfo;
}
public String parse(String urlStr, String savePath, String fileName) {
try {
//文件下载下来 保存的全路径
File fileInfo = read(urlStr, savePath, fileName);
String result = parseTemplate(fileInfo);
return result;
} catch (Exception e) {
return LogError.CERTIFICATE_ANALYSIS_ERROR;
}
}
private String pointFile(File file) {
String name=null;
if(file.exists()){
if (file.isFile()) {
name=file.getAbsolutePath();
if(name.indexOf("index.html")>0&&name.indexOf("_index.html")==-1) {
return name;
}
} else {
File[] list = file.listFiles();
if (list.length == 0) {
System.out.println(file.getAbsolutePath() + " is null");
} else {
for (int i = 0; i < list.length; i++) {
name=pointFile(list[i]);
if(name!=null) {
return name;
}
}
}
}
}else{
System.out.println("The directory is not exist!");
}
return null;
}
}
package com.yizhi.application.certificate.util;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
/**
* 当java调用wkhtmltopdf时,用于获取wkhtmltopdf返回的内容
*/
public class HtmlToPdfInter extends Thread {
private static final Logger LOG = LoggerFactory
.getLogger(HtmlToPdfInter.class);
private InputStream is;
public HtmlToPdfInter(InputStream is) {
this.is = is;
}
@Override
public void run() {
try {
InputStreamReader isr = new InputStreamReader(is, "utf-8");
BufferedReader br = new BufferedReader(isr);
br.readLine();
} catch (IOException e) {
LOG.error(e.getMessage());
e.printStackTrace();
}
}
}
\ No newline at end of file
package com.yizhi.application.certificate.util;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.File;
public class HtmltopdfAndImage {
private static final Logger LOG = LoggerFactory.getLogger(HtmltopdfAndImage.class);
// private static final String TOPDFTOOL = "D:\\development\\wkhtmltopdf\\bin\\wkhtmltopdf.exe";
// private static final String TOIMGTOOL = "D:\\development\\wkhtmltopdf\\bin\\wkhtmltoimage.exe";
private static final String TOPDFTOOL = "wkhtmltopdf";
private static final String TOIMGTOOL = "wkhtmltoimage";
//
/**
* html转pdf或者Img
* @param srcPath html路径,可以是硬盘上的路径,也可以是网络路径
* @param destPath pdf或者Image保存路径
* @param outType 需要生成的文件类型:1.pdf 2.jpg
* @return 转换成功返回true
*/
public static boolean convert(String srcPath, String destPath,int outType,int height,int width) {
File file = new File(destPath);
File parent = file.getParentFile();
// 如果pdf保存路径不存在,则创建路径
if (!parent.exists()) {
parent.mkdirs();
}
StringBuilder cmd = new StringBuilder();
if (outType == 1) {
cmd.append(TOPDFTOOL);
}else if(outType == 2){
cmd.append(TOIMGTOOL);
}
cmd.append(" ");
if(height>width ){
cmd.append("--page-size A4");// 参数
cmd.append(" ");
}else {
cmd.append("--page-width ").append(297).append("mm");
cmd.append(" ");
cmd.append("--page-height ").append(210).append("mm");
cmd.append(" ");
}
cmd.append(srcPath);
cmd.append(" ");
cmd.append(destPath);
System.out.println(cmd);
boolean result = true;
try {
Process proc = Runtime.getRuntime().exec(cmd.toString());
HtmlToPdfInter error = new HtmlToPdfInter(
proc.getErrorStream());
HtmlToPdfInter output = new HtmlToPdfInter(
proc.getInputStream());
error.start();
output.start();
proc.waitFor();
LOG.info("转换成功,参数---html路径:{},pdf保存路径 :{}", new Object[] {srcPath, destPath });
} catch (Exception e) {
LOG.error("转换失败,srcPath地址:{},错误信息:{}", new Object[]{srcPath, e.getMessage()});
result = false;
}
return result;
}
}
\ No newline at end of file
package com.yizhi.application.certificate.util;
import org.apache.pdfbox.pdmodel.PDDocument;
import org.apache.pdfbox.rendering.PDFRenderer;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import javax.imageio.ImageIO;
import javax.imageio.stream.ImageOutputStream;
import java.awt.image.BufferedImage;
import java.io.*;
/**
* 转多页 完成
* @author wangfeida
*
*/
public class PdfToPng {
private final static Logger logger = LoggerFactory.getLogger(PdfToPng.class);
/***
* PDF文件转PNG图片
* @param pdfPath E:\png\简历.pdf
* @param outputFilePath 图片存放的文件夹 E:\png
* @param dpi dpi越大转换后越清晰,相对转换速度越慢
* @param flag 页数 为0则转换全部页数
* @return
* @throws IOException
*/
public static String pdfToPng(String pdfPath, String outputFilePath, int dpi,int flag,String filename) throws IOException {
File file = new File(pdfPath);
PDDocument pdDocument = null;
try {
if (createDirectory(outputFilePath)) {
pdDocument = PDDocument.load(file);
PDFRenderer renderer = new PDFRenderer(pdDocument);
int pages = pdDocument.getNumberOfPages();
if(flag > 0) {//大于0则打印具体页数
if(flag<pages) {
pages = flag;
}
}
StringBuffer imgFilePath = null;
for (int i = 0; i < pages; i++) {
String imgFilePathPrefix = outputFilePath+File.separator;
imgFilePath = new StringBuffer();
imgFilePath.append(imgFilePathPrefix);
imgFilePath.append(filename);
imgFilePath.append(".png");
File dstFile = new File(imgFilePath.toString());
BufferedImage image = renderer.renderImageWithDPI(i, dpi);
ImageIO.write(image, "png", dstFile);
}
System.out.println(outputFilePath+"1111");
return outputFilePath;
} else {
return "创建文件夹错误";
}
} catch (Exception e) {
logger.info("Pdf转Png发生错误", e.getMessage());
return "Pdf转Png转换发生错误";
}finally {
pdDocument.close();
}
}
private static boolean createDirectory(String folder) {
File dir = new File(folder);
if (dir.exists()) {
return true;
} else {
return dir.mkdirs();
}
}
public static void pdfFileToImage(File pdffile,String targetPath){
try {
FileInputStream instream = new FileInputStream(pdffile);
InputStream byteInputStream=null;
try {
PDDocument doc = PDDocument.load(instream);
PDFRenderer renderer = new PDFRenderer(doc);
int pageCount = doc.getNumberOfPages();
if (pageCount > 0) {
BufferedImage image = renderer.renderImage(0, 2.0f);
image.flush();
ByteArrayOutputStream bs = new ByteArrayOutputStream();
ImageOutputStream imOut;
imOut = ImageIO.createImageOutputStream(bs);
ImageIO.write(image, "png", imOut);
byteInputStream = new ByteArrayInputStream(bs.toByteArray());
byteInputStream.close();
}
}
catch (IOException e) {
e.printStackTrace();
}
File uploadFile = new File(targetPath);
FileOutputStream fops;
fops = new FileOutputStream(uploadFile);
fops.write(readInputStream(byteInputStream));
fops.flush();
fops.close();
}
catch (Exception e) {
e.printStackTrace();
}
}
public static byte[] readInputStream(InputStream inStream) throws Exception {
ByteArrayOutputStream outStream = new ByteArrayOutputStream();
byte[] buffer = new byte[1024];
int len = 0;
while ((len = inStream.read(buffer)) != -1) {
outStream.write(buffer, 0, len);
}
inStream.close();
return outStream.toByteArray();
}
// public static void main(String[] args) {
// File file =new File("D:\\test\\qwe123.pdf");
// //上传的是png格式的图片结尾
// String targetfile="D:\\test\\qwe123.png";
// try {
//// pdfFileToImage(file,targetfile);
//
// pdfToPng("D:\\test\\qwe123.pdf","D:\\test\\",500,0,"qwe1234");
// } catch (Exception e) {
// }
//
//
//
// }
}
package com.yizhi.application.comment;
import com.baomidou.mybatisplus.plugins.Page;
import com.yizhi.comment.application.feign.ManageCommentClient;
import com.yizhi.comment.application.feign.ReplyClient;
import com.yizhi.comment.application.vo.CommentDelVO;
import com.yizhi.comment.application.vo.CommentVo;
import com.yizhi.util.application.domain.Response;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.*;
/**
* 评论 前端控制器
*
* @author Fairyland
*
*/
@Api(tags = "管理端-评论", description = "评论接口")
@RestController
@RequestMapping("/comment/manage")
public class NewCommentController {
@Autowired
private ManageCommentClient commentClient;
@Autowired
private ReplyClient replyClient;
@ApiOperation(value = "根据业务id获取评论列表(分页查询)", response = CommentVo.class)
@GetMapping("/list")
public Response getCommentList(
@ApiParam(name = "bizId", value = "业务id") @RequestParam(name = "bizId") Long bizId,@ApiParam(name = "bizType", value = "业务类型 0课程 7培训项目 12精选案例 15专辑") @RequestParam("bizType") Integer bizType,
@ApiParam(name = "pageNo", value = "跳转页数,默认第一页") @RequestParam(name = "pageNo", defaultValue = "1", required = false) Integer pageNo,
@ApiParam(name = "pageSize", value = "每页条数,默认10条") @RequestParam(name = "pageSize", defaultValue = "10", required = false) Integer pageSize) {
Page<CommentVo> page = commentClient.list(bizId,bizType, pageNo, pageSize);
return Response.ok(page);
}
@ApiOperation(value = "根据业务id获取评论列表(分页查询)", response = CommentVo.class)
@GetMapping("/reply/list")
public Response getReplyList(
@ApiParam(name = "bizId", value = "业务id") @RequestParam(name = "bizId") Long bizId,
@ApiParam(name = "pageNo", value = "跳转页数,默认第一页") @RequestParam(name = "pageNo", defaultValue = "1", required = false) Integer pageNo,
@ApiParam(name = "pageSize", value = "每页条数,默认10条") @RequestParam(name = "pageSize", defaultValue = "10", required = false) Integer pageSize) {
Page<CommentVo> page = replyClient.list(bizId, pageNo, pageSize);
return Response.ok(page);
}
@ApiOperation(value = "删除评论和回复")
@PostMapping("/deleteComment")
public Response<String> delateComment(@ApiParam(name = "CommentDelVO", value = "评论回复删除参数") @RequestBody CommentDelVO vo) {
String result = commentClient.delateComment(vo);
if (!StringUtils.isEmpty(result)) {
if ("success".equals(result)) {
return Response.ok();
} else {
return Response.fail();
}
}
return Response.fail();
}
@ApiOperation(value = "上架")
@GetMapping("/up")
public Response<String> up(@ApiParam(name = "id", value = "评论或回复id")@RequestParam("id") Long id, @ApiParam(name = "type", value = "0评论 1回复")@RequestParam("type") Integer type) {
Boolean up = commentClient.up(id, type);
if (up) {
return Response.ok();
} else {
return Response.fail();
}
}
@ApiOperation(value = "下架")
@GetMapping("/down")
public Response<String> down(@ApiParam(name = "id", value = "评论或回复id")@RequestParam("id") Long id, @ApiParam(name = "type", value = "0评论 1回复")@RequestParam("type") Integer type) {
Boolean up = commentClient.down(id, type);
if (up) {
return Response.ok();
} else {
return Response.fail();
}
}
@ApiOperation(value = "评论信息导出")
@GetMapping("/list/export")
public Response<String> export(
@ApiParam(name = "bizId", value = "业务id") @RequestParam(name = "bizId") Long bizId,
@ApiParam(name = "bizType", value = "业务类型 0课程 7培训项目 12精选案例 15专辑") @RequestParam("bizType") Integer bizType,
@ApiParam(name = "bizName", value = "业务名称") @RequestParam(name = "bizName") String bizName) {
return Response.ok(commentClient.export(bizId,bizType, bizName).get("result").toString());
}
}
/**
*
*/
package com.yizhi.application.course.constant;
public interface LogError {
final String SCORM_ANALYSIS_ERROR ="SCORM_ANALYSIS_ERROR";
final String SCORM_ANALYSIS_ERROR_MSG ="scorm解析错误";
final String DOC_ANALYSIS_ERROR ="DOC_ANALYSIS_ERROR";
final String DOC_ANALYSIS_ERROR_MSG ="文档解析错误";
}
package com.yizhi.application.course.constant;
public class UtilConstants {
/**
* 证书自定义包下载保存路径,以及解压和解析后的图片
*/
// public static String SCORM_SAVE_PATH = "D:/tmp/scorm";
public static String SCORM_SAVE_PATH = "/home/file/scorm";
public static String SCORM_URL_PATH_UAT = "http://uat.wechat.kmelearning.com/scorm";
public static String SCORM_URL_PATH_PROD = "http://kmelearning.com/scorm";
public static String SCORM_URL_PATH_SIT = "http://192.168.0.173/scorm";
public static String SCORM_URL_PATH_DEV = "http://192.168.0.162/scorm";
/**
* 文档解析用的第三方插件和解析后存放的图片目录
*/
public static String OPENOFFICE_PATH = "/opt/openoffice4";
public static String DOC_PATH = "/home/file/doc";
// public static String DOC_PATH = "D:\\home\\file\\doc";
}
package com.yizhi.application.course.controller;
import com.alibaba.fastjson.JSON;
import com.yizhi.application.course.vo.CardConfigInfoVO;
import com.yizhi.core.application.enums.InternationalEnums;
import com.yizhi.core.application.context.ContextHolder;
import com.yizhi.core.application.context.RequestContext;
import com.yizhi.course.application.feign.CardConfigClient;
import com.yizhi.course.application.vo.CardConfigVO;
import com.yizhi.system.application.system.remote.StudentEditPermissionClient;
import com.yizhi.system.application.vo.StudentEditPermissionVO;
import com.yizhi.util.application.domain.Response;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.Objects;
/**
* @Author: XieHaijun
* @Description:
* @Date: Created in 16:29 2019/3/7
* @Modified By
*/
@Api(tags="管理端-营销课程名片",description="名片的配置接口")
@RestController
@RequestMapping("/manage/cardConfig")
public class CardConfigController {
@Autowired
private CardConfigClient cardConfigClient;
@Autowired
private StudentEditPermissionClient permissionClient;
private Logger logger = LoggerFactory.getLogger(CardConfigController.class);
@ApiOperation(value = "保存名片配置",response = CardConfigInfoVO.class)
@PostMapping("/save")
public Response<CardConfigInfoVO> save(@RequestBody CardConfigInfoVO vo){
logger.info("请求参数={}", JSON.toJSONString(vo));
RequestContext rt = ContextHolder.get();
Long id = vo.getPermissionVO().getId();
if(Objects.isNull(id)){
StudentEditPermissionVO permissionExits = permissionClient.getBySiteId(rt.getSiteId());
if(permissionExits != null){
return Response.fail(InternationalEnums.CARDCONFIGCONTROLLER.getName());
}
}
// 保存个人编辑权限
StudentEditPermissionVO savePermission = vo.getPermissionVO();
savePermission.setCompanyId(rt.getCompanyId());
savePermission.setSiteId(rt.getSiteId());
savePermission.setCreateById(rt.getAccountId());
savePermission.setCreateByName(rt.getAccountName());
StudentEditPermissionVO permissionVO = permissionClient.saveOrUpdate(savePermission);
if(permissionVO != null){
vo.setPermissionVO(permissionVO);
// 保存名片配置信息
CardConfigVO saveCardConfig = vo.getCardConfigVO();
saveCardConfig.setCompanyId(rt.getCompanyId());
saveCardConfig.setSiteId(rt.getSiteId());
saveCardConfig.setUpdateById(rt.getAccountId());
saveCardConfig.setUpdateByName(rt.getAccountName());
CardConfigVO cardConfigVO = cardConfigClient.addConfig(saveCardConfig);
vo.setCardConfigVO(cardConfigVO);
}
return Response.ok(vo);
}
@ApiOperation(value = "获取当前站点-名片信息",response = CardConfigInfoVO.class)
@GetMapping("/get")
public Response<CardConfigInfoVO> getConfigBySiteId(){
CardConfigInfoVO vo = null;
RequestContext rt = ContextHolder.get();
long siteId = rt.getSiteId();
// 保存个人编辑权限
StudentEditPermissionVO permissionVO = permissionClient.getBySiteId(siteId);
if(permissionVO != null){
vo = new CardConfigInfoVO();
vo.setPermissionVO(permissionVO);
// 保存名片配置信息
CardConfigVO cardConfigVO = cardConfigClient.getBySiteId(siteId);
vo.setCardConfigVO(cardConfigVO);
}
return Response.ok(vo);
}
@ApiOperation(value = "检查名片配置是否存在 true 表示该站点存在配置,false表示不存在")
@GetMapping("/check/config/extis")
public Response<Boolean> checkConfigExtis(){
RequestContext rt = ContextHolder.get();
logger.info("上下文信息={}",JSON.toJSONString(rt));
CardConfigVO cardConfigVO = cardConfigClient.getBySiteId(rt.getSiteId());
if(cardConfigVO == null){
return Response.ok(false);
}
return Response.ok(true);
}
@ApiOperation(value = "初始化名片配置信息")
@GetMapping("/init")
public Response<Boolean> initConfig(@RequestParam("siteId") Long siteId){
return Response.ok(cardConfigClient.initConfig(siteId));
}
}
package com.yizhi.application.course.controller;
import com.alibaba.fastjson.JSON;
import com.yizhi.course.application.feign.ClassifyGroupClient;
import com.yizhi.course.application.vo.ClassifyGroupInfoVO;
import com.yizhi.course.application.vo.ClassifyGroupStudentVO;
import com.yizhi.course.application.vo.ClassifyGroupVO;
import com.yizhi.course.application.vo.GroupClassifyItemVO;
import com.yizhi.util.application.domain.Response;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.List;
@RestController
@RequestMapping("/manage/classify/group")
@Api(tags = "管理端-课程分类组", description = "课程分类组接口")
public class ClassifyGroupController {
@Autowired
private ClassifyGroupClient classifyGroupClient;
private static final Logger logger = LoggerFactory.getLogger(ClassifyGroupController.class);
/**
* 保存分类和组的关联数据
* @param classifyGroupInfoVO
* @return
*/
@PostMapping("/save")
@ApiOperation(value = "组关联分类,勾选分类进行保存的接口(作增量保存时候考虑)", response = GroupClassifyItemVO.class)
public Response<ClassifyGroupVO> save(@RequestBody ClassifyGroupInfoVO classifyGroupInfoVO){
List<ClassifyGroupVO> saveObj = classifyGroupClient.save(classifyGroupInfoVO);
return Response.ok(saveObj);
}
@PostMapping("/save/all")
@ApiOperation(value = "组关联分类,勾选分类进行保存的接口(统一一次保存)", response = ClassifyGroupVO.class)
public Response<ClassifyGroupVO> saveAll(@RequestBody ClassifyGroupInfoVO classifyGroupInfoVO){
logger.info("classifyGroupInfoVO=", JSON.toJSONString(classifyGroupInfoVO));
List<ClassifyGroupVO> saveObj = classifyGroupClient.saveAll(classifyGroupInfoVO);
return Response.ok(saveObj);
}
@GetMapping("/get")
@ApiOperation(value = "添加课程分类操作时,对课程分类查看接口(分层级获取回显的分类列表)", response = GroupClassifyItemVO.class)
public Response<GroupClassifyItemVO> get(@ApiParam(name = "id", value = "课程分类组id", required = true) @RequestParam("id") Long id,
@ApiParam(name = "classifyId", value = "点击的课程类型id") @RequestParam(value = "classifyId" ,required = false) Long classifyId,
@ApiParam(name = "layer", value = "点击分类以后,传入要数据要渲染的层级(该情况出现1的情况。2表示2级;3表示3级") @RequestParam(value = "layer",required = false) Integer layer) {
List<GroupClassifyItemVO> infoData = classifyGroupClient.get(id, classifyId, layer);
return Response.ok(infoData);
}
@GetMapping("/get/select/classifyIds")
@ApiOperation(value = "添加课程分类操作时,对课程分类查看接口,返回勾选的分类ids(统一返回)")
public Response<Long> getSelect(@ApiParam(name = "id", value = "课程分类组id", required = true) @RequestParam("id") Long id) {
List<Long> infoData = classifyGroupClient.getSelectIds(id);
return Response.ok(infoData);
}
@ApiOperation(value = "管理端,返回选择的分类信息列表")
@GetMapping("/get/select/classify")
public Response<ClassifyGroupStudentVO> view(
@ApiParam(name = "id", value = "根据分类组的id获取关联的分类详细信息(平铺课程分类信息)", required = true) @RequestParam(name = "id") Long id,
@ApiParam(name = "keyName", value = "分类名模糊搜索", required = false) @RequestParam(name = "keyName",required = false) String keyName){
//return Response.ok(classifyGroupInfoClient.view(id));
return Response.ok(classifyGroupClient.manageView(id,keyName));
}
}
package com.yizhi.application.course.controller;
import com.baomidou.mybatisplus.plugins.Page;
import com.yizhi.core.application.enums.InternationalEnums;
import com.yizhi.application.tools.PageTools;
import com.yizhi.core.application.context.ContextHolder;
import com.yizhi.core.application.context.RequestContext;
import com.yizhi.course.application.feign.ClassifyGroupInfoClient;
import com.yizhi.course.application.vo.ClassifyGroupInfoVO;
import com.yizhi.course.application.vo.domain.ClassifyGroupInfoEntityVo;
import com.yizhi.site.application.feign.PortalManageFeignClients;
import com.yizhi.site.application.vo.domain.PortalNavigateVo;
import com.yizhi.util.application.domain.Response;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.CollectionUtils;
import org.springframework.web.bind.annotation.*;
import java.util.List;
import java.util.Objects;
@RestController
@RequestMapping("/manage/classify/group/info")
@Api(tags = "管理端-课程分类组基本信息(除关联分类id)", description = "课程分类组基本信息")
public class ClassifyGroupInfoController {
@Autowired
private ClassifyGroupInfoClient classifyGroupInfoClient;
@Autowired
private PortalManageFeignClients portalManageFeignClients;
@PostMapping("/save")
@ApiOperation(value = "保存有id(更新没有id)", response = ClassifyGroupInfoEntityVo.class)
public Response<ClassifyGroupInfoEntityVo> save(@RequestBody ClassifyGroupInfoEntityVo classifyGroupInfo){
ClassifyGroupInfoEntityVo addStatus = classifyGroupInfoClient.save(classifyGroupInfo);
if(Objects.isNull(addStatus)){
return Response.fail(InternationalEnums.CLASSIFYGROUPINFOCONTROLLER1.getCode());
}
return Response.ok(addStatus);
}
@GetMapping("/list")
@ApiOperation(value = "获取分类组的列表信息(可增加状态【status】条件指定", response = ClassifyGroupInfoEntityVo.class)
public Response<ClassifyGroupInfoEntityVo> List(
@ApiParam(name = "pageNo", value = "分页的页码", required = true) @RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo,
@ApiParam(name = "pageSize", value = "分页每页的条数", required = true) @RequestParam(name = "pageSize", defaultValue = "20") Integer pageSize,
@ApiParam(name = "status", value = "状态 -1草稿,0 下架,1上架(可选参数)") @RequestParam(name="status", required = false ) Integer status){
Page<ClassifyGroupInfoEntityVo> data = classifyGroupInfoClient.list(pageNo, pageSize, status);
return Response.ok(PageTools.convertPage(data));
}
@GetMapping("/list/all")
@ApiOperation(value = "获取当前用户访问站点下的全部分类组基本信息(例如提供给首页配置分类组的关联选择使用)", response = ClassifyGroupInfoEntityVo.class)
public Response<ClassifyGroupInfoEntityVo> listAll(){
// 上下文下信息
RequestContext rc = ContextHolder.get();
return Response.ok(classifyGroupInfoClient.listAll(rc.getCompanyId(),rc.getSiteId()));
}
@GetMapping("/get")
@ApiOperation(value = "根据课程分类组的id获取分类组的基本信息", response = ClassifyGroupInfoEntityVo.class)
public Response<ClassifyGroupInfoEntityVo> get(
@ApiParam(name = "id", value = "要查看的分类组的id", required = true) @RequestParam(name = "id") Long id){
return Response.ok(classifyGroupInfoClient.get(id));
}
@GetMapping("/delete")
public Response<Boolean> delete(
@ApiParam(name = "id", value = "要删除的分类组的id", required = true) @RequestParam(name = "id") Long id){
RequestContext rc = ContextHolder.get();
List<PortalNavigateVo> data = portalManageFeignClients.getNavigateListByRelationId(rc.getSiteId(),id);
if(CollectionUtils.isEmpty(data)){
return Response.ok(classifyGroupInfoClient.delete(id));
}else {
return Response.fail(InternationalEnums.CLASSIFYGROUPINFOCONTROLLER2.getCode());
}
}
}
package com.yizhi.application.course.controller;
import com.baomidou.mybatisplus.plugins.Page;
import com.yizhi.assignment.application.vo.entity.Comment;
import com.yizhi.course.application.feign.CommClient;
import com.yizhi.course.application.feign.CommentClient;
import com.yizhi.course.application.vo.PageCommentVo;
import com.yizhi.course.application.vo.domain.CommentEntityVo;
import com.yizhi.course.application.vo.domain.ReplyEntityVo;
import com.yizhi.util.application.domain.Response;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
/**
* 评论 前端控制器
*
* @author Fairyland
*
*/
@Api(tags = "管理端-课程评论", description = "评论接口")
@RestController
@RequestMapping("/manage/comment")
public class CommentController {
private static final Logger logger = LoggerFactory.getLogger(CommentController.class);
@Autowired
CommClient commClient;
@Autowired
CommentClient commentClient;
@ApiOperation(value = "根据课程id获取评论列表(分页查询)", response = PageCommentVo.class)
@GetMapping("/list")
public Response getCommentList(
@ApiParam(name = "courseId", value = "课程id") @RequestParam(name = "courseId") Long courseId,
@ApiParam(name = "courseName", value = "课程名称") @RequestParam(name = "courseName") String courseName,
@RequestParam(name = "commentator", required = false) String commentator,
@RequestParam(name = "status", required = false) Integer status,
@ApiParam(name = "pageNo", value = "跳转页数,默认第一页") @RequestParam(name = "pageNo", defaultValue = "1", required = false) Integer pageNo,
@ApiParam(name = "pageSize", value = "每页条数,默认20条") @RequestParam(name = "pageSize", defaultValue = "10", required = false) Integer pageSize) {
PageCommentVo pageCommentVo = commClient.list(courseId, commentator, status, pageNo, pageSize);
pageCommentVo.setCourseName(courseName);
return Response.ok(pageCommentVo);
}
@ApiOperation(value = "根据课程id获取评论列表(分页查询)", response = ReplyEntityVo.class)
@GetMapping("/reply/list")
public Response getCommentList(
@ApiParam(name = "commmentId", value = "课程id") @RequestParam(name = "commmentId") Long commmentId,
@ApiParam(name = "pageNo", value = "跳转页数,默认第一页") @RequestParam(name = "pageNo", defaultValue = "1", required = false) Integer pageNo,
@ApiParam(name = "pageSize", value = "每页条数,默认20条") @RequestParam(name = "pageSize", defaultValue = "10", required = false) Integer pageSize) {
Page<ReplyEntityVo> page = commClient.replyList(commmentId, pageNo, pageSize);
return Response.ok(page);
}
@ApiOperation(value = "根据Comment评论id审核该评论,审核确定后 评论会从列表消失 连评论下的回复一起消失")
@PostMapping("/auditComment")
public Response<String> auditComment(@ApiParam(name = "comment", value = "评论") @RequestBody CommentEntityVo comment) {
String result = commentClient.auditComment(comment);
if (!StringUtils.isEmpty(result)) {
if ("success".equals(result)) {
return Response.ok();
} else {
return Response.fail();
}
}
return Response.fail();
}
@ApiOperation(value = "根据reply回复评论id审核该评论,审核确定后 评论会从列表消失")
@PostMapping("/auditReply")
public Response<String> auditreply(@ApiParam(name = "id", value = "评论id") @RequestBody ReplyEntityVo reply
) {
String result = commentClient.auditreply(reply);
if (!StringUtils.isEmpty(result)) {
if ("success".equals(result)) {
return Response.ok();
} else {
return Response.fail();
}
}
return Response.fail();
}
// @ApiOperation(value="点赞")
// @PostMapping("thumbsUp/save")
// public Response<String> saveThumbsUp(
// @RequestBody ThumbsUp thumbsUp
// ){
// Boolean f = commClient.saveThumbsUp(thumbsUp);
// if (f) {
// return Response.ok();
// }else {
// return Response.fail();
// }
//
// }
@ApiOperation(value = "上架")
@GetMapping("/up")
public Response<String> up(@RequestParam("id") Long id, @RequestParam("type") Integer type) {
Boolean up = commClient.up(id, type);
if (up) {
return Response.ok();
} else {
return Response.fail();
}
}
@ApiOperation(value = "下架")
@GetMapping("/down")
public Response<String> down(@RequestParam("id") Long id, @RequestParam("type") Integer type) {
Boolean up = commClient.down(id, type);
if (up) {
return Response.ok();
} else {
return Response.fail();
}
}
@ApiOperation(value = "评论信息导出")
@GetMapping("/list/export")
public Response<String> export(
@ApiParam(name = "courseId", value = "课程id") @RequestParam(name = "courseId") Long courseId,
@ApiParam(name = "courseName", value = "课程名称") @RequestParam(name = "courseName") String courseName,
@RequestParam(name = "commentator", required = false) String commentator,
@RequestParam(name = "status", required = false) Integer status) {
return Response.ok(commClient.export(courseId, courseName, commentator, status).get("result").toString());
}
}
package com.yizhi.application.course.controller;
import com.yizhi.course.application.feign.CourseStatusSyncClient;
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;
/**
* 课程同步
*/
@RestController
@RequestMapping("/manage/course/sync")
public class CourseStatusSyncController {
@Autowired
private CourseStatusSyncClient courseStatusSyncClient;
/**
* 培训项目完成到课程
* @return
*/
@GetMapping("/sendFinishStatus")
public String TrainningFinishToCourse(){
courseStatusSyncClient.TrainningFinishToCourse();
return "ok";
}
}
package com.yizhi.application.course.controller;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import com.baomidou.mybatisplus.plugins.Page;
import com.yizhi.application.course.vo.CourseVO;
import com.yizhi.core.application.context.ContextHolder;
import com.yizhi.course.application.feign.LessonClient;
import com.yizhi.course.application.vo.MaterialManageDetailsVo;
import com.yizhi.course.application.vo.MaterialManageVo;
import com.yizhi.course.application.vo.MaterialStateUpdateVo;
import com.yizhi.course.application.vo.NoPassReason;
import com.yizhi.system.application.system.remote.AccountClient;
import com.yizhi.system.application.vo.AccountVO;
import com.yizhi.util.application.constant.ReturnCode;
import com.yizhi.util.application.domain.Response;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang3.tuple.MutablePair;
import org.apache.commons.lang3.tuple.Pair;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
@Api(tags="做课接口",description="LessonManageController")
@RestController
@RequestMapping("/manage")
public class LessonManageController {
private static final Logger logger=LoggerFactory.getLogger(LessonManageController.class);
@Autowired
private LessonClient lessonClient;
@Autowired
private AccountClient accountClient;
@ApiOperation(value="后台做课列表",notes="后台做课列表")
@GetMapping("/lesson/list")
public Response<MaterialManageVo> getLessonList(@ApiParam(name="name",value="模糊查询做课名称",required=false) @RequestParam(name = "name", required = false) String name,
@ApiParam(name="commitName",value="提交人",required=false) @RequestParam(name = "commitName", required = false) String commitName,
@ApiParam(name="auditorName",value="审批人",required=false) @RequestParam(name = "auditorName", required = false) String auditorName,
@ApiParam(name="state",value="状态 0已撤回 1未提交 2审核中 3已通过 4未通过 5删除",required=false) @RequestParam(name = "state", required = false) Integer state,
@ApiParam(name = "pageNo", value = "要跳转的页数",required=false) @RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo,
@ApiParam(name = "pageSize", value = "每页条数,默认:20", required = false) @RequestParam(name = "pageSize", defaultValue = "20") Integer pageSize) {
try {
Long orgId= ContextHolder.get().getOrgId();
Long companyId=ContextHolder.get().getCompanyId();
//提交人id
List<Long> listCommintIdList=new ArrayList<Long>();
if(commitName!=null) {
List<AccountVO> list=accountClient.fuzzySearchAccountByName(commitName,companyId);
if(!CollectionUtils.isEmpty(list)) {
for (int i = 0; i <list.size(); i++) {
listCommintIdList.add(list.get(i).getId());
}
}
}
//评阅人
List<Long> listAuditorIdList=new ArrayList<Long>();
if(auditorName!=null) {
List<AccountVO> list2=accountClient.fuzzySearchAccountByName(auditorName, companyId);
if(!CollectionUtils.isEmpty(list2)) {
for (int i = 0; i <list2.size(); i++) {
listAuditorIdList.add(list2.get(i).getId());
}
}
}
//返回会的数据
Page<MaterialManageVo> pageList=lessonClient.getLessonList(name, listCommintIdList, listAuditorIdList, state, pageNo, pageSize,orgId);
Page<MaterialManageVo> pageList2=new Page<MaterialManageVo>();
if(pageList!=null) {
List<MaterialManageVo> list=pageList.getRecords();
for (int i = 0; i < list.size(); i++) {
Long accountId=list.get(i).getAccountId();
list.get(i).setAccountName(accountClient.findById(accountId).getName());
Long auditorId=list.get(i).getAuditorId();
list.get(i).setAuditorName(accountClient.findById(auditorId).getName());
}
pageList2.setRecords(list);
}
if(pageList2!=null) {
List<MaterialManageVo> listRecords=pageList2.getRecords();
Map<String,Integer> map=new HashMap<String,Integer>();
map.put("pageSize", pageSize);
map.put("pageNo", pageNo);
map.put("total", pageList.getTotal());
Pair<List<MaterialManageVo>,Map<String,Integer>> pair=new MutablePair(listRecords, map);
return Response.ok(pair);
}
else {
return Response.fail(ReturnCode.RESOURCE_NOT_FOUND.getCode(),ReturnCode.RESOURCE_NOT_FOUND.getMsg());
}
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
return Response.fail(ReturnCode.SERVICE_UNAVAILABLE.getCode(),ReturnCode.SERVICE_UNAVAILABLE.getMsg());
}
}
@ApiOperation(value="根据素材id查看单个做课详情",notes="后台单个做课详情")
@GetMapping("/lesson/details")
public Response<MaterialManageDetailsVo> getLesson(@ApiParam(name="id",value="id主键",required=true)@RequestParam(name="id",required=true)Long id){
try {
MaterialManageDetailsVo materialManageDetailsVo=lessonClient.getLesson(id);
if(materialManageDetailsVo!=null){
return Response.ok(materialManageDetailsVo);
}
else {
return Response.ok(ReturnCode.RESOURCE_NOT_FOUND);
}
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
return Response.fail(ReturnCode.SERVICE_UNAVAILABLE.getCode(),ReturnCode.SERVICE_UNAVAILABLE.getMsg());
}
}
@ApiOperation(value="根据素材id审核/更改状态",notes="审核/更改状态")
@PostMapping("/update/state")
public Response<String> updateState(@RequestBody MaterialStateUpdateVo materialStateUpdateVo){
try {
materialStateUpdateVo.setContext(ContextHolder.get());
Boolean x=lessonClient.updateStateManage(materialStateUpdateVo);
if(x) {
return Response.ok(ReturnCode.SUCCESS);}
else {
return Response.fail(ReturnCode.UPDATE_FAIL.getCode(),ReturnCode.UPDATE_FAIL.getMsg());}
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
return Response.fail(ReturnCode.SERVICE_UNAVAILABLE.getCode(),ReturnCode.SERVICE_UNAVAILABLE.getMsg());
}
}
@ApiOperation(value="根据素材id审核/更改状态并且得到下一个id",notes="根据素材id审核/更改状态并且得到下一个id")
@PostMapping("/update/state/getNextId")
public Response<String> updateStateGetNextId(@RequestBody MaterialStateUpdateVo materialStateUpdateVo){
try {
Long x=lessonClient.updateStateGetNextId(materialStateUpdateVo);
if(x!=null) {
return Response.ok(x);}
else {
return Response.ok(ReturnCode.RESOURCE_NOT_FOUND);}
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
return Response.fail(ReturnCode.SERVICE_UNAVAILABLE.getCode(),ReturnCode.SERVICE_UNAVAILABLE.getMsg());
}
}
@ApiOperation(value="通过做课id查看不通过的原因",notes="查看不通过的原因")
@GetMapping("/nopass/reason")
public Response<String> updateState(@ApiParam(name="lessonId",value="做课id",required=true) @RequestParam(name = "lessonId", required = true) Long lessonId,
@ApiParam(name = "pageNo", value = "要跳转的页数",required=false) @RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo,
@ApiParam(name = "pageSize", value = "每页条数,默认:20", required = false) @RequestParam(name = "pageSize", defaultValue = "20") Integer pageSize){
try {
List<NoPassReason> list=lessonClient.noPassReason(lessonId, pageNo, pageSize);
List<CourseVO> listCourseVO=new ArrayList<>();
if(!CollectionUtils.isEmpty(list)) {
for (int i = 0; i < list.size(); i++) {
NoPassReason noPassReason=list.get(i);
CourseVO courseVO=new CourseVO();
BeanUtils.copyProperties(noPassReason, courseVO);
courseVO.setAuditorName(accountClient.findById(courseVO.getAuditorId()).getFullName());
listCourseVO.add(courseVO);
}}
if(listCourseVO!=null){
return Response.ok(listCourseVO);
}
else {
return Response.ok(ReturnCode.RESOURCE_NOT_FOUND);
}
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
return Response.fail(ReturnCode.SERVICE_UNAVAILABLE.getCode(),ReturnCode.SERVICE_UNAVAILABLE.getMsg());
}
}
}
package com.yizhi.application.course.controller;
import com.baomidou.mybatisplus.plugins.Page;
import com.yizhi.core.application.context.ContextHolder;
import com.yizhi.core.application.context.RequestContext;
import com.yizhi.course.application.feign.ProjectCourseClient;
import com.yizhi.course.application.vo.ProjectCourseVo;
import com.yizhi.course.application.vo.ProjectSeachCourseVo;
import com.yizhi.course.application.vo.domain.ProjectCourseEntityVo;
import com.yizhi.util.application.domain.Response;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.*;
/**
* <p>
* 课程 前端控制器
* </p>
*
* @author wenjunlong
* @since 2018-03-19
*/
@Api(tags="管理端-课程培训项目",description="项目课程相关接口")
@RestController
@RequestMapping("/manage/project")
public class ProjectCourseController {
@Autowired
ProjectCourseClient projectCourseClient;
@GetMapping("/course/list")
@ApiOperation(value = "项目未关联课程分页查询", notes = "返回分页结果集",response = ProjectCourseVo.class)
public Response list(
@ApiParam(name = "id", value = "培训项目id", required = true) @RequestParam(name = "id", required = false) Long id,
@ApiParam(name = "name", value = "课程名称或标签", required = false) @RequestParam(name = "name", required = false) String name,
@ApiParam(name = "classifyId", value = "分类id ", required = false) @RequestParam(name = "classifyId", required = false) Long classifyId,
@ApiParam(name = "pageNo", value = "跳转页数,默认第一页", required = true) @RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo,
@ApiParam(name = "pageSize", value = "每页条数,默认20条", required = true) @RequestParam(name = "pageSize", defaultValue = "20") Integer pageSize) {
ProjectSeachCourseVo projectSeachCourseVo = new ProjectSeachCourseVo();
projectSeachCourseVo.setName(name);
projectSeachCourseVo.setTrainingProjectId(id);
projectSeachCourseVo.setClassifyId(classifyId);
projectSeachCourseVo.setPageNo(pageNo);
projectSeachCourseVo.setPageSize(pageSize);
RequestContext requestContext = ContextHolder.get();
if (StringUtils.isEmpty(requestContext)) {
projectSeachCourseVo.setCompanyId(0L);
}else{
if (requestContext.isAdmin()) {
projectSeachCourseVo.setCompanyId(requestContext.getCompanyId());
}else{
projectSeachCourseVo.setSiteId(requestContext.getSiteId());
if (requestContext.getOrgIds()!=null) {
}
}
}
Page<ProjectCourseVo> page = projectCourseClient.projectList(projectSeachCourseVo);
return Response.ok(page);
}
@PostMapping("/save")
@ApiOperation(value = "项目和课程关联", notes = "返回操作成功与否")
public Response<String> save(@RequestBody ProjectCourseEntityVo projectCourse) {
Boolean f = projectCourseClient.projectCourseSave(projectCourse);
if (f) {
return Response.ok("关联成功");
} else {
return Response.ok("关联失败");
}
}
@PostMapping("/delete")
@ApiOperation(value = "去掉项目和课程关联", notes = "返回操作成功与否")
public Response<String> delete(@RequestBody ProjectCourseEntityVo projectCourse) {
Boolean f = projectCourseClient.projectCourseDelete(projectCourse);
if (f) {
return Response.ok("删除关联成功");
} else {
return Response.ok("删除关联失败");
}
}
}
package com.yizhi.application.course.controller;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.yizhi.course.application.feign.MaterialClient;
import com.yizhi.course.application.vo.AudioVideoVO;
import com.yizhi.course.application.vo.domain.MaterialEntityVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@Api(tags = "管理端-课程完成记录", description = "课程完成记录接口")
@RestController
@RequestMapping("/manage/public/recorde")
public class RecordeController {
private static final Logger LOG = LoggerFactory.getLogger(RecordeController.class);
@Autowired
MaterialClient materialClient;
public static Map<String, Object> parseJSON2Map(String jsonStr) throws Exception {
Map<String, Object> map = new HashMap<String, Object>();
JSONObject json = JSONObject.parseObject(jsonStr);
for (Object k : json.keySet()) {
Object v = json.get(k);
if (v instanceof JSONArray) {
List<Map<String, Object>> list = new ArrayList<Map<String, Object>>();
JSONArray json2 = JSONArray.parseArray(v.toString());
for (int i = 0; i < json2.size(); i++) {
// 遍历 jsonarray 数组,把每一个对象转成 json 对象
JSONObject job = json2.getJSONObject(i);
list.add(parseJSON2Map(job.toString()));
}
map.put(k.toString(), list);
} else {
map.put(k.toString(), v);
}
}
return map;
}
@ApiOperation(value = "学习记录日志解析 保存到学习记录表中")
@PostMapping("/analysis")
public void analysis(@RequestBody String jsonStr) {
LOG.info("回调事件:" + jsonStr);
try {
if (!StringUtils.isEmpty(jsonStr)) {
Map<String, Object> playStr = parseJSON2Map(jsonStr);
if ("TranscodeComplete".equals(playStr.get("EventType")) && "success".equals(playStr.get("Status"))) {
//根据videoid查询相应的实体进行 视频地址更新
if (playStr.containsKey("VideoId")) {
AudioVideoVO video = materialClient.videoView(playStr.get("VideoId").toString());
List<Map<String, Object>> playInfoList = (List<Map<String, Object>>) playStr.get("StreamInfos");
LOG.info("播放list" + playInfoList);
Integer duration = 0;
if (null != video) {
for (int i = 0; i < playInfoList.size(); i++) {
// 遍历 jsonarray 数组,把每一个对象转成 json 对象
Map<String, Object> job = playInfoList.get(i);
if ("FD".equals(job.get("Definition").toString())) {
video.setFdUrl(job.get("FileUrl").toString());
duration = Double.valueOf(job.get("Duration").toString()).intValue();
} else if ("LD".equals(job.get("Definition").toString())) {
video.setLdUrl(job.get("FileUrl").toString());
} else {
video.setSdUrl(job.get("FileUrl").toString());
}
}
int hour = duration / 3600;
int minute = (duration - hour * 3600) / 60;
int second = (duration - hour * 3600 - minute * 60);
MaterialEntityVo material = materialClient.view(video.getMaterialId());
if (null != material) {
material.setTextHour(hour);
material.setTextMinute(minute);
material.setTextSecond(second);
}
Map<String, Object> map = new HashMap<>();
map.put("material", material);
map.put("video", video);
materialClient.videoUpdate(map);
}
}
}
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
package com.yizhi.application.course.util;
public class BatchUploadUtils {
private String active;
private String localFile;
private String objectName;
/**
* 配置信息
* @param active
* @param localFile
* @param objectName
*/
public BatchUploadUtils(String active,String localFile,String objectName){
this.active = active;
this.localFile = localFile;
this.objectName = objectName;
}
public String getActive() {
return active;
}
public String getLocalFile() {
return localFile;
}
public String getObjectName() {
return objectName;
}
/**
* 上传文件
* @param isSimpleUpload 是否简单上传
* @return
*/
public String upload(boolean isSimpleUpload){
String ret ="";
try {
if(isSimpleUpload){
ret = UploadOSSUtils.simpleUpload(this.localFile,this.objectName,active);
}else{
try {
ret = UploadOSSUtils.resumingUpload(this.localFile,this.objectName,active);
} catch (Throwable throwable) {
System.out.println(this.localFile+"上传OSS异常 。objectName= "+this.objectName);
throwable.printStackTrace();
}
}
} catch (Exception e) {
System.out.println(this.localFile+"上传OSS异常 。objectName="+this.objectName);
System.out.println(e);
ret = "";
}
return ret;
}
}
package com.yizhi.application.course.util;
import java.io.*;
import java.util.List;
import java.util.concurrent.*;
import java.util.function.Consumer;
import java.util.stream.Collectors;
public class CommandUtils {
private static class StreamGobbler implements Runnable {
private InputStream inputStream;
private Consumer<String> consumer;
public StreamGobbler(InputStream inputStream, Consumer<String> consumer) {
this.inputStream = inputStream;
this.consumer = consumer;
}
@Override
public void run() {
new BufferedReader(new InputStreamReader(inputStream)).lines().forEach(consumer);
}
}
public static void runtimeExec() throws IOException,InterruptedException {
boolean isWindows = System.getProperty("os.name").toLowerCase().startsWith("windows");
String homeDirectory = System.getProperty("user.home");
Process process;
if (isWindows) {
process = Runtime.getRuntime()
.exec(String.format("cmd.exe /c dir %s", homeDirectory));
} else {
process = Runtime.getRuntime()
.exec(String.format("sh -c ls %s", homeDirectory));
}
StreamGobbler streamGobbler = new StreamGobbler(process.getInputStream(), System.out::println);
Executors.newSingleThreadExecutor().submit(streamGobbler);
int exitCode = process.waitFor();
assert exitCode == 0;
}
public static void processBuilderExec() throws IOException,InterruptedException,ExecutionException,TimeoutException {
// 多线程
ExecutorService pool = Executors.newSingleThreadExecutor();
ProcessBuilder processBuilder = new ProcessBuilder();
boolean isWindows = System.getProperty("os.name").toLowerCase().startsWith("windows");
ProcessBuilder builder = new ProcessBuilder();
if (isWindows) {
builder.command("cmd.exe", "/c", "dir");
} else {
builder.command("sh", "-c", "ls");
}
// 改变目录
//builder.directory(new File(System.getProperty("user.home")));
Process process = builder.start();
ProcessReadTask task = new ProcessReadTask(process.getInputStream());
Future<List<String>> future = pool.submit(task);
List<String> result = future.get(5, TimeUnit.SECONDS);
for (String s : result) {
System.out.println(s);
}
pool.shutdown();
}
private static class ProcessReadTask implements Callable<List<String>> {
private InputStream inputStream;
public ProcessReadTask(InputStream inputStream) {
this.inputStream = inputStream;
}
@Override
public List<String> call() {
return new BufferedReader(new InputStreamReader(inputStream))
.lines().collect(Collectors.toList());
}
}
/**
* 执行命令
* @param parameter
* @return
* @throws IOException
*/
public static String exec(String... parameter) throws IOException {
StringBuilder stringBuilder = new StringBuilder();
ProcessBuilder processBuilder = new ProcessBuilder();
//processBuilder.command("cmd.exe", "/c", "dir");
//processBuilder.directory(new File("C:\\users"));
processBuilder.command(parameter);
Process process = processBuilder.start();
// can also run the java file like this// processBuilder.command("java", "Hello");
try(BufferedReader reader = new BufferedReader(new InputStreamReader(process.getInputStream()));) {
String line;
while ((line = reader.readLine()) != null) {
stringBuilder.append(line);
}
int exitCode = process.waitFor();
System.out.println("Exited with error code : " + exitCode);
} catch (IOException e) {
e.printStackTrace();
} catch (InterruptedException e) {
e.printStackTrace();
}
return stringBuilder.toString();
}
}
/**
* FileName: DocPagesAsynchronizationDeal
* Author: wenjunlong
* Date: 2018/5/30 14:41
* Description: 文档异步解析处理
* History:
* <author> <time> <version> <desc>
* 作者姓名 修改时间 版本号 描述
*/
package com.yizhi.application.course.util;
import com.yizhi.application.course.constant.UtilConstants;
import com.yizhi.core.application.context.TaskContext;
import com.yizhi.core.application.file.task.AbstractDefaultTask;
import com.yizhi.course.application.feign.MaterialClient;
import com.yizhi.course.application.vo.DocPagesVO;
import com.yizhi.course.application.vo.domain.MaterialEntityVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
import java.io.File;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;
/**
* 〈一句话功能简述〉<br>
* 〈文档异步解析处理〉
*
* @author wenjunlong
* @create 2018/5/30
* @since 1.0.0
*/
@Component
public class DocPagesAsynchronizationDeal extends AbstractDefaultTask<String, Map<String, Object>> {
@Value("${ACTIVE}")
public String active;
@Autowired
ScormXMLImporter scormXMLImporter;
@Autowired
UpConvert upConvert;
@Autowired
private MaterialClient materialClient;
@Override
protected String execute(Map<String, Object> stringObjectMap) {
TaskContext taskContext = null;
MaterialEntityVo materialVo = null;
try {
materialVo = (MaterialEntityVo) stringObjectMap.get("material");
// 任务id 任务名字 操作人id 操作时间
taskContext = new TaskContext(System.currentTimeMillis(), materialVo.getName(), materialVo.getCreateById(), new Date(),
materialVo.getSiteId(), materialVo.getCompanyId());
working(taskContext);
String imageDir = upConvert.convert(materialVo.getOriginalFileUrl(), materialVo.getOriginalFile(), UtilConstants.DOC_PATH, 200, 0, UtilConstants.OPENOFFICE_PATH);
File dir = new File(imageDir);
File[] files = dir.listFiles();
String uploadFile;
String key;
List<DocPagesVO> docPages = new ArrayList<DocPagesVO>();
if (files.length > 0) {
for (File file : files) {
uploadFile = file.getAbsolutePath();
key = materialVo.getOriginalFile().substring(0, materialVo.getOriginalFile().lastIndexOf(".")) + "/" + System.currentTimeMillis()+"/"+file.getName();
/*if (materialVo.getDisplayMark()==1) {
String markImg = MarkImageUtils.markImageBySingleText(uploadFile, UtilConstants.DOC_PATH,file.getName().substring(0, file.getName().lastIndexOf(".")), "png", new Color(0, 0, 0,20), materialVo.getWord(), -45);
if (!markImg.equals("添加文字水印失败")) {
uploadFile = markImg;
}
taskDetail(taskContext.getTaskId(),markImg);
}*/
String result = OssUpload.upload(uploadFile, key,active);
DocPagesVO docPages1 = new DocPagesVO();
docPages1.setDocPage(Integer.parseInt(file.getName().substring(0, file.getName().lastIndexOf("."))));
docPages1.setImageUrl(result);
docPages.add(docPages1);
}
}
stringObjectMap.put("docPages", docPages);
if (stringObjectMap.containsKey("action")) {
if ("create".equals(stringObjectMap.get("action").toString())) {
materialClient.insert(stringObjectMap);
} else {
materialClient.update(stringObjectMap);
}
}
success(taskContext, materialVo.getName() + "解析成功!", null);
} catch (Exception e) {
e.printStackTrace();
fail(taskContext, materialVo.getOriginalFileUrl() + "解析失败:"+e.getMessage());
}
return null;
}
}
package com.yizhi.application.course.util;
import com.alibaba.fastjson.JSON;
import com.yizhi.core.application.exception.FileReadException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.*;
import java.net.HttpURLConnection;
import java.net.URL;
public class DownLoad {
private static final Logger logger= LoggerFactory.getLogger(DownLoad.class);
public String downLoadFromUrl(String urlStr,String fileName,String outputFilePath){
File file = null;
// FileInfo fileInfo = new FileInfo();
try {
URL url = new URL(urlStr);
HttpURLConnection conn = (HttpURLConnection)url.openConnection();
//防止屏蔽程序抓取而返回403错误
conn.setRequestProperty("User-Agent", "Mozilla/4.0 (compatible; MSIE 5.0; Windows NT; DigExt)");
conn.setRequestProperty("Charsert", "UTF-8");
conn.setRequestProperty("Accept-Charset", "UTF-8");
//得到输入流
InputStream inputStream = conn.getInputStream();
//获取自己数组
byte[] buffer = new byte[1024];
int len = 0;
ByteArrayOutputStream bos = new ByteArrayOutputStream();
while((len = inputStream.read(buffer)) != -1) {
bos.write(buffer, 0, len);
}
bos.close();
byte[] getData = bos.toByteArray();
//文件保存位置
File saveDir = new File(outputFilePath);
if(!saveDir.exists()){
saveDir.mkdirs();
}
file = new File(saveDir+File.separator+fileName);
FileOutputStream fos = new FileOutputStream(file);
fos.write(getData);
if(fos!=null){
fos.close();
}
if(inputStream!=null){
inputStream.close();
}
} catch (Exception e) {
logger.info("fileName={},outputFilePath={}",fileName,outputFilePath);
logger.info("urlStr={},异常={}",urlStr,JSON.toJSONString(e));
throw new FileReadException();
}
return file.getAbsolutePath();
}
/**
* 从输入流中获取字节数组
* @param inputStream
* @return
* @throws IOException
*/
public static byte[] readInputStream(InputStream inputStream) throws IOException {
byte[] buffer = new byte[1024];
int len = 0;
ByteArrayOutputStream bos = new ByteArrayOutputStream();
while((len = inputStream.read(buffer)) != -1) {
bos.write(buffer, 0, len);
}
bos.close();
return bos.toByteArray();
}
}
package com.yizhi.application.course.util;
import com.alibaba.fastjson.JSON;
import com.yizhi.core.application.context.TaskContext;
import com.yizhi.core.application.file.constant.FileConstant;
import com.yizhi.core.application.file.task.AbstractDefaultTask;
import com.yizhi.course.application.vo.domain.MaterialEntityVo;
import com.yizhi.system.application.system.remote.SiteClient;
import com.yizhi.system.application.vo.SiteVO;
import com.yizhi.util.application.date.DateUtil;
import org.apache.poi.hssf.usermodel.HSSFCell;
import org.apache.poi.hssf.usermodel.HSSFRow;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.ss.util.CellRangeAddress;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;
@Component
public class MaterialExport extends AbstractDefaultTask<String, Map<String,Object>> {
private static final Logger LOGGER = LoggerFactory.getLogger(MaterialExport.class);
@Value("${ACTIVE}")
public String active;
@Autowired
SiteClient siteClient;
@Override
protected String execute(Map<String, Object> map) {
LOGGER.info("素材导出异步处理开始");
String upload = null;
Long companyId = (Long) map.get("companyId");
Long siteId = (Long) map.get("siteId");
String siteName = "素材库素材下载_下载结果数据";
Long taskId = System.currentTimeMillis();
Long accountId = (Long) map.get("accountId");
String taskName = "素材导出任务";
Date submitTime = new Date();
List<MaterialEntityVo> list = (List<MaterialEntityVo>) map.get("list");
String[] types = new String[]{"音频","视频","文本","富媒体","Scrom","考试"};
String[] soures = new String[]{"外部采购", "外部定制", "内部定制", "做课"};
List<Long> ids = new ArrayList<>();
ids.add(siteId);
List<SiteVO> siteVOS = siteClient.selectByIds(ids);
if (null != siteVOS && siteVOS.size() > 0) {
siteName = siteVOS.get(0).getName();
}
StringBuffer a=new StringBuffer().append(siteName).append("_").append(taskName);
taskName=a.toString();
//创建任务
//任务id 任务名字 操作人id 操作时间
TaskContext taskContext = new TaskContext(taskId, taskName, Long.valueOf(String.valueOf(accountId)), submitTime, Long.valueOf(String.valueOf(siteId)), Long.valueOf(String.valueOf(companyId)));
working(taskContext);
try {
String[] headers = new String[]{"素材编号", "素材名称", "素材类型", "素材来源", "创建时间", "素材时长"};
StringBuffer fileNameSb = new StringBuffer().append(siteName).append("_").append("素材库导出").append("_").append(System.currentTimeMillis()).append(".xls");
String fileName = fileNameSb.toString();
String path = new StringBuffer().append(FileConstant.SAVE_PATH).append(File.separator).append(fileNameSb).toString();
// String path = new StringBuffer().append("D:\\test").append(File.separator).append(fileNameSb).toString();
File fileDir = new File(path);
if (!fileDir.exists()) {
fileDir.createNewFile();
}
HSSFWorkbook workBook = null;
FileOutputStream os = null;
File file = null;
try {
os = new FileOutputStream(path);
// 创建新的Excel 工作簿
workBook = new HSSFWorkbook();
// 在Excel工作簿中建一工作表,其名为缺省值
HSSFSheet sheet = workBook.createSheet("素材信息");
// 第一行
HSSFRow row = sheet.createRow(0);
CellRangeAddress cra = new CellRangeAddress(0, 0, 0, 5); // 起始行, 终止行, 起始列, 终止列
sheet.addMergedRegion(cra);
HSSFCell cell = row.createCell((short) 0);
cell.setCellValue(map.get("siteName") + "-" + "素材清单" + cn.hutool.core.date.DateUtil.format(submitTime, "yyyyMMddHHmmss"));
row = sheet.createRow(1);
for (int i = 0; i < headers.length; i++) {
row.createCell(i).setCellValue(headers[i]);
}
MaterialEntityVo evo1 = null;
// 填充数据
for (int i = 0; i < list.size(); i++) {
evo1 = list.get(i);
row = sheet.createRow(2 + i);
row.createCell(0).setCellValue(evo1.getCode());
row.createCell(1).setCellValue(evo1.getName());
row.createCell(2).setCellValue(types[evo1.getType()-1]);
row.createCell(3).setCellValue(soures[evo1.getSource()-1]);
row.createCell(4).setCellValue(DateUtil.format(evo1.getCreateTime(),"yyyy-MM-dd HH:mm:ss"));
if (evo1.getTextHour() != null || evo1.getTextMinute() != null || evo1.getTextHour() != null) {
String hour = evo1.getTextHour() == null? "0" : String.valueOf(evo1.getTextHour());
String minute = evo1.getTextMinute() == null? "0" : String.valueOf(evo1.getTextMinute());
String second = evo1.getTextSecond() == null? "0" : String.valueOf(evo1.getTextSecond());
row.createCell(5).setCellValue(hour + "时" + minute + "分" + second + "秒");
} else {
row.createCell(5).setCellValue("--");
}
taskDetail(taskId, "导出数据第+" + i + "+行成功");
}
workBook.write(os);
upload = OssUpload.upload(path, fileName, active);
file = new File(path);
success(taskContext, upload);
System.out.println(upload);
} catch (Exception e1) {
fail(taskContext, upload);
LOGGER.info(JSON.toJSONString(e1));
} finally {
if (os != null) {
os.close();
}
if (workBook != null) {
workBook.close();
}
if (file != null) {
file.delete();
}
}
//阿里云返回url
} catch (IOException e1) {
// TODO Auto-generated catch block
fail(taskContext, upload);
LOGGER.info(JSON.toJSONString(e1));
}
LOGGER.info("素材导出异步处理结束");
return upload;
}
}
package com.yizhi.application.course.util;
import com.yizhi.core.application.file.task.AbstractDefaultTask;
import com.yizhi.course.application.feign.CourseClient;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
/**
* 素材转移
* @author ly
*/
@Component
public class MaterialTransferService extends AbstractDefaultTask<String, Map<String,Object>> {
private static final Logger LOGGER = LoggerFactory.getLogger(MaterialTransferService.class);
@Autowired
CourseClient courseClient;
@Override
protected String execute(Map<String, Object> map) {
List<String> codeList = (ArrayList<String>)map.get("codeList");
Long afterSiteId = Long.valueOf(String.valueOf(map.get("afterSiteId")));
Long beforeSiteId = Long.valueOf(String.valueOf(map.get("beforeSiteId")));
Long companyId = Long.valueOf(String.valueOf(map.get("companyId")));
LOGGER.info("codeList:"+codeList);
LOGGER.info("afterSiteId:"+afterSiteId+";beforeSiteId:"+beforeSiteId+";companyId:"+companyId);
courseClient.updateMaterialData(codeList,afterSiteId,beforeSiteId,companyId);
return null;
}
}
package com.yizhi.application.course.util;
import org.artofsolving.jodconverter.OfficeDocumentConverter;
import org.artofsolving.jodconverter.office.DefaultOfficeManagerConfiguration;
import org.artofsolving.jodconverter.office.OfficeManager;
import org.springframework.util.StringUtils;
import java.io.File;
public class OfficeToPdf {
/**
* 使Office2003-2007全部格式的文档(.doc|.docx|.xls|.xlsx|.ppt|.pptx) 转化为pdf文件
* @param inputFilePath 源文件路径,如:"C:/Users/phone/Desktop/新建文件夹 (3)/22.docx"
* @return
*/
public File openOfficeToPDF(String filePath,String outputFilePath,String getofficeHome) {
return office2pdf(filePath,outputFilePath,getofficeHome);
}
/**
* 根据插件安装路径连接OpenOffice.org 并且启动OpenOffice.org 启动插件
* officeHome的路径 E:\\pdf\\office\\OpenOfficePortable\\App\\openoffice
* @return
*/
public OfficeManager getOfficeManager(String getofficeHome) {
DefaultOfficeManagerConfiguration config = new DefaultOfficeManagerConfiguration();
// 设置OpenOffice.org 4的安装目录
config.setOfficeHome(getofficeHome);
// 启动OpenOffice的服务
OfficeManager officeManager = config.buildOfficeManager();
officeManager.start();
return officeManager;
}
/**
* 转换文件
* @param inputFile E:\png\简历.docx
* @param outputFilePath E:\png
* @param filePath E:\png\简历.docx
* @param converter
*/
public File converterFile(File inputFile,String outputFilePath,String filePath,OfficeDocumentConverter converter) {
String outputFileName=inputFile.getName(); //输出文件名字的确切路径
String name=outputFileName.substring(0, outputFileName.lastIndexOf(".")); //输出文件名字
File outputFile = new File(outputFilePath+"\\"+name+".pdf");
converter.convert(inputFile, outputFile);//转换
return outputFile;
}
/**
* 使Office2003-2007全部格式的文档(.doc|.docx|.xls|.xlsx|.ppt|.pptx) 转化为pdf文件
* @param inputFilePath 源文件路径,如:"D:/论坛.docx"
* @param outputFilePath 目标文件路径,如:"D:/论坛.pdf"
* @return
*/
public File office2pdf(String filePath,String outputFilePath,String officeHome) {
OfficeManager officeManager = null;
try {
if (StringUtils.isEmpty(filePath)) {
return null;
}
File inputFile = new File(filePath); //需要转换的文件
//转换后的文件路径
String fileName=inputFile.getName(); //转换前的文件名字
if (!inputFile.exists()) {
return null;
}
//获取OpenOffice的安装路劲
officeManager = getOfficeManager(officeHome);
//连接OpenOffice
OfficeDocumentConverter converter=new OfficeDocumentConverter(officeManager);
//转换并返回转换后的文件对象
return converterFile(inputFile,outputFilePath,filePath,converter); //还输出到本目录下 docx路径 输出路径
} catch (Exception e) {
System.out.println("转化出错!");
e.printStackTrace();
} finally {
if (officeManager != null) {
//停止openOffice
officeManager.stop();
}
}
return null;
}
/**
* 获取inputFilePath的后缀名,如:"C:/Users/phone/Desktop/新建文件夹 (3)/22.docx"
* @param inputFilePath
* @return
*/
public String getPostfix(String inputFilePath) {
return inputFilePath.substring(inputFilePath.lastIndexOf(".") + 1);
}
}
package com.yizhi.application.course.util;
import com.aliyun.oss.OSSClient;
import com.aliyun.oss.OSSException;
import com.aliyun.oss.model.CompleteMultipartUploadResult;
import com.aliyun.oss.model.UploadFileRequest;
import com.aliyun.oss.model.UploadFileResult;
import com.netflix.client.ClientException;
public class OssUpload {
public static String upload(String uploadFile,String key,String active){
String endpoint = "";
String accessKeyId = "";
String accessKeySecret = "";
String bucketName = "";
if ("dev".equals(active)||"sit".equals(active)) {//||"uat".equals(active)
endpoint = "https://oss-cn-hangzhou.aliyuncs.com";
accessKeyId = "LTAInZlfTwk5fCDJ";
accessKeySecret = "UavtbFb2vUvRxiwUMLvUEelXTQtHCB";
bucketName = "fulan-test";
} else {
endpoint = "https://oss-cn-shanghai.aliyuncs.com";
accessKeyId = "LTAIeBliOjnD6v25";
accessKeySecret = "qd6iAV7tUvumvEiXxv9IGJbSdHcnmH";
bucketName = "cloud-wmy";
}
OSSClient ossClient = new OSSClient(endpoint, accessKeyId, accessKeySecret);
try {
UploadFileRequest uploadFileRequest = new UploadFileRequest(bucketName, key);
// 待上传的本地文件
uploadFileRequest.setUploadFile(uploadFile);
// 设置并发下载数,默认1
uploadFileRequest.setTaskNum(5);
// 设置分片大小,默认100KB
uploadFileRequest.setPartSize(1024 * 1024 * 1);
// 开启断点续传,默认关闭
uploadFileRequest.setEnableCheckpoint(true);
UploadFileResult uploadResult = ossClient.uploadFile(uploadFileRequest);
CompleteMultipartUploadResult multipartUploadResult =
uploadResult.getMultipartUploadResult();
System.out.println(multipartUploadResult.getLocation());
return multipartUploadResult.getLocation();
} catch (OSSException oe) {
System.out.println("Caught an OSSException, which means your request made it to OSS, "
+ "but was rejected with an error response for some reason.");
System.out.println("Error Message: " + oe.getErrorCode());
System.out.println("Error Code: " + oe.getErrorCode());
System.out.println("Request ID: " + oe.getRequestId());
System.out.println("Host ID: " + oe.getHostId());
return "error";
} catch (ClientException ce) {
System.out.println("Caught an ClientException, which means the client encountered "
+ "a serious internal problem while trying to communicate with OSS, "
+ "such as not being able to access the network.");
System.out.println("Error Message: " + ce.getMessage());
return "error";
} catch (Throwable e) {
e.printStackTrace();
return "error";
} finally {
ossClient.shutdown();
}
}
}
package com.yizhi.application.course.util;
import java.io.IOException;
import java.nio.file.*;
import java.nio.file.attribute.BasicFileAttributes;
import java.util.List;
import java.util.stream.Collectors;
/**
* 文件操作 https://www.cnblogs.com/IcanFixIt/p/4838375.html 过滤文件
*
* 参考https://howtodoinjava.com/java8/java-8-list-all-files-example/ 和 https://www.cnblogs.com/shihaiming/p/11237193.html
*/
public class PathUtils {
/**
*
* @param path src/test/resources
* @return
*/
public static List<String> getPathsByDirectory(String path) throws IOException {
Path folder = Paths.get(path);
// Apache Commons IO 获取目录的大小
/*File folder = new File("src/test/resources");
long size = FileUtils.sizeOfDirectory(folder);*/
//if(Files.exists(folder, LinkOption.NOFOLLOW_LINKS) && Files.isDirectory(folder)){// LinkOption.NOFOLLOW_LINKS 表示检测时不包含符号链接文件
if(Files.notExists(folder)){
//Path newDir = Files.createDirectory(folder);
//Files.createDirectories()
return null;
}
if(!Files.isDirectory(folder)){
//Files.copy(sourcePath, destinationPath, StandardCopyOption.REPLACE_EXISTING); 覆盖存在的文件
//Files.move(sourcePath, destinationPath, StandardCopyOption.REPLACE_EXISTING);
//Files.delete(path);
return null;
}
List<String> data = Files.walk(folder).filter(p-> !p.toFile().isHidden() && p.toFile().isFile() ).map(Path::toString).collect(Collectors.toList());
return data;
}
/**
* 大于等于文件大小进行获取目录下的文件列表
* @param path
* @param filesize 1024为1kb,204800L为200kb
* @return
* @throws IOException
*/
public static List<String> getPathsByDirectoryGe(String path, final long filesize) throws IOException {
Path folder = Paths.get(path);
if(Files.notExists(folder)){
return null;
}
if(!Files.isDirectory(folder)){
return null;
}
// 可以使用过滤出文件,然后对文件进行.mapToLong(p -> p.toFile().length()).sum();
List<String> data = Files.walk(folder).filter(p-> !p.toFile().isHidden() && p.toFile().isFile() && p.toFile().length()>=filesize).map(Path::toString).collect(Collectors.toList());
return data;
}
/**
* 小于文件大小进行获取目录下的文件列表
* @param path
* @param filesize 1024为1kb,204800L为200kb
* @return
* @throws IOException
*/
public static List<String> getPathsByDirectoryLt(String path, final long filesize) throws IOException {
Path folder = Paths.get(path);
if(Files.notExists(folder)){
return null;
}
if(!Files.isDirectory(folder)){
return null;
}
// 可以使用过滤出文件,然后对文件进行.mapToLong(p -> p.toFile().length()).sum();
List<String> data = Files.walk(folder).filter(p-> !p.toFile().isHidden() && p.toFile().isFile() && p.toFile().length()<filesize).map(Path::toString).collect(Collectors.toList());
return data;
}
/* public static void main(String[] args) {
try {
List<String> data = getPathsByDirectory("/Users/xiehaijun/Downloads");
for(String str : data){
System.out.println(str);
}
} catch (IOException e) {
e.printStackTrace();
}
}*/
// FileVisitor的方法会在不同时机被调用: preVisitDirectory()在访问目录前被调用。postVisitDirectory()在访问后调用。
// visitFile()会在整个遍历过程中的每次访问文件都被调用。他不是针对目录的,而是针对文件的。visitFileFailed()调用则是在文件访问失败的时候。例如,当缺少合适的权限或者其他错误。
public static boolean deleteDirectory(String directory){
Path rootPath = Paths.get(directory);
try {
Files.walkFileTree(rootPath, new SimpleFileVisitor<Path>() {
@Override
public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
System.out.println("delete file: " + file.toString());
Files.delete(file);
return FileVisitResult.CONTINUE;
// CONTINE表示文件遍历和正常情况下一样继续。
// TERMINATE表示文件访问需要终止。
// SKIP_SIBLINGS表示文件访问继续,但是不需要访问其他同级文件或目录。
// SKIP_SUBTREE表示继续访问,但是不需要访问该目录下的子目录。这个枚举值仅在preVisitDirectory()中返回才有效。如果在另外几个方法中返回,那么会被理解为CONTINE。
}
@Override
public FileVisitResult postVisitDirectory(Path dir, IOException exc) throws IOException {
Files.delete(dir);
System.out.println("delete dir: " + dir.toString());
return FileVisitResult.CONTINUE;
}
});
} catch(IOException e){
e.printStackTrace();
return false;
}
return true;
}
}
This diff is collapsed. Click to expand it.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment