فهرست منبع

管理用户 单位

xiao547607 4 سال پیش
والد
کامیت
ec53dbcdc8

+ 42 - 0
common/src/main/java/com/jpsoft/bus/modules/base/dao/CompanyInfoDAO.java

@@ -0,0 +1,42 @@
+package com.jpsoft.bus.modules.base.dao;
+
+import com.jpsoft.bus.modules.base.entity.CompanyInfo;
+import com.jpsoft.bus.modules.common.dto.Sort;
+import org.apache.ibatis.annotations.Param;
+import org.springframework.stereotype.Repository;
+
+import java.util.List;
+import java.util.Map;
+
+@Repository
+public interface CompanyInfoDAO {
+	int insert(CompanyInfo entity);
+
+	int update(CompanyInfo entity);
+
+	int exist(String id);
+
+	CompanyInfo get(String id);
+
+	int delete(String id);
+
+	List<CompanyInfo> list();
+
+	List<CompanyInfo> search(Map<String, Object> searchParams, List<Sort> sortList);
+
+	int updateCode(String oldCode, int startIndex, String newCode);
+
+    List<CompanyInfo> findByParentId(@Param("parentId") String parentId);
+
+	CompanyInfo findByName(String name);
+
+	List<CompanyInfo> findByCompanyCodeAndType(@Param("code") String code, @Param("type") String type);
+
+	List<CompanyInfo> findAllCompanyByCode(String code);
+
+    List<CompanyInfo> findByType(String type);
+
+	long countByParentId(@Param("parentId") String parentId);
+
+	List<CompanyInfo> findByCompanyCode(String code, Long personId);
+}

+ 55 - 0
common/src/main/java/com/jpsoft/bus/modules/base/entity/CompanyInfo.java

@@ -0,0 +1,55 @@
+package com.jpsoft.bus.modules.base.entity;
+
+import com.fasterxml.jackson.annotation.JsonFormat;
+import io.swagger.annotations.ApiModel;
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+import org.springframework.format.annotation.DateTimeFormat;
+
+import java.util.Date;
+
+/**
+  描述:base_company_info的实体类
+ */
+@Data
+@ApiModel(value = "base_company_info的实体类")
+public class CompanyInfo {
+    @ApiModelProperty(value = "公司编号")
+	private String id;
+    @ApiModelProperty(value = "序号")
+	private Integer sortNo;
+    @ApiModelProperty(value = "公司名称")
+	private String name;
+	@ApiModelProperty(value = "公司全称")
+	private String fullName;
+    @ApiModelProperty(value = "备注")
+	private String remark;
+    @ApiModelProperty(value = "创建人")
+	private String createBy;
+	@DateTimeFormat(pattern="yyyy-MM-dd HH:mm")
+	@JsonFormat(pattern = "yyyy-MM-dd HH:mm",timezone ="GMT+8")
+    @ApiModelProperty(value = "创建时间")
+	private Date createTime;
+    @ApiModelProperty(value = "更新人")
+	private String updateBy;
+	@DateTimeFormat(pattern="yyyy-MM-dd HH:mm")
+	@JsonFormat(pattern = "yyyy-MM-dd HH:mm",timezone ="GMT+8")
+    @ApiModelProperty(value = "更新时间")
+	private Date updateTime;
+    @ApiModelProperty(value = "是否删除")
+	private Boolean delFlag;
+	@ApiModelProperty(value = "上级公司")
+	private String parentId;
+	@ApiModelProperty(value = "企业编码")
+	private String code;
+	@ApiModelProperty(value = "上级单位")
+	private String parentName;
+	@ApiModelProperty(value = "单位性质")
+	private String type;
+	@ApiModelProperty(value = "单位性质翻译")
+	private String typeName;
+	@ApiModelProperty(value = "层级")
+	private Integer level;
+	@ApiModelProperty(value = "是否有子单位")
+	private Boolean hasChildren;
+}

+ 30 - 0
common/src/main/java/com/jpsoft/bus/modules/base/service/CompanyInfoService.java

