Browse Source

新增单位

jz.kai 2 years ago
parent
commit
1d0d43ac43

+ 19 - 0
common/src/main/java/com/jpsoft/excellent/modules/base/dao/OfficeDAO.java

@@ -0,0 +1,19 @@
+package com.jpsoft.excellent.modules.base.dao;
+
+import java.util.List;
+import org.springframework.stereotype.Repository;
+import com.jpsoft.excellent.modules.base.entity.Office;
+import java.util.Map;
+import com.jpsoft.excellent.modules.common.dto.Sort;
+
+@Repository
+public interface OfficeDAO {
+	int insert(Office entity);
+	int update(Office entity);
+	int exist(String id);
+	Office get(String id);
+	int delete(String id);
+	List<Office> list();
+	List<Office> search(Map<String,Object> searchParams,List<Sort> sortList);
+	List<Office> listByName(String name);
+}

+ 40 - 0
common/src/main/java/com/jpsoft/excellent/modules/base/entity/Office.java

@@ -0,0 +1,40 @@
+package com.jpsoft.excellent.modules.base.entity;
+
+import java.io.Serializable;
+import java.util.Date;
+import java.text.SimpleDateFormat;
+import java.math.BigDecimal;
+import org.springframework.format.annotation.DateTimeFormat;
+import com.fasterxml.jackson.annotation.JsonFormat;
+import io.swagger.annotations.ApiModelProperty;
+import io.swagger.annotations.ApiModel;
+import lombok.Data;
+
+/**
+  描述:base_office的实体类
+ */
+@Data
+@ApiModel(value = "base_office的实体类")
+public class Office {
+        @ApiModelProperty(value = "编号")
+    private String id;
+        @ApiModelProperty(value = "区域编号")
+    private String areaId;
+    private String areaName;
+        @ApiModelProperty(value = "单位名称")
+    private String name;
+        @ApiModelProperty(value = "是否删除")
+    private Boolean delFlag;
+        @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 createBy;
+        @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 String updateBy;
+}

+ 18 - 0
common/src/main/java/com/jpsoft/excellent/modules/base/service/OfficeService.java

@@ -0,0 +1,18 @@
+package com.jpsoft.excellent.modules.base.service;
+
+import java.util.List;
+import java.util.Map;
+import com.jpsoft.excellent.modules.base.entity.Office;
+import com.github.pagehelper.Page;
+import com.jpsoft.excellent.modules.common.dto.Sort;
+
+public interface OfficeService {
+	Office get(String id);
+	boolean exist(String id);
+	int insert(Office model);
+	int update(Office model);
+	int delete(String id);
+	List<Office> list();
+	Page<Office> pageSearch(Map<String, Object> searchParams,int pageNum,int pageSize,boolean count,List<Sort> sortList);
+	List<Office> listByName(String name);
+}

+ 76 - 0
common/src/main/java/com/jpsoft/excellent/modules/base/service/impl/OfficeServiceImpl.java

@@ -0,0 +1,76 @@
+package com.jpsoft.excellent.modules.base.service.impl;
+
+import java.util.List;
+import java.util.Map;
+import java.util.UUID;
+import javax.annotation.Resource;
+import org.springframework.stereotype.Component;
+import org.springframework.transaction.annotation.Transactional;
+import com.jpsoft.excellent.modules.base.dao.OfficeDAO;
+import com.jpsoft.excellent.modules.base.entity.Office;
+import com.jpsoft.excellent.modules.base.service.OfficeService;
+import com.github.pagehelper.Page;
+import com.jpsoft.excellent.modules.common.dto.Sort;
+import com.github.pagehelper.PageHelper;
+
+@Transactional
+@Component(value="officeService")
+public class OfficeServiceImpl implements OfficeService {
+	@Resource(name="officeDAO")
+	private OfficeDAO officeDAO;
+
+	@Override
+	public Office get(String id) {
+		// TODO Auto-generated method stub
+		return officeDAO.get(id);
+	}
+
+	@Override
+	public int insert(Office model) {
+		// TODO Auto-generated method stub
+		//model.setId(UUID.randomUUID().toString());
+		
+		return officeDAO.insert(model);
+	}
+
+	@Override
+	public int update(Office model) {
+		// TODO Auto-generated method stub
+		return officeDAO.update(model);		
+	}
+
+	@Override
+	public int delete(String id) {
+		// TODO Auto-generated method stub
+		return officeDAO.delete(id);
+	}
+
+	@Override
+	public boolean exist(String id) {
+		// TODO Auto-generated method stub
+		int count = officeDAO.exist(id);
+		
+		return count > 0 ? true : false;
+	}
+	
+	@Override
+	public List<Office> list() {
+		// TODO Auto-generated method stub
+		return officeDAO.list();
+	}
+		
+	@Override
+	public Page<Office> pageSearch(Map<String, Object> searchParams, int pageNumber, int pageSize,boolean count,List<Sort> sortList) {
+        Page<Office> page = PageHelper.startPage(pageNumber,pageSize,count).doSelectPage(()->{
+            officeDAO.search(searchParams,sortList);
+        });
+        
+        return page;
+	}
+
+	@Override
+	public List<Office> listByName(String name) {
+		// TODO Auto-generated method stub
+		return officeDAO.listByName(name);
+	}
+}

