Browse Source

新增乐保导出

周箭河 4 years ago
parent
commit
8939ba41ae

+ 19 - 0
mec-biz/src/main/java/com/ym/mec/biz/dal/dao/StudentInstrumentDao.java

@@ -1,6 +1,8 @@
 package com.ym.mec.biz.dal.dao;
 
+import com.ym.mec.biz.dal.dto.StudentInstrumentExportDto;
 import com.ym.mec.biz.dal.entity.StudentInstrument;
+import com.ym.mec.biz.dal.entity.StudentRegistration;
 import com.ym.mec.common.dal.BaseDAO;
 import org.apache.ibatis.annotations.Param;
 
@@ -55,4 +57,21 @@ public interface StudentInstrumentDao extends BaseDAO<Long, StudentInstrument> {
      * @return
      */
     List<StudentInstrument> getOldStudentInstrument(@Param("startTime") Date startTime, @Param("goodsIds") List<Integer> goodsIds);
+
+    /**
+     * 获取乐保订单列表
+     *
+     * @param startTime
+     * @param endTime
+     * @param organId
+     * @return
+     */
+    List<StudentInstrumentExportDto> getInstruments(@Param("startTime") Date startTime, @Param("endTime") Date endTime, @Param("organId") String organId);
+
+    /**
+     * 获取学生的乐团信息
+     * @param userId
+     * @return
+     */
+    StudentRegistration findStudentMusicGroup(@Param("userId") Integer userId);
 }

+ 84 - 0
mec-biz/src/main/java/com/ym/mec/biz/dal/dto/StudentInstrumentExportDto.java

@@ -0,0 +1,84 @@
+package com.ym.mec.biz.dal.dto;
+
+import com.ym.mec.biz.dal.entity.StudentInstrument;
+import com.ym.mec.biz.dal.enums.StudentMusicGroupStatusEnum;
+import io.swagger.annotations.ApiModelProperty;
+
+public class StudentInstrumentExportDto extends StudentInstrument {
+    @ApiModelProperty(value = "订单编号")
+    private String orderNo;
+
+    @ApiModelProperty(value = "订单流水号")
+    private String transNo;
+
+    @ApiModelProperty(value = "乐团名称")
+    private String musicGroupName;
+
+    @ApiModelProperty(value = "学员状态")
+    private StudentMusicGroupStatusEnum studentStatus;
+
+    @ApiModelProperty(value = "维修技师id")
+    private Integer repairerId;
+
+    @ApiModelProperty(value = "维修技师")
+    private String repairerName;
+
+    @ApiModelProperty(value = "乐保类型")
+    private String type = "新增";
+
+    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 getMusicGroupName() {
+        return musicGroupName;
+    }
+
+    public void setMusicGroupName(String musicGroupName) {
+        this.musicGroupName = musicGroupName;
+    }
+
+    public StudentMusicGroupStatusEnum getStudentStatus() {
+        return studentStatus;
+    }
+
+    public void setStudentStatus(StudentMusicGroupStatusEnum studentStatus) {
+        this.studentStatus = studentStatus;
+    }
+
+    public Integer getRepairerId() {
+        return repairerId;
+    }
+
+    public void setRepairerId(Integer repairerId) {
+        this.repairerId = repairerId;
+    }
+
+    public String getRepairerName() {
+        return repairerName;
+    }
+
+    public void setRepairerName(String repairerName) {
+        this.repairerName = repairerName;
+    }
+
+    public String getType() {
+        return type;
+    }
+
+    public void setType(String type) {
+        this.type = type;
+    }
+}

+ 40 - 0
mec-biz/src/main/resources/config/mybatis/StudentInstrumentMapper.xml

@@ -229,4 +229,44 @@
         ORDER BY spo.create_time_ ASC
     </select>
 