@@ -0,0 +1,30 @@
+package com.jpsoft.bus.modules.base.service;
+
+import com.github.pagehelper.Page;
+import com.jpsoft.bus.modules.base.entity.CompanyInfo;
+import com.jpsoft.bus.modules.common.dto.Sort;
+
+import java.util.List;
+import java.util.Map;
+
+public interface CompanyInfoService {
+	CompanyInfo get(String id);
+	boolean exist(String id);
+	int insert(CompanyInfo model);
+	int update(CompanyInfo model);
+	int delete(String id);
+	List<CompanyInfo> list();
+	Page<CompanyInfo> pageSearch(Map<String, Object> searchParams, int pageNum, int pageSize, List<Sort> sortList);
+    int updateCode(String oldCode, String newCode);
+	List<CompanyInfo> findByParentId(String parentId);
+	CompanyInfo findByName(String name);
+	List<CompanyInfo> findByCompanyCodeAndType(String code, String type);
+
+	List<CompanyInfo> findAllCompanyByCode(String code);
+
+    List<CompanyInfo> findByType(String type);
+	long countByParentId(String parentId);
+	Boolean hasChildren(String parentId);
+	List<CompanyInfo> findByCompanyCode(String code,Long personId);
+
+}

+ 118 - 0
common/src/main/java/com/jpsoft/bus/modules/base/service/impl/CompanyInfoServiceImpl.java

@@ -0,0 +1,118 @@
+package com.jpsoft.bus.modules.base.service.impl;
+
+import com.github.pagehelper.Page;
+import com.github.pagehelper.PageHelper;
+import com.jpsoft.bus.modules.base.dao.CompanyInfoDAO;
+import com.jpsoft.bus.modules.base.entity.CompanyInfo;
+import com.jpsoft.bus.modules.base.service.CompanyInfoService;
+import com.jpsoft.bus.modules.common.dto.Sort;
+import org.springframework.stereotype.Component;
+import org.springframework.transaction.annotation.Transactional;
+
+import javax.annotation.Resource;
+import java.util.List;
+import java.util.Map;
+
+@Transactional
+@Component(value="companyInfoService")
+public class CompanyInfoServiceImpl implements CompanyInfoService {
+	@Resource(name="companyInfoDAO")
+	private CompanyInfoDAO companyInfoDAO;
+
+	@Override
+	public CompanyInfo get(String id) {
+		// TODO Auto-generated method stub
+		return companyInfoDAO.get(id);
+	}
+
+	@Override
+	public int insert(CompanyInfo model) {
+		// TODO Auto-generated method stub
+		//model.setId(UUID.randomUUID().toString());
+
+		return companyInfoDAO.insert(model);
+	}
+
+	@Override
+	public int update(CompanyInfo model) {
+		// TODO Auto-generated method stub
+		return companyInfoDAO.update(model);
+	}
+
+	@Override
+	public int delete(String id) {
+		// TODO Auto-generated method stub
+		return companyInfoDAO.delete(id);
+	}
+
+	@Override
+	public boolean exist(String id) {
+		// TODO Auto-generated method stub
+		int count = companyInfoDAO.exist(id);
+
+		return count > 0 ? true : false;
+	}
+
+	@Override
+	public List<CompanyInfo> list() {
+		// TODO Auto-generated method stub
+		return companyInfoDAO.list();
+	}
+
+	@Override
+	public Page<CompanyInfo> pageSearch(Map<String, Object> searchParams, int pageNumber, int pageSize,List<Sort> sortList) {
+        Page<CompanyInfo> page = PageHelper.startPage(pageNumber,pageSize).doSelectPage(()->{
+            companyInfoDAO.search(searchParams,sortList);
+        });
+
+        return page;
+	}
+
+
+	@Override
+	public List<CompanyInfo> findAllCompanyByCode(String code) {
+		return companyInfoDAO.findAllCompanyByCode(code);
+	}
+
+
+	@Override
+	public List<CompanyInfo> findByType(String type) {
+		return companyInfoDAO.findByType(type);
+	}
+
+	@Override
+	public int updateCode(String oldCode, String newCode) {
+		return companyInfoDAO.updateCode(oldCode + "%",oldCode.length()+1 ,newCode);
+	}
+
+	@Override
+	public List<CompanyInfo> findByParentId(String parentId) {
+		return companyInfoDAO.findByParentId(parentId);
+	}
+
+	@Override
+	public CompanyInfo findByName(String name) {
+		return companyInfoDAO.findByName(name);
+	}
+
+	@Override
+	public List<CompanyInfo> findByCompanyCodeAndType(String code,String type){
+		return companyInfoDAO.findByCompanyCodeAndType(code,type);
+	}
+
+	@Override
+	public Boolean hasChildren(String id) {
+		return countByParentId(id)>0;
+	}
+
+	@Override
+	public long countByParentId(String parentId) {
+		return companyInfoDAO.countByParentId(parentId);
+	}
+
+	@Override
+	public List<CompanyInfo> findByCompanyCode(String code,Long personId) {
+		return companyInfoDAO.findByCompanyCode(code,personId);
+	}
+
+}

