Newer
Older
huludao / src / main / java / com / newfiber / api / pc / controller / OrgController.java
package com.newfiber.api.pc.controller;

import com.baomidou.mybatisplus.plugins.Page;
import com.newfiber.api.core.annotation.SysLog;
import com.newfiber.api.core.bean.ReqBodyObj;
import com.newfiber.api.core.bean.RespBodyObj;
import com.newfiber.api.core.utils.Response;
import com.newfiber.api.pc.dto.CommonDto;
import com.newfiber.api.pc.dto.SysOrgDto;
import com.newfiber.api.pc.model.entity.SysOrganization;
import com.newfiber.api.pc.service.Sys_OrgService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.net.URLDecoder;
import java.util.List;
import java.util.Map;

@RestController
@Api(value = "OrgController",tags = "SYS-05、部门机构管理", position = 105)
public class OrgController {
	@Autowired
	private Sys_OrgService sysOrgService;


	//获取所有机构信息
	@PostMapping(value="/OrgList",produces = "application/json;charset=utf-8")
	@SysLog(actionType="4",value = "获取所有机构信息")
	@ApiOperation("部门机构管理-获取所有的机构信息")
	public RespBodyObj<Page<SysOrganization>> OrgList(@RequestBody ReqBodyObj<CommonDto> params){
		int pageSize=params.getSize();
		int pageNo=(params.getCurrent()-1)*pageSize;
		String str = null;
		try {
			CommonDto so = params.getData();
			  if(so.getFuzzyQuery()!=null&&so.getFuzzyQuery()!=""){
				  str = URLDecoder.decode(so.getFuzzyQuery(),"UTF-8");
			  }
			Page<SysOrganization> json=sysOrgService.OrgList(so.getSort() ,so.getOrder(),pageNo, pageSize, str);
			  return RespBodyObj.ok(json);
		} catch (Exception e) {
			e.printStackTrace();
			return RespBodyObj.error("查询失败!");
		}
	}
	//添加机构信息
	@PostMapping(value="/AddOrg",produces = "application/json;charset=utf-8")
	@SysLog(actionType="1",value = "添加机构信息")
	@ApiOperation("部门机构管理-添加机构信息")
	public RespBodyObj AddOrg(@RequestBody SysOrgDto so){
		try {
			sysOrgService.addOrg(so.getOrgNo(), so.getOrgName(), so.getOrgType(), so.getOrgState(), so.getAddress(), so.getRemark(), so.getOrderSort());
			return RespBodyObj.ok("添加成功!");
		} catch (Exception e) {
			e.printStackTrace();
			return RespBodyObj.error("添加失败!");
		}
	}

	
	//修改机构信息
	@PostMapping(value="/UpdateOrg",produces = "application/json;charset=utf-8")
	@SysLog(actionType="3",value = "修改机构信息")
	@ApiOperation("部门机构管理-修改机构信息")
	public RespBodyObj UpdateOrg(@RequestBody SysOrgDto so){
		try {
			sysOrgService.updateOrg(so.getSerial(), so.getOrgNo(), so.getOrgName(), so.getOrgType(), so.getOrgState(), so.getAddress(), so.getRemark(), so.getOrderSort());
			return RespBodyObj.ok("修改成功!");
		} catch (Exception e) {
			e.printStackTrace();
			return RespBodyObj.error("修改失败!");
		}
	}
	//删除机构信息
	@PostMapping(value="deleteOrg",produces = "application/json;charset=utf-8")
	@SysLog(actionType="2",value = "删除机构信息")
	@ApiOperation("部门机构管理-批量删除机构信息( 多个主键之间通过,分隔)")
	public RespBodyObj deleteOrg(@RequestParam("serial") String serial){
		try {
            if(serial != null && serial != ""){
            	sysOrgService.deleteOrg(serial);
            	return RespBodyObj.ok("删除成功!");
			}else{
				return RespBodyObj.error("未选中删除项");
			}
		} catch (Exception e) {
			e.printStackTrace();
			return RespBodyObj.error("删除失败!");
		}
	}
}