+ 99 - 0
common/src/main/resources/mapper/base/Office.xml

@@ -0,0 +1,99 @@
+<?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.excellent.modules.base.dao.OfficeDAO">
+	<resultMap id="OfficeMap" type="com.jpsoft.excellent.modules.base.entity.Office">
+		<id property="id" column="id_" />
+			<result property="areaId" column="area_id" />
+			<result property="name" column="name_" />
+			<result property="delFlag" column="del_flag" />
+			<result property="createTime" column="create_time" />
+			<result property="createBy" column="create_by" />
+			<result property="updateTime" column="update_time" />
+			<result property="updateBy" column="update_by" />
+			</resultMap>
+	<insert id="insert" parameterType="com.jpsoft.excellent.modules.base.entity.Office">
+	<!--
+	<selectKey resultType="java.lang.String" order="BEFORE" keyProperty="id">
+		select sys_guid() from dual
+	</selectKey>
+	-->
+	<![CDATA[
+		insert into base_office
+	    (id_,area_id,name_,del_flag,create_time,create_by,update_time,update_by)
+		values
+		(
+#{id,jdbcType=VARCHAR}
+,#{areaId,jdbcType=VARCHAR}
+,#{name,jdbcType=VARCHAR}
+,#{delFlag,jdbcType= NUMERIC }
+,#{createTime,jdbcType= TIMESTAMP }
+,#{createBy,jdbcType=VARCHAR}
+,#{updateTime,jdbcType= TIMESTAMP }
+,#{updateBy,jdbcType=VARCHAR}
+		)
+	]]>
+	</insert>
+	<delete id="delete" parameterType="string">
+		delete from base_office where id_=#{id,jdbcType=VARCHAR}
+	</delete>
+	<update id="update" parameterType="com.jpsoft.excellent.modules.base.entity.Office">
+		update base_office
+		<set>
+				<if test="areaId!=null">
+		area_id=#{areaId,jdbcType=VARCHAR},
+		</if>
+				<if test="name!=null">
+		name_=#{name,jdbcType=VARCHAR},
+		</if>
+				<if test="delFlag!=null">
+		del_flag=#{delFlag,jdbcType= NUMERIC },
+		</if>
+				<if test="createTime!=null">
+		create_time=#{createTime,jdbcType= TIMESTAMP },
+		</if>
+				<if test="createBy!=null">
+		create_by=#{createBy,jdbcType=VARCHAR},
+		</if>
+				<if test="updateTime!=null">
+		update_time=#{updateTime,jdbcType= TIMESTAMP },
+		</if>
+				<if test="updateBy!=null">
+		update_by=#{updateBy,jdbcType=VARCHAR},
+		</if>
+		</set>
+	where id_=#{id}
+	</update>
+	<select id="get" parameterType="string" resultMap="OfficeMap">
+		select 
+id_,area_id,name_,del_flag,create_time,create_by,update_time,update_by		from base_office where id_=#{0}
+	</select>
+	<select id="exist" parameterType="string" resultType="int">
+		select count(*) from base_office where id_=#{0}
+	</select>
+	<select id="list" resultMap="OfficeMap">
+		select * from base_office
+	</select>
+	<select id="search" parameterType="hashmap" resultMap="OfficeMap">
+		<![CDATA[
+			select * from base_office
+		]]>
+		<where>
+			<if test="searchParams.areaId != null">
+				and area_id = #{searchParams.areaId}
+			</if>
+			<if test="searchParams.name != null">
+				and name_ like #{searchParams.name}
+			</if>
+		</where>
+		<foreach item="sort" collection="sortList"  open="order by" separator=",">
+	        ${sort.name} ${sort.order}
+	 	</foreach>
+	</select>
+	<select id="listByName" parameterType="string" resultMap="OfficeMap">
+		select * from base_office
+		where del_flag=0
+		and name_ =#{0}
+	</select>
+</mapper>