+ 1 - 0
common/src/main/java/com/jpsoft/bus/modules/sys/dao/UserDAO.java

@@ -20,4 +20,5 @@ public interface UserDAO {
 	List<User> search(Map<String, Object> searchParams, List<Sort> sortList);
 	List<User> search(Map<String, Object> searchParams, List<Sort> sortList);
 	User findByUserName(@Param("userName") String userName);
 	User findByUserName(@Param("userName") String userName);
     long hasRole(@Param("userId") String userId, @Param("roleName") String roleName);
     long hasRole(@Param("userId") String userId, @Param("roleName") String roleName);
+	User findByOpenId(String openId);
 }
 }

+ 1 - 0
common/src/main/java/com/jpsoft/bus/modules/sys/service/UserService.java

@@ -18,4 +18,5 @@ public interface UserService {
 	User findByUserName(String userName);
 	User findByUserName(String userName);
 	List<User> findByRoleName(String roleName);
 	List<User> findByRoleName(String roleName);
 	boolean hasRole(String userId, String roleName) ;
 	boolean hasRole(String userId, String roleName) ;
+	User findByOpenId(String openId);
 }
 }

+ 5 - 0
common/src/main/java/com/jpsoft/bus/modules/sys/service/impl/UserServiceImpl.java

@@ -84,4 +84,9 @@ public class UserServiceImpl implements UserService {
 
 
 		return count>0;
 		return count>0;
 	}
 	}
+
+	@Override
+	public User findByOpenId(String openId) {
+		return userDAO.findByOpenId(openId);
+	}
 }
 }

+ 226 - 0
common/src/main/resources/mapper/base/CompanyInfo.xml

