|
@@ -0,0 +1,297 @@
|
|
|
|
+package com.jpsoft.smart.modules.business.controller;
|
|
|
|
+
|
|
|
|
+import com.github.pagehelper.Page;
|
|
|
|
+import com.jpsoft.smart.modules.base.entity.CompanyInfo;
|
|
|
|
+import com.jpsoft.smart.modules.base.service.CompanyInfoService;
|
|
|
|
+import com.jpsoft.smart.modules.business.entity.FillAttendance;
|
|
|
|
+import com.jpsoft.smart.modules.business.service.FillAttendanceService;
|
|
|
|
+import com.jpsoft.smart.modules.common.dto.MessageResult;
|
|
|
|
+import com.jpsoft.smart.modules.common.dto.Sort;
|
|
|
|
+import com.jpsoft.smart.modules.common.utils.PojoUtils;
|
|
|
|
+import com.jpsoft.smart.modules.sys.entity.User;
|
|
|
|
+import com.jpsoft.smart.modules.sys.service.DataDictionaryService;
|
|
|
|
+import com.jpsoft.smart.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.slf4j.Logger;
|
|
|
|
+import org.slf4j.LoggerFactory;
|
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
+import org.springframework.web.bind.annotation.*;
|
|
|
|
+
|
|
|
|
+import javax.servlet.http.HttpServletRequest;
|
|
|
|
+import java.text.SimpleDateFormat;
|
|
|
|
+import java.util.*;
|
|
|
|
+
|
|
|
|
+@RestController
|
|
|
|
+@RequestMapping("/business/fillAttendance")
|
|
|
|
+@Api(description = "fillAttendance")
|
|
|
|
+public class FillAttendanceController {
|
|
|
|
+ private Logger logger = LoggerFactory.getLogger(getClass());
|
|
|
|
+
|
|
|
|
+ @Autowired
|
|
|
|
+ private FillAttendanceService fillAttendanceService;
|
|
|
|
+
|
|
|
|
+ @Autowired
|
|
|
|
+ private UserService userService;
|
|
|
|
+
|
|
|
|
+ @Autowired
|
|
|
|
+ private CompanyInfoService companyInfoService;
|
|
|
|
+
|
|
|
|
+ @Autowired
|
|
|
|
+ private DataDictionaryService dataDictionaryService;
|
|
|
|
+
|
|
|
|
+ @ApiOperation(value="创建空记录")
|
|
|
|
+ @GetMapping("create")
|
|
|
|
+ public MessageResult<FillAttendance> create(){
|
|
|
|
+ MessageResult<FillAttendance> msgResult = new MessageResult<>();
|
|
|
|
+
|
|
|
|
+ FillAttendance fillAttendance = new FillAttendance();
|
|
|
|
+
|
|
|
|
+ msgResult.setData(fillAttendance);
|
|
|
|
+ msgResult.setResult(true);
|
|
|
|
+
|
|
|
|
+ return msgResult;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @ApiOperation(value="添加信息")
|
|
|
|
+ @PostMapping("add")
|
|
|
|
+ public MessageResult<FillAttendance> add(@RequestBody FillAttendance fillAttendance,@RequestAttribute String subject){
|
|
|
|
+ MessageResult<FillAttendance> msgResult = new MessageResult<>();
|
|
|
|
+
|
|
|
|
+ try {
|
|
|
|
+ fillAttendance.setId(UUID.randomUUID().toString());
|
|
|
|
+ fillAttendance.setDelFlag(false);
|
|
|
|
+ fillAttendance.setCreateBy(subject);
|
|
|
|
+ fillAttendance.setCreateTime(new Date());
|
|
|
|
+
|
|
|
|
+ int affectCount = fillAttendanceService.insert(fillAttendance);
|
|
|
|
+
|
|
|
|
+ if (affectCount > 0) {
|
|
|
|
+ msgResult.setResult(true);
|
|
|
|
+ msgResult.setData(fillAttendance);
|
|
|
|
+ } 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<FillAttendance> edit(@PathVariable("id") String id){
|
|
|
|
+ MessageResult<FillAttendance> msgResult = new MessageResult<>();
|
|
|
|
+
|
|
|
|
+ try {
|
|
|
|
+ FillAttendance fillAttendance = fillAttendanceService.get(id);
|
|
|
|
+
|
|
|
|
+ if (fillAttendance != null) {
|
|
|
|
+ msgResult.setResult(true);
|
|
|
|
+ msgResult.setData(fillAttendance);
|
|
|
|
+ } 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<FillAttendance> update(@RequestBody FillAttendance fillAttendance,@RequestAttribute String subject){
|
|
|
|
+ MessageResult<FillAttendance> msgResult = new MessageResult<>();
|
|
|
|
+
|
|
|
|
+ try {
|
|
|
|
+ fillAttendance.setUpdateBy(subject);
|
|
|
|
+ fillAttendance.setUpdateTime(new Date());
|
|
|
|
+
|
|
|
|
+ int affectCount = fillAttendanceService.update(fillAttendance);
|
|
|
|
+
|
|
|
|
+ if (affectCount > 0) {
|
|
|
|
+ msgResult.setResult(true);
|
|
|
|
+ msgResult.setData(fillAttendance);
|
|
|
|
+ } 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 {
|
|
|
|
+ FillAttendance fillAttendance = fillAttendanceService.get(id);
|
|
|
|
+ fillAttendance.setDelFlag(true);
|
|
|
|
+ fillAttendance.setUpdateBy(subject);
|
|
|
|
+ fillAttendance.setUpdateTime(new Date());
|
|
|
|
+
|
|
|
|
+ int affectCount = fillAttendanceService.update(fillAttendance);
|
|
|
|
+
|
|
|
|
+ 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) {
|
|
|
|
+ FillAttendance fillAttendance = fillAttendanceService.get(id);
|
|
|
|
+ fillAttendance.setDelFlag(true);
|
|
|
|
+ fillAttendance.setUpdateBy(subject);
|
|
|
|
+ fillAttendance.setUpdateTime(new Date());
|
|
|
|
+
|
|
|
|
+ affectCount += fillAttendanceService.update(fillAttendance);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ 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="列表")
|
|
|
|
+ @ApiImplicitParams({
|
|
|
|
+ @ApiImplicitParam(name = "personName", value = "申请人姓名", required = false, paramType = "form", dataType = "String"),
|
|
|
|
+ @ApiImplicitParam(name = "type", value = "类型", required = false, paramType = "form", dataType = "String"),
|
|
|
|
+ @ApiImplicitParam(name = "status", value = "状态", required = false, paramType = "form", dataType = "String"),
|
|
|
|
+ @ApiImplicitParam(name = "parentId",value = "上级企业ID", required = false, paramType = "form",dataType = "String"),
|
|
|
|
+ @ApiImplicitParam(name = "subordinate",value = "是否查询下级单位", required = false, paramType = "form",dataType = "String"),
|
|
|
|
+ })
|
|
|
|
+ @RequestMapping(value = "pageList",method = RequestMethod.POST)
|
|
|
|
+ public MessageResult<Map> pageList(
|
|
|
|
+ String id,
|
|
|
|
+ @RequestParam(value="personName",defaultValue="") String personName,
|
|
|
|
+ @RequestParam(value="type",defaultValue="") String type,
|
|
|
|
+ @RequestParam(value="status",defaultValue="") String status,
|
|
|
|
+ @RequestParam(value="parentId",defaultValue="") String parentId,
|
|
|
|
+ @RequestParam(value="subordinate",defaultValue="false") Boolean subordinate,
|
|
|
|
+ @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("id_","asc"));
|
|
|
|
+
|
|
|
|
+ //为公司管理员
|
|
|
|
+ boolean is_admin = userService.hasRole(subject,"ADMIN");
|
|
|
|
+ if(is_admin){
|
|
|
|
+ User user = userService.get(subject);
|
|
|
|
+ String companyId = user.getCompanyId();
|
|
|
|
+ searchParams.put("bindCompanyId", companyId);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if (StringUtils.isNotEmpty(id)) {
|
|
|
|
+ searchParams.put("id","%" + id + "%");
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if (StringUtils.isNotEmpty(personName)) {
|
|
|
|
+ searchParams.put("personName","%" + personName + "%");
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if (StringUtils.isNotEmpty(type)) {
|
|
|
|
+ searchParams.put("type",type);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if (StringUtils.isNotEmpty(status)) {
|
|
|
|
+ searchParams.put("status","%" + status + "%");
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if(StringUtils.isNotEmpty(parentId)){
|
|
|
|
+ CompanyInfo parentCompanyInfo = companyInfoService.get(parentId);
|
|
|
|
+
|
|
|
|
+ String parentCode = parentCompanyInfo.getCode();
|
|
|
|
+
|
|
|
|
+ if (StringUtils.isEmpty(parentCode)){
|
|
|
|
+ if (!userService.hasRole(subject,"SYSADMIN")) {
|
|
|
|
+ searchParams.put("companyCode", parentCode + "%");
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ else{
|
|
|
|
+ if(subordinate){
|
|
|
|
+ searchParams.put("companyCode", parentCode + "%");
|
|
|
|
+ }
|
|
|
|
+ else {
|
|
|
|
+ searchParams.put("companyCode", parentCode);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ Page<FillAttendance> page = fillAttendanceService.pageSearch(searchParams,pageIndex,pageSize,sortList);
|
|
|
|
+ for(FillAttendance fillAttendance : page.getResult()){
|
|
|
|
+ String typeN = dataDictionaryService.findNameByCatalogNameAndValue("补卡类型",fillAttendance.getType());
|
|
|
|
+ fillAttendance.setTypeN(typeN);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ msgResult.setResult(true);
|
|
|
|
+ msgResult.setData(PojoUtils.pageWrapper(page));
|
|
|
|
+
|
|
|
|
+ return msgResult;
|
|
|
|
+ }
|
|
|
|
+}
|