| | |
| | | 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.pojo.*; |
| | | import com.consum.base.service.BaseCategoryServiceImpl; |
| | | 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.pojo.LWhFormOutputParam; |
| | | 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.model.po.*; |
| | | import com.consum.base.service.LWhGoodsService; |
| | | 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.StringUtils; |
| | | 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.IOException; |
| | | import java.io.OutputStream; |
| | | import java.lang.reflect.Field; |
| | | import java.net.URLEncoder; |
| | | import java.util.ArrayList; |
| | | import java.util.HashMap; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | import javax.annotation.Resource; |
| | | import javax.servlet.http.HttpServletRequest; |
| | | 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.beans.factory.annotation.Autowired; |
| | | import org.springframework.web.bind.annotation.*; |
| | | |
| | | import java.lang.reflect.Field; |
| | | import java.util.ArrayList; |
| | | import java.util.List; |
| | | 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; |
| | | |
| | | /** |
| | | * @Description 出库单 |
| | | * @Author 卢庆阳 |
| | | * @Date 2023/10/27 |
| | | */ |
| | | @Api(value = "出库单", tags = "出库单") |
| | | @RestController |
| | | @RequestMapping("/pc/l/wh/form/output") |
| | | public class LWhFormOutputController extends BaseController { |
| | | |
| | | @Autowired |
| | | private LWhFormOutputServiceImpl lWhFormOutputService; |
| | | @Autowired |
| | | private LWhProcureModelService lWhProcureModelService; |
| | | @Autowired |
| | | private LWhGoodsService lWhGoodsService; |
| | | @Resource |
| | | private LWarehouseFlowService lWarehouseFlowService; |
| | | |
| | | /** |
| | | * @Description 新增出库单 |
| | | * @Author 卢庆阳 |
| | | * @Date 2023/10/27 |
| | | */ |
| | | @ApiOperation(value = "新增出库单", notes = "新增出库单") |
| | | @ApiImplicitParams({ |
| | | @ApiImplicitParam(name = "param", value = "出库单实体", dataType = "lWhFormOutputParam", dataTypeClass = LWhFormOutputParam.class, paramType = "body") |
| | | }) |
| | | @PostMapping("/add") |
| | | public ResponseValue add(@RequestBody LWhFormOutputParam param) { |
| | | public ResponseValue add() { |
| | | LWhFormOutputParam param = CommonUtil.getObjFromReqBody(LWhFormOutputParam.class); |
| | | S_user_core currentUser = this.getCurrentUser(); |
| | | if (currentUser == null) { |
| | | return ResponseValue.error("登录用户信息不存在"); |
| | | } |
| | | int result = this.lWhFormOutputService.add(param, currentUser,this.getSysInfo()); |
| | | if (result > 0) return ResponseValue.success(1); |
| | | int result = this.lWhFormOutputService.add(param, currentUser, this.getSysInfo()); |
| | | if (result > 0) { |
| | | return ResponseValue.success(1); |
| | | } |
| | | return ResponseValue.error("新增失败!"); |
| | | } |
| | | |
| | | /** |
| | | * @Description 列表查询 |
| | | */ |
| | | @ApiOperation(value = "列表查询", notes = "列表查询") |
| | | @ApiImplicitParam(name = "param", value = "出库单实体", required = true, dataType = "LWhFormOutputParam", paramType = "query") |
| | | @GetMapping("/list") |
| | | public ResponseValue queryFormOutputList(LWhFormOutputParam param) { |
| | | public ResponseValue queryFormOutputList() { |
| | | LWhFormOutputQry param = CommonUtil.getObjFromReq(LWhFormOutputQry.class); |
| | | S_user_core currentUser = this.getCurrentUser(); |
| | | if (currentUser == null) { |
| | | return ResponseValue.error("登录用户信息不存在"); |
| | | } |
| | | FinSysTenantUser sysInfo = getSysInfo(); |
| | | |
| | | //只能查询本级 及以下机构的出库单 |
| | | //?????? |
| | | |
| | | /*当前登录人只能看到自己机构下的列表*/ |
| | | FinSysTenantUser sysInfo = this.getSysInfo(); |
| | | String tenantId = sysInfo.getTenantId(); |
| | | if (param.getAgencyId() == null) { |
| | | param.setAgencyId(Long.valueOf(tenantId)); |
| | | } |
| | | GenericPager genericPager = lWhFormOutputService.queryFormOutputList(param); |
| | | List<LWhFormOutput> datas = genericPager.getDatas(); |
| | | ArrayList<LWhFormProcureExtend> newDatas = new ArrayList<>(); |
| | | if (!CollectionUtils.isEmpty(datas)) { |
| | | datas.forEach(item -> { |
| | | List<LWhFormOutput> data = genericPager.getDatas(); |
| | | |
| | | List<FormOutputVO> resultList = Lists.newArrayList(); |
| | | if (!CollectionUtils.isEmpty(data)) { |
| | | data.forEach(item -> { |
| | | // 查询型号数量 |
| | | LWhProcureModel lWhProcureModel = new LWhProcureModel(); |
| | | lWhProcureModel.setBusinessType(3); |
| | | lWhProcureModel.setBusinessId(item.getId()); |
| | | List<LWhProcureModel> models = lWhFormOutputService.select(lWhProcureModel); |
| | | LWhFormProcureExtend formProcureExtend = new LWhFormProcureExtend(); |
| | | BeanUtils.copyProperties(item, formProcureExtend); |
| | | formProcureExtend.setModels(models); |
| | | newDatas.add(formProcureExtend); |
| | | 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); |
| | | |
| | | resultList.add(formOutputVO); |
| | | }); |
| | | } |
| | | try { |
| | | Field fieldDatas = GenericPager.class.getDeclaredField("datas"); |
| | | fieldDatas.setAccessible(true); |
| | | fieldDatas.set(genericPager, newDatas); |
| | | // fieldDatas.setAccessible(true); |
| | | // fieldDatas.set(genericPager, resultList); |
| | | ReflectUtil.setFieldValue(genericPager, fieldDatas, resultList); |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | } |
| | | // genericPager.setDatas(newDatas); |
| | | return ResponseValue.success(genericPager); |
| | | } |
| | | |
| | | /** |
| | | * 根据id查询详情 |
| | | */ |
| | | @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 { |
| | | if (id == null) { |
| | | return ResponseValue.error("出库单id为空"); |
| | | } |
| | | LWhFormOutput lWhFormOutput = lWhFormOutputService.get(new LWhFormOutput(id)); |
| | | LWhFormOutputExtend formOutputExtend = new LWhFormOutputExtend(); |
| | | BeanUtils.copyProperties(lWhFormOutput, formOutputExtend); |
| | | LWhFormOutputExtendVO lWhFormOutputExtendVO = new LWhFormOutputExtendVO(); |
| | | BeanUtils.copyProperties(lWhFormOutput, lWhFormOutputExtendVO); |
| | | |
| | | // 物品 |
| | | LWhFormProcureGoods lWhFormProcureGoods = new LWhFormProcureGoods(); |
| | | lWhFormProcureGoods.setWhFormProcureId(id); |
| | | List<LWhFormProcureGoods> formProcureGoods = lWhFormOutputService.select(lWhFormProcureGoods); |
| | | |
| | | Field fieldModels = null; |
| | | try { |
| | | fieldModels = LWhFormProcureGoodsParams.class.getDeclaredField("models"); |
| | | } catch (NoSuchFieldException e) { |
| | | e.printStackTrace(); |
| | | } |
| | | fieldModels.setAccessible(true); |
| | | ArrayList<LWhFormProcureGoodsParams> procureGoodsParams = new ArrayList<>(); |
| | | for (LWhFormProcureGoods formProcureGood : formProcureGoods) { |
| | | LWhFormProcureGoodsParams lWhFormProcureGoodsParams = new LWhFormProcureGoodsParams(); |
| | | BeanUtils.copyProperties(formProcureGood, lWhFormProcureGoodsParams); |
| | | 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); |
| | | |
| | | // 查询型号数量 |
| | | LWhProcureModel lWhProcureModel = new LWhProcureModel(); |
| | | lWhProcureModel.setFromProcureGoodsId(formProcureGood.getId()); |
| | | List<LWhProcureModel> models = lWhFormOutputService.select(lWhProcureModel); |
| | | fieldModels.set(lWhFormProcureGoodsParams, models); |
| | | procureGoodsParams.add(lWhFormProcureGoodsParams); |
| | | 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); |
| | | } |
| | | formOutputExtend.setProcureGoods(procureGoodsParams); |
| | | return ResponseValue.success("查询成功!", formOutputExtend); |
| | | lWhFormOutputExtendVO.setFromOutputGoods(fromOutputGoods); |
| | | |
| | | return ResponseValue.success("查询成功!", lWhFormOutputExtendVO); |
| | | } |
| | | |
| | | |
| | | @ApiOperation(value = "查询出库单详情明细", notes = "查询出库单详情明细") |
| | | @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(); |
| | | if (currentUser == null) { |
| | | return ResponseValue.error("登录用户信息不存在"); |
| | | } |
| | | GenericPager<Map<String, Object>> genericPager = lWarehouseFlowService.queryAllBusinessFlow(formOutputQry); |
| | | return ResponseValue.success(genericPager); |
| | | } |
| | | |
| | | |
| | | @ApiOperation(value = "出库单导出", notes = "出库单导出") |
| | | @GetMapping("/list/export") |
| | | public void export(Long id, HttpServletRequest request, HttpServletResponse response) throws IOException { |
| | | TemplateExportParams params = new TemplateExportParams( |
| | | "import/采购退货单.xls"); |
| | | |
| | | FinSysTenantUser sysInfo = this.getSysInfo(); |
| | | String userName = sysInfo.getUserName(); |
| | | |
| | | String sql = "SELECT\n" |
| | | + "\tfo.BUSINESS_FORM_CODE,\n" |
| | | + "\tfo.AGENCY_NAME tenantName,\n" |
| | | + "\tGOODS_NAME goodsName,\n" |
| | | + "\tpm.BASE_GOODS_MODELS_NAME goodsModeName,\n" |
| | | + "\tcounts num,\n" |
| | | + "\ttotal_amount sqje,\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_output fo ON fo.ID = pm.BUSINESS_ID\n" |
| | | + "WHERE\n" |
| | | + "\tpm.BUSINESS_ID = 1393373943914496"; |
| | | |
| | | Map<String, Object> param = new HashMap<>(); |
| | | param.put("id", id); |
| | | List<Map<String, Object>> select = lWhFormOutputService.select(sql, param, new MapperUtil()); |
| | | |
| | | String dateForHuman = DateUtils.getDateForHuman(System.currentTimeMillis()); |
| | | Map<String, Object> map = new HashMap<>(); |
| | | //获取select中的BUSINESS_FORM_CODE值, |
| | | for (Map<String, Object> item : select) { |
| | | String businessFormCode = (String) item.get("businessFormCode"); |
| | | map.put("code", businessFormCode); |
| | | Object num = item.get("num"); |
| | | map.put("numCount", 100); |
| | | map.put("amountCount", 100); |
| | | } |
| | | List<Map<String, String>> listMap = new ArrayList<>(); |
| | | map.put("code", "贰佰万"); |
| | | map.put("date", dateForHuman); |
| | | map.put("name", userName); |
| | | // for (int i = 0; i < 4; i++) { |
| | | // Map<String, String> lm = new HashMap<>(); |
| | | // lm.put("tenantName", i + 1 + ""); |
| | | // lm.put("goodsName", "A001"); |
| | | // lm.put("goodsModeName", "设计"); |
| | | // lm.put("num", "EasyPoi " + i + "期"); |
| | | // lm.put("price", "开源项目"); |
| | | // lm.put("sqje", i * 10000 + ""); |
| | | // lm.put("remark", i * 10000 + ""); |
| | | // listMap.add(lm); |
| | | // } |
| | | map.put("maplist", select); |
| | | |
| | | Workbook workbook = ExcelExportUtil.exportExcel(params, map); |
| | | |
| | | try (OutputStream outputStream = response.getOutputStream()) { |
| | | response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet;charset=utf-8"); |
| | | response.setHeader("Content-disposition", "attachment;filename=" + URLEncoder.encode("采购退货单.xls", "utf-8")); |
| | | workbook.write(outputStream); |
| | | workbook.close(); |
| | | } |
| | | } |
| | | |
| | | } |
| | | |