@@ -0,0 +1,226 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
+        "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
+<!-- namespace必须指向DAO接口 -->
+<mapper namespace="com.jpsoft.bus.modules.base.dao.CompanyInfoDAO">
+    <resultMap id="CompanyInfoMap" type="com.jpsoft.bus.modules.base.entity.CompanyInfo">
+        <id property="id" column="id_"/>
+        <result property="sortNo" column="sort_no"/>
+        <result property="name" column="name_"/>
+        <result property="fullName" column="full_name"/>
+        <result property="remark" column="remark_"/>
+        <result property="createBy" column="create_by"/>
+        <result property="createTime" column="create_time"/>
+        <result property="updateBy" column="update_by"/>
+        <result property="updateTime" column="update_time"/>
+        <result property="delFlag" column="del_flag"/>
+        <result property="parentId" column="parent_id"/>
+        <result property="code" column="code_"/>
+        <result property="parentName" column="parent_name"/>
+        <result property="type" column="type_"/>
+        <result property="typeName" column="type_name" />
+        <result property="level" column="level_"/>
+    </resultMap>
+    <insert id="insert" parameterType="com.jpsoft.bus.modules.base.entity.CompanyInfo">
+        <!--
+        <selectKey resultType="java.lang.String" order="BEFORE" keyProperty="id">
+            select sys_guid() from dual
+        </selectKey>
+        -->
+        <![CDATA[
+		insert into base_company_info
+	    (id_,sort_no,name_,full_name,remark_,create_by,create_time,
+	    update_by,update_time,del_flag,parent_id,code_,type_,level_
+	    )
+		values
+		(
+			#{id,jdbcType=VARCHAR}
+			,#{sortNo,jdbcType= NUMERIC }
+			,#{name,jdbcType=VARCHAR}
+			,#{fullName,jdbcType=VARCHAR}
+			,#{remark,jdbcType=VARCHAR}
+			,#{createBy,jdbcType=VARCHAR}
+			,#{createTime,jdbcType= TIMESTAMP }
+			,#{updateBy,jdbcType=VARCHAR}
+			,#{updateTime,jdbcType= TIMESTAMP }
+			,#{delFlag,jdbcType= NUMERIC }
+			,#{parentId,jdbcType=VARCHAR}
+			,#{code,jdbcType=VARCHAR}
+			,#{type,jdbcType=VARCHAR}
+			,#{level,jdbcType= NUMERIC }
+		)
+	]]>
+    </insert>
+    <delete id="delete" parameterType="string">
+        delete from base_company_info where id_=#{id,jdbcType=VARCHAR}
+    </delete>
+    <update id="update" parameterType="com.jpsoft.bus.modules.base.entity.CompanyInfo">
+        update base_company_info
+        <set>
+            <if test="sortNo!=null">
+                sort_no=#{sortNo,jdbcType= NUMERIC },
+            </if>
+            <if test="name!=null">
+                name_=#{name,jdbcType=VARCHAR},
+            </if>
+            <if test="name!=null">
+                full_name=#{fullName,jdbcType=VARCHAR},
+            </if>
+            <if test="remark!=null">
+                remark_=#{remark,jdbcType=VARCHAR},
+            </if>
+            <if test="createBy!=null">
+                create_by=#{createBy,jdbcType=VARCHAR},
+            </if>
+            <if test="createTime!=null">
+                create_time=#{createTime,jdbcType= TIMESTAMP },
+            </if>
+            <if test="updateBy!=null">
+                update_by=#{updateBy,jdbcType=VARCHAR},
+            </if>
+            <if test="updateTime!=null">
+                update_time=#{updateTime,jdbcType= TIMESTAMP },
+            </if>
+            <if test="delFlag!=null">
+                del_flag=#{delFlag,jdbcType= NUMERIC },
+            </if>
+            <if test="parentId!=null">
+                parent_id=#{parentId,jdbcType=VARCHAR},
+            </if>
+            <if test="code!=null">
+                code_=#{code,jdbcType=VARCHAR},
+            </if>
+            <if test="type!=null">
+                type_=#{type,jdbcType=VARCHAR},
+            </if>
+            <if test="level!=null">
+                level_=#{level,jdbcType= NUMERIC },
+            </if>
+        </set>
+        where id_=#{id}
+    </update>
+    <update id="updateCode">
+        update base_company_info
+        set code_ = concat(#{newCode},substr(code_,#{startIndex}))
+        where code_ like #{oldCode}
+    </update>
+    <select id="get" parameterType="string" resultMap="CompanyInfoMap">
+        select a.*,b.name_ as parent_name
+        from base_company_info a
+        left join base_company_info b on a.parent_id = b.id_
+        where a.id_=#{0}
+    </select>
+    <select id="exist" parameterType="string" resultType="int">
+        select count(*) from base_company_info where id_=#{0} and del_flag = 0
+    </select>
+    <select id="list" resultMap="CompanyInfoMap">
+        select * from base_company_info where del_flag=0 order by level_ asc,sort_no asc
+    </select>
+    <select id="search" parameterType="hashmap" resultMap="CompanyInfoMap">
+        <![CDATA[
+            select
+            a.*,
+            b.name_ as parent_name
+            from base_company_info a
+            left join base_company_info b on a.parent_id = b.id_
+		]]>
+        <where>
+            a.del_flag = 0
+            <if test="searchParams.name != null">
+                and a.name_ like #{searchParams.name}
+            </if>
+            <if test="searchParams.parentCode != null">
+                and b.code_ like #{searchParams.parentCode}
+            </if>
+            <if test="searchParams.bindCompanyCode != null">
+                and a.code_ like #{searchParams.bindCompanyCode}
+            </if>
+            <if test="searchParams.type != null">
+                and a.type_ = #{searchParams.type}
+            </if>
+        </where>
+        <foreach item="sort" collection="sortList" open="order by" separator=",">
+            a.${sort.name} ${sort.order}
+        </foreach>
+    </select>
+    <select id="findByParentId" resultMap="CompanyInfoMap">
+        select a.*,b.name_ as parent_name
+        from base_company_info a
+        left join base_company_info b on a.parent_id = b.id_
+        where a.del_flag=0
+        <if test="parentId!=null">
+            and a.parent_id=#{parentId,jdbcType=VARCHAR}
+        </if>
+        <if test="parentId==null">
+            and (a.parent_id is null or a.parent_id='')
+        </if>
+        order by a.level_ asc,a.sort_no asc,a.name_ asc
+    </select>
+    <select id="findByName" parameterType="string" resultMap="CompanyInfoMap">
+        select a.*,b.name_ as parent_name
+        from base_company_info a
+        left join base_company_info b on a.parent_id = b.id_
+        where (a.name_=#{0} or a.full_name=#{0})
+        and a.del_flag = 0
+        limit 1
+    </select>
+    <select id="findByCompanyCodeAndType" resultMap="CompanyInfoMap">
+        select * from base_company_info
+        where del_flag = 0
+        and code_ like #{code}
+        <if test="type!=null">
+            and type_ = #{type}
+        </if>
+        order by level_,sort_no asc
+    </select>
+
+    <select id="findAllCompanyByCode" resultMap="CompanyInfoMap">
+        <![CDATA[
+            select * from base_company_info
+            where del_flag = 0
+            and code_ like #{code}
+        ]]>
+    </select>
+
+    <select id="findByType" resultMap="CompanyInfoMap">
+        <![CDATA[
+        select * from base_company_info
+        where del_flag = 0
+        and type_ = #{type}
+        ]]>
+    </select>
+
+    <select id="countByParentId" resultType="long">
+        select count(*) from base_company_info
+        <where>
+            del_flag=0
+            <if test="parentId!=null">
+                and parent_id=#{parentId,jdbcType=VARCHAR}
+            </if>
+            <if test="parentId==null">
+                and (parent_id is null or parent_id='')
+            </if>
+        </where>
+    </select>
+
+    <select id="findByCompanyCode" resultMap="CompanyInfoMap">
+        select a.*,b.name_ as parent_name
+        from base_company_info a
+        left join base_company_info b on a.parent_id = b.id_
+        where a.del_flag=0
+        <trim prefix="and (" prefixOverrides="AND|OR" suffix=")">
+            <if test="code!=null">
+                a.code_ like #{code}
+            </if>
+            <if test="code==null">
+                a.code_='-1'
+            </if>
+            <if test="personId!=null">
+                or a.id_ in (
+                select c.company_id from base_person_company c where c.person_id = #{personId}
+                )
+            </if>
+        </trim>
+        order by a.level_ asc,a.sort_no asc,a.name_ asc
+    </select>
+</mapper>

+ 4 - 2
common/src/main/resources/mapper/sys/User.xml

@@ -100,8 +100,10 @@
     </select>
     </select>
     <select id="search" parameterType="hashmap" resultMap="UserMap">
     <select id="search" parameterType="hashmap" resultMap="UserMap">
         <![CDATA[
         <![CDATA[
-			select a.*,b.name_ as company_name
-			from sys_user a LEFT JOIN base_company_info b ON a.company_id = b.id_
+			select a.*,
+			b.name_ as company_name
+			from sys_user a
+			LEFT JOIN base_company_info b ON a.company_id = b.id_
 			where a.del_flag = 0
 			where a.del_flag = 0
 		]]>
 		]]>
         <if test="searchParams.userName != null">
         <if test="searchParams.userName != null">

+ 449 - 0
web/src/main/java/com/jpsoft/bus/modules/base/controller/CompanyInfoController.java

@@ -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;
+    }
+
+
+}

