Просмотр исходного кода

bug修改,教师梯度奖励,定时任务更改

zouxuan 5 лет назад
Родитель
Сommit
f9ecc98ae4

+ 17 - 0
mec-biz/src/main/java/com/ym/mec/biz/dal/dao/CourseScheduleRewardsRulesDao.java

@@ -1,8 +1,10 @@
 package com.ym.mec.biz.dal.dao;
 
+import java.util.Date;
 import java.util.List;
 import java.util.Map;
 
+import com.ym.mec.biz.dal.dto.TaskRewardsRulesDto;
 import org.apache.ibatis.annotations.Param;
 
 import com.ym.mec.biz.dal.entity.CourseSchedule.CourseScheduleType;
@@ -60,4 +62,19 @@ public interface CourseScheduleRewardsRulesDao extends BaseDAO<Integer, CourseSc
 	 * @return
 	 */
 	List<Map<Integer, String>> findVipCategoryNames(@Param("rewardsIds") List<Integer> rewardsIds);
+
+	/**
+	 * 获取教师时间段内已结算课时(课时阶梯奖励)
+	 * @param firstDayOfMonth
+	 * @param lastDayOfMonth
+	 * @return
+	 */
+    List<TaskRewardsRulesDto> queryVipGroupTeachereClassTimesByMonth(@Param("firstDayOfMonth") String firstDayOfMonth, @Param("lastDayOfMonth") String lastDayOfMonth);
+
+	/**
+	 * 根据主键列表获取数据
+	 * @param activeIds
+	 * @return
+	 */
+	List<CourseScheduleRewardsRules> findByIds(List<Integer> activeIds);
 }

+ 7 - 0
mec-biz/src/main/java/com/ym/mec/biz/dal/dao/SysUserCashAccountDetailDao.java

@@ -22,4 +22,11 @@ public interface SysUserCashAccountDetailDao extends BaseDAO<Long, SysUserCashAc
     int batchInsert(@Param("sysUserCashAccountDetails") List<SysUserCashAccountDetail> sysUserCashAccountDetails);
 
     Map<String, Object> queryStatistics(@Param("organId") String organId);
+
+    /**
+     * 查看当前月是否执行过教师奖励
+     * @param currentMonth
+     * @return
+     */
+    Integer countByTypeAndTime(String currentMonth);
 }

+ 58 - 0
mec-biz/src/main/java/com/ym/mec/biz/dal/dto/RewardsRulesJsonDto.java

@@ -0,0 +1,58 @@
+package com.ym.mec.biz.dal.dto;
+
+import java.math.BigDecimal;
+
+/**
+ * 班级老师
+ */
+public class RewardsRulesJsonDto{
+	private Integer min;
+
+	private Integer max;
+
+	private BigDecimal money;
+
+	private boolean disabled;
+
+	private String key;
+
+	public Integer getMin() {
+		return min;
+	}
+
+	public void setMin(Integer min) {
+		this.min = min;
+	}
+
+	public Integer getMax() {
+		return max;
+	}
+
+	public void setMax(Integer max) {
+		this.max = max;
+	}
+
+	public BigDecimal getMoney() {
+		return money;
+	}
+
+	public void setMoney(BigDecimal money) {
+		this.money = money;
+	}
+
+	public boolean isDisabled() {
+		return disabled;
+	}
+
+	public void setDisabled(boolean disabled) {
+		this.disabled = disabled;
+	}
+
+	public String getKey() {
+		return key;
+	}
+
+	public void setKey(String key) {
+		this.key = key;
+	}
+}

+ 39 - 0
mec-biz/src/main/java/com/ym/mec/biz/dal/dto/TaskRewardsRulesDto.java

@@ -0,0 +1,39 @@
+package com.ym.mec.biz.dal.dto;
+
+import io.swagger.annotations.ApiModelProperty;
+
+public class TaskRewardsRulesDto{
+
+    @ApiModelProperty(value = "已上课时数",required = false)
+    private Integer times;
+
+    @ApiModelProperty(value = "教师编号",required = false)
+    private Integer teacherId;
+
+    @ApiModelProperty(value = "活动编号",required = false)
+    private Integer activeId;
+
+    public Integer getTimes() {
+        return times;
+    }
+
+    public void setTimes(Integer times) {
+        this.times = times;
+    }
+
+    public Integer getTeacherId() {
+        return teacherId;
+    }
+
+    public void setTeacherId(Integer teacherId) {
+        this.teacherId = teacherId;
+    }
+
+    public Integer getActiveId() {
+        return activeId;
+    }
+
+    public void setActiveId(Integer activeId) {
+        this.activeId = activeId;
+    }
+}

