package com.hivekion.baseData.controller; import com.hivekion.baseData.domain.TblEntity; import com.hivekion.baseData.entity.Fightpowerhierarchy; import com.hivekion.baseData.entity.Fightpowerstaff; import com.hivekion.baseData.entity.Fightpowerweaponstaff; import com.hivekion.baseData.entity.OrgSupplier; import com.hivekion.baseData.service.FightpowerhierarchyService; import com.hivekion.baseData.service.FightpowerstaffService; import com.hivekion.baseData.service.FightpowerweaponstaffService; import com.hivekion.baseData.service.ITblEntityService; import com.hivekion.baseData.service.OrgSupplierService; import com.hivekion.common.entity.ResponseData; import com.hivekion.common.enums.ResultCodeEnum; import com.hivekion.common.uuid.IdUtils; import com.hivekion.supplier.entity.SuppliesDict; import com.hivekion.supplier.service.SuppliesDictService; import com.hivekion.unit.entity.UnitMaterialStation; import com.hivekion.unit.entity.UnitStation; import com.hivekion.unit.service.IUnitMaterialStationService; import com.hivekion.unit.service.IUnitStationService; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import java.util.List; import java.util.Map; import javax.annotation.Resource; import javax.validation.Valid; import org.springframework.validation.BindingResult; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PathVariable; 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; /** * 前端控制器 * * @author liDongYu * @since 2025-08-06 */ @RestController @RequestMapping("/baseData/fightPowerHierarchy") @Api(value = "组织机构", tags = {"数据管理-组织机构"}) public class FightPowerHierarchyController extends BaseController { //组织机构服务类 @Resource private FightpowerhierarchyService fightpowerhierarchyService; //组织机构和岗位对应服务类 @Resource private FightpowerstaffService fightpowerstaffService; @Resource //组织机构和装备对应服务类 private FightpowerweaponstaffService fightpowerweaponstaffService; //装备服务类 @Resource private ITblEntityService tblEntityService; //岗位服务类 @Resource private IUnitStationService unitStationService; //岗位和武器武器装备的对应服务类 @Resource private IUnitMaterialStationService unitMaterialStationService; @Resource private OrgSupplierService orgSupplierService; @Resource private SuppliesDictService suppliesDictService; /** * 保存组织机构 * * @param entity 数据 * @param bindingResult 绑定的错误对象 * @return 操作结果 */ @ApiOperation(value = "保存组织机构", notes = "") @PostMapping("/save") public ResponseData save(@Valid @RequestBody Fightpowerhierarchy entity, BindingResult bindingResult) { if (bindingResult.hasErrors()) { return bindingErrors(bindingResult); } entity.setParentCodeName("0000"); if (entity.getParentId() != null) { Fightpowerhierarchy parent = fightpowerhierarchyService.getById(entity.getParentId()); if (parent != null) { entity.setParentCodeName(parent.getCodeName()); } } if (entity.getId() == null) { fightpowerhierarchyService.save(entity); } else { fightpowerhierarchyService.updateById(entity); } return ResponseData.success(entity); } /** * 删除组织机构 * * @param id 要删除的ID * @return 操作结果 */ @GetMapping("/remove/{id}") @ApiOperation(value = "删除组织机构", notes = "根据ID删除") public ResponseData remove(@PathVariable("id") Integer id) { //查询是否有子机构,如果有,无法删除 List list = fightpowerhierarchyService.queryChildRen(id); if (!list.isEmpty()) { return ResponseData.error(ResultCodeEnum.RECORD_IS_TAKEN, null); } fightpowerhierarchyService.removeById(id); return ResponseData.success(null); } /** * 查看组织机构 * * @param id 查看的ID * @return 结果对象, 包含组织机构 */ @GetMapping("/{id}") @ApiOperation(value = "查看组织机构", notes = "根据ID查看") public ResponseData view(@PathVariable("id") Integer id) { Fightpowerhierarchy fightPower = fightpowerhierarchyService.getById(id); if (fightPower == null) { return ResponseData.error(ResultCodeEnum.RECORD_NOT_EXIT, null); } return ResponseData.success(fightPower); } /** * 获取组织机构下的岗位信息 * * @param id 组织机构ID * @return 岗位列表 */ @GetMapping("/staff/{id}") @ApiOperation(value = "获取组织机构下的岗位信息", notes = "传入组织机构ID") public ResponseData> staff(@PathVariable("id") Integer id) { return ResponseData.success(fightpowerstaffService.queryListByOrgId(id)); } /** * 获取组织机构下的武器装备信息 * * @param id 组织机构ID * @return 武器装备列表 */ @GetMapping("/weapon/{id}") @ApiOperation(value = "获取组织机构下的武器装备信息", notes = "传入组织机构ID") public ResponseData> weaponsStaff(@PathVariable("id") Integer id) { return ResponseData.success(fightpowerweaponstaffService.queryListByOrgId(id)); } /** * 保存组织下分配的岗位信息 * * @param entity 岗位关联对象 * @return 操作结果 */ @PostMapping("/staff/save") @ApiOperation(value = "保存组织机构下的岗位信息", notes = "typeId:岗位ID;parentId:当前组织ID,number:岗位数量") public ResponseData staffSave(@Valid @RequestBody Fightpowerstaff entity, BindingResult bindingResult) { if (bindingResult.hasErrors()) { return bindingErrors(bindingResult); } UnitStation staff = unitStationService.getById(entity.getTypeId()); if (staff == null) { return ResponseData.error(ResultCodeEnum.RECORD_NOT_EXIT, null); } List meterialList = unitMaterialStationService.selectMaterialByStationId( entity.getTypeId()); if (!meterialList.isEmpty()) { StringBuilder sBuilder = new StringBuilder(); meterialList.forEach(meter -> { sBuilder.append(meter.getName()).append(":").append(meter.getMaterialNum()).append(";"); }); entity.setMaterial(sBuilder.toString()); } else { entity.setMaterial("无"); } entity.setName(staff.getName()); fightpowerstaffService.saveOrUpdate(entity); return ResponseData.success(entity); } /** * 保存组织下分配的武器装备信息 * * @param entity 武器装备关联对象 * @return 操作结果 */ @ApiOperation(value = "保存组织机构下的武器装备信息", notes = "weaponId:武器D;parentId:当前组织ID,number:岗位数量") @PostMapping("/weapon/save") public ResponseData saveWeapon(@Valid @RequestBody Fightpowerweaponstaff entity, BindingResult bindingResult) { if (bindingResult.hasErrors()) { return bindingErrors(bindingResult); } TblEntity weapon = tblEntityService.getById(entity.getWeaponId()); if (weapon == null) { return ResponseData.error(ResultCodeEnum.RECORD_NOT_EXIT, "武器装备不存在"); } entity.setType(0); entity.setName(weapon.getEntityName()); entity.setGuid(weapon.getId() + ""); fightpowerweaponstaffService.saveOrUpdate(entity); return ResponseData.success(entity); } @PostMapping("/supplier/save") public ResponseData saveSupplier(@RequestBody OrgSupplier orgSupplier) { if (orgSupplier.getId() == null) { orgSupplier.setId(IdUtils.simpleUUID()); orgSupplierService.save(orgSupplier); } else { orgSupplierService.updateById(orgSupplier); } return ResponseData.success(orgSupplier); } @GetMapping("/supplier/getByOrgId") public ResponseData> getSupplier(Integer id) { Map dictMap = suppliesDictService.supplierDictMap(); List list = orgSupplierService.getByOrgId(id); list.forEach(supplier -> { if (dictMap.get(supplier.getSupplierId()) != null) { supplier.setName(dictMap.get(supplier.getSupplierId()).getSupplierName()); } }); return ResponseData.success(list); } @GetMapping("/supplier/remove/{id}") public ResponseData removeSupplier(@PathVariable("id") String id) { orgSupplierService.removeById(id); return ResponseData.success(null); } }