+ 156 - 0
web/src/main/java/com/jpsoft/bus/modules/common/controller/JwtsUserController.java

@@ -0,0 +1,156 @@
+package com.jpsoft.bus.modules.common.controller;
+
+import com.jpsoft.bus.modules.common.dto.MessageResult;
+import com.jpsoft.bus.modules.common.utils.DES3;
+import com.jpsoft.bus.modules.common.utils.JwtUtil;
+import com.jpsoft.bus.modules.sys.entity.User;
+import com.jpsoft.bus.modules.sys.service.UserService;
+import io.swagger.annotations.ApiImplicitParam;
+import io.swagger.annotations.ApiImplicitParams;
+import io.swagger.annotations.ApiOperation;
+import lombok.extern.slf4j.Slf4j;
+import org.apache.commons.lang3.StringUtils;
+import org.joda.time.DateTime;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.annotation.Value;
+import org.springframework.data.redis.core.ValueOperations;
+import org.springframework.web.bind.annotation.*;
+import springfox.documentation.annotations.ApiIgnore;
+
+import javax.servlet.http.HttpSession;
+import java.util.concurrent.TimeUnit;
+
+@Slf4j
+@RestController
+public class JwtsUserController {
+    @Value("${jwt.secret}")
+    private String jwtSecret;
+
+    @Autowired
+    private UserService userService;
+
+    @Autowired
+    private ValueOperations<String,Object> valueOperations;
+
+    /**
+     * 接收扫码登录回调
+     * @param eventKey
+     * @param openId
+     * @return 返回值会在微信中显示
+     */
+    @ApiOperation(value = "接收扫码登录回调")
+    @PostMapping(value="/qrcode/scanLogin")
+    @ResponseBody
+    public MessageResult<String> scanLogin(String eventKey, String openId){
+        MessageResult<String> messageResult = new MessageResult<>();
+        log.warn(openId + "请求登录!");
+        String result;
+
+        User user = userService.findByOpenId(openId);
+
+        if(user!=null) {
+            String[] arr = eventKey.split(",");
+            String randNum = arr[1];
+
+            long expireSeconds = 3000; //5分钟
+
+            //生成token
+            String token = JwtUtil.createToken(jwtSecret,user.getId(), DateTime.now().plusHours(6).toDate());
+
+            valueOperations.set("scan_qrcode_login_" + randNum, token, expireSeconds, TimeUnit.SECONDS);
+            messageResult.setMessage("扫码登录成功!");
+            messageResult.setResult(true);
+        }
+        else{
+            messageResult.setMessage("当前用户未绑定微信!");
+            messageResult.setResult(false);
+        }
+
+        return messageResult;
+    }
+
+    @PostMapping("/qrcode/queryScanResult")
+    @ApiOperation(value="查询扫码结果")
+    public MessageResult<String> queryScanResult(String rnd){
+        MessageResult<String> messageResult = new MessageResult<>();
+
+        try {
+            String data = (String)valueOperations.get("scan_qrcode_login_" + rnd);
+
+            if(StringUtils.isNotEmpty(data)) {
+                messageResult.setData(data);
+                messageResult.setResult(true);
+            }
+            else{
+                messageResult.setResult(false);
+                messageResult.setMessage("暂无扫码结果");
+            }
+        }
+        catch (Exception ex){
+            log.error(ex.getMessage(),ex);
+
+            messageResult.setResult(false);
+            messageResult.setMessage(ex.getMessage());
+        }
+
+        return messageResult;
+    }
+
+    @PostMapping("/login")
+    @ApiOperation(value="登录获取token,在swagger ui中获取token时将写入session,调用其它接口时不用再设置header")
+    @ApiImplicitParams({
+            @ApiImplicitParam(name="userName", paramType="query", required=true, value="用户名"),
+            @ApiImplicitParam(name="password", paramType="query", required=true, value="密码")
+    })
+    public MessageResult<String> login(String userName, String password, @ApiIgnore HttpSession session){
+        MessageResult<String> messageResult = new MessageResult<>();
+
+        try {
+            User user = userService.findByUserName(userName);
+
+            DES3 des3 = new DES3();
+
+            String passwordEnc = des3.encrypt(jwtSecret,password);
+
+            if(user!=null && passwordEnc.equals(user.getPassword())){
+
+                //生成token
+                String token = JwtUtil.createToken(jwtSecret,user.getId(), DateTime.now().plusHours(6).toDate());
+
+                session.setAttribute("token",token);
+
+                messageResult.setResult(true);
+                messageResult.setData(token);
+            }
+            else{
+                messageResult.setResult(false);
+                messageResult.setMessage("用户不存在或密码错误!");
+            }
+
+        }
+        catch(Exception ex){
+            messageResult.setResult(false);
+            messageResult.setMessage(ex.getMessage());
+        }
+
+        return messageResult;
+    }
+
+    @GetMapping("/userInfo")
+    public MessageResult<User> userInfo(@RequestAttribute String subject){
+        MessageResult<User> messageResult = new MessageResult<>();
+
+        try {
+            User user = userService.get(subject);
+
+            messageResult.setResult(true);
+            messageResult.setData(user);
+        }
+        catch(Exception ex){
+            messageResult.setResult(false);
+            messageResult.setMessage(ex.getMessage());
+        }
+
+        return messageResult;
+    }
+}