+ 20 - 4
mec-biz/src/main/java/com/ym/mec/biz/service/CourseScheduleRewardsRulesService.java

@@ -1,15 +1,16 @@
 package com.ym.mec.biz.service;
 
-import java.math.BigDecimal;
-import java.util.List;
-
+import com.ym.mec.biz.dal.dto.TaskRewardsRulesDto;
 import com.ym.mec.biz.dal.entity.CourseSchedule.CourseScheduleType;
 import com.ym.mec.biz.dal.entity.CourseScheduleRewardsRules;
 import com.ym.mec.biz.dal.page.RewardsRulesQueryInfo;
 import com.ym.mec.common.page.PageInfo;
-import com.ym.mec.common.page.QueryInfo;
 import com.ym.mec.common.service.BaseService;
 
+import java.math.BigDecimal;
+import java.util.Date;
+import java.util.List;
+
 public interface CourseScheduleRewardsRulesService extends BaseService<Integer, CourseScheduleRewardsRules> {
 
 	/**
@@ -47,4 +48,19 @@ public interface CourseScheduleRewardsRulesService extends BaseService<Integer,
 	 * @return
 	 */
 	int updateDetail(CourseScheduleRewardsRules courseScheduleRewardsRules);
+
+	/**
+	 * 获取教师时间段内已结算课时(课时阶梯奖励)
+	 * @param firstDayOfMonth
+	 * @param lastDayOfMonth
+	 * @return
+	 */
+    List<TaskRewardsRulesDto> queryVipGroupTeachereClassTimesByMonth(String firstDayOfMonth,String lastDayOfMonth);
+
+	/**
+	 * 根据主键列表获取数据
+	 * @param activeIds
+	 * @return
+	 */
+	List<CourseScheduleRewardsRules> findByIds(List<Integer> activeIds);
 }

+ 11 - 0
mec-biz/src/main/java/com/ym/mec/biz/service/impl/CourseScheduleRewardsRulesServiceImpl.java

@@ -4,6 +4,7 @@ import java.math.BigDecimal;
 import java.util.*;
 import java.util.stream.Collectors;
 
+import com.ym.mec.biz.dal.dto.TaskRewardsRulesDto;
 import com.ym.mec.biz.dal.page.RewardsRulesQueryInfo;
 import com.ym.mec.common.exception.BizException;
 import org.apache.commons.lang3.StringUtils;
@@ -203,6 +204,16 @@ public class CourseScheduleRewardsRulesServiceImpl extends BaseServiceImpl<Integ
 		return courseScheduleRewardsRules.getId();
 	}
 
