package com.ydtech.modules.esm.controller; import cn.hutool.core.bean.BeanUtil; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport; import com.ydtech.aop.request.RequestSingleParam; import com.ydtech.constants.enums.dict.agreement.SupplierTypeEnum; import com.ydtech.core.page.HttpResult; import com.ydtech.core.page.PageRequest; import com.ydtech.core.page.PageResult; import com.ydtech.exception.SystemException; import com.ydtech.modules.admin.model.SysDept; import com.ydtech.modules.base.controller.BaseController; import com.ydtech.modules.esm.model.EsmInsCompany; import com.ydtech.modules.esm.model.vo.req.EsmInsCompanyReq; import com.ydtech.modules.esm.model.vo.res.EsmInsCompanyResVo; import com.ydtech.modules.esm.service.EsmInsCompanyService; import com.ydtech.modules.protocol.utils.AssertionUtils; import com.ydtech.utils.StringUtils; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import org.springframework.web.bind.annotation.*; import java.util.List; /** * --------------------------- * 保险公司机构管理 (EsmInsCompanyController) * --------------------------- * 作者: * --------------------------- */ @Api(tags = "保险公司机构管理") @RestController @RequestMapping("esmInsCompany") public class EsmInsCompanyController extends BaseController { private final EsmInsCompanyService esmInsCompanyService; public EsmInsCompanyController(EsmInsCompanyService esmInsCompanyService) { this.esmInsCompanyService = esmInsCompanyService; } @PostMapping("/findLeftInsTree") @ApiOperation("查询左侧树") public HttpResult> findLeftInsTree(@RequestSingleParam("type") String type) { LambdaQueryWrapper wrapper = new LambdaQueryWrapper<>(); wrapper.eq(StringUtils.isNullOrEmpty(type), EsmInsCompany::getType, type); List lst = esmInsCompanyService.list(wrapper); return HttpResult.ok(lst); } @PostMapping("/findTree") @ApiOperation(value = "获取树结构") public HttpResult> findTree(@RequestBody EsmInsCompanyReq req) { return HttpResult.ok(esmInsCompanyService.findTree(req)); } @PostMapping(value = "/saveInsCompany") @ApiOperation(value = "保存信息") @ApiOperationSupport(ignoreParameters = "children") public HttpResult save(@RequestBody EsmInsCompany esmInsCompany) { if (StringUtils.isNullOrEmpty(esmInsCompany.getId())) return HttpResult.ok("编号必填"); LambdaQueryWrapper lqw = new LambdaQueryWrapper<>(); lqw.eq(EsmInsCompany::getId, esmInsCompany.getId()); long i = esmInsCompanyService.count(lqw); AssertionUtils.isFail(i > 0, "供应商编码重复"); esmInsCompanyService.save(esmInsCompany); return HttpResult.ok("保存成功"); } @PostMapping(value = "/editInsCompany") @ApiOperation(value = "修改信息") @ApiOperationSupport(ignoreParameters = "record.children") public HttpResult update(@RequestBody EsmInsCompany esmInsCompany) { LambdaQueryWrapper lqw = new LambdaQueryWrapper<>(); lqw.eq(EsmInsCompany::getId, esmInsCompany.getId()); long i = esmInsCompanyService.count(lqw); AssertionUtils.isFail(i > 1, "供应商编码重复"); esmInsCompanyService.updateById(esmInsCompany); return HttpResult.ok("修改成功"); } /** * 查询下级机构列表 * * @param parentid * @return */ @ApiOperation(value = "查询下级机构列表") @PostMapping(value = "/selectList") public HttpResult> selectList(@RequestParam String parentid) { if (StringUtils.isNullOrEmpty(parentid)) parentid = "0"; LambdaQueryWrapper lqw = new LambdaQueryWrapper<>(); lqw.eq(EsmInsCompany::getParentId, parentid); List selectList = esmInsCompanyService.list(lqw); return HttpResult.ok(selectList); } /** * 根据主键查询 * * @param id * @return */ @ApiOperation(value = "根据主键查询") @GetMapping(value = "/findById") public HttpResult findById(@RequestParam String id) { return HttpResult.ok(esmInsCompanyService.getById(id)); } /** * 基础分页查询 * * @param pageRequest * @return */ @PostMapping(value = "/findPage") public HttpResult findPage(@RequestBody PageRequest pageRequest) { String id = PageRequest.getColumnFilterValue(pageRequest, "id"); String name = PageRequest.getColumnFilterValue(pageRequest, "name"); String parentId = PageRequest.getColumnFilterValue(pageRequest, "parentId"); Page p = PageRequest.buildPageRequest(pageRequest); LambdaQueryWrapper lqw = new LambdaQueryWrapper<>(); lqw.eq(StringUtils.isNotEmpty(id), EsmInsCompany::getId, id); lqw.like(StringUtils.isNotEmpty(name), EsmInsCompany::getName, name); lqw.eq(StringUtils.isNotEmpty(parentId), EsmInsCompany::getParentId, parentId); IPage pResult = esmInsCompanyService.page(p, lqw); //传入查询条件 PageResult pageResult = PageResult.buildPageResult(pResult); return HttpResult.ok(pageResult); } // /** // * 删除公司信息 // * // * @param idList // * @return // */ // @PostMapping(value = "/deleteInsCompany") // public HttpResult delete(@RequestParam List idList) { // Integer result = 0; // String msg = "删除成功"; // // if (idList != null && idList.size() > 0) { //// result = esmInsCompanyService.delete(idList); // esmInsCompanyService.removeByIds(idList); // //// esmInsCompanyService.allowQuote(null,idList); // return HttpResult.ok(msg); // // } else { // msg = "编码不能为空"; // return HttpResult.ok(msg, result); // } // } /** * 批量逻辑删除 * * @author: lig * @date: 2023年04月14日 0014 */ // @ApiOperation(value = "批量删除操作") // @DeleteMapping(value = "/idBatch") // public HttpResult deleteBatch(@RequestParam List idList) { // // LambdaUpdateWrapper lqw = new LambdaUpdateWrapper<>(); // lqw.in(EsmInsCompany::getId, idList); // esmInsCompanyService.remove(lqw); // // return HttpResult.ok("操作成功"); // // } @ApiOperation(value = "删除操作") @DeleteMapping(value = "/{id}") public HttpResult delete(@PathVariable("id") String id) { EsmInsCompany esmInsCompany = esmInsCompanyService.isExists(id); if ("0".equals(esmInsCompany.getParentId()) && !SupplierTypeEnum.AS0.getCode().equals(esmInsCompany.getType())) { throw new SystemException("财险,寿险,一级保险公司无法删除"); } List list = esmInsCompanyService.list(new LambdaQueryWrapper().eq(EsmInsCompany::getParentId, id)); AssertionUtils.isSucceed(list.isEmpty(), "此公司还有下级公司无法删除"); esmInsCompanyService.removeById(id); return HttpResult.ok("操作成功"); } // @ApiOperation(value = "恢复删除操作") // @GetMapping(value = "/{id}") // public HttpResult rollBackDelete(@PathVariable("id") String id) { // // EsmInsCompany eic = esmInsCompanyService.getById(id); // if (null == eic) return HttpResult.error("对象不存在"); // // eic.setDelFlag(0); // esmInsCompanyService.updateById(eic); // // return HttpResult.ok("操作成功"); // // } // @ApiOperation(value = "获取允许报价的保险公司列表") // @GetMapping(value = "/gainAllowQuoteList") // public HttpResult gainAllowQuoteList() { // LambdaQueryWrapper lqw = new LambdaQueryWrapper<>(); // lqw.eq(EsmInsCompany::getDelFlag, 0); // lqw.eq(EsmInsCompany::getOpenQuote, 1); // lqw.eq(EsmInsCompany::getParentId, "0"); // List list = esmInsCompanyService.list(lqw); // return HttpResult.ok(list); // // } @ApiOperation(value = "获取顶级保险公司列表") @GetMapping(value = "/gainTopList") public HttpResult> gainTopList(@RequestParam String type) { LambdaQueryWrapper lqw = new LambdaQueryWrapper<>(); lqw.eq(EsmInsCompany::getParentId, "0"); lqw.orderByAsc(EsmInsCompany::getOrderNum); lqw.eq(!StringUtils.isNullOrEmpty(type), EsmInsCompany::getType, type); List list = esmInsCompanyService.list(lqw); List esmInsCompanyResVos = BeanUtil.copyToList(list, EsmInsCompanyResVo.class); return HttpResult.ok(esmInsCompanyResVos); } @ApiOperation(value = "查询保司机构下级") @GetMapping(value = "/queryListByParentId/{parentId}") public HttpResult> queryListByParentId(@PathVariable("parentId") String parentId) { if(parentId==null || "".equals(parentId)) { return HttpResult.error("parentId父级id不能为空"); } List esmInsCompanyList = esmInsCompanyService.queryListByParentId(parentId); return HttpResult.ok(esmInsCompanyList); } /** * @version * @author: hxl * @Date: 2024/9/20 16:22 * @Description: 查询子订单中的保险公司列表 */ @ApiOperation(value = "查询子订单中的保险公司列表") @GetMapping(value = "/findOrderCompanyList") public HttpResult> findOrderCompanyList() { List esmInsCompanyList = esmInsCompanyService.findOrderCompanyList(); return HttpResult.ok(esmInsCompanyList); } }