|
|
@@ -0,0 +1,178 @@
|
|
|
+package com.ydtech.modules.admin.controller;
|
|
|
+
|
|
|
+
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
+import com.ydtech.core.page.HttpResult;
|
|
|
+import com.ydtech.modules.admin.model.SysDept;
|
|
|
+import com.ydtech.modules.admin.model.SysUser;
|
|
|
+import com.ydtech.modules.admin.model.po.SysOrganizationQuotation;
|
|
|
+import com.ydtech.modules.admin.model.po.SysQuotationTheme;
|
|
|
+import com.ydtech.modules.admin.model.vo.SysQuotationThemeVo;
|
|
|
+import com.ydtech.modules.admin.service.SysDeptService;
|
|
|
+import com.ydtech.modules.admin.service.SysOrganizationQuotationService;
|
|
|
+import com.ydtech.modules.admin.service.SysQuotationThemeService;
|
|
|
+import com.ydtech.modules.admin.service.SysUserService;
|
|
|
+import com.ydtech.modules.base.controller.BaseController;
|
|
|
+import com.ydtech.modules.protocol.utils.AssertionUtils;
|
|
|
+import io.swagger.annotations.Api;
|
|
|
+import io.swagger.annotations.ApiOperation;
|
|
|
+import lombok.RequiredArgsConstructor;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.web.bind.annotation.*;
|
|
|
+
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.Date;
|
|
|
+import java.util.List;
|
|
|
+
|
|
|
+
|
|
|
+@RestController
|
|
|
+@RequestMapping("/sys/quotation")
|
|
|
+@RequiredArgsConstructor
|
|
|
+@Api(tags = "报价单管理")
|
|
|
+public class SysQuotationController extends BaseController {
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private SysOrganizationQuotationService sysOrganizationQuotationService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private SysQuotationThemeService sysQuotationThemeService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private SysUserService sysUserService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private SysDeptService sysDeptService;
|
|
|
+
|
|
|
+
|
|
|
+ @ApiOperation(value = "分页查询报价单")
|
|
|
+ @PostMapping(value = "page")
|
|
|
+ public HttpResult<Page<SysQuotationTheme>> getpage(@RequestBody SysQuotationThemeVo sysQuotationThemeVo) {
|
|
|
+ Page<SysQuotationTheme> page = sysQuotationThemeService.getPage(sysQuotationThemeVo);
|
|
|
+ return HttpResult.ok(page);
|
|
|
+ }
|
|
|
+
|
|
|
+ @ApiOperation(value = "获取所有报价单主题")
|
|
|
+ @PostMapping(value = "list")
|
|
|
+ public HttpResult<List<SysQuotationTheme>> getlist() {
|
|
|
+ List<SysQuotationTheme> list = sysQuotationThemeService.list();
|
|
|
+ return HttpResult.ok(list);
|
|
|
+ }
|
|
|
+
|
|
|
+ @ApiOperation(value = "添加报价单主题")
|
|
|
+ @PostMapping(value = "/save/sysQuotationTheme")
|
|
|
+ public HttpResult<SysQuotationTheme> save(@RequestBody SysQuotationTheme sysQuotationTheme) {
|
|
|
+ SysQuotationTheme one = sysQuotationThemeService.getOne(new LambdaQueryWrapper<SysQuotationTheme>().eq(SysQuotationTheme::getThemeCode, sysQuotationTheme.getThemeCode()));
|
|
|
+ if (one != null) {
|
|
|
+ return HttpResult.error("code重复,请重新输入");
|
|
|
+ }
|
|
|
+ sysQuotationTheme.setUserId(getUserId());
|
|
|
+ sysQuotationTheme.setCreateTime(new Date());
|
|
|
+ boolean save = sysQuotationThemeService.save(sysQuotationTheme);
|
|
|
+ AssertionUtils.isSucceed(save, "添加失败");
|
|
|
+ return HttpResult.ok("添加成功");
|
|
|
+ }
|
|
|
+
|
|
|
+ @ApiOperation(value = "修改报价单主题")
|
|
|
+ @PostMapping(value = "/update/sysQuotationTheme")
|
|
|
+ public HttpResult<SysQuotationTheme> update(@RequestBody SysQuotationTheme sysQuotationTheme) {
|
|
|
+ SysQuotationTheme one = sysQuotationThemeService.getOne(new LambdaQueryWrapper<SysQuotationTheme>().eq(SysQuotationTheme::getThemeCode, sysQuotationTheme.getThemeCode()));
|
|
|
+ if (one != null) {
|
|
|
+ return HttpResult.error("code重复,请重新输入");
|
|
|
+ }
|
|
|
+ sysQuotationTheme.setUserId(getUserId());
|
|
|
+ sysQuotationTheme.setCreateTime(new Date());
|
|
|
+ boolean update = sysQuotationThemeService.updateById(sysQuotationTheme);
|
|
|
+ AssertionUtils.isSucceed(update, "修改失败");
|
|
|
+ return HttpResult.ok(sysQuotationTheme);
|
|
|
+ }
|
|
|
+
|
|
|
+ @ApiOperation(value = "删除报价单主题")
|
|
|
+ @PostMapping(value = "/delete/sysQuotationTheme")
|
|
|
+ public HttpResult<SysQuotationTheme> delete(@RequestBody SysQuotationTheme sysQuotationTheme) {
|
|
|
+ boolean delete = sysQuotationThemeService.removeById(sysQuotationTheme);
|
|
|
+ AssertionUtils.isSucceed(delete, "删除失败");
|
|
|
+ return HttpResult.ok("删除成功");
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ @ApiOperation(value = "获取树结构")
|
|
|
+ @GetMapping(value = "/findTree")
|
|
|
+ public HttpResult<List<SysDept>> findTree(String deptId, String managementSource) {
|
|
|
+ //获取主题报价单关联数据
|
|
|
+ List<SysOrganizationQuotation> quotations = sysOrganizationQuotationService.list();
|
|
|
+ //获取主题数据
|
|
|
+ List<SysQuotationTheme> quotationThemes = sysQuotationThemeService.list();
|
|
|
+ //获取机构数据
|
|
|
+ List<SysDept> Depts = sysDeptService.findTree(deptId, managementSource);
|
|
|
+ List<SysDept> DeptList = sysOrganizationQuotationService.findTree(quotations, quotationThemes, Depts);
|
|
|
+ return HttpResult.ok(DeptList);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ @ApiOperation(value = "报价单授权批量编辑")
|
|
|
+ @PostMapping(value = "/batch")
|
|
|
+ public HttpResult<SysOrganizationQuotation> batch(@RequestBody SysOrganizationQuotation sysOrganizationQuotation) {
|
|
|
+ // 构造查询条件,根据提供的组织ID集合查询出对应的报价单授权信息,然后进行删除
|
|
|
+ LambdaQueryWrapper<SysOrganizationQuotation> removeWrapper = new LambdaQueryWrapper<>();
|
|
|
+ removeWrapper.in(SysOrganizationQuotation::getOrganizationId, sysOrganizationQuotation.getOrganizationIds());
|
|
|
+ sysOrganizationQuotationService.remove(removeWrapper);
|
|
|
+ List<String> organizationIds = sysOrganizationQuotation.getOrganizationIds();
|
|
|
+ // 遍历组织ID集合,为每个组织ID构造新的报价单授权信息,并添加到待保存的列表中
|
|
|
+ ArrayList<SysOrganizationQuotation> quotations = new ArrayList<>();
|
|
|
+ for (String organizationId : organizationIds) {
|
|
|
+ SysOrganizationQuotation quotation = new SysOrganizationQuotation();
|
|
|
+ quotation.setOrganizationId(organizationId);
|
|
|
+ quotation.setThemeId(sysOrganizationQuotation.getThemeId());
|
|
|
+ quotation.setUserId(getUserId());
|
|
|
+ quotation.setCreateTime(new Date());
|
|
|
+ quotations.add(quotation);
|
|
|
+ }
|
|
|
+ // 批量保存新的报价单授权信息
|
|
|
+ boolean saveBatch = sysOrganizationQuotationService.saveBatch(quotations);
|
|
|
+ // 断言添加操作成功,若失败则抛出异常
|
|
|
+ AssertionUtils.isSucceed(saveBatch, "添加失败");
|
|
|
+ return HttpResult.ok("添加成功");
|
|
|
+ }
|
|
|
+
|
|
|
+ @ApiOperation(value = "报价单授权编辑")
|
|
|
+ @PostMapping(value = "/redact")
|
|
|
+ public HttpResult<SysOrganizationQuotation> redact(@RequestBody SysOrganizationQuotation sysOrganizationQuotation) {
|
|
|
+ // 构造查询条件,删除与新报价单组织ID相同的旧报价单
|
|
|
+ LambdaQueryWrapper<SysOrganizationQuotation> removeWrapper = new LambdaQueryWrapper<>();
|
|
|
+ removeWrapper.eq(SysOrganizationQuotation::getOrganizationId, sysOrganizationQuotation.getOrganizationId());
|
|
|
+ sysOrganizationQuotationService.remove(removeWrapper);
|
|
|
+ // 设置新报价单信息,包括用户ID和创建时间
|
|
|
+ sysOrganizationQuotation.setUserId(getUserId());
|
|
|
+ sysOrganizationQuotation.setCreateTime(new Date());
|
|
|
+ // 保存新的报价单信息
|
|
|
+ boolean save = sysOrganizationQuotationService.save(sysOrganizationQuotation);
|
|
|
+ // 断言新增操作成功
|
|
|
+ AssertionUtils.isSucceed(save, "添加失败");
|
|
|
+ return HttpResult.ok("添加成功");
|
|
|
+ }
|
|
|
+
|
|
|
+ @ApiOperation(value = "报价单授权编辑回填")
|
|
|
+ @GetMapping(value = "/get/{id}")
|
|
|
+ public HttpResult<SysOrganizationQuotation> getSysOrganizationQuotation(@PathVariable String id) {
|
|
|
+ LambdaQueryWrapper<SysOrganizationQuotation> queryWrapper = new LambdaQueryWrapper<>();
|
|
|
+ queryWrapper.eq(SysOrganizationQuotation::getOrganizationId, id);
|
|
|
+ SysOrganizationQuotation serviceOne = sysOrganizationQuotationService.getOne(queryWrapper);
|
|
|
+ return HttpResult.ok(serviceOne);
|
|
|
+ }
|
|
|
+
|
|
|
+ @ApiOperation(value = "获取用户对应报价单")
|
|
|
+ @GetMapping(value = "/getThemeByUserId")
|
|
|
+ public HttpResult<SysOrganizationQuotation> getThemeByUserId() {
|
|
|
+ SysUser user = getUser();
|
|
|
+ String deptId = user.getDeptId();
|
|
|
+ LambdaQueryWrapper<SysOrganizationQuotation> oQueryWrapper = new LambdaQueryWrapper<>();
|
|
|
+ oQueryWrapper.eq(SysOrganizationQuotation::getOrganizationId, deptId);
|
|
|
+ SysOrganizationQuotation quotationServiceOne = sysOrganizationQuotationService.getOne(oQueryWrapper);
|
|
|
+ if (quotationServiceOne == null) {
|
|
|
+ quotationServiceOne = new SysOrganizationQuotation();
|
|
|
+ quotationServiceOne.setThemeCode("QD");
|
|
|
+ }
|
|
|
+ return HttpResult.ok(quotationServiceOne);
|
|
|
+ }
|
|
|
+}
|