+	@Override
+	public List<TaskRewardsRulesDto> queryVipGroupTeachereClassTimesByMonth(String firstDayOfMonth, String lastDayOfMonth) {
+		return courseScheduleRewardsDao.queryVipGroupTeachereClassTimesByMonth(firstDayOfMonth,lastDayOfMonth);
+	}
+
+	@Override
+	public List<CourseScheduleRewardsRules> findByIds(List<Integer> activeIds) {
+		return courseScheduleRewardsDao.findByIds(activeIds);
+	}
+
 	class RewardsRules implements Comparable<RewardsRules> {
 
 		private int min;

+ 4 - 4
mec-biz/src/main/java/com/ym/mec/biz/service/impl/StudentPaymentOrderDetailServiceImpl.java

@@ -70,14 +70,14 @@ public class StudentPaymentOrderDetailServiceImpl extends BaseServiceImpl<Long,
 			String[] goodSIdArr = goodsIdsStr.split(",");
 
 			List<Goods> goodies = goodsService.findGoodsByIds(goodsIdsStr);
-//            MusicGroup musicGroup = musicGroupDao.get(musicGroupId);
-//            Organization organization = organizationDao.get(musicGroup.getOrganId());
+            MusicGroup musicGroup = musicGroupDao.get(musicGroupId);
+            Organization organization = organizationDao.get(musicGroup.getOrganId());
             goodies.forEach(e->{
                 e.setSellCount(0);
                 //当作乐团名称字段处理
-//                e.setMemo(musicGroup.getName());
+                e.setMemo(musicGroup.getName());
                 //当作分部名称字段处理
-//                e.setBrief(organization.getName());
+                e.setBrief(organization.getName());
                 for (String goodsIdStr : goodSIdArr) {
                     if (e.getId().equals(Integer.parseInt(goodsIdStr))) {
                         e.setSellCount(e.getSellCount() + 1);

+ 1 - 5
mec-biz/src/main/java/com/ym/mec/biz/service/impl/TeacherServiceImpl.java

@@ -98,11 +98,7 @@ public class TeacherServiceImpl extends BaseServiceImpl<Integer, Teacher>  imple
 		//添加用户电子签章账户
 //		contractService.register(teacher.getId(), user.getRealName(), user.getIdCardNo(), user.getPhone());
 		teacherDao.insert(teacher);
-		if(StringUtils.isEmpty(teacher.getAvatar())){
-			SysConfig head_url = configDao.findByParamName("user_default_head_url");
-			teacher.setAvatar(head_url.getParanValue());
-		}
-		ImResult imResult = imFeignService.register(new ImUserModel(teacher.getId().toString(), teacher.getUsername(), teacher.getAvatar()));
+		ImResult imResult = imFeignService.register(new ImUserModel(teacher.getId().toString(), teacher.getUsername(), null));
 		if(imResult != null){
 			teacher.setImToken(imResult.getToken());
 			teacherDao.updateUser(teacher);

+ 44 - 20
mec-biz/src/main/java/com/ym/mec/biz/service/impl/VipGroupServiceImpl.java

@@ -1,6 +1,7 @@
 package com.ym.mec.biz.service.impl;
 
 import com.alibaba.fastjson.JSON;
+import com.alibaba.fastjson.JSONArray;
 import com.alibaba.fastjson.JSONObject;
 import com.ym.mec.auth.api.client.SysUserFeignService;
 import com.ym.mec.auth.api.entity.SysUser;
@@ -1562,30 +1563,53 @@ public class VipGroupServiceImpl extends BaseServiceImpl<Long, VipGroup> impleme
 	@Override
 	@Transactional(propagation = Propagation.REQUIRED, rollbackFor = Exception.class)
 	public boolean awardedMonthlyRewards() {
-		//获取
-		List<Map<Integer, Integer>> list = courseScheduleDao.queryVipGroupTeachereClassTimesByMonth(new Date(), CourseStatusEnum.OVER);
-
-		if (list != null && list.size() > 0) {
-
-			Integer organId = null, teacherId = null, coursesTimes = 0;
-			boolean isSupportCourseScheduleRewardsRules = false;
-
-			for (Map<Integer, Integer> map : list) {
-				organId = map.get("organ_id_");
-				teacherId = map.get("teacher_id_");
-				coursesTimes = map.get("times");
-				isSupportCourseScheduleRewardsRules = Boolean.parseBoolean(map.get("is_support_course_schedule_rewards_rules_").toString());
-
-				if (isSupportCourseScheduleRewardsRules) {
-					BigDecimal decimal = courseScheduleRewardsRulesService.queryRewardsAmount(organId, CourseScheduleType.VIP, coursesTimes);
-					if (decimal.doubleValue() > 0) {
-						sysUserCashAccountDetailService.addCashAccountDetail(teacherId, decimal, "", SysUserCashAccountDetailService.ORGAN,
+		//获取上个月的时间
+		Date months = DateUtil.addMonths(new Date(), -1);
+		String firstDayOfMonth = DateUtil.format(DateUtil.getFirstDayOfMonth(months),DateUtil.ISO_EXPANDED_DATE_FORMAT);
+		String lastDayOfMonth =  DateUtil.format(DateUtil.getLastDayOfMonth(months),DateUtil.ISO_EXPANDED_DATE_FORMAT);
+
+		List<TaskRewardsRulesDto> rewardsRulesDtos = courseScheduleRewardsRulesService.queryVipGroupTeachereClassTimesByMonth(firstDayOfMonth,lastDayOfMonth);
+		if(rewardsRulesDtos != null && rewardsRulesDtos.size() > 0){
+			List<Integer> activeIds = rewardsRulesDtos.stream().map(e -> e.getActiveId()).collect(Collectors.toList());
+			List<CourseScheduleRewardsRules> rewardsRules = courseScheduleRewardsRulesService.findByIds(activeIds);
+			Map<Integer, List<CourseScheduleRewardsRules>> integerListMap = rewardsRules.stream().collect(Collectors.groupingBy(CourseScheduleRewardsRules::getId));
+			rewardsRulesDtos.forEach(e->{
+				CourseScheduleRewardsRules rewardsRule = integerListMap.get(e.getActiveId()).get(0);
+				String rewardsRulesJson = rewardsRule.getRewardsRulesJson();
+				List<RewardsRulesJsonDto> rulesJsonDtos = JSONObject.parseArray(rewardsRulesJson, RewardsRulesJsonDto.class);
+				BigDecimal money = BigDecimal.ZERO;
+				//STAIR 阶梯, PER 累计, TOTAL
+				switch (rewardsRule.getRewardMode()){
+					case STAIR:
+						rulesJsonDtos.forEach(rule->{
+							if(e.getTimes() >= rule.getMin()){
+								money.add(rule.getMoney());
+							}
+						});
+						break;
+					case PER:
+						int count = 0;
+						for (RewardsRulesJsonDto rule:rulesJsonDtos) {
+							if(e.getTimes() >= rule.getMin()){
+								count++;
+								rule.getMoney().multiply(new BigDecimal(count));
+							}
+						}
+						break;
+					case TOTAL:
+						break;
+				}
+				if (money.doubleValue() > 0) {
+					//当前用户是否已经发放过上月奖励
+					String currentMonth = DateUtil.format(new Date(),DateUtil.ISO_YEAR_MONTH_FORMAT);
+					Integer num = sysUserCashAccountDetailDao.countByTypeAndTime(currentMonth);
+					if(num == null || num == 0){
+						sysUserCashAccountDetailService.addCashAccountDetail(e.getTeacherId(), money, "", SysUserCashAccountDetailService.ORGAN,
 								PlatformCashAccountDetailTypeEnum.REWARDS, null, DealStatusEnum.SUCCESS, "分部奖励");
 					}
 				}
-			}
+			});
 		}
-
 		return true;
 	}
 

+ 19 - 0
mec-biz/src/main/resources/config/mybatis/CourseScheduleRewardsMapper.xml

@@ -138,6 +138,25 @@
 		</foreach>
 		GROUP BY csrr.id_
 	</select>
+	<resultMap id="TaskRewardsRulesDtoMap" type="com.ym.mec.biz.dal.dto.TaskRewardsRulesDto">
+		<result property="teacherId" column="actual_teacher_id_"/>
+		<result property="times" column="times_"/>
+		<result property="activeId" column="active_id_"/>
+	</resultMap>
+    <select id="queryVipGroupTeachereClassTimesByMonth" resultMap="TaskRewardsRulesDtoMap">
+		SELECT COUNT(cs.id_) times_,cs.actual_teacher_id_,csrr.id_ active_id_ FROM course_schedule_rewards_rules csrr
+		LEFT JOIN vip_group vg ON FIND_IN_SET(vg.vip_group_category_id_,csrr.vip_group_category_id_list_)
+		LEFT JOIN course_schedule cs ON vg.id_ = cs.music_group_id_ AND FIND_IN_SET(cs.actual_teacher_id_,csrr.teacher_id_)
+		LEFT JOIN course_schedule_teacher_salary csts ON csts.course_schedule_id_ = cs.id_ AND csts.user_id_ = cs.actual_teacher_id_
+		WHERE cs.group_type_ = 'VIP' AND csts.settlement_time_ IS NULL AND cs.class_date_ &gt;= #{firstDayOfMonth} AND cs.class_date_ &lt;= #{lastDayOfMonth}
+		GROUP BY cs.actual_teacher_id_,csrr.id_
+	</select>
+	<select id="findByIds" resultMap="CourseScheduleRewardsRules">
+		SELECT * FROM course_schedule_rewards_rules csrr WHERE csrr.id_ IN
+		<foreach collection="activeIds" separator="," open="(" close=")" item="item">
+			#{item}
+		</foreach>
+	</select>
 	<sql id="findDetailPageSql">
 		<where>
 			<if test="teacherId">

+ 4 - 0
mec-biz/src/main/resources/config/mybatis/SysUserCashAccountDetailMapper.xml

@@ -189,4 +189,8 @@
             AND FIND_IN_SET(u.organ_id_,#{organId})
         </if>
     </select>
+    <select id="countByTypeAndTime" resultType="java.lang.Integer">
+      SELECT COUNT(s.id_) FROM sys_user_cash_account_detail s
+      WHERE s.type_ = 'REWARDS' AND DATE_FORMAT(s.create_time_,'%Y-%m') = #{currentMonth}
+    </select>
 </mapper>

+ 19 - 0
mec-util/src/main/java/com/ym/mec/util/date/DateUtil.java

@@ -40,6 +40,11 @@ public class DateUtil {
 	public static final String ISO_EXPANDED_DATE_FORMAT = "yyyy-MM-dd";
 
 	/**
+	 * ISO8601扩展日期格式 yyyy-MM-dd ,如:2002-12-25 代表2002年12月25日。
+	 */
+	public static final String ISO_YEAR_MONTH_FORMAT = "yyyy-MM";
+
+	/**
 	 * ISO8601基本时间格式 HHmmssSSSzzz ,如:143212333-0500 代表西5区,14点32分12秒333毫秒 24小时制
 	 */
 	public static final String ISO_TIME_FORMAT = "HHmmssSSSzzz";
@@ -798,6 +803,18 @@ public class DateUtil {
 		return DateUtil.stringToDate(str, DateUtil.ISO_EXPANDED_DATE_FORMAT);
 	}
 
+	/**
+	 * 返回date所在月的最后一天
+	 *
+	 * @return
+	 */
+	public static Date getLastDayOfMonth(Date date) {
+		Calendar calendar = Calendar.getInstance();
+		calendar.setTime(date);
+		calendar.set(Calendar.DAY_OF_MONTH, calendar.getActualMaximum(Calendar.DAY_OF_MONTH));
+		return calendar.getTime();
+	}
+
 	// 取最近的时间
 	public static Date getMaxDate(Date lastDate, Date newDate) {
 		if (lastDate != null && newDate != null) {
@@ -1091,5 +1108,7 @@ public class DateUtil {
 		System.out.println(getNextWeekMonday(new Date()));
 		System.out.println(getNextWeekSunday(new Date()));
 		System.out.println(dayEnd(new Date()));
+		System.out.println(format(getLastDayOfMonth(new Date()),CHINESE_DATA_FORMAT));
+
 	}
 }

+ 89 - 6
mec-util/src/main/java/com/ym/mec/util/excel/POIUtil.java

@@ -5,6 +5,7 @@ import java.io.FileInputStream;
 import java.io.IOException;
 import java.io.InputStream;
 import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
 import java.security.cert.CertificateException;
 import java.security.cert.X509Certificate;
 import java.text.SimpleDateFormat;
@@ -39,12 +40,7 @@ import org.apache.poi.hssf.usermodel.HSSFFont;
 import org.apache.poi.hssf.usermodel.HSSFRow;
 import org.apache.poi.hssf.usermodel.HSSFSheet;
 import org.apache.poi.hssf.usermodel.HSSFWorkbook;
-import org.apache.poi.ss.usermodel.Cell;
-import org.apache.poi.ss.usermodel.CellStyle;
-import org.apache.poi.ss.usermodel.Font;
-import org.apache.poi.ss.usermodel.Row;
-import org.apache.poi.ss.usermodel.Sheet;
-import org.apache.poi.ss.usermodel.Workbook;
+import org.apache.poi.ss.usermodel.*;
 import org.apache.poi.xssf.streaming.SXSSFWorkbook;
 import org.apache.poi.xssf.usermodel.XSSFWorkbook;
 import org.slf4j.Logger;
@@ -631,4 +627,91 @@ public class POIUtil {
 
 		}
 	}
+
+	/**
+	 * 创建excel文档
+	 *
+	 * @param getters list中map的key数组集合
+	 * @param headers excel的列名
+	 */
+	public static Workbook createWorkBook(List list, String[] getters, String[] headers, Class clazz) {
+
+		List<Method> methods = getMethodsByStrs(getters, clazz);
+
+		// 创建.xlsx工作簿
+		Workbook wb = new XSSFWorkbook();
+		// 创建第一个sheet(页),并命名
+		Sheet sheet = wb.createSheet("sheet1");
+		// 手动设置列宽.第一个参数表示要为第几列设,第二个参数表示列的宽度,n为列高的像素数.
+
+		for (int i = 0; i < getters.length; i++) {
+			sheet.setColumnWidth((short) i, (short) (35.7 * 200));
+		}
+
+		// 创建第一行
+		Row header = sheet.createRow(0);
+
+		// 创建两种单元格格式
+		CellStyle cellStyle1 = wb.createCellStyle();
+		CellStyle cellStyle2 = wb.createCellStyle();
+
+		// 创建两种字体
+		Font font1 = wb.createFont(); // 标题字体
+		Font font2 = wb.createFont(); // 正文字体
+
+		// 标题加粗
+		font1.setBoldweight(Font.BOLDWEIGHT_BOLD);
+
+		// 设置两种单元格的样式
+		setCellStype(cellStyle1, font1);
+		setCellStype(cellStyle2, font2);
+
+		//设置header
+		for (int i = 0; i < headers.length; i++) {
+			Cell cell = header.createCell(i);
+			cell.setCellValue(headers[i]);
+			cell.setCellStyle(cellStyle1);
+		}
+
+		//设置data
+		int headersNum = 1;
+		for (int i = 0; i < list.size(); i++) {
+			Row row = sheet.createRow(i + headersNum);
+			for (int j = 0; j < methods.size(); j++) {
+				try {
+					Object invoke = methods.get(j).invoke(list.get(i));
+					if (invoke != null) {
+						row.createCell(j).setCellValue(invoke.toString());
+					}
+				} catch (Exception e) {
+					e.printStackTrace();
+				}
+			}
+		}
+		return wb;
+	}
+
+	private static void setCellStype(CellStyle cellStyle, Font font) {
+		font.setFontHeightInPoints((short) 10);
+		font.setColor(IndexedColors.BLACK.getIndex());
+		cellStyle.setFont(font);
+		cellStyle.setBorderLeft(CellStyle.BORDER_THIN);
+		cellStyle.setBorderRight(CellStyle.BORDER_THIN);
+		cellStyle.setBorderTop(CellStyle.BORDER_THIN);
+		cellStyle.setBorderBottom(CellStyle.BORDER_THIN);
+		cellStyle.setAlignment(CellStyle.ALIGN_CENTER);
+	}
+
+	private static List<Method> getMethodsByStrs(String[] getters, Class clazz) {
+		List<Method> list = new ArrayList<>();
+		for (String getter : getters) {
+			try {
+				list.add(clazz.getDeclaredMethod(getter));
+			} catch (NoSuchMethodException e) {
+				e.printStackTrace();
+			}
+		}
+		return list;
+	}
+
 }

+ 47 - 26
mec-web/src/main/java/com/ym/mec/web/controller/ExportController.java

@@ -1,25 +1,5 @@
 package com.ym.mec.web.controller;
 
-import io.swagger.annotations.Api;
-import io.swagger.annotations.ApiImplicitParam;
-import io.swagger.annotations.ApiImplicitParams;
-import io.swagger.annotations.ApiOperation;
-
-import java.io.IOException;
-import java.io.OutputStream;
-import java.util.Date;
-import java.util.List;
-
-import javax.servlet.http.HttpServletResponse;
-
-import org.apache.poi.hssf.usermodel.HSSFWorkbook;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.security.access.prepost.PreAuthorize;
-import org.springframework.stereotype.Controller;
-import org.springframework.web.bind.annotation.GetMapping;
-import org.springframework.web.bind.annotation.PostMapping;
-import org.springframework.web.bind.annotation.RequestMapping;
-
 import com.ym.mec.biz.dal.dto.StudentApplyDetailDto;
 import com.ym.mec.biz.dal.dto.TeacherSalaryDto;
 import com.ym.mec.biz.dal.entity.Goods;
@@ -32,6 +12,20 @@ import com.ym.mec.common.controller.BaseController;
 import com.ym.mec.common.exception.BizException;
 import com.ym.mec.util.date.DateUtil;
 import com.ym.mec.util.excel.POIUtil;
+import io.swagger.annotations.Api;
+import io.swagger.annotations.ApiOperation;
+import org.apache.poi.hssf.usermodel.HSSFWorkbook;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Controller;
+import org.springframework.web.bind.annotation.PostMapping;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RestController;
+
+import javax.servlet.http.HttpServletResponse;
+import java.io.IOException;
+import java.io.OutputStream;
+import java.util.Date;
+import java.util.List;
 
 @RequestMapping
 @Api(tags = "数据导出服务")
@@ -45,18 +39,45 @@ public class ExportController extends BaseController {
     @Autowired
     private CourseScheduleTeacherSalaryService courseScheduleTeacherSalaryService;
 
+    /*@RequestMapping("order/musicalListExport")
+    public ResponseEntity<byte[]> exportExcel(String musicGroupId) {
+        // 每次只需要改这几行
+        List<Goods> musicalList = studentPaymentOrderDetailService.getMusicalList(musicGroupId);
+        if(musicalList == null || musicalList.size() < 1){
+            throw new BizException("数据为空");
+        }
+        String fileName = "乐器采购清单";
+        String[] headers = new String[] {"乐团","分部","商品类型", "商品名称", "型号", "数量"};
+        String[] getters  = new String[] {"getMemo","getBrief","getType","getName","getSpecification","getSellCount"};
+        Workbook wb = POIUtil.createWorkBook(musicalList, getters, headers,Goods.class);
+        ByteArrayOutputStream os = new ByteArrayOutputStream();
+        try {
+            wb.write(os);
+        } catch (IOException e) {
+            e.printStackTrace();
+        }
+        byte[] content = os.toByteArray();
+        HttpHeaders httpHeaders = new HttpHeaders();
+        try {
+            fileName = URLEncoder.encode(fileName, "UTF-8");
+        } catch (UnsupportedEncodingException e) {
+            e.printStackTrace();
+        }
+        httpHeaders.setContentDispositionFormData("attachment", fileName + ".xlsx");
+        return new ResponseEntity<>(content, httpHeaders, HttpStatus.OK);
+    }*/
+
     @ApiOperation(value = "导出乐器采购清单")
-    @GetMapping("order/musicalListExport")
-    @ApiImplicitParams({@ApiImplicitParam(name = "musicGroupId", value = "乐团id", required = true, dataType = "String")})
-    public void musicalListExport(HttpServletResponse response,String musicGroupId){
+    @PostMapping("order/musicalListExport")
+    public void musicalListExport(HttpServletResponse response, String musicGroupId){
         List<Goods> musicalList = studentPaymentOrderDetailService.getMusicalList(musicGroupId);
         if(musicalList == null || musicalList.size() < 1){
             throw new BizException("数据为空");
         }
         OutputStream outputStream = null;
         try {
-            HSSFWorkbook workbook = POIUtil.exportExcel(new String[] { "分部","乐团", "声部", "商品名称", "数量"}, new String[] {
-                    "brief","memo", "currentGrade", "currentClass", "gender", "isAllowAdjust.msg"}, musicalList);
+            HSSFWorkbook workbook = POIUtil.exportExcel(new String[] {"乐团","分部","商品类型", "商品名称", "型号", "数量"}, new String[] {
+                    "brief","memo","type.desc","name","specification","sellCount"}, musicalList);
             response.setContentType("application/msexcel");
             response.setHeader("Content-disposition", "attachment;filename=lender-" + DateUtil.getDate(new Date()) + ".xls");
             outputStream = response.getOutputStream();
@@ -86,7 +107,7 @@ public class ExportController extends BaseController {
         try {
             HSSFWorkbook workbook = POIUtil.exportExcel(new String[] { "学生姓名","家长姓名", "年级", "班级", "性别", "服从调剂","报名专业", "实际专业","联系电话", "学员缴费状态", "乐器购买方式"}, new String[] {
                     "studentName","parentsName", "currentGrade", "currentClass", "gender", "isAllowAdjust.msg", "subjectName", "actualSubjectName", "parentsPhone","paymentStatus","kitGroupPurchaseTypeEnum.msg"}, studentApplyDetail);
-            response.setContentType("application/msexcel");
+            response.setContentType("application/vnd.ms-excel");
             response.setHeader("Content-disposition", "attachment;filename=lender-" + DateUtil.getDate(new Date()) + ".xls");
             outputStream = response.getOutputStream();
             workbook.write(outputStream);