| | |
| | | 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 com.consum.base.BaseController; |
| | | import com.consum.base.core.utils.CommonUtil; |
| | | 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.LWhFormOutputParam; |
| | | import com.consum.base.pojo.excel.OutputExcelTemplate; |
| | | import com.consum.base.pojo.query.LWhFormOutputQry; |
| | | import com.consum.base.pojo.response.FormOutputGoodsVO; |
| | | import com.consum.base.pojo.response.FormOutputTemplateInfoVO; |
| | | import com.consum.base.pojo.response.FormOutputVO; |
| | | import com.consum.base.pojo.response.GoodsModelVO; |
| | | import com.consum.base.pojo.response.LWhFormOutputExtendVO; |
| | | import com.consum.base.service.LWarehouseFlowService; |
| | | import com.consum.base.service.LWhFormOutputServiceImpl; |
| | | import com.consum.base.service.LWhProcureModelService; |
| | | import com.consum.model.po.FinSysTenantUser; |
| | | import com.consum.model.po.LWhFormOutput; |
| | | import com.iplatform.model.po.S_user_core; |
| | | import com.walker.db.page.GenericPager; |
| | | import com.walker.infrastructure.utils.CollectionUtils; |
| | | import com.walker.infrastructure.utils.DateUtils; |
| | | import com.walker.web.ResponseValue; |
| | | import io.swagger.annotations.Api; |
| | | import io.swagger.annotations.ApiImplicitParam; |
| | | import io.swagger.annotations.ApiImplicitParams; |
| | | import io.swagger.annotations.ApiOperation; |
| | | import java.io.InputStream; |
| | | import java.lang.reflect.Field; |
| | | import java.util.HashMap; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | import java.util.Map.Entry; |
| | | import java.util.Optional; |
| | | import java.util.stream.Collectors; |
| | | |
| | | import javax.annotation.Resource; |
| | | import javax.servlet.http.HttpServletResponse; |
| | | |
| | | import org.apache.commons.compress.utils.Lists; |
| | | import org.apache.poi.hssf.usermodel.HSSFWorkbook; |
| | | import org.apache.poi.ss.usermodel.Workbook; |
| | |
| | | import org.springframework.web.bind.annotation.PostMapping; |
| | | import org.springframework.web.bind.annotation.RequestMapping; |
| | | import org.springframework.web.bind.annotation.RestController; |
| | | |
| | | import com.consum.base.BaseController; |
| | | import com.consum.base.core.utils.CommonUtil; |
| | | import com.consum.base.core.utils.CurrencyUtil; |
| | | import com.consum.base.core.utils.PageUtil; |
| | | import com.consum.base.pojo.LWhFormOutputParam; |
| | | import com.consum.base.pojo.dto.GoodModelInfoDTO; |
| | | import com.consum.base.pojo.excel.OutputExcelTemplate; |
| | | import com.consum.base.pojo.query.LWhFormOutputQry; |
| | | import com.consum.base.pojo.response.FormOutputVO; |
| | | 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.LWhFormOutputExtendVO; |
| | | import com.consum.base.service.LWarehouseFlowService; |
| | | import com.consum.base.service.LWhFormOutputService; |
| | | import com.consum.base.service.LWhProcureModelService; |
| | | import com.consum.model.po.FinSysTenantUser; |
| | | import com.consum.model.po.LWhFormOutput; |
| | | import com.iplatform.model.po.S_user_core; |
| | | import com.walker.db.page.GenericPager; |
| | | 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; |
| | | |
| | | /** |
| | | * @Description 出库单 |
| | |
| | | public class LWhFormOutputController extends BaseController { |
| | | |
| | | @Autowired |
| | | private LWhFormOutputServiceImpl lWhFormOutputService; |
| | | private LWhFormOutputService lWhFormOutputService; |
| | | @Autowired |
| | | private LWhProcureModelService lWhProcureModelService; |
| | | @Resource |
| | | private LWarehouseFlowService lWarehouseFlowService; |
| | | private LWarehouseFlowService lWarehouseFlowServiceImpl; |
| | | |
| | | /** |
| | | * @Description 新增出库单 |
| | |
| | | * @Date 2023/10/27 |
| | | */ |
| | | @ApiOperation(value = "新增出库单", notes = "新增出库单") |
| | | @ApiImplicitParams({ |
| | | @ApiImplicitParam(name = "param", value = "出库单实体", dataType = "lWhFormOutputParam", dataTypeClass = LWhFormOutputParam.class, paramType = "body") |
| | | }) |
| | | @ApiImplicitParams({@ApiImplicitParam(name = "param", value = "出库单实体", dataType = "lWhFormOutputParam", |
| | | dataTypeClass = LWhFormOutputParam.class, paramType = "body")}) |
| | | @PostMapping("/add") |
| | | public ResponseValue add() { |
| | | LWhFormOutputParam param = CommonUtil.getObjFromReqBody(LWhFormOutputParam.class); |
| | |
| | | * @Description 列表查询 |
| | | */ |
| | | @ApiOperation(value = "列表查询", notes = "列表查询") |
| | | @ApiImplicitParam(name = "param", value = "出库单实体", required = true, dataType = "LWhFormOutputParam", paramType = "query") |
| | | @ApiImplicitParam(name = "param", value = "出库单实体", required = true, dataType = "LWhFormOutputParam", |
| | | paramType = "query") |
| | | @GetMapping("/list") |
| | | public ResponseValue queryFormOutputList() { |
| | | LWhFormOutputQry param = CommonUtil.getObjFromReq(LWhFormOutputQry.class); |
| | |
| | | List<FormOutputVO> resultList = Lists.newArrayList(); |
| | | if (!CollectionUtils.isEmpty(data)) { |
| | | data.forEach(item -> { |
| | | // 查询型号数量 |
| | | FormOutputVO formOutputVO = new FormOutputVO(); |
| | | BeanUtils.copyProperties(item, formOutputVO); |
| | | |
| | | List<FormOutputTemplateInfoVO> procureTemplateInfoList = Lists.newArrayList(); |
| | | |
| | | // 查询型号数量 |
| | | String sql = "SELECT bgt.id,bgm.GOODS_TEMPLATES_ID,GOODS_NAME,sum( counts ) count FROM " |
| | | + "l_wh_procure_model pm LEFT JOIN base_goods_models bgm ON pm.BASE_GOODS_MODELS_ID = bgm.id " |
| | | + "LEFT JOIN base_goods_template bgt ON bgm.GOODS_TEMPLATES_ID = bgt.id " |
| | | + "WHERE pm.BUSINESS_ID =:id GROUP BY bgm.GOODS_TEMPLATES_ID"; |
| | | Map<String, Object> paramMap = new HashMap<>(); |
| | | paramMap.put("id", item.getId()); |
| | | List<Map<String, Object>> procureModelList = lWhProcureModelService.select(sql, paramMap, new MapperUtil()); |
| | | for (Map<String, Object> map : procureModelList) { |
| | | FormOutputTemplateInfoVO procureTemplateInfoVO = MapUtils.convertMapToObj(map, FormOutputTemplateInfoVO.class); |
| | | procureTemplateInfoList.add(procureTemplateInfoVO); |
| | | } |
| | | formOutputVO.setFormOutputTemplateInfoList(procureTemplateInfoList); |
| | | // 查询物品型号统计数量 |
| | | List<GoodsTemplateCountVO> goodsTemplateCount = |
| | | lWhProcureModelService.getGoodsTemplateCountByBusinessId(item.getId()); |
| | | formOutputVO.setFormOutputTemplateInfoList(goodsTemplateCount); |
| | | |
| | | resultList.add(formOutputVO); |
| | | }); |
| | | } |
| | | try { |
| | | Field fieldDatas = GenericPager.class.getDeclaredField("datas"); |
| | | // fieldDatas.setAccessible(true); |
| | | // fieldDatas.set(genericPager, resultList); |
| | | ReflectUtil.setFieldValue(genericPager, fieldDatas, resultList); |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | logger.error("查询出库单列表失败", e); |
| | | } |
| | | return ResponseValue.success(genericPager); |
| | | } |
| | |
| | | @ApiOperation(value = "根据id查询详情", notes = "根据id查询详情") |
| | | @ApiImplicitParam(name = "id", value = "出库单id", required = true, dataType = "Long", paramType = "query") |
| | | @GetMapping("/detail") |
| | | public ResponseValue getById(Long id) throws IllegalAccessException { |
| | | public ResponseValue getById(Long id) throws Exception { |
| | | if (id == null) { |
| | | return ResponseValue.error("出库单id为空"); |
| | | } |
| | |
| | | BeanUtils.copyProperties(lWhFormOutput, lWhFormOutputExtendVO); |
| | | lWhFormOutputExtendVO.setDoc(lWhFormOutput.getOutputDoc()); |
| | | |
| | | String sql = "SELECT bgt.id, CATEGORY_ID, CATEGORY_NAME, GOODS_NAME " |
| | | + "FROM l_wh_procure_model pm LEFT JOIN base_goods_models bgm ON bgm.id = pm.BASE_GOODS_MODELS_ID " |
| | | + "LEFT JOIN base_goods_template bgt ON bgt.id = bgm.GOODS_TEMPLATES_ID " |
| | | + "WHERE pm.BUSINESS_ID =:id GROUP BY bgt.id "; |
| | | Map<String, Object> paramMap = new HashMap<>(); |
| | | paramMap.put("id", lWhFormOutputExtendVO.getId()); |
| | | List<Map<String, Object>> procureModelList = lWhFormOutputService.select(sql, paramMap, new MapperUtil()); |
| | | List<FormOutputGoodsVO> fromOutputGoods = Lists.newArrayList(); |
| | | for (Map<String, Object> map : procureModelList) { |
| | | FormOutputGoodsVO procureTemplateInfoVO = MapUtils.convertMapToObj(map, FormOutputGoodsVO.class); |
| | | |
| | | // 查询型号数量 |
| | | List<GoodsModelVO> goodsModelVOList = Lists.newArrayList(); |
| | | String sql2 = "SELECT pm.id,pm.BASE_GOODS_MODELS_NAME,bgm.UNIT,COUNTS,total_amount " |
| | | + "FROM l_wh_procure_model pm LEFT JOIN base_goods_models bgm ON bgm.id = pm.BASE_GOODS_MODELS_ID " |
| | | + "LEFT JOIN base_goods_template bgt ON bgt.id = bgm.GOODS_TEMPLATES_ID " |
| | | + "WHERE pm.BUSINESS_ID =:id"; |
| | | List<Map<String, Object>> modelList = lWhFormOutputService.select(sql2, paramMap, new MapperUtil()); |
| | | modelList.forEach(item -> { |
| | | GoodsModelVO goodsModelVO = MapUtils.convertMapToObj(item, GoodsModelVO.class); |
| | | goodsModelVOList.add(goodsModelVO); |
| | | }); |
| | | procureTemplateInfoVO.setModels(goodsModelVOList); |
| | | fromOutputGoods.add(procureTemplateInfoVO); |
| | | List<GoodModelInfoDTO> goodsModelList = |
| | | lWhProcureModelService.getGoodsModelListByBusinessId(lWhFormOutputExtendVO.getId(), null); |
| | | if (CollectionUtils.isEmpty(goodsModelList)) { |
| | | return ResponseValue.success(lWhFormOutputExtendVO); |
| | | } |
| | | lWhFormOutputExtendVO.setFromOutputGoods(fromOutputGoods); |
| | | Map<Long, List<GoodModelInfoDTO>> collect = |
| | | goodsModelList.stream().collect(Collectors.groupingBy(GoodModelInfoDTO::getBaseGoodsTemplateId)); |
| | | List<GoodsTemplateInfoVO> goodsTemplateInfoList = Lists.newArrayList(); |
| | | for (Map.Entry<Long, List<GoodModelInfoDTO>> entry : collect.entrySet()) { |
| | | GoodsTemplateInfoVO goodsTemplateInfoVO = getFormOutputGoodsVO(entry); |
| | | goodsTemplateInfoList.add(goodsTemplateInfoVO); |
| | | } |
| | | lWhFormOutputExtendVO.setFromOutputGoods(goodsTemplateInfoList); |
| | | |
| | | return ResponseValue.success("查询成功!", lWhFormOutputExtendVO); |
| | | } |
| | | |
| | | private GoodsTemplateInfoVO getFormOutputGoodsVO(Entry<Long, List<GoodModelInfoDTO>> entry) { |
| | | Long baseGoodsTemplateId = entry.getKey(); |
| | | List<GoodModelInfoDTO> goodModelInfoDTOS = entry.getValue(); |
| | | GoodModelInfoDTO goodModelInfoDTO = goodModelInfoDTOS.stream().findFirst().orElse(null); |
| | | GoodsTemplateInfoVO goodsTemplateInfoVO = new GoodsTemplateInfoVO(); |
| | | if (goodModelInfoDTO != null) { |
| | | goodsTemplateInfoVO.setId(baseGoodsTemplateId); |
| | | goodsTemplateInfoVO.setCategoryName(goodModelInfoDTO.getCategoryName()); |
| | | goodsTemplateInfoVO.setGoodsName(goodModelInfoDTO.getBaseGoodsModelsName()); |
| | | } |
| | | List<GoodsModelVO> goodsModelList = Lists.newArrayList(); |
| | | for (GoodModelInfoDTO goodModelInfo : goodModelInfoDTOS) { |
| | | GoodsModelVO goodsModelVO = new GoodsModelVO(); |
| | | goodsModelVO.setId(goodModelInfo.getId()); |
| | | goodsModelVO.setBaseGoodsModelsName(goodModelInfo.getBaseGoodsModelsName()); |
| | | goodsModelVO.setUnit(goodModelInfo.getUnit()); |
| | | goodsModelVO.setCounts(goodModelInfo.getCounts()); |
| | | goodsModelVO.setTotalAmount(CurrencyUtil.convertFenToYuan(goodModelInfo.getTotalAmount())); |
| | | goodsModelList.add(goodsModelVO); |
| | | } |
| | | goodsTemplateInfoVO.setModels(goodsModelList); |
| | | return goodsTemplateInfoVO; |
| | | } |
| | | |
| | | @ApiOperation(value = "查询出库单详情明细", notes = "查询出库单详情明细") |
| | | @ApiImplicitParam(name = "formOutputQry", value = "出库单详情查询条件", required = true, dataType = "LWhFormOutputQry", paramType = "query") |
| | | @ApiImplicitParam(name = "formOutputQry", value = "出库单详情查询条件", required = true, dataType = "LWhFormOutputQry", |
| | | paramType = "query") |
| | | @GetMapping("/detail/list") |
| | | public ResponseValue queryFormOutputDetailList() { |
| | | LWhFormOutputQry formOutputQry = CommonUtil.getObjFromReq(LWhFormOutputQry.class); |
| | | S_user_core currentUser = this.getCurrentUser(); |
| | | FinSysTenantUser currentUser = this.getSysInfo(); |
| | | if (currentUser == null) { |
| | | return ResponseValue.error("登录用户信息不存在"); |
| | | } |
| | | PageUtil genericPager = lWarehouseFlowService.queryAllBusinessFlow(formOutputQry); |
| | | formOutputQry.setAgencyId(Long.valueOf(currentUser.getTenantId())); |
| | | PageUtil genericPager = lWarehouseFlowServiceImpl.queryAllBusinessFlow(formOutputQry); |
| | | return ResponseValue.success(genericPager); |
| | | } |
| | | |
| | | |
| | | @ApiOperation(value = "出库单导出", notes = "出库单导出") |
| | | @ApiImplicitParam(name = "id", value = "出库单id", required = true, dataType = "Long", paramType = "query") |
| | | @GetMapping("/list/export") |
| | | public void export(Long id, HttpServletResponse response) throws Exception { |
| | | public ResponseValue export(Long id, HttpServletResponse response) throws Exception { |
| | | FinSysTenantUser sysInfo = this.getSysInfo(); |
| | | if (sysInfo == null) { |
| | | throw new RuntimeException("登录用户信息不存在"); |
| | |
| | | if (CollectionUtils.isEmpty(exportList)) { |
| | | throw new RuntimeException("数据为空"); |
| | | } |
| | | int countNum = exportList.stream().filter(item -> item.getNum() != null).mapToInt(OutputExcelTemplate::getNum).sum(); |
| | | double totalAmount = exportList.stream().filter(item -> item.getTotalAmount() != null).mapToDouble(OutputExcelTemplate::getAmount).sum(); |
| | | int countNum = |
| | | exportList.stream().filter(item -> item.getNum() != null).mapToInt(OutputExcelTemplate::getNum).sum(); |
| | | double totalAmount = exportList.stream().filter(item -> item.getTotalAmount() != null) |
| | | .mapToDouble(OutputExcelTemplate::getAmount).sum(); |
| | | Optional<OutputExcelTemplate> first = exportList.stream().findFirst(); |
| | | OutputExcelTemplate templateExcelExport = first.get(); |
| | | String businessFormCode = templateExcelExport.getBusinessFormCode(); |
| | |
| | | map.put("totalAmount", totalAmount); |
| | | |
| | | Workbook workbook = ExcelExportUtil.exportExcel(params, OutputExcelTemplate.class, exportList, map); |
| | | downLoadExcel("出库单", response, workbook); |
| | | String filePath = downLoadExcel("出库单", workbook); |
| | | return ResponseValue.success("导出成功", filePath); |
| | | |
| | | } |
| | | |
| | | |
| | | } |
| | | |