hgw vor 3 Jahren
Ursprung
Commit
467d734330
30 geänderte Dateien mit 1662 neuen und 1106 gelöschten Zeilen
  1. 6 0
      cms/pom.xml
  2. 13 2
      mec-auth/mec-auth-api/src/main/java/com/ym/mec/auth/api/entity/SysRole.java
  3. 7 0
      mec-biz/pom.xml
  4. 16 0
      mec-biz/src/main/java/com/ym/mec/biz/dal/dao/EmployeeDao.java
  5. 4 0
      mec-biz/src/main/java/com/ym/mec/biz/dal/dao/PlatformProductDao.java
  6. 0 2
      mec-biz/src/main/java/com/ym/mec/biz/dal/dao/TenantInfoDao.java
  7. 25 0
      mec-biz/src/main/java/com/ym/mec/biz/dal/dto/TenantConfigDto.java
  8. 24 0
      mec-biz/src/main/java/com/ym/mec/biz/dal/dto/TenantInfoDto.java
  9. 139 0
      mec-biz/src/main/java/com/ym/mec/biz/dal/dto/TenantOrderRecordDto.java
  10. 26 1
      mec-biz/src/main/java/com/ym/mec/biz/dal/entity/TenantConfig.java
  11. 4 0
      mec-biz/src/main/java/com/ym/mec/biz/dal/entity/TenantOrderRecord.java
  12. 32 0
      mec-biz/src/main/java/com/ym/mec/biz/dal/enums/TenantOrderRecordEnum.java
  13. 2 0
      mec-biz/src/main/java/com/ym/mec/biz/service/ContractService.java
  14. 7 0
      mec-biz/src/main/java/com/ym/mec/biz/service/EmployeeService.java
  15. 4 0
      mec-biz/src/main/java/com/ym/mec/biz/service/PlatformProductService.java
  16. 3 1
      mec-biz/src/main/java/com/ym/mec/biz/service/PlatformServeService.java
  17. 4 0
      mec-biz/src/main/java/com/ym/mec/biz/service/TenantOrderRecordService.java
  18. 1027 1049
      mec-biz/src/main/java/com/ym/mec/biz/service/impl/ContractServiceImpl.java
  19. 37 18
      mec-biz/src/main/java/com/ym/mec/biz/service/impl/EmployeeServiceImpl.java
  20. 13 2
      mec-biz/src/main/java/com/ym/mec/biz/service/impl/PlatformProductServiceImpl.java
  21. 144 16
      mec-biz/src/main/java/com/ym/mec/biz/service/impl/TenantInfoServiceImpl.java
  22. 23 0
      mec-biz/src/main/java/com/ym/mec/biz/service/impl/TenantOrderRecordServiceImpl.java
  23. 16 0
      mec-biz/src/main/resources/config/mybatis/EmployeeMapper.xml
  24. 13 0
      mec-biz/src/main/resources/config/mybatis/PlatformProductMapper.xml
  25. 7 4
      mec-biz/src/main/resources/config/mybatis/TenantConfigMapper.xml
  26. 0 6
      mec-biz/src/main/resources/config/mybatis/TenantInfoMapper.xml
  27. 1 1
      mec-common/common-core/src/main/java/com/ym/mec/common/page/PageUtil.java
  28. 50 0
      mec-common/common-core/src/main/java/com/ym/mec/common/page/QueryWrapperUtil.java
  29. 4 4
      mec-web/src/main/java/com/ym/mec/web/controller/TenantInfoController.java
  30. 11 0
      mec-web/src/main/java/com/ym/mec/web/controller/TenantOrderRecordController.java

+ 6 - 0
cms/pom.xml

@@ -56,6 +56,12 @@
 		<dependency>
 			<groupId>com.ym</groupId>
 			<artifactId>mec-auth-api</artifactId>
+            <exclusions>
+                <exclusion>
+                    <groupId>org.redisson</groupId>
+                    <artifactId>redisson-spring-boot-starter</artifactId>
+                </exclusion>
+            </exclusions>
 		</dependency>
 
 		<dependency>

+ 13 - 2
mec-auth/mec-auth-api/src/main/java/com/ym/mec/auth/api/entity/SysRole.java