+ 62 - 0
web/src/main/java/com/jpsoft/bus/modules/common/controller/TinymceController.java

@@ -0,0 +1,62 @@
+package com.jpsoft.bus.modules.common.controller;
+
+import com.jpsoft.bus.config.OSSConfig;
+import com.jpsoft.bus.modules.common.utils.OSSUtil;
+import org.apache.commons.lang3.StringUtils;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Controller;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RequestMethod;
+import org.springframework.web.bind.annotation.RequestParam;
+import org.springframework.web.bind.annotation.ResponseBody;
+import org.springframework.web.multipart.MultipartFile;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import java.io.IOException;
+import java.util.HashMap;
+import java.util.Map;
+
+@Controller
+@RequestMapping("/tinymce")
+public class TinymceController {
+    @Autowired
+    private OSSConfig ossConfig;
+
+    @RequestMapping(value = "/upload", method = RequestMethod.POST)
+    @ResponseBody
+    public Map<String, String> upload(HttpServletRequest request, HttpServletResponse response, @RequestParam MultipartFile upfile) throws IOException {
+	    Map<String, String> result = new HashMap<>();
+
+	    if (request.getMethod().equals("OPTIONS")){
+            response.setStatus(202);
+            return result;
+        }
+
+    	String retImgUrl = "";
+		String subFolder ="/editor";
+
+		try {
+            retImgUrl = OSSUtil.upload(ossConfig,subFolder,upfile.getOriginalFilename(),upfile.getInputStream());
+		} catch (Exception e) {
+			// TODO Auto-generated catch block
+			e.printStackTrace();
+		}
+
+    	String oldFileName= upfile.getOriginalFilename();
+
+    	//返回类型
+        if(StringUtils.isNotEmpty(retImgUrl)){
+	    	result.put("url", retImgUrl);
+	        result.put("size", String.valueOf(upfile.getSize()));  
+	        result.put("type", oldFileName.substring(oldFileName.lastIndexOf(".")));
+	        result.put("title", oldFileName.substring(0,oldFileName.lastIndexOf(".")));
+	        result.put("original", oldFileName.substring(0,oldFileName.lastIndexOf(".")));//文件名称
+	        result.put("state", STATE_SUCESS);
+        }
+
+        return result;  
+    }
+
+    private final static String STATE_SUCESS = "SUCCESS";
+}

