|
@@ -0,0 +1,449 @@
|
|
|
+package com.jpsoft.bus.modules.base.controller;
|
|
|
+
|
|
|
+import com.alipay.api.domain.DeviceInfo;
|
|
|
+import com.github.pagehelper.Page;
|
|
|
+import com.jpsoft.bus.config.OSSConfig;
|
|
|
+import com.jpsoft.bus.modules.base.entity.*;
|
|
|
+import com.jpsoft.bus.modules.base.service.*;
|
|
|
+import com.jpsoft.bus.modules.common.dto.MessageResult;
|
|
|
+import com.jpsoft.bus.modules.common.dto.Sort;
|
|
|
+import com.jpsoft.bus.modules.common.utils.OSSUtil;
|
|
|
+import com.jpsoft.bus.modules.common.utils.POIUtils;
|
|
|
+import com.jpsoft.bus.modules.common.utils.PojoUtils;
|
|
|
+import com.jpsoft.bus.modules.sys.entity.User;
|
|
|
+import com.jpsoft.bus.modules.sys.service.DataDictionaryService;
|
|
|
+import com.jpsoft.bus.modules.sys.service.UserService;
|
|
|
+import io.swagger.annotations.Api;
|
|
|
+import io.swagger.annotations.ApiImplicitParam;
|
|
|
+import io.swagger.annotations.ApiImplicitParams;
|
|
|
+import io.swagger.annotations.ApiOperation;
|
|
|
+import org.apache.commons.lang3.StringUtils;
|
|
|
+import org.apache.poi.ss.usermodel.Sheet;
|
|
|
+import org.apache.poi.ss.usermodel.Workbook;
|
|
|
+import org.slf4j.Logger;
|
|
|
+import org.slf4j.LoggerFactory;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.transaction.annotation.Transactional;
|
|
|
+import org.springframework.transaction.interceptor.TransactionAspectSupport;
|
|
|
+import org.springframework.web.bind.annotation.*;
|
|
|
+import org.springframework.web.multipart.MultipartFile;
|
|
|
+
|
|
|
+import javax.servlet.http.HttpServletRequest;
|
|
|
+import java.io.ByteArrayInputStream;
|
|
|
+import java.io.ByteArrayOutputStream;
|
|
|
+import java.text.DecimalFormat;
|
|
|
+import java.util.*;
|
|
|
+
|
|
|
+@RestController
|
|
|
+@RequestMapping("/base/companyInfo")
|
|
|
+@Api(description = "companyInfo")
|
|
|
+public class CompanyInfoController {
|
|
|
+ private Logger logger = LoggerFactory.getLogger(getClass());
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private OSSConfig ossConfig;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private CompanyInfoService companyInfoService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private UserService userService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private DataDictionaryService dataDictionaryService;
|
|
|
+
|
|
|
+ @ApiOperation(value="创建空记录")
|
|
|
+ @GetMapping("create")
|
|
|
+ public MessageResult<CompanyInfo> create(){
|
|
|
+ MessageResult<CompanyInfo> msgResult = new MessageResult<>();
|
|
|
+
|
|
|
+ CompanyInfo companyInfoDTO = new CompanyInfo();
|
|
|
+
|
|
|
+ msgResult.setData(companyInfoDTO);
|
|
|
+ msgResult.setResult(true);
|
|
|
+
|
|
|
+ return msgResult;
|
|
|
+ }
|
|
|
+
|
|
|
+ @ApiOperation(value="添加信息")
|
|
|
+ @PostMapping("add")
|
|
|
+ public MessageResult<Map> add(@RequestBody CompanyInfo companyInfoDTO, @RequestAttribute String subject){
|
|
|
+ MessageResult<Map> msgResult = new MessageResult<>();
|
|
|
+ Map<String,Object> map = new HashMap<>();
|
|
|
+
|
|
|
+ try {
|
|
|
+ CompanyInfo companyInfo = new CompanyInfo();
|
|
|
+ PojoUtils.map(companyInfoDTO, companyInfo);
|
|
|
+ companyInfo.setId(UUID.randomUUID().toString());
|
|
|
+
|
|
|
+ DecimalFormat df = new DecimalFormat("000");
|
|
|
+
|
|
|
+ //上级单位code
|
|
|
+ if (StringUtils.isNotEmpty(companyInfo.getParentId())){
|
|
|
+ CompanyInfo parent = companyInfoService.get(companyInfo.getParentId());
|
|
|
+ companyInfo.setCode(parent.getCode() + "," + companyInfo.getId());
|
|
|
+ companyInfo.setLevel(parent.getLevel()+1);
|
|
|
+ }
|
|
|
+ else{
|
|
|
+ companyInfo.setCode(companyInfo.getId());
|
|
|
+ companyInfo.setLevel(1);
|
|
|
+ }
|
|
|
+
|
|
|
+ companyInfo.setDelFlag(false);
|
|
|
+ companyInfo.setCreateBy(subject);
|
|
|
+ companyInfo.setCreateTime(new Date());
|
|
|
+ int affectCount = companyInfoService.insert(companyInfo);
|
|
|
+ map.put("companyInfo",companyInfo);
|
|
|
+ if (affectCount > 0) {
|
|
|
+ msgResult.setResult(true);
|
|
|
+ msgResult.setData(map);
|
|
|
+ } else {
|
|
|
+ msgResult.setResult(false);
|
|
|
+ msgResult.setMessage("数据库添加失败");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ catch(Exception ex){
|
|
|
+ logger.error(ex.getMessage(),ex);
|
|
|
+
|
|
|
+ msgResult.setResult(false);
|
|
|
+ msgResult.setMessage(ex.getMessage());
|
|
|
+ }
|
|
|
+
|
|
|
+ return msgResult;
|
|
|
+ }
|
|
|
+
|
|
|
+ @ApiOperation(value="获取信息")
|
|
|
+ @GetMapping("edit/{id}")
|
|
|
+ public MessageResult<CompanyInfo> edit(@PathVariable("id") String id, @RequestAttribute String subject){
|
|
|
+ MessageResult<CompanyInfo> msgResult = new MessageResult<>();
|
|
|
+
|
|
|
+ try {
|
|
|
+ User user = userService.get(subject);
|
|
|
+
|
|
|
+ CompanyInfo companyInfo = companyInfoService.get(id);
|
|
|
+
|
|
|
+ if (companyInfo != null) {
|
|
|
+
|
|
|
+ msgResult.setResult(true);
|
|
|
+ msgResult.setData(companyInfo);
|
|
|
+ } else {
|
|
|
+ msgResult.setResult(false);
|
|
|
+ msgResult.setMessage("数据库不存在该记录!");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ catch(Exception ex){
|
|
|
+ logger.error(ex.getMessage(),ex);
|
|
|
+
|
|
|
+ msgResult.setResult(false);
|
|
|
+ msgResult.setMessage(ex.getMessage());
|
|
|
+ }
|
|
|
+
|
|
|
+ return msgResult;
|
|
|
+ }
|
|
|
+
|
|
|
+ @ApiOperation(value="更新")
|
|
|
+ @PostMapping("update")
|
|
|
+ public MessageResult<Map> update(@RequestBody CompanyInfo companyInfoDTO, @RequestAttribute String subject){
|
|
|
+ MessageResult<Map> msgResult = new MessageResult<>();
|
|
|
+ Map<String,Object> map = new HashMap<>();
|
|
|
+
|
|
|
+ try {
|
|
|
+ int affectCount = 0;
|
|
|
+ CompanyInfo srcCompany = companyInfoService.get(companyInfoDTO.getId());
|
|
|
+
|
|
|
+ CompanyInfo destCompany = new CompanyInfo();
|
|
|
+ PojoUtils.map(companyInfoDTO, destCompany);
|
|
|
+
|
|
|
+ //上级单位code
|
|
|
+ if (StringUtils.isNotEmpty(destCompany.getParentId())){
|
|
|
+ CompanyInfo parent = companyInfoService.get(destCompany.getParentId());
|
|
|
+ destCompany.setCode(parent.getCode() + "," + destCompany.getId());
|
|
|
+ destCompany.setLevel(parent.getLevel()+1);
|
|
|
+ }
|
|
|
+ else{
|
|
|
+ destCompany.setCode(destCompany.getId());
|
|
|
+ destCompany.setLevel(1);
|
|
|
+ }
|
|
|
+
|
|
|
+ String newCode = destCompany.getCode();
|
|
|
+ String oldCode = srcCompany.getCode();
|
|
|
+
|
|
|
+ if (StringUtils.isNotEmpty(oldCode) && !oldCode.equals(newCode)) {
|
|
|
+ companyInfoService.updateCode(oldCode,newCode);
|
|
|
+ }
|
|
|
+
|
|
|
+ destCompany.setUpdateBy(subject);
|
|
|
+ destCompany.setUpdateTime(new Date());
|
|
|
+ companyInfoService.update(destCompany);
|
|
|
+
|
|
|
+ map.put("companyInfo",destCompany);
|
|
|
+
|
|
|
+ affectCount++;
|
|
|
+
|
|
|
+ if (affectCount > 0) {
|
|
|
+ msgResult.setResult(true);
|
|
|
+ msgResult.setData(map);
|
|
|
+ } else {
|
|
|
+ msgResult.setResult(false);
|
|
|
+ msgResult.setMessage("数据库更新失败");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ catch(Exception ex){
|
|
|
+ logger.error(ex.getMessage(),ex);
|
|
|
+
|
|
|
+ msgResult.setResult(false);
|
|
|
+ msgResult.setMessage(ex.getMessage());
|
|
|
+ }
|
|
|
+
|
|
|
+ return msgResult;
|
|
|
+ }
|
|
|
+
|
|
|
+ @ApiOperation(value="删除")
|
|
|
+ @PostMapping("delete/{id}")
|
|
|
+ public MessageResult<Integer> delete(@PathVariable("id") String id, @RequestAttribute String subject){
|
|
|
+ MessageResult<Integer> msgResult = new MessageResult<>();
|
|
|
+
|
|
|
+ try {
|
|
|
+ CompanyInfo companyInfo = companyInfoService.get(id);
|
|
|
+ companyInfo.setDelFlag(true);
|
|
|
+ companyInfo.setUpdateBy(subject);
|
|
|
+ companyInfo.setUpdateTime(new Date());
|
|
|
+
|
|
|
+ int affectCount = companyInfoService.update(companyInfo);
|
|
|
+
|
|
|
+ if (affectCount > 0) {
|
|
|
+ msgResult.setResult(true);
|
|
|
+ msgResult.setData(affectCount);
|
|
|
+ } else {
|
|
|
+ msgResult.setResult(false);
|
|
|
+ msgResult.setMessage("删除失败");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ catch(Exception ex){
|
|
|
+ logger.error(ex.getMessage(),ex);
|
|
|
+
|
|
|
+ msgResult.setResult(false);
|
|
|
+ msgResult.setMessage(ex.getMessage());
|
|
|
+ }
|
|
|
+
|
|
|
+ return msgResult;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ @ApiOperation(value="批量删除")
|
|
|
+ @PostMapping("batchDelete")
|
|
|
+ public MessageResult<Integer> batchDelete(@RequestBody List<String> idList, @RequestAttribute String subject){
|
|
|
+ MessageResult<Integer> msgResult = new MessageResult<>();
|
|
|
+
|
|
|
+ try {
|
|
|
+ int affectCount = 0;
|
|
|
+
|
|
|
+ for (String id : idList) {
|
|
|
+ CompanyInfo companyInfo = companyInfoService.get(id);
|
|
|
+ companyInfo.setDelFlag(true);
|
|
|
+ companyInfo.setUpdateBy(subject);
|
|
|
+ companyInfo.setUpdateTime(new Date());
|
|
|
+
|
|
|
+ affectCount += companyInfoService.update(companyInfo);
|
|
|
+ }
|
|
|
+
|
|
|
+ if (affectCount > 0) {
|
|
|
+ msgResult.setResult(true);
|
|
|
+ msgResult.setData(affectCount);
|
|
|
+ } else {
|
|
|
+ msgResult.setResult(false);
|
|
|
+ msgResult.setMessage("删除失败");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ catch(Exception ex){
|
|
|
+ logger.error(ex.getMessage(),ex);
|
|
|
+
|
|
|
+ msgResult.setResult(false);
|
|
|
+ msgResult.setMessage(ex.getMessage());
|
|
|
+ }
|
|
|
+
|
|
|
+ return msgResult;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ @ApiOperation(value="列表")
|
|
|
+ @RequestMapping(value = "pageList",method = RequestMethod.POST)
|
|
|
+ public MessageResult<Map> pageList(
|
|
|
+ String name,String parentId,Boolean subordinate,
|
|
|
+ String type,
|
|
|
+ @RequestParam(value="pageIndex",defaultValue="1") int pageIndex,
|
|
|
+ @RequestParam(value="pageSize",defaultValue="20") int pageSize,
|
|
|
+ @RequestAttribute String subject){
|
|
|
+
|
|
|
+ //当前用户ID
|
|
|
+ System.out.println(subject);
|
|
|
+ MessageResult<Map> msgResult = new MessageResult<>();
|
|
|
+
|
|
|
+ Map<String,Object> searchParams = new HashMap<>();
|
|
|
+
|
|
|
+ List<Sort> sortList = new ArrayList<>();
|
|
|
+ sortList.add(new Sort("level_","asc"));
|
|
|
+ sortList.add(new Sort("sort_no","asc"));
|
|
|
+ sortList.add(new Sort("name_","asc"));
|
|
|
+
|
|
|
+ if (StringUtils.isNotEmpty(name)) {
|
|
|
+ searchParams.put("name","%" + name + "%");
|
|
|
+ }
|
|
|
+
|
|
|
+ if (StringUtils.isNotEmpty(parentId)) {
|
|
|
+ CompanyInfo parent = companyInfoService.get(parentId);
|
|
|
+
|
|
|
+ if (parent!=null){
|
|
|
+ if(subordinate!=null && subordinate){
|
|
|
+ searchParams.put("parentCode",parent.getCode() + "%");
|
|
|
+ }
|
|
|
+ else{
|
|
|
+ searchParams.put("parentCode",parent.getCode());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ if (StringUtils.isNotEmpty(type)) {
|
|
|
+ searchParams.put("type", type);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ User user = userService.get(subject);
|
|
|
+
|
|
|
+ boolean isAdmin = false;
|
|
|
+
|
|
|
+ if(!userService.hasRole(user.getId(),"SYSADMIN")) {
|
|
|
+ CompanyInfo companyInfo = companyInfoService.get(user.getCompanyId());
|
|
|
+ searchParams.put("bindCompanyCode",companyInfo.getCode() + "%");
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ if (StringUtils.isEmpty(name) && StringUtils.isEmpty(parentId)) {
|
|
|
+ //系统管理员,如果查询条件为空则只查根目录
|
|
|
+ searchParams.put("root", true);
|
|
|
+ isAdmin = true;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ Page<CompanyInfo> page = companyInfoService.pageSearch(searchParams,pageIndex,pageSize,sortList);
|
|
|
+ Page<CompanyInfo> pageDTO = PojoUtils.convertPage(page, CompanyInfo.class);
|
|
|
+
|
|
|
+ for(CompanyInfo li : pageDTO.getResult()){
|
|
|
+ String typeName = dataDictionaryService.findNameByCatalogNameAndValue("单位性质",li.getType());
|
|
|
+ li.setTypeName(typeName);
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ msgResult.setResult(true);
|
|
|
+ msgResult.setData(PojoUtils.pageWrapper(pageDTO));
|
|
|
+
|
|
|
+ return msgResult;
|
|
|
+ }
|
|
|
+
|
|
|
+ @ApiOperation(value="查询子单位")
|
|
|
+ @RequestMapping(value = "children",method = RequestMethod.POST)
|
|
|
+ public MessageResult<List<CompanyInfo>> children(String parentId){
|
|
|
+ MessageResult<List<CompanyInfo>> msgResult = new MessageResult<>();
|
|
|
+
|
|
|
+ try {
|
|
|
+ List<CompanyInfo> list = companyInfoService.findByParentId(parentId);
|
|
|
+
|
|
|
+ List<CompanyInfo> dtoList = new ArrayList<>();
|
|
|
+
|
|
|
+ for (CompanyInfo companyInfo : list) {
|
|
|
+ CompanyInfo dto = new CompanyInfo();
|
|
|
+
|
|
|
+ PojoUtils.map(companyInfo,dto);
|
|
|
+
|
|
|
+ Boolean hasChildren = companyInfoService.hasChildren(companyInfo.getId());
|
|
|
+ dto.setHasChildren(hasChildren);
|
|
|
+
|
|
|
+ dtoList.add(dto);
|
|
|
+ }
|
|
|
+
|
|
|
+ msgResult.setResult(true);
|
|
|
+ msgResult.setData(dtoList);
|
|
|
+ }
|
|
|
+ catch (Exception ex){
|
|
|
+ msgResult.setResult(false);
|
|
|
+ logger.error(ex.getMessage(),ex);
|
|
|
+ }
|
|
|
+
|
|
|
+ return msgResult;
|
|
|
+ }
|
|
|
+
|
|
|
+ @ApiOperation(value="所有单位列表")
|
|
|
+ @RequestMapping(value = "list",method = RequestMethod.POST)
|
|
|
+ public MessageResult<List<CompanyInfo>> list(String companyId,String type,String scope,@RequestAttribute String subject){
|
|
|
+
|
|
|
+ MessageResult<List<CompanyInfo>> msgResult = new MessageResult<>();
|
|
|
+ User user = userService.get(subject);
|
|
|
+ String companyCode = "";
|
|
|
+
|
|
|
+ if (StringUtils.isNotEmpty(companyId)){
|
|
|
+ CompanyInfo companyInfo = companyInfoService.get(companyId);
|
|
|
+ companyCode = companyInfo.getCode();
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ if (userService.hasRole(subject, "SYSADMIN") || "all".equals(scope)) {
|
|
|
+ companyCode = "";
|
|
|
+ }
|
|
|
+ else{
|
|
|
+ CompanyInfo companyInfo = companyInfoService.get(user.getCompanyId());
|
|
|
+ companyCode = companyInfo.getCode();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ List<CompanyInfo> list = companyInfoService.findByCompanyCodeAndType(companyCode + "%", type);
|
|
|
+
|
|
|
+ msgResult.setResult(true);
|
|
|
+ msgResult.setData(list);
|
|
|
+
|
|
|
+ return msgResult;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ @ApiOperation(value="单位树")
|
|
|
+ @RequestMapping(value = "treeList",method = RequestMethod.POST)
|
|
|
+ @ApiImplicitParams({
|
|
|
+ @ApiImplicitParam(name="subject",value = "当前用户编号(不传)",paramType = "form")
|
|
|
+ })
|
|
|
+ public MessageResult<List<Map>> treeList(HttpServletRequest request){
|
|
|
+ String subject = (String)request.getAttribute("subject");
|
|
|
+
|
|
|
+ MessageResult<List<Map>> msgResult = new MessageResult<>();
|
|
|
+ User user = userService.get(subject);
|
|
|
+ List<CompanyInfo> list = new ArrayList<>();
|
|
|
+
|
|
|
+ if (userService.hasRole(subject,"SYSADMIN")) {
|
|
|
+ list = companyInfoService.list();
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ CompanyInfo companyInfo = companyInfoService.get(user.getCompanyId());
|
|
|
+ list = companyInfoService.findByCompanyCode(companyInfo.getCode() + "%",null);
|
|
|
+ }
|
|
|
+
|
|
|
+ //id_,name_,parent_id,type_
|
|
|
+ List<Map> mapList = new ArrayList<>();
|
|
|
+
|
|
|
+ for (CompanyInfo companyInfo : list) {
|
|
|
+ Map<String,Object> map = new HashMap<>();
|
|
|
+
|
|
|
+ map.put("id", companyInfo.getId());
|
|
|
+ map.put("name", companyInfo.getName());
|
|
|
+ map.put("parentId", companyInfo.getParentId());
|
|
|
+ map.put("type", companyInfo.getType());
|
|
|
+
|
|
|
+ mapList.add(map);
|
|
|
+ }
|
|
|
+
|
|
|
+ msgResult.setResult(true);
|
|
|
+ msgResult.setData(mapList);
|
|
|
+
|
|
|
+ return msgResult;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+}
|