//package com.ruoyi.web.baseandprocure.controller;
//
//
//import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
//import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
//import com.ruoyi.common.core.domain.AjaxResult;
//import com.ruoyi.framework.web.service.TokenService;
//import com.ruoyi.web.baseandprocure.domain.ProcureSettlement;
//import com.ruoyi.web.baseandprocure.domain.ProcureSettlementGoods;
//import com.ruoyi.web.baseandprocure.service.IProcureSettlementGoodsService;
//import com.ruoyi.web.baseandprocure.service.IProcureSettlementService;
//import com.ruoyi.web.baseandprocure.service.IProcureSettlementGoodsService;
//import com.ruoyi.web.baseandprocure.service.IProcureSettlementService;
//import io.swagger.annotations.ApiOperation;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.transaction.annotation.Transactional;
//import org.springframework.web.bind.annotation.*;
//
//import javax.servlet.http.HttpServletRequest;
//import java.util.List;
//import java.util.Map;
//
//import static com.ruoyi.common.core.domain.AjaxResult.success;
//import static com.ruoyi.common.utils.SecurityUtils.getUsername;
//
///**
// * <p>
// * 采购结算单 前端控制器
// * </p>
// *
// * @author author
// * @since 2026-02-05
// */
//@RestController
//@RequestMapping("/procure-settlement")
//public class ProcureSettlementController {
//    @Autowired
//    private IProcureSettlementService settlementService;
//    @Autowired
//    private IProcureSettlementGoodsService goodsService;
//    @Autowired
//    private TokenService tokenService;
//
//    @ApiOperation("供应商报价单添加")
//    @PostMapping("/add")
//    @Transactional
//    public AjaxResult add(@RequestBody ProcureSettlement procureSettlement, HttpServletRequest request) throws Exception {
//        String loginOrgId = tokenService.getLoginOrgId(request);
//
//        String username = getUsername();
//        procureSettlement.setOrgId(loginOrgId);
//        procureSettlement.setCreateBy(username);
//        List<ProcureSettlementGoods> goods = procureSettlement.getGoods();
//        for (ProcureSettlementGoods good : goods) {
//            good.setOrgId(loginOrgId);
//            good.setCreateBy(username);
//            good.setReceivingNum(procureSettlement.getReceivingNum());
//            goodsService.save(good);
//        }
//
//        return success(settlementService.save(procureSettlement));
//    }
//
//    @ApiOperation("供应商报价单修改")
//    @PostMapping("/edit")
//    @Transactional
//    public AjaxResult edit(@RequestBody ProcureSettlement procureSettlement, HttpServletRequest request) throws Exception {
//        String loginOrgId = tokenService.getLoginOrgId(request);
//        if (settlementService.count(new QueryWrapper<ProcureSettlement>().ne("id",procureSettlement.getId()).eq("org_id",loginOrgId).eq("receiving_num", procureSettlement.getReceivingNum())) >0 ){
//            throw new Exception("该编号已存在");
//        }
//
//        String username = getUsername();
//        procureSettlement.setOrgId(loginOrgId);
//        procureSettlement.setCreateBy(username);
//        List<ProcureSettlementGoods> goods = procureSettlement.getGoods();
//        goodsService.remove(new QueryWrapper<ProcureSettlementGoods>().eq("receiving_num",procureSettlement.getReceivingNum()));
//        for (ProcureSettlementGoods good : goods) {
//            good.setOrgId(loginOrgId);
//            good.setCreateBy(username);
//            good.setReceivingNum(procureSettlement.getReceivingNum());
//            goodsService.save(good);
//        }
//        procureSettlement.setUpdateBy(username);
//
//        return success(settlementService.updateById(procureSettlement));
//    }
//
//    @ApiOperation("供应商报价单删除")
//    @PostMapping("/delete")
//    public AjaxResult delete(@RequestBody Map<String, String> paramsMap) {
//        String ids = paramsMap.get("ids");
//        for (String s : ids.split(",")) {
//            settlementService.removeById(s);
//        }
//        return success();
//    }
//
//    @ApiOperation("供应商报价单列表")
//    @PostMapping("/list")
//    public AjaxResult listAll( HttpServletRequest request){
//
//        return success(settlementService.list(new QueryWrapper<ProcureSettlement>().eq("org_id", tokenService.getLoginOrgId(request))));
//    }
//
//    @ApiOperation("供应商报价单分页")
//    @GetMapping("/page")
//    public AjaxResult page(@RequestParam("pageNum") Integer pageNum, @RequestParam("pageSize") Integer pageSize
//            , HttpServletRequest request) {
//        return success(settlementService.page(new Page<ProcureSettlement>(pageNum,pageSize),new QueryWrapper<ProcureSettlement>().eq("org_id", tokenService.getLoginOrgId(request))));
//    }
//
//    @ApiOperation("供应商报价单详情")
//    @PostMapping("/listById")
//    public AjaxResult listById(@RequestBody Map<String, String> paramsMap){
//        String id = paramsMap.get("id");
//        return success(settlementService.getById(id));
//    }
//}
