|
@@ -1,18 +1,27 @@
|
|
|
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.dto.RepairGoodsDto;
|
|
|
+import com.ym.mec.biz.dal.entity.CooperationOrgan;
|
|
|
import com.ym.mec.biz.dal.entity.Employee;
|
|
|
+import com.ym.mec.biz.dal.entity.StudentRepair;
|
|
|
+import com.ym.mec.biz.dal.page.CooperationOrganQueryInfo;
|
|
|
import com.ym.mec.biz.dal.page.RepairStudentQueryInfo;
|
|
|
import com.ym.mec.biz.service.StudentRepairService;
|
|
|
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.ApiOperation;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
+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;
|
|
@@ -21,6 +30,10 @@ 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;
|
|
@@ -46,20 +59,20 @@ public class StudentRepairController extends BaseController {
|
|
|
if (sysUser == null) {
|
|
|
return failed("用户信息获取失败");
|
|
|
}
|
|
|
- Employee employee = employeeDao.get(sysUser.getId());
|
|
|
- if (StringUtils.isEmpty(queryInfo.getOrganIdList())) {
|
|
|
- queryInfo.setOrganIdList(employee.getOrganIdList());
|
|
|
- }else if(StringUtils.isEmpty(employee.getOrganIdList())){
|
|
|
- return failed("用户所在分部异常");
|
|
|
- }else {
|
|
|
- List<String> list = Arrays.asList(employee.getOrganIdList().split(","));
|
|
|
- if(!list.containsAll(Arrays.asList(queryInfo.getOrganIdList().split(",")))){
|
|
|
- return failed("非法请求");
|
|
|
- }
|
|
|
+ Employee employee = employeeDao.get(sysUser.getId());
|
|
|
+ if (StringUtils.isEmpty(queryInfo.getOrganIdList())) {
|
|
|
+ queryInfo.setOrganIdList(employee.getOrganIdList());
|
|
|
+ } else if (StringUtils.isEmpty(employee.getOrganIdList())) {
|
|
|
+ return failed("用户所在分部异常");
|
|
|
+ } else {
|
|
|
+ List<String> list = Arrays.asList(employee.getOrganIdList().split(","));
|
|
|
+ if (!list.containsAll(Arrays.asList(queryInfo.getOrganIdList().split(",")))) {
|
|
|
+ return failed("非法请求");
|
|
|
}
|
|
|
+ }
|
|
|
Date endTime = queryInfo.getEndTime();
|
|
|
- if(endTime != null){
|
|
|
- queryInfo.setEndTime(DateUtil.addDays(endTime, 1));
|
|
|
+ if (endTime != null) {
|
|
|
+ queryInfo.setEndTime(DateUtil.getLastTimeWithDay(endTime));
|
|
|
}
|
|
|
queryInfo.setPayStatus(2);
|
|
|
return succeed(studentRepairService.queryPage(queryInfo));
|
|
@@ -69,8 +82,71 @@ public class StudentRepairController extends BaseController {
|
|
|
@ApiOperation("维修完成")
|
|
|
@PostMapping(value = "/repairSuccess")
|
|
|
@PreAuthorize("@pcs.hasPermissions('studentRepair/repairSuccess')")
|
|
|
- public HttpResponseResult repairSuccess(Integer id,String description,Integer repairStatus) {
|
|
|
- studentRepairService.repairSuccess(id,description,repairStatus);
|
|
|
+ public HttpResponseResult repairSuccess(Integer id, String description, Integer repairStatus) {
|
|
|
+ studentRepairService.repairSuccess(id, description, repairStatus);
|
|
|
return succeed();
|
|
|
}
|
|
|
+
|
|
|
+ @ApiOperation(value = "维修记录导出")
|
|
|
+ @RequestMapping("/export")
|
|
|
+ @PreAuthorize("@pcs.hasPermissions('studentRepair/export')")
|
|
|
+ public void export(RepairStudentQueryInfo queryInfo, HttpServletResponse response) throws Exception {
|
|
|
+ SysUser sysUser = sysUserFeignService.queryUserInfo();
|
|
|
+ if (sysUser == null) {
|
|
|
+ throw new BizException("用户信息获取失败");
|
|
|
+ }
|
|
|
+ Employee employee = employeeDao.get(sysUser.getId());
|
|
|
+ if (StringUtils.isEmpty(queryInfo.getOrganIdList())) {
|
|
|
+ queryInfo.setOrganIdList(employee.getOrganIdList());
|
|
|
+ } else if (StringUtils.isEmpty(employee.getOrganIdList())) {
|
|
|
+ throw new BizException("用户所在分部异常");
|
|
|
+ } else {
|
|
|
+ List<String> list = Arrays.asList(employee.getOrganIdList().split(","));
|
|
|
+ if (!list.containsAll(Arrays.asList(queryInfo.getOrganIdList().split(",")))) {
|
|
|
+ throw new BizException("非法请求");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ Date endTime = queryInfo.getEndTime();
|
|
|
+ if (endTime != null) {
|
|
|
+ queryInfo.setEndTime(DateUtil.getLastTimeWithDay(endTime));
|
|
|
+ }
|
|
|
+ queryInfo.setPayStatus(2);
|
|
|
+ queryInfo.setRows(65000);
|
|
|
+
|
|
|
+ PageInfo<StudentRepair> pageList = studentRepairService.queryPage(queryInfo);
|
|
|
+
|
|
|
+ if (pageList.getTotal() <= 0) {
|
|
|
+ throw new BizException("没有可导出的记录");
|
|
|
+ }
|
|
|
+ for (StudentRepair row : pageList.getRows()) {
|
|
|
+ if (row.getGoodsJson() == null || row.getGoodsJson().equals("[]")) continue;
|
|
|
+ List<RepairGoodsDto> repairGoodsDtos = JSONObject.parseArray(row.getGoodsJson(), RepairGoodsDto.class);
|
|
|
+ BigDecimal repairGoodsAmount = repairGoodsDtos.stream().map(RepairGoodsDto::getGroupPurchasePrice).reduce(BigDecimal.ZERO, BigDecimal::add);
|
|
|
+ row.setRepairGoodsAmount(repairGoodsAmount);
|
|
|
+ }
|
|
|
+
|
|
|
+ OutputStream outputStream = response.getOutputStream();
|
|
|
+ try {
|
|
|
+ String[] header = {"分部", "维修单号", "学生姓名", "学生编号", "维修技师", "维修类型", "维修单名称", "维修服务费", "商品金额", "特权减免金额", "送修日期", "完成日期", "状态"};
|
|
|
+ String[] body = {"organName", "transNo", "studentName", "studentId", "employeeName", "type == 0 ? '线下' : '线上'", "repairName", "amount", "repairGoodsAmount", "exemptionAmount", "createTime", "finishTime", "repairStatus == 0 ? '维修中' : '已完成'"};
|
|
|
+ HSSFWorkbook workbook = POIUtil.exportExcel(header, body, pageList.getRows());
|
|
|
+ response.setContentType("application/octet-stream");
|
|
|
+ response.setHeader("Content-Disposition", "attachment;filename=repairList-" + 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 {
|
|
|
+ outputStream.close();
|
|
|
+ } catch (IOException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|