首页接口

This commit is contained in:
cwchen 2025-01-17 11:20:12 +08:00
parent e2c495003a
commit 8db6d34665
6 changed files with 107 additions and 8 deletions

View File

@ -8,6 +8,9 @@ package com.bonus.gzcar.business.backstage.controller;
* @description:首页
*/
import cn.afterturn.easypoi.excel.ExcelExportUtil;
import cn.afterturn.easypoi.excel.entity.ExportParams;
import cn.afterturn.easypoi.excel.entity.enmus.ExcelType;
import com.bonus.gzcar.business.backstage.entity.BackParamsDto;
import com.bonus.gzcar.business.backstage.entity.HomeProDetailVo;
import com.bonus.gzcar.business.backstage.service.HomeIndexService;
@ -19,13 +22,15 @@ import com.github.pagehelper.PageInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.apache.poi.ss.usermodel.Workbook;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletResponse;
import java.net.URLEncoder;
import java.util.List;
import java.util.Objects;
@Api(tags = "首页")
@RestController
@ -93,4 +98,34 @@ public class HomeIndexController {
List<HomeProDetailVo> list = service.getProDetails(dto.getData());;
return new PageInfo<>(list);
}
@ApiOperation(value = "首页-二级页面-工程详情导出")
@PostMapping("exportProDetails")
public void exportApplyPlanList(HttpServletResponse response, @RequestBody BackParamsDto dto) {
try {
List<HomeProDetailVo> list = service.getProDetails(dto);
final int[] num = {1};
list.forEach(vo -> {
vo.setSerialNum(num[0]);
if(Objects.equals(vo.getDispatchStatus(),"1")){
vo.setDispatchStatus("部分派车");
}else if(Objects.equals(vo.getDispatchStatus(),"2")){
vo.setDispatchStatus("待派车");
}else if(Objects.equals(vo.getDispatchStatus(),"3")){
vo.setDispatchStatus("全部派车");
}
num[0]++;
});
ExportParams exportParams = new ExportParams("工程详情", "工程详情", ExcelType.XSSF);
Workbook workbook = ExcelExportUtil.exportExcel(exportParams, HomeProDetailVo.class, list);
response.setContentType("application/vnd.ms-excel");
response.setHeader("content-disposition", "attachment;fileName=" + URLEncoder.encode("工程详情" + ".xlsx", "UTF-8"));
ServletOutputStream outputStream = response.getOutputStream();
workbook.write(outputStream);
outputStream.close();
workbook.close();
} catch (Exception e) {
log.error(e.toString(), e);
}
}
}

View File

