|  |  |  | 
|---|
|  |  |  | package com.matrix.system.padApi.action; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | import cn.hutool.core.collection.CollUtil; | 
|---|
|  |  |  | import com.matrix.core.constance.MatrixConstance; | 
|---|
|  |  |  | import cn.hutool.core.util.ObjectUtil; | 
|---|
|  |  |  | import com.matrix.core.pojo.AjaxResult; | 
|---|
|  |  |  | import com.matrix.core.pojo.PaginationVO; | 
|---|
|  |  |  | import com.matrix.core.tools.DateUtil; | 
|---|
|  |  |  | import com.matrix.core.tools.RSAUtils; | 
|---|
|  |  |  | import com.matrix.core.tools.UUIDUtil; | 
|---|
|  |  |  | import com.matrix.core.tools.WebUtil; | 
|---|
|  |  |  | import com.matrix.core.tools.*; | 
|---|
|  |  |  | import com.matrix.system.app.vo.UserInfoVo; | 
|---|
|  |  |  | import com.matrix.system.common.authority.DefaultAuthorityManager; | 
|---|
|  |  |  | import com.matrix.system.common.authority.strategy.AccountPasswordLogin; | 
|---|
|  |  |  | import com.matrix.system.common.authority.strategy.LoginStrategy; | 
|---|
|  |  |  | import com.matrix.system.common.bean.SysUsers; | 
|---|
|  |  |  | import com.matrix.system.common.dao.SysCompanyDao; | 
|---|
|  |  |  | import com.matrix.system.common.dao.SysUsersDao; | 
|---|
|  |  |  | import com.matrix.system.common.init.LocalCache; | 
|---|
|  |  |  | import com.matrix.system.common.service.SysUsersService; | 
|---|
|  |  |  | import com.matrix.system.constance.Dictionary; | 
|---|
|  |  |  | import com.matrix.system.hive.action.BaseController; | 
|---|
|  |  |  | import com.matrix.system.hive.action.util.QueryUtil; | 
|---|
|  |  |  | import com.matrix.system.hive.bean.SysBeauticianState; | 
|---|
|  |  |  | import com.matrix.system.hive.bean.SysBedInfo; | 
|---|
|  |  |  | import com.matrix.system.hive.bean.SysProjServices; | 
|---|
|  |  |  | 
|---|
|  |  |  | import com.matrix.system.hive.service.SysOrderService; | 
|---|
|  |  |  | import com.matrix.system.hive.service.SysShopInfoService; | 
|---|
|  |  |  | import com.matrix.system.hive.service.SysWorktimeService; | 
|---|
|  |  |  | import com.matrix.system.padApi.dto.Base64UploadDto; | 
|---|
|  |  |  | import com.matrix.system.padApi.dto.PadOrderListDto; | 
|---|
|  |  |  | import com.matrix.system.padApi.dto.WebPadLoginDto; | 
|---|
|  |  |  | import com.matrix.system.padApi.vo.PadOrderDetailVo; | 
|---|
|  |  |  | 
|---|
|  |  |  | import io.swagger.annotations.ApiOperation; | 
|---|
|  |  |  | import io.swagger.annotations.ApiResponse; | 
|---|
|  |  |  | import io.swagger.annotations.ApiResponses; | 
|---|
|  |  |  | import org.apache.log4j.Logger; | 
|---|
|  |  |  | import org.springframework.beans.factory.annotation.Autowired; | 
|---|
|  |  |  | import org.springframework.beans.factory.annotation.Value; | 
|---|
|  |  |  | import org.springframework.util.FileCopyUtils; | 
|---|
|  |  |  | import org.springframework.validation.annotation.Validated; | 
|---|
|  |  |  | import org.springframework.web.bind.annotation.*; | 
|---|
|  |  |  | import sun.misc.BASE64Decoder; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | import javax.annotation.Resource; | 
|---|
|  |  |  | import java.io.File; | 
|---|
|  |  |  | import java.io.IOException; | 
|---|
|  |  |  | import java.text.SimpleDateFormat; | 
|---|
|  |  |  | import java.util.ArrayList; | 
|---|
|  |  |  | import java.util.Date; | 
|---|
|  |  |  | import java.util.List; | 
|---|
|  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Value("${login_public_key}") | 
|---|
|  |  |  | private String publicKey; | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | private SysUsersDao sysUsersDao; | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | Logger log = Logger.getLogger(PadApiCommonAction.class); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Value("${file_storage_path}") | 
|---|
|  |  |  | private String fileStoragePath; | 
|---|
|  |  |  | @Value("${static_resource_url}") | 
|---|
|  |  |  | private String nginxUrl; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 最大值 | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | private Long maxSize = 1024*1024*100L; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @ApiOperation(value = "登陆接口", notes = "pad端登陆接口") | 
|---|
|  |  |  | @ApiResponses({ | 
|---|
|  |  |  | 
|---|
|  |  |  | return result; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @ApiOperation(value = "首页", notes = "首页") | 
|---|
|  |  |  | @GetMapping(value = "/frist") | 
|---|
|  |  |  | public AjaxResult frist() { | 
|---|
|  |  |  | SysUsers user = WebUtil.getSessionAttribute(MatrixConstance.LOGIN_KEY); | 
|---|
|  |  |  | @GetMapping(value = "/frist/{suId}") | 
|---|
|  |  |  | public AjaxResult frist(@PathVariable Long suId) { | 
|---|
|  |  |  | SysUsers user = usersService.findById(suId); | 
|---|
|  |  |  | LogUtil.info("首页 shopId={}", user.getShopId()); | 
|---|
|  |  |  | //        SysUsers user = WebUtil.getSessionAttribute(MatrixConstance.LOGIN_KEY); | 
|---|
|  |  |  | PadOrderListDto orderListDto = new PadOrderListDto(); | 
|---|
|  |  |  | orderListDto.setPageNum(1); | 
|---|
|  |  |  | orderListDto.setPageSize(5); | 
|---|
|  |  |  | 
|---|
|  |  |  | PaginationVO pageVo = new PaginationVO(); | 
|---|
|  |  |  | pageVo.setOffset(offset); | 
|---|
|  |  |  | pageVo.setLimit(limit); | 
|---|
|  |  |  | //        if (!DataAuthUtil.hasAllShopAuth()) { | 
|---|
|  |  |  | if(ObjectUtil.isNotEmpty(user.getShopId())){ | 
|---|
|  |  |  | orderListDto.setShopId(user.getShopId()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | //        if (!DataAuthUtil.hasAllShopAuth()) { | 
|---|
|  |  |  | //            orderListDto.setShopId(user.getShopId()); | 
|---|
|  |  |  | //        } | 
|---|
|  |  |  | QueryUtil.setQueryLimitCom(orderListDto); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | if(ObjectUtil.isNotEmpty(user.getCompanyId())){ | 
|---|
|  |  |  | orderListDto.setCompanyId(user.getCompanyId()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | //        QueryUtil.setQueryLimitCom(orderListDto); | 
|---|
|  |  |  | List<PadOrderDetailVo> padApiOrderListInPage = sysOrderService.findPadApiOrderListInPage(orderListDto, pageVo); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | AjaxResult result = AjaxResult.buildSuccessInstance(""); | 
|---|
|  |  |  | result.putInMap("orderList",padApiOrderListInPage); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | Date date = new Date(); | 
|---|
|  |  |  | List<SysUsers> mls = usersService.findByRoleName(true, Dictionary.STAFF_POST_MLS); | 
|---|
|  |  |  | SysUsers shopstaffInfo = new SysUsers(); | 
|---|
|  |  |  | shopstaffInfo.setCompanyId(user.getCompanyId()); | 
|---|
|  |  |  | shopstaffInfo.setShopId(user.getShopId()); | 
|---|
|  |  |  | shopstaffInfo.setRoleName(Dictionary.STAFF_POST_MLS); | 
|---|
|  |  |  | List<SysUsers> mls = sysUsersDao.selectByRoleName(shopstaffInfo); | 
|---|
|  |  |  | LogUtil.info("美疗师 size={}", mls.size()); | 
|---|
|  |  |  | //        List<SysUsers> mls = usersService.findByRoleName(true, Dictionary.STAFF_POST_MLS); | 
|---|
|  |  |  | if(CollUtil.isNotEmpty(mls)){ | 
|---|
|  |  |  | SysBeauticianState sysBeauticianState = new SysBeauticianState(); | 
|---|
|  |  |  | sysBeauticianState.setBeginTime(DateUtil.getStartDate(date)); | 
|---|
|  |  |  | sysBeauticianState.setEndTime(DateUtil.getStartDate(date)); | 
|---|
|  |  |  | String panBanCodes = DateUtil.dateToString(sysBeauticianState.getBeginTime(),DateUtil.DATE_FORMAT_NO_SPLITE_DD); | 
|---|
|  |  |  | List<SysUsers> staffs=new ArrayList<>(); | 
|---|
|  |  |  | if(sysWorkTimeService.isInWorkTime(user.getShopId(),sysBeauticianState.getBeginTime(),sysBeauticianState.getEndTime())){ | 
|---|
|  |  |  | //            if(sysWorkTimeService.isInWorkTime(user.getShopId(),sysBeauticianState.getBeginTime(),sysBeauticianState.getEndTime())){ | 
|---|
|  |  |  | staffs= sysUsersService.findByCodeBeaStateShop(user.getShopId(), | 
|---|
|  |  |  | sysBeauticianState, panBanCodes); | 
|---|
|  |  |  | if(CollUtil.isNotEmpty(staffs)){ | 
|---|
|  |  |  | 
|---|
|  |  |  | result.putInMap("usedMls", mls.size()); | 
|---|
|  |  |  | result.putInMap("freeMls", 0); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | //            } | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | SysBedInfo bedInfo = new SysBedInfo(); | 
|---|
|  |  |  | bedInfo.setShopId(getMe().getShopId()); | 
|---|
|  |  |  | bedInfo.setShopId(user.getShopId()); | 
|---|
|  |  |  | List<SysBedInfo> totalBed = bedInfoService.findByModel(bedInfo); | 
|---|
|  |  |  | if(CollUtil.isNotEmpty(totalBed)){ | 
|---|
|  |  |  | SysProjServices sysProjServices = new SysProjServices(); | 
|---|
|  |  |  | sysProjServices.setShopId(getMe().getShopId()); | 
|---|
|  |  |  | sysProjServices.setShopId(user.getShopId()); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | sysProjServices.setStartTime(DateUtil.getStartDate(date)); | 
|---|
|  |  |  | sysProjServices.setEndTime(DateUtil.getStartDate(date)); | 
|---|
|  |  |  | 
|---|
|  |  |  | return AjaxResult.buildSuccessInstance("退出系统成功"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 文件上传方法 | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | @ApiOperation(value = "文件上传方法", notes = "文件上传方法") | 
|---|
|  |  |  | @PostMapping(value = "/doUpload") | 
|---|
|  |  |  | public AjaxResult doFileUpload(@RequestBody @Validated Base64UploadDto uploadDto){ | 
|---|
|  |  |  | // 文件保存目录路径 | 
|---|
|  |  |  | String savePath = fileStoragePath; | 
|---|
|  |  |  | // 文件保存目录URL | 
|---|
|  |  |  | String saveUrl = nginxUrl; | 
|---|
|  |  |  | // 保存和访问路径检查 | 
|---|
|  |  |  | if (StringUtils.isBlank(saveUrl) || StringUtils.isBlank(savePath)) { | 
|---|
|  |  |  | return AjaxResult.buildFailInstance("文件上传失败错误代码:001"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | // 检查目录 | 
|---|
|  |  |  | File uploadDir = new File(savePath); | 
|---|
|  |  |  | if (!uploadDir.isDirectory()) { | 
|---|
|  |  |  | uploadDir.mkdir(); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | log.info("uploadDto:" + uploadDto.getBase64Str()); | 
|---|
|  |  |  | BASE64Decoder decoder = new BASE64Decoder(); | 
|---|
|  |  |  | byte[] bytes = new byte[0]; | 
|---|
|  |  |  | try { | 
|---|
|  |  |  | bytes = decoder.decodeBuffer(uploadDto.getBase64Str()); | 
|---|
|  |  |  | } catch (IOException e) { | 
|---|
|  |  |  | return AjaxResult.buildFailInstance("上传文件失败"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd"); | 
|---|
|  |  |  | String ymd = sdf.format(new Date()); | 
|---|
|  |  |  | savePath += ymd + "/"; | 
|---|
|  |  |  | saveUrl += ymd + "/"; | 
|---|
|  |  |  | File dirFile = new File(savePath); | 
|---|
|  |  |  | if (!dirFile.exists()) { | 
|---|
|  |  |  | dirFile.mkdirs(); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if (bytes.length > maxSize) { | 
|---|
|  |  |  | return AjaxResult.buildFailInstance("上传文件大小超过限制"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | String newFileName = UUIDUtil.getRandomID() + UUIDUtil.getRandomID() + ".png"; | 
|---|
|  |  |  | File uploadedFile = new File(savePath, newFileName); | 
|---|
|  |  |  | try { | 
|---|
|  |  |  | FileCopyUtils.copy(bytes, uploadedFile); | 
|---|
|  |  |  | } catch (Exception e) { | 
|---|
|  |  |  | return AjaxResult.buildFailInstance("上传文件失败"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | log.info("saveUrl:" + saveUrl); | 
|---|
|  |  |  | String visitPath = saveUrl + newFileName; | 
|---|
|  |  |  | log.info("上传一个文件:" + newFileName); | 
|---|
|  |  |  | log.info("访问路径:" + visitPath); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | AjaxResult result = AjaxResult.buildSuccessInstance("上传成功"); | 
|---|
|  |  |  | result.putInMap("path", visitPath); | 
|---|
|  |  |  | result.putInMap("fileName", newFileName); | 
|---|
|  |  |  | return result; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | } | 
|---|