package com.consum.base.controller; import com.consum.base.BaseController; import com.consum.base.pojo.LWhFormScrappedExtend; import com.consum.base.pojo.LWhFormScrappedParam; import com.consum.base.service.LWhFormScrappedGoodsService; import com.consum.base.service.LWhFormScrappedServiceImpl; import com.consum.model.po.FinSysTenantUser; import com.consum.model.po.LWhFormScrapped; import com.consum.model.po.LWhFormScrappedGoods; import com.walker.db.page.GenericPager; import com.walker.infrastructure.utils.CollectionUtils; import com.walker.web.ResponseValue; import java.lang.reflect.Field; import java.util.ArrayList; import java.util.List; import java.util.Map; import org.springframework.beans.BeanUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; /** * @Description 报废单 * @Author 卢庆阳 * @Date 2023/11/1 */ @RestController @RequestMapping("/pc/l/wh/form/scrapped") public class LWhFormScrappedController extends BaseController { @Autowired private LWhFormScrappedServiceImpl lWhFormScrappedService; @Autowired private LWhFormScrappedGoodsService scrappedGoodsService; /** * @Description 新增报废单 * @Author 卢庆阳 * @Date 2023/11/1 */ @PostMapping("/add") public ResponseValue add(@RequestBody LWhFormScrappedParam param) { FinSysTenantUser sysInfo = this.getSysInfo(); int result = this.lWhFormScrappedService.add(param, this.getCurrentUser(), sysInfo); if (result > 0) { return ResponseValue.success(1); } return ResponseValue.error("新增失败!"); } /** * @Description 列表查询 * @Author 卢庆阳 * @Date 2023/11/02 */ //1.查询报废单 //2.查询报废单物品 @GetMapping("/list") public ResponseValue queryList(LWhFormScrappedParam param) { FinSysTenantUser sysInfo = getSysInfo(); if (sysInfo == null) { return ResponseValue.error("登录用户信息不存在"); } GenericPager genericPager = lWhFormScrappedService.queryList(param, sysInfo); List datas = genericPager.getDatas(); ArrayList newDatas = new ArrayList<>(); if (!CollectionUtils.isEmpty(datas)) { datas.forEach(item -> { // 查询报废单物品 LWhFormScrappedGoods scrappedGoods = new LWhFormScrappedGoods(); scrappedGoods.setFormScrappedId(item.getId()); List scrappedGoodsList = scrappedGoodsService.select(scrappedGoods); LWhFormScrappedExtend formScrappedExtend = new LWhFormScrappedExtend(); BeanUtils.copyProperties(item, formScrappedExtend); formScrappedExtend.setScrappedGoodsList(scrappedGoodsList); newDatas.add(formScrappedExtend); }); } try { Field fieldDatas = GenericPager.class.getDeclaredField("datas"); fieldDatas.setAccessible(true); fieldDatas.set(genericPager, newDatas); } catch (Exception e) { e.printStackTrace(); } // genericPager.setDatas(newDatas); return ResponseValue.success(genericPager); } /** * @Description 根据id查询详情 * @Author 卢庆阳 * @Date 2023/11/2 */ @GetMapping("/detail") public ResponseValue getById(Long id) { if (id == null) { return ResponseValue.error("报废单id为空"); } LWhFormScrappedExtend scrappedExtend = this.lWhFormScrappedService.getById(id); return ResponseValue.success(scrappedExtend); } /** * 报废明细 * * @param param * @return */ @GetMapping("/list/detailList") public ResponseValue queryDetailList(LWhFormScrappedParam param) { FinSysTenantUser sysInfo = this.getSysInfo(); if (sysInfo == null) { return ResponseValue.error("登录用户信息不存在"); } GenericPager> genericPager = lWhFormScrappedService.queryDetailList(param, sysInfo); return ResponseValue.success(genericPager); } /** * @Description 导出报废登记单 * @Author 卢庆阳 * @Date 2023/11/2 */ @GetMapping("/export") public ResponseValue export(Long id) { if (id == null) { return ResponseValue.error("报废单id为空"); } LWhFormScrappedExtend scrappedExtend = this.lWhFormScrappedService.export(id, this.getSysInfo()); return ResponseValue.success(scrappedExtend); } }