@ -14,7 +14,7 @@ public class BackParamsDto {
/**分公司*/
private String companyId;
/**派车状态 1.已派车 2.待派车*/
/**派车状态 1.部分派车 2.未派车 3.全部派车*/
private String dispatchStatus;
/**年份*/
private String year;

View File

@ -13,27 +13,39 @@ import lombok.Data;
@Data
public class HomeProDetailVo {
/**序号*/
@Excel(name = "序号", width = 10.0, orderNum = "0")
private int serialNum;
/**工程ID*/
private String proId;
/**工程名称*/
@Excel(name = "序号", width = 10.0, orderNum = "0")
@Excel(name = "工程名称", width = 20.0, orderNum = "1")
private String proName;
/**计划数*/
@Excel(name = "计划数", width = 20.0, orderNum = "2")
private int planNum;
/**已派车计划*/
@Excel(name = "已派车计划", width = 20.0, orderNum = "3")
private int dispatchPlanNum;
/**待派车计划*/
@Excel(name = "待派车计划", width = 20.0, orderNum = "4")
private int noDispatchPlanNum;
/**派车状态*/
@Excel(name = "派车状态", width = 20.0, orderNum = "5")
private String dispatchStatus;
/**应派车数量*/
@Excel(name = "应派车数量", width = 20.0, orderNum = "6")
private int shouldDispatchNum;
/**已派车数量*/
@Excel(name = "已派车数量", width = 20.0, orderNum = "7")
private int dispatchNum;
/**待派车数量*/
@Excel(name = "待派车数量", width = 20.0, orderNum = "8")
private int noDispatchNum;
/**已派车金额*/
@Excel(name = "已派车金额", width = 20.0, orderNum = "9")
private double money;
/**所属分公司*/
@Excel(name = "所属分公司", width = 20.0, orderNum = "10")
private String companyName;
}

View File

@ -1,6 +1,7 @@
package com.bonus.gzcar.business.backstage.mapper;
import com.bonus.gzcar.business.backstage.entity.BackParamsDto;
import com.bonus.gzcar.business.backstage.entity.HomeProDetailVo;
import com.bonus.gzcar.business.backstage.entity.HomeProRankingVo;
import com.bonus.gzcar.business.backstage.entity.HomeSupStatisticsVo;
import org.apache.ibatis.annotations.Param;
@ -99,4 +100,13 @@ public interface HomeIndexMapper {
* @date 2025/1/16 16:41
*/
List<Map<String, String>> getCompanyData(BackParamsDto dto);
/**
* 首页-二级页面-工程详情
* @param dto
* @return List<HomeProDetailVo>
* @author cwchen
* @date 2025/1/17 9:58
*/
List<HomeProDetailVo> getProDetails(BackParamsDto dto);
}

View File

@ -3,6 +3,7 @@ package com.bonus.gzcar.business.backstage.service;
import com.bonus.gzcar.business.backstage.entity.*;
import com.bonus.gzcar.business.backstage.mapper.HomeIndexMapper;
import com.bonus.gzcar.manager.common.util.DateTimeHelper;
import com.bonus.gzcar.manager.common.util.StringUtils;
import com.bonus.gzcar.manager.webResult.ServerResponse;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections4.CollectionUtils;
@ -331,10 +332,17 @@ public class HomeIndexServiceImpl implements HomeIndexService {
}
@Override
public List<HomeProDetailVo> getProDetails(BackParamsDto data) {
public List<HomeProDetailVo> getProDetails(BackParamsDto dto) {
List<HomeProDetailVo> list = new ArrayList<>();
if(StringUtils.isNotEmpty(dto.getYear()) && StringUtils.isNotEmpty(dto.getMonth())){
dto.setYearMonth(dto.getYear() + "-" + dto.getMonth());
}
try {
list = mapper.getProDetails(dto);
for (HomeProDetailVo vo : list) {
vo.setNoDispatchNum(vo.getShouldDispatchNum() - vo.getDispatchNum());
// 金额待计算
}
} catch (Exception e) {
log.error(e.toString(),e);
}

View File

@ -112,4 +112,38 @@
FROM bm_company bc
WHERE IS_ACTIVE = '1'
</select>
<!--首页-二级页面-工程详情-->
<select id="getProDetails" resultType="com.bonus.gzcar.business.backstage.entity.HomeProDetailVo">
SELECT bp.name AS proName,
cpa.pro_id AS proId,
COUNT(ANY_VALUE(cpa.id)) AS planNum,
COUNT(ANY_VALUE(IF(cpa.dispatch_num > 0, 1, null))) AS dispatchPlanNum,
COUNT(ANY_VALUE(IF(cpa.dispatch_num = 0, 1, null))) AS noDispatchPlanNum,
IFNULL(SUM(ANY_VALUE(cpa.need_num)),0) AS shouldDispatchNum,
IFNULL(SUM(ANY_VALUE(cpa.dispatch_num)),0) AS dispatchNum,
ANY_VALUE(bp.bmname) AS companyName,
CASE WHEN SUM(ANY_VALUE(cpa.dispatch_num)) = 0 OR SUM(ANY_VALUE(cpa.dispatch_num)) IS NULL THEN '2'
WHEN SUM(ANY_VALUE(cpa.dispatch_num)) = SUM(ANY_VALUE(cpa.need_num)) THEN '3'
ELSE '1' END AS dispatchStatus
FROM car_plan_apply cpa
LEFT JOIN bm_project bp ON cpa.pro_id = bp.bid_id
<where>
<if test="yearMonth!=null and yearMonth!=''">
AND DATE_FORMAT(cpa.create_time,'%Y-%m') = #{yearMonth}
</if>
<if test="year!=null and year!=''">
AND DATE_FORMAT(cpa.create_time,'%Y') = #{year}
</if>
<if test="month!=null and month!=''">
AND DATE_FORMAT(cpa.create_time,'%m') = #{month}
</if>
AND cpa.`status` = '2' AND cpa.status_type = '1'
</where>
GROUP BY cpa.pro_id
<if test="dispatchStatus!='0' and dispatchStatus!=null">
HAVING (CASE WHEN SUM(ANY_VALUE(cpa.dispatch_num)) = 0 OR SUM(ANY_VALUE(cpa.dispatch_num)) IS NULL THEN '2'
WHEN SUM(ANY_VALUE(cpa.dispatch_num)) = SUM(ANY_VALUE(cpa.need_num)) THEN '3'
ELSE '1' END = #{dispatchStatus})
</if>
</select>
</mapper>