|
@@ -0,0 +1,364 @@
|
|
|
|
+package com.jpsoft.smart.modules.base.controller;
|
|
|
|
+
|
|
|
|
+import com.github.pagehelper.Page;
|
|
|
|
+import com.jpsoft.smart.config.OSSConfig;
|
|
|
|
+import com.jpsoft.smart.modules.base.dto.EmployeeInfoDTO;
|
|
|
|
+import com.jpsoft.smart.modules.common.utils.OSSUtil;
|
|
|
|
+import com.jpsoft.smart.modules.common.utils.PojoUtils;
|
|
|
|
+import com.jpsoft.smart.modules.common.dto.Sort;
|
|
|
|
+import com.jpsoft.smart.modules.common.dto.MessageResult;
|
|
|
|
+import com.jpsoft.smart.modules.base.entity.EmployeeInfo;
|
|
|
|
+import com.jpsoft.smart.modules.base.service.EmployeeInfoService;
|
|
|
|
+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.slf4j.Logger;
|
|
|
|
+import org.slf4j.LoggerFactory;
|
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
+import org.springframework.http.MediaType;
|
|
|
|
+import org.springframework.stereotype.Controller;
|
|
|
|
+import org.springframework.web.bind.annotation.*;
|
|
|
|
+import org.springframework.web.multipart.MultipartFile;
|
|
|
|
+
|
|
|
|
+import javax.servlet.http.HttpServletRequest;
|
|
|
|
+import javax.servlet.http.HttpServletResponse;
|
|
|
|
+import java.io.InputStream;
|
|
|
|
+import java.io.InputStreamReader;
|
|
|
|
+import java.io.OutputStream;
|
|
|
|
+import java.io.StringReader;
|
|
|
|
+import java.text.SimpleDateFormat;
|
|
|
|
+import java.util.*;
|
|
|
|
+
|
|
|
|
+@Controller
|
|
|
|
+@RequestMapping("/base/employeeInfo")
|
|
|
|
+@Api(description = "employeeInfo")
|
|
|
|
+public class EmployeeInfoController {
|
|
|
|
+ private Logger logger = LoggerFactory.getLogger(getClass());
|
|
|
|
+
|
|
|
|
+ @Autowired
|
|
|
|
+ private OSSConfig ossConfig;
|
|
|
|
+
|
|
|
|
+ @Autowired
|
|
|
|
+ private EmployeeInfoService employeeInfoService;
|
|
|
|
+
|
|
|
|
+ @ApiOperation(value="创建空记录")
|
|
|
|
+ @GetMapping("create")
|
|
|
|
+ @ResponseBody
|
|
|
|
+ public MessageResult<EmployeeInfo> create(){
|
|
|
|
+ MessageResult<EmployeeInfo> msgResult = new MessageResult<>();
|
|
|
|
+
|
|
|
|
+ EmployeeInfo employeeInfo = new EmployeeInfo();
|
|
|
|
+
|
|
|
|
+ msgResult.setData(employeeInfo);
|
|
|
|
+ msgResult.setResult(true);
|
|
|
|
+
|
|
|
|
+ return msgResult;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @ApiOperation(value="编辑信息")
|
|
|
|
+ @GetMapping("edit/{id}")
|
|
|
|
+ @ResponseBody
|
|
|
|
+ public MessageResult<EmployeeInfo> edit(@PathVariable("id") Long id){
|
|
|
|
+ MessageResult<EmployeeInfo> msgResult = new MessageResult<>();
|
|
|
|
+
|
|
|
|
+ try {
|
|
|
|
+ EmployeeInfo employeeInfo = employeeInfoService.get(id);
|
|
|
|
+
|
|
|
|
+ if (employeeInfo != null) {
|
|
|
|
+ msgResult.setResult(true);
|
|
|
|
+ msgResult.setData(employeeInfo);
|
|
|
|
+ } 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")
|
|
|
|
+ @ResponseBody
|
|
|
|
+ public MessageResult<EmployeeInfo> update(@RequestBody EmployeeInfo employeeInfo,@RequestAttribute String subject){
|
|
|
|
+ MessageResult<EmployeeInfo> msgResult = new MessageResult<>();
|
|
|
|
+
|
|
|
|
+ try {
|
|
|
|
+ employeeInfo.setUpdateBy(subject);
|
|
|
|
+ employeeInfo.setUpdateTime(new Date());
|
|
|
|
+
|
|
|
|
+ int affectCount = employeeInfoService.update(employeeInfo);
|
|
|
|
+
|
|
|
|
+ if (affectCount > 0) {
|
|
|
|
+ msgResult.setResult(true);
|
|
|
|
+ msgResult.setData(employeeInfo);
|
|
|
|
+ } 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}")
|
|
|
|
+ @ResponseBody
|
|
|
|
+ public MessageResult<Integer> delete(@PathVariable("id") Long id,@RequestAttribute String subject){
|
|
|
|
+ MessageResult<Integer> msgResult = new MessageResult<>();
|
|
|
|
+
|
|
|
|
+ try {
|
|
|
|
+ EmployeeInfo employeeInfo = employeeInfoService.get(id);
|
|
|
|
+ employeeInfo.setDelFlag(true);
|
|
|
|
+ employeeInfo.setUpdateBy(subject);
|
|
|
|
+ employeeInfo.setUpdateTime(new Date());
|
|
|
|
+
|
|
|
|
+ int affectCount = employeeInfoService.update(employeeInfo);
|
|
|
|
+
|
|
|
|
+ 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)
|
|
|
|
+ @ResponseBody
|
|
|
|
+ public MessageResult<Map> pageList(
|
|
|
|
+ String employeeName,
|
|
|
|
+ String companyId,
|
|
|
|
+ @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("c.sort_no","asc"));
|
|
|
|
+ sortList.add(new Sort("e.id_","asc"));
|
|
|
|
+
|
|
|
|
+ if (StringUtils.isNotEmpty(employeeName)) {
|
|
|
|
+ searchParams.put("employeeName","%" + employeeName + "%");
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if (StringUtils.isNotEmpty(companyId)) {
|
|
|
|
+ searchParams.put("companyId",companyId);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ Page<EmployeeInfo> page = employeeInfoService.pageSearch(searchParams,pageIndex,pageSize,sortList);
|
|
|
|
+
|
|
|
|
+ msgResult.setResult(true);
|
|
|
|
+ msgResult.setData(PojoUtils.pageWrapper(page));
|
|
|
|
+
|
|
|
|
+ return msgResult;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @ApiOperation(value="根据openId获取员工信息")
|
|
|
|
+ @GetMapping("mobile/findByOpenId")
|
|
|
|
+ @ResponseBody
|
|
|
|
+ public MessageResult<EmployeeInfoDTO> findByOpenId(String openId){
|
|
|
|
+ MessageResult<EmployeeInfoDTO> msgResult = new MessageResult<>();
|
|
|
|
+
|
|
|
|
+ try {
|
|
|
|
+ EmployeeInfo employeeInfo = employeeInfoService.findByOpenId(openId);
|
|
|
|
+
|
|
|
|
+ if (employeeInfo != null) {
|
|
|
|
+ msgResult.setResult(true);
|
|
|
|
+
|
|
|
|
+ EmployeeInfoDTO dto = new EmployeeInfoDTO();
|
|
|
|
+ PojoUtils.map(employeeInfo,dto);
|
|
|
|
+
|
|
|
|
+ msgResult.setData(dto);
|
|
|
|
+ } 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("mobile/save")
|
|
|
|
+ @ResponseBody
|
|
|
|
+ public MessageResult<String> save(EmployeeInfoDTO employeeInfoDTO){
|
|
|
|
+ MessageResult<String> msgResult = new MessageResult<>();
|
|
|
|
+
|
|
|
|
+ try {
|
|
|
|
+ int affectCount = 0;
|
|
|
|
+
|
|
|
|
+ EmployeeInfo employeeInfo = employeeInfoService.findByOpenId(employeeInfoDTO.getOpenId());
|
|
|
|
+
|
|
|
|
+ if(employeeInfo==null) {
|
|
|
|
+ employeeInfo = new EmployeeInfo();
|
|
|
|
+
|
|
|
|
+ PojoUtils.map(employeeInfoDTO,employeeInfo);
|
|
|
|
+
|
|
|
|
+ employeeInfo.setCreateTime(new Date());
|
|
|
|
+ affectCount = employeeInfoService.insert(employeeInfo);
|
|
|
|
+ }
|
|
|
|
+ else{
|
|
|
|
+ PojoUtils.map(employeeInfoDTO,employeeInfo);
|
|
|
|
+ employeeInfo.setUpdateTime(new Date());
|
|
|
|
+
|
|
|
|
+ affectCount = employeeInfoService.update(employeeInfo);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if (affectCount > 0) {
|
|
|
|
+ msgResult.setResult(true);
|
|
|
|
+ } else {
|
|
|
|
+ msgResult.setResult(false);
|
|
|
|
+ msgResult.setMessage("保存失败");
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ catch(Exception ex){
|
|
|
|
+ logger.error(ex.getMessage(),ex);
|
|
|
|
+
|
|
|
|
+ msgResult.setResult(false);
|
|
|
|
+ msgResult.setMessage(ex.getMessage());
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ return msgResult;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ @PostMapping("mobile/upload")
|
|
|
|
+ @ResponseBody
|
|
|
|
+ @ApiOperation(value="员工照片上传")
|
|
|
|
+ @ApiImplicitParams({
|
|
|
|
+ @ApiImplicitParam(name = "photoFile",value = "员工照片", required = true,paramType="form", dataType = "__file")
|
|
|
|
+ })
|
|
|
|
+ public MessageResult<String> upload(MultipartFile photoFile){
|
|
|
|
+ MessageResult<String> messageResult = new MessageResult<>();
|
|
|
|
+
|
|
|
|
+ try {
|
|
|
|
+ String fileName = photoFile.getOriginalFilename();
|
|
|
|
+ String retFileUrl = OSSUtil.upload(ossConfig,"/employee",fileName,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;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @ApiOperation(value="打包下载员工资料")
|
|
|
|
+ @RequestMapping(value = "downloadZip",method = RequestMethod.GET)
|
|
|
|
+ @ApiImplicitParams({
|
|
|
|
+ @ApiImplicitParam(name="ids",value = "选中用户编号",required = true,paramType = "query"),
|
|
|
|
+ @ApiImplicitParam(name="localPath",value = "压缩包解压后文件夹所在路径",required = true,paramType = "query"),
|
|
|
|
+ })
|
|
|
|
+ public void downloadZip(String ids,String localPath, HttpServletRequest request, HttpServletResponse response){
|
|
|
|
+ try {
|
|
|
|
+ String path = request.getContextPath();
|
|
|
|
+ String basePath = request.getScheme() + "://" + request.getServerName()+":"+request.getServerPort()+path+"/";
|
|
|
|
+
|
|
|
|
+ response.setCharacterEncoding("utf-8");
|
|
|
|
+ response.setContentType(MediaType.APPLICATION_OCTET_STREAM_VALUE);
|
|
|
|
+
|
|
|
|
+ //设置编码 为了解决中文名称乱码问题
|
|
|
|
+ String fileName = "员工资料";
|
|
|
|
+ String zipFileName = new String(fileName.getBytes("UTF-8"), "iso-8859-1");
|
|
|
|
+ response.setHeader("Content-Disposition", "attachment;fileName=" + zipFileName + ".zip");
|
|
|
|
+
|
|
|
|
+ //打包文件
|
|
|
|
+ List<Map<String,Object>> fileList = new ArrayList<>();
|
|
|
|
+
|
|
|
|
+ //读取模板
|
|
|
|
+ InputStream inputStream = this.getClass().getResourceAsStream("/static/模板.csv");
|
|
|
|
+ byte[] bytes = new byte[inputStream.available()];
|
|
|
|
+ inputStream.read(bytes);
|
|
|
|
+
|
|
|
|
+ StringBuilder csvBuilder = new StringBuilder();
|
|
|
|
+ csvBuilder.append(new String(bytes,"UTF-8"));
|
|
|
|
+
|
|
|
|
+ List<EmployeeInfo> employeeInfos = employeeInfoService.findByArray(ids.split(","));
|
|
|
|
+
|
|
|
|
+ if(employeeInfos.size()>0) {
|
|
|
|
+ for (EmployeeInfo employeeInfo : employeeInfos) {
|
|
|
|
+ csvBuilder.append(employeeInfo.getId() + ",");
|
|
|
|
+ csvBuilder.append(employeeInfo.getName() + ",");
|
|
|
|
+
|
|
|
|
+ String photoExt = employeeInfo.getPhoto().substring(employeeInfo.getPhoto().lastIndexOf("."));
|
|
|
|
+
|
|
|
|
+ csvBuilder.append(localPath + "\\照片\\" + employeeInfo.getId() + photoExt + "\r\n");
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ Map<String, Object> fileMap = new HashMap<>();
|
|
|
|
+ fileMap.put("fileData", csvBuilder.toString().getBytes("UTF-8"));
|
|
|
|
+ fileMap.put("fileName", "人员名单.csv");
|
|
|
|
+
|
|
|
|
+// fileList.add(fileMap);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ //身份证
|
|
|
|
+ for (EmployeeInfo employeeInfo : employeeInfos) {
|
|
|
|
+ if (StringUtils.isNotEmpty(employeeInfo.getPhoto())){
|
|
|
|
+ String url = employeeInfo.getPhoto();
|
|
|
|
+
|
|
|
|
+ String ext = url.substring(url.lastIndexOf("."));
|
|
|
|
+
|
|
|
|
+ Map<String,Object> fileMap = new HashMap<>();
|
|
|
|
+ fileMap.put("fileUrl",url + "?x-oss-process=image/resize,l_800,limit_1");
|
|
|
|
+ fileMap.put("filePath", "照片/");
|
|
|
|
+ fileMap.put("fileName", employeeInfo.getId() + ext);
|
|
|
|
+
|
|
|
|
+ fileList.add(fileMap);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ OutputStream output = response.getOutputStream();
|
|
|
|
+
|
|
|
|
+ OSSUtil.batchDownload(fileList,output);
|
|
|
|
+
|
|
|
|
+ output.flush();
|
|
|
|
+ output.close();
|
|
|
|
+ }
|
|
|
|
+ catch (Exception ex){
|
|
|
|
+ logger.error(ex.getMessage(),ex);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+}
|