Commit 00174e31 by liangkaiping

copy

parent 50974a1e
# cloud-certificate-group
证书
\ No newline at end of file
<?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">
<parent>
<artifactId>cloud-certificate</artifactId>
<groupId>com.yizhi</groupId>
<version>1.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<groupId>com.yizhi</groupId>
<artifactId>cloud-certificate-api</artifactId>
<version>1.0-SNAPSHOT</version>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
<configuration>
<skip>true</skip>
</configuration>
</plugin>
<plugin>
<groupId>org.mybatis.generator</groupId>
<artifactId>mybatis-generator-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
\ No newline at end of file
package com.yizhi.certificate.application.feign;
import com.baomidou.mybatisplus.plugins.Page;
import com.yizhi.certificate.application.vo.ApiUserCertificateVo;
import com.yizhi.certificate.application.vo.domain.TrUserCertificateVo;
import com.yizhi.certificate.application.vo.ApiSeachCerticateVo;
import org.springframework.cloud.openfeign.FeignClient;
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.RequestParam;
import java.util.Date;
import java.util.List;
import java.util.Map;
/**
* 证书
*
* @author Fairyland
*/
@FeignClient(name = "certificate", contextId = "CertificateAppClient")
public interface CertificateAppClient {
/**
* 根据学员端用户id查询学员端证书数量
*
* @return
*/
@GetMapping("/certificateApp/getCount")
Integer getCertificateCount(
@RequestParam(value = "accountId") Long accountId,
@RequestParam(value = "companyId") Long companyId,
@RequestParam(value = "siteId") Long siteId
);
/**
* 获取我的证书对象
*
* @return
*/
@GetMapping("/certificateApp/get")
TrUserCertificateVo getCertificate(@RequestParam(value = "id") Long id);
/**
* 获取 app我的证书列表
*
* @return
*/
@GetMapping("/certificateApp/list")
Page<TrUserCertificateVo> list(@RequestBody ApiSeachCerticateVo apiSeachCerticateVo);
@GetMapping("/certificateApp/appSerachAppList")
Page<ApiUserCertificateVo> appSerachAppList(@RequestBody ApiSeachCerticateVo apiSeachCerticateVo);
@PostMapping("/certificateApp/my/update")
Boolean updateTrUserCertificate(@RequestBody TrUserCertificateVo trUserCertificate);
@GetMapping("/certificateApp/view")
TrUserCertificateVo view(
@RequestParam(value = "id") Long id,
@RequestParam(value = "accountId") Long accountId,
@RequestParam(value = "projectId") Long projectId
);
/**
* 周期内用户得到第一个证书的时间
* @param accountId
* @param siteIds
* @param startDate
* @param endDate
* @return
*/
@GetMapping("/certificateApp/first")
public Map<Long, Date> firstCertificate( @RequestParam("siteIds") List<Long> siteIds,
@RequestParam("startDate") String startDate, @RequestParam("endDate") String endDate);
}
package com.yizhi.certificate.application.feign;
import com.yizhi.certificate.application.vo.CertificateClassifyListVO;
import com.yizhi.certificate.application.vo.domain.CertificateClassifyVo;
import org.springframework.cloud.openfeign.FeignClient;
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.RequestParam;
import java.util.List;
/**
* 证书分类
*
* @author ding
*/
@FeignClient(name = "certificate", contextId = "CertificateClassifyClient")
public interface CertificateClassifyClient {
/**
* 新建分类入库
* @param certificateClassify
* @return
*/
@PostMapping("/certificate/classify/insert")
Integer insertClassify(@RequestBody CertificateClassifyVo certificateClassify);
/**
* 获取分类列表
* @return
*/
@GetMapping("/certificate/classify/list")
List<CertificateClassifyListVO> getClassifyList();
/**
* 修改分类
* @param certificateClassify
* @return
*/
@PostMapping("/certificate/classify/update")
boolean updateClassify(@RequestBody CertificateClassifyVo certificateClassify);
/**
* 删除分类
* @param id
* @return
*/
@GetMapping("/certificate/classify/delete")
Integer deleteClassify(@RequestParam("id") Long id);
}
package com.yizhi.certificate.application.feign;
import com.baomidou.mybatisplus.plugins.Page;
import com.yizhi.certificate.application.vo.*;
import com.yizhi.certificate.application.vo.domain.CertificateVo;
import com.yizhi.certificate.application.vo.domain.RelationActivitiesVo;
import com.yizhi.certificate.application.vo.domain.TrCertificateTemplateVo;
import org.springframework.cloud.openfeign.FeignClient;
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.RequestParam;
import java.util.List;
import java.util.Map;
/**
* 证书
*
* @author Fairyland
*/
@FeignClient(name = "certificate", contextId = "CertificateClient")
public interface CertificateClient {
/**
* 证书管理端分页列表
*
* @param title 证书标题 模糊查询
* @param companyId 企业id
* @param siteId 站点id
* @param orgIds 管辖区id
* @param status 证书状态 不传全部 1:已关联 2:未关联 3:草稿
* @param pageNo 分页页数
* @param pageSize 分页条数
* @return Page<Certificate> 证书的分页列表
*/
@GetMapping("/certificate/searchCertificateList")
Page<CertificateListVO> searchCertificateList(
@RequestParam(value = "title", required = false) String title,
@RequestParam(value = "status", required = false) Integer status,
@RequestParam(value = "classifyId", required = false) Long classifyId,
@RequestParam(value = "currentTime", required = false) String currentTime,
@RequestParam(value = "companyId") Long companyId,
@RequestParam(value = "siteId") Long siteId,
@RequestParam(value = "orgIds", required = false) List<Long> orgIds,
@RequestParam(value = "pageNo", defaultValue = "1") Integer pageNo,
@RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize
);
/**
* 根据证书名称模糊 查询证书列表(分页) company_id 项目id 为0的证书
*
* @return
*/
@GetMapping("/certificate/getlist")
PageCertificateVo getList(
@RequestBody ApiSeachCerticateVo ApiSeachCerticateVo
);
/**
* 解析证书
*
* @return
*/
@GetMapping("/certificate/analysis")
TrCertificateTemplateVO analysisCertificate(@RequestParam(value = "url") String url, @RequestParam(value = "fileName") String fileName);
/**
* 获得证书模板列表
*
* @return
*/
@GetMapping("/certificate/template")
List<TrCertificateTemplateVo> getTemplateList();
/**
* 获得证书列表
*
* @return
*/
@GetMapping("/certificate/list")
Page<CertificateVo> getCertificateList(@RequestBody CertificateVoList certificateVoList);
/**
* 根据证书对象修改证书
*
* @return
*/
@PostMapping("/certificate/update")
Boolean updateCertificate(@RequestBody CertificateVo certificate);
/**
* 新增证书
*
* @return
*/
@PostMapping("/certificate/save")
Boolean saveCertificate(@RequestBody CertificateVo certificate);
/**
* 根据证书id,选择是否启用,修改证书状态
*
* @return
*/
@PostMapping("/certificate/enable")
Boolean enableCertificate(@RequestBody CertificateVo certificate);
/**
* 根据证书id,查询单个证书信息,返回证书对象
*
* @return
*/
@GetMapping("/certificate/get")
CertificateListVO getCertificate(@RequestParam(value = "id") Long id);
/**
* 根据证书id,复制单个证书信息,数据库新增一条数据,证书信息完全一致但名称修改为“***证书【复制件】:证书状态为“下架
*
* @return
*/
@PostMapping("/certificate/copy")
Boolean copyCertificate(@RequestBody CertificateVo certificate);
/**
* 自定义模板保存
*
* @param trCertificateTemplate
* @return
*/
@PostMapping("/certificate/template/save")
TrCertificateTemplateVo saveTemplate(@RequestBody TrCertificateTemplateVo trCertificateTemplate);
@GetMapping("/certificate/by/new/server")
public List<Map<String, Object>> getServerByCompanyIdAndIds(@RequestParam("companyId") Long companyId, @RequestParam(name = "ids", required = false) List<Long> ids);
/**
* 证书清单导出
*
* @param title
* @param status
* @param classifyId
* @param currentTime
* @return
*/
@GetMapping("/certificate/searchCertificateList/export")
String searchCertificateListExport(
@RequestParam(value = "title", required = false) String title,
@RequestParam(value = "status", required = false) Integer status,
@RequestParam(value = "classifyId", required = false) Long classifyId,
@RequestParam(value = "currentTime", required = false) String currentTime
);
/**
* 证书关联培训项目/课程
*
* @param relateCertificateParam
* @return
*/
@PostMapping("/certificate/relateProject")
Boolean relateProject(@RequestBody RelateCertificateParam relateCertificateParam);
/**
* 证书取消关联状态
*
* @param bizdType
* @param certificateId
* @param bizdId
* @param tpPlanId
* @return
*/
@GetMapping("/certificate/cancelRelate")
Boolean cancelRelate(@RequestParam("bizdType") Integer bizdType,
@RequestParam(value = "certificateId",required = false) Long certificateId,
@RequestParam(value = "bizdId",required = false) Long bizdId,
@RequestParam(value = "tpPlanId", required = false) Long tpPlanId);
/**
* 查看关联活动
* @param certificateId
* @return
*/
@GetMapping("/certificate/getRelationActivities")
List<RelationActivitiesVo> getRelationActivities(@RequestParam("certificateId") Long certificateId);
/**
* 通过证书id获取证书信息map
* @param certificateIds
* @return
*/
@GetMapping("/certificate/getCertificateMap")
Map<Long, CertificateVo> getCertificateMap(@RequestBody List<Long> certificateIds);
/**
* 获取某个活动发放数量
* @param certificateNumParam
* @return
*/
@PostMapping("/certificate/getCertificateNum")
Integer getCertificateNum(@RequestBody CertificateNumParam certificateNumParam);
}
package com.yizhi.certificate.application.feign;
import com.baomidou.mybatisplus.plugins.Page;
import com.yizhi.certificate.application.vo.domain.TrUserCertificateVo;
import com.yizhi.certificate.application.vo.ApiSeachCerticateVo;
import com.yizhi.certificate.application.vo.PushCertificateParam;
import org.springframework.cloud.openfeign.FeignClient;
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.RequestParam;
/**
* PC端 证书
*/
@FeignClient(name = "certificate", contextId = "CertificatePcClient")
public interface CertificatePcClient {
/**
* 获取 PC端 我的证书列表
*
* @param apiSeachCerticateVo
* @return
*/
@GetMapping("/certificatePc/list")
Page<TrUserCertificateVo> list(@RequestBody ApiSeachCerticateVo apiSeachCerticateVo);
// /**
// * 获取图片和证书名称( PC端 )
// * @param id
// * @return
// */
// @GetMapping("/certificatePc/imageView")
// public TrUserCertificatePcVo view(@RequestParam(value = "id") Long id, @RequestParam(value = "accountId") Long accountId);
/**
* 获取图片和证书名称( PC端 )
* @param id
* @return
*/
@GetMapping("/certificatePc/imageView")
public TrUserCertificateVo getCertificate(@RequestParam(value = "id") Long id);
@GetMapping("certificatePc/view")
public TrUserCertificateVo view(
@RequestParam(value = "id") Long id,
@RequestParam(value = "accountId") Long accountId,
@RequestParam(value = "projectId") Long projectId,
@RequestParam(value = "type") Integer type
);
/**
* 证书异步补发,及生成
* @param pushCertificateParam
* @return
*/
@PostMapping("certificatePc/pushCertificate")
public TrUserCertificateVo pushCertificate(@RequestBody PushCertificateParam pushCertificateParam);
}
package com.yizhi.certificate.application.feign;
import com.baomidou.mybatisplus.plugins.Page;
import com.yizhi.certificate.application.vo.CertificateListVO;
import com.yizhi.certificate.application.vo.CertificateUserListVO;
import com.yizhi.certificate.application.vo.TrUserCertificateDetailsVo;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import java.util.List;
@FeignClient(name = "certificate", contextId = "CertificateUserFeignClients")
public interface CertificateUserFeignClients {
@GetMapping("/manage/certificate/user/rank/list")
public Page<CertificateUserListVO> userRankList(
@RequestParam(name = "startDate", required = false) String startDate,
@RequestParam(name = "endDate", required = false) String endDate,
@RequestParam(name = "pageNo", required = false) Integer pageNo,
@RequestParam(name = "pageSize", required = false) Integer pageSize,
@RequestParam(name = "siteId", required = false) Long siteId,
@RequestParam(name = "companyId", required = false) Long companyId,
@RequestParam(name = "userName", required = false) String userName,
@RequestParam(name = "orgNameLike", required = false) String orgNameLike,
@RequestParam(name = "orgIds", required = false) List<Long> orgIds,
@RequestParam(name = "isAdmin", required = true) boolean isAdmin,
@RequestParam(name = "accountId", required = true) Long accountId);
@GetMapping("/manage/certificate/user/details")
public Page<TrUserCertificateDetailsVo> userDetails(@RequestParam(name = "startDate", required = false) String startDate,
@RequestParam(name = "endDate", required = false) String endDate,
@RequestParam(name = "pageNo", required = false) Integer pageNo,
@RequestParam(name = "pageSize", required = false) Integer pageSize,
@RequestParam(name = "siteId", required = false) Long siteId,
@RequestParam(name = "companyId", required = false) Long companyId,
@RequestParam(name = "userName", required = false) String userName,
@RequestParam(name = "orgNameLike", required = false) String orgNameLike,
@RequestParam(name = "orgIds", required = false) List<Long> orgIds,
@RequestParam(name = "isAdmin", required = true) boolean isAdmin,
@RequestParam(name = "accountId", required = true) Long accountId);
/**
* 证书统计按证书维度
*
* @param startDate
* @param endDate
* @param pageNo
* @param pageSize
* @param certificateName
* @return
*/
@GetMapping("/manage/certificate/user/certificate/list")
public Page<CertificateListVO> certificateList(
@RequestParam(name = "startDate", required = false) String startDate,
@RequestParam(name = "endDate", required = false) String endDate,
@RequestParam(name = "pageNo", required = false) Integer pageNo,
@RequestParam(name = "pageSize", required = false) Integer pageSize,
@RequestParam(name = "certificateName", required = false) String certificateName);
/**
* 证书统计按证书维度下载
*
* @param startDate
* @param endDate
* @param certificateName
* @return
*/
@GetMapping("/manage/certificate/user/certificate/export")
public String certificateListExport(
@RequestParam(name = "startDate", required = false) String startDate,
@RequestParam(name = "endDate", required = false) String endDate,
@RequestParam(name = "certificateName", required = false) String certificateName);
}
package com.yizhi.certificate.application.vo;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.util.List;
@Data
public class ApiSeachCerticateVo {
@ApiModelProperty(value = "证书名称")
private String title;
@ApiModelProperty(value = "证证书类型:1为有效,0为失效")
private String validityType = "1";
private Long companyId;
private List<Long> orgId;
private Long siteId;
private Integer pageNo;
private Integer pageSize;
private Long accountId;
}
/**
* FileName: ApiUserCertificateVo
* Author: wenjunlong
* Date: 2018/4/18 10:09
* Description: app端和前端展示用vo
* History:
* <author> <time> <version> <desc>
* 作者姓名 修改时间 版本号 描述
*/
package com.yizhi.certificate.application.vo;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.util.Date;
/**
* 〈一句话功能简述〉<br>
* 〈app端和前端展示用vo〉
*
* @author wenjunlong
* @create 2018/4/18
* @since 1.0.0
*/
@Data
public class ApiUserCertificateVo {
@ApiModelProperty(value = "主键id")
private Long id;
@ApiModelProperty(value = "证书id")
private Long certificateId;
@ApiModelProperty(value = "创建时间")
private Date createTime;
@ApiModelProperty(value = "失效时间")
private Date endTime;
@ApiModelProperty(value = "证书名称")
private String certificateTitle;
@ApiModelProperty(value = "证书缩略图")
private String certificateLogourl;
@ApiModelProperty(value = "证书是否有效 1 有效 0 无效")
private String status;
@ApiModelProperty(value = "项目名")
private String trainingProjectName;
}
package com.yizhi.certificate.application.vo;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.util.List;
/**
* <p>
* 一级分类
* </p>
*
* @author dingxiaowei123
* @since 2019-12-23
*/
@Data
@ApiModel(value = "Classify", description = "一级分类")
public class CertificateClassifyListVO {
private static final long serialVersionUID = 1L;
private Long id;
private String name;
@ApiModelProperty("分类编码")
private Integer code;
private String codeName;
@ApiModelProperty(value = "1:一级分类 2:二级分类 3:三级分类")
private Integer level;
@ApiModelProperty(value = "分类描述")
private String description;
@ApiModelProperty(value = "父级id 0为一级分类没有父级")
private Long parentId;
@ApiModelProperty(value = "分类排序")
private Integer sort;
@ApiModelProperty("二级分类列表")
private List<CertificateClassifyVO> children;
}
package com.yizhi.certificate.application.vo;
import com.yizhi.certificate.application.vo.domain.CertificateClassifyVo;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.util.List;
/**
* <p>
* 二级分类
* </p>
*
* @author dingxiaowei123
* @since 2019-12-23
*/
@Data
@ApiModel(value = "Classify", description = "二级分类")
public class CertificateClassifyVO {
private static final long serialVersionUID = 1L;
private Long id;
private String name;
@ApiModelProperty("分类编码")
private Integer code;
@ApiModelProperty(value = "1:一级分类 2:二级分类 3:三级分类")
private Integer level;
@ApiModelProperty(value = "分类描述")
private String description;
@ApiModelProperty(value = "父级id 0为一级分类没有父级")
private Long parentId;
@ApiModelProperty(value = "父级id 0为一级分类没有父级")
private Long rootId;
@ApiModelProperty(value = "分类排序")
private Integer sort;
@ApiModelProperty("三级分类列表")
private List<CertificateClassifyVo> children;
}
package com.yizhi.certificate.application.vo;
import com.yizhi.certificate.application.vo.domain.CertificateVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
/**
* <p>
* <p>
* </p>
*
* @author ding
* @since 2019-12-24
*/
@Data
@Api(tags = "CertificateListVO", description = "证书列表类(改版)")
public class CertificateListVO extends CertificateVo {
private static final long serialVersionUID = 1L;
@ApiModelProperty("证书获证人数")
private Integer grantNum;
@ApiModelProperty("所属分类名称")
private String classifyName;
@ApiModelProperty("关联活动数")
private Integer relationNum;
@ApiModelProperty("一级分类id")
private Long oneLevelId;
@ApiModelProperty("二级分类id")
private Long twoLevelId;
}
package com.yizhi.certificate.application.vo;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
/**
* 获取某个活动发放数量
* @author dingxiaowei
* Date: 2020/01/13
*/
@Data
@ApiModel(
value = "CertificateNumParam",
description = "获取某个活动发放数量"
)
public class CertificateNumParam {
@ApiModelProperty("活动id")
Long bizdId;
@ApiModelProperty("学员id")
Long accountId;
@ApiModelProperty("关联类型 0:培训项目 1:课程")
Integer type;
@ApiModelProperty("开始时间")
String startTime;
@ApiModelProperty("结束时间")
String endTime;
}
package com.yizhi.certificate.application.vo;
/**
* Created with report.
* User:zhuwenwen
* Date: 2018/3/9
* Time: 16:22
*/
/**
* 证书模板vo类
*/
public class CertificateTemplateVo {
private String templateUrl;
private String templateImage;
private String templateName;
public String getTemplateUrl() {
return templateUrl;
}
public void setTemplateUrl(String templateUrl) {
this.templateUrl = templateUrl;
}
public String getTemplateImage() {
return templateImage;
}
public void setTemplateImage(String templateImage) {
this.templateImage = templateImage;
}
public String getTemplateName() {
return templateName;
}
public void setTemplateName(String templateName) {
this.templateName = templateName;
}
}
package com.yizhi.certificate.application.vo;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
@Data
@ApiModel(value = "证书排名列表", description = "CertificateUserListVo")
public class CertificateUserListVO {
@ApiModelProperty("用户id")
private Long accountId;
@ApiModelProperty("用户名")
private String userName;
@ApiModelProperty("姓名")
private String name;
@ApiModelProperty("所在部门")
private String orgName;
@ApiModelProperty("工号")
private String workNum;
@ApiModelProperty("职位")
private String position;
@ApiModelProperty("总证书")
private String totalCertificate;
@ApiModelProperty("用户状态")
private boolean accountState;
@ApiModelProperty("起始日期")
private String startDate;
@ApiModelProperty(value = "公司ID")
private Long companyId;
@ApiModelProperty(value = "部门ID")
private Long orgId;
@ApiModelProperty(value = "站点ID")
private Long siteId;
}
package com.yizhi.certificate.application.vo;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.util.List;
@Data
@ApiModel(value = "CertificateUserParamVO", description = "证书排名")
public class CertificateUserParamVO {
@ApiModelProperty("用户名")
private String userName;
private String orgNameLike;
@ApiModelProperty("用户集合")
private List<Long> accountIds;
private Long siteId;
private Long companyId;
private Long orgId;
private Long accountId;
private Integer pageNo;
private Integer pageSize;
private List<Long> orgIds;
}
package com.yizhi.certificate.application.vo;
/**
* Created with report.
* User:zhuwenwen
* Date: 2018/3/9
* Time: 13:25
*/
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
/**
* 证书vo类
*/
@Data
public class CertificateVo {
private Long id;
@ApiModelProperty(value = "证书编号")
private String code;
@ApiModelProperty(value = "发行机构")
private String issuer;
@ApiModelProperty(value = "证书标题")
private String title;
@ApiModelProperty(value = "模板")
private String template;
@ApiModelProperty(value = "证书标签,用,分割")
private String tags;
@ApiModelProperty(value = "企业id")
private Long companyId;
@ApiModelProperty(value = "部门id")
private Long orgId;
@ApiModelProperty(value = "广告url")
private String logourl;
@ApiModelProperty(value = "过期类型")
private Integer type;
@ApiModelProperty(value = "固定周期数")
private Integer circleCount;
@ApiModelProperty(value = "失效日期")
private String endTime;
@ApiModelProperty(value = "证书状态")
private Integer status;
@ApiModelProperty(value = "过期单位")
private String circleUnit;
private Long templateId;
private String templateImage;
@ApiModelProperty(value = "站点id")
private Long siteId;
}
package com.yizhi.certificate.application.vo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
/**
* 证书列表入参VO
* @author Fairyland
*
*/
@Data
@Api(tags="CertificateVoList",description="证书VO列表")
public class CertificateVoList {
private static final long serialVersionUID = 1L;
@ApiModelProperty(value = "证书标题")
private String title;
@ApiModelProperty(value = "证书状态")
private Integer status;
@ApiModelProperty(value = "角色")
private Integer level;
@ApiModelProperty(value = "企业id")
private Long companyId;
@ApiModelProperty(value = "站点id")
private Long siteId;
@ApiModelProperty(value = "部门id集合")
private String [] orgIds;
@ApiModelProperty(value = "部门id")
private Long orgId;
@ApiModelProperty(value = "要跳转的页数")
private Integer pageNo;
@ApiModelProperty(value = "每页显示的条数")
private Integer pageSize;
}
package com.yizhi.certificate.application.vo;
import lombok.Data;
import java.util.Date;
@Data
public class FirstVO {
private Long accountId;
private Date first;
}
package com.yizhi.certificate.application.vo;
import io.swagger.annotations.ApiModelProperty;
import java.util.Date;
public class ListCertificateVo {
private Long id;
private String title;
@ApiModelProperty(value = "发行机构")
private String issuer;
private Date create_time;
private Integer status;
@ApiModelProperty(value = "企业id")
private Long companyId;
@ApiModelProperty(value = "部门id")
private Long orgId;
@ApiModelProperty(value = "站点id")
private Long siteId;
@ApiModelProperty(value = "项目id")
private Long trainingProjectId;
@ApiModelProperty(value = "项目名称")
private String trainingProjectName;
}
package com.yizhi.certificate.application.vo;
import com.baomidou.mybatisplus.plugins.Page;
import com.yizhi.certificate.application.vo.domain.CertificateVo;
import lombok.Data;
@Data
public class PageCertificateVo {
Page<CertificateVo> page = new Page<CertificateVo>();
}
package com.yizhi.certificate.application.vo;
import com.yizhi.core.application.context.RequestContext;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
/**
* 发放证书请求类
* @author dingxiaowei
* Date: 2019/12/25
*/
@Data
@ApiModel(
value = "PushCertificateParam",
description = "发放证书请求类"
)
public class PushCertificateParam {
@ApiModelProperty("证书id")
Long certificateId;
@ApiModelProperty("培训项目/课程id")
Long bizdId;
@ApiModelProperty("培训项目/课程名称")
String bizdName;
@ApiModelProperty("关联类型 0:培训项目 1:课程")
Integer type;
@ApiModelProperty("用户信息上下文")
RequestContext res;
@ApiModelProperty("分数")
String score;
}
package com.yizhi.certificate.application.vo;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.util.List;
/**
* 关联培训项目请求类
* @author dingxiaowei
* Date: 2019/12/25
*/
@Data
@ApiModel(
value = "RelateCertificateParam",
description = "关联培训项目请求类"
)
public class RelateCertificateParam {
@ApiModelProperty("证书id")
List<Long> certificateIds;
@ApiModelProperty("培训项目/课程id")
Long bizdId;
@ApiModelProperty("培训项目/课程名称")
String bizdName;
@ApiModelProperty("计划id")
Long tpPlanId;
@ApiModelProperty("计划名称")
String tpPlanName;
@ApiModelProperty("关联类型 0:培训项目 1:课程")
Integer type;
}
package com.yizhi.certificate.application.vo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.util.Date;
/**
* 证书解析VO类
*/
@Data
@Api(tags="TrCertificateTemplateVO",description="证书解析VO类")
public class TrCertificateTemplateVO {
private static final long serialVersionUID = 1L;
@ApiModelProperty(value = "CERTIFICATE_ANALYSIS_ERROR")
private String CERTIFICATE_ANALYSIS_ERROR;
@ApiModelProperty(value = "自定义证书解析错误")
private String CERTIFICATE_ANALYSIS_ERROR_MSG;
@ApiModelProperty(value = "TEMPLATE_CREATE_ERROR")
private String TEMPLATE_CREATE_ERROR;
@ApiModelProperty(value = "自定义模板信息保存失败")
private String TEMPLATE_CREATE_ERROR_MAG;
private Long id;
@ApiModelProperty(value = "模板url")
private String templateUrl;
@ApiModelProperty(value = "模板类型")
private Integer type;
@ApiModelProperty(value = "模板缩略图")
private String templateImage;
@ApiModelProperty(value = "模板名称")
private String templateName;
private Long createById;
private String createByName;
private Date createTime;
}
package com.yizhi.certificate.application.vo;
import com.yizhi.certificate.application.vo.domain.TrUserCertificateVo;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
/**
* *
*
* @author ding
* @date 2019/3/22
*/
@Data
public class TrUserCertificateDetailsVo extends TrUserCertificateVo {
@ApiModelProperty(value = "用户名")
private String userName;
@ApiModelProperty(value = "姓名")
private String fullName;
@ApiModelProperty(value = "工号")
private String workNum;
@ApiModelProperty(value = "职务")
private String position;
@ApiModelProperty(value = "是否启用")
private Integer accountState;
@ApiModelProperty(value = "部门名称")
private String orgName;
@ApiModelProperty(value = "部门id")
private Long orgId;
@ApiModelProperty("关联类型 0:培训项目 1:课程")
private Integer relateType;
}
package com.yizhi.certificate.application.vo;
import com.baomidou.mybatisplus.annotations.TableField;
import com.baomidou.mybatisplus.enums.FieldFill;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.util.Date;
@Data
public class TrUserCertificatePcVo {
@ApiModelProperty(value = "主键id")
private Long id;
@ApiModelProperty(value = "学员id")
private Long userId;
@ApiModelProperty(value = "证书id")
private Long certificateId;
@TableField(value = "create_by_id", fill = FieldFill.INSERT)
private Long createById;
@TableField(value = "create_by_name", fill = FieldFill.INSERT)
private String createByName;
@TableField(value = "create_time", fill = FieldFill.INSERT)
private Date createTime;
@TableField("company_id")
private Long companyId;
@ApiModelProperty(value = "企业名称")
private String companyName;
@ApiModelProperty(value = "账号id")
private Long accountId;
@ApiModelProperty(value = "账号名")
private String accountName;
private String userName;
private String trainingProjectName;
private Long trainingProjectId;
private String issuer;
@ApiModelProperty(value = "失效时间")
private Date endTime;
@ApiModelProperty(value = "得分")
private String score;
@ApiModelProperty(value = "证书名称")
private String certificateTitle;
@ApiModelProperty(value = "证书缩略图")
private String certificateLogourl;
@ApiModelProperty(value = "学员证书生成图片")
private String userImage;
@ApiModelProperty(value = "学员证书生成图片相对路径")
private String unOssImage;
@ApiModelProperty(value = "站点id")
private Long siteId;
@ApiModelProperty(value = "过期类型")
private Integer type;
}
package com.yizhi.certificate.application.vo.domain;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.util.Date;
/**
* <p>
* 文件夹分类表
* </p>
*
* @author dingxiaowei123
* @since 2019-12-23
*/
@Data
@ApiModel(value = "Classify", description = "文件夹分类表")
public class CertificateClassifyVo {
private static final long serialVersionUID = 1L;
private Long id;
@ApiModelProperty("分类名称")
private String name;
@ApiModelProperty("分类编码")
private Integer code;
@ApiModelProperty(value = "1:一级分类 2:二级分类 3:三级分类")
private Integer level;
@ApiModelProperty(value = "分类描述")
private String description;
@ApiModelProperty(value = "父级id 0为一级分类没有父级")
private Long parentId;
@ApiModelProperty("顶级分类id")
private Long rootId;
@ApiModelProperty(value = "分类排序")
private Integer sort;
private Long createById;
private String createByName;
private Date createTime;
private Long updateById;
private String updateByName;
private Date updateTime;
private Long companyId;
private Long siteId;
private Long orgId;
@ApiModelProperty(value = "(0:删除, 1:未删除)")
private Integer state;
}
package com.yizhi.certificate.application.vo.domain;
import com.fasterxml.jackson.annotation.JsonFormat;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.io.Serializable;
import java.util.Date;
/**
* <p>
* <p>
* </p>
*
* @author fulan123
* @since 2018-03-07
*/
@Data
@Api(tags = "Certificate", description = "证书")
public class CertificateVo {
private static final long serialVersionUID = 1L;
private Long id;
@ApiModelProperty(value = "证书编号")
private String code;
@ApiModelProperty(value = "证书编号规则类型 0:获取时间+六位顺序编号 | 1:六位顺序编号")
private Integer ruleType;
@ApiModelProperty(value = "发行机构")
private String issuer;
@ApiModelProperty(value = "证书标题")
private String title;
@ApiModelProperty("分类id")
private Long classifyId;
@ApiModelProperty(value = "模板")
private String template;
private Long createById;
private String createByName;
private Date createTime;
private Long updateById;
private String updateByName;
private Date updateTime;
@ApiModelProperty(value = "证书标签,用,分割")
private String tags;
@ApiModelProperty(value = "企业id")
private Long companyId;
@ApiModelProperty(value = "部门id")
private Long orgId;
@ApiModelProperty(value = "广告url")
private String logourl;
@ApiModelProperty(value = "过期类型")
private Integer type;
@ApiModelProperty(value = "固定周期数")
private Integer circleCount;
@ApiModelProperty(value = "失效日期")
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss",timezone="GMT+8")
private Date endTime;
@ApiModelProperty(value = "证书状态 0:下架 1:上架 2:草稿 3:删除")
private Integer status;
@ApiModelProperty(value = "过期单位")
private String circleUnit;
private Long templateId;
private String templateImage;
@ApiModelProperty(value = "站点id")
private Long siteId;
@ApiModelProperty(value = "项目/课程id")
private Long trainingProjectId;
@ApiModelProperty(value = "项目/课程名称")
private String trainingProjectName;
protected Serializable pkVal() {
return this.id;
}
}
package com.yizhi.certificate.application.vo.domain;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.util.Date;
/**
* <p>
* 学员证书中间表
* </p>
*
* @author dingxiaowei123
* @since 2019-12-30
*/
@Data
@ApiModel(value = "RelationActivities", description = "学员证书中间表")
public class RelationActivitiesVo {
private static final long serialVersionUID = 1L;
@ApiModelProperty(value = "主键id")
private Long id;
@ApiModelProperty(value = "证书id")
private Long certificateId;
@ApiModelProperty(value = "关联活动类型0:培训项目 1:课程")
private Integer bizdType;
@ApiModelProperty(value = "活动名称")
private String bizdName;
@ApiModelProperty(value = "活动id")
private Long bizdId;
@ApiModelProperty(value = "如果是培训项目关联计划id")
private Long tpPlanId;
@ApiModelProperty(value = "如果是培训项目,计划名称")
private String tpPlanName;
private Long createById;
private String createByName;
private Date createTime;
private Long updateById;
private String updateByName;
private Date updateTime;
private Long companyId;
private Long siteId;
@ApiModelProperty(value = "关联状态 0:无效 1:有效")
private Integer relationState;
}
package com.yizhi.certificate.application.vo.domain;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.io.Serializable;
import java.util.Date;
/**
* <p>
* 证书模板表
* </p>
*
* @author fulan123
* @since 2018-03-07
*/
@Data
@Api(tags = "TrCertificateTemplate", description = "证书模板表")
public class TrCertificateTemplateVo{
private static final long serialVersionUID = 1L;
private Long id;
@ApiModelProperty(value = "模板url")
private String templateUrl;
@ApiModelProperty(value = "模板类型")
private Integer type;
@ApiModelProperty(value = "模板缩略图")
private String templateImage;
@ApiModelProperty(value = "模板名称")
private String templateName;
private Long createById;
private String createByName;
private Date createTime;
protected Serializable pkVal() {
return this.id;
}
}
package com.yizhi.certificate.application.vo.domain;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.io.Serializable;
import java.util.Date;
/**
* <p>
* 学员证书中间表
* </p>
*
* @author fulan123
* @since 2018-03-07
*/
@Data
@Api(tags = "TrUserCertificate", description = "学员证书中间表")
public class TrUserCertificateVo {
private static final long serialVersionUID = 1L;
@ApiModelProperty(value = "主键id")
private Long id;
@ApiModelProperty(value = "学员id")
private Long userId;
@ApiModelProperty(value = "证书id")
private Long certificateId;
private Long createById;
private String createByName;
private Date createTime;
private Long companyId;
@ApiModelProperty(value = "企业名称")
private String companyName;
@ApiModelProperty(value = "账号id")
private Long accountId;
@ApiModelProperty(value = "账号名")
private String accountName;
private String userName;
private String trainingProjectName;
private Long trainingProjectId;
private Integer bizdType;
private String issuer;
@ApiModelProperty(value = "失效时间")
private Date endTime;
@ApiModelProperty(value = "得分")
private String score;
@ApiModelProperty(value = "证书名称")
private String certificateTitle;
@ApiModelProperty(value = "证书缩略图")
private String certificateLogourl;
@ApiModelProperty(value = "学员证书生成图片")
private String userImage;
@ApiModelProperty(value = "站点id")
private Long siteId;
@ApiModelProperty(value = "过期类型")
private Integer type;
@ApiModelProperty(value = "证书编号")
private String certificateCode;
private Long tpPlanId;
@ApiModelProperty(value = "计划名称")
private String tpPlanName;
protected Serializable pkVal() {
return this.id;
}
}
<?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">
<parent>
<artifactId>cloud-certificate</artifactId>
<groupId>com.yizhi</groupId>
<version>1.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<groupId>com.yizhi</groupId>
<artifactId>cloud-certificate-service</artifactId>
<version>1.0-SNAPSHOT</version>
<dependencies>
<dependency>
<groupId>com.yizhi</groupId>
<artifactId>cloud-certificate-api</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>com.yizhi</groupId>
<artifactId>cloud-system-api</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
<!-- <dependency>-->
<!-- <groupId>com.aliyun</groupId>-->
<!-- <artifactId>aliyun-java-sdk-core</artifactId>-->
<!-- <version>3.2.2</version>-->
<!-- </dependency>-->
<!-- <dependency>-->
<!-- <groupId>com.aliyun.oss</groupId>-->
<!-- <artifactId>aliyun-sdk-oss</artifactId>-->
<!-- <version>2.8.3</version>-->
<!-- </dependency>-->
<!-- -->
<dependency>
<groupId>org.apache.pdfbox</groupId>
<artifactId>pdfbox</artifactId>
<version>2.0.8</version>
</dependency>
</dependencies>
<build>
<plugins>
<!-- deploy 时跳过该模块 -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-deploy-plugin</artifactId>
<configuration>
<skip>true</skip>
</configuration>
</plugin>
</plugins>
</build>
</project>
\ No newline at end of file
package com.yizhi.certificate.application;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.cloud.openfeign.EnableFeignClients;
import org.springframework.context.annotation.ComponentScan;
/**
* @Author: shengchenglong
* @Date: 2018/3/6 14:29
*/
@SpringBootApplication
@EnableDiscoveryClient
@EnableFeignClients(basePackages = "com.yizhi")
@ComponentScan(basePackages = {"com.yizhi"})
public class CertificateApplication {
public static void main(String[] args) {
SpringApplication.run(CertificateApplication.class, args);
}
}
package com.yizhi.certificate.application;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.ResponseEntity;
import org.springframework.web.context.request.async.DeferredResult;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;
import static com.google.common.base.Predicates.or;
import static springfox.documentation.builders.PathSelectors.regex;
/**
* swagger接口文档配置
* @author scotthu
*
* @date 2018年2月28日
*/
@Configuration
@EnableSwagger2
public class SwaggerConfig extends WebMvcConfigurerAdapter {
/**
* 这个地方要重新注入一下资源文件,不然不会注入资源的,也没有注入requestHandlerMappping,相当于xml配置的
* <!--swagger资源配置-->
* <mvc:resources location="classpath:/META-INF/resources/" mapping="swagger-ui.html"/>
* <mvc:resources location="classpath:/META-INF/resources/webjars/" mapping="/webjars/**"/>
* 不知道为什么,这也是spring boot的一个缺点(菜鸟觉得的)
* @param registry
*/
@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
registry.addResourceHandler("/webjars/**")
.addResourceLocations("classpath:/META-INF/resources/webjars/");
registry.addResourceHandler("swagger-ui.html")
.addResourceLocations("classpath:/META-INF/resources/");
}
@Bean
public Docket createRestApi() {
return new Docket(DocumentationType.SWAGGER_2)
.groupName("证书服务")
.genericModelSubstitutes(DeferredResult.class)
.genericModelSubstitutes(ResponseEntity.class)
.useDefaultResponseMessages(false)
.forCodeGeneration(true)
.pathMapping("/")
.select()
.paths(or(regex("/api.*"),regex("/manage.*")))
.build()
.apiInfo(apiInfo());
}
private ApiInfo apiInfo() {
return new ApiInfoBuilder()
.title("证书服务")
.version("1.0")//版本
.build();
}
}
package com.yizhi.certificate.application.asynchronousTask;
import com.baomidou.mybatisplus.plugins.Page;
import com.yizhi.certificate.application.service.ICertificateService;
import com.yizhi.certificate.application.vo.CertificateListVO;
import com.yizhi.core.application.context.RequestContext;
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 org.apache.poi.ss.util.CellRangeAddress;
import org.apache.poi.xssf.usermodel.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.util.CollectionUtils;
import java.io.File;
import java.io.FileOutputStream;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import java.util.Map;
/**
* @author Ding
* @className CertificateListExport
* @description TODO
* @date 2019/7/31
**/
@Component("certificateListExport1")
public class CertificateListExport extends AbstractDefaultTask<Map, Map<String, Object>> {
private static final Logger LOGGER = LoggerFactory.getLogger(CertificateListExport.class);
@Autowired
private ICertificateService certificateService;
@Override
protected Map execute(Map<String, Object> map) {
//从map中取信息
RequestContext res = (RequestContext) map.get("res");
String serialNo = (String) map.get("serialNo");
String taskName = (String) map.get("taskName");
Long taskId = (Long) map.get("taskId");
String title = (String) map.get("title");
Integer status = (Integer) map.get("status");
Long classifyId = (Long) map.get("classifyId");
String currentTime = (String) map.get("currentTime");
//开始异步任务
TaskContext taskContext = new TaskContext(taskId, serialNo, taskName,
res.getAccountId(), new Date(), res.getSiteId(), res.getCompanyId());
working(taskContext);
List<CertificateListVO> list = null;
//获取导出数据
try {
Page<CertificateListVO> page = certificateService.searchCertificateList(title, classifyId, res.getCompanyId(),
res.getSiteId(), null, status, 1, Integer.MAX_VALUE, currentTime, res);
list = page.getRecords();
if (CollectionUtils.isEmpty(list)) {
success(taskContext, "未找到数据");
}
} catch (Exception e) {
LOGGER.error("获取数据过程中出现错误", e);
fail(taskContext, "获取数据过程中出现错误");
}
//生成excel,上传阿里云返回url
try {
//创建excel文件
XSSFWorkbook wb = new XSSFWorkbook();
//创建报表页
XSSFSheet sheet = wb.createSheet("证书清单获取");
//创建表头
XSSFRow row = sheet.createRow(0);
//设置格式(加粗,字体大小14号)
XSSFCellStyle style = wb.createCellStyle();
XSSFFont font = wb.createFont();
font.setBold(true);
font.setFontHeightInPoints((short) 14);
style.setFont(font);
CellRangeAddress cra = new CellRangeAddress(0, 0, 0, 7);
//表头合并单元格
sheet.addMergedRegion(cra);
XSSFCell cell = row.createCell(0);
//填写表头名
cell.setCellValue("证书清单获取数据");
//表头格式
cell.setCellStyle(style);
row = sheet.createRow(1);
//重新设置格式(只加粗)
style = wb.createCellStyle();
font = wb.createFont();
font.setBold(true);
style.setFont(font);
cell = row.createCell(0);
cell.setCellStyle(style);
cell.setCellValue("证书编号");
cell = row.createCell(1);
cell.setCellStyle(style);
cell.setCellValue("证书名称");
cell = row.createCell(2);
cell.setCellStyle(style);
cell.setCellValue("发证机构");
cell = row.createCell(3);
cell.setCellStyle(style);
cell.setCellValue("创建人");
cell = row.createCell(4);
cell.setCellStyle(style);
cell.setCellValue("创建时间");
cell = row.createCell(5);
cell.setCellStyle(style);
cell.setCellValue("关联活动数");
cell = row.createCell(6);
cell.setCellStyle(style);
cell.setCellValue("获证人数");
cell = row.createCell(7);
cell.setCellStyle(style);
cell.setCellValue("状态");
//组装数据
if (!CollectionUtils.isEmpty(list)) {
for (int i = 0; i < list.size(); i++) {
CertificateListVO certificateListVO = list.get(i);
row = sheet.createRow(i + 2);
row.createCell(0).setCellValue(certificateListVO.getId().toString());
row.createCell(1).setCellValue(certificateListVO.getTitle());
row.createCell(2).setCellValue(certificateListVO.getIssuer());
row.createCell(3).setCellValue(certificateListVO.getCreateByName());
SimpleDateFormat sdf = new SimpleDateFormat("yyyy/M/dd HH:mm:ss");
row.createCell(4).setCellValue(sdf.format(certificateListVO.getCreateTime()));
row.createCell(5).setCellValue(certificateListVO.getRelationNum());
row.createCell(6).setCellValue(certificateListVO.getGrantNum());
if (certificateListVO.getStatus()==0){
row.createCell(7).setCellValue("下架");
}else if (certificateListVO.getStatus()==1){
row.createCell(7).setCellValue("上架");
}else if (certificateListVO.getStatus()==2){
row.createCell(7).setCellValue("草稿");
}
}
}
SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmss");
String fileName = "证书清单获取数据" + sdf.format(new Date()) + ".xlsx";
// String requestPath = "/Users/dingxiaowei/aaa";
String requestPath = FileConstant.SAVE_PATH;
File fileDir = new File(requestPath);
if (!fileDir.exists()) {
fileDir.mkdir();
}
String path = requestPath + "/" + fileName;
FileOutputStream os = null;
File file = null;
try {
os = new FileOutputStream(path);
wb.write(os);
//阿里云返回url
String uploadUrl = OssUpload.upload(path, fileName);
file = new File(path);
success(taskContext, "成功导出" + list.size() + "条记录", uploadUrl);
} catch (Exception e2) {
e2.printStackTrace();
fail(taskContext, "证书清单数据导出写入过程中发生错误");
LOGGER.error("证书清单数据导出写入过程中发生错误");
} finally {
if (os != null) {
os.close();
}
if (wb != null) {
wb.close();
}
if (file != null) {
file.delete();
}
}
} catch (Exception e) {
e.printStackTrace();
fail(taskContext, "证书清单数据导出下载发生错误");
LOGGER.error("证书清单数据导出下载发生错误,请查看日志");
}
return null;
}
}
package com.yizhi.certificate.application.asynchronousTask;
import com.baomidou.mybatisplus.plugins.Page;
import com.yizhi.certificate.application.service.CertificateUserService;
import com.yizhi.certificate.application.vo.CertificateListVO;
import com.yizhi.core.application.context.RequestContext;
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 org.apache.poi.ss.usermodel.CellStyle;
import org.apache.poi.ss.util.CellRangeAddress;
import org.apache.poi.xssf.usermodel.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.util.CollectionUtils;
import java.io.File;
import java.io.FileOutputStream;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import java.util.Map;
/**
* @author Ding
* @className CertificateListExport
* @description TODO
* @date 2019/7/31
**/
@Component
public class CertificateStatisticExport extends AbstractDefaultTask<Map, Map<String, Object>> {
private static final Logger LOGGER = LoggerFactory.getLogger(CertificateStatisticExport.class);
@Autowired
private CertificateUserService certificateUserService;
@Override
protected Map execute(Map<String, Object> map) {
//从map中取信息
RequestContext res = (RequestContext) map.get("res");
String serialNo = (String) map.get("serialNo");
String taskName = (String) map.get("taskName");
Long taskId = (Long) map.get("taskId");
String startDate = (String) map.get("startDate");
String endDate = (String) map.get("endDate");
String certificateName = (String) map.get("certificateName");
//开始异步任务
TaskContext taskContext = new TaskContext(taskId, serialNo, taskName,
res.getAccountId(), new Date(), res.getSiteId(), res.getCompanyId());
working(taskContext);
List<CertificateListVO> list = null;
//获取导出数据
try {
Page<CertificateListVO> page = certificateUserService.certificateList(startDate, endDate, certificateName, 1, Integer.MAX_VALUE, res);
list = page.getRecords();
if (CollectionUtils.isEmpty(list)) {
success(taskContext, "未找到数据");
}
} catch (Exception e) {
LOGGER.error("获取数据过程中出现错误", e);
fail(taskContext, "获取数据过程中出现错误");
}
//生成excel,上传阿里云返回url
try {
//新建excel对象
XSSFWorkbook workbook = new XSSFWorkbook();
XSSFSheet sheet = workbook.createSheet("按证书维度获取统计数据");
XSSFRow row = sheet.createRow(0);
CellStyle cellStyle = workbook.createCellStyle();
XSSFFont font = workbook.createFont();
font.setBold(true);
cellStyle.setFont(font);
CellRangeAddress cra = new CellRangeAddress(0, 0, 0, 4);
sheet.addMergedRegion(cra);
XSSFCell cell = row.createCell(0);
cell.setCellValue("按证书维度获取统计数据");
cell.setCellStyle(cellStyle);
row = sheet.createRow(1);
cell = row.createCell(0);
cell.setCellValue("统计周期:");
cell.setCellStyle(cellStyle);
cra = new CellRangeAddress(1, 1, 1, 4);
sheet.addMergedRegion(cra);
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
cell = row.createCell(1);
cell.setCellValue(null != startDate && null != endDate ? startDate + "~" + endDate : "");
cell.setCellStyle(cellStyle);
row = sheet.createRow(2);
row.createCell(0).setCellValue("证书编码");
row.createCell(1).setCellValue("证书名称");
row.createCell(2).setCellValue("发证机构");
row.createCell(3).setCellValue("获证人数");
row.createCell(4).setCellValue("状态");
//组装数据
if (!CollectionUtils.isEmpty(list)) {
for (int i = 0; i < list.size(); i++) {
CertificateListVO certificateListVO = list.get(i);
row = sheet.createRow(i + 3);
row.createCell(0).setCellValue(certificateListVO.getId().toString());
row.createCell(1).setCellValue(certificateListVO.getTitle());
row.createCell(2).setCellValue(certificateListVO.getIssuer());
row.createCell(3).setCellValue(certificateListVO.getGrantNum());
if (certificateListVO.getStatus() == 0) {
row.createCell(4).setCellValue("下架");
} else if (certificateListVO.getStatus() == 1) {
row.createCell(4).setCellValue("上架");
} else if (certificateListVO.getStatus() == 2) {
row.createCell(4).setCellValue("草稿");
}
}
}
SimpleDateFormat sdf1 = new SimpleDateFormat("yyyyMMddHHmmss");
String fileName = "证书清单获取数据" + sdf.format(new Date()) + ".xlsx";
// String requestPath = "/Users/dingxiaowei/aaa";
String requestPath = FileConstant.SAVE_PATH;
File fileDir = new File(requestPath);
if (!fileDir.exists()) {
fileDir.mkdir();
}
String path = requestPath + "/" + fileName;
FileOutputStream os = null;
File file = null;
try {
os = new FileOutputStream(path);
workbook.write(os);
//阿里云返回url
String uploadUrl = OssUpload.upload(path, fileName);
file = new File(path);
success(taskContext, "成功导出" + list.size() + "条记录", uploadUrl);
} catch (Exception e2) {
e2.printStackTrace();
fail(taskContext, "按证书统计写入过程中发生错误");
LOGGER.error("按证书统计写入过程中发生错误");
} finally {
if (os != null) {
os.close();
}
if (workbook != null) {
workbook.close();
}
if (file != null) {
file.delete();
}
}
} catch (Exception e) {
e.printStackTrace();
fail(taskContext, "按证书统计下载发生错误");
LOGGER.error("按证书统计下载发生错误,请查看日志");
}
return null;
}
}
package com.yizhi.certificate.application.config;
import com.yizhi.certificate.application.domain.Certificate;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
/**
* Created with report.
* User:zhuwenwen
* Date: 2018/3/8
* Time: 10:26
*/
/**
* 配置文件
*/
@Configuration
@ComponentScan("com.yizhi.certificate.application.config")
public class CertificateConfig extends WebMvcConfigurerAdapter {
/**
* 实例化一个证书对象
* @return
*/
@Bean(name = "certificate")
public Certificate certificate(){
return new Certificate();
}
}
package com.yizhi.certificate.application.config;
import com.yizhi.certificate.application.domain.TrCertificateTemplate;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
/**
* Created with report.
* User:zhuwenwen
* Date: 2018/3/8
* Time: 13:59
*/
/**
* 配置文件
*/
@Configuration
public class TrCertificateTemplateconf {
/**
* 实例化一个证书模板对象
* @return
*/
@Bean
public TrCertificateTemplate trCertificateTemplate(){
return new TrCertificateTemplate();
}
}
/**
*
*/
package com.yizhi.certificate.application.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 LOG_SEARCH_ERROR_COUNTCERTIFICATEMSG="没有证书";
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.certificate.application.constant;
public class UtilConstants {
/**
* 证书自定义包下载保存路径,以及解压和解析后的图片
*/
// public static String CERTIFICATE_SAVE_PATH = "D:/tmp";
public static String CERTIFICATE_SAVE_PATH = "/tmp";
}
package com.yizhi.certificate.application.controller;
import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.yizhi.certificate.application.domain.TrUserCertificate;
import com.yizhi.certificate.application.service.ICertificateService;
import com.yizhi.certificate.application.service.ITrUserCertificateService;
import com.yizhi.certificate.application.vo.ApiSeachCerticateVo;
import com.yizhi.certificate.application.vo.ApiUserCertificateVo;
import com.yizhi.certificate.application.vo.domain.TrUserCertificateVo;
import com.yizhi.system.application.system.remote.ReportClient;
import com.yizhi.util.application.beanutil.BeanCopyListUtil;
import io.swagger.annotations.Api;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.*;
import java.util.Date;
import java.util.List;
import java.util.Map;
@Api(tags = "app端证书api", description = "app端证书接口")
@RestController
@RequestMapping("/certificateApp")
public class CertificateAppController {
private static final Logger logger = LoggerFactory.getLogger(CertificateController.class);
@Autowired
private ITrUserCertificateService trUserCertificateService;
@Autowired
private ICertificateService certificateService;
@Autowired
private ReportClient reportClient;
/**
* 根据学员端用户id查询学员端证书数量
*
* @return
*/
@GetMapping("/getCount")
Integer getCertificateCount(
@RequestParam(value = "accountId") Long accountId,
@RequestParam(value = "companyId") Long companyId,
@RequestParam(value = "siteId") Long siteId
) {
return trUserCertificateService.getCertificateCount(accountId,companyId,siteId);
}
/**
* 获取我的证书对象
*
* @return
*/
@GetMapping("/get")
public TrUserCertificateVo getCertificate(@RequestParam(value = "id") Long id) {
TrUserCertificate trUserCertificate = trUserCertificateService.selectById(id);
if (StringUtils.isEmpty(trUserCertificate)) {
logger.info("*******************************getCertificate="+ JSON.toJSONString(trUserCertificate));
return null;
}
TrUserCertificateVo trUserCertificateVo = new TrUserCertificateVo();
BeanUtils.copyProperties(trUserCertificate, trUserCertificateVo);
return trUserCertificateVo;
}
/**
* 获取 app我的证书列表
*
* @return
*/
@GetMapping("/list")
Page<TrUserCertificateVo> list(@RequestBody ApiSeachCerticateVo apiSeachCerticateVo) {
Page<TrUserCertificate> trUserCertificates = trUserCertificateService.getMyList(apiSeachCerticateVo.getAccountId(),
apiSeachCerticateVo.getTitle(),
apiSeachCerticateVo.getValidityType(),apiSeachCerticateVo.getCompanyId(),apiSeachCerticateVo.getSiteId(),
apiSeachCerticateVo.getPageNo(), apiSeachCerticateVo.getPageSize());
Page<TrUserCertificateVo> trUserCertificateVoPage = new Page<>();
BeanUtils.copyProperties(trUserCertificates, trUserCertificateVoPage);
trUserCertificateVoPage.setRecords(BeanCopyListUtil.copyListProperties(trUserCertificates.getRecords(), TrUserCertificateVo::new));
return trUserCertificateVoPage;
}
@GetMapping("/appSerachAppList")
Page<ApiUserCertificateVo> appSerachAppList(@RequestBody ApiSeachCerticateVo apiSeachCerticateVo) {
Page<ApiUserCertificateVo> page = trUserCertificateService.getMyListSearch(apiSeachCerticateVo.getAccountId(),
apiSeachCerticateVo.getTitle(), apiSeachCerticateVo.getCompanyId(),apiSeachCerticateVo.getSiteId(),apiSeachCerticateVo.getPageNo(), apiSeachCerticateVo.getPageSize());
return page;
}
@PostMapping("/my/update")
public Boolean updateTrUserCertificate(@RequestBody TrUserCertificate trUserCertificate) {
return trUserCertificateService.updateById(trUserCertificate);
}
@GetMapping("/view")
public TrUserCertificateVo view(
@RequestParam(value = "id") Long id,
@RequestParam(value = "accountId") Long accountId,
@RequestParam(value = "projectId") Long projectId
){
TrUserCertificate trUserCertificate = new TrUserCertificate();
trUserCertificate.setAccountId(accountId);
trUserCertificate.setCertificateId(id);
EntityWrapper<TrUserCertificate> entityWrapper = new EntityWrapper<TrUserCertificate>(trUserCertificate);
TrUserCertificateVo trUserCertificateVo = new TrUserCertificateVo();
BeanUtils.copyProperties(trUserCertificateService.selectOne(entityWrapper), trUserCertificateVo);
return trUserCertificateVo;
}
@GetMapping("/first")
public Map<Long, Date> firstCertificate(@RequestParam("siteIds") List<Long> siteIds,
@RequestParam("startDate") String startDate, @RequestParam("endDate") String endDate) {
return trUserCertificateService.first( siteIds, startDate, endDate);
}
}
package com.yizhi.certificate.application.controller;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.yizhi.application.orm.id.IdGenerator;
import com.yizhi.certificate.application.asynchronousTask.CertificateListExport;
import com.yizhi.certificate.application.domain.Certificate;
import com.yizhi.certificate.application.domain.CertificateClassify;
import com.yizhi.certificate.application.domain.RelationActivities;
import com.yizhi.certificate.application.domain.TrCertificateTemplate;
import com.yizhi.certificate.application.service.ICertificateService;
import com.yizhi.certificate.application.service.IClassifyService;
import com.yizhi.certificate.application.service.IRelationActivitiesService;
import com.yizhi.certificate.application.service.ITrCertificateTemplateService;
import com.yizhi.certificate.application.vo.*;
import com.yizhi.certificate.application.vo.domain.CertificateVo;
import com.yizhi.certificate.application.vo.domain.RelationActivitiesVo;
import com.yizhi.certificate.application.vo.domain.TrCertificateTemplateVo;
import com.yizhi.core.application.context.ContextHolder;
import com.yizhi.core.application.context.RequestContext;
import com.yizhi.util.application.beanutil.BeanCopyListUtil;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.util.CollectionUtils;
import org.springframework.web.bind.annotation.*;
import java.util.*;
//import com.fulan.application.util.CertificateZipAnalysisCallBack;
//@Api(tags = "证书接口", description = "certificate Controller")
@RestController
@RequestMapping("/certificate")
public class CertificateController {
private static final Logger logger = LoggerFactory.getLogger(CertificateController.class);
@Autowired
private ICertificateService certificateService;
@Autowired
private ITrCertificateTemplateService iTrCertificateTemplateService;
@Autowired
@Qualifier("certificate")
private Certificate certificate;
@Autowired
IdGenerator idGenerator;
@Autowired
private CertificateListExport certificateListExport;
@Autowired
private IRelationActivitiesService relationActivitiesService;
@Autowired
private IClassifyService classifyService;
/**
* 证书管理端分页列表
*
* @param title 证书标题
* @param companyId 企业id
* @param siteId 站点id
* @param orgIds 管辖区
* @param status 证书状态 0代表停用,1代表启用
* @param pageNo 分页页数
* @param pageSize 分页条数
* @return Page<Certificate> 证书的分页列表
*/
@GetMapping("/searchCertificateList")
public Page<CertificateListVO> searchCertificateList(
@RequestParam(value = "title", required = false) String title,
@RequestParam(value = "status", required = false) Integer status,
@RequestParam(value = "classifyId", required = false) Long classifyId,
@RequestParam(value = "currentTime", required = false) String currentTime,
@RequestParam(value = "companyId") Long companyId,
@RequestParam(value = "siteId") Long siteId,
@RequestParam(value = "orgIds", required = false) List<Long> orgIds,
@RequestParam(value = "pageNo", defaultValue = "1") Integer pageNo,
@RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize
) {
RequestContext res = ContextHolder.get();
return certificateService.searchCertificateList(title, classifyId, companyId, siteId, orgIds, status, pageNo, pageSize, currentTime, res);
}
/**
* 根据证书名称模糊 查询证书列表(分页) company_id 项目id 为0的证书
*
* @return
*/
@GetMapping("/getlist")
public PageCertificateVo getList(@RequestBody ApiSeachCerticateVo ApiSeachCerticateVo
) {
Page<Certificate> page = certificateService.getCertificatePage(ApiSeachCerticateVo.getTitle(),
ApiSeachCerticateVo.getCompanyId(), ApiSeachCerticateVo.getSiteId(), ApiSeachCerticateVo.getOrgId(),
ApiSeachCerticateVo.getPageNo(), ApiSeachCerticateVo.getPageSize());
PageCertificateVo pageCertificateVo = new PageCertificateVo();
Page<CertificateVo> certificateVoPage = new Page<>();
BeanUtils.copyProperties(page, certificateVoPage);
certificateVoPage.setRecords(BeanCopyListUtil.copyListProperties(page.getRecords(), CertificateVo::new));
pageCertificateVo.setPage(certificateVoPage);
return pageCertificateVo;
}
/**
* 根据证书对象修改证书
* 基于对象操作,用于清空circleCount的数值,
* 解决更新后前端查询会显示出来
* 使用updateAllColumnById()不要使用updateById(),不然会忽略circleCount字段
*
* @return
*/
@PostMapping("/update")
public Boolean updateCertificate(@RequestBody Certificate certificate) {
Certificate certificateUpdate = certificateService.selectById(certificate.getId());
//certificateUpdate.setCode(certificate.getCode());
//certificateUpdate.setCreateById(certificate.getCreateById());
//certificateUpdate.setCreateByName(certificate.getCreateByName());
certificateUpdate.setTags(certificate.getTags());
certificateUpdate.setTitle(certificate.getTitle());
certificateUpdate.setLogourl(certificate.getLogourl());
certificateUpdate.setIssuer(certificate.getIssuer());
certificateUpdate.setType(certificate.getType());
certificateUpdate.setTemplate(certificate.getTemplate());
certificateUpdate.setTemplateId(certificate.getTemplateId());
certificateUpdate.setTemplateImage(certificate.getTemplateImage());
certificateUpdate.setRuleType(certificate.getRuleType());
certificateUpdate.setClassifyId(certificate.getClassifyId());
//1为固定有效 2为固定失效期 0或其他为永不过期
if (certificate.getType().equals(1)) {
certificateUpdate.setCircleCount(certificate.getCircleCount());
certificateUpdate.setCircleUnit(certificate.getCircleUnit());
certificateUpdate.setEndTime(null);
} else if (certificate.getType().equals(2)) {
certificateUpdate.setCircleCount(null);
certificateUpdate.setCircleUnit(null);
certificateUpdate.setEndTime(certificate.getEndTime());
} else {
certificateUpdate.setCircleCount(null);
certificateUpdate.setCircleUnit(null);
certificateUpdate.setEndTime(null);
}
// 获取请求上下文信息
RequestContext requestContext = ContextHolder.get();
// 用于获取当前用户的信息
certificateUpdate.setUpdateById(requestContext.getAccountId());
certificateUpdate.setUpdateByName(requestContext.getAccountName());
certificateUpdate.setUpdateTime(new Date());
return certificateService.updateAllColumnById(certificateUpdate);
}
/**
* 获得证书列表
*
* @return
*/
@GetMapping("/list")
public Page<CertificateVo> getCertificateList(@RequestBody CertificateVoList certificateVoList) {
// 获取证书列表
Page<CertificateVo> certificateVoPage = new Page<>();
BeanUtils.copyProperties(certificateService.listCertificate(certificateVoList),certificateVoPage);
certificateVoPage.setRecords(BeanCopyListUtil.copyListProperties(certificateService.listCertificate(certificateVoList).getRecords(), CertificateVo::new));
return certificateVoPage;
}
/**
* 获得证书模板列表
*
* @return
*/
@GetMapping("/template")
public List<TrCertificateTemplateVo> getTemplateList() {
List<TrCertificateTemplateVo> trCertificateTemplateVos = BeanCopyListUtil.copyListProperties(iTrCertificateTemplateService.getList(), TrCertificateTemplateVo::new);
return trCertificateTemplateVos;
}
/**
* 新增证书
*
* @return
*/
@PostMapping("/save")
public Boolean saveCertificate(@RequestBody Certificate certificate) {
certificate.setId(idGenerator.generate());
certificate.setCode(idGenerator.generate().toString());
certificate.setStatus(0);
//胡涛写
if (certificate.getType() == 1) {
Date date = new Date();
Calendar calendar = Calendar.getInstance();
//设置时间为当天晚上23:59:59,有效期最后一天24:00后证书失效
calendar.set(calendar.get(Calendar.YEAR), calendar.get(Calendar.MONTH), calendar.get(Calendar.DAY_OF_MONTH), 23, 59, 59);
// calendar.setTime(date);
int circleCount = certificate.getCircleCount();//获取其周期数值
int circleUnit = Integer.valueOf(certificate.getCircleUnit());//获取其周期单位(0为年、1为月、2为天)
switch (circleUnit) {
case 2:
calendar.add(Calendar.DAY_OF_MONTH, circleCount);
break;
case 1:
calendar.add(Calendar.MONTH, circleCount);
break;
case 0:
calendar.add(Calendar.YEAR, circleCount);
break;
}
date = calendar.getTime();//重新转为Date
if (StringUtils.isNotBlank(date.toString())) {
System.out.println(date);
certificate.setEndTime(date);
}
//
}
return certificateService.insert(certificate);
}
@ApiOperation(value = "根据证书id,选择是否启用,修改证书状态")
@PostMapping("/enable")
public Boolean enableCertificate(@RequestBody Certificate certificate1) {
// 根据证书Id查询证书对象
Certificate certificate = certificateService.selectById(certificate1.getId());
if (certificate != null) {
if (certificate.getStatus() != null) {
// 修改证书状态
if (certificate1.getStatus() == 0) {
//如果是下架需要验证是否有关联活动
RelationActivities relationActivities = new RelationActivities();
relationActivities.setRelationState(1);
relationActivities.setCertificateId(certificate1.getId());
List<RelationActivities> list = relationActivitiesService.selectList(new EntityWrapper<>(relationActivities));
if (!CollectionUtils.isEmpty(list)) {
return false;
}
certificate.setStatus(0);
} else if (certificate1.getStatus() == 1) {
certificate.setStatus(1);
}
}
}
// 调用修改方法
certificateService.updateById(certificate);
return true;
}
/**
* 根据证书id,查询单个证书信息,返回证书对象
*
* @return
*/
@GetMapping("/get")
public CertificateListVO getCertificate(@RequestParam(value = "id") Long id) {
Certificate certificate = certificateService.selectById(id);
CertificateListVO certificateListVO = new CertificateListVO();
BeanUtils.copyProperties(certificate, certificateListVO);
if (null != certificate.getClassifyId()) {
CertificateClassify certificateClassify = classifyService.selectById(certificate.getClassifyId());
if (certificateClassify.getLevel() == 2) {
certificateListVO.setOneLevelId(certificateClassify.getParentId());
} else if (certificateClassify.getLevel() == 3) {
certificateListVO.setOneLevelId(certificateClassify.getRootId());
certificateListVO.setTwoLevelId(certificateClassify.getParentId());
}
}
return certificateListVO;
}
/**
* 根据证书id,复制单个证书信息,数据库新增一条数据,证书信息完全一致但名称修改为“***证书【复制件】:证书状态为“下架
*
* @return
*/
@PostMapping("/copy")
public Boolean copyCertificate(@RequestBody Certificate certificate2) {
System.out.println(certificate.getId() + "~~~~~~~~~~~~");
// 根据证书id查询证书信息
Certificate certificate = certificateService.selectById(certificate2.getId());
Certificate certificate1 = new Certificate();
System.out.println(certificate2 + "*********************");
if (certificate != null) {
// 将查询到的证书信息复制(添加)到数据库
certificate1.setId(idGenerator.generate());
certificate1.setCode(idGenerator.generate().toString());
certificate1.setSiteId(certificate.getSiteId());
certificate1.setIssuer(certificate.getIssuer());
certificate1.setTitle(certificate.getTitle() + "【复制件】");
certificate1.setTemplate(certificate.getTemplate());
certificate1.setCreateById(ContextHolder.get().getAccountId());
certificate1.setCreateByName(ContextHolder.get().getAccountName());
certificate1.setCreateTime(new Date());
certificate1.setUpdateById(ContextHolder.get().getAccountId());
certificate1.setUpdateByName(ContextHolder.get().getAccountName());
certificate1.setUpdateTime(new Date());
certificate1.setTags(certificate.getTags());
certificate1.setCompanyId(certificate.getCompanyId());
certificate1.setOrgId(certificate.getOrgId());
certificate1.setLogourl(certificate.getLogourl());
certificate1.setType(certificate.getType());
certificate1.setCircleCount(certificate.getCircleCount());
certificate1.setEndTime(certificate.getEndTime());
certificate1.setStatus(0);
certificate1.setCircleUnit(certificate.getCircleUnit());
certificate1.setTemplateId(certificate.getTemplateId());
certificate1.setTemplateImage(certificate.getTemplateImage());
certificate1.setRuleType(certificate.getRuleType());
certificate1.setClassifyId(certificate.getClassifyId());
// 调用添加方法
Boolean f = certificateService.insert(certificate1);
if (f) {
return f;
} else {
return Boolean.FALSE;
}
} else {
return Boolean.FALSE;
}
}
/**
* 自定义模板保存
*
* @param trCertificateTemplate
* @return
*/
@PostMapping("/template/save")
public TrCertificateTemplateVo saveTemplate(@RequestBody TrCertificateTemplate trCertificateTemplate) {
trCertificateTemplate.setId(idGenerator.generate());
TrCertificateTemplateVo trCertificateTemplateVo = new TrCertificateTemplateVo();
iTrCertificateTemplateService.insert(trCertificateTemplate);
BeanUtils.copyProperties(trCertificateTemplate, trCertificateTemplateVo);
return trCertificateTemplateVo;
}
@GetMapping(value = "/by/new/server")
public List<Map<String, Object>> getServerByCompanyIdAndIds(@RequestParam("companyId") Long companyId, @RequestParam(value = "ids", required = false) List<Long> ids) {
return certificateService.getServerByCompanyIdAndIds(companyId, ids);
}
@GetMapping("/searchCertificateList/export")
String searchCertificateListExport(
@RequestParam(value = "title", required = false) String title,
@RequestParam(value = "status", required = false) Integer status,
@RequestParam(value = "classifyId", required = false) Long classifyId,
@RequestParam(value = "currentTime", required = false) String currentTime
) {
Map<String, Object> map = new HashMap<>(16);
RequestContext res = ContextHolder.get();
Long taskId = idGenerator.generate();
String serialNo = "CERTIFICATE-LIST-EXPORT-" + taskId.toString();
String taskName = "证书清单导出-" + taskId.toString();
map.put("res", res);
map.put("taskId", taskId);
map.put("serialNo", serialNo);
map.put("taskName", taskName);
map.put("title", title);
map.put("status", status);
map.put("classifyId", classifyId);
map.put("currentTime", currentTime);
certificateListExport.execute(map, true);
return serialNo;
}
@PostMapping("/relateProject")
Boolean relateProject(@RequestBody RelateCertificateParam relateCertificateParam) {
return certificateService.relateProject(relateCertificateParam);
}
@GetMapping("/cancelRelate")
Boolean cancelRelate(@RequestParam("bizdType") Integer bizdType,
@RequestParam(value = "certificateId", required = false) Long certificateId,
@RequestParam(value = "bizdId", required = false) Long bizdId,
@RequestParam(value = "tpPlanId", required = false) Long tpPlanId) {
RequestContext res = ContextHolder.get();
RelationActivities relationActivities = new RelationActivities();
if (null != certificateId) {
relationActivities.setCertificateId(certificateId);
}
relationActivities.setBizdType(bizdType);
if (null != bizdId) {
relationActivities.setBizdId(bizdId);
}
relationActivities.setRelationState(1);
//如果关联培训项目,需要计划id
if (bizdType == 0) {
if (null != tpPlanId) {
relationActivities.setTpPlanId(tpPlanId);
}
}
List<RelationActivities> list = relationActivitiesService.selectList(new EntityWrapper<>(relationActivities));
if (!CollectionUtils.isEmpty(list)) {
for (RelationActivities relationActivities1 : list) {
relationActivities1.setUpdateById(res.getAccountId());
relationActivities1.setUpdateByName(res.getAccountName());
relationActivities1.setUpdateTime(new Date());
relationActivities1.setRelationState(0);
}
} else {
return true;
}
relationActivitiesService.updateBatchById(list);
return true;
}
@GetMapping("/getRelationActivities")
List<RelationActivitiesVo> getRelationActivities(@RequestParam("certificateId") Long certificateId) {
List<RelationActivitiesVo> relationActivitiesVos = BeanCopyListUtil.copyListProperties(relationActivitiesService.getRelationActivities(certificateId), RelationActivitiesVo::new);
return relationActivitiesVos;
}
@GetMapping("/getCertificateMap")
Map<Long, Certificate> getCertificateMap(@RequestBody List<Long> certificateIds) {
return certificateService.getCertificateMap(certificateIds);
}
@PostMapping("/getCertificateNum")
Integer getCertificateNum(@RequestBody CertificateNumParam certificateNumParam) {
return certificateService.getCertificateNum(certificateNumParam);
}
}
package com.yizhi.certificate.application.controller;
import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.yizhi.certificate.application.domain.Certificate;
import com.yizhi.certificate.application.domain.TrUserCertificate;
import com.yizhi.application.orm.id.IdGenerator;
import com.yizhi.certificate.application.service.ICertificateService;
import com.yizhi.certificate.application.service.ITrUserCertificateService;
import com.yizhi.certificate.application.util.CertificateCodeLock;
import com.yizhi.certificate.application.vo.ApiSeachCerticateVo;
import com.yizhi.certificate.application.vo.PushCertificateParam;
import com.yizhi.certificate.application.vo.domain.TrUserCertificateVo;
import com.yizhi.core.application.context.RequestContext;
import com.yizhi.core.application.event.EventWrapper;
import com.yizhi.core.application.publish.CloudEventPublisher;
import com.yizhi.core.application.task.AbstractTaskHandler;
import com.yizhi.core.application.task.TaskExecutor;
import com.yizhi.system.application.system.remote.AccountClient;
import com.yizhi.system.application.vo.AccountVO;
import com.yizhi.util.application.beanutil.BeanCopyListUtil;
import com.yizhi.util.application.constant.QueueConstant;
import com.yizhi.util.application.constant.TpActivityType;
import com.yizhi.util.application.event.TrainingProjectEvent;
import io.swagger.annotations.Api;
import org.apache.commons.lang3.StringUtils;
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.*;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
@Api(tags = "PC端证书api", description = "PC端证书接口")
@RestController
@RequestMapping("/certificatePc")
public class CertificateStuPcController {
private static final Logger logger = LoggerFactory.getLogger(CertificateController.class);
@Autowired
private ITrUserCertificateService trUserCertificateService;
@Autowired
ICertificateService iCertificateService;
@Autowired
CertificateCodeLock lock;
@Autowired
private TaskExecutor taskExecutor;
@Autowired
private CloudEventPublisher cloudEventPublisher;
@Autowired
private AccountClient accountClient;
@Autowired
private IdGenerator idGenerator;
/**
* 获取 PC端 我的证书列表
*
* @return
*/
@GetMapping("/list")
Page<TrUserCertificateVo> list(@RequestBody ApiSeachCerticateVo apiSeachCerticateVo) {
Page<TrUserCertificate> trUserCertificates = trUserCertificateService.getMyList(apiSeachCerticateVo.getAccountId(),
apiSeachCerticateVo.getTitle(),
apiSeachCerticateVo.getValidityType(), apiSeachCerticateVo.getCompanyId(), apiSeachCerticateVo.getSiteId(),
apiSeachCerticateVo.getPageNo(), apiSeachCerticateVo.getPageSize());
Page<TrUserCertificateVo> trUserCertificateVoPage = new Page<>();
BeanUtils.copyProperties(trUserCertificates, trUserCertificateVoPage);
trUserCertificateVoPage.setRecords(BeanCopyListUtil.copyListProperties(trUserCertificates.getRecords(), TrUserCertificateVo::new));
return trUserCertificateVoPage;
}
// /**
// * 根据学员证书中间表id 获取图片和证书名称( PC端 )
// *
// * @param id
// * @return
// */
// @GetMapping("/imageView")
// public TrUserCertificatePcVo view(
// @RequestParam(value = "id") Long id,
// @RequestParam(value = "accountId") Long accountId
// ){
// TrUserCertificate trUserCertificate = new TrUserCertificate();
// trUserCertificate.setAccountId(accountId);
// trUserCertificate.setCertificateId(id);
// EntityWrapper<TrUserCertificate> entityWrapper = new EntityWrapper<TrUserCertificate>(trUserCertificate);
//
// TrUserCertificate tc = trUserCertificateService.selectOne(entityWrapper);
// TrUserCertificatePcVo vo = new TrUserCertificatePcVo();
// if (tc != null){
//
// vo.setCertificateTitle(tc.getCertificateTitle());
// vo.setCertificateLogourl(tc.getCertificateLogourl());
// vo.setCertificateId(tc.getCertificateId());
//
// //相对路径( 去除 http://fulan-test.oss-cn-hangzhou.aliyuncs.com/)
// String imageStr = tc.getUserImage();
// String unOss = "http://fulan-test.oss-cn-hangzhou.aliyuncs.com/";
//
// vo.setUserImage(imageStr);
// if (!StringUtils.isEmpty(imageStr)){
// vo.setUnOssImage(imageStr.replace(unOss,""));
// }
// }
//
// return vo;
// }
/**
* 获取我的证书对象 (PC端 证书查看和下载)
*
* @return
*/
@GetMapping("/imageView")
public TrUserCertificateVo getCertificate(@RequestParam(value = "id") Long id) {
TrUserCertificate trUserCertificate = trUserCertificateService.selectById(id);
if (null == trUserCertificate){
return null;
}
Certificate certificate = iCertificateService.selectById(trUserCertificate.getCertificateId());
if (StringUtils.isBlank(trUserCertificate.getCertificateCode())) {
lock.addCertificateCode(certificate, trUserCertificate);
trUserCertificate.setCertificateLogourl(certificate.getTemplateImage());
trUserCertificate.setIssuer(certificate.getIssuer());
}
boolean isOk = trUserCertificateService.updateById(trUserCertificate);
if (org.springframework.util.StringUtils.isEmpty(trUserCertificate)) {
logger.info("*******************************getCertificate=" + JSON.toJSONString(trUserCertificate));
return null;
}
//其他业务也可关联证书,发放也要向培训项目发消息
if (isOk) {
toProject(trUserCertificate, certificate.getSiteId());
}
TrUserCertificateVo trUserCertificateVo = new TrUserCertificateVo();
BeanUtils.copyProperties(trUserCertificate, trUserCertificateVo);
return trUserCertificateVo;
}
@GetMapping("/view")
public TrUserCertificateVo view(
@RequestParam(value = "id") Long id,
@RequestParam(value = "accountId") Long accountId,
@RequestParam(value = "projectId") Long projectId,
@RequestParam(value = "type") Integer type
) {
TrUserCertificate trUserCertificate = new TrUserCertificate();
trUserCertificate.setAccountId(accountId);
trUserCertificate.setCertificateId(id);
EntityWrapper<TrUserCertificate> entityWrapper = new EntityWrapper<TrUserCertificate>(trUserCertificate);
TrUserCertificate trUserCertificate1 = trUserCertificateService.selectOne(entityWrapper);
Certificate certificate = iCertificateService.selectById(trUserCertificate1.getCertificateId());
if (StringUtils.isBlank(trUserCertificate1.getCertificateCode())) {
lock.addCertificateCode(certificate, trUserCertificate1);
trUserCertificate1.setCertificateLogourl(certificate.getTemplateImage());
trUserCertificate1.setIssuer(certificate.getIssuer());
}
boolean isOk = trUserCertificateService.updateById(trUserCertificate1);
if (isOk) {
toProject(trUserCertificate, certificate.getSiteId());
}
TrUserCertificateVo trUserCertificateVo = new TrUserCertificateVo();
BeanUtils.copyProperties(trUserCertificate1, trUserCertificateVo);
return trUserCertificateVo;
}
/**
* 给项目发送证书完成消息
*/
private void toProject(final TrUserCertificate trUserCertificate, final Long siteId) {
taskExecutor.asynExecute(new AbstractTaskHandler() {
public void handle() {
try {
cloudEventPublisher.publish(QueueConstant.TRAINING_PROJECT_EVENT_QUEUE,
new EventWrapper<TrainingProjectEvent>(trUserCertificate.getCertificateId(),
TrainingProjectEvent.getInstance(trUserCertificate.getCertificateId(),
TpActivityType.TYPE_CERTIFICATE, trUserCertificate.getAccountId(),
new Date(), siteId, null, Boolean.TRUE)));
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
@PostMapping("/pushCertificate")
public TrUserCertificateVo pushCertificate(@RequestBody PushCertificateParam pushCertificateParam) {
TrUserCertificateVo trUserCertificateVo = new TrUserCertificateVo();
RequestContext res = pushCertificateParam.getRes();
// 验证此人是否已经获得改证书
TrUserCertificate vailHas = new TrUserCertificate();
Integer bizdType = pushCertificateParam.getType();
vailHas.setCertificateId(pushCertificateParam.getCertificateId());
vailHas.setAccountId(res.getAccountId());
EntityWrapper<TrUserCertificate> entityWrapper = new EntityWrapper<TrUserCertificate>(vailHas);
TrUserCertificate tuc = trUserCertificateService.selectOne(entityWrapper);
if (null != tuc) {
logger.error("该学员已获得此证书");
BeanUtils.copyProperties(tuc, trUserCertificateVo);
return trUserCertificateVo;
}
// 验证证书是否存在
Certificate certificate = iCertificateService.selectById(pushCertificateParam.getCertificateId());
if (null != certificate) {
AccountVO accountVO = accountClient.findById(res.getAccountId());
TrUserCertificate trUserCertificate = new TrUserCertificate();
trUserCertificate.setId(idGenerator.generate());
trUserCertificate.setCreateTime(new Date());
trUserCertificate.setCertificateId(pushCertificateParam.getCertificateId());
trUserCertificate.setCertificateTitle(certificate.getTitle());
trUserCertificate.setCertificateLogourl(certificate.getTemplateImage());
trUserCertificate.setAccountId(res.getAccountId());
if (null != accountVO) {
trUserCertificate.setAccountName(accountVO.getName());
trUserCertificate.setUserName(accountVO.getFullName());
}
trUserCertificate.setBizdType(bizdType);
if (bizdType == 1) {
//课程
trUserCertificate.setTpPlanId(pushCertificateParam.getBizdId());
trUserCertificate.setTpPlanName(pushCertificateParam.getBizdName());
}
trUserCertificate.setType(certificate.getType());// 设置过期类型
lock.addCertificateCode(certificate, trUserCertificate);
if (StringUtils.isNotBlank(pushCertificateParam.getScore())) {
trUserCertificate.setScore(pushCertificateParam.getScore());
} else {
trUserCertificate.setScore("0");
}
trUserCertificate.setIssuer(certificate.getIssuer());
trUserCertificate.setCompanyId(certificate.getCompanyId());
trUserCertificate.setSiteId(certificate.getSiteId());
// AccountVO accountVO =
// iCertificateService.getAccountVO(accountId);
// trUserCertificate.setUserName(accountVO.getFullName());
// trUserCertificate.setAccountName(accountVO.getName());
// trUserCertificate.setCompanyName(accountVO.getCompanyName());
if (0 == certificate.getType()) {
SimpleDateFormat dft = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
try {
trUserCertificate.setEndTime(dft.parse("2038-01-19 01:14:07"));
} catch (Exception e) {
e.printStackTrace();
}
}
if (1 == certificate.getType()) {
//设置时间为当天晚上23:59:59,有效期最后一天24:00后证书失效
Calendar date = Calendar.getInstance();
date.set(date.get(Calendar.YEAR),
date.get(Calendar.MONTH), date.get(Calendar.DAY_OF_MONTH), 23, 59, 59);
if ("0".equals(certificate.getCircleUnit())) {
date.add(Calendar.YEAR, certificate.getCircleCount());
trUserCertificate.setEndTime(date.getTime());
}
if ("1".equals(certificate.getCircleUnit())) {
date.add(Calendar.MONTH, certificate.getCircleCount());
trUserCertificate.setEndTime(date.getTime());
}
if ("2".equals(certificate.getCircleUnit())) {
date.add(Calendar.DAY_OF_MONTH, certificate.getCircleCount());
trUserCertificate.setEndTime(date.getTime());
}
}
if (2 == certificate.getType()) {
trUserCertificate.setEndTime(certificate.getEndTime());
}
if (trUserCertificateService.insert(trUserCertificate)) {
toProject(trUserCertificate, certificate.getSiteId());
}
BeanUtils.copyProperties(trUserCertificate, trUserCertificateVo);
return trUserCertificateVo;
}
return null;
}
}
package com.yizhi.certificate.application.controller;
import com.baomidou.mybatisplus.plugins.Page;
import com.yizhi.certificate.application.asynchronousTask.CertificateStatisticExport;
import com.yizhi.application.orm.id.IdGenerator;
import com.yizhi.certificate.application.service.CertificateUserService;
import com.yizhi.certificate.application.vo.CertificateListVO;
import com.yizhi.certificate.application.vo.CertificateUserListVO;
import com.yizhi.certificate.application.vo.TrUserCertificateDetailsVo;
import com.yizhi.core.application.context.ContextHolder;
import com.yizhi.core.application.context.RequestContext;
import io.swagger.annotations.Api;
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.List;
import java.util.Map;
@Api(tags = "学员证书 管理端", description = "学员证书 管理端")
@RestController
@RequestMapping("/manage/certificate/user")
public class CertificateUserController {
@Autowired
CertificateUserService certificateUserService;
@Autowired
private IdGenerator idGenerator;
@Autowired
private CertificateStatisticExport certificateStatisticExport;
@GetMapping("/rank/list")
public Page<CertificateUserListVO> userRankList(
@RequestParam(name = "startDate", required = false) String startDate,
@RequestParam(name = "endDate", required = false) String endDate,
@RequestParam(name = "pageNo", required = false) Integer pageNo,
@RequestParam(name = "pageSize", required = false) Integer pageSize,
@RequestParam(name = "siteId", required = false) Long siteId,
@RequestParam(name = "companyId", required = false) Long companyId,
@RequestParam(name = "userName", required = false) String userName,
@RequestParam(name = "orgNameLike", required = false) String orgNameLike,
@RequestParam(name = "orgIds", required = false) List<Long> orgIds,
@RequestParam(name = "isAdmin", required = true) boolean isAdmin,
@RequestParam(name = "accountId", required = true) Long accountId) {
return certificateUserService.userRankList(startDate, endDate, pageNo, pageSize, siteId,
companyId, userName, orgNameLike, orgIds, isAdmin, accountId);
}
@GetMapping("/details")
public Page<TrUserCertificateDetailsVo> userDetails(@RequestParam(name = "startDate", required = false) String startDate,
@RequestParam(name = "endDate", required = false) String endDate,
@RequestParam(name = "pageNo", required = false) Integer pageNo,
@RequestParam(name = "pageSize", required = false) Integer pageSize,
@RequestParam(name = "siteId", required = false) Long siteId,
@RequestParam(name = "companyId", required = false) Long companyId,
@RequestParam(name = "userName", required = false) String userName,
@RequestParam(name = "orgNameLike", required = false) String orgNameLike,
@RequestParam(name = "orgIds", required = false) List<Long> orgIds,
@RequestParam(name = "isAdmin", required = true) boolean isAdmin,
@RequestParam(name = "accountId", required = true) Long accountId) {
return certificateUserService.userDetails(startDate, endDate, pageNo, pageSize, siteId, companyId, userName, orgNameLike, orgIds, isAdmin, accountId);
}
@GetMapping("/certificate/list")
public Page<CertificateListVO> certificateList(
@RequestParam(name = "startDate", required = false) String startDate,
@RequestParam(name = "endDate", required = false) String endDate,
@RequestParam(name = "pageNo", required = false) Integer pageNo,
@RequestParam(name = "pageSize", required = false) Integer pageSize,
@RequestParam(name = "certificateName", required = false) String certificateName) {
RequestContext res = ContextHolder.get();
return certificateUserService.certificateList(startDate, endDate, certificateName, pageNo, pageSize, res);
}
@GetMapping("/certificate/export")
public String certificateListExport(
@RequestParam(name = "startDate", required = false) String startDate,
@RequestParam(name = "endDate", required = false) String endDate,
@RequestParam(name = "certificateName", required = false) String certificateName) {
Map<String, Object> map = new HashMap<>(16);
RequestContext res = ContextHolder.get();
Long taskId = idGenerator.generate();
String serialNo = "CERTIFICATE-STATISTICS-EXPORT-" + taskId.toString();
String taskName = "按证书统计-" + taskId.toString();
map.put("res", res);
map.put("taskId", taskId);
map.put("serialNo", serialNo);
map.put("taskName", taskName);
map.put("startDate", startDate);
map.put("endDate", endDate);
map.put("certificateName", certificateName);
certificateStatisticExport.execute(map, true);
return serialNo;
}
}
package com.yizhi.certificate.application.controller;
import com.yizhi.certificate.application.domain.CertificateClassify;
import com.yizhi.certificate.application.feign.CertificateClassifyClient;
import com.yizhi.certificate.application.service.IClassifyService;
import com.yizhi.certificate.application.vo.CertificateClassifyListVO;
import com.yizhi.certificate.application.vo.domain.CertificateClassifyVo;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.List;
/**
* <p>
* 前端控制器
* </p>
*
* @author dingxiaowei123
* @since 2019-12-23
*/
@RestController
@RequestMapping
public class ClassifyController implements CertificateClassifyClient {
@Autowired
private IClassifyService classifyService;
@Override
public Integer insertClassify(@RequestBody CertificateClassifyVo certificateClassify) {
CertificateClassify classify = new CertificateClassify();
BeanUtils.copyProperties(certificateClassify, classify);
return classifyService.insertClassify(classify);
}
@Override
public List<CertificateClassifyListVO> getClassifyList() {
return classifyService.getClassifyList();
}
@Override
public boolean updateClassify(@RequestBody CertificateClassifyVo certificateClassify) {
CertificateClassify classify = new CertificateClassify();
BeanUtils.copyProperties(certificateClassify, classify);
return classifyService.updateClassify(classify);
}
@Override
public Integer deleteClassify(Long id) {
return classifyService.deleteClassify(id);
}
}
package com.yizhi.certificate.application.controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.stereotype.Controller;
/**
* <p>
* 学员证书中间表 前端控制器
* </p>
*
* @author dingxiaowei123
* @since 2019-12-30
*/
@Controller
@RequestMapping("/relationActivities")
public class RelationActivitiesController {
}
package com.yizhi.certificate.application.domain;
import com.baomidou.mybatisplus.activerecord.Model;
import com.baomidou.mybatisplus.annotations.TableField;
import com.baomidou.mybatisplus.annotations.TableName;
import com.baomidou.mybatisplus.enums.FieldFill;
import com.fasterxml.jackson.annotation.JsonFormat;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.io.Serializable;
import java.util.Date;
/**
* <p>
* <p>
* </p>
*
* @author fulan123
* @since 2018-03-07
*/
@Data
@Api(tags = "Certificate", description = "证书")
@TableName("certificate")
public class Certificate extends Model<Certificate> {
private static final long serialVersionUID = 1L;
private Long id;
@ApiModelProperty(value = "证书编号")
private String code;
@ApiModelProperty(value = "证书编号规则类型 0:获取时间+六位顺序编号 | 1:六位顺序编号")
@TableField("rule_type")
private Integer ruleType;
@ApiModelProperty(value = "发行机构")
private String issuer;
@ApiModelProperty(value = "证书标题")
private String title;
@ApiModelProperty("分类id")
@TableField("classify_id")
private Long classifyId;
@ApiModelProperty(value = "模板")
private String template;
@TableField(value = "create_by_id", fill = FieldFill.INSERT)
private Long createById;
@TableField(value = "create_by_name", fill = FieldFill.INSERT)
private String createByName;
@TableField(value = "create_time", fill = FieldFill.INSERT)
private Date createTime;
@TableField(value = "update_by_id", fill = FieldFill.INSERT)
private Long updateById;
@TableField(value = "update_by_name", fill = FieldFill.INSERT)
private String updateByName;
@TableField(value = "update_time")
private Date updateTime;
@ApiModelProperty(value = "证书标签,用,分割")
private String tags;
@ApiModelProperty(value = "企业id")
@TableField("company_id")
private Long companyId;
@ApiModelProperty(value = "部门id")
@TableField("org_id")
private Long orgId;
@ApiModelProperty(value = "广告url")
private String logourl;
@ApiModelProperty(value = "过期类型")
private Integer type;
@ApiModelProperty(value = "固定周期数")
@TableField("circle_count")
private Integer circleCount;
@ApiModelProperty(value = "失效日期")
@TableField("end_time")
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss",timezone="GMT+8")
private Date endTime;
@ApiModelProperty(value = "证书状态 0:下架 1:上架 2:草稿 3:删除")
private Integer status;
@ApiModelProperty(value = "过期单位")
@TableField("circle_unit")
private String circleUnit;
@TableField("template_id")
private Long templateId;
@TableField("template_image")
private String templateImage;
@ApiModelProperty(value = "站点id")
@TableField("site_id")
private Long siteId;
@ApiModelProperty(value = "项目/课程id")
@TableField("training_project_id")
private Long trainingProjectId;
@ApiModelProperty(value = "项目/课程名称")
@TableField("training_project_name")
private String trainingProjectName;
@Override
protected Serializable pkVal() {
return this.id;
}
}
package com.yizhi.certificate.application.domain;
import com.baomidou.mybatisplus.annotations.TableField;
import com.baomidou.mybatisplus.annotations.TableName;
import com.baomidou.mybatisplus.enums.FieldFill;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.util.Date;
/**
* <p>
* 文件夹分类表
* </p>
*
* @author dingxiaowei123
* @since 2019-12-23
*/
@Data
@ApiModel(value = "Classify", description = "文件夹分类表")
@TableName("certificate_classify")
public class CertificateClassify {
private static final long serialVersionUID = 1L;
private Long id;
@ApiModelProperty("分类名称")
private String name;
@ApiModelProperty("分类编码")
private Integer code;
@ApiModelProperty(value = "1:一级分类 2:二级分类 3:三级分类")
private Integer level;
@ApiModelProperty(value = "分类描述")
private String description;
@ApiModelProperty(value = "父级id 0为一级分类没有父级")
@TableField("parent_id")
private Long parentId;
@ApiModelProperty("顶级分类id")
@TableField("root_id")
private Long rootId;
@ApiModelProperty(value = "分类排序")
private Integer sort;
@TableField(value = "create_by_id", fill = FieldFill.INSERT)
private Long createById;
@TableField(value = "create_by_name", fill = FieldFill.INSERT)
private String createByName;
@TableField(value = "create_time", fill = FieldFill.INSERT)
private Date createTime;
@TableField(value = "update_by_id", fill = FieldFill.INSERT)
private Long updateById;
@TableField(value = "update_by_name", fill = FieldFill.INSERT)
private String updateByName;
@TableField(value = "update_time", fill = FieldFill.INSERT)
private Date updateTime;
@TableField("company_id")
private Long companyId;
@TableField("site_id")
private Long siteId;
@TableField("org_id")
private Long orgId;
@ApiModelProperty(value = "(0:删除, 1:未删除)")
private Integer state;
}
package com.yizhi.certificate.application.domain;
import com.baomidou.mybatisplus.annotations.TableField;
import com.baomidou.mybatisplus.annotations.TableName;
import com.baomidou.mybatisplus.enums.FieldFill;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.util.Date;
/**
* <p>
* 学员证书中间表
* </p>
*
* @author dingxiaowei123
* @since 2019-12-30
*/
@Data
@ApiModel(value = "RelationActivities", description = "学员证书中间表")
@TableName("relation_activities")
public class RelationActivities {
private static final long serialVersionUID = 1L;
@ApiModelProperty(value = "主键id")
private Long id;
@ApiModelProperty(value = "证书id")
@TableField("certificate_id")
private Long certificateId;
@ApiModelProperty(value = "关联活动类型0:培训项目 1:课程")
@TableField("bizd_type")
private Integer bizdType;
@ApiModelProperty(value = "活动名称")
@TableField("bizd_name")
private String bizdName;
@ApiModelProperty(value = "活动id")
@TableField("bizd_id")
private Long bizdId;
@ApiModelProperty(value = "如果是培训项目关联计划id")
@TableField("tp_plan_id")
private Long tpPlanId;
@ApiModelProperty(value = "如果是培训项目,计划名称")
@TableField("tp_plan_name")
private String tpPlanName;
@TableField(value = "create_by_id", fill = FieldFill.INSERT)
private Long createById;
@TableField(value = "create_by_name", fill = FieldFill.INSERT)
private String createByName;
@TableField(value = "create_time", fill = FieldFill.INSERT)
private Date createTime;
@TableField(value = "update_by_id", fill = FieldFill.INSERT)
private Long updateById;
@TableField(value = "update_by_name", fill = FieldFill.INSERT)
private String updateByName;
@TableField(value = "update_time", fill = FieldFill.INSERT)
private Date updateTime;
@TableField("company_id")
private Long companyId;
@TableField("site_id")
private Long siteId;
@ApiModelProperty(value = "关联状态 0:无效 1:有效")
@TableField("relation_state")
private Integer relationState;
}
package com.yizhi.certificate.application.domain;
import com.baomidou.mybatisplus.activerecord.Model;
import com.baomidou.mybatisplus.annotations.TableField;
import com.baomidou.mybatisplus.annotations.TableName;
import com.baomidou.mybatisplus.enums.FieldFill;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.io.Serializable;
import java.util.Date;
/**
* <p>
* 证书模板表
* </p>
*
* @author fulan123
* @since 2018-03-07
*/
@Data
@Api(tags = "TrCertificateTemplate", description = "证书模板表")
@TableName("tr_certificate_template")
public class TrCertificateTemplate extends Model<TrCertificateTemplate> {
private static final long serialVersionUID = 1L;
private Long id;
@ApiModelProperty(value = "模板url")
@TableField("template_url")
private String templateUrl;
@ApiModelProperty(value = "模板类型")
@TableField("type")
private Integer type;
@ApiModelProperty(value = "模板缩略图")
@TableField("template_image")
private String templateImage;
@ApiModelProperty(value = "模板名称")
@TableField("template_name")
private String templateName;
@TableField(value = "create_by_id", fill = FieldFill.INSERT)
private Long createById;
@TableField(value = "create_by_name", fill = FieldFill.INSERT)
private String createByName;
@TableField(value = "create_time", fill = FieldFill.INSERT)
private Date createTime;
@Override
protected Serializable pkVal() {
return this.id;
}
}
package com.yizhi.certificate.application.domain;
import com.baomidou.mybatisplus.activerecord.Model;
import com.baomidou.mybatisplus.annotations.TableField;
import com.baomidou.mybatisplus.annotations.TableName;
import com.baomidou.mybatisplus.enums.FieldFill;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.io.Serializable;
import java.util.Date;
/**
* <p>
* 学员证书中间表
* </p>
*
* @author fulan123
* @since 2018-03-07
*/
@Data
@Api(tags = "TrUserCertificate", description = "学员证书中间表")
@TableName("tr_user_certificate")
public class TrUserCertificate extends Model<TrUserCertificate> {
private static final long serialVersionUID = 1L;
@ApiModelProperty(value = "主键id")
private Long id;
@ApiModelProperty(value = "学员id")
@TableField("user_id")
private Long userId;
@ApiModelProperty(value = "证书id")
@TableField("certificate_id")
private Long certificateId;
@TableField(value = "create_by_id", fill = FieldFill.INSERT)
private Long createById;
@TableField(value = "create_by_name", fill = FieldFill.INSERT)
private String createByName;
@TableField(value = "create_time", fill = FieldFill.INSERT)
private Date createTime;
@TableField("company_id")
private Long companyId;
@ApiModelProperty(value = "企业名称")
@TableField("company_name")
private String companyName;
@ApiModelProperty(value = "账号id")
@TableField("account_id")
private Long accountId;
@ApiModelProperty(value = "账号名")
@TableField("account_name")
private String accountName;
@TableField("user_name")
private String userName;
@TableField("training_project_name")
private String trainingProjectName;
@TableField("training_project_id")
private Long trainingProjectId;
@TableField("bizd_type")
private Integer bizdType;
private String issuer;
@ApiModelProperty(value = "失效时间")
@TableField("end_time")
private Date endTime;
@ApiModelProperty(value = "得分")
private String score;
@ApiModelProperty(value = "证书名称")
@TableField("certificate_title")
private String certificateTitle;
@ApiModelProperty(value = "证书缩略图")
@TableField("certificate_logourl")
private String certificateLogourl;
@ApiModelProperty(value = "学员证书生成图片")
@TableField("user_image")
private String userImage;
@ApiModelProperty(value = "站点id")
@TableField("site_id")
private Long siteId;
@ApiModelProperty(value = "过期类型")
@TableField("type")
private Integer type;
@ApiModelProperty(value = "证书编号")
@TableField("certificate_code")
private String certificateCode;
@TableField("tp_plan_id")
private Long tpPlanId;
@ApiModelProperty(value = "计划名称")
@TableField("tp_plan_name")
private String tpPlanName;
@Override
protected Serializable pkVal() {
return this.id;
}
}
/**
* FileName: MyCertificateListener
* Author: wenjunlong
* Date: 2018/6/28 17:33
* Description: 监听 学员获得证书
* History:
* <author> <time> <version> <desc>
* 作者姓名 修改时间 版本号 描述
*/
package com.yizhi.certificate.application.listener;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.yizhi.certificate.application.domain.Certificate;
import com.yizhi.certificate.application.domain.TrUserCertificate;
import com.yizhi.application.orm.id.IdGenerator;
import com.yizhi.certificate.application.service.ICertificateService;
import com.yizhi.certificate.application.service.ITrUserCertificateService;
import com.yizhi.certificate.application.util.CertificateCodeLock;
import com.yizhi.core.application.event.EventWrapper;
import com.yizhi.core.application.publish.CloudEventPublisher;
import com.yizhi.core.application.task.AbstractTaskHandler;
import com.yizhi.core.application.task.TaskExecutor;
import com.yizhi.system.application.system.remote.AccountClient;
import com.yizhi.system.application.vo.AccountVO;
import com.yizhi.util.application.constant.QueueConstant;
import com.yizhi.util.application.constant.TpActivityType;
import com.yizhi.util.application.event.TrainingProjectEvent;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.Map;
/**
* 〈一句话功能简述〉<br>
* 〈监听 学员获得证书〉
*
* @author wenjunlong
* @create 2018/6/28
* @since 1.0.0
*/
@Component
public class MyCertificateListener {
private static final Logger LOG = LoggerFactory.getLogger(MyCertificateListener.class);
@Autowired
ICertificateService iCertificateService;
@Autowired
ITrUserCertificateService trUserCertificateService;
@Autowired
IdGenerator idGenerator;
@Autowired
private TaskExecutor taskExecutor;
@Autowired
private CloudEventPublisher cloudEventPublisher;
@Autowired
private CertificateCodeLock lock;
@Autowired
private AccountClient accountClient;
@RabbitListener(queues = "myCertificate")
@Transactional
public void processMyCertifucate(EventWrapper eventWrapper) {
LOG.info("", eventWrapper);
Map<String, Object> json = (Map<String, Object>) eventWrapper.getData();
// 验证必要参数
Boolean vailParam = json.containsKey("certificateId") && json.containsKey("accountId");
if (!vailParam) {
LOG.error("必要参数 证书certificateId,账号accountId 缺失其中一个或多个");
}
Long certificateId = null;
Long accountId = null;
Long projectId = null;
String projectName = null;
Long planId = null;
String planName = null;
Integer bizdType = null;
String courseName = null;
Long courseId = null;
try {
if (null != json.get("certificateId")) {
certificateId = Long.valueOf(json.get("certificateId").toString());
}
if (null != json.get("accountId")) {
accountId = Long.valueOf(json.get("accountId").toString());
}
if (null != json.get("projectId")) {
projectId = Long.valueOf(json.get("projectId").toString());
}
if (null != json.get("projectName")) {
projectName = json.get("projectName").toString();
}
if (null != json.get("bizdType")) {
bizdType = Integer.valueOf(json.get("bizdType").toString());
}
if (null == bizdType) {
bizdType = 0;
}
if (null != json.get("courseName")) {
courseName = json.get("courseName").toString();
}
if (null != json.get("courseId")) {
courseId = Long.valueOf(json.get("courseId").toString());
}
LOG.info("============================================= trPlanId {}", json.get("trPlanId"));
if (null != json.get("trPlanId")) {
planId = Long.valueOf(json.get("trPlanId").toString());
}
if (null != json.get("trPlanName")) {
planName = json.get("trPlanName").toString();
}
} catch (Exception e) {
e.printStackTrace();
LOG.error("参数 证书certificateId(Long),账号accountId(Long) ,培训项目 projectId(Long) , "
+ "培训项目名字projectName(String) 类型转换异常");
}
// 验证此人是否已经获得改证书
TrUserCertificate vailHas = new TrUserCertificate();
vailHas.setCertificateId(certificateId);
vailHas.setAccountId(accountId);
EntityWrapper<TrUserCertificate> entityWrapper = new EntityWrapper<TrUserCertificate>(vailHas);
TrUserCertificate tuc = trUserCertificateService.selectOne(entityWrapper);
if (null != tuc) {
LOG.error("该学员已获得此证书");
return;
}
// 验证证书是否存在
Certificate certificate = iCertificateService.selectById(certificateId);
if (null != certificate) {
AccountVO accountVO = accountClient.findById(accountId);
TrUserCertificate trUserCertificate = new TrUserCertificate();
trUserCertificate.setId(idGenerator.generate());
trUserCertificate.setCreateTime(new Date());
trUserCertificate.setCertificateId(certificateId);
trUserCertificate.setCertificateTitle(certificate.getTitle());
trUserCertificate.setCertificateLogourl(certificate.getTemplateImage());
trUserCertificate.setAccountId(accountId);
if (null != accountVO) {
trUserCertificate.setAccountName(accountVO.getName());
trUserCertificate.setUserName(accountVO.getFullName());
}
trUserCertificate.setBizdType(bizdType);
if (bizdType == 0) {
//培训项目
trUserCertificate.setTrainingProjectId(projectId);
trUserCertificate.setTrainingProjectName(projectName);
trUserCertificate.setTpPlanId(planId);
trUserCertificate.setTpPlanName(planName);
} else if (bizdType == 1) {
//课程
trUserCertificate.setTpPlanId(courseId);
trUserCertificate.setTpPlanName(courseName);
}
trUserCertificate.setType(certificate.getType());// 设置过期类型
lock.addCertificateCode(certificate, trUserCertificate);
if (json.containsKey("score")) {
try {
trUserCertificate.setScore(json.get("score").toString());
} catch (Exception e) {
}
} else {
trUserCertificate.setScore("0");
}
trUserCertificate.setIssuer(certificate.getIssuer());
trUserCertificate.setCompanyId(certificate.getCompanyId());
trUserCertificate.setSiteId(certificate.getSiteId());
// AccountVO accountVO =
// iCertificateService.getAccountVO(accountId);
// trUserCertificate.setUserName(accountVO.getFullName());
// trUserCertificate.setAccountName(accountVO.getName());
// trUserCertificate.setCompanyName(accountVO.getCompanyName());
if (0 == certificate.getType()) {
SimpleDateFormat dft = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
try {
trUserCertificate.setEndTime(dft.parse("2038-01-19 01:14:07"));
} catch (Exception e) {
e.printStackTrace();
}
}
if (1 == certificate.getType()) {
//设置时间为当天晚上23:59:59,有效期最后一天24:00后证书失效
Calendar date = Calendar.getInstance();
date.set(date.get(Calendar.YEAR),
date.get(Calendar.MONTH), date.get(Calendar.DAY_OF_MONTH), 23, 59, 59);
if ("0".equals(certificate.getCircleUnit())) {
date.add(Calendar.YEAR, certificate.getCircleCount());
trUserCertificate.setEndTime(date.getTime());
}
if ("1".equals(certificate.getCircleUnit())) {
date.add(Calendar.MONTH, certificate.getCircleCount());
trUserCertificate.setEndTime(date.getTime());
}
if ("2".equals(certificate.getCircleUnit())) {
date.add(Calendar.DAY_OF_MONTH, certificate.getCircleCount());
trUserCertificate.setEndTime(date.getTime());
}
}
if (2 == certificate.getType()) {
trUserCertificate.setEndTime(certificate.getEndTime());
}
if (trUserCertificateService.insert(trUserCertificate)) {
toProject(trUserCertificate, certificate.getSiteId());
}
}
}
/**
* 给项目发送证书完成消息
*/
private void toProject(final TrUserCertificate trUserCertificate, final Long siteId) {
taskExecutor.asynExecute(new AbstractTaskHandler() {
public void handle() {
try {
cloudEventPublisher.publish(QueueConstant.TRAINING_PROJECT_EVENT_QUEUE,
new EventWrapper<TrainingProjectEvent>(trUserCertificate.getCertificateId(),
TrainingProjectEvent.getInstance(trUserCertificate.getCertificateId(),
TpActivityType.TYPE_CERTIFICATE, trUserCertificate.getAccountId(),
new Date(), siteId, null, Boolean.TRUE)));
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
}
package com.yizhi.certificate.application.mapper;
import com.baomidou.mybatisplus.mapper.BaseMapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.yizhi.certificate.application.domain.Certificate;
import com.yizhi.certificate.application.vo.CertificateListVO;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.session.RowBounds;
import java.util.List;
/**
* <p>
* Mapper 接口
* </p>
*
* @author fulan123
* @since 2018-03-07
*/
public interface CertificateMapper extends BaseMapper<Certificate> {
/**
* 根据证书名称模糊 查询证书列表(分页) company_id 项目id 为0的证书
*
* @param title 证书标题
* @param pageNo 要跳转的页数
* @param pageSize 每条页数,默认:10
* @return
*/
List<Certificate> getCertificatePage(@Param(value = "title") String title, @Param(value = "companyId") Long companyId,
@Param(value = "siteId") Long siteId, @Param(value = "orgIds") List<Long> orgIds, RowBounds rowBounds);
/**
* 证书管理端分页列表
*
* @param accountIds
* @param certificateIds 证书ids
* @return List<Certificate> 证书列表对象
*/
List<CertificateListVO> searchCertificateList(@Param("accountIds") List<Long> accountIds,
@Param("certificateIds") List<Long> certificateIds);
/**
* 证书管理端分页列表总数
*
* @param accountIds
* @param title 证书标题
* @param classifyId
* @param companyId 企业id
* @param siteId 站点id
* @param orgIds 管辖区
* @param status 证书状态 0代表停用,1代表启用
* @return List<Certificate> 证书列表对象
*/
Integer searchCertificateListCount(@Param("accountIds") List<Long> accountIds, @Param(value = "title") String title, @Param("classifyId") Long classifyId, @Param(value = "companyId") Long companyId,
@Param(value = "siteId") Long siteId, @Param(value = "orgIds") List<Long> orgIds,
@Param(value = "status") Integer status, @Param("date") String date);
/**
* 证书关联培训项目
*
* @param bizdId
* @param bizdName
* @param certificateIds
* @param type
* @return
*/
Boolean relateProject(@Param("bizdId") Long bizdId,
@Param("bizdName") String bizdName,
@Param("certificateIds") List<Long> certificateIds,
@Param("type") Integer type);
/**
* 证书取消关联状态
*
* @param certificateId
* @return
*/
Boolean cancelRelate(@Param("certificateId") Long certificateId);
/**
* 通过证书id获取证书信息map
*
* @param certificateIds
* @return
*/
List<Certificate> getCertificateMap(@Param("certificateIds") List<Long> certificateIds);
/**
* 获取某个活动发放数量
*
* @param bizdId
* @param accountId
* @param type
* @param startTime
* @param endTime
* @return
*/
Integer getCertificateNum(@Param("bizdId") Long bizdId,
@Param("accountId") Long accountId,
@Param("type") Integer type,
@Param("startTime") String startTime,
@Param("endTime") String endTime);
/**
* 证书管理端分页列表id
*
* @param title
* @param classifyId
* @param companyId
* @param siteId
* @param orgIds
* @param status
* @param date
* @param page
* @return
*/
List<CertificateListVO> searchCertificateIds(@Param("title") String title,
@Param("classifyId") Long classifyId,
@Param("companyId") Long companyId,
@Param("siteId") Long siteId,
@Param("orgIds") List<Long> orgIds,
@Param("status") Integer status,
@Param("date") String date, Page<CertificateListVO> page);
}
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.yizhi.certificate.application.mapper.CertificateMapper">
<!-- 通用查询映射结果 -->
<resultMap id="BaseResultMap" type="com.yizhi.certificate.application.domain.Certificate">
<id column="id" property="id"/>
<result column="code" property="code"/>
<result column="issuer" property="issuer"/>
<result column="title" property="title"/>
<result column="template" property="template"/>
<result column="create_by_id" property="createById"/>
<result column="create_by_name" property="createByName"/>
<result column="create_time" property="createTime"/>
<result column="update_by_id" property="updateById"/>
<result column="update_by_name" property="updateByName"/>
<result column="update_time" property="updateTime"/>
<result column="tags" property="tags"/>
<result column="company_id" property="companyId"/>
<result column="org_id" property="orgId"/>
<result column="logourl" property="logourl"/>
<result column="type" property="type"/>
<result column="circle_count" property="circleCount"/>
<result column="end_time" property="endTime"/>
<result column="status" property="status"/>
<result column="circle_unit" property="circleUnit"/>
<result column="template_id" property="templateId"/>
<result column="template_image" property="templateImage"/>
<result column="site_id" property="siteId"/>
</resultMap>
<update id="relateProject">
UPDATE certificate
SET bizd_id = #{bizdId},
bizd_name = #{bizdName},
bizd_type = #{type},
relation_state = 1
WHERE
id IN
<foreach item="item" index="index" collection="certificateIds" open="(" separator="," close=")">
#{item}
</foreach>
</update>
<update id="cancelRelate">
UPDATE certificate
SET
relation_state = 0
WHERE
id = #{certificateId}
</update>
<!-- <resultMap id="VoResultMap" type="com.fulan.application.vo.ListCertificateVo">
<id column="id" property="id"/>
<id column="title" property="title"/>
<id column="issuer" property="issuer"/>
<id column="create_time" property="createTime"/>
<id column="status" property="status"/>
<id column="orgId" property="orgId"/>
<id column="siteId" property="siteId"/>
<id column="companyId" property="companyId"/>
<id column="trainingProjectId" property="trainingProjectId"/>
<id column="trainingProjectName" property="trainingProjectName"/>
</resultMap>
-->
<!-- 分页查询: 根据证书名称模糊 查询证书列表 company_id 项目id 为0的证书 -->
<select id="getCertificatePage" resultMap="BaseResultMap">
SELECT c.`id`,c.`title`,c.`issuer`,c.`create_time`,c.`status`,c.`org_id`,c.`site_id`,
c.`company_id`,c.`bizd_id`,c.`bizd_name`
FROM
`certificate` c
WHERE
c.`training_project_id` is null
<if test="title!=null and title!=''">
AND c.`title` LIKE CONCAT('%', #{title}, '%')
</if>
<if test="companyId!=null and companyId!=''">
AND c.`company_id` = #{companyId}
</if>
<if test="siteId!=null and siteId!=''">
AND c.`site_id` = #{siteId}
</if>
<!--
<if test="orgIds != null">
AND c.`org_id` IN
<foreach collection="orgIds" open="(" close=")" separator=","
item="oId" index="index">
#{oId}
</foreach>
</if>
-->
ORDER BY c.`create_time` DESC
</select>
<!-- 证书管理端列表 -->
<select id="searchCertificateList"
resultType="com.yizhi.certificate.application.vo.CertificateListVO">
SELECT
c.*,d.name as classify_name,COUNT(DISTINCT(b.id)) as grantNum,COUNT(DISTINCT(e.tp_plan_id)) as relationNum
FROM
certificate c
LEFT JOIN certificate_classify d
ON c.classify_id = d.id
LEFT JOIN tr_user_certificate b ON c.id = b.certificate_id
<if test="accountIds!=null and accountIds.size()>0">
and b.account_id IN
<foreach item="item" index="index" collection="accountIds" open="(" separator="," close=")">
#{item}
</foreach>
</if>
LEFT JOIN relation_activities e
on c.id = e.certificate_id AND e.relation_state = 1
where
1 = 1
<if test="certificateIds!=null and certificateIds.size()>0">
and c.id IN
<foreach item="item" index="index" collection="certificateIds" open="(" separator="," close=")">
#{item}
</foreach>
</if>
GROUP BY c.id
ORDER BY c.create_time DESC,c.title,c.id
</select>
<select id="searchCertificateListCount" resultType="java.lang.Integer">
SELECT
count(*)
FROM
certificate c
<if test="classifyId!=null">
LEFT JOIN certificate_classify d
ON c.classify_id = d.id
</if>
where
c.`company_id` = #{companyId}
AND c.`site_id` = #{siteId}
AND c.status != 3
<if test="title!=null">
AND (c.`title` LIKE CONCAT('%', #{title}, '%') or c.tags LIKE CONCAT('%', #{title}, '%') )
</if>
<if test="status!=null">
AND c.status = #{status}
</if>
<if test="classifyId!=null and classifyId!=-1">
AND (d.id = #{classifyId} OR d.parent_id = #{classifyId} OR d.root_id = #{classifyId})
</if>
<if test="classifyId!=null and classifyId==-1">
AND c.classify_id is NULL
</if>
<if test="date !=null and date !='' ">
AND(c.end_time >= #{date} or c.type =0)
</if>
</select>
<select id="getCertificateMap" resultType="com.yizhi.certificate.application.domain.Certificate">
SELECT
*
FROM
certificate
WHERE
id IN
<foreach item="item" index="index" collection="certificateIds" open="(" separator="," close=")">
#{item}
</foreach>
</select>
<select id="getCertificateNum" resultType="java.lang.Integer">
SELECT
COUNT(1)
FROM
tr_user_certificate
WHERE
bizd_type = #{type}
AND tp_plan_id = #{bizdId}
AND account_id = #{accountId}
<if test="startTime!=null and startTime!='' and endTime!=null and endTime!=''">
AND
<![CDATA[ DATE_FORMAT(create_time,'%Y-%m-%d')<=DATE_FORMAT(#{endTime,jdbcType=VARCHAR},'%Y-%m-%d') ]]>
AND
<![CDATA[ DATE_FORMAT(create_time,'%Y-%m-%d')>=DATE_FORMAT(#{startTime,jdbcType=VARCHAR},'%Y-%m-%d') ]]>
</if>
</select>
<select id="searchCertificateIds" resultType="com.yizhi.certificate.application.vo.CertificateListVO">
SELECT
c.*
FROM
certificate c
LEFT JOIN certificate_classify d
ON c.classify_id = d.id
where
c.`company_id` = #{companyId}
AND c.`site_id` = #{siteId}
AND c.status != 3
<if test="title!=null">
AND (c.`title` LIKE CONCAT('%', #{title}, '%') or c.tags LIKE CONCAT('%', #{title}, '%') )
</if>
<if test="status!=null">
AND c.status = #{status}
</if>
<if test="classifyId!=null and classifyId!=-1">
AND (d.id = #{classifyId} OR d.parent_id = #{classifyId} OR d.root_id = #{classifyId})
</if>
<if test="classifyId!=null and classifyId==-1">
AND c.classify_id is NULL
</if>
<if test="date !=null and date !='' ">
AND(c.end_time >= #{date} or c.type =0)
</if>
ORDER BY c.create_time DESC,c.title,c.id
</select>
</mapper>
package com.yizhi.certificate.application.mapper;
import java.util.List;
import com.yizhi.certificate.application.domain.TrUserCertificate;
import com.yizhi.certificate.application.vo.CertificateListVO;
import com.yizhi.certificate.application.vo.TrUserCertificateDetailsVo;
import org.apache.ibatis.annotations.Param;
import com.baomidou.mybatisplus.mapper.BaseMapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.yizhi.certificate.application.vo.CertificateUserListVO;
public interface CertificateUserMapper extends BaseMapper<TrUserCertificate> {
List<CertificateUserListVO> userRankList(
@Param("siteId") Long siteId,
@Param("companyId") Long companyId,
@Param("accountIds") List<Long> accountIds,
@Param("startDate") String startDate,
@Param("endDate") String endDate,
Page<CertificateUserListVO> page);
List<TrUserCertificateDetailsVo> userDetailsList(@Param("siteId") Long siteId,
@Param("companyId") Long companyId,
@Param("accountIds") List<Long> accountIds,
@Param("startDate") String startDate,
@Param("endDate") String endDate,
Page<TrUserCertificateDetailsVo> page);
/**
* 证书统计按证书维度获取列表
* @param startDate
* @param endDate
* @param certificateName
* @param start
* @param pageSize
* @param companyId
* @param siteId
* @param accountIds
* @return
*/
List<CertificateListVO> certificateList(@Param("startDate") String startDate,
@Param("endDate") String endDate,
@Param("certificateName") String certificateName,
@Param("start") Integer start,
@Param("pageSize") Integer pageSize,
@Param("companyId") Long companyId,
@Param("siteId") Long siteId,
@Param("accountIds") List<Long> accountIds);
/**
* 证书统计按证书维度获取总记录数
* @param startDate
* @param endDate
* @param certificateName
* @param companyId
* @param siteId
* @param accountIds
* @return
*/
Integer certificateListCount(@Param("startDate") String startDate,
@Param("endDate") String endDate,
@Param("certificateName") String certificateName,
@Param("companyId") Long companyId,
@Param("siteId") Long siteId,
@Param("accountIds") List<Long> accountIds);
}
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.yizhi.certificate.application.mapper.CertificateUserMapper">
<select id="userRankList" resultType="com.yizhi.certificate.application.vo.CertificateUserListVO">
SELECT a.account_id as accountId,COUNT(a.id) as totalCertificate
from tr_user_certificate a
where 1=1
and a.site_id=#{siteId}
and a.company_id=#{companyId}
and a.account_id is not null
<if test="accountIds != null and accountIds.size() > 0">
and a.account_id in
<foreach item="itemId" index="index" collection="accountIds"
open="(" separator="," close=")">
#{itemId}
</foreach>
</if>
<if test="startDate!=null and startDate!='' and endDate!=null and endDate!=''">
AND (<![CDATA[ DATE_FORMAT(a.create_time,'%Y-%m-%d')<=DATE_FORMAT(#{endDate,jdbcType=VARCHAR},'%Y-%m-%d') ]]>
AND <![CDATA[ DATE_FORMAT(a.create_time,'%Y-%m-%d')>=DATE_FORMAT(#{startDate,jdbcType=VARCHAR},'%Y-%m-%d') ]]>
)
</if>
GROUP BY a.account_id
order by totalCertificate DESC,a.account_name
</select>
<select id="userDetailsList" resultType="com.yizhi.certificate.application.vo.TrUserCertificateDetailsVo">
select c.account_id as accountId,c.certificate_title as certificateTitle,c.certificate_code as certificateCode,c.type,c.issuer,c.certificate_id as certificateId,
c.bizd_type,c.tp_plan_name as tpPlanName,c.training_project_name as trainingProjectName,c.create_time as createTime,c.end_time as endTime
from tr_user_certificate c
where 1=1
and c.site_id=#{siteId}
and c.company_id=#{companyId}
<if test="accountIds != null and accountIds.size() > 0">
and c.account_id in
<foreach item="itemId" index="index" collection="accountIds"
open="(" separator="," close=")">
#{itemId}
</foreach>
</if>
<if test="startDate!=null and startDate!='' and endDate!=null and endDate!=''">
AND (<![CDATA[ DATE_FORMAT(c.create_time,'%Y-%m-%d')<=DATE_FORMAT(#{endDate,jdbcType=VARCHAR},'%Y-%m-%d') ]]>
AND <![CDATA[ DATE_FORMAT(c.create_time,'%Y-%m-%d')>=DATE_FORMAT(#{startDate,jdbcType=VARCHAR},'%Y-%m-%d') ]]>
)
</if>
ORDER BY c.account_name,c.create_time desc,c.id
</select>
<select id="certificateList" resultType="com.yizhi.certificate.application.vo.CertificateListVO">
SELECT a.*,COUNT(b.id) as grantNum FROM
(SELECT *
FROM
certificate
WHERE
company_id = #{companyId}
AND site_id = #{siteId}
AND `status` != 3
<if test="startDate!=null and startDate!='' and endDate!=null and endDate!=''">
AND (<![CDATA[ DATE_FORMAT(create_time,'%Y-%m-%d')<=DATE_FORMAT(#{endDate,jdbcType=VARCHAR},'%Y-%m-%d') ]]>
AND <![CDATA[ DATE_FORMAT(create_time,'%Y-%m-%d')>=DATE_FORMAT(#{startDate,jdbcType=VARCHAR},'%Y-%m-%d') ]]>
)
</if>
<if test="certificateName!=null and certificateName!=''">
AND (`title` LIKE CONCAT('%', #{certificateName}, '%') or tags LIKE CONCAT('%', #{certificateName}, '%') )
</if>
LIMIT #{start},#{pageSize})a
LEFT JOIN tr_user_certificate b
on a.id = b.certificate_id
<if test="accountIds != null and accountIds.size() > 0">
and b.account_id in
<foreach item="itemId" index="index" collection="accountIds"
open="(" separator="," close=")">
#{itemId}
</foreach>
</if>
GROUP BY a.id
</select>
<select id="certificateListCount" resultType="java.lang.Integer">
SELECT count(1)
FROM
certificate
WHERE
company_id = #{companyId}
AND site_id = #{siteId}
AND `status` != 3
<if test="startDate!=null and startDate!='' and endDate!=null and endDate!=''">
AND (<![CDATA[ DATE_FORMAT(create_time,'%Y-%m-%d')<=DATE_FORMAT(#{endDate,jdbcType=VARCHAR},'%Y-%m-%d') ]]>
AND <![CDATA[ DATE_FORMAT(create_time,'%Y-%m-%d')>=DATE_FORMAT(#{startDate,jdbcType=VARCHAR},'%Y-%m-%d') ]]>
)
</if>
<if test="certificateName!=null and certificateName!=''">
AND (`title` LIKE CONCAT('%', #{certificateName}, '%') or tags LIKE CONCAT('%', #{certificateName}, '%') )
</if>
</select>
</mapper>
package com.yizhi.certificate.application.mapper;
import com.yizhi.certificate.application.domain.CertificateClassify;
import com.baomidou.mybatisplus.mapper.BaseMapper;
import org.apache.ibatis.annotations.Param;
/**
* <p>
* Mapper 接口
* </p>
*
* @author dingxiaowei123
* @since 2019-12-23
*/
public interface ClassifyMapper extends BaseMapper<CertificateClassify> {
/**
* 获取目前最大分类编码
* @param companyId
* @param siteId
* @return
*/
Integer getMaxCode(@Param("companyId") Long companyId,@Param("siteId") Long siteId);
/**
* 获取分类关联证书数
* @param id
* @param companyId
* @param siteId
* @return
*/
Integer getRelationNum(@Param("id") Long id, @Param("companyId") Long companyId,@Param("siteId") Long siteId);
}
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
<mapper namespace="com.yizhi.certificate.application.mapper.ClassifyMapper">
<select id="getMaxCode" resultType="java.lang.Integer">
SELECT
MAX(code)
FROM
certificate_classify
WHERE
company_id = #{companyId}
AND site_id = #{siteId}
AND state = 1
</select>
<select id="getRelationNum" resultType="java.lang.Integer">
SELECT
COUNT(1)
FROM
certificate
WHERE
company_id = #{companyId}
AND site_id = #{siteId}
AND classify_id = #{id}
</select>
</mapper>
package com.yizhi.certificate.application.mapper;
import com.yizhi.certificate.application.domain.RelationActivities;
import com.baomidou.mybatisplus.mapper.BaseMapper;
/**
* <p>
* 学员证书中间表 Mapper 接口
* </p>
*
* @author dingxiaowei123
* @since 2019-12-30
*/
public interface RelationActivitiesMapper extends BaseMapper<RelationActivities> {
}
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
<mapper namespace="com.yizhi.certificate.application.mapper.RelationActivitiesMapper">
</mapper>
package com.yizhi.certificate.application.mapper;
import com.baomidou.mybatisplus.mapper.BaseMapper;
import com.yizhi.certificate.application.domain.TrCertificateTemplate;
/**
* <p>
* 证书模板表 Mapper 接口
* </p>
*
* @author fulan123
* @since 2018-03-07
*/
public interface TrCertificateTemplateMapper extends BaseMapper<TrCertificateTemplate> {
}
package com.yizhi.certificate.application.mapper;
import com.baomidou.mybatisplus.mapper.BaseMapper;
import com.yizhi.certificate.application.domain.TrUserCertificate;
import com.yizhi.certificate.application.vo.ApiUserCertificateVo;
import com.yizhi.certificate.application.vo.FirstVO;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.session.RowBounds;
import java.util.List;
/**
* <p>
* 学员证书中间表 Mapper 接口
* </p>
*
* @author fulan123
* @since 2018-03-07
*/
public interface TrUserCertificateMapper extends BaseMapper<TrUserCertificate> {
/**
*根据学员端用户id查询学员端证书数量
*
* @return
*/
Integer getCertificateCount(@Param(value = "accountId") Long accountId, @Param(value = "companyId") Long companyId,
@Param(value = "siteId") Long siteId);
List<TrUserCertificate> getMyList(@Param(value = "accountId") Long accountId, @Param(value = "certificate_title") String certificate_title,
@Param(value = "validityType") String validityType, @Param(value = "companyId") Long companyId,
@Param(value = "siteId") Long siteId,RowBounds rowBounds);
Integer getMyListCount(@Param(value = "accountId") Long accountId, @Param(value = "certificate_title") String certificate_title,
@Param(value = "validityType") String validityType,@Param(value = "companyId") Long companyId,
@Param(value = "siteId") Long siteId);
List<ApiUserCertificateVo> getMyListSearch(@Param(value = "accountId") Long accountId, @Param(value = "certificate_title") String certificate_title,
@Param(value = "companyId") Long companyId,
@Param(value = "siteId") Long siteId,RowBounds rowBounds);
Integer getMyListSearchCount(@Param(value = "accountId") Long accountId, @Param(value = "certificate_title") String certificate_title,@Param(value = "companyId") Long companyId,
@Param(value = "siteId") Long siteId);
String getCountByCompanyId(@Param(value = "companyId") Long companyId);
List<FirstVO> first(@Param("siteIds") List<Long> siteIds,
@Param("startDate") String startDate, @Param("endDate") String endDate);
}
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper
namespace="com.yizhi.certificate.application.mapper.TrUserCertificateMapper">
<!-- 通用查询映射结果 -->
<resultMap id="BaseResultMap"
type="com.yizhi.certificate.application.domain.TrUserCertificate">
<id column="id" property="id" />
<result column="user_id" property="userId" />
<result column="certificate_id" property="certificateId" />
<result column="create_by_id" property="createById" />
<result column="create_by_name" property="createByName" />
<result column="create_time" property="createTime" />
<result column="company_id" property="companyId" />
<result column="company_name" property="companyName" />
<result column="account_id" property="accountId" />
<result column="account_name" property="accountName" />
<result column="user_name" property="userName" />
<result column="training_project_name"
property="trainingProjectName" />
<result column="tp_plan_name"
property="tpPlanName" />
<result column="training_project_id"
property="trainingProjectId" />
<result column="issuer" property="issuer" />
<result column="end_time" property="endTime" />
<result column="score" property="score" />
<result column="certificate_title" property="certificateTitle" />
<result column="certificate_logourl"
property="certificateLogourl" />
<result column="user_image" property="userImage" />
</resultMap>
<!-- 我的证书列表 -->
<select id="getMyList" resultMap="BaseResultMap">
SELECT
tu.`id`,
tu.`certificate_id`,
tu.`certificate_title`,
tu.`certificate_logourl`,
tu.`end_time`,
tu.`create_time`,
tu.`training_project_name`,tu.issuer,
tu.user_image,
tp_plan_name
FROM tr_user_certificate tu
WHERE
tu.`company_id` = #{companyId}
AND tu.`site_id` = #{siteId}
<if test="accountId !=null">
AND tu.`account_id` = #{accountId}
</if>
<if test="validityType !=null">
<choose>
<when test="validityType ==0"> <![CDATA[ and tu.`end_time` <= NOW() ]]>
</when>
<when test="validityType ==1"> <![CDATA[ and tu.`end_time` >= NOW() ]]></when>
</choose>
</if>
<if test="certificate_title !=null">
AND tu.`certificate_title` LIKE
CONCAT('%',#{certificate_title},'%')
</if>
ORDER BY tu.`create_time` DESC
</select>
<select id="getMyListCount" resultType="java.lang.Integer">
SELECT
count(tu.`id`)
FROM tr_user_certificate tu
WHERE
tu.`company_id` =
#{companyId}
AND tu.`site_id` = #{siteId}
<if test="accountId !=null">
AND tu.`account_id` = #{accountId}
</if>
<if test="validityType !=null">
<choose>
<when test="validityType ==0"> <![CDATA[ and tu.`end_time` <= NOW() ]]>
</when>
<when test="validityType ==1"> <![CDATA[ and tu.`end_time` >= NOW() ]]></when>
</choose>
</if>
<if test="certificate_title !=null">
AND tu.`certificate_title` LIKE
CONCAT('%',#{certificate_title},'%')
</if>
ORDER BY tu.`create_time` DESC
</select>
<!-- 我的证书列表 结束 -->
<resultMap id="appResultMap"
type="com.yizhi.certificate.application.vo.ApiUserCertificateVo">
<id column="id" property="id" />
<result column="certificate_id" property="certificateId" />
<result column="training_project_name"
property="trainingProjectName" />
<result column="create_time" property="createTime" />
<result column="end_time" property="endTime" />
<result column="certificate_title" property="certificateTitle" />
<result column="certificate_logourl"
property="certificateLogourl" />
<result column="status" property="status" />
</resultMap>
<!-- 根据证书名称查询我的证书列表 -->
<select id="getMyListSearch" resultMap="appResultMap">
SELECT
tu.`id`,
tu.`certificate_id`,
tu.`certificate_title`,
tu.`certificate_logourl`,
tu.`end_time`,
tu.`create_time`,
tu.`training_project_name`,
CASE WHEN tu.`end_time` >= NOW() THEN 1
ELSE 0 END AS status
FROM tr_user_certificate tu
WHERE
tu.`company_id` =
#{companyId}
AND tu.`site_id` = #{siteId}
<if test="accountId !=null">
AND tu.`account_id` = #{accountId}
</if>
<if test="certificate_title !=null">
AND tu.`certificate_title` LIKE
CONCAT('%',#{certificate_title},'%')
</if>
ORDER BY tu.`create_time` DESC
</select>
<select id="getMyListSearchCount" resultType="java.lang.Integer">
SELECT
count(tu.`id`)
FROM tr_user_certificate tu
WHERE
tu.`company_id` =
#{companyId}
AND tu.`site_id` = #{siteId}
<if test="accountId !=null">
AND tu.`account_id` = #{accountId}
</if>
<if test="certificate_title !=null">
AND tu.`certificate_title` LIKE
CONCAT('%',#{certificate_title},'%')
</if>
ORDER BY tu.`create_time` DESC
</select>
<!-- 根据证书名称查询我的证书列表 结束 -->
<!-- 根据学员端用户id查询学员端证书数量 -->
<select id="getCertificateCount" resultType="java.lang.Integer">
SELECT
COUNT(tu.`certificate_title`)
FROM tr_user_certificate tu
WHERE
tu.`company_id` = #{companyId}
AND tu.`site_id` = #{siteId}
<if test="accountId !=null">
AND tu.`account_id` = #{accountId}
</if>
AND tu.end_time > now()
</select>
<select id="getCountByCompanyId" resultType="java.lang.String">
SELECT
IFNULL(MAX(a.certificate_code),0) AS certificate_code
FROM (
SELECT CASE
WHEN b.rule_type=0 THEN
CONVERT(RIGHT(a.certificate_code,LENGTH(a.certificate_code)-8),SIGNED)
ELSE
CONVERT(a.certificate_code,SIGNED) END AS certificate_code
FROM
tr_user_certificate a
LEFT JOIN certificate b ON a.certificate_id=b.id
WHERE a.certificate_id=b.id and IFNULL(a.certificate_code,'')!='' and
a.company_id = #{companyId}
) a
</select>
<resultMap type="com.yizhi.certificate.application.vo.FirstVO"
id="firstMap">
<result property="accountId" column="accountId" />
<result property="first" column="first" />
</resultMap>
<select id="first" resultType="com.yizhi.certificate.application.vo.FirstVO">
SELECT MIN(t.create_time) first,account_id accountId FROM
tr_user_certificate t WHERE
t.site_id IN (
<foreach collection="siteIds" separator="," item="item">#{item}
</foreach>
)
AND create_time BETWEEN #{startDate}
AND #{endDate}
group by accountId
</select>
</mapper>
package com.yizhi.certificate.application.service;
import com.baomidou.mybatisplus.plugins.Page;
import com.baomidou.mybatisplus.service.IService;
import com.yizhi.certificate.application.domain.TrUserCertificate;
import com.yizhi.certificate.application.vo.CertificateListVO;
import com.yizhi.certificate.application.vo.CertificateUserListVO;
import com.yizhi.certificate.application.vo.TrUserCertificateDetailsVo;
import com.yizhi.core.application.context.RequestContext;
import java.util.List;
public interface CertificateUserService extends IService<TrUserCertificate> {
Page<CertificateUserListVO> userRankList(String startDate, String endDate,
Integer pageNo, Integer pageSize, Long siteId, Long companyId,
String userName, String orgNameLike, List<Long> orgIds, boolean isAdmin, Long accountId);
Page<TrUserCertificateDetailsVo> userDetails(String startDate, String endDate, Integer pageNo,
Integer pageSize, Long siteId, Long companyId,
String userName, String orgNameLike, List<Long> orgIds,
boolean isAdmin, Long accountId);
/**
* 证书统计按证书维度
* @param startDate
* @param endDate
* @param certificateName
* @param pageNo
* @param pageSize
* @param res
* @return
*/
Page<CertificateListVO> certificateList(String startDate, String endDate, String certificateName, Integer pageNo, Integer pageSize, RequestContext res);
}
package com.yizhi.certificate.application.service;
import com.baomidou.mybatisplus.plugins.Page;
import com.baomidou.mybatisplus.service.IService;
import com.yizhi.certificate.application.domain.Certificate;
import com.yizhi.certificate.application.vo.CertificateListVO;
import com.yizhi.certificate.application.vo.CertificateNumParam;
import com.yizhi.certificate.application.vo.CertificateVoList;
import com.yizhi.certificate.application.vo.RelateCertificateParam;
import com.yizhi.core.application.context.RequestContext;
import java.util.List;
import java.util.Map;
/**
* <p>
* 服务类
* </p>
*
* @author fulan123
* @since 2018-03-07
*/
public interface ICertificateService extends IService<Certificate> {
/**
* 根据证书名称模糊 查询证书列表(分页) company_id 项目id 为0的证书
@param title 证书名称
* @param pageNo 要跳转的页数
* @param pageSize 每条页数,默认:10
* @return
*/
Page<Certificate> getCertificatePage(String title, Long companyId, Long siteId, List<Long> orgIds , Integer pageNo, Integer pageSize );
/**
* 获取证书列表
* @param title
* @param status
* @param level
* @param companyId
* @param site_id
* @param org_id
* @return
*/
Page<Certificate> listCertificate( CertificateVoList certificateVoList);
/**
* 证书管理端分页列表
* @param title 证书标题
* @param classifyId
* @param companyId 企业id
* @param siteId 站点id
* @param orgIds 管辖区
* @param status 证书状态 0代表停用,1代表启用
* @param pageNo 分页页数
* @param pageSize 分页条数
* @param res
* @return Page<Certificate> 证书的分页列表
*/
Page<CertificateListVO> searchCertificateList(String title, Long classifyId, Long companyId,
Long siteId, List<Long> orgIds,
Integer status, Integer pageNo, Integer pageSize, String currentTime, RequestContext res);
List<Map<String, Object>> getServerByCompanyIdAndIds(Long companyId,List<Long> ids);
/**
* 证书关联培训项目
* @param relateCertificateParam
* @return
*/
Boolean relateProject(RelateCertificateParam relateCertificateParam);
/**
* 证书取消关联状态
* @param certificateId
* @param projectId
* @param tpPlanId
* @return
*/
Boolean cancelRelate(Long certificateId, Long projectId, Long tpPlanId);
/**
* 通过证书id获取证书信息map
* @param certificateIds
* @return
*/
Map<Long, Certificate> getCertificateMap(List<Long> certificateIds);
/**
* 获取某个活动发放数量
* @param certificateNumParam
* @return
*/
Integer getCertificateNum(CertificateNumParam certificateNumParam);
}
package com.yizhi.certificate.application.service;
import com.baomidou.mybatisplus.service.IService;
import com.yizhi.certificate.application.domain.CertificateClassify;
import com.yizhi.certificate.application.vo.CertificateClassifyListVO;
import java.util.List;
/**
* <p>
* 服务类
* </p>
*
* @author dingxiaowei123
* @since 2019-12-23
*/
public interface IClassifyService extends IService<CertificateClassify> {
/**
* 新建分类入库
* @param certificateClassify
* @return
*/
Integer insertClassify(CertificateClassify certificateClassify);
/**
* 获取分类列表
* @return
*/
List<CertificateClassifyListVO> getClassifyList();
/**
* 修改分类
* @param certificateClassify
* @return
*/
boolean updateClassify(CertificateClassify certificateClassify);
/**
* 删除分类
* @param id
* @return
*/
Integer deleteClassify(Long id);
}
package com.yizhi.certificate.application.service;
import com.yizhi.certificate.application.domain.RelationActivities;
import com.baomidou.mybatisplus.service.IService;
import java.util.List;
/**
* <p>
* 学员证书中间表 服务类
* </p>
*
* @author dingxiaowei123
* @since 2019-12-30
*/
public interface IRelationActivitiesService extends IService<RelationActivities> {
/**
* 查看关联活动
* @param certificateId
* @return
*/
List<RelationActivities> getRelationActivities(Long certificateId);
}
package com.yizhi.certificate.application.service;
import com.baomidou.mybatisplus.service.IService;
import com.yizhi.certificate.application.domain.TrCertificateTemplate;
import java.util.List;
/**
* <p>
* 证书模板表 服务类
* </p>
*
* @author fulan123
* @since 2018-03-07
*/
public interface ITrCertificateTemplateService extends IService<TrCertificateTemplate> {
/**
* 获取通用模板列表
* @return
*/
List<TrCertificateTemplate> getList();
}
package com.yizhi.certificate.application.service;
import java.util.Date;
import java.util.List;
import java.util.Map;
import com.baomidou.mybatisplus.plugins.Page;
import com.baomidou.mybatisplus.service.IService;
import com.yizhi.certificate.application.domain.TrUserCertificate;
import com.yizhi.certificate.application.vo.ApiUserCertificateVo;
import com.yizhi.certificate.application.vo.TrUserCertificatePcVo;
/**
* <p>
* 学员证书中间表 服务类
* </p>
*
* @author fulan123
* @since 2018-03-07
*/
public interface ITrUserCertificateService extends IService<TrUserCertificate> {
/**
* 根据学员端用户id查询学员端证书数量
* @return
*/
Integer getCertificateCount(Long accountId, Long companyId,
Long siteId);
/**
* 学员端 获得自己所得的证书列表
* @param accountId 账号id
* @param certificate_title 标题名称
* @return List<TrUserCertificate>
*/
Page<TrUserCertificate> getMyList(Long accountId, String certificate_title, String validityType, Long companyId,
Long siteId, Integer pageNo, Integer pageSize);
/**
* 学员端 搜索获得自己所得的证书列表
* @param accountId 账号id
* @param certificate_title 标题名称
* @return List<TrUserCertificate>
*/
Page<ApiUserCertificateVo> getMyListSearch(Long accountId, String certificate_title, Long companyId,
Long siteId, Integer pageNo, Integer pageSize);
/**
* 根据学员证书中间表id 获取图片和正书名称
* @param id
* @return
*/
TrUserCertificatePcVo viewImage(Long id);
String getCountByCompanyId(Long companyId);
Map<Long, Date> first(List<Long> siteIds,String startDate,String endDate);
}
package com.yizhi.certificate.application.service.impl;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import com.yizhi.certificate.application.domain.Certificate;
import com.yizhi.certificate.application.domain.RelationActivities;
import com.yizhi.certificate.application.mapper.CertificateMapper;
import com.yizhi.application.orm.hierarchicalauthorization.HQueryUtil;
import com.yizhi.application.orm.id.IdGenerator;
import com.yizhi.certificate.application.service.ICertificateService;
import com.yizhi.certificate.application.service.IRelationActivitiesService;
import com.yizhi.certificate.application.vo.CertificateListVO;
import com.yizhi.certificate.application.vo.CertificateNumParam;
import com.yizhi.certificate.application.vo.CertificateVoList;
import com.yizhi.certificate.application.vo.RelateCertificateParam;
import com.yizhi.core.application.context.ContextHolder;
import com.yizhi.core.application.context.RequestContext;
import com.yizhi.system.application.constant.AuthzConstant;
import com.yizhi.system.application.system.remote.ReportClient;
import com.yizhi.system.application.vo.HQAccountInManageParam;
import com.yizhi.system.application.vo.ReportAccountRespInManageVO;
import com.yizhi.system.application.vo.ReportAccountRespVO;
import com.yizhi.system.application.vo.ReportRangeAccountReqVO;
import org.apache.ibatis.session.RowBounds;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
import org.springframework.util.StringUtils;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.stream.Collectors;
/**
* <p>
* 服务实现类
* </p>
*
* @author fulan123
* @since 2018-03-07
*/
@Service
public class CertificateServiceImpl extends ServiceImpl<CertificateMapper, Certificate> implements ICertificateService {
private Logger logger = LoggerFactory.getLogger(CertificateServiceImpl.class);
@Autowired
private ReportClient reportClient;
@Autowired
private IdGenerator idGenerator;
@Autowired
private IRelationActivitiesService relationActivitiesService;
/**
* 根据证书名称模糊 查询证书列表(分页) company_id 项目id 为0的证书
*
* @param course_id 课程id
* @param pageNo 要跳转的页数
* @param pageSize 每条页数,默认:10
* @return
*/
@Override
public Page<Certificate> getCertificatePage(String title, Long companyId, Long siteId, List<Long> orgIds, Integer pageNo, Integer pageSize) {
HQueryUtil.startHQ(Certificate.class);
Page<Certificate> page = new Page<Certificate>(pageNo, pageSize);
page.setRecords(this.baseMapper.getCertificatePage(title, companyId, siteId, orgIds, new RowBounds(page.getOffset(), page.getLimit())));
return page;
}
/**
* 获取证书查询列表
*
* @param title
* @param status
* @param level
* @param companyId
* @param site_id
* @param org_id
* @param pageNo
* @param pageSize
* @return
*/
@Override
public Page<Certificate> listCertificate(CertificateVoList certificateVoList) {
Page<Certificate> page = new Page<Certificate>(certificateVoList.getPageNo(), certificateVoList.getPageSize());
Certificate certificate = new Certificate();
EntityWrapper<Certificate> wrapper = new EntityWrapper<Certificate>(certificate);
//根据权限判断用户的角色判断查找证书列表的条件
if (certificateVoList.getLevel() == 1) {
certificate.setCompanyId(certificateVoList.getCompanyId());
if (certificateVoList.getStatus() != null) {
certificate.setStatus(certificateVoList.getStatus());
}
if (certificateVoList.getTitle() != null) {
wrapper.and("title like {0}", "%" + certificateVoList.getTitle() + "%").or("tags like {0}", "%" + certificateVoList.getTitle() + "%").orderBy("create_time", false);
System.out.println("wrapper--------------- " + wrapper.getSqlSegment());
try {
return this.selectPage(page, wrapper);
} catch (Exception e) {
e.printStackTrace();
logger.error("查找证书列表错误");
return null;
}
}
wrapper.orderBy("create_time", false);
try {
return this.selectPage(page, wrapper);
} catch (Exception e) {
e.printStackTrace();
logger.error("查找证书列表错误");
return null;
}
} else {
if (certificateVoList.getLevel() == 2) {
certificate.setSiteId(certificateVoList.getSiteId());
if (certificateVoList.getStatus() != null) {
certificate.setStatus(certificateVoList.getStatus());
}
if (certificateVoList.getTitle() != null) {
wrapper.and("title like {0}", "%" + certificateVoList.getTitle() + "%").or("tags like {0}", "%" + certificateVoList.getTitle() + "%)").orderBy("create_time", false);
try {
return this.selectPage(page, wrapper);
} catch (Exception e) {
e.printStackTrace();
logger.error("查找证书列表错误");
return null;
}
}
wrapper.orderBy("create_time", false);
try {
return this.selectPage(page, wrapper);
} catch (Exception e) {
e.printStackTrace();
logger.error("查找证书列表错误");
return null;
}
} else {
certificate.setOrgId(certificateVoList.getOrgId());
if (certificateVoList.getStatus() != null) {
certificate.setStatus(certificateVoList.getStatus());
}
if (certificateVoList.getTitle() != null) {
wrapper.and("title like {0}", "%" + certificateVoList.getTitle() + "%").or("tags like {0}", "%" + certificateVoList.getTitle() + "%)").orderBy("create_time", false);
try {
return this.selectPage(page, wrapper);
} catch (Exception e) {
e.printStackTrace();
logger.error("查找证书列表错误");
return null;
}
}
wrapper.orderBy("create_time", false);
try {
return this.selectPage(page, wrapper);
} catch (Exception e) {
e.printStackTrace();
logger.error("查找证书列表错误");
return null;
}
}
}
}
@Override
public Page<CertificateListVO> searchCertificateList(String title, Long classifyId, Long companyId, Long siteId, List<Long> orgIds,
Integer status, Integer pageNo, Integer pageSize, String currentTime, RequestContext res) {
String date = null;
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
if (!StringUtils.isEmpty(currentTime)) {
Long timeStamp = null;
try {
timeStamp = Long.valueOf(currentTime);
} catch (NumberFormatException e) {
e.printStackTrace();
}
date = sdf.format(timeStamp);
}
Page<CertificateListVO> page = new Page<>(pageNo, pageSize);
List<Long> accountIds1 = null;
//如果是一般管理员加上管辖区
if (!res.isAdmin()) {
HQAccountInManageParam hqAccountInManageParam = new HQAccountInManageParam();
hqAccountInManageParam.setSiteId(res.getSiteId());
hqAccountInManageParam.setAccountId(res.getAccountId());
hqAccountInManageParam.setModuleType(AuthzConstant.moduleType.statistics_certificate);
ReportAccountRespInManageVO respInManageVO = reportClient.getRangeAccountsInManage(hqAccountInManageParam);
if (null != respInManageVO) {
//如果不是根目录(根目录不用管)
if (!respInManageVO.getIsAdmin()) {
List<ReportAccountRespVO> accountRespVOS = respInManageVO.getList();
accountIds1 = accountRespVOS.stream().map(ReportAccountRespVO::getUserId).collect(Collectors.toList());
if (CollectionUtils.isEmpty(accountIds1)) {
return null;
}
}
} else {
return null;
}
}
Integer start = (pageNo - 1) * pageSize;
HQueryUtil.startHQ(Certificate.class);
List<CertificateListVO> idList = this.baseMapper.searchCertificateIds(title, classifyId, companyId, siteId, orgIds, status, date, page);
List<Long> ids = null;
if (!CollectionUtils.isEmpty(idList)) {
ids = idList.stream().map(CertificateListVO::getId).collect(Collectors.toList());
}else {
return page;
}
List<CertificateListVO> list = this.baseMapper.searchCertificateList(accountIds1, ids);
// Integer count = this.baseMapper.searchCertificateListCount(accountIds1, title, classifyId, companyId, siteId, orgIds, status, date);
// if (count == 0) {
// return new Page<>(pageNo, pageSize);
// }
// page.setTotal(count);
if (!CollectionUtils.isEmpty(list)) {
List<Long> accountIds = new ArrayList<>();
//获取用户名,培训项目名,课程名
for (CertificateListVO certificateListVO : list) {
if (!accountIds.contains(certificateListVO.getCreateById())) {
accountIds.add(certificateListVO.getCreateById());
}
}
Map<Long, ReportAccountRespVO> accountMap = new HashMap<>(16);
if (!CollectionUtils.isEmpty(accountIds)) {
ReportRangeAccountReqVO reqVO = new ReportRangeAccountReqVO();
reqVO.setAccountIds(accountIds);
reqVO.setSiteId(siteId);
List<ReportAccountRespVO> accounts = reportClient.getRangeAccounts(reqVO);
if (!CollectionUtils.isEmpty(accounts)) {
for (ReportAccountRespVO respVO : accounts) {
accountMap.put(respVO.getUserId(), respVO);
}
}
}
for (CertificateListVO certificateListVO : list) {
ReportAccountRespVO accountRespVO = accountMap.get(certificateListVO.getCreateById());
if (null != accountRespVO) {
certificateListVO.setCreateByName(accountRespVO.getUserName());
}
}
page.setRecords(list);
}
return page;
}
@Override
public List<Map<String, Object>> getServerByCompanyIdAndIds(Long companyId, List<Long> ids) {
// TODO Auto-generated method stub
List<Map<String, Object>> listMap = null;
//查询
Certificate certificate = new Certificate();
certificate.setCompanyId(companyId);
EntityWrapper<Certificate> wrapper = new EntityWrapper<Certificate>(certificate);
if (!CollectionUtils.isEmpty(ids)) {
wrapper.in("id", ids);
}
List<Certificate> listCertificate = this.selectList(wrapper);
//循环组装到输出对象
Map<String, Object> map = null;
if (!CollectionUtils.isEmpty(listCertificate)) {
listMap = new ArrayList<Map<String, Object>>();
for (Certificate c : listCertificate) {
map = new HashMap<String, Object>();
map.put("catalog", 6);
map.put("id", c.getId());
map.put("name", c.getTitle());
map.put("logo_url", c.getLogourl());
listMap.add(map);
}
}
return listMap;
}
@Override
public Boolean relateProject(RelateCertificateParam relateCertificateParam) {
RequestContext res = ContextHolder.get();
List<Long> certificateIds = relateCertificateParam.getCertificateIds();
//除了培训项目关联,保存之前先清除之前的记录
if (relateCertificateParam.getType() != 0) {
RelationActivities relationActivities = new RelationActivities();
relationActivities.setBizdType(relateCertificateParam.getType());
relationActivities.setRelationState(1);
relationActivities.setTpPlanId(relateCertificateParam.getBizdId());
List<RelationActivities> relationActivitiesList = relationActivitiesService.selectList(new EntityWrapper<>(relationActivities));
if (!CollectionUtils.isEmpty(relationActivitiesList)) {
for (RelationActivities relationActivities1 : relationActivitiesList) {
relationActivities1.setRelationState(0);
relationActivities.setUpdateById(res.getAccountId());
relationActivities.setUpdateByName(res.getAccountName());
relationActivities.setUpdateTime(new Date());
}
relationActivitiesService.updateBatchById(relationActivitiesList);
}
}
if (!CollectionUtils.isEmpty(certificateIds)) {
for (Long certificateId : certificateIds) {
RelationActivities relationActivities = new RelationActivities();
relationActivities.setRelationState(1);
relationActivities.setCertificateId(certificateId);
relationActivities.setBizdType(relateCertificateParam.getType());
//如果是关联培训项目,加上计划id
if (relateCertificateParam.getType() == 0) {
relationActivities.setBizdId(relateCertificateParam.getBizdId());
relationActivities.setTpPlanId(relateCertificateParam.getTpPlanId());
} else {
relationActivities.setTpPlanId(relateCertificateParam.getBizdId());
}
List<RelationActivities> list = relationActivitiesService.selectList(new EntityWrapper<>(relationActivities));
if (!CollectionUtils.isEmpty(list)) {
//如果有关联记录,跳过
continue;
} else {
//没有关联记录,插入记录数据
relationActivities.setId(idGenerator.generate());
relationActivities.setBizdType(relateCertificateParam.getType());
if (relateCertificateParam.getType() == 0) {
relationActivities.setBizdName(relateCertificateParam.getBizdName());
relationActivities.setTpPlanName(relateCertificateParam.getTpPlanName());
} else {
relationActivities.setTpPlanName(relateCertificateParam.getBizdName());
}
relationActivities.setCompanyId(res.getCompanyId());
relationActivities.setSiteId(res.getSiteId());
relationActivities.setCreateById(res.getAccountId());
relationActivities.setCreateByName(res.getAccountName());
relationActivities.setCreateTime(new Date());
relationActivities.setUpdateById(res.getAccountId());
relationActivities.setUpdateByName(res.getAccountName());
relationActivities.setUpdateTime(new Date());
relationActivitiesService.insert(relationActivities);
}
}
}
return true;
}
@Override
public Boolean cancelRelate(Long certificateId, Long projectId, Long tpPlanId) {
return this.baseMapper.cancelRelate(certificateId);
}
@Override
public Map<Long, Certificate> getCertificateMap(List<Long> certificateIds) {
Map<Long, Certificate> map = new HashMap<>(6);
if (CollectionUtils.isEmpty(certificateIds)) {
return map;
}
List<Certificate> list = this.baseMapper.getCertificateMap(certificateIds);
if (!CollectionUtils.isEmpty(list)) {
for (Certificate certificate : list) {
map.put(certificate.getId(), certificate);
}
}
return map;
}
@Override
public Integer getCertificateNum(CertificateNumParam certificateNumParam) {
return this.baseMapper.getCertificateNum(certificateNumParam.getBizdId(),
certificateNumParam.getAccountId(),
certificateNumParam.getType(),
certificateNumParam.getStartTime(),
certificateNumParam.getEndTime());
}
}
package com.yizhi.certificate.application.service.impl;
import com.baomidou.mybatisplus.plugins.Page;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import com.yizhi.certificate.application.domain.TrUserCertificate;
import com.yizhi.certificate.application.mapper.CertificateUserMapper;
import com.yizhi.certificate.application.service.CertificateUserService;
import com.yizhi.certificate.application.vo.CertificateListVO;
import com.yizhi.certificate.application.vo.CertificateUserListVO;
import com.yizhi.certificate.application.vo.CertificateUserParamVO;
import com.yizhi.certificate.application.vo.TrUserCertificateDetailsVo;
import com.yizhi.core.application.context.RequestContext;
import com.yizhi.system.application.constant.AuthzConstant;
import com.yizhi.system.application.system.remote.AccountClient;
import com.yizhi.system.application.system.remote.ReportClient;
import com.yizhi.system.application.vo.HQAccountInManageParam;
import com.yizhi.system.application.vo.ReportAccountRespInManageVO;
import com.yizhi.system.application.vo.ReportAccountRespVO;
import com.yizhi.system.application.vo.ReportRangeAccountReqVO;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
@Service
public class CertificateUserServiceImpl extends
ServiceImpl<CertificateUserMapper, TrUserCertificate> implements
CertificateUserService {
private static final Logger LOGGER = LoggerFactory
.getLogger(CertificateUserServiceImpl.class);
@Autowired
CertificateUserMapper certificateUserMapper;
@Autowired
AccountClient accountClient;
@Autowired
ReportClient reportClient;
@Override
public Page<CertificateUserListVO> userRankList(String startDate,
String endDate, Integer pageNo, Integer pageSize, Long siteId,
Long companyId, String userName, String orgNameLike, List<Long> orgIds, boolean isAdmin , Long accountId1) {
CertificateUserParamVO vo = new CertificateUserParamVO();
vo.setUserName(userName);
vo.setOrgNameLike(orgNameLike);
vo.setCompanyId(companyId);
vo.setSiteId(siteId);
vo.setPageNo(pageNo);
vo.setPageSize(pageSize);
vo.setOrgIds(orgIds);
vo.setAccountId(accountId1);
Page<CertificateUserListVO> page = new Page<CertificateUserListVO>(
vo.getPageNo(), vo.getPageSize());
//根据 用户关键字 获取用户id 集合
List<ReportAccountRespVO> accountVOList = null;
boolean isGetAccount = true;
if (isAdmin) {
//管理员模糊查询
if (StringUtils.isNotBlank(userName) || StringUtils.isNotBlank(orgNameLike)) {
isGetAccount = false;
ReportRangeAccountReqVO reportRangeAccountReqVO = new ReportRangeAccountReqVO();
reportRangeAccountReqVO.setSiteId(vo.getSiteId());
if (StringUtils.isNotBlank(userName)) {
reportRangeAccountReqVO.setAccountName(userName.trim());
}
if (StringUtils.isNotBlank(orgNameLike)) {
reportRangeAccountReqVO.setOrgName(orgNameLike.trim());
}
accountVOList = reportClient.getRangeAccounts(reportRangeAccountReqVO);
if (CollectionUtils.isEmpty(accountVOList)) {
return page;
}
}
} else {
isGetAccount = false;
//一般管理员
HQAccountInManageParam reportRangeAccountReqVO = new HQAccountInManageParam();
reportRangeAccountReqVO.setAccountId(vo.getAccountId());
reportRangeAccountReqVO.setSiteId(vo.getSiteId());
reportRangeAccountReqVO.setModuleType(AuthzConstant.moduleType.statistics_certificate);
if (StringUtils.isNotBlank(userName)) {
reportRangeAccountReqVO.setAccountName(userName.trim());
}
if (StringUtils.isNotBlank(orgNameLike)) {
reportRangeAccountReqVO.setOrgName(orgNameLike.trim());
}
ReportAccountRespInManageVO reportAccountRespInManageVO = reportClient.getRangeAccountsInManage(reportRangeAccountReqVO);
if (null != reportAccountRespInManageVO) {
if (!reportAccountRespInManageVO.getIsAdmin()) {
accountVOList = reportAccountRespInManageVO.getList();
} else {
if (StringUtils.isNotBlank(userName) || StringUtils.isNotBlank(orgNameLike)) {
isGetAccount = false;
ReportRangeAccountReqVO reportRangeAccountReqVO1 = new ReportRangeAccountReqVO();
reportRangeAccountReqVO1.setSiteId(vo.getSiteId());
if (StringUtils.isNotBlank(userName)) {
reportRangeAccountReqVO1.setAccountName(userName.trim());
}
if (StringUtils.isNotBlank(orgNameLike)) {
reportRangeAccountReqVO1.setOrgName(orgNameLike.trim());
}
accountVOList = reportClient.getRangeAccounts(reportRangeAccountReqVO1);
if (CollectionUtils.isEmpty(accountVOList)) {
return page;
}
} else {
//授权根目录
if (StringUtils.isNotBlank(userName) || StringUtils.isNotBlank(orgNameLike)) {
isGetAccount = false;
ReportRangeAccountReqVO reportRangeAccountReqVO1 = new ReportRangeAccountReqVO();
reportRangeAccountReqVO1.setSiteId(vo.getSiteId());
if (StringUtils.isNotBlank(userName)) {
reportRangeAccountReqVO1.setAccountName(userName.trim());
}
if (StringUtils.isNotBlank(orgNameLike)) {
reportRangeAccountReqVO1.setOrgName(orgNameLike.trim());
}
accountVOList = reportClient.getRangeAccounts(reportRangeAccountReqVO1);
if (CollectionUtils.isEmpty(accountVOList)) {
return page;
}
} else {
isGetAccount = true;
}
}
}
}
if (CollectionUtils.isEmpty(accountVOList)) {
return page;
}
}
Map<Long, ReportAccountRespVO> accountMap = new HashMap<>(16);
List<Long> accountIds = new ArrayList<>();
if (!CollectionUtils.isEmpty(accountVOList)) {
for (ReportAccountRespVO reportAccountRespVO : accountVOList) {
accountIds.add(reportAccountRespVO.getUserId());
accountMap.put(reportAccountRespVO.getUserId(), reportAccountRespVO);
}
}
List<CertificateUserListVO> list = null;
//管理员不带模糊查询或者授权用户管理的根目录,不带用户id筛选
if (isGetAccount) {
list = certificateUserMapper.userRankList(
vo.getSiteId(), vo.getCompanyId(), null, startDate, endDate, page);
//根据记录查找对应的用户信息并放入map中,优化性能
if (!CollectionUtils.isEmpty(list)) {
for (CertificateUserListVO certificateUserListVO : list) {
accountIds.add(certificateUserListVO.getAccountId());
}
ReportRangeAccountReqVO reportRangeAccountReqVO = new ReportRangeAccountReqVO();
reportRangeAccountReqVO.setSiteId(vo.getSiteId());
reportRangeAccountReqVO.setAccountIds(accountIds);
accountVOList = reportClient.getRangeAccounts(reportRangeAccountReqVO);
if (!CollectionUtils.isEmpty(accountVOList)) {
for (ReportAccountRespVO respVO : accountVOList) {
accountMap.put(respVO.getUserId(), respVO);
}
} else {
page.setTotal(0);
return page;
}
}
} else {
//其他都带accountIds筛选
list = certificateUserMapper.userRankList(
vo.getSiteId(), vo.getCompanyId(), accountIds, startDate, endDate, page);
}
if (!CollectionUtils.isEmpty(list)) {
for (CertificateUserListVO cvo : list) {
Long accountId = cvo.getAccountId();
if (accountId == null) {
continue;
}
ReportAccountRespVO reportAccountRespVO = accountMap.get(accountId);
if (reportAccountRespVO != null) {
cvo.setUserName(reportAccountRespVO.getUserName());
cvo.setName(reportAccountRespVO.getUserFullName());
cvo.setOrgName(reportAccountRespVO.getOrgName());
cvo.setOrgId(reportAccountRespVO.getOrgId());
cvo.setWorkNum(reportAccountRespVO.getWorkNum());
cvo.setPosition(reportAccountRespVO.getPosition());
cvo.setAccountState(reportAccountRespVO.getStatus() == 1 ? true : false);
}
}
page.setRecords(list);
}
return page;
}
@Override
public Page<TrUserCertificateDetailsVo> userDetails(String startDate, String endDate, Integer pageNo, Integer pageSize, Long siteId,
Long companyId, String userName, String orgNameLike, List<Long> orgIds, boolean isAdmin, Long accountId1) {
CertificateUserParamVO vo = new CertificateUserParamVO();
vo.setUserName(userName);
vo.setOrgNameLike(orgNameLike);
vo.setCompanyId(companyId);
vo.setSiteId(siteId);
vo.setPageNo(pageNo);
vo.setPageSize(pageSize);
vo.setOrgIds(orgIds);
vo.setAccountId(accountId1);
Page<TrUserCertificateDetailsVo> page = new Page<TrUserCertificateDetailsVo>(
vo.getPageNo(), vo.getPageSize());
//根据 用户关键字 获取用户id 集合
List<ReportAccountRespVO> accountVOList = null;
if (isAdmin) {
ReportRangeAccountReqVO reportRangeAccountReqVO = new ReportRangeAccountReqVO();
reportRangeAccountReqVO.setSiteId(vo.getSiteId());
if (StringUtils.isNotBlank(userName)) {
reportRangeAccountReqVO.setAccountName(userName.trim());
}
if (StringUtils.isNotBlank(orgNameLike)) {
reportRangeAccountReqVO.setOrgName(orgNameLike.trim());
}
accountVOList = reportClient.getRangeAccounts(reportRangeAccountReqVO);
} else {
HQAccountInManageParam reportRangeAccountReqVO = new HQAccountInManageParam();
reportRangeAccountReqVO.setAccountId(vo.getAccountId());
reportRangeAccountReqVO.setSiteId(vo.getSiteId());
reportRangeAccountReqVO.setModuleType(AuthzConstant.moduleType.statistics_certificate);
if (StringUtils.isNotBlank(userName)) {
reportRangeAccountReqVO.setAccountName(userName.trim());
}
if (StringUtils.isNotBlank(orgNameLike)) {
reportRangeAccountReqVO.setOrgName(orgNameLike.trim());
}
ReportAccountRespInManageVO reportAccountRespInManageVO = reportClient.getRangeAccountsInManage(reportRangeAccountReqVO);
if (null != reportAccountRespInManageVO) {
if (reportAccountRespInManageVO.getIsAdmin()) {
//管辖区为根目录
ReportRangeAccountReqVO reportRangeAccountReqVO1 = new ReportRangeAccountReqVO();
reportRangeAccountReqVO1.setSiteId(vo.getSiteId());
if (StringUtils.isNotBlank(userName)) {
reportRangeAccountReqVO1.setAccountName(userName.trim());
}
if (StringUtils.isNotBlank(orgNameLike)) {
reportRangeAccountReqVO1.setOrgName(orgNameLike.trim());
}
accountVOList = reportClient.getRangeAccounts(reportRangeAccountReqVO1);
} else {
accountVOList = reportAccountRespInManageVO.getList();
}
}
}
Map<Long, ReportAccountRespVO> accountMap = new HashMap<>(16);
List<Long> accountIds = new ArrayList<>();
if (!CollectionUtils.isEmpty(accountVOList)) {
for (ReportAccountRespVO reportAccountRespVO : accountVOList) {
accountIds.add(reportAccountRespVO.getUserId());
accountMap.put(reportAccountRespVO.getUserId(), reportAccountRespVO);
}
} else {
return page;
}
List<TrUserCertificateDetailsVo> list = certificateUserMapper.userDetailsList(
vo.getSiteId(), vo.getCompanyId(), accountIds, startDate, endDate, page);
if (!CollectionUtils.isEmpty(list)) {
for (TrUserCertificateDetailsVo cvo : list) {
Long accountId = cvo.getAccountId();
if (accountId == null) {
continue;
}
ReportAccountRespVO reportAccountRespVO = accountMap.get(accountId);
if (reportAccountRespVO != null) {
cvo.setUserName(reportAccountRespVO.getUserName());
cvo.setFullName(reportAccountRespVO.getUserFullName());
cvo.setWorkNum(reportAccountRespVO.getWorkNum());
cvo.setPosition(reportAccountRespVO.getPosition());
cvo.setOrgName(reportAccountRespVO.getOrgName());
cvo.setOrgId(reportAccountRespVO.getOrgId());
cvo.setAccountState(reportAccountRespVO.getStatus());
cvo.setOrgName(reportAccountRespVO.getOrgName());
cvo.setAccountState(reportAccountRespVO.getStatus());
}
}
page.setRecords(list);
}
return page;
}
@Override
public Page<CertificateListVO> certificateList(String startDate, String endDate, String certificateName, Integer pageNo, Integer pageSize, RequestContext res) {
Page<CertificateListVO> page = new Page<>(pageNo, pageSize);
//根据 用户关键字 获取用户id 集合
List<Long> accountIds = null;
if (!res.isAdmin()) {
HQAccountInManageParam reportRangeAccountReqVO = new HQAccountInManageParam();
reportRangeAccountReqVO.setAccountId(res.getAccountId());
reportRangeAccountReqVO.setSiteId(res.getSiteId());
reportRangeAccountReqVO.setModuleType(AuthzConstant.moduleType.statistics_certificate);
ReportAccountRespInManageVO reportAccountRespInManageVO = reportClient.getRangeAccountsInManage(reportRangeAccountReqVO);
if (null != reportAccountRespInManageVO) {
if (!reportAccountRespInManageVO.getIsAdmin()) {
List<ReportAccountRespVO> accountList = reportAccountRespInManageVO.getList();
if (!CollectionUtils.isEmpty(accountList)) {
accountIds = accountList.stream().map(ReportAccountRespVO::getUserId).collect(Collectors.toList());
}
if (CollectionUtils.isEmpty(accountIds)) {
return page;
}
}
}
}
Integer start = (pageNo - 1) * pageSize;
List<CertificateListVO> list = certificateUserMapper.certificateList(startDate, endDate, certificateName, start, pageSize, res.getCompanyId(), res.getSiteId(), accountIds);
Integer total = certificateUserMapper.certificateListCount(startDate, endDate, certificateName, res.getCompanyId(), res.getSiteId(), accountIds);
page.setTotal(total);
if (!CollectionUtils.isEmpty(list)) {
page.setRecords(list);
}
return page;
}
}
package com.yizhi.certificate.application.service.impl;
import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import com.yizhi.application.orm.id.IdGenerator;
import com.yizhi.certificate.application.domain.CertificateClassify;
import com.yizhi.certificate.application.mapper.ClassifyMapper;
import com.yizhi.certificate.application.service.IClassifyService;
import com.yizhi.certificate.application.vo.CertificateClassifyListVO;
import com.yizhi.certificate.application.vo.CertificateClassifyVO;
import com.yizhi.certificate.application.vo.domain.CertificateClassifyVo;
import com.yizhi.core.application.context.ContextHolder;
import com.yizhi.core.application.context.RequestContext;
import com.yizhi.util.application.beanutil.BeanCopyListUtil;
import org.apache.commons.collections.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.*;
/**
* <p>
* 服务实现类
* </p>
*
* @author dingxiaowei123
* @since 2019-12-23
*/
@Service
public class ClassifyServiceImpl extends ServiceImpl<ClassifyMapper, CertificateClassify> implements IClassifyService {
@Autowired
private IdGenerator idGenerator;
@Autowired
private ClassifyMapper classifyMapper;
@Override
public Integer insertClassify(CertificateClassify certificateClassify) {
RequestContext res = ContextHolder.get();
if (null != certificateClassify) {
if (null != certificateClassify.getLevel()) {
//等级异常
if (certificateClassify.getLevel() < 1 || certificateClassify.getLevel() > 3){
return 2;
}
}
Date date = new Date();
//验证同级分类下是否重名
CertificateClassify certificateClassify1 = new CertificateClassify();
if (certificateClassify.getLevel() == 1) {
certificateClassify1.setParentId(0L);
} else {
certificateClassify1.setParentId(certificateClassify.getParentId());
}
certificateClassify1.setCompanyId(res.getCompanyId());
certificateClassify1.setSiteId(res.getSiteId());
certificateClassify1.setName(certificateClassify.getName());
certificateClassify1.setState(1);
List<CertificateClassify> classifyList = this.selectList(new EntityWrapper<>(certificateClassify1));
//同级分类下有重名返回
if (CollectionUtils.isNotEmpty(classifyList)) {
return 3;
}
if (null == certificateClassify.getId()) {
certificateClassify.setId(idGenerator.generate());
}
if (certificateClassify.getLevel() == 1) {
Integer maxCode = classifyMapper.getMaxCode(res.getCompanyId(), res.getSiteId());
if (null == maxCode) {
maxCode = 999;
}
certificateClassify.setParentId(0L);
certificateClassify.setRootId(0L);
certificateClassify.setCode(maxCode + 1);
}
if (certificateClassify.getLevel() == 2) {
//二级分类的rootId即为parentId
certificateClassify.setRootId(certificateClassify.getParentId());
} else if (certificateClassify.getLevel() == 3) {
//三级分类的rootId即为上级分类的parentId
CertificateClassify certificateClassify2 = this.selectById(certificateClassify.getParentId());
if (null != certificateClassify2) {
certificateClassify.setRootId(certificateClassify2.getParentId());
}
}
certificateClassify.setCompanyId(res.getCompanyId());
certificateClassify.setSiteId(res.getSiteId());
certificateClassify.setOrgId(res.getOrgId());
certificateClassify.setCreateById(res.getAccountId());
certificateClassify.setCreateByName(res.getAccountName());
certificateClassify.setCreateTime(date);
certificateClassify.setUpdateById(res.getAccountId());
certificateClassify.setUpdateByName(res.getAccountName());
certificateClassify.setUpdateTime(date);
this.insert(certificateClassify);
return 1;
}
return 2;
}
@Override
public List<CertificateClassifyListVO> getClassifyList() {
RequestContext res = ContextHolder.get();
CertificateClassify certificateClassify = new CertificateClassify();
certificateClassify.setParentId(0L);
certificateClassify.setState(1);
certificateClassify.setLevel(1);
certificateClassify.setCompanyId(res.getCompanyId());
certificateClassify.setSiteId(res.getSiteId());
//获取一级分类列表
List<CertificateClassify> classifyList = this.selectList(new EntityWrapper<>(certificateClassify));
List<CertificateClassifyListVO> list = new ArrayList<>();
if (CollectionUtils.isNotEmpty(classifyList)) {
list = JSON.parseArray(JSON.toJSONString(classifyList), CertificateClassifyListVO.class);
} else {
return list;
}
//获取所有二级,三级分类
CertificateClassify certificateClassify2 = new CertificateClassify();
certificateClassify2.setState(1);
certificateClassify2.setCompanyId(res.getCompanyId());
certificateClassify2.setSiteId(res.getSiteId());
EntityWrapper<CertificateClassify> entityWrapper = new EntityWrapper<>(certificateClassify2);
List<Integer> levelList = new ArrayList<>();
levelList.add(2);
levelList.add(3);
entityWrapper.in("level", levelList);
List<CertificateClassify> list1 = this.selectList(entityWrapper);
//二级分类map
Map<Long, List<CertificateClassify>> levelTwoMap = new HashMap<>(16);
//三级分类map
Map<Long, List<CertificateClassify>> levelThreeMap = new HashMap<>(16);
if (CollectionUtils.isNotEmpty(list1)) {
for (CertificateClassify certificateClassify1 : list1) {
if (certificateClassify1.getLevel() == 2) {
List<CertificateClassify> levelTwoList = new ArrayList<>();
//获取是否创建对应二级分类下list
levelTwoList = levelTwoMap.get(certificateClassify1.getParentId());
if (null == levelTwoList) {
//没有就新建
levelTwoList = new ArrayList<>();
}
//添加到对应list中放入map中
levelTwoList.add(certificateClassify1);
levelTwoMap.put(certificateClassify1.getParentId(), levelTwoList);
} else if (certificateClassify1.getLevel() == 3) {
List<CertificateClassify> levelThreeList = new ArrayList<>();
//获取是否创建对应三级分类下list
levelThreeList = levelThreeMap.get(certificateClassify1.getParentId());
if (null == levelThreeList) {
//没有就新建
levelThreeList = new ArrayList<>();
}
//添加到对应list中放入map中
levelThreeList.add(certificateClassify1);
levelThreeMap.put(certificateClassify1.getParentId(), levelThreeList);
}
}
if (CollectionUtils.isNotEmpty(list)) {
for (CertificateClassifyListVO classifyListVO : list) {
//组装codeName
String codeName = classifyListVO.getCode().toString() + "--" + classifyListVO.getName();
//获取二级分类列表
List<CertificateClassify> classifyList1 = levelTwoMap.get(classifyListVO.getId());
List<CertificateClassifyVO> classifyVOList = new ArrayList<>();
if (CollectionUtils.isNotEmpty(classifyList1)) {
classifyVOList = JSON.parseArray(JSON.toJSONString(classifyList1), CertificateClassifyVO.class);
}
if (CollectionUtils.isNotEmpty(classifyVOList)) {
//装配二级分类
classifyListVO.setChildren(classifyVOList);
for (CertificateClassifyVO classifyVO : classifyVOList) {
//获取一级分类
List<CertificateClassify> classifyList2 = levelThreeMap.get(classifyVO.getId());
if (CollectionUtils.isNotEmpty(classifyList2)) {
List<CertificateClassifyVo> certificateClassifyVos = BeanCopyListUtil.copyListProperties(classifyList2, CertificateClassifyVo::new);
classifyVO.setChildren(certificateClassifyVos);
}
}
}
}
}
}
return list;
}
@Override
public boolean updateClassify(CertificateClassify certificateClassify) {
RequestContext res = ContextHolder.get();
//验证同级分类下是否重名
CertificateClassify certificateClassify1 = new CertificateClassify();
if (certificateClassify.getLevel() == 1) {
certificateClassify1.setParentId(0L);
} else {
certificateClassify1.setParentId(certificateClassify.getParentId());
}
certificateClassify1.setCompanyId(res.getCompanyId());
certificateClassify1.setSiteId(res.getSiteId());
certificateClassify1.setName(certificateClassify.getName());
certificateClassify1.setState(1);
EntityWrapper<CertificateClassify> entityWrapper = new EntityWrapper<>(certificateClassify1);
entityWrapper.notIn("id", certificateClassify.getId());
List<CertificateClassify> classifyList = this.selectList(entityWrapper);
//同级分类下有重名返回
if (CollectionUtils.isNotEmpty(classifyList)) {
return false;
}
certificateClassify.setUpdateById(res.getAccountId());
certificateClassify.setUpdateByName(res.getAccountName());
certificateClassify.setUpdateTime(new Date());
this.updateById(certificateClassify);
return true;
}
@Override
public Integer deleteClassify(Long id) {
CertificateClassify certificateClassify = this.selectById(id);
RequestContext res = ContextHolder.get();
//先查找是否被关联
Integer relationNum = classifyMapper.getRelationNum(id, res.getCompanyId(), res.getSiteId());
if (relationNum > 0) {
return 2;
}
if (certificateClassify.getLevel() == 1 || certificateClassify.getLevel() == 2) {
CertificateClassify certificateClassify1 = new CertificateClassify();
certificateClassify1.setParentId(certificateClassify.getId());
certificateClassify1.setState(1);
certificateClassify1.setCompanyId(res.getCompanyId());
certificateClassify1.setSiteId(res.getSiteId());
List<CertificateClassify> list = this.selectList(new EntityWrapper<>(certificateClassify1));
if (CollectionUtils.isNotEmpty(list)) {
//有子分类,不能删除
return 2;
}
}
certificateClassify.setState(0);
certificateClassify.setUpdateTime(new Date());
certificateClassify.setUpdateById(res.getAccountId());
certificateClassify.setUpdateByName(res.getAccountName());
this.updateById(certificateClassify);
return 1;
}
}
package com.yizhi.certificate.application.service.impl;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import com.yizhi.certificate.application.domain.RelationActivities;
import com.yizhi.certificate.application.mapper.RelationActivitiesMapper;
import com.yizhi.certificate.application.service.IRelationActivitiesService;
import com.yizhi.core.application.context.ContextHolder;
import com.yizhi.core.application.context.RequestContext;
import org.apache.commons.collections.CollectionUtils;
import org.springframework.stereotype.Service;
import java.util.List;
/**
* <p>
* 学员证书中间表 服务实现类
* </p>
*
* @author dingxiaowei123
* @since 2019-12-30
*/
@Service
public class RelationActivitiesServiceImpl extends ServiceImpl<RelationActivitiesMapper, RelationActivities> implements IRelationActivitiesService {
@Override
public List<RelationActivities> getRelationActivities(Long certificateId) {
RequestContext res = ContextHolder.get();
RelationActivities relationActivities = new RelationActivities();
relationActivities.setCertificateId(certificateId);
relationActivities.setRelationState(1);
List<RelationActivities> list = this.selectList(new EntityWrapper<>(relationActivities));
if (CollectionUtils.isNotEmpty(list)){
for (RelationActivities relationActivities1 : list){
if (relationActivities1.getBizdType()==0){
continue;
}else {
relationActivities1.setBizdName(relationActivities1.getTpPlanName());
relationActivities1.setTpPlanName(null);
}
}
}
return list;
}
}
package com.yizhi.certificate.application.service.impl;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import com.yizhi.certificate.application.domain.TrCertificateTemplate;
import com.yizhi.certificate.application.mapper.TrCertificateTemplateMapper;
import com.yizhi.certificate.application.service.ITrCertificateTemplateService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;
/**
* <p>
* 证书模板表 服务实现类
* </p>
*
* @author fulan123
* @since 2018-03-07
*/
@Service
public class TrCertificateTemplateServiceImpl extends ServiceImpl<TrCertificateTemplateMapper, TrCertificateTemplate> implements ITrCertificateTemplateService {
private Logger logger= LoggerFactory.getLogger(TrCertificateTemplateServiceImpl.class);
@Autowired
private TrCertificateTemplate trCertificateTemplate;
@Autowired
private TrCertificateTemplateMapper certificateTemplateMapper;
/**
* 获取通用模板列表
* @return
*/
public List<TrCertificateTemplate> getList() {
trCertificateTemplate.setType(0);
try {
return certificateTemplateMapper.selectList(new EntityWrapper<TrCertificateTemplate>(trCertificateTemplate));
} catch (Exception e) {
e.printStackTrace();
logger.error("获取模板列表失败");
return null;
}
}
}
package com.yizhi.certificate.application.service.impl;
import com.baomidou.mybatisplus.plugins.Page;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import com.yizhi.certificate.application.domain.TrUserCertificate;
import com.yizhi.certificate.application.mapper.TrUserCertificateMapper;
import com.yizhi.certificate.application.service.ITrUserCertificateService;
import com.yizhi.certificate.application.vo.ApiUserCertificateVo;
import com.yizhi.certificate.application.vo.FirstVO;
import com.yizhi.certificate.application.vo.TrUserCertificatePcVo;
import org.apache.ibatis.session.RowBounds;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* <p>
* 学员证书中间表 服务实现类
* </p>
*
* @author fulan123
* @since 2018-03-07
*/
@Service
public class TrUserCertificateServiceImpl extends ServiceImpl<TrUserCertificateMapper, TrUserCertificate> implements ITrUserCertificateService {
@Autowired
private TrUserCertificateMapper trCertificateMapper;
/**
* 根据学员端用户id查询学员端证书数量
*
* @return
*/
public Integer getCertificateCount(Long accountId, Long companyId,
Long siteId) {
return trCertificateMapper.getCertificateCount(accountId,companyId,siteId);
}
public Page<TrUserCertificate> getMyList(Long accountId, String certificate_title, String validityType, Long companyId,
Long siteId, Integer pageNo, Integer pageSize) {
Page<TrUserCertificate> page = new Page<TrUserCertificate>(pageNo, pageSize);
List<TrUserCertificate> trUserCertificates = this.baseMapper.getMyList(accountId,certificate_title,validityType,companyId,siteId, new RowBounds(page.getOffset(), page.getLimit()));
page.setRecords(trUserCertificates);
Integer count = this.trCertificateMapper.getMyListCount(accountId,certificate_title,validityType,companyId,siteId);
page.setTotal(count);
return page;
}
public Page<ApiUserCertificateVo> getMyListSearch(Long accountId, String certificate_title, Long companyId,
Long siteId,Integer pageNo, Integer pageSize) {
Page<ApiUserCertificateVo> page = new Page<ApiUserCertificateVo>(pageNo, pageSize);
List<ApiUserCertificateVo> trUserCertificates = this.baseMapper.getMyListSearch(accountId,certificate_title,companyId,siteId, new RowBounds(page.getOffset(), page.getLimit()));
page.setRecords(trUserCertificates);
Integer count = this.baseMapper.getMyListSearchCount(accountId,certificate_title,companyId,siteId);
page.setTotal(count);
return page;
}
/**
* 根据学员证书中间表id 获取图片和证书名称( PC端 )
*
* @param id
* @return
*/
public TrUserCertificatePcVo viewImage(Long id) {
TrUserCertificate trUserCertificate = trCertificateMapper.selectById(id);
TrUserCertificatePcVo trUserCertificatePcVo = new TrUserCertificatePcVo();
trUserCertificatePcVo.setId(id);
trUserCertificatePcVo.setCertificateLogourl(trUserCertificate.getCertificateLogourl());
trUserCertificatePcVo.setCertificateTitle(trUserCertificate.getCertificateTitle());
return trUserCertificatePcVo;
}
public String getCountByCompanyId(Long companyId) {
// TODO Auto-generated method stub
return trCertificateMapper.getCountByCompanyId(companyId);
}
@Override
public Map<Long, Date> first(List<Long> siteIds, String startDate, String endDate) {
// TODO Auto-generated method stub
Map<Long, Date> hashMap = new HashMap<Long, Date>();
List<FirstVO> list = trCertificateMapper.first(siteIds, startDate, endDate);
for(FirstVO vo:list){
hashMap.put(vo.getAccountId(), vo.getFirst());
}
return hashMap;
}
}
package com.yizhi.certificate.application.util;
import java.text.SimpleDateFormat;
import java.util.Date;
import com.yizhi.certificate.application.domain.Certificate;
import com.yizhi.certificate.application.domain.TrUserCertificate;
import com.yizhi.certificate.application.service.ITrUserCertificateService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
@Component
public class CertificateCodeLock {
@Autowired
ITrUserCertificateService trUserCertificateService;
public void addCertificateCode(Certificate certificate, TrUserCertificate trUserCertificate) {
synchronized (this) {
if (0 == certificate.getRuleType()) {
String max = trUserCertificateService.getCountByCompanyId(certificate.getCompanyId());
if (null == max) {
max = "0";
}
Integer count = Integer.valueOf(max);
SimpleDateFormat format = new SimpleDateFormat("yyyyMMdd");
String date = format.format(new Date());
if (String.valueOf(count).length() <= 6) {
trUserCertificate.setCertificateCode(date + String.format("%06d", count + 1));
} else {
trUserCertificate.setCertificateCode(
date + String.format("%0" + String.valueOf(count).length() + "d", count + 1));
}
} else {
String max = trUserCertificateService.getCountByCompanyId(certificate.getCompanyId());
if (null == max) {
max = "0";
}
Integer count = Integer.valueOf(max);
if (String.valueOf(count).length() <= 6) {
trUserCertificate.setCertificateCode(String.format("%06d", count + 1));
} else {
trUserCertificate
.setCertificateCode(String.format("%0" + String.valueOf(count).length() + "d", count + 1));
}
}
}
}
}
package com.yizhi.certificate.application.util;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Component;
import org.springframework.util.StringUtils;
@Component
public class RedisLock {
Logger logger = LoggerFactory.getLogger(this.getClass());
// @Autowired
private StringRedisTemplate redisTemplate;
/**
* 加锁
* @param key 证书id
* @param value 当前时间+超时时间
* @return
*/
public boolean lock(String key, String value) {
if (redisTemplate.opsForValue().setIfAbsent(key, value)) {
return true;
}
//避免死锁,且只让一个线程拿到锁
String currentValue = redisTemplate.opsForValue().get(key);
//如果锁过期了
if (!StringUtils.isEmpty(currentValue) && Long.parseLong(currentValue) < System.currentTimeMillis()) {
//获取上一个锁的时间
String oldValues = redisTemplate.opsForValue().getAndSet(key, value);
/*
只会让一个线程拿到锁
如果旧的value和currentValue相等,只会有一个线程达成条件,因为第二个线程拿到的oldValue已经和currentValue不一样了
*/
if (!StringUtils.isEmpty(oldValues) && oldValues.equals(currentValue)) {
return true;
}
}
return false;
}
/**
* 解锁
* @param key
* @param value
*/
public void unlock(String key, String value) {
try {
String currentValue = redisTemplate.opsForValue().get(key);
if (!StringUtils.isEmpty(currentValue) && currentValue.equals(value)) {
redisTemplate.opsForValue().getOperations().delete(key);
}
} catch (Exception e) {
logger.error("『redis分布式锁』解锁异常,{}", e);
}
}
}
\ No newline at end of file
server.port=33012
spring.application.name=certificate
ACTIVE=${spring.profiles.active}
spring.profiles.active=dev
# nacos
spring.cloud.nacos.config.shared-dataids=common-${spring.profiles.active}.properties
spring.cloud.nacos.config.namespace=${spring.profiles.active}
spring.cloud.nacos.config.prefix=${spring.application.name}
spring.cloud.nacos.config.file-extension=properties
spring.cloud.nacos.config.server-addr=192.168.1.22:3333,192.168.1.22:4444,192.168.1.22:5555
package ${package.Entity};
#if(${activeRecord})
import java.io.Serializable;
#end
#foreach($pkg in ${table.importPackages})
import ${pkg};
#end
#if(${entityLombokModel})
import com.baomidou.mybatisplus.annotations.Version;
import lombok.Data;
#end
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiModelProperty;
/**
* <p>
* $!{table.comment}
* </p>
*
* @author ${author}
* @since ${date}
*/
#if(${entityLombokModel})
@Data
#end
@Api(tags = "${entity}", description = "${table.comment}")
#if(${table.convert})
@TableName("${table.name}")
#end
#if(${superEntityClass})
public class ${entity} extends ${superEntityClass}#if(${activeRecord})<${entity}>#end {
#elseif(${activeRecord})
public class ${entity} extends Model<${entity}> {
#else
public class ${entity} implements Serializable {
#end
private static final long serialVersionUID = 1L;
##
#foreach($field in ${table.fields})
#if(${field.keyFlag})
#set($keyPropertyName=${field.propertyName})
#end
#if("$!field.comment" != "")
@ApiModelProperty(value = "${field.comment}")
#end
#if(${field.keyFlag})
##
#if(${field.keyIdentityFlag})
@TableId(value="${field.name}", type= IdType.AUTO)
#elseif(${field.convert})
@TableId("${field.name}")
#end
##
#elseif(${field.fill})
##
#if(${field.convert})
@TableField(value = "${field.name}", fill = FieldFill.${field.fill})
#else
@TableField(fill = FieldFill.${field.fill})
#end
#elseif(${field.convert})
#if(${field.name}=="create_by_id" || ${field.name}=="create_by_name" || ${field.name}=="create_time"
|| ${field.name}=="update_by_id" || ${field.name}=="update_by_name" || ${field.name}=="update_time")
@TableField(value = "${field.name}", fill = FieldFill.INSERT)
#else
@TableField("${field.name}")
#end
#end
##
#if(${versionFieldName}==${field.name})
@Version
#end
##
#if(${logicDeleteFieldName}==${field.name})
@TableLogic
#end
private ${field.propertyType} ${field.propertyName};
#end
##
#if(!${entityLombokModel})
#foreach($field in ${table.fields})
#if(${field.propertyType.equals("boolean")})
#set($getprefix="is")
#else
#set($getprefix="get")
#end
public ${field.propertyType} ${getprefix}${field.capitalName}() {
return ${field.propertyName};
}
#if(${entityBuilderModel})
public ${entity} set${field.capitalName}(${field.propertyType} ${field.propertyName}) {
#else
public void set${field.capitalName}(${field.propertyType} ${field.propertyName}) {
#end
this.${field.propertyName} = ${field.propertyName};
#if(${entityBuilderModel})
return this;
#end
}
#end
#end
#if(${entityColumnConstant})
#foreach($field in ${table.fields})
public static final String ${field.name.toUpperCase()} = "${field.name}";
#end
#end
#if(${activeRecord})
@Override
protected Serializable pkVal() {
#if(${keyPropertyName})
return this.${keyPropertyName};
#else
return this.id;
#end
}
#end
#if(!${entityLombokModel})
@Override
public String toString() {
return "${entity}{" +
#foreach($field in ${table.fields})
#if($!{velocityCount}==1)
"${field.propertyName}=" + ${field.propertyName} +
#else
", ${field.propertyName}=" + ${field.propertyName} +
#end
#end
"}";
}
#end
}
<?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>
<parent>
<groupId>com.yizhi</groupId>
<artifactId>wmy-parent</artifactId>
<version>1.0-SNAPSHOT</version>
</parent>
<groupId>com.yizhi</groupId>
<artifactId>cloud-certificate</artifactId>
<version>1.0-SNAPSHOT</version>
<modules>
<module>cloud-certificate-api</module>
<module>cloud-certificate-service</module>
</modules>
<packaging>pom</packaging>
<dependencies>
<dependency>
<groupId>com.yizhi</groupId>
<artifactId>cloud-common-api</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>com.yizhi</groupId>
<artifactId>cloud-orm</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>com.yizhi</groupId>
<artifactId>cloud-util</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>com.yizhi</groupId>
<artifactId>cloud-core</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
</dependencies>
<repositories>
<repository>
<id>wmy4.0</id>
<url>http://mvn.km365.pw/nexus/content/groups/wmy4.0-group/</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
</repositories>
</project>
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