diff --git a/fengmi-car-management/src/main/java/cn/insectmk/stat/controller/StatController.java b/fengmi-car-management/src/main/java/cn/insectmk/stat/controller/StatController.java new file mode 100644 index 0000000000000000000000000000000000000000..e2c02aa8ac7eefe4f0d5b97940e8ba4efbc89cad --- /dev/null +++ b/fengmi-car-management/src/main/java/cn/insectmk/stat/controller/StatController.java @@ -0,0 +1,143 @@ +package cn.insectmk.stat.controller; + +import cn.insectmk.bus.domain.Customer; +import cn.insectmk.bus.domain.Rent; +import cn.insectmk.bus.service.CustomerService; +import cn.insectmk.bus.service.RentService; +import cn.insectmk.stat.domain.BaseEntity; +import cn.insectmk.stat.service.StatService; +import cn.insectmk.sys.utils.ExportRentUtils; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.http.HttpHeaders; +import org.springframework.http.HttpStatus; +import org.springframework.http.MediaType; +import org.springframework.http.ResponseEntity; +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.ResponseBody; +import java.io.ByteArrayOutputStream; +import java.io.UnsupportedEncodingException; +import java.net.URLEncoder; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +/** + * @Description 统计分析模块控制器 + * @Author makun + * @Date 2023/7/4 14:52 + * @Version 1.0 + */ +@RequestMapping("stat") +@Controller +public class StatController { + @Autowired + private CustomerService customerService; + @Autowired + private RentService rentService; + @Autowired + private StatService statService; + + /** + * 加载公司年度业务统计数据 + * @return + */ + @RequestMapping("loadCompanyYearGradeStatJson") + @ResponseBody + public List loadCompanyYearGradeStatJson(String year){ + List entities = this.statService.loadCompanyYearGradeStatList(year); + for (int i = 0; i < entities.size(); i++) { + if (null==entities.get(i)){ + entities.set(i,0.0); + } + } + return entities; + } + + /** + * 跳转到公司年度业务统计 + * @return + */ + @RequestMapping("toCompanyYearGradeStat") + public String toCompanyYearGradeStat(){ + return "stat/companyYearGradeStat"; + } + + /** + * 跳转到业务员年度销售额 + * @return + */ + @RequestMapping("toOpernameYearGradeStat") + public String toOpernameYearGradeStat() { + return "stat/opernameYearGradeStat"; + } + + /** + * 加载业务员年度业务统计数据 + * @return + */ + @RequestMapping("loadOpernameYearGradeStatJson") + @ResponseBody + public Map loadOpernameYearGradeStatJson(String year){ + List entities = this.statService.loadOpernameYearGradeStatList(year); + Map map = new HashMap(); + List names = new ArrayList(); + List values = new ArrayList(); + for (BaseEntity baseEntity : entities) { + names.add(baseEntity.getName()); + values.add(baseEntity.getValue()); + } + map.put("name",names); + map.put("value",values); + return map; + } + + /** + * 加载客户地区数据 + * @return + */ + @RequestMapping("loadCustomerAreaStatJson") + @ResponseBody + public List loadCustomerAreaStatJson(){ + return this.statService.loadCustomerAreaStatList(); + } + + /** + * 跳转到客户地区统计页面 + */ + @RequestMapping("toCustomerAreaStat") + public String toCustomerAreaStat(){ + return "stat/customerAreaStat"; + } + + /** + * 导出出租单数据 + * @param rentid + */ + @RequestMapping("exportRent") + public ResponseEntity exportRent(String rentid){ + //根据出租单号查询出租单信息 + Rent rent = rentService.queryRentByRentId(rentid); + //根据身份证号查询客户信息 + Customer customer = customerService.queryCustomerByIdentity(rent.getIdentity()); + String fileName=customer.getCustname()+"-的出租单.xls"; + String sheetName=customer.getCustname()+"出租单"; + ByteArrayOutputStream bos = ExportRentUtils.exportRent(rent,customer,sheetName); + + try { + //处理文件名乱码 + fileName= URLEncoder.encode(fileName,"UTF-8"); + //创建 封装响应头信息的对象 + HttpHeaders headers = new HttpHeaders(); + //封装响应内容类型(APPLICATION_OCTET_STREAM 响应的内容不限定) + headers.setContentType(MediaType.APPLICATION_OCTET_STREAM); + //设置下载的文件的名称 + headers.setContentDispositionFormData("attachment",fileName); + return new ResponseEntity(bos.toByteArray(),headers, HttpStatus.CREATED); + } catch (UnsupportedEncodingException e) { + e.printStackTrace(); + } + return null; + } +}