package cn.huge.module.pauser.controller.web; import cn.huge.base.common.utils.ReturnFailUtils; import cn.huge.base.common.utils.ReturnSucUtils; import cn.huge.module.pauser.domain.po.PaAccount; import cn.huge.module.pauser.service.PaAccountService; import com.google.common.collect.Maps; import lombok.extern.slf4j.Slf4j; import org.apache.commons.lang3.StringUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.data.domain.Page; import org.springframework.data.domain.PageRequest; import org.springframework.data.domain.Sort; import org.springframework.web.bind.annotation.*; import javax.servlet.http.HttpServletRequest; import java.util.Map; import java.util.stream.Collectors; import java.util.stream.Stream; /** * @title: 公众用户账号表接口api-web端 * @description: 公众用户账号表接口api-web端 * @company: hugeinfo * @author: liyj * @time: 2024-08-19 20:04:19 * @version: 1.0.0 */ @Slf4j @RestController @RequestMapping("/api/web/paAccount") public class PaAccountWebController { @Autowired(required = false) private HttpServletRequest request; @Autowired private PaAccountService service; /** * 获取请求URL参数 * @return Map */ private Map getParameter(){ Map terms = Maps.newHashMap(); // 账号编号 String id = request.getParameter("id"); if (StringUtils.isNotBlank(id)){ terms.put("id", id); } // 当事人编号 String userId = request.getParameter("userId"); if (StringUtils.isNotBlank(userId)){ terms.put("userId", userId); } // 帐号类型,1:平台web端,2:平台小程序 String accType = request.getParameter("accType"); if (StringUtils.isNotBlank(accType)){ terms.put("accType", accType); } // 身份唯一标识(存储唯一标识,比如账号、邮箱、手机号、第三方获取的唯一标识等) String acc = request.getParameter("acc"); if (StringUtils.isNotBlank(acc)){ terms.put("acc", acc); } // 授权凭证(比如密码 、第三方登录的token、授权账号等) String cipher = request.getParameter("cipher"); if (StringUtils.isNotBlank(cipher)){ terms.put("cipher", cipher); } // 授权凭证明文 String cipherOpen = request.getParameter("cipherOpen"); if (StringUtils.isNotBlank(cipherOpen)){ terms.put("cipherOpen", cipherOpen); } // 密码最新更新时间 String cipherTime = request.getParameter("cipherTime"); if (StringUtils.isNotBlank(cipherTime)){ terms.put("cipherTime", cipherTime); } // 最新登录时间 String loginTime = request.getParameter("loginTime"); if (StringUtils.isNotBlank(loginTime)){ terms.put("loginTime", loginTime); } // 限制登录时间(密码错误次数超过限制,默认30分钟) String limitTime = request.getParameter("limitTime"); if (StringUtils.isNotBlank(limitTime)){ terms.put("limitTime", limitTime); } // 删除状态,0:未删除,1:已删除 String deleteStatus = request.getParameter("deleteStatus"); if (StringUtils.isNotBlank(deleteStatus)){ terms.put("deleteStatus", deleteStatus); } // 客户编号 String custId = request.getParameter("custId"); if (StringUtils.isNotBlank(custId)){ terms.put("custId", custId); } // 创建时间区间 String createStart = request.getParameter("createStart"); String createEnd = request.getParameter("createEnd"); if(StringUtils.isNotBlank(createStart) && StringUtils.isNotBlank(createEnd)) { terms.put("createStart", createStart); terms.put("createEnd", createEnd); } // 更新时间区间 String updateStart = request.getParameter("updateStart"); String updateEnd = request.getParameter("updateEnd"); if(StringUtils.isNotBlank(updateStart) && StringUtils.isNotBlank(updateEnd)) { terms.put("updateStart", updateStart); terms.put("updateEnd", updateEnd); } return terms; } /** * 条件查询多个 * @url {ctx}/api/web/paAccount/listQuery * @return Object */ @GetMapping("/listQuery") public Object listQuery() { try { Map terms = getParameter(); return ReturnSucUtils.getRepInfo(service.listTerms(terms)); } catch (Exception e) { return ReturnFailUtils.getRepInfo(); } } /** * 条件分页查询 * @url {ctx}/api/web/paAccount/pageQuery * @param page 页码 * @param size 每页数量 * @return Object */ @GetMapping("/pageQuery") public Object pageQuery(@RequestParam(value = "page") int page, @RequestParam(value = "size") int size) { try { Map terms = getParameter(); Sort sort = Sort.by(Sort.Direction.DESC, "create_time"); PageRequest pageRequest = PageRequest.of(page-1, size, sort); Page paAccountPage = service.pageQuery(pageRequest, terms); return ReturnSucUtils.getRepInfo( "处理成功", paAccountPage); } catch (Exception e) { return ReturnFailUtils.getRepInfo(); } } /** * 根据编号查询单个 * @url {ctx}/api/web/paAccount/getById * @param id 主键编号 * @return Object */ @GetMapping("/getById") public Object getById(@RequestParam(value = "id") String id) { try { return ReturnSucUtils.getRepInfo(service.getById(id)); } catch (Exception e) { return ReturnFailUtils.getRepInfo(); } } /** * 根据主键单个 * @url {ctx}/api/web/paAccount/deleteById * @param id 主键编号 * @return Object */ @GetMapping("/deleteById") public Object deleteById(@RequestParam(value = "id") String id) { try { service.removeById(id); return ReturnSucUtils.getRepInfo(); } catch (Exception e) { return ReturnFailUtils.getRepInfo(); } } /** * 新增或更新对象 * @url {ctx}/api/web/paAccount/savePaAccount * @param paAccount 实体对象 * @return Object */ @PostMapping("/savePaAccount") public Object savePaAccount(@RequestBody PaAccount paAccount) { try { service.savePaAccount(paAccount); return ReturnSucUtils.getRepInfo(); } catch (Exception e) { return ReturnFailUtils.getRepInfo(); } } }