Browse Source

健康小屋-用户反馈excel导出

huangzhiyong 6 years ago
parent
commit
3c9b45f553

+ 1 - 0
common/common-request-mapping/src/main/java/com/yihu/jw/rm/health/house/HealthyHouseMapping.java

@ -77,6 +77,7 @@ public class HealthyHouseMapping {
            public static final String GET_FEEDBACK_BY_ID = "/getFeedBackById";
            public static final String GET_FEEDBACKS_BY_FIELD = "/getFeedBacksByField";
            public static final String UPDATE_FEEDBACKS_BY_ID = "/updateFeedBacksById";
            public static final String EXPORT_EXCEL = "/exportExcel/feedBacks";
        }
        //用户使用导航记录

+ 4 - 4
svr/svr-healthy-house/src/main/java/com/yihu/jw/healthyhouse/controller/LoginController.java

@ -25,7 +25,7 @@ import java.util.HashMap;
 * @author HZY
 * @created 2018/9/18 19:55
 */
@Api(value = "LoginController", description = "登录", tags = {"登录"})
@Api(value = "LoginController", description = "登录管理", tags = {"登录","验证"})
@RestController
public class LoginController extends EnvelopRestEndpoint {
@ -51,9 +51,9 @@ public class LoginController extends EnvelopRestEndpoint {
            throw new InvalidRequestException("username");
        }
        //验证请求间隔超时,防止频繁获取验证码
        if (!wlyyRedisVerifyCodeService.isIntervalTimeout(clientId, username)) {
            throw new IllegalAccessException("SMS request frequency is too fast");
        }
//        if (!wlyyRedisVerifyCodeService.isIntervalTimeout(clientId, username)) {
//            throw new IllegalAccessException("SMS request frequency is too fast");
//        }
        //发送短信获取验证码
        ResponseEntity<HashMap> result = loginService.sendDemoSms(clientId,msgType,username);
        return result;

+ 0 - 16
svr/svr-healthy-house/src/main/java/com/yihu/jw/healthyhouse/controller/facilities/FacilitiesController.java

@ -313,20 +313,4 @@ public class FacilitiesController extends EnvelopRestEndpoint {
    }
//    @ApiOperation(value = "搜索附近的小屋", responseContainer = "List")
//    @GetMapping(value = HealthyHouseMapping.HealthyHouse.Facilities.NEARBY_FACILITY)
//    public PageEnvelop<Facility> nearbyFacility(
//            @ApiParam(name = "lng", value = "当前经度", defaultValue = "")
//            @RequestParam(value = "lng", required = false) String lng,
//            @ApiParam(name = "lat", value = "当前纬度", defaultValue = "")
//            @RequestParam(value = "lat", required = false) String lat,
//            @ApiParam(name = "page", value = "页码", defaultValue = "1")
//            @RequestParam(value = "page", required = false) Integer page,
//            @ApiParam(name = "size", value = "分页大小", defaultValue = "15")
//            @RequestParam(value = "size", required = false) Integer size) throws Exception {
//        List<Facility> facilityList = facilityService.search(fields, filters, sorts, page, size);
//        return success(facilityList, (null == facilityList) ? 0 : facilityList.size(), page, size);
//    }
}

+ 20 - 0
svr/svr-healthy-house/src/main/java/com/yihu/jw/healthyhouse/controller/user/FeedBackController.java

@ -1,7 +1,9 @@
package com.yihu.jw.healthyhouse.controller.user;
import com.yihu.jw.exception.business.ManageException;
import com.yihu.jw.healthyhouse.model.user.FeedBack;
import com.yihu.jw.healthyhouse.model.user.User;
import com.yihu.jw.healthyhouse.service.user.FeedBackService;
import com.yihu.jw.restmodel.web.Envelop;
import com.yihu.jw.restmodel.web.ListEnvelop;
@ -17,8 +19,12 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.text.ParseException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
@ -116,4 +122,18 @@ public class FeedBackController extends EnvelopRestEndpoint {
        return success("success");
    }
    @GetMapping(value = HealthyHouseMapping.HealthyHouse.FeedBack.EXPORT_EXCEL)
    @ApiOperation(value = "意见反馈列表导出excel")
    public void exportToExcel(
            HttpServletResponse response,
            @ApiParam(name = "fields", value = "返回的字段,为空返回全部字段", defaultValue = "")
            @RequestParam(value = "fields", required = false) String fields,
            @ApiParam(name = "filters", value = "过滤器", defaultValue = "")
            @RequestParam(value = "filters", required = false) String filters,
            @ApiParam(name = "sorts", value = "排序", defaultValue = "")
            @RequestParam(value = "sorts", required = false) String sorts) throws ManageException, ParseException {
        List<FeedBack> feedBackList = feedBackService.search(fields, filters, sorts);
        feedBackService.exportUsersExcel(response,feedBackList);
    }
}

+ 1 - 1
svr/svr-healthy-house/src/main/java/com/yihu/jw/healthyhouse/controller/user/UserController.java

