| | |
| | | package com.consum.base.controller; |
| | | |
| | | import cn.afterturn.easypoi.excel.ExcelExportUtil; |
| | | import cn.afterturn.easypoi.excel.entity.TemplateExportParams; |
| | | import cn.hutool.core.util.ReflectUtil; |
| | | import java.io.IOException; |
| | | import java.lang.reflect.Field; |
| | | import java.util.ArrayList; |
| | | import java.util.HashMap; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | import java.util.Optional; |
| | | |
| | | import javax.annotation.Resource; |
| | | import javax.servlet.http.HttpServletResponse; |
| | | |
| | | import org.apache.commons.compress.utils.Lists; |
| | | import org.apache.poi.ss.usermodel.Workbook; |
| | | import org.springframework.beans.BeanUtils; |
| | | import org.springframework.web.bind.annotation.DeleteMapping; |
| | | 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.springframework.web.multipart.MultipartFile; |
| | | |
| | | import com.alibaba.excel.EasyExcelFactory; |
| | | import com.alibaba.excel.context.AnalysisContext; |
| | | import com.alibaba.excel.event.AnalysisEventListener; |
| | | import com.alibaba.excel.exception.ExcelDataConvertException; |
| | | import com.consum.base.BaseController; |
| | | import com.consum.base.core.utils.CommonUtil; |
| | | import com.consum.base.core.utils.PageUtil; |
| | | import com.consum.base.pojo.LWhFormProcureGoodsInfoParam; |
| | | import com.consum.base.pojo.LWhFormProcureParam; |
| | | import com.consum.base.pojo.dto.GoodModelInfoDTO; |
| | | import com.consum.base.pojo.excel.ImportProcureOrderTemplate; |
| | | import com.consum.base.pojo.excel.ProcureExcelTemplate; |
| | | import com.consum.base.pojo.query.FormProcureQry; |
| | | import com.consum.base.pojo.response.*; |
| | | import com.consum.base.pojo.response.FormProcureVO; |
| | | import com.consum.base.pojo.response.GoodsModelVO; |
| | | import com.consum.base.pojo.response.GoodsTemplateCountVO; |
| | | import com.consum.base.pojo.response.GoodsTemplateInfoVO; |
| | | import com.consum.base.pojo.response.LWhFormProcureExtendVO; |
| | | import com.consum.base.service.BaseCategoryService; |
| | | import com.consum.base.service.LWhFormProcureGoodsService; |
| | | import com.consum.base.service.LWhFormProcureService; |
| | | import com.consum.base.service.LWhProcureModelService; |
| | | import com.consum.base.service.impl.LWhFormProcureCoreService; |
| | | import com.consum.base.service.core.LWhFormProcureCoreService; |
| | | import com.consum.model.po.BaseCategory; |
| | | import com.consum.model.po.FinSysTenantUser; |
| | | import com.consum.model.po.LWhFormProcure; |
| | | import com.consum.model.po.LWhFormProcureGoods; |
| | |
| | | import com.walker.infrastructure.utils.CollectionUtils; |
| | | import com.walker.infrastructure.utils.DateUtils; |
| | | import com.walker.web.ResponseValue; |
| | | |
| | | import cn.afterturn.easypoi.excel.ExcelExportUtil; |
| | | import cn.afterturn.easypoi.excel.entity.TemplateExportParams; |
| | | import cn.hutool.core.util.ReflectUtil; |
| | | import io.swagger.annotations.Api; |
| | | import io.swagger.annotations.ApiImplicitParam; |
| | | import io.swagger.annotations.ApiImplicitParams; |
| | | import io.swagger.annotations.ApiOperation; |
| | | import org.apache.commons.compress.utils.Lists; |
| | | import org.apache.poi.ss.usermodel.Workbook; |
| | | import org.springframework.beans.BeanUtils; |
| | | import org.springframework.web.bind.annotation.*; |
| | | |
| | | import javax.annotation.Resource; |
| | | import javax.servlet.http.HttpServletResponse; |
| | | import java.lang.reflect.Field; |
| | | import java.util.*; |
| | | |
| | | /** |
| | | * @ClassName LWhFormProcureController |
| | |
| | | private LWhFormProcureCoreService lWhFormProcureCoreService; |
| | | @Resource |
| | | private LWhProcureModelService lWhProcureModelService; |
| | | @Resource |
| | | private BaseCategoryService baseCategoryService; |
| | | |
| | | /** |
| | | * @Description 新增 |
| | |
| | | } |
| | | try { |
| | | Field fieldDatas = GenericPager.class.getDeclaredField("datas"); |
| | | // fieldDatas.setAccessible(true); |
| | | // fieldDatas.set(genericPager, result); |
| | | ReflectUtil.setFieldValue(genericPager, fieldDatas, result); |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | |
| | | * 根据id查询详情 |
| | | */ |
| | | @GetMapping("/detail") |
| | | public ResponseValue getById(Long id) throws IllegalAccessException { |
| | | public ResponseValue getById(Long id) throws Exception { |
| | | if (id == null) { |
| | | return ResponseValue.error("采购单id为空"); |
| | | } |
| | |
| | | if (sysInfo == null) { |
| | | return ResponseValue.error("登录用户信息不存在"); |
| | | } |
| | | formProcureQry.setAgencyId(Long.valueOf(sysInfo.getTenantId())); |
| | | // formProcureQry.setAgencyId(Long.valueOf(sysInfo.getTenantId())); |
| | | GenericPager genericPager = lWhFormProcureService.queryFormProcureDetailList(formProcureQry); |
| | | return ResponseValue.success(genericPager); |
| | | } |
| | |
| | | map.put("totalAmount", totalAmount); |
| | | |
| | | Workbook workbook = ExcelExportUtil.exportExcel(params, ProcureExcelTemplate.class, exportList, map); |
| | | return ResponseValue.success(downLoadExcel("采购入库单", response, workbook)); |
| | | String filePath = downLoadExcel("采购入库单", workbook); |
| | | return ResponseValue.success("导出成功", filePath); |
| | | |
| | | } |
| | | |
| | | @ApiOperation(value = "采购单导入", notes = "采购单导入") |
| | | @PostMapping("/import") |
| | | public ResponseValue upload(MultipartFile file) throws IOException { |
| | | String originalFilename = file.getOriginalFilename(); |
| | | if (!".xls".endsWith(originalFilename)) { |
| | | return ResponseValue.error("文件格式有误!"); |
| | | } |
| | | FinSysTenantUser sysInfo = this.getSysInfo(); |
| | | if (sysInfo == null) { |
| | | return ResponseValue.error("当前登录用户为空"); |
| | | } |
| | | EasyExcelFactory.read(file.getInputStream(), ImportProcureOrderTemplate.class, |
| | | new AnalysisEventListener<ImportProcureOrderTemplate>() { |
| | | List<LWhFormProcureParam> list = Lists.newArrayList(); |
| | | |
| | | @Override |
| | | public void invoke(ImportProcureOrderTemplate data, AnalysisContext analysisContext) { |
| | | String categoryOne = data.getCategoryOne(); |
| | | String categoryTwo = data.getCategoryTwo(); |
| | | String categoryThree = data.getCategoryThree(); |
| | | String goodsName = data.getGoodsName(); |
| | | String goodModelName = data.getGoodModelName(); |
| | | String unit = data.getUnit(); |
| | | String type = data.getType(); |
| | | String agencyName = data.getAgencyName(); |
| | | String warehouseName = data.getWarehouseName(); |
| | | String supplierName = data.getSupplierName(); |
| | | String price = data.getPrice(); |
| | | String num = data.getNum(); |
| | | |
| | | BaseCategory baseCategory = baseCategoryService.getByCategoryByName(categoryThree); |
| | | Long categoryId = baseCategory.getId(); |
| | | |
| | | // Optional<BaseGoodsTemplateParam> optional = |
| | | // list.stream().filter(item -> item.getCategoryId().equals(categoryId)).findFirst(); |
| | | // |
| | | // if (optional.isPresent()) { |
| | | // BaseGoodsModels baseGoodsModels = new BaseGoodsModels(); |
| | | // baseGoodsModels.setModelName(goodModelName); |
| | | // baseGoodsModels.setUnit(unit); |
| | | // optional.get().getModels().add(baseGoodsModels); |
| | | // } else { |
| | | // BaseGoodsTemplateParam baseGoodsTemplate = new BaseGoodsTemplateParam(); |
| | | // baseGoodsTemplate.setCategoryId(categoryId); |
| | | // baseGoodsTemplate.setGoodsName(goodsName); |
| | | // baseGoodsTemplate.setStates(1); |
| | | // FinSysTenant finSysTenant = finSysTenantService.selectByName(agencyName); |
| | | // baseGoodsTemplate.setAgencyId(finSysTenant.getId()); |
| | | // baseGoodsTemplate.setAgencyName(agencyName); |
| | | // |
| | | // List<BaseGoodsModels> models = new ArrayList<>(); |
| | | // BaseGoodsModels baseGoodsModels = new BaseGoodsModels(); |
| | | // baseGoodsModels.setModelName(goodModelName); |
| | | // baseGoodsModels.setUnit(unit); |
| | | // models.add(baseGoodsModels); |
| | | // baseGoodsTemplate.setModels(models); |
| | | // |
| | | // list.add(baseGoodsTemplate); |
| | | // } |
| | | } |
| | | |
| | | @Override |
| | | public void doAfterAllAnalysed(AnalysisContext analysisContext) { |
| | | for (LWhFormProcureParam procureParam : list) { |
| | | // lWhFormProcureService.add(procureParam, null); |
| | | } |
| | | } |
| | | |
| | | @Override |
| | | public void onException(Exception exception, AnalysisContext analysisContext) throws Exception { |
| | | if (exception instanceof ExcelDataConvertException) { |
| | | ExcelDataConvertException excelDataConvertException = (ExcelDataConvertException)exception; |
| | | Integer row = excelDataConvertException.getRowIndex() + 1; |
| | | Integer column = excelDataConvertException.getColumnIndex() + 1; |
| | | throw new RuntimeException("第" + row + "行,第" + column + "列解析异常,请正确填写"); |
| | | } else { |
| | | throw new RuntimeException(exception.getMessage()); |
| | | } |
| | | } |
| | | }).sheet(0).doRead(); |
| | | |
| | | return ResponseValue.success("导入成功!"); |
| | | } |
| | | |
| | | } |