@@ -35,9 +35,12 @@ public class SysRole {
 	/** 删除标识(0-正常,1-删除) */
 	@ApiModelProperty(value = "删除标识(0-正常,1-删除)",required = false)
 	private String delFlag;
-	
+
 	private Integer organId;
 
+	@ApiModelProperty(value = "机构id")
+	private Integer tenantId;
+
 	@ApiModelProperty(value = "菜单列表",required = false)
 	private List<Integer> menuIds;
 
@@ -113,7 +116,15 @@ public class SysRole {
 		this.organId = organId;
 	}
 
-	@Override
+    public Integer getTenantId() {
+        return tenantId;
+    }
+
+    public void setTenantId(Integer tenantId) {
+        this.tenantId = tenantId;
+    }
+
+    @Override
 	public String toString() {
 		return ToStringBuilder.reflectionToString(this);
 	}

+ 7 - 0
mec-biz/pom.xml

@@ -13,6 +13,7 @@
 	<url>http://maven.apache.org</url>
 	<properties>
 		<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+        <redisson.version>3.16.4</redisson.version>
 	</properties>
 
 	<dependencies>
@@ -39,5 +40,11 @@
 			<groupId>com.ym</groupId>
 			<artifactId>snakerflowy</artifactId>
 		</dependency>
+
+        <dependency>
+            <groupId>org.redisson</groupId>
+            <artifactId>redisson-spring-boot-starter</artifactId>
+            <version>${redisson.version}</version>
+        </dependency>
     </dependencies>
 </project>

+ 16 - 0
mec-biz/src/main/java/com/ym/mec/biz/dal/dao/EmployeeDao.java

@@ -1,5 +1,6 @@
 package com.ym.mec.biz.dal.dao;
 
+import com.ym.mec.auth.api.entity.SysRole;
 import com.ym.mec.auth.api.entity.SysUser;
 import com.ym.mec.biz.dal.dto.EmployeeDto;
 import com.ym.mec.biz.dal.dto.EmployeeLevelDto;
@@ -201,4 +202,19 @@ public interface EmployeeDao extends BaseDAO<Integer, Employee> {
      * @return
      */
     List<SysUser> getUsers(@Param("userIds") List<Integer> userIds);
+
+    /**
+     * 批量添加角色和菜单关系
+     * @param roleId 角色id
+     * @param menuIds 菜单集合
+     */
+    int batchInsertRoleMenu(@Param("roleId") Integer roleId,@Param("menuIds")  List<Integer> menuIds);
+
+    /**
+     * 添加角色信息
+     * @param sysRole
+     * @return
+     */
+    int insertSysRole(SysRole sysRole);
+
 }

+ 4 - 0
mec-biz/src/main/java/com/ym/mec/biz/dal/dao/PlatformProductDao.java

@@ -7,6 +7,8 @@ import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.ym.mec.biz.dal.entity.PlatformProduct;
 import org.apache.ibatis.annotations.Param;
 
+import java.util.List;
+
 public interface PlatformProductDao extends BaseMapper<PlatformProduct> {
     int deleteByPrimaryKey(Integer id);
 
@@ -17,4 +19,6 @@ public interface PlatformProductDao extends BaseMapper<PlatformProduct> {
     int updateByPrimaryKeySelective(PlatformProduct record);
 
     <T> IPage<T> queryPage(Page<T> page, @Param("search") String search);
+
+    List<String> queryMenuIdList(Integer serveId);
 }

+ 0 - 2
mec-biz/src/main/java/com/ym/mec/biz/dal/dao/TenantInfoDao.java

@@ -10,7 +10,5 @@ import java.util.Map;
 
 public interface TenantInfoDao extends BaseMapper<TenantInfo> {
 
-    int opsTenantState(@Param("id") Integer id, @Param("state") Integer state);
-
     <T> IPage<T> queryPage(Page<T> page, @Param("param") Map<String, Object> param);
 }

+ 25 - 0
mec-biz/src/main/java/com/ym/mec/biz/dal/dto/TenantConfigDto.java

@@ -3,6 +3,7 @@ package com.ym.mec.biz.dal.dto;
 import io.swagger.annotations.ApiModel;
 import io.swagger.annotations.ApiModelProperty;
 
+import javax.validation.constraints.NotBlank;
 import javax.validation.constraints.NotNull;
 import java.io.Serializable;
 import java.math.BigDecimal;
@@ -28,6 +29,14 @@ public class TenantConfigDto implements Serializable {
     @ApiModelProperty(value = "可用教材id,多个用逗号分割")
     private String teachingMaterialId;
 
+    @NotBlank(message = "主题不能为空")
+    @ApiModelProperty(value = "主题")
+    private String theme;
+
+    @NotBlank(message = "主题色不能为空")
+    @ApiModelProperty(value = "主题色")
+    private String themeColor;
+
     @ApiModelProperty(value = "机构动态配置,以json格式储存")
     private String config;
 
@@ -66,6 +75,22 @@ public class TenantConfigDto implements Serializable {
         this.teachingMaterialId = teachingMaterialId;
     }
 
+    public String getTheme() {
+        return theme;
+    }
+
+    public void setTheme(String theme) {
+        this.theme = theme;
+    }
+
+    public String getThemeColor() {
+        return themeColor;
+    }
+
+    public void setThemeColor(String themeColor) {
+        this.themeColor = themeColor;
+    }
+
     public String getConfig() {
         return config;
     }

+ 24 - 0
mec-biz/src/main/java/com/ym/mec/biz/dal/dto/TenantInfoDto.java

@@ -90,6 +90,14 @@ public class TenantInfoDto implements Serializable {
     @ApiModelProperty(value = "状态0 草稿 1启动 2停用")
     private Integer state;
 
+    @NotBlank(message = "营业执照编号不能为空")
+    @ApiModelProperty(value = "营业执照编号")
+    private String tsignCode;
+
+    @NotBlank(message = "公司名称名称不能为空")
+    @ApiModelProperty(value = "公司名称")
+    private String tsignName;
+
     @NotNull(message = "请选择机构的产品信息!")
     @ApiModelProperty(value = "机构关联的产品信息")
     private TenantProductInfoDto productInfo;
@@ -201,4 +209,20 @@ public class TenantInfoDto implements Serializable {
     public void setConfig(TenantConfigDto config) {
         this.config = config;
     }
+
+    public String getTsignCode() {
+        return tsignCode;
+    }
+
+    public void setTsignCode(String tsignCode) {
+        this.tsignCode = tsignCode;
+    }
+
+    public String getTsignName() {
+        return tsignName;
+    }
+
+    public void setTsignName(String tsignName) {
+        this.tsignName = tsignName;
+    }
 }

+ 139 - 0
mec-biz/src/main/java/com/ym/mec/biz/dal/dto/TenantOrderRecordDto.java

@@ -0,0 +1,139 @@
+package com.ym.mec.biz.dal.dto;
+
+
+import com.baomidou.mybatisplus.annotation.TableField;
+import io.swagger.annotations.ApiModel;
+import io.swagger.annotations.ApiModelProperty;
+
+import java.io.Serializable;
+
+/**
+ * 机构付款记录表(TenantOrderRecord)表实体类
+ *
+ * @author hgw
+ * @since 2021-12-20 10:08:28
+ */
+@ApiModel(value = "机构付款记录表")
+public class TenantOrderRecordDto implements Serializable {
+
+    private static final long serialVersionUID = 1L;
+
+    @TableField("tenant_id_")
+    @ApiModelProperty(value = "机构产品设置表id")
+    private Integer tenantId;
+
+    @TableField("order_no_")
+    @ApiModelProperty(value = "订单流水")
+    private String orderNo;
+
+    @TableField("trans_no_")
+    @ApiModelProperty(value = "支付编号")
+    private String transNo;
+
+    /**
+     * TenantOrderRecordEnum.class
+     */
+    @TableField("order_type_")
+    @ApiModelProperty(value = "订单类型/机构开通缴费、续费、充值、激活团练宝")
+    private String orderType;
+
+    @TableField("order_state_")
+    @ApiModelProperty(value = "订单状态/0待支付、1已支付")
+    private Integer orderState;
+
+    @ApiModelProperty(value = "开始时间")
+    private String startDate;
+
+    @ApiModelProperty(value = "结束时间")
+    private String endDate;
+
+    @ApiModelProperty(value = "页数")
+    private Integer page;
+
+    @ApiModelProperty(value = "每页数量")
+    private Integer rows;
+
+    @ApiModelProperty(value = "关键字")
+    private String search;
+
+    public Integer getTenantId() {
+        return tenantId;
+    }
+
+    public void setTenantId(Integer tenantId) {
+        this.tenantId = tenantId;
+    }
+
+    public String getOrderNo() {
+        return orderNo;
+    }
+
+    public void setOrderNo(String orderNo) {
+        this.orderNo = orderNo;
+    }
+
+    public String getTransNo() {
+        return transNo;
+    }
+
+    public void setTransNo(String transNo) {
+        this.transNo = transNo;
+    }
+
+    public String getOrderType() {
+        return orderType;
+    }
+
+    public void setOrderType(String orderType) {
+        this.orderType = orderType;
+    }
+
+    public Integer getOrderState() {
+        return orderState;
+    }
+
+    public void setOrderState(Integer orderState) {
+        this.orderState = orderState;
+    }
+
+    public String getStartDate() {
+        return startDate;
+    }
+
+    public void setStartDate(String startDate) {
+        this.startDate = startDate;
+    }
+
+    public String getEndDate() {
+        return endDate;
+    }
+
+    public void setEndDate(String endDate) {
+        this.endDate = endDate;
+    }
+
+    public Integer getPage() {
+        return page;
+    }
+
+    public void setPage(Integer page) {
+        this.page = page;
+    }
+
+    public Integer getRows() {
+        return rows;
+    }
+
+    public void setRows(Integer rows) {
+        this.rows = rows;
+    }
+
+    public String getSearch() {
+        return search;
+    }
+
+    public void setSearch(String search) {
+        this.search = search;
+    }
+}
+

+ 26 - 1
mec-biz/src/main/java/com/ym/mec/biz/dal/entity/TenantConfig.java

@@ -16,7 +16,7 @@ import java.util.Date;
  * @author hgw
  * @since 2021-12-09 13:37:18
  */
-@ApiModel(value = "机构配置表")
+@ApiModel(value = "tenant_config-机构配置表")
 public class TenantConfig implements Serializable {
     @TableId(value = "id_", type = IdType.AUTO)
     @ApiModelProperty(value = "主键")
@@ -34,6 +34,14 @@ public class TenantConfig implements Serializable {
     @ApiModelProperty(value = "可用教材id,多个用逗号分割")
     private String teachingMaterialId;
 
+    @TableField("theme_")
+    @ApiModelProperty(value = "主题")
+    private String theme;
+
+    @TableField("theme_color_")
+    @ApiModelProperty(value = "主题色")
+    private String themeColor;
+
     @TableField("config_")
     @ApiModelProperty(value = "机构动态配置,以json格式储存")
     private String config;
@@ -80,6 +88,22 @@ public class TenantConfig implements Serializable {
         this.teachingMaterialId = teachingMaterialId;
     }
 
+    public String getTheme() {
+        return theme;
+    }
+
+    public void setTheme(String theme) {
+        this.theme = theme;
+    }
+
+    public String getThemeColor() {
+        return themeColor;
+    }
+
+    public void setThemeColor(String themeColor) {
+        this.themeColor = themeColor;
+    }
+
     public String getConfig() {
         return config;
     }
@@ -103,4 +127,5 @@ public class TenantConfig implements Serializable {
     public void setUpdatedTime(Date updatedTime) {
         this.updatedTime = updatedTime;
     }
+
 }

+ 4 - 0
mec-biz/src/main/java/com/ym/mec/biz/dal/entity/TenantOrderRecord.java

@@ -4,6 +4,7 @@ package com.ym.mec.biz.dal.entity;
 import com.baomidou.mybatisplus.annotation.IdType;
 import com.baomidou.mybatisplus.annotation.TableField;
 import com.baomidou.mybatisplus.annotation.TableId;
+import com.fasterxml.jackson.annotation.JsonFormat;
 import io.swagger.annotations.ApiModel;
 import io.swagger.annotations.ApiModelProperty;
 
@@ -59,14 +60,17 @@ public class TenantOrderRecord implements Serializable {
     @ApiModelProperty(value = "订单状态/0待支付、1已支付")
     private Integer orderState;
 
+    @JsonFormat(pattern = "yyyy-MM-dd")
     @TableField("pay_date_")
     @ApiModelProperty(value = "支付日期")
     private Date payDate;
 
+    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
     @TableField("pay_time_")
     @ApiModelProperty(value = "支付时间")
     private Date payTime;
 
+    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
     @TableField("created_time_")
     @ApiModelProperty(value = "订单创建时间")
     private Date createdTime;

+ 32 - 0
mec-biz/src/main/java/com/ym/mec/biz/dal/enums/TenantOrderRecordEnum.java

@@ -0,0 +1,32 @@
+package com.ym.mec.biz.dal.enums;
+
+public enum TenantOrderRecordEnum {
+    TENANT_OPEN("TENANT_OPEN","机构开通缴费"),
+    TENANT_RENEW("TENANT_RENEW","机构续费"),
+    CLOUD_TEACHER("CLOUD_TEACHER","激活团练宝");
+
+    private String code;
+
+    private String msg;
+
+    TenantOrderRecordEnum(String code, String msg) {
+        this.code = code;
+        this.msg = msg;
+    }
+
+    public String getCode() {
+        return code;
+    }
+
+    public void setCode(String code) {
+        this.code = code;
+    }
+
+    public String getMsg() {
+        return msg;
+    }
+
+    public void setMsg(String msg) {
+        this.msg = msg;
+    }
+}

+ 2 - 0
mec-biz/src/main/java/com/ym/mec/biz/service/ContractService.java

@@ -24,6 +24,8 @@ public interface ContractService {
 	 */
 	SysUserTsign register(Integer userId, String realName, String idCardNo, String mobileNo);
 
+    void addTsign(String organCode, String orgName);
+
 	/**
 	 * 传递注册协议至第三方公证平台
 	 * @param userId

+ 7 - 0
mec-biz/src/main/java/com/ym/mec/biz/service/EmployeeService.java

@@ -1,5 +1,6 @@
 package com.ym.mec.biz.service;
 
+import com.ym.mec.auth.api.entity.SysRole;
 import com.ym.mec.biz.dal.dto.EmployeeLevelDto;
 import com.ym.mec.biz.dal.dto.SimpleUserDto;
 import com.ym.mec.biz.dal.entity.Employee;
@@ -96,4 +97,10 @@ public interface EmployeeService extends BaseService<Integer, Employee> {
     List<SimpleUserDto> findAllByRole(String roleIds,String organIds);
 
     List<Integer> queryUserRole(Integer sysUserId);
+
+    int batchInsertRoleMenu( Integer roleId, List<Integer> menuIds);
+
+    int insertSysRole(SysRole sysRole);
+
+
 }

+ 4 - 0
mec-biz/src/main/java/com/ym/mec/biz/service/PlatformProductService.java

@@ -4,6 +4,8 @@ import com.ym.mec.biz.dal.dto.PlatformProductDto;
 import com.ym.mec.biz.dal.entity.PlatformProduct;
 import com.ym.mec.common.page.PageInfo;
 
+import java.util.List;
+
 public interface PlatformProductService {
 
     void addProduct(PlatformProductDto obj);
@@ -12,6 +14,8 @@ public interface PlatformProductService {
 
     PageInfo<PlatformProduct> queryPage(String search, Integer page, Integer rows);
 
+    List<String> queryMenuIdList(Integer serveId);
+
     void deleteProduct(Integer id);
 
 }

+ 3 - 1
mec-biz/src/main/java/com/ym/mec/biz/service/PlatformServeService.java

@@ -1,6 +1,8 @@
 package com.ym.mec.biz.service;
 
+import com.baomidou.mybatisplus.extension.service.IService;
 import com.ym.mec.biz.dal.dto.PlatformServeDto;
+import com.ym.mec.biz.dal.entity.PlatformServe;
 import com.ym.mec.biz.dal.vo.PlatformServeInfoVo;
 import com.ym.mec.biz.dal.vo.PlatformServeModeVo;
 import com.ym.mec.biz.dal.vo.PlatformServePageVo;
@@ -8,7 +10,7 @@ import com.ym.mec.common.page.PageInfo;
 
 import java.util.List;
 
-public interface PlatformServeService {
+public interface PlatformServeService extends IService<PlatformServe> {
 
     void addServe(PlatformServeDto obj);
 

+ 4 - 0
mec-biz/src/main/java/com/ym/mec/biz/service/TenantOrderRecordService.java

@@ -1,7 +1,9 @@
 package com.ym.mec.biz.service;
 
 import com.baomidou.mybatisplus.extension.service.IService;
+import com.ym.mec.biz.dal.dto.TenantOrderRecordDto;
 import com.ym.mec.biz.dal.entity.TenantOrderRecord;
+import com.ym.mec.common.page.PageInfo;
 
 /**
  * 机构付款记录表(TenantOrderRecord)表服务接口
@@ -11,5 +13,7 @@ import com.ym.mec.biz.dal.entity.TenantOrderRecord;
  */
 public interface TenantOrderRecordService extends IService<TenantOrderRecord> {
 
+    PageInfo<TenantOrderRecord> queryPage(TenantOrderRecordDto dto);
+
 }
 

+ 1027 - 1049
mec-biz/src/main/java/com/ym/mec/biz/service/impl/ContractServiceImpl.java

@@ -1,69 +1,18 @@
 package com.ym.mec.biz.service.impl;
 
-import java.io.File;
-import java.io.IOException;
-import java.math.BigDecimal;
-import java.math.RoundingMode;
-import java.text.DateFormat;
-import java.text.SimpleDateFormat;
-import java.time.LocalDateTime;
-import java.util.*;
-import java.util.Map.Entry;
-import java.util.stream.Collectors;
-
-import com.ym.mec.biz.dal.dao.*;
-import com.ym.mec.biz.dal.dto.CirculationUser;
-import com.ym.mec.biz.dal.dto.OAFinancialDto;
-import org.apache.commons.io.FileUtils;
-import org.apache.commons.lang3.StringUtils;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import org.springframework.beans.factory.InitializingBean;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.beans.factory.annotation.Value;
-import org.springframework.context.annotation.Lazy;
-import org.springframework.http.HttpStatus;
-import org.springframework.scheduling.annotation.Async;
-import org.springframework.stereotype.Service;
-import org.springframework.transaction.annotation.Isolation;
-import org.springframework.transaction.annotation.Propagation;
-import org.springframework.transaction.annotation.Transactional;
-import org.springframework.util.CollectionUtils;
-
 import com.ym.mec.auth.api.client.SysUserFeignService;
 import com.ym.mec.auth.api.entity.SysUser;
 import com.ym.mec.auth.api.enums.CertificateTypeEnum;
+import com.ym.mec.biz.dal.dao.*;
+import com.ym.mec.biz.dal.dto.CirculationUser;
+import com.ym.mec.biz.dal.dto.OAFinancialDto;
 import com.ym.mec.biz.dal.dto.StudentInfo;
 import com.ym.mec.biz.dal.entity.CooperationOrgan.OwnershipType;
-import com.ym.mec.biz.dal.entity.Goods;
-import com.ym.mec.biz.dal.entity.MusicGroup;
-import com.ym.mec.biz.dal.entity.MusicGroupPaymentCalender;
-import com.ym.mec.biz.dal.entity.MusicGroupStudentFee;
-import com.ym.mec.biz.dal.entity.MusicGroupSubjectGoodsGroup;
-import com.ym.mec.biz.dal.entity.MusicGroupSubjectPlan;
-import com.ym.mec.biz.dal.entity.StudentPaymentOrder;
-import com.ym.mec.biz.dal.entity.StudentPaymentOrderDetail;
-import com.ym.mec.biz.dal.entity.StudentRegistration;
-import com.ym.mec.biz.dal.entity.Subject;
-import com.ym.mec.biz.dal.entity.SysUserContracts;
+import com.ym.mec.biz.dal.entity.*;
 import com.ym.mec.biz.dal.entity.SysUserContracts.ContractType;
-import com.ym.mec.biz.dal.entity.SysUserTsign;
-import com.ym.mec.biz.dal.entity.VipGroup;
 import com.ym.mec.biz.dal.enums.CourseViewTypeEnum;
-import com.ym.mec.biz.dal.enums.DealStatusEnum;
 import com.ym.mec.biz.dal.enums.KitGroupPurchaseTypeEnum;
-import com.ym.mec.biz.dal.enums.OrderDetailTypeEnum;
-import com.ym.mec.biz.service.ContractService;
-import com.ym.mec.biz.service.GoodsService;
-import com.ym.mec.biz.service.MusicGroupService;
-import com.ym.mec.biz.service.MusicGroupSubjectGoodsGroupService;
-import com.ym.mec.biz.service.MusicGroupSubjectPlanService;
-import com.ym.mec.biz.service.StudentPaymentOrderService;
-import com.ym.mec.biz.service.StudentRegistrationService;
-import com.ym.mec.biz.service.SubjectService;
-import com.ym.mec.biz.service.SysUserContractsService;
-import com.ym.mec.biz.service.SysUserTsignService;
-import com.ym.mec.biz.service.VipGroupService;
+import com.ym.mec.biz.service.*;
 import com.ym.mec.common.controller.BaseController;
 import com.ym.mec.common.entity.HttpResponseResult;
 import com.ym.mec.common.exception.BizException;
@@ -76,422 +25,451 @@ import com.ym.mec.util.date.DateUtil;
 import com.ym.mec.util.freemarker.FreemarkerTemplateEngine;
 import com.ym.mec.util.money.MoneyUtil;
 import com.ym.mec.util.pdf.PDFUtil;
+import org.apache.commons.io.FileUtils;
+import org.apache.commons.lang3.StringUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.InitializingBean;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.annotation.Value;
+import org.springframework.context.annotation.Lazy;
+import org.springframework.http.HttpStatus;
+import org.springframework.scheduling.annotation.Async;
+import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Isolation;
+import org.springframework.transaction.annotation.Propagation;
+import org.springframework.transaction.annotation.Transactional;
+import org.springframework.util.CollectionUtils;
+
+import java.io.File;
+import java.io.IOException;
+import java.math.BigDecimal;
+import java.math.RoundingMode;
+import java.text.DateFormat;
+import java.text.SimpleDateFormat;
+import java.time.LocalDateTime;
+import java.util.*;
+import java.util.Map.Entry;
+import java.util.stream.Collectors;
 
 @Service
 public class ContractServiceImpl implements ContractService, InitializingBean {
 
-	@Autowired
-	private SysUserTsignService sysUserTsignService;
-
-	@Autowired
-	private SysUserFeignService sysUserFeignService;
-
-	@Autowired
-	private SysUserContractsService sysUserContractsService;
-
-	@Autowired
-	private SysUserContractsDao sysUserContractsDao;
+    @Autowired
+    private SysUserTsignService sysUserTsignService;
 
-	@Autowired
-	private StudentRegistrationService studentRegistrationService;
+    @Autowired
+    private SysUserFeignService sysUserFeignService;
 
-	@Autowired
-	private StudentRegistrationDao studentRegistrationDao;
+    @Autowired
+    private SysUserContractsService sysUserContractsService;
 
-	@Autowired
-	private StudentPaymentOrderService studentPaymentOrderService;
+    @Autowired
+    private SysUserContractsDao sysUserContractsDao;
 
-	@Autowired
-	private MusicGroupSubjectPlanService musicGroupSubjectPlanService;
+    @Autowired
+    private StudentRegistrationService studentRegistrationService;
 
-	@Autowired
-	private MusicGroupSubjectGoodsGroupService musicGroupSubjectGoodsGroupService;
+    @Autowired
+    private StudentRegistrationDao studentRegistrationDao;
 
-	@Autowired
-	private MusicGroupPaymentCalenderDao musicGroupPaymentCalenderDao;
+    @Autowired
+    private StudentPaymentOrderService studentPaymentOrderService;
 
-	@Autowired
-	private MusicGroupStudentFeeDao musicGroupStudentFeeDao;
+    @Autowired
+    private MusicGroupSubjectPlanService musicGroupSubjectPlanService;
 
-	@Autowired
-	private StudentPaymentOrderDetailDao studentPaymentOrderDetailDao;
+    @Autowired
+    private MusicGroupSubjectGoodsGroupService musicGroupSubjectGoodsGroupService;
 
-	@Autowired
-	@Lazy
-	private VipGroupService vipGroupService;
+    @Autowired
+    private MusicGroupPaymentCalenderDao musicGroupPaymentCalenderDao;
 
-	@Autowired
-	private SubjectService subjectService;
+    @Autowired
+    private MusicGroupStudentFeeDao musicGroupStudentFeeDao;
 
-	@Autowired
-	private ESealPlugin eSealPlugin;
+    @Autowired
+    private StudentPaymentOrderDetailDao studentPaymentOrderDetailDao;
 
-	@Autowired
-	private StoragePluginContext storagePluginContext;
+    @Autowired
+    @Lazy
+    private VipGroupService vipGroupService;
 
-	@Autowired
-	private GoodsService goodsService;
+    @Autowired
+    private SubjectService subjectService;
 
-	@Autowired
-	private MusicGroupService musicGroupService;
+    @Autowired
+    private ESealPlugin eSealPlugin;
 
-	@Autowired
-	private StudentDao studentDao;
+    @Autowired
+    private StoragePluginContext storagePluginContext;
 
-	@Autowired
-	private EmployeeDao employeeDao;
+    @Autowired
+    private GoodsService goodsService;
 
-	@Value("${contract.baseDir:/var/pdf}")
-	private String contractBaseDir;
+    @Autowired
+    private MusicGroupService musicGroupService;
 
-	@Value("${message.debugMode}")
-	private boolean debugMode;
+    @Autowired
+    private StudentDao studentDao;
 
-	@Autowired
-	private RealnameAuthenticationPluginContext realnameAuthenticationPluginContext;
+    @Autowired
+    private EmployeeDao employeeDao;
 
-	private DateFormat dateFormatOss = new SimpleDateFormat("yyyy/MM/dd");
+    @Value("${contract.baseDir:/var/pdf}")
+    private String contractBaseDir;
 
-	private DateFormat dateFormat1 = new SimpleDateFormat("yyMMddHHmmSS");
+    @Value("${message.debugMode}")
+    private boolean debugMode;
 
-	private final Logger logger = LoggerFactory.getLogger(ContractService.class);
+    @Autowired
+    private RealnameAuthenticationPluginContext realnameAuthenticationPluginContext;
 
-	@Override
-	public void afterPropertiesSet() throws Exception {
-		// 注册企业账户
-		Map<String, String> organList = new HashMap<String, String>();
-		organList.put("91420106333619290A", "武汉长乐长风乐器销售有限公司");
-		organList.put("91440300326364429H", "深圳大雅乐盟网络教育股份有限公司");
+    private DateFormat dateFormatOss = new SimpleDateFormat("yyyy/MM/dd");
 
-		for (Entry<String, String> organ : organList.entrySet()) {
+    private DateFormat dateFormat1 = new SimpleDateFormat("yyMMddHHmmSS");
 
-			String organCode = organ.getKey();
-			String orgName = organ.getValue();
+    private final Logger logger = LoggerFactory.getLogger(ContractService.class);
 
-			SysUserTsign sysUserTsign = sysUserTsignService.queryByCardNo(organCode);
+    @Override
+    public void afterPropertiesSet() throws Exception {
+        // 注册企业账户
+        Map<String, String> organList = new HashMap<String, String>();
+        organList.put("91420106333619290A", "武汉长乐长风乐器销售有限公司");
+        organList.put("91440300326364429H", "深圳大雅乐盟网络教育股份有限公司");
 
-			if (sysUserTsign == null) {
-				String accountId = eSealPlugin.createOrganAccount(orgName, organCode);
+        organList.forEach((code, name) -> {
+            SysUserTsign sysUserTsign = sysUserTsignService.queryByCardNo(code);
+            if (Objects.isNull(sysUserTsign)) {
+                addTsign(code, name);
+            }
+        });
+    }
 
-				if (StringUtils.isBlank(accountId)) {
-					throw new BizException("创建企业电子存证账户失败");
-				}
+    /**
+     * 校验企业营业信息,不存在则添加一个
+     */
+    @Override
+    public void addTsign(String organCode, String orgName) {
+        Optional.ofNullable(organCode).orElseThrow(() -> new BizException("营业执照编号不能为空!"));
+        Optional.ofNullable(orgName).orElseThrow(() -> new BizException("营业名称不能为空"));
 
-				String sealData = eSealPlugin.createOrganSeal(accountId, "", "");
+        String accountId = eSealPlugin.createOrganAccount(orgName, organCode);
+        if (StringUtils.isBlank(accountId)) {
+            throw new BizException("创建企业电子存证账户失败");
+        }
 
-				if (StringUtils.isBlank(sealData)) {
-					throw new BizException("创建电子存证印章失败");
-				}
+        String sealData = eSealPlugin.createOrganSeal(accountId, "", "");
+        if (StringUtils.isBlank(sealData)) {
+            throw new BizException("创建电子存证印章失败");
+        }
 
-				sysUserTsign = new SysUserTsign(-1, accountId, sealData, orgName, organCode);
+        SysUserTsign sysUserTsign = new SysUserTsign(-1, accountId, sealData, orgName, organCode);
+        sysUserTsignService.insert(sysUserTsign);
+    }
 
-				sysUserTsignService.insert(sysUserTsign);
-			}
-		}
-	}
+    @Override
+    public SysUserTsign register(Integer userId, String realName, String idCardNo, String mobileNo) {
 
-	@Override
-	public SysUserTsign register(Integer userId, String realName, String idCardNo, String mobileNo) {
+        if (StringUtils.isBlank(realName) || StringUtils.isBlank(idCardNo) || StringUtils.isBlank(mobileNo)) {
+            return null;
+        }
 
-		if (StringUtils.isBlank(realName) || StringUtils.isBlank(idCardNo) || StringUtils.isBlank(mobileNo)) {
-			return null;
-		}
+        SysUserTsign sysUserTsign = sysUserTsignService.get(userId);
+        if (sysUserTsign == null) {
 
-		SysUserTsign sysUserTsign = sysUserTsignService.get(userId);
-		if (sysUserTsign == null) {
+            String accountId = "";
+            String sealData = "";
 
-			String accountId = "";
-			String sealData = "";
+            SysUser user = studentDao.getUser(userId);
+            if (user == null) {
+                throw new BizException("用户信息查询失败");
+            }
 
-			SysUser user = studentDao.getUser(userId);
-			if (user == null) {
-				throw new BizException("用户信息查询失败");
-			}
+            if (CertificateTypeEnum.IDENTITY.getCode().equals(user.getCertificateType())) {
+                if (!debugMode) {
+                    realnameAuthenticationPluginContext.getRealnameAuthenticationPlugin(LinkfaceRealnameAuthenticationPlugin.getName()).verify(realName, idCardNo);
+                }
 
-			if(CertificateTypeEnum.IDENTITY.getCode().equals(user.getCertificateType())){
-				if(!debugMode){
-					realnameAuthenticationPluginContext.getRealnameAuthenticationPlugin(LinkfaceRealnameAuthenticationPlugin.getName()).verify(realName, idCardNo);
-				}
+                accountId = eSealPlugin.createUserAccount(realName, idCardNo, mobileNo);
 
-				accountId = eSealPlugin.createUserAccount(realName, idCardNo, mobileNo);
+                if (StringUtils.isBlank(accountId)) {
+                    throw new BizException("创建电子存证账户失败");
+                }
 
-				if (StringUtils.isBlank(accountId)) {
-					throw new BizException("创建电子存证账户失败");
-				}
+                sealData = eSealPlugin.createUserSeal(accountId);
 
-				sealData = eSealPlugin.createUserSeal(accountId);
+                if (StringUtils.isBlank(sealData)) {
+                    throw new BizException("创建电子存证印章失败");
+                }
+            }
 
-				if (StringUtils.isBlank(sealData)) {
-					throw new BizException("创建电子存证印章失败");
-				}
-			}
+            sysUserTsign = new SysUserTsign(userId, accountId, sealData, realName, idCardNo);
 
-			sysUserTsign = new SysUserTsign(userId, accountId, sealData, realName, idCardNo);
+            sysUserTsignService.insert(sysUserTsign);
 
-			sysUserTsignService.insert(sysUserTsign);
+            return sysUserTsign;
+        }
 
-			return sysUserTsign;
-		}
+        return null;
+    }
 
-		return null;
-	}
+    @Override
+    public boolean transferRegisterContract(Integer userId) {
 
-	@Override
-	public boolean transferRegisterContract(Integer userId) {
+        SysUserTsign sysUserTsign = sysUserTsignService.get(userId);
 
-		SysUserTsign sysUserTsign = sysUserTsignService.get(userId);
+        if (sysUserTsign == null) {
+            SysUser user = sysUserFeignService.queryUserById(userId);
+            if (user == null) {
+                throw new BizException("用户信息查询失败");
+            }
+            sysUserTsign = register(userId, user.getRealName(), user.getIdCardNo(), user.getPhone());
+        }
 
-		if (sysUserTsign == null) {
-			SysUser user = sysUserFeignService.queryUserById(userId);
-			if (user == null) {
-				throw new BizException("用户信息查询失败");
-			}
-			sysUserTsign = register(userId, user.getRealName(), user.getIdCardNo(), user.getPhone());
-		}
+        // 合成freemarker
+        String srcPdfPath = contractBaseDir + "/register/" + userId + ".pdf";
 
-		// 合成freemarker
-		String srcPdfPath = contractBaseDir + "/register/" + userId + ".pdf";
+        File srcFile = new File(srcPdfPath);
+
+        File debtFile = new File(srcFile.getParent());
+        if (!debtFile.exists()) {
+            debtFile.mkdirs();
+        }
 
-		File srcFile = new File(srcPdfPath);
+        FreemarkerTemplateEngine templateEngine = FreemarkerTemplateEngine.getInstance();
+        templateEngine.setClassForTemplateLoading(ContractServiceImpl.class, "/config/contracts/");
 
-		File debtFile = new File(srcFile.getParent());
-		if (!debtFile.exists()) {
-			debtFile.mkdirs();
-		}
+        Map<String, Object> params = new HashMap<String, Object>();
 
-		FreemarkerTemplateEngine templateEngine = FreemarkerTemplateEngine.getInstance();
-		templateEngine.setClassForTemplateLoading(ContractServiceImpl.class, "/config/contracts/");
+        templateEngine.render(params, "register.ftl", srcFile);
 
-		Map<String, Object> params = new HashMap<String, Object>();
+        // 生成借款协议PDF
+        try {
+            PDFUtil.renderToPDFByData(ContractServiceImpl.class.getResource("/").getFile(), FileUtils.readFileToString(srcFile), srcPdfPath, "simsun.ttc");
+        } catch (IOException e) {
+            throw new BizException("生成pdf协议失败", e);
+        }
 
-		templateEngine.render(params, "register.ftl", srcFile);
+        if (sysUserTsign != null) {
+            eSealPlugin.userSign(sysUserTsign.getAccountId(), sysUserTsign.getSealData(), srcPdfPath, srcPdfPath);
+        }
 
-		// 生成借款协议PDF
-		try {
-			PDFUtil.renderToPDFByData(ContractServiceImpl.class.getResource("/").getFile(), FileUtils.readFileToString(srcFile), srcPdfPath, "simsun.ttc");
-		} catch (IOException e) {
-			throw new BizException("生成pdf协议失败", e);
-		}
+        Date date = new Date();
+        // 上传到oss
+        String dateStrOss = dateFormatOss.format(date);
+        dateStrOss = "users/" + dateStrOss + "/" + DateUtil.getHour(date);
+        String pdfFilePath = storagePluginContext.uploadFile(KS3StoragePlugin.PLUGIN_NAME, dateStrOss, srcFile);
 
-		if (sysUserTsign != null) {
-			eSealPlugin.userSign(sysUserTsign.getAccountId(), sysUserTsign.getSealData(), srcPdfPath, srcPdfPath);
-		}
+        SysUserContracts sysUserContracts = new SysUserContracts();
+        sysUserContracts.setCreateTime(date);
+        sysUserContracts.setType(ContractType.REGISTER);
+        sysUserContracts.setUrl(pdfFilePath);
+        sysUserContracts.setUserId(userId);
 
-		Date date = new Date();
-		// 上传到oss
-		String dateStrOss = dateFormatOss.format(date);
-		dateStrOss = "users/" + dateStrOss + "/" + DateUtil.getHour(date);
-		String pdfFilePath = storagePluginContext.uploadFile(KS3StoragePlugin.PLUGIN_NAME, dateStrOss, srcFile);
+        sysUserContractsService.insert(sysUserContracts);
 
-		SysUserContracts sysUserContracts = new SysUserContracts();
-		sysUserContracts.setCreateTime(date);
-		sysUserContracts.setType(ContractType.REGISTER);
-		sysUserContracts.setUrl(pdfFilePath);
-		sysUserContracts.setUserId(userId);
+        FileUtils.deleteQuietly(srcFile);
 
-		sysUserContractsService.insert(sysUserContracts);
+        return true;
+    }
 
-		FileUtils.deleteQuietly(srcFile);
+    @Override
+    public String queryRegisterContract(Integer userId) {
 
-		return true;
-	}
+        // 合成freemarker
+        String srcPdfPath = contractBaseDir + "/register/" + userId + ".pdf";
 
-	@Override
-	public String queryRegisterContract(Integer userId) {
+        File srcFile = new File(srcPdfPath);
 
-		// 合成freemarker
-		String srcPdfPath = contractBaseDir + "/register/" + userId + ".pdf";
+        File debtFile = new File(srcFile.getParent());
+        if (!debtFile.exists()) {
+            debtFile.mkdirs();
+        }
 
-		File srcFile = new File(srcPdfPath);
+        FreemarkerTemplateEngine templateEngine = FreemarkerTemplateEngine.getInstance();
+        templateEngine.setClassForTemplateLoading(ContractServiceImpl.class, "/config/contracts/");
 
-		File debtFile = new File(srcFile.getParent());
-		if (!debtFile.exists()) {
-			debtFile.mkdirs();
-		}
+        Map<String, Object> params = new HashMap<String, Object>();
 
-		FreemarkerTemplateEngine templateEngine = FreemarkerTemplateEngine.getInstance();
-		templateEngine.setClassForTemplateLoading(ContractServiceImpl.class, "/config/contracts/");
+        templateEngine.render(params, "register.ftl", srcFile);
 
-		Map<String, Object> params = new HashMap<String, Object>();
+        String result = "";
+        try {
+            result = FileUtils.readFileToString(srcFile);
+        } catch (IOException e) {
+            throw new BizException("读取注册协议出错", e);
+        } finally {
+            FileUtils.deleteQuietly(srcFile);
+        }
 
-		templateEngine.render(params, "register.ftl", srcFile);
-
-		String result = "";
-		try {
-			result = FileUtils.readFileToString(srcFile);
-		} catch (IOException e) {
-			throw new BizException("读取注册协议出错", e);
-		} finally {
-			FileUtils.deleteQuietly(srcFile);
-		}
-
-		return result;
-	}
-
-	@Override
-	public boolean transferMusicGroupCoursesContract(Integer userId, String musicGroupId) {
-		if(true){
-			transferProduceContract(userId, musicGroupId, null);
-			return true;
-		}
-		SysUserTsign sysUserTsign = sysUserTsignService.get(userId);
-
-		if (sysUserTsign == null) {
-			SysUser user = sysUserFeignService.queryUserById(userId);
-			if (user == null) {
-				throw new BizException("用户信息查询失败");
-			}
-			sysUserTsign = register(userId, user.getRealName(), user.getIdCardNo(), user.getPhone());
-		}
-		Date date = new Date();
-
-		// 合成freemarker
-		String srcPdfPath = contractBaseDir + "/courses/" + dateFormat1.format(date) + "/" + userId + ".pdf";
-
-		File srcFile = new File(srcPdfPath);
-
-		File debtFile = new File(srcFile.getParent());
-		if (!debtFile.exists()) {
-			debtFile.mkdirs();
-		}
-
-		FreemarkerTemplateEngine templateEngine = FreemarkerTemplateEngine.getInstance();
-		templateEngine.setClassForTemplateLoading(ContractServiceImpl.class, "/config/contracts/");
-
-		Map<String, Object> params = new HashMap<String, Object>();
-
-		// 查询参数信息
-		StudentInfo studentInfo = studentRegistrationService.queryStudentInfo(userId);
-		params.put("studentInfo", studentInfo);
-
-		// 课程类型
-		params.put("classesType", "乐团团课");
-
-		// 课程费用
-		StudentRegistration studentRegistration = studentRegistrationService.queryByUserIdAndMusicGroupId(userId, musicGroupId);
-		if (studentRegistration == null) {
-			throw new BizException("用户 报名信息不存在");
-		}
-		MusicGroupStudentFee musicGroupStudentFee = musicGroupStudentFeeDao.findByUser(userId, musicGroupId);
-		if (musicGroupStudentFee == null) {
-			MusicGroupSubjectPlan musicGroupSubjectPlan = musicGroupSubjectPlanService.getMusicOneSubjectClassPlan(musicGroupId,
-					studentRegistration.getActualSubjectId());
-			if (musicGroupSubjectPlan == null) {
-				throw new BizException("声部课程费用设置找不到");
-			}
-			params.put("courseFee", musicGroupSubjectPlan.getFee().doubleValue());
-		} else {
-			params.put("courseFee", musicGroupStudentFee.getTemporaryCourseFee().doubleValue() > 0 ? musicGroupStudentFee.getTemporaryCourseFee().doubleValue()
-					: musicGroupStudentFee.getCourseFee().doubleValue());
-		}
+        return result;
+    }
 
-		// 收费形式
-		List<MusicGroupPaymentCalender> calenders = musicGroupPaymentCalenderDao.findByMusicGroupId(musicGroupId);
+    @Override
+    public boolean transferMusicGroupCoursesContract(Integer userId, String musicGroupId) {
+        if (true) {
+            transferProduceContract(userId, musicGroupId, null);
+            return true;
+        }
+        SysUserTsign sysUserTsign = sysUserTsignService.get(userId);
+
+        if (sysUserTsign == null) {
+            SysUser user = sysUserFeignService.queryUserById(userId);
+            if (user == null) {
+                throw new BizException("用户信息查询失败");
+            }
+            sysUserTsign = register(userId, user.getRealName(), user.getIdCardNo(), user.getPhone());
+        }
+        Date date = new Date();
+
+        // 合成freemarker
+        String srcPdfPath = contractBaseDir + "/courses/" + dateFormat1.format(date) + "/" + userId + ".pdf";
+
+        File srcFile = new File(srcPdfPath);
+
+        File debtFile = new File(srcFile.getParent());
+        if (!debtFile.exists()) {
+            debtFile.mkdirs();
+        }
+
+        FreemarkerTemplateEngine templateEngine = FreemarkerTemplateEngine.getInstance();
+        templateEngine.setClassForTemplateLoading(ContractServiceImpl.class, "/config/contracts/");
+
+        Map<String, Object> params = new HashMap<String, Object>();
+
+        // 查询参数信息
+        StudentInfo studentInfo = studentRegistrationService.queryStudentInfo(userId);
+        params.put("studentInfo", studentInfo);
+
+        // 课程类型
+        params.put("classesType", "乐团团课");
+
+        // 课程费用
+        StudentRegistration studentRegistration = studentRegistrationService.queryByUserIdAndMusicGroupId(userId, musicGroupId);
+        if (studentRegistration == null) {
+            throw new BizException("用户 报名信息不存在");
+        }
+        MusicGroupStudentFee musicGroupStudentFee = musicGroupStudentFeeDao.findByUser(userId, musicGroupId);
+        if (musicGroupStudentFee == null) {
+            MusicGroupSubjectPlan musicGroupSubjectPlan = musicGroupSubjectPlanService.getMusicOneSubjectClassPlan(musicGroupId,
+                    studentRegistration.getActualSubjectId());
+            if (musicGroupSubjectPlan == null) {
+                throw new BizException("声部课程费用设置找不到");
+            }
+            params.put("courseFee", musicGroupSubjectPlan.getFee().doubleValue());
+        } else {
+            params.put("courseFee", musicGroupStudentFee.getTemporaryCourseFee().doubleValue() > 0 ? musicGroupStudentFee.getTemporaryCourseFee().doubleValue()
+                    : musicGroupStudentFee.getCourseFee().doubleValue());
+        }
+
+        // 收费形式
+        List<MusicGroupPaymentCalender> calenders = musicGroupPaymentCalenderDao.findByMusicGroupId(musicGroupId);
 
 		/*if (calenders == null || calenders.size() == 0) {
 			
 		} else {
 			params.put("paymentcalender", calenders.stream().map(cal -> cal.getPaymentMonth().toString()).collect(Collectors.joining("月,")) + "月");
 		}*/
-		params.put("paymentcalender", "一次性");
-
-		params.put("isShowVisualSeal", false);
-
-		MusicGroup musicGroup = musicGroupService.get(musicGroupId);
-		if (musicGroup == null) {
-			throw new BizException("乐团信息没找到");
-		}
-
-		params.put("ownershipType", musicGroup.getOwnershipType().name());
-
-		templateEngine.render(params, "courses.ftl", srcFile);
-
-		// 生成借款协议PDF
-		try {
-			PDFUtil.renderToPDFByData(ContractServiceImpl.class.getResource("/").getFile(), FileUtils.readFileToString(srcFile), srcPdfPath, "simsun.ttc");
-		} catch (IOException e) {
-			throw new BizException("生成pdf协议失败", e);
-		}
-		String organCode = "";
-		if (musicGroup.getOwnershipType() == OwnershipType.OWN) {
-			organCode = "91440300326364429H";
-		} else {
-			organCode = "91420106333619290A";
-		}
-		SysUserTsign organTsign = sysUserTsignService.queryByCardNo(organCode);
-		if (organTsign == null) {
-			throw new BizException("甲方未创建签章");
-		}
-
-		eSealPlugin.organSign(organTsign.getSealData(), srcPdfPath, srcPdfPath);
-		if (sysUserTsign != null) {
-			eSealPlugin.userSign(sysUserTsign.getAccountId(), sysUserTsign.getSealData(), srcPdfPath, srcPdfPath);
-		}
-
-		// 上传到oss
-		String dateStrOss = dateFormatOss.format(date);
-		dateStrOss = "musicCourses/" + dateStrOss + "/" + DateUtil.getHour(date);
-		String pdfFilePath = storagePluginContext.uploadFile(KS3StoragePlugin.PLUGIN_NAME, dateStrOss, srcFile);
-
-		SysUserContracts sysUserContracts = new SysUserContracts();
-		sysUserContracts.setCreateTime(date);
-		sysUserContracts.setType(ContractType.COURSES);
-		sysUserContracts.setUrl(pdfFilePath);
-		sysUserContracts.setUserId(userId);
-
-		sysUserContractsService.insert(sysUserContracts);
-
-		FileUtils.deleteQuietly(srcFile);
-
-		return true;
-	}
-
-	@Override
-	public String queryMusicGroupCoursesContract(Integer userId, String musicGroupId) {
-
-		// 合成freemarker
-		String srcPdfPath = contractBaseDir + "/courses/" + userId + ".pdf";
-
-		File srcFile = new File(srcPdfPath);
-
-		File debtFile = new File(srcFile.getParent());
-		if (!debtFile.exists()) {
-			debtFile.mkdirs();
-		}
-
-		FreemarkerTemplateEngine templateEngine = FreemarkerTemplateEngine.getInstance();
-		templateEngine.setClassForTemplateLoading(ContractServiceImpl.class, "/config/contracts/");
-
-		Map<String, Object> params = new HashMap<String, Object>();
-
-		StudentInfo studentInfo = studentRegistrationService.queryStudentInfo(userId);
-		params.put("studentInfo", studentInfo);
-
-		// 课程类型
-		params.put("classesType", "乐团团课");
-
-		// 课程费用
-		StudentRegistration studentRegistration = studentRegistrationService.queryByUserIdAndMusicGroupId(userId, musicGroupId);
-		if (studentRegistration == null) {
-			throw new BizException("用户报名信息不存在");
-		}
-		MusicGroupStudentFee musicGroupStudentFee = musicGroupStudentFeeDao.findByUser(userId, musicGroupId);
-		if (musicGroupStudentFee == null) {
-			MusicGroupSubjectPlan musicGroupSubjectPlan = musicGroupSubjectPlanService.getMusicOneSubjectClassPlan(musicGroupId,
-					studentRegistration.getActualSubjectId());
-			if (musicGroupSubjectPlan == null) {
-				throw new BizException("声部课程费用设置找不到");
-			}
-			params.put("courseFee", musicGroupSubjectPlan.getFee().doubleValue());
-		} else {
-			params.put(
-					"courseFee",
-					(musicGroupStudentFee.getTemporaryCourseFee() != null && musicGroupStudentFee.getTemporaryCourseFee().doubleValue() > 0) ? musicGroupStudentFee
-							.getTemporaryCourseFee().doubleValue() : musicGroupStudentFee.getCourseFee().doubleValue());
-		}
-
-		// 收费形式
-		List<MusicGroupPaymentCalender> calenders = musicGroupPaymentCalenderDao.findByMusicGroupId(musicGroupId);
+        params.put("paymentcalender", "一次性");
+
+        params.put("isShowVisualSeal", false);
+
+        MusicGroup musicGroup = musicGroupService.get(musicGroupId);
+        if (musicGroup == null) {
+            throw new BizException("乐团信息没找到");
+        }
+
+        params.put("ownershipType", musicGroup.getOwnershipType().name());
+
+        templateEngine.render(params, "courses.ftl", srcFile);
+
+        // 生成借款协议PDF
+        try {
+            PDFUtil.renderToPDFByData(ContractServiceImpl.class.getResource("/").getFile(), FileUtils.readFileToString(srcFile), srcPdfPath, "simsun.ttc");
+        } catch (IOException e) {
+            throw new BizException("生成pdf协议失败", e);
+        }
+        String organCode = "";
+        if (musicGroup.getOwnershipType() == OwnershipType.OWN) {
+            organCode = "91440300326364429H";
+        } else {
+            organCode = "91420106333619290A";
+        }
+        SysUserTsign organTsign = sysUserTsignService.queryByCardNo(organCode);
+        if (organTsign == null) {
+            throw new BizException("甲方未创建签章");
+        }
+
+        eSealPlugin.organSign(organTsign.getSealData(), srcPdfPath, srcPdfPath);
+        if (sysUserTsign != null) {
+            eSealPlugin.userSign(sysUserTsign.getAccountId(), sysUserTsign.getSealData(), srcPdfPath, srcPdfPath);
+        }
+
+        // 上传到oss
+        String dateStrOss = dateFormatOss.format(date);
+        dateStrOss = "musicCourses/" + dateStrOss + "/" + DateUtil.getHour(date);
+        String pdfFilePath = storagePluginContext.uploadFile(KS3StoragePlugin.PLUGIN_NAME, dateStrOss, srcFile);
+
+        SysUserContracts sysUserContracts = new SysUserContracts();
+        sysUserContracts.setCreateTime(date);
+        sysUserContracts.setType(ContractType.COURSES);
+        sysUserContracts.setUrl(pdfFilePath);
+        sysUserContracts.setUserId(userId);
+
+        sysUserContractsService.insert(sysUserContracts);
+
+        FileUtils.deleteQuietly(srcFile);
+
+        return true;
+    }
+
+    @Override
+    public String queryMusicGroupCoursesContract(Integer userId, String musicGroupId) {
+
+        // 合成freemarker
+        String srcPdfPath = contractBaseDir + "/courses/" + userId + ".pdf";
+
+        File srcFile = new File(srcPdfPath);
+
+        File debtFile = new File(srcFile.getParent());
+        if (!debtFile.exists()) {
+            debtFile.mkdirs();
+        }
+
+        FreemarkerTemplateEngine templateEngine = FreemarkerTemplateEngine.getInstance();
+        templateEngine.setClassForTemplateLoading(ContractServiceImpl.class, "/config/contracts/");
+
+        Map<String, Object> params = new HashMap<String, Object>();
+
+        StudentInfo studentInfo = studentRegistrationService.queryStudentInfo(userId);
+        params.put("studentInfo", studentInfo);
+
+        // 课程类型
+        params.put("classesType", "乐团团课");
+
+        // 课程费用
+        StudentRegistration studentRegistration = studentRegistrationService.queryByUserIdAndMusicGroupId(userId, musicGroupId);
+        if (studentRegistration == null) {
+            throw new BizException("用户报名信息不存在");
+        }
+        MusicGroupStudentFee musicGroupStudentFee = musicGroupStudentFeeDao.findByUser(userId, musicGroupId);
+        if (musicGroupStudentFee == null) {
+            MusicGroupSubjectPlan musicGroupSubjectPlan = musicGroupSubjectPlanService.getMusicOneSubjectClassPlan(musicGroupId,
+                    studentRegistration.getActualSubjectId());
+            if (musicGroupSubjectPlan == null) {
+                throw new BizException("声部课程费用设置找不到");
+            }
+            params.put("courseFee", musicGroupSubjectPlan.getFee().doubleValue());
+        } else {
+            params.put(
+                    "courseFee",
+                    (musicGroupStudentFee.getTemporaryCourseFee() != null && musicGroupStudentFee.getTemporaryCourseFee().doubleValue() > 0) ? musicGroupStudentFee
+                            .getTemporaryCourseFee().doubleValue() : musicGroupStudentFee.getCourseFee().doubleValue());
+        }
+
+        // 收费形式
+        List<MusicGroupPaymentCalender> calenders = musicGroupPaymentCalenderDao.findByMusicGroupId(musicGroupId);
 
 		/*if (calenders == null || calenders.size() == 0) {
 			params.put("paymentcalender", "一次性");
@@ -499,736 +477,736 @@ public class ContractServiceImpl implements ContractService, InitializingBean {
 			params.put("paymentcalender", calenders.stream().map(cal -> cal.getPaymentMonth().toString()).collect(Collectors.joining("月,")) + "月");
 		}*/
 
-		params.put("paymentcalender", "一次性");
+        params.put("paymentcalender", "一次性");
 
-		params.put("isShowVisualSeal", true);
+        params.put("isShowVisualSeal", true);
 
-		MusicGroup musicGroup = musicGroupService.get(musicGroupId);
-		if (musicGroup == null) {
-			throw new BizException("乐团信息没找到");
-		}
+        MusicGroup musicGroup = musicGroupService.get(musicGroupId);
+        if (musicGroup == null) {
+            throw new BizException("乐团信息没找到");
+        }
 
-		params.put("ownershipType", musicGroup.getOwnershipType().name());
+        params.put("ownershipType", musicGroup.getOwnershipType().name());
 
-		templateEngine.render(params, "courses.ftl", srcFile);
+        templateEngine.render(params, "courses.ftl", srcFile);
 
-		String result = "";
-		try {
-			result = FileUtils.readFileToString(srcFile);
-		} catch (IOException e) {
-			throw new BizException("读取课程协议出错", e);
-		} finally {
-			FileUtils.deleteQuietly(srcFile);
-		}
+        String result = "";
+        try {
+            result = FileUtils.readFileToString(srcFile);
+        } catch (IOException e) {
+            throw new BizException("读取课程协议出错", e);
+        } finally {
+            FileUtils.deleteQuietly(srcFile);
+        }
 
-		return result;
-	}
+        return result;
+    }
 
-	@Override
-	public boolean transferVipGroupCoursesContract(Integer userId, Long vipGroupId) {
-		if(true){
-			transferProduceContract(userId, null, null);
-			return true;
-		}
+    @Override
+    public boolean transferVipGroupCoursesContract(Integer userId, Long vipGroupId) {
+        if (true) {
+            transferProduceContract(userId, null, null);
+            return true;
+        }
 
-		SysUserTsign sysUserTsign = sysUserTsignService.get(userId);
+        SysUserTsign sysUserTsign = sysUserTsignService.get(userId);
 
-		if (sysUserTsign == null) {
-			SysUser user = sysUserFeignService.queryUserById(userId);
-			if (user == null) {
-				throw new BizException("用户信息查询失败");
-			}
-			sysUserTsign = register(userId, user.getRealName(), user.getIdCardNo(), user.getPhone());
-		}
-		Date date = new Date();
+        if (sysUserTsign == null) {
+            SysUser user = sysUserFeignService.queryUserById(userId);
+            if (user == null) {
+                throw new BizException("用户信息查询失败");
+            }
+            sysUserTsign = register(userId, user.getRealName(), user.getIdCardNo(), user.getPhone());
+        }
+        Date date = new Date();
 
-		// 合成freemarker
-		String srcPdfPath = contractBaseDir + "/vipCourses/" + dateFormat1.format(date) + "/" + userId + ".pdf";
+        // 合成freemarker
+        String srcPdfPath = contractBaseDir + "/vipCourses/" + dateFormat1.format(date) + "/" + userId + ".pdf";
 
-		File srcFile = new File(srcPdfPath);
+        File srcFile = new File(srcPdfPath);
 
-		File debtFile = new File(srcFile.getParent());
-		if (!debtFile.exists()) {
-			debtFile.mkdirs();
-		}
+        File debtFile = new File(srcFile.getParent());
+        if (!debtFile.exists()) {
+            debtFile.mkdirs();
+        }
 
-		FreemarkerTemplateEngine templateEngine = FreemarkerTemplateEngine.getInstance();
-		templateEngine.setClassForTemplateLoading(ContractServiceImpl.class, "/config/contracts/");
+        FreemarkerTemplateEngine templateEngine = FreemarkerTemplateEngine.getInstance();
+        templateEngine.setClassForTemplateLoading(ContractServiceImpl.class, "/config/contracts/");
 
-		Map<String, Object> params = new HashMap<String, Object>();
+        Map<String, Object> params = new HashMap<String, Object>();
 
-		// 查询参数信息
-		StudentInfo studentInfo = studentRegistrationService.queryStudentInfo(userId);
-		params.put("studentInfo", studentInfo);
+        // 查询参数信息
+        StudentInfo studentInfo = studentRegistrationService.queryStudentInfo(userId);
+        params.put("studentInfo", studentInfo);
 
-		// 课程类型
-		params.put("classesType", "VIP课");
+        // 课程类型
+        params.put("classesType", "VIP课");
 
-		// 课程费用
-		VipGroup vipGroup = vipGroupService.get(vipGroupId);
-		if (vipGroup == null) {
-			throw new BizException("VIP课找不到");
-		}
-		params.put("courseFee", vipGroup.getTotalPrice().doubleValue());
+        // 课程费用
+        VipGroup vipGroup = vipGroupService.get(vipGroupId);
+        if (vipGroup == null) {
+            throw new BizException("VIP课找不到");
+        }
+        params.put("courseFee", vipGroup.getTotalPrice().doubleValue());
 
-		// 收费形式
-		params.put("paymentcalender", "一次性");
+        // 收费形式
+        params.put("paymentcalender", "一次性");
 
-		params.put("isShowVisualSeal", false);
+        params.put("isShowVisualSeal", false);
 
-		params.put("ownershipType", "OWN");
+        params.put("ownershipType", "OWN");
 
-		templateEngine.render(params, "courses.ftl", srcFile);
+        templateEngine.render(params, "courses.ftl", srcFile);
 
-		// 生成借款协议PDF
-		try {
-			PDFUtil.renderToPDFByData(ContractServiceImpl.class.getResource("/").getFile(), FileUtils.readFileToString(srcFile), srcPdfPath, "simsun.ttc");
-		} catch (IOException e) {
-			throw new BizException("生成pdf协议失败", e);
-		}
-		String organCode = "91440300326364429H";
-		SysUserTsign organTsign = sysUserTsignService.queryByCardNo(organCode);
-		if (organTsign == null) {
-			throw new BizException("甲方未创建签章");
-		}
+        // 生成借款协议PDF
+        try {
+            PDFUtil.renderToPDFByData(ContractServiceImpl.class.getResource("/").getFile(), FileUtils.readFileToString(srcFile), srcPdfPath, "simsun.ttc");
+        } catch (IOException e) {
+            throw new BizException("生成pdf协议失败", e);
+        }
+        String organCode = "91440300326364429H";
+        SysUserTsign organTsign = sysUserTsignService.queryByCardNo(organCode);
+        if (organTsign == null) {
+            throw new BizException("甲方未创建签章");
+        }
 
-		eSealPlugin.organSign(organTsign.getSealData(), srcPdfPath, srcPdfPath);
+        eSealPlugin.organSign(organTsign.getSealData(), srcPdfPath, srcPdfPath);
 
-		if (sysUserTsign != null) {
-			eSealPlugin.userSign(sysUserTsign.getAccountId(), sysUserTsign.getSealData(), srcPdfPath, srcPdfPath);
-		}
+        if (sysUserTsign != null) {
+            eSealPlugin.userSign(sysUserTsign.getAccountId(), sysUserTsign.getSealData(), srcPdfPath, srcPdfPath);
+        }
 
-		// 上传到oss
-		String dateStrOss = dateFormatOss.format(date);
-		dateStrOss = "vipCourses/" + dateStrOss + "/" + DateUtil.getHour(date);
-		String pdfFilePath = storagePluginContext.uploadFile(KS3StoragePlugin.PLUGIN_NAME, dateStrOss, srcFile);
+        // 上传到oss
+        String dateStrOss = dateFormatOss.format(date);
+        dateStrOss = "vipCourses/" + dateStrOss + "/" + DateUtil.getHour(date);
+        String pdfFilePath = storagePluginContext.uploadFile(KS3StoragePlugin.PLUGIN_NAME, dateStrOss, srcFile);
 
-		SysUserContracts sysUserContracts = new SysUserContracts();
-		sysUserContracts.setCreateTime(date);
-		sysUserContracts.setType(ContractType.VIP_COURSES);
-		sysUserContracts.setUrl(pdfFilePath);
-		sysUserContracts.setUserId(userId);
+        SysUserContracts sysUserContracts = new SysUserContracts();
+        sysUserContracts.setCreateTime(date);
+        sysUserContracts.setType(ContractType.VIP_COURSES);
+        sysUserContracts.setUrl(pdfFilePath);
+        sysUserContracts.setUserId(userId);
 
-		sysUserContractsService.insert(sysUserContracts);
+        sysUserContractsService.insert(sysUserContracts);
 
-		FileUtils.deleteQuietly(srcFile);
+        FileUtils.deleteQuietly(srcFile);
 
-		return true;
-	}
+        return true;
+    }
 
-	@Override
-	public String queryVipGroupCoursesContract(Integer userId, Long vipGroupId) {
+    @Override
+    public String queryVipGroupCoursesContract(Integer userId, Long vipGroupId) {
 
-		// 合成freemarker
-		String srcPdfPath = contractBaseDir + "/courses/" + userId + ".pdf";
+        // 合成freemarker
+        String srcPdfPath = contractBaseDir + "/courses/" + userId + ".pdf";
 
-		File srcFile = new File(srcPdfPath);
+        File srcFile = new File(srcPdfPath);
 
-		File debtFile = new File(srcFile.getParent());
-		if (!debtFile.exists()) {
-			debtFile.mkdirs();
-		}
+        File debtFile = new File(srcFile.getParent());
+        if (!debtFile.exists()) {
+            debtFile.mkdirs();
+        }
 
-		FreemarkerTemplateEngine templateEngine = FreemarkerTemplateEngine.getInstance();
-		templateEngine.setClassForTemplateLoading(ContractServiceImpl.class, "/config/contracts/");
+        FreemarkerTemplateEngine templateEngine = FreemarkerTemplateEngine.getInstance();
+        templateEngine.setClassForTemplateLoading(ContractServiceImpl.class, "/config/contracts/");
 
-		Map<String, Object> params = new HashMap<String, Object>();
+        Map<String, Object> params = new HashMap<String, Object>();
 
-		StudentInfo studentInfo = studentRegistrationService.queryStudentInfo(userId);
-		params.put("studentInfo", studentInfo);
+        StudentInfo studentInfo = studentRegistrationService.queryStudentInfo(userId);
+        params.put("studentInfo", studentInfo);
 
-		// 课程类型
-		params.put("classesType", "VIP课");
+        // 课程类型
+        params.put("classesType", "VIP课");
 
-		// 课程费用
-		VipGroup vipGroup = vipGroupService.get(vipGroupId);
-		if (vipGroup == null) {
-			throw new BizException("VIP课找不到");
-		}
-		params.put("courseFee", vipGroup.getTotalPrice().doubleValue());
+        // 课程费用
+        VipGroup vipGroup = vipGroupService.get(vipGroupId);
+        if (vipGroup == null) {
+            throw new BizException("VIP课找不到");
+        }
+        params.put("courseFee", vipGroup.getTotalPrice().doubleValue());
 
-		// 收费形式
-		params.put("paymentcalender", "一次性");
+        // 收费形式
+        params.put("paymentcalender", "一次性");
 
-		params.put("isShowVisualSeal", true);
+        params.put("isShowVisualSeal", true);
 
-		params.put("ownershipType", "OWN");
+        params.put("ownershipType", "OWN");
 
-		templateEngine.render(params, "courses.ftl", srcFile);
+        templateEngine.render(params, "courses.ftl", srcFile);
 
-		String result = "";
-		try {
-			result = FileUtils.readFileToString(srcFile);
-		} catch (IOException e) {
-			throw new BizException("读取课程协议出错", e);
-		} finally {
-			FileUtils.deleteQuietly(srcFile);
-		}
+        String result = "";
+        try {
+            result = FileUtils.readFileToString(srcFile);
+        } catch (IOException e) {
+            throw new BizException("读取课程协议出错", e);
+        } finally {
+            FileUtils.deleteQuietly(srcFile);
+        }
 
-		return result;
-	}
+        return result;
+    }
 
-	@Override
-	public boolean transferGoodsContract(Integer userId, String musicGroupId, String goodsIds, KitGroupPurchaseTypeEnum kitGroupPurchaseTypeEnum) {
+    @Override
+    public boolean transferGoodsContract(Integer userId, String musicGroupId, String goodsIds, KitGroupPurchaseTypeEnum kitGroupPurchaseTypeEnum) {
 
-		transferProduceContract(userId, musicGroupId,null);
-		return true;
-	}
+        transferProduceContract(userId, musicGroupId, null);
+        return true;
+    }
 
-	@Override
-	public String queryGoodsContract(Integer userId, String musicGroupId, String goodsIds, KitGroupPurchaseTypeEnum kitGroupPurchaseTypeEnum) {
+    @Override
+    public String queryGoodsContract(Integer userId, String musicGroupId, String goodsIds, KitGroupPurchaseTypeEnum kitGroupPurchaseTypeEnum) {
 
-		// 合成freemarker
-		String srcPdfPath = contractBaseDir + "/goods/" + userId + ".pdf";
+        // 合成freemarker
+        String srcPdfPath = contractBaseDir + "/goods/" + userId + ".pdf";
 
-		File srcFile = new File(srcPdfPath);
+        File srcFile = new File(srcPdfPath);
 
-		File debtFile = new File(srcFile.getParent());
-		if (!debtFile.exists()) {
-			debtFile.mkdirs();
-		}
+        File debtFile = new File(srcFile.getParent());
+        if (!debtFile.exists()) {
+            debtFile.mkdirs();
+        }
 
-		FreemarkerTemplateEngine templateEngine = FreemarkerTemplateEngine.getInstance();
-		templateEngine.setClassForTemplateLoading(ContractServiceImpl.class, "/config/contracts/");
+        FreemarkerTemplateEngine templateEngine = FreemarkerTemplateEngine.getInstance();
+        templateEngine.setClassForTemplateLoading(ContractServiceImpl.class, "/config/contracts/");
 
-		Map<String, Object> params = new HashMap<String, Object>();
+        Map<String, Object> params = new HashMap<String, Object>();
 
-		// 查询参数信息
-		StudentInfo studentInfo = studentRegistrationService.queryStudentInfo(userId);
+        // 查询参数信息
+        StudentInfo studentInfo = studentRegistrationService.queryStudentInfo(userId);
 
-		int subjectId = studentInfo.getSubject().getId();
+        int subjectId = studentInfo.getSubject().getId();
 
-		Subject subject = subjectService.get(subjectId);
-		studentInfo.setSubject(subject);
+        Subject subject = subjectService.get(subjectId);
+        studentInfo.setSubject(subject);
 
-		params.put("studentInfo", studentInfo);
+        params.put("studentInfo", studentInfo);
 
-		List<Goods> goodsList = goodsService.findGoodsByIds(goodsIds);
-		params.put("goodsList", goodsList);
+        List<Goods> goodsList = goodsService.findGoodsByIds(goodsIds);
+        params.put("goodsList", goodsList);
 
-		double depositFee = 0d;
-		if (kitGroupPurchaseTypeEnum == KitGroupPurchaseTypeEnum.LEASE) {
-			MusicGroupSubjectGoodsGroup musicGroupSubjectPlan = musicGroupSubjectGoodsGroupService.query(musicGroupId, subjectId, goodsIds);
-			if (musicGroupSubjectPlan != null) {
-				depositFee = musicGroupSubjectPlan.getDepositFee().doubleValue();
-			}
-		}
-		params.put("depositFee", depositFee);
-		params.put("depositFeeFmt", MoneyUtil.toChinese(depositFee + ""));
+        double depositFee = 0d;
+        if (kitGroupPurchaseTypeEnum == KitGroupPurchaseTypeEnum.LEASE) {
+            MusicGroupSubjectGoodsGroup musicGroupSubjectPlan = musicGroupSubjectGoodsGroupService.query(musicGroupId, subjectId, goodsIds);
+            if (musicGroupSubjectPlan != null) {
+                depositFee = musicGroupSubjectPlan.getDepositFee().doubleValue();
+            }
+        }
+        params.put("depositFee", depositFee);
+        params.put("depositFeeFmt", MoneyUtil.toChinese(depositFee + ""));
 
-		params.put("isShowVisualSeal", true);
+        params.put("isShowVisualSeal", true);
 
-		MusicGroup musicGroup = musicGroupService.get(musicGroupId);
-		if (musicGroup == null) {
-			throw new BizException("乐团信息没找到");
-		}
+        MusicGroup musicGroup = musicGroupService.get(musicGroupId);
+        if (musicGroup == null) {
+            throw new BizException("乐团信息没找到");
+        }
 
-		params.put("ownershipType", musicGroup.getOwnershipType().name());
+        params.put("ownershipType", musicGroup.getOwnershipType().name());
 
-		templateEngine.render(params, "goods.ftl", srcFile);
+        templateEngine.render(params, "goods.ftl", srcFile);
 
-		String result = "";
-		try {
-			result = FileUtils.readFileToString(srcFile);
-		} catch (IOException e) {
-			throw new BizException("读取商品协议出错", e);
-		} finally {
-			FileUtils.deleteQuietly(srcFile);
-		}
+        String result = "";
+        try {
+            result = FileUtils.readFileToString(srcFile);
+        } catch (IOException e) {
+            throw new BizException("读取商品协议出错", e);
+        } finally {
+            FileUtils.deleteQuietly(srcFile);
+        }
 
-		return result;
-	}
+        return result;
+    }
 
-	@Override
-	public String queryPracticeCoursesContract(Integer userId, int courseSectionNum, Date startDate, Date endDate, BigDecimal fee) {
-		// 合成freemarker
-		String srcPdfPath = contractBaseDir + "/practice/" + userId + ".pdf";
+    @Override
+    public String queryPracticeCoursesContract(Integer userId, int courseSectionNum, Date startDate, Date endDate, BigDecimal fee) {
+        // 合成freemarker
+        String srcPdfPath = contractBaseDir + "/practice/" + userId + ".pdf";
 
-		File srcFile = new File(srcPdfPath);
+        File srcFile = new File(srcPdfPath);
 
-		File debtFile = new File(srcFile.getParent());
-		if (!debtFile.exists()) {
-			debtFile.mkdirs();
-		}
+        File debtFile = new File(srcFile.getParent());
+        if (!debtFile.exists()) {
+            debtFile.mkdirs();
+        }
 
-		FreemarkerTemplateEngine templateEngine = FreemarkerTemplateEngine.getInstance();
-		templateEngine.setClassForTemplateLoading(ContractServiceImpl.class, "/config/contracts/");
+        FreemarkerTemplateEngine templateEngine = FreemarkerTemplateEngine.getInstance();
+        templateEngine.setClassForTemplateLoading(ContractServiceImpl.class, "/config/contracts/");
 
-		Map<String, Object> params = new HashMap<String, Object>();
-		params.put("courseSectionNum", courseSectionNum);
-		params.put("startDate", startDate);
-		params.put("endDate", endDate);
-		params.put("fee", fee);
+        Map<String, Object> params = new HashMap<String, Object>();
+        params.put("courseSectionNum", courseSectionNum);
+        params.put("startDate", startDate);
+        params.put("endDate", endDate);
+        params.put("fee", fee);
 
-		params.put("isShowVisualSeal", false);
+        params.put("isShowVisualSeal", false);
 
-		params.put("ownershipType", "OWN");
+        params.put("ownershipType", "OWN");
 
-		templateEngine.render(params, "practice.ftl", srcFile);
+        templateEngine.render(params, "practice.ftl", srcFile);
 
-		String result = "";
-		try {
-			result = FileUtils.readFileToString(srcFile);
-		} catch (IOException e) {
-			throw new BizException("读取网管课购买协议出错", e);
-		} finally {
-			FileUtils.deleteQuietly(srcFile);
-		}
+        String result = "";
+        try {
+            result = FileUtils.readFileToString(srcFile);
+        } catch (IOException e) {
+            throw new BizException("读取网管课购买协议出错", e);
+        } finally {
+            FileUtils.deleteQuietly(srcFile);
+        }
 
-		return result;
-	}
+        return result;
+    }
 
-	@Override
-	@Async
-	public boolean transferPracticeCoursesContract(Integer userId, int courseSectionNum, Date startDate, Date endDate, BigDecimal fee) {
-		if(true){
-			 transferProduceContract(userId, null, null);
-			 return true;
-		}
-
-		SysUserTsign sysUserTsign = sysUserTsignService.get(userId);
-
-		if (sysUserTsign == null) {
-			SysUser user = sysUserFeignService.queryUserById(userId);
-			if (user == null) {
-				throw new BizException("用户信息查询失败");
-			}
-			sysUserTsign = register(userId, user.getRealName(), user.getIdCardNo(), user.getPhone());
-		}
-
-		Date date = new Date();
-
-		// 合成freemarker
-		String srcPdfPath = contractBaseDir + "/practice/" + userId + ".pdf";
-
-		File srcFile = new File(srcPdfPath);
-
-		File debtFile = new File(srcFile.getParent());
-		if (!debtFile.exists()) {
-			debtFile.mkdirs();
-		}
-
-		FreemarkerTemplateEngine templateEngine = FreemarkerTemplateEngine.getInstance();
-		templateEngine.setClassForTemplateLoading(ContractServiceImpl.class, "/config/contracts/");
-
-		Map<String, Object> params = new HashMap<String, Object>();
-		params.put("courseSectionNum", courseSectionNum);
-		params.put("startDate", startDate);
-		params.put("endDate", endDate);
-		params.put("fee", fee);
-
-		params.put("isShowVisualSeal", false);
-
-		params.put("ownershipType", "OWN");
-
-		templateEngine.render(params, "practice.ftl", srcFile);
-
-		// 生成借款协议PDF
-		try {
-			PDFUtil.renderToPDFByData(ContractServiceImpl.class.getResource("/").getFile(), FileUtils.readFileToString(srcFile), srcPdfPath, "simsun.ttc");
-		} catch (IOException e) {
-			throw new BizException("生成pdf协议失败", e);
-		}
-		String organCode = "91440300326364429H";
-		SysUserTsign organTsign = sysUserTsignService.queryByCardNo(organCode);
-		if (organTsign == null) {
-			throw new BizException("甲方未创建签章");
-		}
-
-		eSealPlugin.organSign(organTsign.getSealData(), srcPdfPath, srcPdfPath);
-
-		if (sysUserTsign != null) {
-			eSealPlugin.userSign(sysUserTsign.getAccountId(), sysUserTsign.getSealData(), srcPdfPath, srcPdfPath);
-		}
-
-		// 上传到oss
-		String dateStrOss = dateFormatOss.format(date);
-		dateStrOss = "practice/" + dateStrOss + "/" + DateUtil.getHour(date);
-		String pdfFilePath = storagePluginContext.uploadFile(KS3StoragePlugin.PLUGIN_NAME, dateStrOss, srcFile);
-
-		SysUserContracts sysUserContracts = new SysUserContracts();
-		sysUserContracts.setCreateTime(date);
-		sysUserContracts.setType(ContractType.PRACTICE);
-		sysUserContracts.setUrl(pdfFilePath);
-		sysUserContracts.setUserId(userId);
-
-		sysUserContractsService.insert(sysUserContracts);
-
-		FileUtils.deleteQuietly(srcFile);
-
-		return true;
-	}
-
-	@Override
-	@Async
-	@Transactional(rollbackFor = Exception.class, isolation = Isolation.READ_COMMITTED, propagation = Propagation.REQUIRES_NEW)
-	public void transferProduceContract(Integer userId,String musicGroupId, CourseViewTypeEnum courseViewType) {
-		SysUser user = studentDao.lockUserReturnInfo(userId);
-
-		if (user == null) {
-			logger.error("用户不存在({})", userId);
-			return;
-		}
-
-		if(StringUtils.isBlank(user.getRealName())||StringUtils.isBlank(user.getIdCardNo())){
-			logger.error("身份信息缺失({})", userId);
-			return;
-		}
-
-		SysUserTsign sysUserTsign = sysUserTsignService.get(userId);
-		if (sysUserTsign == null) {
-			try {
-				sysUserTsign = register(userId, user.getRealName(), user.getIdCardNo(), user.getPhone());
-			} catch (Exception e) {
-				logger.error("用户电子签章注册失败", e);
-				return;
-			}
-		}
-		Date date = new Date();
-
-		// 合成freemarker
-		String srcPdfPath = contractBaseDir + "/product/" + dateFormat1.format(date) + "/" + userId + "_" + LocalDateTime.now().getSecond() + ".pdf";
-
-		File srcFile = new File(srcPdfPath);
-
-		File debtFile = new File(srcFile.getParent());
-		if (!debtFile.exists()) {
-			debtFile.mkdirs();
-		}
-
-		FreemarkerTemplateEngine templateEngine = FreemarkerTemplateEngine.getInstance();
-		templateEngine.setClassForTemplateLoading(ContractServiceImpl.class, "/config/contracts/");
-
-		Map<String, Object> params = new HashMap<String, Object>();
-
-		// 查询参数信息
-		StudentInfo studentInfo = studentRegistrationService.queryStudentInfo(userId);
-		params.put("studentInfo", studentInfo);
-
-		params.put("isShowVisualSeal", false);
-
-		CourseViewTypeEnum ownershipType = CourseViewTypeEnum.COURSE_FEE;
-
-		if(StringUtils.isBlank(musicGroupId)){
-			params.put("ownershipType", "OWN");
-			MusicGroup userLastNormalMusicGroup = studentRegistrationDao.getUserLastNormalMusicGroup(userId);
-			if(Objects.nonNull(userLastNormalMusicGroup)){
-				ownershipType = userLastNormalMusicGroup.getCourseViewType();
-			}
-		}else{
-			MusicGroup musicGroup = musicGroupService.get(musicGroupId);
-			if (musicGroup == null) {
-				logger.error("乐团信息没找到({})", musicGroupId);
-				return;
-			}
-			params.put("ownershipType", musicGroup.getOwnershipType().name());
-			ownershipType = musicGroup.getCourseViewType();
-		}
-
-		if(Objects.nonNull(courseViewType)){
-			ownershipType = courseViewType;
-		}
-
-		List<SysUserContracts> userContracts = sysUserContractsService.getUserContractWithType(userId, ContractType.PRODUCT, ownershipType.getContractVersion());
-		if(!CollectionUtils.isEmpty(userContracts)){
-			return;
-		}
-
-		templateEngine.render(params, "product"+ownershipType.getContractVersion()+".ftl", srcFile);
-
-		// 生成借款协议PDF
-		try {
-			PDFUtil.renderToPDFByData(ContractServiceImpl.class.getResource("/").getFile(), FileUtils.readFileToString(srcFile), srcPdfPath, "simsun.ttc");
-		} catch (IOException e) {
-			logger.error("生成产品协议失败", e);
-			return;
-		}
-
-
-		String organCode = "";
-		if (OwnershipType.OWN.name().equals(params.get("ownershipType"))){
-			organCode = "91440300326364429H";
-		} else {
-			organCode = "91420106333619290A";
-		}
-		SysUserTsign organTsign = sysUserTsignService.queryByCardNo(organCode);
-		if (organTsign == null) {
-			logger.error("甲方未创建签章");
-			return;
-		}
-
-		eSealPlugin.organSign(organTsign.getSealData(), srcPdfPath, srcPdfPath);
-		if (sysUserTsign != null && CertificateTypeEnum.IDENTITY.getCode().equals(user.getCertificateType())) {
-			eSealPlugin.userSign(sysUserTsign.getAccountId(), sysUserTsign.getSealData(), srcPdfPath, srcPdfPath);
-		}
-
-		// 上传到oss
-		String dateStrOss = dateFormatOss.format(date);
-		dateStrOss = "product/" + dateStrOss + "/" + DateUtil.getHour(date);
-		String pdfFilePath = storagePluginContext.uploadFile(KS3StoragePlugin.PLUGIN_NAME, dateStrOss, srcFile);
-
-		SysUserContracts sysUserContracts = new SysUserContracts();
-		sysUserContracts.setCreateTime(date);
-		sysUserContracts.setType(ContractType.PRODUCT);
-		sysUserContracts.setUrl(pdfFilePath);
-		sysUserContracts.setUserId(userId);
-		sysUserContracts.setVersion(ownershipType.getContractVersion());
-
-		sysUserContractsService.insert(sysUserContracts);
-
-		FileUtils.deleteQuietly(srcFile);
-	}
-
-	@Override
-	@Transactional(isolation = Isolation.READ_COMMITTED)
-	public Map<String, Object> queryProductContract(Integer userId,String musicGroupId, CourseViewTypeEnum courseViewType) {
-		// 合成freemarker
-		String srcPdfPath = contractBaseDir + "/product/" + userId + ".pdf";
-
-		File srcFile = new File(srcPdfPath);
-
-		File debtFile = new File(srcFile.getParent());
-		if (!debtFile.exists()) {
-			debtFile.mkdirs();
-		}
-
-		FreemarkerTemplateEngine templateEngine = FreemarkerTemplateEngine.getInstance();
-		templateEngine.setClassForTemplateLoading(ContractServiceImpl.class, "/config/contracts/");
-
-		Map<String, Object> params = new HashMap<String, Object>();
-
-		StudentInfo studentInfo = studentRegistrationService.queryStudentInfo(userId);
-		if(Objects.isNull(studentInfo)){
-			studentInfo = new StudentInfo();
-		}
-		if(StringUtils.isEmpty(studentInfo.getCertificateType())){
-			studentInfo.setCertificateType(CertificateTypeEnum.IDENTITY.getCode());
-		}
-		params.put("studentInfo", studentInfo);
-		params.put("isShowVisualSeal", true);
-
-		Map<String, Object> result = new HashMap<>();
-		result.put("courseViewType", CourseViewTypeEnum.COURSE_FEE);
-		CourseViewTypeEnum ownershipType = CourseViewTypeEnum.COURSE_FEE;
-
-		if(StringUtils.isBlank(musicGroupId)){
-			params.put("ownershipType", "OWN");
-			MusicGroup userLastNormalMusicGroup = studentRegistrationDao.getUserLastNormalMusicGroup(userId);
-			if(Objects.nonNull(userLastNormalMusicGroup)){
-				result.put("courseViewType", userLastNormalMusicGroup.getCourseViewType());
-				ownershipType = userLastNormalMusicGroup.getCourseViewType();
-			}
-		}else{
-			MusicGroup musicGroup = musicGroupService.get(musicGroupId);
-			if (musicGroup == null) {
-				throw new BizException("乐团信息没找到");
-			}
-			params.put("ownershipType", musicGroup.getOwnershipType().name());
-			result.put("courseViewType", musicGroup.getCourseViewType());
-			ownershipType = musicGroup.getCourseViewType();
-		}
-
-		if(Objects.nonNull(courseViewType)){
-			ownershipType = courseViewType;
-		}
-
-		templateEngine.render(params, "product"+ownershipType.getContractVersion()+".ftl", srcFile);
-
-		String html = "";
-		try {
-			html = FileUtils.readFileToString(srcFile);
-		} catch (IOException e) {
-			throw new BizException("读取产品协议出错", e);
-		} finally {
-			FileUtils.deleteQuietly(srcFile);
-		}
-
-		List<SysUserContracts> userContractWithType = sysUserContractsService.getUserContractWithType(userId, ContractType.PRODUCT, ownershipType.getContractVersion());
-
-		result.put("exists", !CollectionUtils.isEmpty(userContractWithType));
-		result.put("productContract", html);
-		return result;
-	}
-
-	@Override
-	@Transactional(rollbackFor = Exception.class)
-	public HttpResponseResult transferProduceContractOnlyWithCourseList(Integer userId) {
-		SysUser user = studentDao.lockUserReturnInfo(userId);
-		if (user == null) {
-			logger.error("用户不存在({})", userId);
-			return BaseController.failed("用户不存在");
-		}
-
-		int validContactNum = sysUserContractsDao.countUserValidContact(userId);
-		if(validContactNum>0){
-			return BaseController.succeed();
-		}
-
-		if(StringUtils.isBlank(user.getRealName())||StringUtils.isBlank(user.getIdCardNo())){
-			return BaseController.failed(HttpStatus.PARTIAL_CONTENT, user, "");
-		}
-
-		SysUserTsign sysUserTsign = sysUserTsignService.get(userId);
-		if (sysUserTsign == null) {
-			try {
-				sysUserTsign = register(userId, user.getRealName(), user.getIdCardNo(), user.getPhone());
-			} catch (Exception e) {
-				logger.error("用户电子签章注册失败", e);
-				return BaseController.failed("用户电子签章注册失败");
-			}
-		}
-		Date date = new Date();
-
-		// 合成freemarker
-		String srcPdfPath = contractBaseDir + "/product/" + dateFormat1.format(date) + "/" + userId + "_" + LocalDateTime.now().getSecond() + ".pdf";
-
-		File srcFile = new File(srcPdfPath);
-
-		File debtFile = new File(srcFile.getParent());
-		if (!debtFile.exists()) {
-			debtFile.mkdirs();
-		}
-
-		FreemarkerTemplateEngine templateEngine = FreemarkerTemplateEngine.getInstance();
-		templateEngine.setClassForTemplateLoading(ContractServiceImpl.class, "/config/contracts/");
-
-		Map<String, Object> params = new HashMap<String, Object>();
-
-		// 查询参数信息
-		StudentInfo studentInfo = studentRegistrationService.queryStudentInfo(userId);
-		params.put("studentInfo", studentInfo);
-
-		params.put("isShowVisualSeal", false);
-
-		CourseViewTypeEnum courseViewType = CourseViewTypeEnum.COURSE_FEE;
-		params.put("ownershipType", "OWN");
-
-		List<SysUserContracts> userContracts = sysUserContractsService.getUserContractWithType(userId, ContractType.PRODUCT, 2);
-		if(!CollectionUtils.isEmpty(userContracts)){
-			return BaseController.succeed();
-		}
-
-		templateEngine.render(params, "product2.ftl", srcFile);
-
-		// 生成借款协议PDF
-		try {
-			PDFUtil.renderToPDFByData(ContractServiceImpl.class.getResource("/").getFile(), FileUtils.readFileToString(srcFile), srcPdfPath, "simsun.ttc");
-		} catch (IOException e) {
-			logger.error("生成产品协议失败", e);
-			return BaseController.failed("生成产品协议失败");
-		}
-
-		String organCode = "91440300326364429H";
-
-		SysUserTsign organTsign = sysUserTsignService.queryByCardNo(organCode);
-		if (organTsign == null) {
-			logger.error("甲方未创建签章");
-			return BaseController.failed("甲方未创建签章");
-		}
-
-		eSealPlugin.organSign(organTsign.getSealData(), srcPdfPath, srcPdfPath);
-		if (sysUserTsign != null && CertificateTypeEnum.IDENTITY.getCode().equals(user.getCertificateType())) {
-			eSealPlugin.userSign(sysUserTsign.getAccountId(), sysUserTsign.getSealData(), srcPdfPath, srcPdfPath);
-		}
-
-		// 上传到oss
-		String dateStrOss = dateFormatOss.format(date);
-		dateStrOss = "product/" + dateStrOss + "/" + DateUtil.getHour(date);
-		String pdfFilePath = storagePluginContext.uploadFile(KS3StoragePlugin.PLUGIN_NAME, dateStrOss, srcFile);
-
-		SysUserContracts sysUserContracts = new SysUserContracts();
-		sysUserContracts.setCreateTime(date);
-		sysUserContracts.setType(ContractType.PRODUCT);
-		sysUserContracts.setUrl(pdfFilePath);
-		sysUserContracts.setUserId(userId);
-		sysUserContracts.setVersion(2);
-
-		sysUserContractsService.insert(sysUserContracts);
-
-		FileUtils.deleteQuietly(srcFile);
-		return BaseController.succeed();
-	}
-
-	@Override
-	public String transferOaFinancial(OAFinancialDto financialDto) {
-		List<Integer> circulationUserIds = financialDto.getCirculationUsers().stream().map(CirculationUser::getUserId).collect(Collectors.toList());
-		List<Integer> executorIds = financialDto.getExecutors().stream().map(CirculationUser::getUserId).collect(Collectors.toList());
-		circulationUserIds.addAll(executorIds);
-		List<SysUser> users = employeeDao.getUsers(circulationUserIds);
-
-		Integer workOrderId = null;
-		List<SysUserTsign> sysUserTsigns = new ArrayList<>();
-		for (SysUser user : users) {
-			for (CirculationUser circulationUser : financialDto.getCirculationUsers()) {
-				if (workOrderId == null) {
-					workOrderId = circulationUser.getWorkOrder();
-				}
-				if (!circulationUser.getUserId().equals(user.getId())) continue;
-				circulationUser.setRealName(user.getRealName());
-			}
-			for (CirculationUser executor : financialDto.getExecutors()) {
-				if (!executor.getUserId().equals(user.getId())) continue;
-				executor.setRealName(user.getRealName());
-			}
-			SysUserTsign sysUserTsign = sysUserTsignService.get(user.getId());
-			if (sysUserTsign == null) {
-				try {
-					sysUserTsign = register(user.getId(), user.getRealName(), user.getIdCardNo(), user.getPhone());
-				} catch (Exception e) {
-					logger.error("用户电子签章注册失败", e);
-					continue;
-				}
-			}
-			sysUserTsigns.add(sysUserTsign);
-		}
-
-		Date date = new Date();
-
-		// 合成freemarker
-		String srcPdfPath = contractBaseDir + "/oa/" + dateFormat1.format(date) + "/" + workOrderId + "_" + LocalDateTime.now().getSecond() + ".pdf";
-
-		File srcFile = new File(srcPdfPath);
-
-		File debtFile = new File(srcFile.getParent());
-		if (!debtFile.exists()) {
-			debtFile.mkdirs();
-		}
-
-		FreemarkerTemplateEngine templateEngine = FreemarkerTemplateEngine.getInstance();
-		templateEngine.setClassForTemplateLoading(ContractServiceImpl.class, "/config/contracts/");
-
-		Map<String, Object> params = new HashMap<String, Object>();
-
-		// 查询参数信息
-		params.put("organName", financialDto.getOrganName());
-		params.put("realName", financialDto.getRealName());
-		params.put("feeType", financialDto.getFeeType());
-		params.put("totalMoney", financialDto.getTotalMoney().setScale(2, RoundingMode.HALF_UP));
-		params.put("hasLoan", financialDto.getHasLoan());
-		params.put("memo", financialDto.getMemo());
-		params.put("circulationUsers", financialDto.getCirculationUsers());
-		params.put("executors", financialDto.getExecutors());
-
-		templateEngine.render(params, "financial.ftl", srcFile);
-
-		// 生成借款协议PDF
-		try {
-			PDFUtil.renderToPDFByData(ContractServiceImpl.class.getResource("/").getFile(), FileUtils.readFileToString(srcFile), srcPdfPath, "simsun.ttc");
-		} catch (IOException e) {
-			logger.error("生成签章协议失败", e);
-		}
-
-		for (SysUserTsign sysUserTsign : sysUserTsigns) {
-			eSealPlugin.userSign(sysUserTsign.getAccountId(), sysUserTsign.getSealData(), sysUserTsign.getUserId().toString(), srcPdfPath, srcPdfPath);
-		}
-
-		//上传到oss
-		String dateStrOss = dateFormatOss.format(date);
-		dateStrOss = "oa/" + dateStrOss + "/" + DateUtil.getHour(date);
-		String pdfFilePath = storagePluginContext.uploadFile(KS3StoragePlugin.PLUGIN_NAME, dateStrOss, srcFile);
-
-		FileUtils.deleteQuietly(srcFile);
-
-		return pdfFilePath;
-	}
+    @Override
+    @Async
+    public boolean transferPracticeCoursesContract(Integer userId, int courseSectionNum, Date startDate, Date endDate, BigDecimal fee) {
+        if (true) {
+            transferProduceContract(userId, null, null);
+            return true;
+        }
+
+        SysUserTsign sysUserTsign = sysUserTsignService.get(userId);
+
+        if (sysUserTsign == null) {
+            SysUser user = sysUserFeignService.queryUserById(userId);
+            if (user == null) {
+                throw new BizException("用户信息查询失败");
+            }
+            sysUserTsign = register(userId, user.getRealName(), user.getIdCardNo(), user.getPhone());
+        }
+
+        Date date = new Date();
+
+        // 合成freemarker
+        String srcPdfPath = contractBaseDir + "/practice/" + userId + ".pdf";
+
+        File srcFile = new File(srcPdfPath);
+
+        File debtFile = new File(srcFile.getParent());
+        if (!debtFile.exists()) {
+            debtFile.mkdirs();
+        }
+
+        FreemarkerTemplateEngine templateEngine = FreemarkerTemplateEngine.getInstance();
+        templateEngine.setClassForTemplateLoading(ContractServiceImpl.class, "/config/contracts/");
+
+        Map<String, Object> params = new HashMap<String, Object>();
+        params.put("courseSectionNum", courseSectionNum);
+        params.put("startDate", startDate);
+        params.put("endDate", endDate);
+        params.put("fee", fee);
+
+        params.put("isShowVisualSeal", false);
+
+        params.put("ownershipType", "OWN");
+
+        templateEngine.render(params, "practice.ftl", srcFile);
+
+        // 生成借款协议PDF
+        try {
+            PDFUtil.renderToPDFByData(ContractServiceImpl.class.getResource("/").getFile(), FileUtils.readFileToString(srcFile), srcPdfPath, "simsun.ttc");
+        } catch (IOException e) {
+            throw new BizException("生成pdf协议失败", e);
+        }
+        String organCode = "91440300326364429H";
+        SysUserTsign organTsign = sysUserTsignService.queryByCardNo(organCode);
+        if (organTsign == null) {
+            throw new BizException("甲方未创建签章");
+        }
+
+        eSealPlugin.organSign(organTsign.getSealData(), srcPdfPath, srcPdfPath);
+
+        if (sysUserTsign != null) {
+            eSealPlugin.userSign(sysUserTsign.getAccountId(), sysUserTsign.getSealData(), srcPdfPath, srcPdfPath);
+        }
+
+        // 上传到oss
+        String dateStrOss = dateFormatOss.format(date);
+        dateStrOss = "practice/" + dateStrOss + "/" + DateUtil.getHour(date);
+        String pdfFilePath = storagePluginContext.uploadFile(KS3StoragePlugin.PLUGIN_NAME, dateStrOss, srcFile);
+
+        SysUserContracts sysUserContracts = new SysUserContracts();
+        sysUserContracts.setCreateTime(date);
+        sysUserContracts.setType(ContractType.PRACTICE);
+        sysUserContracts.setUrl(pdfFilePath);
+        sysUserContracts.setUserId(userId);
+
+        sysUserContractsService.insert(sysUserContracts);
+
+        FileUtils.deleteQuietly(srcFile);
+
+        return true;
+    }
+
+    @Override
+    @Async
+    @Transactional(rollbackFor = Exception.class, isolation = Isolation.READ_COMMITTED, propagation = Propagation.REQUIRES_NEW)
+    public void transferProduceContract(Integer userId, String musicGroupId, CourseViewTypeEnum courseViewType) {
+        SysUser user = studentDao.lockUserReturnInfo(userId);
+
+        if (user == null) {
+            logger.error("用户不存在({})", userId);
+            return;
+        }
+
+        if (StringUtils.isBlank(user.getRealName()) || StringUtils.isBlank(user.getIdCardNo())) {
+            logger.error("身份信息缺失({})", userId);
+            return;
+        }
+
+        SysUserTsign sysUserTsign = sysUserTsignService.get(userId);
+        if (sysUserTsign == null) {
+            try {
+                sysUserTsign = register(userId, user.getRealName(), user.getIdCardNo(), user.getPhone());
+            } catch (Exception e) {
+                logger.error("用户电子签章注册失败", e);
+                return;
+            }
+        }
+        Date date = new Date();
+
+        // 合成freemarker
+        String srcPdfPath = contractBaseDir + "/product/" + dateFormat1.format(date) + "/" + userId + "_" + LocalDateTime.now().getSecond() + ".pdf";
+
+        File srcFile = new File(srcPdfPath);
+
+        File debtFile = new File(srcFile.getParent());
+        if (!debtFile.exists()) {
+            debtFile.mkdirs();
+        }
+
+        FreemarkerTemplateEngine templateEngine = FreemarkerTemplateEngine.getInstance();
+        templateEngine.setClassForTemplateLoading(ContractServiceImpl.class, "/config/contracts/");
+
+        Map<String, Object> params = new HashMap<String, Object>();
+
+        // 查询参数信息
+        StudentInfo studentInfo = studentRegistrationService.queryStudentInfo(userId);
+        params.put("studentInfo", studentInfo);
+
+        params.put("isShowVisualSeal", false);
+
+        CourseViewTypeEnum ownershipType = CourseViewTypeEnum.COURSE_FEE;
+
+        if (StringUtils.isBlank(musicGroupId)) {
+            params.put("ownershipType", "OWN");
+            MusicGroup userLastNormalMusicGroup = studentRegistrationDao.getUserLastNormalMusicGroup(userId);
+            if (Objects.nonNull(userLastNormalMusicGroup)) {
+                ownershipType = userLastNormalMusicGroup.getCourseViewType();
+            }
+        } else {
+            MusicGroup musicGroup = musicGroupService.get(musicGroupId);
+            if (musicGroup == null) {
+                logger.error("乐团信息没找到({})", musicGroupId);
+                return;
+            }
+            params.put("ownershipType", musicGroup.getOwnershipType().name());
+            ownershipType = musicGroup.getCourseViewType();
+        }
+
+        if (Objects.nonNull(courseViewType)) {
+            ownershipType = courseViewType;
+        }
+
+        List<SysUserContracts> userContracts = sysUserContractsService.getUserContractWithType(userId, ContractType.PRODUCT, ownershipType.getContractVersion());
+        if (!CollectionUtils.isEmpty(userContracts)) {
+            return;
+        }
+
+        templateEngine.render(params, "product" + ownershipType.getContractVersion() + ".ftl", srcFile);
+
+        // 生成借款协议PDF
+        try {
+            PDFUtil.renderToPDFByData(ContractServiceImpl.class.getResource("/").getFile(), FileUtils.readFileToString(srcFile), srcPdfPath, "simsun.ttc");
+        } catch (IOException e) {
+            logger.error("生成产品协议失败", e);
+            return;
+        }
+
+
+        String organCode = "";
+        if (OwnershipType.OWN.name().equals(params.get("ownershipType"))) {
+            organCode = "91440300326364429H";
+        } else {
+            organCode = "91420106333619290A";
+        }
+        SysUserTsign organTsign = sysUserTsignService.queryByCardNo(organCode);
+        if (organTsign == null) {
+            logger.error("甲方未创建签章");
+            return;
+        }
+
+        eSealPlugin.organSign(organTsign.getSealData(), srcPdfPath, srcPdfPath);
+        if (sysUserTsign != null && CertificateTypeEnum.IDENTITY.getCode().equals(user.getCertificateType())) {
+            eSealPlugin.userSign(sysUserTsign.getAccountId(), sysUserTsign.getSealData(), srcPdfPath, srcPdfPath);
+        }
+
+        // 上传到oss
+        String dateStrOss = dateFormatOss.format(date);
+        dateStrOss = "product/" + dateStrOss + "/" + DateUtil.getHour(date);
+        String pdfFilePath = storagePluginContext.uploadFile(KS3StoragePlugin.PLUGIN_NAME, dateStrOss, srcFile);
+
+        SysUserContracts sysUserContracts = new SysUserContracts();
+        sysUserContracts.setCreateTime(date);
+        sysUserContracts.setType(ContractType.PRODUCT);
+        sysUserContracts.setUrl(pdfFilePath);
+        sysUserContracts.setUserId(userId);
+        sysUserContracts.setVersion(ownershipType.getContractVersion());
+
+        sysUserContractsService.insert(sysUserContracts);
+
+        FileUtils.deleteQuietly(srcFile);
+    }
+
+    @Override
+    @Transactional(isolation = Isolation.READ_COMMITTED)
+    public Map<String, Object> queryProductContract(Integer userId, String musicGroupId, CourseViewTypeEnum courseViewType) {
+        // 合成freemarker
+        String srcPdfPath = contractBaseDir + "/product/" + userId + ".pdf";
+
+        File srcFile = new File(srcPdfPath);
+
+        File debtFile = new File(srcFile.getParent());
+        if (!debtFile.exists()) {
+            debtFile.mkdirs();
+        }
+
+        FreemarkerTemplateEngine templateEngine = FreemarkerTemplateEngine.getInstance();
+        templateEngine.setClassForTemplateLoading(ContractServiceImpl.class, "/config/contracts/");
+
+        Map<String, Object> params = new HashMap<String, Object>();
+
+        StudentInfo studentInfo = studentRegistrationService.queryStudentInfo(userId);
+        if (Objects.isNull(studentInfo)) {
+            studentInfo = new StudentInfo();
+        }
+        if (StringUtils.isEmpty(studentInfo.getCertificateType())) {
+            studentInfo.setCertificateType(CertificateTypeEnum.IDENTITY.getCode());
+        }
+        params.put("studentInfo", studentInfo);
+        params.put("isShowVisualSeal", true);
+
+        Map<String, Object> result = new HashMap<>();
+        result.put("courseViewType", CourseViewTypeEnum.COURSE_FEE);
+        CourseViewTypeEnum ownershipType = CourseViewTypeEnum.COURSE_FEE;
+
+        if (StringUtils.isBlank(musicGroupId)) {
+            params.put("ownershipType", "OWN");
+            MusicGroup userLastNormalMusicGroup = studentRegistrationDao.getUserLastNormalMusicGroup(userId);
+            if (Objects.nonNull(userLastNormalMusicGroup)) {
+                result.put("courseViewType", userLastNormalMusicGroup.getCourseViewType());
+                ownershipType = userLastNormalMusicGroup.getCourseViewType();
+            }
+        } else {
+            MusicGroup musicGroup = musicGroupService.get(musicGroupId);
+            if (musicGroup == null) {
+                throw new BizException("乐团信息没找到");
+            }
+            params.put("ownershipType", musicGroup.getOwnershipType().name());
+            result.put("courseViewType", musicGroup.getCourseViewType());
+            ownershipType = musicGroup.getCourseViewType();
+        }
+
+        if (Objects.nonNull(courseViewType)) {
+            ownershipType = courseViewType;
+        }
+
+        templateEngine.render(params, "product" + ownershipType.getContractVersion() + ".ftl", srcFile);
+
+        String html = "";
+        try {
+            html = FileUtils.readFileToString(srcFile);
+        } catch (IOException e) {
+            throw new BizException("读取产品协议出错", e);
+        } finally {
+            FileUtils.deleteQuietly(srcFile);
+        }
+
+        List<SysUserContracts> userContractWithType = sysUserContractsService.getUserContractWithType(userId, ContractType.PRODUCT, ownershipType.getContractVersion());
+
+        result.put("exists", !CollectionUtils.isEmpty(userContractWithType));
+        result.put("productContract", html);
+        return result;
+    }
+
+    @Override
+    @Transactional(rollbackFor = Exception.class)
+    public HttpResponseResult transferProduceContractOnlyWithCourseList(Integer userId) {
+        SysUser user = studentDao.lockUserReturnInfo(userId);
+        if (user == null) {
+            logger.error("用户不存在({})", userId);
+            return BaseController.failed("用户不存在");
+        }
+
+        int validContactNum = sysUserContractsDao.countUserValidContact(userId);
+        if (validContactNum > 0) {
+            return BaseController.succeed();
+        }
+
+        if (StringUtils.isBlank(user.getRealName()) || StringUtils.isBlank(user.getIdCardNo())) {
+            return BaseController.failed(HttpStatus.PARTIAL_CONTENT, user, "");
+        }
+
+        SysUserTsign sysUserTsign = sysUserTsignService.get(userId);
+        if (sysUserTsign == null) {
+            try {
+                sysUserTsign = register(userId, user.getRealName(), user.getIdCardNo(), user.getPhone());
+            } catch (Exception e) {
+                logger.error("用户电子签章注册失败", e);
+                return BaseController.failed("用户电子签章注册失败");
+            }
+        }
+        Date date = new Date();
+
+        // 合成freemarker
+        String srcPdfPath = contractBaseDir + "/product/" + dateFormat1.format(date) + "/" + userId + "_" + LocalDateTime.now().getSecond() + ".pdf";
+
+        File srcFile = new File(srcPdfPath);
+
+        File debtFile = new File(srcFile.getParent());
+        if (!debtFile.exists()) {
+            debtFile.mkdirs();
+        }
+
+        FreemarkerTemplateEngine templateEngine = FreemarkerTemplateEngine.getInstance();
+        templateEngine.setClassForTemplateLoading(ContractServiceImpl.class, "/config/contracts/");
+
+        Map<String, Object> params = new HashMap<String, Object>();
+
+        // 查询参数信息
+        StudentInfo studentInfo = studentRegistrationService.queryStudentInfo(userId);
+        params.put("studentInfo", studentInfo);
+
+        params.put("isShowVisualSeal", false);
+
+        CourseViewTypeEnum courseViewType = CourseViewTypeEnum.COURSE_FEE;
+        params.put("ownershipType", "OWN");
+
+        List<SysUserContracts> userContracts = sysUserContractsService.getUserContractWithType(userId, ContractType.PRODUCT, 2);
+        if (!CollectionUtils.isEmpty(userContracts)) {
+            return BaseController.succeed();
+        }
+
+        templateEngine.render(params, "product2.ftl", srcFile);
+
+        // 生成借款协议PDF
+        try {
+            PDFUtil.renderToPDFByData(ContractServiceImpl.class.getResource("/").getFile(), FileUtils.readFileToString(srcFile), srcPdfPath, "simsun.ttc");
+        } catch (IOException e) {
+            logger.error("生成产品协议失败", e);
+            return BaseController.failed("生成产品协议失败");
+        }
+
+        String organCode = "91440300326364429H";
+
+        SysUserTsign organTsign = sysUserTsignService.queryByCardNo(organCode);
+        if (organTsign == null) {
+            logger.error("甲方未创建签章");
+            return BaseController.failed("甲方未创建签章");
+        }
+
+        eSealPlugin.organSign(organTsign.getSealData(), srcPdfPath, srcPdfPath);
+        if (sysUserTsign != null && CertificateTypeEnum.IDENTITY.getCode().equals(user.getCertificateType())) {
+            eSealPlugin.userSign(sysUserTsign.getAccountId(), sysUserTsign.getSealData(), srcPdfPath, srcPdfPath);
+        }
+
+        // 上传到oss
+        String dateStrOss = dateFormatOss.format(date);
+        dateStrOss = "product/" + dateStrOss + "/" + DateUtil.getHour(date);
+        String pdfFilePath = storagePluginContext.uploadFile(KS3StoragePlugin.PLUGIN_NAME, dateStrOss, srcFile);
+
+        SysUserContracts sysUserContracts = new SysUserContracts();
+        sysUserContracts.setCreateTime(date);
+        sysUserContracts.setType(ContractType.PRODUCT);
+        sysUserContracts.setUrl(pdfFilePath);
+        sysUserContracts.setUserId(userId);
+        sysUserContracts.setVersion(2);
+
+        sysUserContractsService.insert(sysUserContracts);
+
+        FileUtils.deleteQuietly(srcFile);
+        return BaseController.succeed();
+    }
+
+    @Override
+    public String transferOaFinancial(OAFinancialDto financialDto) {
+        List<Integer> circulationUserIds = financialDto.getCirculationUsers().stream().map(CirculationUser::getUserId).collect(Collectors.toList());
+        List<Integer> executorIds = financialDto.getExecutors().stream().map(CirculationUser::getUserId).collect(Collectors.toList());
+        circulationUserIds.addAll(executorIds);
+        List<SysUser> users = employeeDao.getUsers(circulationUserIds);
+
+        Integer workOrderId = null;
+        List<SysUserTsign> sysUserTsigns = new ArrayList<>();
+        for (SysUser user : users) {
+            for (CirculationUser circulationUser : financialDto.getCirculationUsers()) {
+                if (workOrderId == null) {
+                    workOrderId = circulationUser.getWorkOrder();
+                }
+                if (!circulationUser.getUserId().equals(user.getId())) continue;
+                circulationUser.setRealName(user.getRealName());
+            }
+            for (CirculationUser executor : financialDto.getExecutors()) {
+                if (!executor.getUserId().equals(user.getId())) continue;
+                executor.setRealName(user.getRealName());
+            }
+            SysUserTsign sysUserTsign = sysUserTsignService.get(user.getId());
+            if (sysUserTsign == null) {
+                try {
+                    sysUserTsign = register(user.getId(), user.getRealName(), user.getIdCardNo(), user.getPhone());
+                } catch (Exception e) {
+                    logger.error("用户电子签章注册失败", e);
+                    continue;
+                }
+            }
+            sysUserTsigns.add(sysUserTsign);
+        }
+
+        Date date = new Date();
+
+        // 合成freemarker
+        String srcPdfPath = contractBaseDir + "/oa/" + dateFormat1.format(date) + "/" + workOrderId + "_" + LocalDateTime.now().getSecond() + ".pdf";
+
+        File srcFile = new File(srcPdfPath);
+
+        File debtFile = new File(srcFile.getParent());
+        if (!debtFile.exists()) {
+            debtFile.mkdirs();
+        }
+
+        FreemarkerTemplateEngine templateEngine = FreemarkerTemplateEngine.getInstance();
+        templateEngine.setClassForTemplateLoading(ContractServiceImpl.class, "/config/contracts/");
+
+        Map<String, Object> params = new HashMap<String, Object>();
+
+        // 查询参数信息
+        params.put("organName", financialDto.getOrganName());
+        params.put("realName", financialDto.getRealName());
+        params.put("feeType", financialDto.getFeeType());
+        params.put("totalMoney", financialDto.getTotalMoney().setScale(2, RoundingMode.HALF_UP));
+        params.put("hasLoan", financialDto.getHasLoan());
+        params.put("memo", financialDto.getMemo());
+        params.put("circulationUsers", financialDto.getCirculationUsers());
+        params.put("executors", financialDto.getExecutors());
+
+        templateEngine.render(params, "financial.ftl", srcFile);
+
+        // 生成借款协议PDF
+        try {
+            PDFUtil.renderToPDFByData(ContractServiceImpl.class.getResource("/").getFile(), FileUtils.readFileToString(srcFile), srcPdfPath, "simsun.ttc");
+        } catch (IOException e) {
+            logger.error("生成签章协议失败", e);
+        }
+
+        for (SysUserTsign sysUserTsign : sysUserTsigns) {
+            eSealPlugin.userSign(sysUserTsign.getAccountId(), sysUserTsign.getSealData(), sysUserTsign.getUserId().toString(), srcPdfPath, srcPdfPath);
+        }
+
+        //上传到oss
+        String dateStrOss = dateFormatOss.format(date);
+        dateStrOss = "oa/" + dateStrOss + "/" + DateUtil.getHour(date);
+        String pdfFilePath = storagePluginContext.uploadFile(KS3StoragePlugin.PLUGIN_NAME, dateStrOss, srcFile);
+
+        FileUtils.deleteQuietly(srcFile);
+
+        return pdfFilePath;
+    }
 }

+ 37 - 18
mec-biz/src/main/java/com/ym/mec/biz/service/impl/EmployeeServiceImpl.java

@@ -1,36 +1,24 @@
 package com.ym.mec.biz.service.impl;
 
-import java.util.*;
-import java.util.stream.Collectors;
-
-import com.alibaba.fastjson.JSON;
-import com.ym.mec.biz.dal.dao.*;
-import com.ym.mec.biz.dal.entity.Organization;
-import com.ym.mec.biz.dal.enums.GroupType;
-import com.ym.mec.biz.service.ImUserFriendService;
-import com.ym.mec.biz.service.OaUserService;
-import com.ym.mec.im.entity.GroupMember;
-import com.ym.mec.im.entity.GroupModel;
-import com.ym.mec.oa.entity.OAUser;
-import org.apache.commons.lang3.StringUtils;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
-import org.springframework.stereotype.Service;
-import org.springframework.transaction.annotation.Transactional;
-
 import com.ym.mec.auth.api.client.SysUserFeignService;
+import com.ym.mec.auth.api.entity.SysRole;
 import com.ym.mec.auth.api.entity.SysUser;
 import com.ym.mec.auth.api.enums.YesOrNoEnum;
+import com.ym.mec.biz.dal.dao.*;
 import com.ym.mec.biz.dal.dto.EmployeeDto;
 import com.ym.mec.biz.dal.dto.EmployeeLevelDto;
 import com.ym.mec.biz.dal.dto.SimpleUserDto;
 import com.ym.mec.biz.dal.entity.Employee;
+import com.ym.mec.biz.dal.entity.Organization;
 import com.ym.mec.biz.dal.entity.SysUserCashAccount;
 import com.ym.mec.biz.dal.enums.EmployeeOperateEnum;
+import com.ym.mec.biz.dal.enums.GroupType;
 import com.ym.mec.biz.dal.enums.ParamEnum;
 import com.ym.mec.biz.dal.page.EmployeeQueryInfo;
 import com.ym.mec.biz.service.EmployeeService;
 import com.ym.mec.biz.service.ImGroupMemberService;
+import com.ym.mec.biz.service.ImUserFriendService;
+import com.ym.mec.biz.service.OaUserService;
 import com.ym.mec.common.dal.BaseDAO;
 import com.ym.mec.common.entity.ImGroupModel;
 import com.ym.mec.common.entity.ImResult;
@@ -39,9 +27,19 @@ import com.ym.mec.common.exception.BizException;
 import com.ym.mec.common.page.PageInfo;
 import com.ym.mec.common.service.impl.BaseServiceImpl;
 import com.ym.mec.im.ImFeignService;
+import com.ym.mec.im.entity.GroupMember;
+import com.ym.mec.im.entity.GroupModel;
 import com.ym.mec.util.collection.MapUtil;
+import org.apache.commons.lang3.StringUtils;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
+import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
 import org.springframework.util.CollectionUtils;
 
+import java.util.*;
+import java.util.stream.Collectors;
+
 @Service
 public class EmployeeServiceImpl extends BaseServiceImpl<Integer, Employee>  implements EmployeeService {
 
@@ -405,4 +403,25 @@ public class EmployeeServiceImpl extends BaseServiceImpl<Integer, Employee>  imp
 	public List<Integer> queryUserRole(Integer sysUserId) {
 		return employeeDao.queryUserRole(sysUserId);
 	}
+
+    /**
+     * 批量添加角色和菜单关系
+     *
+     * @param roleId  角色id
+     * @param menuIds 菜单集合
+     */
+    @Override
+    public int batchInsertRoleMenu(Integer roleId, List<Integer> menuIds) {
+        return employeeDao.batchInsertRoleMenu(roleId, menuIds);
+    }
+
+    /**
+     * 添加角色信息
+     *
+     * @param sysRole
+     */
+    @Override
+    public int insertSysRole(SysRole sysRole) {
+        return employeeDao.insertSysRole(sysRole);
+    }
 }

+ 13 - 2
mec-biz/src/main/java/com/ym/mec/biz/service/impl/PlatformProductServiceImpl.java

@@ -16,6 +16,7 @@ import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
 import java.util.Date;
+import java.util.List;
 import java.util.Optional;
 
 /**
@@ -51,7 +52,7 @@ public class PlatformProductServiceImpl extends ServiceImpl<PlatformProductDao,
      */
     @Override
     public void updateProduct(PlatformProductDto obj) {
-        Optional.ofNullable(obj.getId()).orElseThrow(()-> new BizException("产品Id不能为空"));
+        Optional.ofNullable(obj.getId()).orElseThrow(() -> new BizException("产品Id不能为空"));
         Integer userId = Optional.ofNullable(sysUserFeignService.queryUserInfo())
                 .map(SysUser::getId)
                 .orElseThrow(() -> new BizException("用户信息获取失败"));
@@ -67,11 +68,12 @@ public class PlatformProductServiceImpl extends ServiceImpl<PlatformProductDao,
 
     /**
      * 删除
+     *
      * @param id 产品id
      */
     @Override
     public void deleteProduct(Integer id) {
-        Optional.ofNullable(id).orElseThrow(()-> new BizException("产品Id不能为空"));
+        Optional.ofNullable(id).orElseThrow(() -> new BizException("产品Id不能为空"));
         Integer userId = Optional.ofNullable(sysUserFeignService.queryUserInfo())
                 .map(SysUser::getId)
                 .orElseThrow(() -> new BizException("用户信息获取失败"));
@@ -98,5 +100,14 @@ public class PlatformProductServiceImpl extends ServiceImpl<PlatformProductDao,
         return PageUtil.pageInfo(productIPage);
     }
 
+    /**
+     * 根据serveId查询对应的菜单id集合
+     *
+     * @param serveId
+     */
+    @Override
+    public List<String> queryMenuIdList(Integer serveId) {
+        return baseMapper.queryMenuIdList(serveId);
+    }
 
 }

+ 144 - 16
mec-biz/src/main/java/com/ym/mec/biz/service/impl/TenantInfoServiceImpl.java

@@ -3,29 +3,34 @@ package com.ym.mec.biz.service.impl;
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import com.google.common.collect.Lists;
 import com.ym.mec.auth.api.client.SysUserFeignService;
+import com.ym.mec.auth.api.entity.SysRole;
 import com.ym.mec.auth.api.entity.SysUser;
 import com.ym.mec.biz.dal.dao.TenantInfoDao;
 import com.ym.mec.biz.dal.dto.TenantConfigDto;
 import com.ym.mec.biz.dal.dto.TenantInfoDto;
 import com.ym.mec.biz.dal.dto.TenantProductInfoDto;
-import com.ym.mec.biz.dal.entity.TenantConfig;
-import com.ym.mec.biz.dal.entity.TenantInfo;
-import com.ym.mec.biz.dal.entity.TenantProductInfo;
+import com.ym.mec.biz.dal.entity.*;
+import com.ym.mec.biz.dal.enums.JobNatureEnum;
 import com.ym.mec.biz.dal.vo.TenantInfoInfoPageVo;
-import com.ym.mec.biz.service.TenantConfigService;
-import com.ym.mec.biz.service.TenantInfoService;
-import com.ym.mec.biz.service.TenantProductInfoService;
+import com.ym.mec.biz.service.*;
 import com.ym.mec.common.exception.BizException;
 import com.ym.mec.common.page.PageInfo;
 import com.ym.mec.common.page.PageUtil;
+import org.apache.commons.collections.CollectionUtils;
+import org.joda.time.LocalDate;
+import org.redisson.api.RBucket;
+import org.redisson.api.RedissonClient;
 import org.springframework.beans.BeanUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
 
 import java.util.*;
+import java.util.concurrent.TimeUnit;
 import java.util.function.Consumer;
+import java.util.stream.Collectors;
 
 @Service
 public class TenantInfoServiceImpl extends ServiceImpl<TenantInfoDao, TenantInfo> implements TenantInfoService {
@@ -33,9 +38,17 @@ public class TenantInfoServiceImpl extends ServiceImpl<TenantInfoDao, TenantInfo
     @Autowired
     private SysUserFeignService sysUserFeignService;
     @Autowired
+    private EmployeeService employeeService;
+    @Autowired
     private TenantProductInfoService tenantProductInfoService;
     @Autowired
+    private PlatformProductService platformProductService;
+    @Autowired
     private TenantConfigService tenantConfigService;
+    @Autowired
+    private RedissonClient redissonClient;
+    @Autowired
+    private SysUserTsignService sysUserTsignService;
 
     /**
      * 新增机构
@@ -45,11 +58,11 @@ public class TenantInfoServiceImpl extends ServiceImpl<TenantInfoDao, TenantInfo
     public void addTenantInfo(TenantInfoDto dto) {
         //校验手机号是否唯一
         checkPhone(dto);
+        //校验营业执照信息
+        checkTsign(dto.getTsignCode());
 
         //添加机构基本信息
-        Integer userId = Optional.ofNullable(sysUserFeignService.queryUserInfo())
-                .map(SysUser::getId)
-                .orElseThrow(() -> new BizException("用户信息获取失败"));
+        Integer userId = getUserId();
         TenantInfo tenantInfo = new TenantInfo();
         BeanUtils.copyProperties(dto, tenantInfo);
         tenantInfo.setPayState(0);
@@ -96,18 +109,16 @@ public class TenantInfoServiceImpl extends ServiceImpl<TenantInfoDao, TenantInfo
 
         //机构状态 0未缴费
         if (0 == tenantInfo.getPayState()) {
+            //校验营业执照信息
+            checkTsign(dto.getTsignCode());
             //修改产品
             setIdByApply(tenantId, dto.getProductInfo(), dto.getProductInfo()::setTenantId,
                     tenantProductInfoService::updateTenantProduct);
         }
 
-        //修改机构基础信息
-        Integer userId = Optional.ofNullable(sysUserFeignService.queryUserInfo())
-                .map(SysUser::getId)
-                .orElseThrow(() -> new BizException("用户信息获取失败"));
         Date now = new Date();
         BeanUtils.copyProperties(dto, tenantInfo);
-        tenantInfo.setUpdatedBy(userId);
+        tenantInfo.setUpdatedBy(getUserId());
         tenantInfo.setUpdatedTime(now);
         this.updateById(tenantInfo);
 
@@ -141,6 +152,7 @@ public class TenantInfoServiceImpl extends ServiceImpl<TenantInfoDao, TenantInfo
 
     /**
      * 启用/停用
+     * 第一个启用默认激活账号等信息
      *
      * @param id    机构id
      * @param state 机构状态 0草稿 1启动 2停用
@@ -150,11 +162,104 @@ public class TenantInfoServiceImpl extends ServiceImpl<TenantInfoDao, TenantInfo
     public void opsTenantState(Integer id, Integer state) {
         if (Objects.nonNull(state)) {
             if (state == 1 || state == 2) {
-                baseMapper.opsTenantState(id, state);
+                TenantInfo tenantInfo = baseMapper.selectById(id);
+                if (Objects.isNull(tenantInfo)) {
+                    throw new BizException("该机构数据异常! ID : [" + id + "]");
+                }
+                Integer userId = getUserId();
+                tenantInfo.setUpdatedBy(userId);
+                tenantInfo.setUpdatedTime(new Date());
+                tenantInfo.setState(state);
+                //状态= 开通并且已支付完成
+                if (state == 1) {
+                    if (tenantInfo.getPayState() == 1) {
+                        //判断是否初次启用
+                        firstOpen(tenantInfo);
+                    } else {
+                        throw new BizException("机构未缴费无法开通!");
+                    }
+                }
+                baseMapper.updateById(tenantInfo);
                 return;
             }
         }
-        throw new BizException("机构状态参数异常!");
+        throw new BizException("传入机构状态参数异常!");
+    }
+
+    /**
+     * 第一次开通服务
+     *
+     * @param tenantInfo 机构信息
+     */
+    private void firstOpen(TenantInfo tenantInfo) {
+        Integer tenantId = tenantInfo.getId();
+        SysUser user = sysUserFeignService.queryUserByMobile(tenantInfo.getPhone());
+        if (Objects.nonNull(user)) {
+            return;
+        }
+        //防止重复点击 加锁
+        String key = "Tenant_First_Open:" + tenantId;
+        RBucket<Object> bucket = redissonClient.getBucket(key);
+        //原子操作 抢锁成功为true
+        if (!bucket.trySet(tenantId, 3L, TimeUnit.MINUTES)) {
+            throw new BizException("该机构数正在开通中请勿频繁操作");
+        }
+        //获取产品信息得到服务id
+        TenantProductInfo productInfo = tenantProductInfoService.getOne(new QueryWrapper<TenantProductInfo>()
+                .eq("tenant_id_", tenantId));
+        if (Objects.isNull(productInfo)) {
+            throw new BizException("开通账号信息异常!未查询到购买的产品信息!");
+        }
+        //根据服务id查询对应的菜单值(该值是多个id用逗号分割的)
+        List<String> menuIdList = platformProductService.queryMenuIdList(productInfo.getServeId());
+        if (CollectionUtils.isEmpty(menuIdList)) {
+            throw new BizException("开通账号信息异常!未查询到购买的产品信息!!");
+        }
+        //拆分菜单获取菜单ID
+        List<Integer> collectMenuId = getMenuId(menuIdList);
+        //建立角色
+        Integer roleId = createRole(tenantId);
+        //建立角色和菜单关系数据
+        employeeService.batchInsertRoleMenu(roleId, collectMenuId);
+        // 创建账号、用户信息、用户和角色关系
+        createUser(tenantInfo, Lists.newArrayList(roleId));
+    }
+
+    //拆分菜单获取菜单ID
+    private List<Integer> getMenuId(List<String> menuIdList) {
+        return menuIdList.stream()
+                .map(ids -> ids.split(","))
+                .flatMap(Arrays::stream)
+                .distinct()
+                .map(Integer::parseInt)
+                .collect(Collectors.toList());
+    }
+
+    //创建角色
+    private Integer createRole(Integer tenantId) {
+        SysRole sysRole = new SysRole();
+        sysRole.setRoleName("管理员");
+        sysRole.setRoleDesc("管理员");
+        sysRole.setCreateTime(new Date());
+        sysRole.setDelFlag("0");
+        sysRole.setTenantId(tenantId);
+        employeeService.insertSysRole(sysRole);
+        return sysRole.getId();
+    }
+
+    //创建账号、用户信息、用户和角色关系
+    private void createUser(TenantInfo tenantInfo, List<Integer> roles) {
+        Employee e = new Employee();
+        e.setPhone(tenantInfo.getPhone());
+        e.setRealName(tenantInfo.getContacts());
+        e.setJobNature(JobNatureEnum.FULL_TIME);
+        e.setEntryDate(LocalDate.now().toDate());
+        e.setRoles(roles);
+        try {
+            employeeService.add(e);
+        } catch (Exception ex) {
+            throw new BizException("开通账号信息异常!");
+        }
     }
 
     /**
@@ -176,6 +281,14 @@ public class TenantInfoServiceImpl extends ServiceImpl<TenantInfoDao, TenantInfo
     }
 
     /**
+     * 机构缴费
+     */
+    public void pay(){
+
+    }
+
+
+    /**
      * 校验手机号
      */
     private void checkPhone(TenantInfoDto dto) {
@@ -216,4 +329,19 @@ public class TenantInfoServiceImpl extends ServiceImpl<TenantInfoDao, TenantInfo
         }
     }
 
+    private Integer getUserId() {
+        //修改机构基础信息
+        return Optional.ofNullable(sysUserFeignService.queryUserInfo())
+                .map(SysUser::getId)
+                .orElseThrow(() -> new BizException("用户信息获取失败,请刷新页面或者重新登录!"));
+    }
+
+    private void checkTsign(String code) {
+        //校验营业信息
+        SysUserTsign sysUserTsign = sysUserTsignService.queryByCardNo(code);
+        if (Objects.nonNull(sysUserTsign)) {
+            throw new BizException("营业执照编号已被注册!");
+        }
+    }
+
 }

+ 23 - 0
mec-biz/src/main/java/com/ym/mec/biz/service/impl/TenantOrderRecordServiceImpl.java

@@ -1,9 +1,16 @@
 package com.ym.mec.biz.service.impl;
 
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import com.ym.mec.biz.dal.dao.TenantOrderRecordDao;
+import com.ym.mec.biz.dal.dto.TenantOrderRecordDto;
 import com.ym.mec.biz.dal.entity.TenantOrderRecord;
 import com.ym.mec.biz.service.TenantOrderRecordService;
+import com.ym.mec.common.page.PageInfo;
+import com.ym.mec.common.page.PageUtil;
+import com.ym.mec.common.page.QueryWrapperUtil;
+import org.apache.commons.lang3.StringUtils;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.stereotype.Service;
@@ -18,5 +25,21 @@ import org.springframework.stereotype.Service;
 public class TenantOrderRecordServiceImpl extends ServiceImpl<TenantOrderRecordDao, TenantOrderRecord> implements TenantOrderRecordService {
 
     private final static Logger logger = LoggerFactory.getLogger(TenantOrderRecordServiceImpl.class);
+
+    @Override
+    public PageInfo<TenantOrderRecord> queryPage(TenantOrderRecordDto dto) {
+        Page<TenantOrderRecord> pageInfo = PageUtil.getPage(dto.getPage(), dto.getRows());
+        QueryWrapper<TenantOrderRecord> queryWrapper = new QueryWrapperUtil<TenantOrderRecord>()
+                .hasEq("order_no_", dto.getOrderNo())
+                .hasEq("tenant_id_", dto.getTenantId())
+                .hasEq("trans_no_", dto.getTransNo())
+                .hasEq("order_type_", dto.getOrderType())
+                .hasEq("order_state_", dto.getOrderState())
+                .queryWrapper()
+                .ge(StringUtils.isNotBlank(dto.getStartDate()), "created_time_", dto.getStartDate())
+                .le(StringUtils.isNotBlank(dto.getEndDate()), "created_time_", dto.getEndDate());
+        return PageUtil.pageInfo(this.page(pageInfo, queryWrapper));
+    }
+
 }
 

+ 16 - 0
mec-biz/src/main/resources/config/mybatis/EmployeeMapper.xml

@@ -80,6 +80,7 @@
         VALUES(#{userId},#{organIdList},#{jobNature},#{isProbationPeriod},#{educationBackground},#{graduateSchool},
         #{technicalTitles},#{entryDate},#{certificateType},#{certificateNum},now(),now(),#{introduction},#{demissionDate},#{contactAddress},#{postalCode},#{deptId},#{deptIds},#{postIds},#{postDeptIds})
     </insert>
+
     <insert id="batchAddEmployeeRole">
         INSERT INTO sys_user_role(user_id_,role_id_) values
         <foreach collection="roleIds" item="item" index="index" separator=",">
@@ -87,6 +88,21 @@
         </foreach>
     </insert>
 
+    <insert id="batchInsertRoleMenu">
+        INSERT INTO sys_role_menu (role_id_,menu_id_) VALUES
+        <foreach collection="menuIds" item="item" index="index" separator=",">
+            (#{roleId}, #{item})
+        </foreach>
+    </insert>
+
+    <insert id="insertSysRole" keyColumn="id_" keyProperty="id" parameterType="com.ym.mec.auth.api.entity.SysRole"
+            useGeneratedKeys="true">
+        INSERT INTO `sys_role` (`role_name_`, `role_code_`, `role_desc_`, `create_time_`,
+                                `update_time_`, `del_flag_`, `organ_id_`, `tenant_id_`)
+        VALUES (#{RoleName}, #{RoleCode}, #{RoleDesc}, #{CreateTime},
+                #{UpdateTime}, #{DelFlag}, #{OrganId}, #{TenantId});
+    </insert>
+
     <select id="queryByPhone" resultMap="SysUser">
 		select * from sys_user where phone_ = #{phone} OR username_ = #{phone}
 	</select>

+ 13 - 0
mec-biz/src/main/resources/config/mybatis/PlatformProductMapper.xml

@@ -137,4 +137,17 @@
             </if>
         </where>
     </select>
+    
+    <select id="queryMenuIdList" parameterType="integer" resultType="string">
+        SELECT
+            b.`menu_id_`
+        FROM
+            `platform_serve` AS a
+                JOIN `platform_product` AS b
+                     ON FIND_IN_SET(b.`id_`, a.`product_id_`)
+        WHERE
+            a.deleted_ = 0 AND b.deleted_ = 0
+          AND a.`id_` = #{serveId}
+    </select>
+    
 </mapper>

+ 7 - 4
mec-biz/src/main/resources/config/mybatis/TenantConfigMapper.xml

@@ -6,6 +6,8 @@
         <result column="tenant_id_" jdbcType="INTEGER" property="tenantId"/>
         <result column="charge_rate_" jdbcType="VARCHAR" property="chargeRate"/>
         <result column="teaching_material_id_" jdbcType="VARCHAR" property="teachingMaterialId"/>
+        <result column="theme_" jdbcType="VARCHAR" property="theme"/>
+        <result column="theme_color_" jdbcType="VARCHAR" property="themeColor"/>
         <result column="config_" jdbcType="VARCHAR" property="config"/>
         <result column="updated_by_" jdbcType="INTEGER" property="updatedBy"/>
         <result column="updated_time_" jdbcType="TIMESTAMP" property="updatedTime"/>
@@ -13,16 +15,17 @@
 
     <sql id="Base_Column_List">
         id_
-        , tenant_id_, charge_rate_, teaching_material_id_, config_, updated_by_, updated_time_
+        , tenant_id_, charge_rate_, teaching_material_id_, theme_, theme_color_, config_, updated_by_, updated_time_
     </sql>
 
     <insert id="insertBatch" keyColumn="id_" keyProperty="id" useGeneratedKeys="true"
             parameterType="com.ym.mec.biz.dal.entity.TenantConfig">
-        insert into tenant_config(tenant_id_, charge_rate_, teaching_material_id_, config_, updated_by_, updated_time_)
+        insert into tenant_config(tenant_id_, charge_rate_, teaching_material_id_, theme_, theme_color_, config_,
+        updated_by_, updated_time_)
         values
         <foreach collection="entities" item="entity" separator=",">
-            (#{entity.tenantId}, #{entity.chargeRate}, #{entity.teachingMaterialId}, #{entity.config},
-            #{entity.updatedBy}, #{entity.updatedTime})
+            (#{entity.tenantId}, #{entity.chargeRate}, #{entity.teachingMaterialId}, #{entity.theme},
+            #{entity.themeColor}, #{entity.config}, #{entity.updatedBy}, #{entity.updatedTime})
         </foreach>
     </insert>
 

+ 0 - 6
mec-biz/src/main/resources/config/mybatis/TenantInfoMapper.xml

@@ -29,12 +29,6 @@
         , name_, contacts_, phone_, address_, email_, logo_, customer_service_phone_, remark_, domain_name_, data_source_, pay_state_, state_, created_by_, created_time_, updated_by_, updated_time_, tsign_code_, tsign_name_
     </sql>
 
-    <update id="opsTenantState" parameterType="object">
-        update tenant_info
-        set state_ = #{state}
-        where id_ = #{id}
-    </update>
-
     <resultMap id="TenantInfoInfoResult" type="com.ym.mec.biz.dal.vo.TenantInfoInfoPageVo">
         <!--  机构基础信息-->
         <id column="id_" jdbcType="INTEGER" property="id"/>

+ 1 - 1
mec-common/common-core/src/main/java/com/ym/mec/common/page/PageUtil.java

@@ -22,7 +22,7 @@ public class PageUtil {
     public static <T> Page<T> getPage(Integer page, Integer rows) {
         Integer pageIndex = Optional.ofNullable(page).orElse(1);
         Integer pageSize = Optional.ofNullable(rows).orElse(20);
-        return new Page<T>(pageIndex, pageSize);
+        return new Page<>(pageIndex, pageSize);
     }
 
     /**

+ 50 - 0
mec-common/common-core/src/main/java/com/ym/mec/common/page/QueryWrapperUtil.java

@@ -0,0 +1,50 @@
+package com.ym.mec.common.page;
+
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
+import org.apache.commons.lang3.StringUtils;
+
+import java.math.BigDecimal;
+import java.util.Objects;
+import java.util.function.Predicate;
+
+/**
+ * @author hgw
+ * Created by 2021-12-20
+ */
+public class QueryWrapperUtil<T> {
+
+    private final QueryWrapper<T> queryWrapper;
+
+    private final Predicate<? super Object> predicate = (Predicate<Object>) Objects::nonNull;
+
+    public QueryWrapperUtil() {
+        this.queryWrapper = new QueryWrapper<>();
+    }
+
+    /**
+     * 值如果不为空则添加到查询条件中
+     * 仅支持简单的类型
+     *
+     * @param column 列名称
+     * @param val    值
+     */
+    public QueryWrapperUtil<T> hasEq(String column, String val) {
+        Predicate<? super Object> predicate = (Predicate<Object>) o -> StringUtils.isNotBlank((String) o);
+        queryWrapper.eq(predicate.test(val), column, val);
+        return this;
+    }
+
+    public QueryWrapperUtil<T> hasEq(String column, Object val) {
+        queryWrapper.eq(predicate.test(val), column, val);
+        return this;
+    }
+
+    /**
+     * 可以当作结束语句
+     * 或者获取QueryWrapper类还可以继续拼接其他条件SQL
+     */
+    public QueryWrapper<T> queryWrapper() {
+        return queryWrapper;
+    }
+
+}

+ 4 - 4
mec-web/src/main/java/com/ym/mec/web/controller/TenantInfoController.java

@@ -33,7 +33,7 @@ public class TenantInfoController extends BaseController {
 
     @ApiOperation("修改机构信息")
     @PostMapping(value = "/update")
-    @PreAuthorize("@pcs.hasPermissions('tenantInfo/update')")
+//    @PreAuthorize("@pcs.hasPermissions('tenantInfo/update')")
     public Object updateTenantInfo(@Valid @RequestBody TenantInfoDto dto) {
         tenantInfoService.updateTenantInfo(dto);
         return succeed();
@@ -41,7 +41,7 @@ public class TenantInfoController extends BaseController {
 
     @ApiOperation("修改机构启用停用状态")
     @GetMapping(value = "/opsState/{id}")
-    @PreAuthorize("@pcs.hasPermissions('tenantInfo/opsState')")
+//    @PreAuthorize("@pcs.hasPermissions('tenantInfo/opsState')")
     public Object opsState(@ApiParam(value = "机构ID", required = true) @PathVariable("id") Integer id, Integer state) {
         tenantInfoService.opsTenantState(id, state);
         return succeed();
@@ -49,7 +49,7 @@ public class TenantInfoController extends BaseController {
 
     @ApiOperation("查询单个机构详情")
     @GetMapping(value = "/info/{id}")
-    @PreAuthorize("@pcs.hasPermissions('tenantInfo/info')")
+//    @PreAuthorize("@pcs.hasPermissions('tenantInfo/info')")
     public Object queryTenantInfo(@ApiParam(value = "机构ID", required = true) @PathVariable("id") Integer id) {
         return succeed(tenantInfoService.queryTenantInfo(id));
     }
@@ -67,7 +67,7 @@ public class TenantInfoController extends BaseController {
     })
     @ApiOperation("分页查询")
     @PostMapping(value = "/queryPage")
-    @PreAuthorize("@pcs.hasPermissions('tenantInfo/queryPage')")
+//    @PreAuthorize("@pcs.hasPermissions('tenantInfo/queryPage')")
     public Object queryPage(@RequestBody Map<String, Object> param) {
         return succeed(tenantInfoService.queryPage(param));
     }

+ 11 - 0
mec-web/src/main/java/com/ym/mec/web/controller/TenantOrderRecordController.java

@@ -1,8 +1,13 @@
 package com.ym.mec.web.controller;
 
 
+import com.ym.mec.biz.dal.dto.TenantOrderRecordDto;
+import com.ym.mec.biz.dal.entity.TenantOrderRecord;
 import com.ym.mec.biz.service.TenantOrderRecordService;
 import com.ym.mec.common.controller.BaseController;
+import io.swagger.annotations.ApiOperation;
+import org.springframework.web.bind.annotation.PostMapping;
+import org.springframework.web.bind.annotation.RequestBody;
 import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RestController;
 
@@ -23,5 +28,11 @@ public class TenantOrderRecordController extends BaseController {
     @Resource
     private TenantOrderRecordService tenantOrderRecordService;
 
+    @ApiOperation("分页查询")
+    @PostMapping(value = "/queryPage")
+    public Object queryPage(@RequestBody TenantOrderRecordDto dto) {
+        return tenantOrderRecordService.queryPage(dto);
+    }
+
 }