+ 47 - 0
web/src/main/java/com/jpsoft/bus/modules/common/controller/fileUploadController.java

@@ -0,0 +1,47 @@
+package com.jpsoft.bus.modules.common.controller;
+
+import com.jpsoft.bus.config.OSSConfig;
+import com.jpsoft.bus.modules.common.dto.MessageResult;
+import com.jpsoft.bus.modules.common.utils.OSSUtil;
+import io.swagger.annotations.ApiImplicitParam;
+import io.swagger.annotations.ApiImplicitParams;
+import io.swagger.annotations.ApiOperation;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.PostMapping;
+import org.springframework.web.bind.annotation.RestController;
+import org.springframework.web.multipart.MultipartFile;
+
+@RestController
+public class fileUploadController {
+    private Logger logger = LoggerFactory.getLogger(getClass());
+
+    @Autowired
+    private OSSConfig ossConfig;
+
+    @PostMapping("uploadPicture")
+    @ApiOperation(value="人员照片上传")
+    @ApiImplicitParams({
+            @ApiImplicitParam(name="subFolder",value = "路径",required = true,paramType = "form"),
+            @ApiImplicitParam(name = "photoFile",value = "员工照片", required = true,paramType="form", dataType = "__file")
+    })
+    public MessageResult<String> uploadPicture(String subFolder, MultipartFile photoFile){
+        MessageResult<String> messageResult = new MessageResult<>();
+
+        try {
+            String retFileUrl = OSSUtil.upload(ossConfig,"/" + subFolder,photoFile.getOriginalFilename(),photoFile.getInputStream());
+
+            messageResult.setResult(true);
+            messageResult.setData(retFileUrl);
+            messageResult.setCode(200);
+        } catch (Exception e) {
+            logger.error(e.getMessage(),e);
+
+            messageResult.setResult(false);
+            messageResult.setMessage(e.getMessage());
+        }
+
+        return messageResult;
+    }
+}