+ 371 - 0
web/src/main/java/com/jpsoft/excellent/modules/base/controller/OfficeController.java

@@ -0,0 +1,371 @@
+package com.jpsoft.excellent.modules.base.controller;
+
+import com.github.pagehelper.Page;
+import com.jpsoft.excellent.config.OSSConfig;
+import com.jpsoft.excellent.modules.base.entity.Area;
+import com.jpsoft.excellent.modules.base.entity.WorkStation;
+import com.jpsoft.excellent.modules.base.entity.WorkWindow;
+import com.jpsoft.excellent.modules.base.service.AreaService;
+import com.jpsoft.excellent.modules.common.utils.OSSUtil;
+import com.jpsoft.excellent.modules.common.utils.POIUtils;
+import com.jpsoft.excellent.modules.common.utils.PojoUtils;
+import com.jpsoft.excellent.modules.common.dto.Sort;
+import com.jpsoft.excellent.modules.common.dto.MessageResult;
+import com.jpsoft.excellent.modules.base.entity.Office;
+import com.jpsoft.excellent.modules.base.service.OfficeService;
+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.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.SimpleDateFormat;
+import java.util.*;
+
+@RestController
+@RequestMapping("/base/office")
+@Api(description = "office")
+public class OfficeController {
+    private Logger logger = LoggerFactory.getLogger(getClass());
+
+    @Autowired
+    private OSSConfig ossConfig;
+    @Autowired
+    private OfficeService officeService;
+    @Autowired
+    private AreaService areaService;
+
+    @ApiOperation(value="创建空记录")
+    @GetMapping("create")
+    public MessageResult<Office> create(){
+        MessageResult<Office> msgResult = new MessageResult<>();
+
+        Office office = new Office();
+
+        msgResult.setData(office);
+        msgResult.setResult(true);
+
+        return msgResult;
+    }
+    
+    @ApiOperation(value="添加信息")
+    @PostMapping("add")
+    public MessageResult<Office> add(@RequestBody Office office,@RequestAttribute String subject){
+        MessageResult<Office> msgResult = new MessageResult<>();
+
+        try {
+            office.setId(UUID.randomUUID().toString());
+            office.setDelFlag(false);
+            office.setCreateBy(subject);
+            office.setCreateTime(new Date());
+            
+            int affectCount = officeService.insert(office);
+
+            if (affectCount > 0) {
+                msgResult.setResult(true);
+                msgResult.setData(office);
+            } 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<Office> edit(@PathVariable("id") String id){
+        MessageResult<Office> msgResult = new MessageResult<>();
+
+        try {
+            Office office = officeService.get(id);
+            Area area = areaService.get(office.getAreaId());
+            if(area != null){
+                office.setAreaName(area.getName());
+            }
+
+            if (office != null) {
+                msgResult.setResult(true);
+                msgResult.setData(office);
+            } 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<Office> update(@RequestBody Office office,@RequestAttribute String subject){
+        MessageResult<Office> msgResult = new MessageResult<>();
+
+        try {
+            office.setUpdateBy(subject);
+            office.setUpdateTime(new Date());
+            
+            int affectCount = officeService.update(office);
+
+            if (affectCount > 0) {
+                msgResult.setResult(true);
+                msgResult.setData(office);
+            } 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 {
+            Office office = officeService.get(id);
+            office.setDelFlag(true);
+            office.setUpdateBy(subject);
+            office.setUpdateTime(new Date());
+
+            int affectCount = officeService.update(office);
+
+            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) {
+                Office office = officeService.get(id);
+                office.setDelFlag(true);
+                office.setUpdateBy(subject);
+                office.setUpdateTime(new Date());
+
+                affectCount += officeService.update(office);
+            }
+
+            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 areaId, String name,
+            @RequestParam(value="pageIndex",defaultValue="1") int pageIndex,
+            @RequestParam(value="pageSize",defaultValue="20") int pageSize,
+            @RequestAttribute String subject){
+        MessageResult<Map> msgResult = new MessageResult<>();
+
+        Map<String,Object> searchParams = new HashMap<>();
+
+        List<Sort> sortList = new ArrayList<>();
+        sortList.add(new Sort("name_","asc"));
+
+        if (StringUtils.isNotEmpty(areaId)) {
+            searchParams.put("areaId",areaId);
+        }
+        if (StringUtils.isNotEmpty(name)) {
+            searchParams.put("name","%" + name + "%");
+        }
+
+        Page<Office> page = officeService.pageSearch(searchParams,pageIndex,pageSize,true,sortList);
+        for(Office office : page.getResult()){
+            office.setAreaName(parentFullName(office.getAreaId()));
+        }
+
+        msgResult.setResult(true);
+        msgResult.setData(PojoUtils.pageWrapper(page));
+
+        return msgResult;
+    }
+
+    private String parentFullName(String parentId){
+        String fullName = "";
+
+        Area area = areaService.get(parentId);
+        if(StringUtils.isNotEmpty(area.getParentId())){
+            fullName = parentFullName(area.getParentId()) + "-" + area.getName();
+        }
+        else {
+            fullName = area.getName();
+        }
+
+        return fullName;
+    }
+
+    @ApiOperation(value="导入站点")
+    @PostMapping("importXls")
+    @ApiImplicitParams({
+            @ApiImplicitParam(name = "uploadFile",value = "上传文件", required = true,paramType="form", dataType = "__file")
+    })
+    public MessageResult<String> importXls(MultipartFile uploadFile, @RequestAttribute String subject){
+        MessageResult<String> msgResult = new MessageResult<>();
+
+        try {
+            POIUtils poiUtils = new POIUtils(uploadFile.getInputStream());
+            Sheet sheet1 = poiUtils.getSheetAt(0);
+
+            int affectCount = 0;
+            int failCount = 0;
+            int validateColIndex = 2;
+
+            for(int rowIndex=1; rowIndex<=sheet1.getLastRowNum(); rowIndex++){
+                try {
+                    String strArea = poiUtils.getCellValue(0,rowIndex,0).toString();
+                    String strName = poiUtils.getCellValue(0,rowIndex,1).toString();
+
+                    //单位信息
+                    Office office = new Office();
+                    office.setId(UUID.randomUUID().toString());
+                    office.setDelFlag(false);
+                    office.setCreateBy(subject);
+                    office.setCreateTime(new Date());
+
+                    if(StringUtils.isNotEmpty(strArea)){
+                        Area area = areaService.getByName(strArea);
+                        if(area != null) {
+                            office.setAreaId(area.getId());
+                        }
+                        else{
+                            sheet1.getRow(rowIndex).createCell(validateColIndex).setCellValue("未找到该区域!");
+                            failCount++;
+                            continue;
+                        }
+                    }
+                    else{
+                        sheet1.getRow(rowIndex).createCell(validateColIndex).setCellValue("请填写区域!");
+                        failCount++;
+                        continue;
+                    }
+
+                    if(StringUtils.isNotEmpty(strName)){
+                        office.setName(strName);
+                    }
+                    else{
+                        sheet1.getRow(rowIndex).createCell(validateColIndex).setCellValue("请填写单位名称!");
+                        failCount++;
+                        continue;
+                    }
+
+                    List<Office> officeExtant = officeService.listByName(strName);
+                    if(officeExtant.size() == 0) {
+                        officeService.insert(office);
+                    }
+                    else{
+                        office = officeExtant.get(0);
+                    }
+
+                    affectCount++;
+                }
+                catch(Exception innerEx){
+                    logger.error(innerEx.getMessage(),innerEx);
+                    failCount++;
+                }
+            }
+
+            if (failCount>0){
+                //有导入失败的记录
+                msgResult.setResult(false);
+                msgResult.setMessage("数据成功导入" + affectCount + "条,有" + failCount + "条数据未导入成功,错误原因请查看报表。");
+
+                //todo 只保留错误数据的sheet
+                Workbook wb = poiUtils.exportErrorXls(0,validateColIndex,1 + affectCount + failCount);
+
+                //todo 将wb保存到oss
+                ByteArrayOutputStream output = new ByteArrayOutputStream();
+                wb.write(output);
+
+                byte[] buffer = output.toByteArray();
+                ByteArrayInputStream input = new ByteArrayInputStream(buffer);
+
+                //格式化holidayInfo
+                SimpleDateFormat sim = new SimpleDateFormat("yyyyMMddHHmmss");
+                String fileName = "error" + sim.format(new Date()) + ".xls";
+                String downloadUrl = OSSUtil.upload(ossConfig,"excellent",fileName,input);
+
+                //todo 返回导入失败报表下载链接
+                msgResult.setData(downloadUrl);
+            }
+            else{
+                msgResult.setResult(true);
+                msgResult.setMessage("数据成功导入" + affectCount + "条");
+            }
+        }
+        catch(Exception ex){
+            logger.error(ex.getMessage(),ex);
+
+            msgResult.setResult(false);
+            msgResult.setMessage(ex.getMessage());
+        }
+
+        return msgResult;
+    }
+}