parent
13a7763cf3
commit
f28e09acc1
@ -0,0 +1,136 @@
|
||||
package com.ruoyi.tc.controller;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.ruoyi.common.annotation.Log;
|
||||
import com.ruoyi.common.core.domain.AjaxResult;
|
||||
import com.ruoyi.common.core.domain.entity.Unit;
|
||||
import com.ruoyi.common.core.domain.request.UnitRequest;
|
||||
import com.ruoyi.common.enums.BusinessType;
|
||||
import com.ruoyi.common.exception.ServiceException;
|
||||
import com.ruoyi.common.utils.poi.ExcelUtil;
|
||||
import com.ruoyi.system.service.UnitService;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import javax.validation.Valid;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 单位(unit)表控制层
|
||||
* @author du
|
||||
* @since 2024/11/18 17:11
|
||||
*/
|
||||
@Api(tags = "单位表控制层")
|
||||
@RestController
|
||||
//@PreAuthorize("@ss.hasAnyRoles('admin,common')")
|
||||
@RequestMapping("/tc/unit")
|
||||
public class UnitController {
|
||||
|
||||
@Resource
|
||||
private UnitService unitService;
|
||||
|
||||
/**
|
||||
* 获取单位列表
|
||||
*/
|
||||
@ApiOperation(value = "获取单位列表",response = Unit.class)
|
||||
@GetMapping("/list")
|
||||
public AjaxResult list(Page<Unit> page, UnitRequest unit) {
|
||||
return AjaxResult.success(unitService.page(page,unit));
|
||||
}
|
||||
/**
|
||||
* 单位导出
|
||||
*/
|
||||
@ApiOperation(value = "单位导出")
|
||||
@Log(title = "单位导出", businessType = BusinessType.EXPORT)
|
||||
@PostMapping("/export")
|
||||
public void export(HttpServletResponse response, UnitRequest unit) {
|
||||
List<Unit> list = unitService.selectUnitList(unit);
|
||||
ExcelUtil<Unit> util = new ExcelUtil<>(Unit.class);
|
||||
util.exportExcel(response, list, "单位数据");
|
||||
}
|
||||
/**
|
||||
* 单位导入
|
||||
*/
|
||||
@ApiOperation(value = "单位导入")
|
||||
@Log(title = "单位导入", businessType = BusinessType.IMPORT)
|
||||
@PostMapping("/importData")
|
||||
public AjaxResult importData(MultipartFile file) throws Exception {
|
||||
ExcelUtil<Unit> util = new ExcelUtil<>(Unit.class);
|
||||
List<Unit> list = util.importExcel(file.getInputStream());
|
||||
unitService.saveBatch(list);
|
||||
for (Unit x : list) {
|
||||
//查询用户表是否存在该用户
|
||||
unitService.validUser(x);
|
||||
}
|
||||
return AjaxResult.success();
|
||||
}
|
||||
|
||||
@PostMapping("/importTemplate")
|
||||
public void importTemplate(HttpServletResponse response) {
|
||||
ExcelUtil<Unit> util = new ExcelUtil<>(Unit.class);
|
||||
util.importTemplateExcel(response, "单位模板");
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据id获取详细信息
|
||||
*/
|
||||
@ApiOperation(value = "根据用户编号获取详细信息")
|
||||
@GetMapping("/{id}")
|
||||
public AjaxResult getInfo(@PathVariable(value = "id") Long id) {
|
||||
return AjaxResult.success(unitService.getById(id));
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增单位
|
||||
*/
|
||||
@ApiOperation(value = "新增单位")
|
||||
@Log(title = "用户管理", businessType = BusinessType.INSERT)
|
||||
@PostMapping
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public AjaxResult add(@Valid @RequestBody Unit unit) {
|
||||
if (!unitService.lambdaQuery().eq(Unit::getUserName, unit.getUserName()).eq(Unit::getDelFlag,"0").list().isEmpty()) {
|
||||
throw new ServiceException(unit.getUserName() + "'已存在单位!");
|
||||
}
|
||||
//新增单位到单位信息表
|
||||
unitService.save(unit);
|
||||
//查询用户表是否存在该用户
|
||||
unitService.validUser(unit);
|
||||
return AjaxResult.success();
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改用户
|
||||
*/
|
||||
@ApiOperation(value = "修改用户")
|
||||
@Log(title = "用户管理", businessType = BusinessType.UPDATE)
|
||||
@PutMapping
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public AjaxResult edit(@Valid @RequestBody Unit x) {
|
||||
Unit byId = unitService.getById(x.getId());
|
||||
if (!byId.getUserName().equals(x.getUserName())||!byId.getNickName().equals(x.getNickName())) {
|
||||
throw new ServiceException("不允许修改单位名称和统一信用代码!");
|
||||
}
|
||||
unitService.updateById(x);
|
||||
return AjaxResult.success();
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除单位
|
||||
*/
|
||||
@ApiOperation(value = "删除单位")
|
||||
@Log(title = "删除单位", businessType = BusinessType.DELETE)
|
||||
@DeleteMapping("/{ids}")
|
||||
public AjaxResult remove(@PathVariable Long[] ids) {
|
||||
List<String> userNames = unitService.selectByIds(ids);
|
||||
//逻辑删除单位和用户
|
||||
unitService.deleteUsers(userNames);
|
||||
unitService.deleteUnits(ids);
|
||||
return AjaxResult.success();
|
||||
}
|
||||
}
|
Loading…
Reference in new issue