| | |
| | | package com.consum.base.service; |
| | | |
| | | import com.consum.base.core.utils.MapUtils; |
| | | import com.consum.base.core.utils.MapperUtil; |
| | | import com.consum.base.core.utils.PageUtil; |
| | | import com.consum.base.pojo.excel.TemplateExcelExport; |
| | | import com.consum.base.pojo.query.FormProcureQry; |
| | | import com.consum.model.po.LWhFormProcure; |
| | | import com.walker.db.page.GenericPager; |
| | | import com.walker.infrastructure.utils.CollectionUtils; |
| | | import com.walker.infrastructure.utils.DateUtils; |
| | | import com.walker.infrastructure.utils.StringUtils; |
| | | import com.walker.jdbc.service.BaseServiceImpl; |
| | | import java.util.HashMap; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | import java.util.Optional; |
| | | import org.apache.commons.compress.utils.Lists; |
| | | import org.springframework.stereotype.Service; |
| | | |
| | | /** |
| | |
| | | |
| | | } |
| | | |
| | | public Map<String, Object> getExportList(Long id, String userName) { |
| | | String sql = "SELECT\n" |
| | | + "\tfp.BUSINESS_FORM_CODE,\n" |
| | | + "\tfp.AGENCY_NAME tenantName,\n" |
| | | + "\tGOODS_NAME goodsName,\n" |
| | | + "\tpm.BASE_GOODS_MODELS_NAME goodsModeName,\n" |
| | | + "\tcounts num,\n" |
| | | + "\tprice,\n" |
| | | + "\ttotal_amount totalAmount,\n" |
| | | + "\tWAREHOUSE_NAME,\n" |
| | | + "\tBEIZ remark\n" |
| | | + "FROM\n" |
| | | + "\tl_wh_procure_model pm\n" |
| | | + "\tLEFT JOIN base_goods_models bgm ON pm.BASE_GOODS_MODELS_ID = bgm.id\n" |
| | | + "\tLEFT JOIN base_goods_template bgt ON bgm.GOODS_TEMPLATES_ID = bgt.id\n" |
| | | + "\tLEFT JOIN l_wh_form_procure fp ON fp.ID = pm.BUSINESS_ID\n" |
| | | + "WHERE\n" |
| | | + "\tpm.BUSINESS_ID = :id"; |
| | | Map<String, Object> param = new HashMap<>(); |
| | | param.put("id", id); |
| | | List<Map<String, Object>> select = this.select(sql, param, new MapperUtil()); |
| | | if (CollectionUtils.isEmpty(select)) { |
| | | return null; |
| | | } |
| | | |
| | | List<TemplateExcelExport> list = Lists.newArrayList(); |
| | | select.forEach(item -> { |
| | | TemplateExcelExport templateExcelExport = MapUtils.convertMapToObj(item, TemplateExcelExport.class); |
| | | templateExcelExport.setTotalAmount(templateExcelExport.getTotalAmount() == null ? 0 : templateExcelExport.getTotalAmount()); |
| | | templateExcelExport.setNum(templateExcelExport.getNum() == null ? 0 : templateExcelExport.getNum()); |
| | | templateExcelExport.setTenantName(StringUtils.isNotEmpty(templateExcelExport.getTenantName()) ? templateExcelExport.getTenantName() : ""); |
| | | templateExcelExport.setRemark(StringUtils.isNotEmpty(templateExcelExport.getRemark()) ? templateExcelExport.getRemark() : ""); |
| | | list.add(templateExcelExport); |
| | | }); |
| | | int sum = list.stream().filter(item -> item.getNum() != null).mapToInt(TemplateExcelExport::getNum).sum(); |
| | | int totalAmount = list.stream().filter(export -> export.getTotalAmount() != null).mapToInt(TemplateExcelExport::getTotalAmount).sum(); |
| | | Optional<TemplateExcelExport> first = list.stream().findFirst(); |
| | | TemplateExcelExport templateExcelExport = first.get(); |
| | | String businessFormCode = templateExcelExport.getBusinessFormCode(); |
| | | |
| | | String dateForHuman = DateUtils.getDateForHuman(System.currentTimeMillis()); |
| | | Map<String, Object> map = new HashMap<>(); |
| | | map.put("code", businessFormCode); |
| | | map.put("date", dateForHuman); |
| | | map.put("name", userName); |
| | | map.put("sum", sum); |
| | | map.put("totalAmount", totalAmount); |
| | | map.put("data", list); |
| | | return map; |
| | | |
| | | } |
| | | } |