@ -38,7 +38,7 @@ import java.util.regex.Pattern;
 * @author HZY
 * @created 2018/9/19 17:29
 */
@Api(value = "UserController", description = "用户信息", tags = {"用户"})
@Api(value = "UserController", description = "用户管理信息", tags = {"用户管理"})
@RequestMapping(value = "/user", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
@RestController
public class UserController  extends EnvelopRestEndpoint {

+ 93 - 0
svr/svr-healthy-house/src/main/java/com/yihu/jw/healthyhouse/service/user/FeedBackService.java

@ -1,12 +1,25 @@
package com.yihu.jw.healthyhouse.service.user;
import com.yihu.jw.exception.business.ManageException;
import com.yihu.jw.healthyhouse.dao.user.FeedBackDao;
import com.yihu.jw.healthyhouse.model.user.FeedBack;
import com.yihu.jw.healthyhouse.model.user.User;
import com.yihu.jw.healthyhouse.util.poi.ExcelUtils;
import com.yihu.jw.util.date.DateUtil;
import com.yihu.mysql.query.BaseJpaService;
import jxl.write.Colour;
import jxl.write.WritableCellFormat;
import org.apache.poi.ss.usermodel.*;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.json.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import javax.servlet.http.HttpServletResponse;
import java.io.OutputStream;
import java.util.List;
/**
 * 意见反馈.
 *
@ -25,4 +38,84 @@ public class FeedBackService extends BaseJpaService<FeedBack, FeedBackDao> {
        return  feedBackDao.findById(id);
    }
    /**
     * excel中添加固定内容
     * @param sheet
     */
    private void addStaticCell(Sheet sheet){
        //设置样式
        Workbook workbook = sheet.getWorkbook();
        CellStyle style = workbook.createCellStyle();
        style.setFillForegroundColor(IndexedColors.LIGHT_BLUE.getIndex());//設置背景色
        Font font = workbook.createFont();
        font.setFontName("黑体");
        font.setFontHeightInPoints((short) 12);
        style.setFont(font);
        ExcelUtils.addCellData(sheet,0,0,"序号",style);
        ExcelUtils.addCellData(sheet,1,0,"反馈ID",style);
        ExcelUtils.addCellData(sheet,2,0,"反馈类型",style);
        ExcelUtils.addCellData(sheet,3,0,"反馈用户",style);
        ExcelUtils.addCellData(sheet,4,0,"反馈时间",style);
        ExcelUtils.addCellData(sheet,5,0,"联系电话",style);
        ExcelUtils.addCellData(sheet,6,0,"反馈内容",style);
        ExcelUtils.addCellData(sheet,7,0,"回复",style);
    }
    /**
     *  导出用户反馈列表excel
     * @param response  响应体
     * @param feedBacks  用户反馈列表
     * @throws ManageException
     */
    public void exportUsersExcel(HttpServletResponse response, List<FeedBack> feedBacks) throws ManageException {
        try {
            String fileName = "健康小屋-用户反馈列表";
            //设置下载
            response.setContentType("octets/stream");
            response.setHeader("Content-Disposition", "attachment; filename="
                    + new String( fileName.getBytes("gb2312"), "ISO8859-1" )+".xlsx");
            OutputStream os = response.getOutputStream();
            //获取导出的数据
            JSONObject order = new JSONObject();
            order.put("id","asc");
            //写excel
            Workbook workbook = new XSSFWorkbook();
            int k=0;
            FeedBack metaData = null;
            int row=0;
            //创建Excel工作表 指定名称和位置
            String streetName = "健康小屋-用户反馈列表";
            Sheet sheet = workbook.createSheet(streetName);
            addStaticCell(sheet);
            //添加表格字段信息
            WritableCellFormat wc = new WritableCellFormat();
            wc.setBorder(jxl.format.Border.ALL, jxl.format.BorderLineStyle.THIN, Colour.SKY_BLUE);//边框
            for(int j=0;k<feedBacks.size(); j++,k++){
                metaData = feedBacks.get(k);
                row=j+1;
                ExcelUtils.addCellData(sheet,0,row,j+1+"");//序号
                ExcelUtils.addCellData(sheet,1,row, metaData.getId());//内部id
                ExcelUtils.addCellData(sheet,2,row, metaData.getFeedTypeValue());//反馈类型
                ExcelUtils.addCellData(sheet,3,row, metaData.getCreateUserName());//反馈用户
                ExcelUtils.addCellData(sheet,4,row, DateUtil.dateToStr(metaData.getCreateTime(),DateUtil.YYYY_MM_DD_HH_MM_SS));//反馈时间
                ExcelUtils.addCellData(sheet,5,row, metaData.getUserTelephone());//电话
                ExcelUtils.addCellData(sheet,6,row, metaData.getContent());//反馈内容
                ExcelUtils.addCellData(sheet,7,row, metaData.getReplyContent());//回复内容
            }
            //写入工作表
            workbook.write(os);
            workbook.close();
            os.flush();
            os.close();
        } catch (Exception e) {
            throw new ManageException("导出用户反馈列表异常",e);
        }
    }
}