+ 51 - 0
web/src/main/java/com/jpsoft/bus/modules/common/utils/JwtUtil.java

@@ -0,0 +1,51 @@
+package com.jpsoft.bus.modules.common.utils;
+
+import io.jsonwebtoken.Claims;
+import io.jsonwebtoken.Jwts;
+import io.jsonwebtoken.security.Keys;
+
+import java.security.Key;
+import java.util.Base64;
+import java.util.Date;
+
+public class JwtUtil {
+    public static String createToken(String jwtSecret, String subject, Date expiration) {
+        //token有效时间天
+        byte[] privateKey = Base64.getDecoder().decode(jwtSecret);
+
+        Key key = Keys.hmacShaKeyFor(privateKey);
+
+        String token = Jwts.builder()
+                    .setSubject(subject)
+                //设置自定义claims后,setSubject值将失效
+//               .setClaims(extraInfo)
+                    .signWith(key)
+                    .setExpiration(expiration)
+                    .compact();
+
+        return "Bearer " + token;
+    }
+
+    public static String decodeToken(String jwtSecret,String token) throws Exception{
+        String prefix = "Bearer ";
+
+        if (token==null || token.length() < prefix.length()){
+            throw new Exception("未传递令牌或未带前缀Bearer!");
+        }
+
+        token = token.substring(prefix.length());
+
+        byte[] privateKey = Base64.getDecoder().decode(jwtSecret);
+
+        Key key = Keys.hmacShaKeyFor(privateKey);
+
+        Claims claims = Jwts.parser()
+                .setSigningKey(key)
+                .parseClaimsJws(token)
+                .getBody();
+
+        String subject = claims.getSubject();
+
+        return subject;
+    }
+}