+    <resultMap id="StudentInstrumentExportDto" type="com.ym.mec.biz.dal.dto.StudentInstrumentExportDto"
+               extends="StudentInstrument">
+        <result column="order_no_" property="orderNo"/>
+        <result column="trans_no_" property="transNo"/>
+        <result column="type_" property="type"/>
+    </resultMap>
+
+    <select id="getInstruments" resultMap="StudentInstrumentExportDto">
+        SELECT si.*,spo.create_time_,o.name_ organName,su.username_
+        studentName,spo.order_no_,spo.trans_no_,spod.is_renew_ type_,spo.id_
+        FROM student_payment_order_detail spod
+        LEFT JOIN student_payment_order spo ON spo.id_ = spod.payment_order_id_
+        LEFT JOIN student_instrument si ON si.id_ = spod.student_instrument_id_
+        LEFT JOIN organization o ON spo.organ_id_ = o.id_
+        LEFT JOIN sys_user su ON su.id_ = si.student_id_
+        WHERE spo.status_ = 'SUCCESS' AND spod.type_='MAINTENANCE'
+        <if test="startTime != null ">
+            AND spo.create_time_ >= #{startTime}
+        </if>
+        <if test="endTime != null ">
+            <![CDATA[AND spo.create_time_ <= #{endTime}]]>
+        </if>
+        <if test="organId != null">
+            AND FIND_IN_SET(spo.organ_id_,#{organId})
+        </if>
+    </select>
+
+    <select id="findStudentMusicGroup"
+            resultMap="com.ym.mec.biz.dal.dao.StudentRegistrationDao.StudentRegistration">
+        SELECT sr.id_, sr.user_id_, mg.name_ class_group_name_, su.real_name_ parents_name_, sr.music_group_status_
+        FROM student_registration sr
+                 LEFT JOIN music_group mg ON sr.music_group_id_ = mg.id_
+                 LEFT JOIN sys_user su ON su.id_ = mg.repair_user_id_
+        WHERE sr.user_id_ = #{userId}
+          AND sr.payment_status_ = 2
+          AND mg.status_ IN ('PREPARE', 'PROGRESS', 'PAUSE', 'CLOSE')
+        ORDER BY sr.id_ DESC
+        LIMIT 1
+    </select>
+
 </mapper>

+ 76 - 0
mec-web/src/main/java/com/ym/mec/web/controller/StudentInstrumentController.java

@@ -1,23 +1,32 @@
 package com.ym.mec.web.controller;
 
 
+import com.alibaba.fastjson.JSONObject;
 import com.ym.mec.auth.api.client.SysUserFeignService;
 import com.ym.mec.auth.api.entity.SysUser;
 import com.ym.mec.biz.dal.dao.EmployeeDao;
 import com.ym.mec.biz.dal.dao.StudentInstrumentDao;
+import com.ym.mec.biz.dal.dto.RepairGoodsDto;
+import com.ym.mec.biz.dal.dto.StudentInstrumentExportDto;
 import com.ym.mec.biz.dal.entity.Employee;
 import com.ym.mec.biz.dal.entity.StudentInstrument;
+import com.ym.mec.biz.dal.entity.StudentRegistration;
+import com.ym.mec.biz.dal.entity.StudentRepair;
 import com.ym.mec.biz.dal.page.StudentInstrumentQueryInfo;
 import com.ym.mec.biz.service.StudentInstrumentService;
 import com.ym.mec.common.controller.BaseController;
 import com.ym.mec.common.entity.HttpResponseResult;
+import com.ym.mec.common.exception.BizException;
 import com.ym.mec.common.page.PageInfo;
 import com.ym.mec.util.date.DateUtil;
+import com.ym.mec.util.excel.POIUtil;
 import io.swagger.annotations.Api;
 import io.swagger.annotations.ApiImplicitParam;
 import io.swagger.annotations.ApiImplicitParams;
 import io.swagger.annotations.ApiOperation;
 import org.apache.commons.lang3.StringUtils;
+import org.apache.ibatis.annotations.Param;
+import org.apache.poi.hssf.usermodel.HSSFWorkbook;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.http.HttpStatus;
 import org.springframework.security.access.prepost.PreAuthorize;
@@ -26,10 +35,14 @@ 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.math.BigDecimal;
 import java.util.Arrays;
 import java.util.Date;
 import java.util.List;
+import java.util.stream.Collectors;
 
 @RequestMapping("studentInstrument")
 @Api(tags = "乐器与乐保服务")
@@ -180,4 +193,67 @@ public class StudentInstrumentController extends BaseController {
         studentInstrument.setDelFlag(1);
         return succeed(studentInstrumentService.updateStudentInstrument(studentInstrument));
     }
+
+    @ApiOperation(value = "导出")
+    @GetMapping("/export")
+    @PreAuthorize("@pcs.hasPermissions('studentInstrument/export')")
+    public void export(Date startTime, Date endTime, HttpServletResponse response) throws Exception {
+        SysUser sysUser = sysUserFeignService.queryUserInfo();
+        if (sysUser == null) {
+            throw new BizException("用户信息获取失败");
+        }
+        Employee employee = employeeDao.get(sysUser.getId());
+        String organId = null;
+        if (StringUtils.isEmpty(employee.getOrganIdList())) {
+            throw new BizException("用户所在分部异常");
+        } else {
+            organId = employee.getOrganIdList();
+        }
+        if (startTime != null) {
+            startTime = DateUtil.trunc(startTime);
+        }
+        if (endTime != null) {
+            endTime = DateUtil.getLastTimeWithDay(endTime);
+        }
+
+        List<StudentInstrumentExportDto> instruments = studentInstrumentDao.getInstruments(startTime, endTime, organId);
+
+        if (instruments.size() <= 0) {
+            throw new BizException("没有可导出的记录");
+        }
+        for (StudentInstrumentExportDto instrument : instruments) {
+            StudentRegistration studentMusicGroup = studentInstrumentDao.findStudentMusicGroup(instrument.getStudentId());
+            if (studentMusicGroup != null) {
+                instrument.setRepairerName(studentMusicGroup.getParentsName());
+                instrument.setMusicGroupName(studentMusicGroup.getClassGroupName());
+                instrument.setStudentStatus(studentMusicGroup.getMusicGroupStatus());
+            }
+        }
+
+        OutputStream outputStream = response.getOutputStream();
+        HSSFWorkbook workbook = null;
+        try {
+            String[] header = {"交易流水号", "订单号", "订单日期", "分部", "学员姓名", "学员编号", "所属乐团", "学员状态", "维修技师", "乐器名称", "具体型号", "乐保类型"};
+            String[] body = {"transNo", "orderNo", "createTime", "organName", "studentName", "studentId", "musicGroupName", "studentStatus.msg", "repairerName", "goodsName", "specification", "type == '0' ? '新增' : '续费'"};
+            workbook = POIUtil.exportExcel(header, body, instruments);
+            response.setContentType("application/octet-stream");
+            response.setHeader("Content-Disposition", "attachment;filename=maintenance-" + DateUtil.getDate(new Date()) + ".xls");
+            response.flushBuffer();
+            outputStream = response.getOutputStream();
+            workbook.write(outputStream);
+            outputStream.flush();
+            workbook.close();
+        } catch (Exception e) {
+            e.printStackTrace();
+        } finally {
+            if (outputStream != null) {
+                try {
+                    workbook.close();
+                    outputStream.close();
+                } catch (IOException e) {
+                    e.printStackTrace();
+                }
+            }
+        }
+    }
 }