| | |
| | | package com.sandu.ximon.admin.controller; |
| | | |
| | | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| | | import com.baomidou.mybatisplus.core.toolkit.Wrappers; |
| | | import com.github.pagehelper.PageHelper; |
| | | import com.sandu.common.domain.ResponseVO; |
| | | import com.sandu.common.object.BaseConditionVO; |
| | | import com.sandu.common.util.ResponseUtil; |
| | | import com.sandu.ximon.admin.context.CustomerInspectContextHolder; |
| | | import com.sandu.ximon.admin.param.ClientPrarm; |
| | | import com.sandu.ximon.admin.security.SecurityUtils; |
| | | import com.sandu.ximon.admin.service.ClientService; |
| | | import com.sandu.ximon.dao.domain.Client; |
| | | import com.sandu.ximon.dao.enums.AdministratorEnums; |
| | | import lombok.AllArgsConstructor; |
| | | import org.springframework.web.bind.annotation.*; |
| | | |
| | | /** |
| | | *客户模块 |
| | | */ |
| | | @RestController |
| | | @AllArgsConstructor |
| | | @RequestMapping("v1/client") |
| | |
| | | |
| | | private final ClientService clientService; |
| | | |
| | | @GetMapping("/add") |
| | | @PostMapping("/add") |
| | | public ResponseVO<Object> addClient(@RequestBody ClientPrarm clientPrarm){ |
| | | boolean b = clientService.addClient(clientPrarm); |
| | | if(b){ |
| | |
| | | } |
| | | |
| | | |
| | | @GetMapping ("/update/{id}") |
| | | @PostMapping ("/update/{id}") |
| | | public ResponseVO<Object> updateClient(@PathVariable Long id,@RequestBody ClientPrarm clientPrarm){ |
| | | boolean b = clientService.updateClient(id,clientPrarm); |
| | | if(b){ |
| | |
| | | } |
| | | } |
| | | |
| | | @GetMapping("/delete/{id}") |
| | | @PostMapping("/delete/{id}") |
| | | public ResponseVO<Object> deleteClient(@PathVariable Long id){ |
| | | boolean b = clientService.deleteClient(id); |
| | | if(b){ |
| | |
| | | } |
| | | |
| | | |
| | | @PostMapping("/list") |
| | | public ResponseVO<Object> listClient(){ |
| | | // Integer administratorIdentity = SecurityUtils.getAdministratorIdentity();//0 为管理员 |
| | | /* if(administratorIdentity==0){//判断 如果是管理员 就判断下CustomerInspectContextHolder.getCustomerId() 有没有值 |
| | | // Long customerId = CustomerInspectContextHolder.getCustomerId(); |
| | | if(customerId!=null){ |
| | | return ResponseUtil.success(clientService.list()); |
| | | } |
| | | return ResponseUtil.success(clientService.list()); |
| | | }else { |
| | | |
| | | }*/ |
| | | if(SecurityUtils.getClientId().equals(SecurityUtils.getAdministratorIdentity())) { |
| | | return ResponseUtil.success(clientService.clientList(SecurityUtils.getUserId())); |
| | | /* @GetMapping("/list") |
| | | public ResponseVO<Object> listClient(BaseConditionVO baseConditionVO) { |
| | | PageHelper.startPage(baseConditionVO.getPageNo(), baseConditionVO.getPageSize()); |
| | | if(AdministratorEnums.CUSTOMER.getCode().equals(SecurityUtils.getAdministratorIdentity())) { |
| | | return ResponseUtil.success(clientService.clientList(SecurityUtils.getUserId(),baseConditionVO)); |
| | | // }else if("0".equals(SecurityUtils.getAdministratorIdentity())){ |
| | | }else { |
| | | return ResponseUtil.success(clientService.list()); |
| | | return ResponseUtil.successPage(clientService.list()); |
| | | } |
| | | }*/ |
| | | |
| | | @GetMapping("/list") |
| | | public ResponseVO<Object> listLikeClient(BaseConditionVO baseConditionVO, @RequestParam(value = "keyword", required = false) String keyword) { |
| | | PageHelper.startPage(baseConditionVO.getPageNo(), baseConditionVO.getPageSize()); |
| | | LambdaQueryWrapper<Client> wrapper = Wrappers.lambdaQuery(Client.class); |
| | | if(AdministratorEnums.CUSTOMER.getCode().equals(SecurityUtils.getAdministratorIdentity())){ |
| | | wrapper.eq(Client::getSuperiorId,SecurityUtils.getUserId()); |
| | | } |
| | | if(null!=keyword){ |
| | | wrapper.like(Client::getClientName,keyword) |
| | | .or(clientLambdaQueryWrapper -> clientLambdaQueryWrapper.like(Client::getMobile,keyword)) |
| | | .or(clientLambdaQueryWrapper -> clientLambdaQueryWrapper.like(Client::getLinkMan,keyword)); |
| | | } |
| | | return ResponseUtil.successPage(clientService.list(wrapper)); |
| | | } |
| | | } |