2024-01-23 16:42:27 +08:00
|
|
|
package com.ics.admin.controller;
|
|
|
|
|
2024-04-03 14:28:17 +08:00
|
|
|
import cn.hutool.core.collection.CollUtil;
|
2024-03-29 08:55:47 +08:00
|
|
|
import cn.hutool.core.lang.Assert;
|
2024-04-03 14:28:17 +08:00
|
|
|
import cn.hutool.core.util.StrUtil;
|
2024-01-23 16:42:27 +08:00
|
|
|
import com.alibaba.fastjson.JSON;
|
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
|
import com.google.common.collect.Maps;
|
2024-04-08 11:15:03 +08:00
|
|
|
import com.ics.admin.domain.Building;
|
2024-01-23 16:42:27 +08:00
|
|
|
import com.ics.admin.domain.Customer;
|
2024-03-29 08:55:47 +08:00
|
|
|
import com.ics.admin.domain.Park;
|
|
|
|
import com.ics.admin.domain.Room;
|
2024-04-08 11:15:03 +08:00
|
|
|
import com.ics.admin.service.*;
|
2024-03-02 17:13:10 +08:00
|
|
|
import com.ics.common.constant.Constants;
|
2024-01-23 16:42:27 +08:00
|
|
|
import com.ics.common.core.controller.BaseController;
|
2024-03-13 15:15:35 +08:00
|
|
|
import com.ics.common.core.domain.IcsCustomerStaff;
|
2024-01-23 16:42:27 +08:00
|
|
|
import com.ics.common.core.domain.R;
|
2024-04-03 14:28:17 +08:00
|
|
|
import com.ics.common.core.text.Convert;
|
2024-01-23 16:42:27 +08:00
|
|
|
import com.ics.common.utils.ValidatorUtils;
|
|
|
|
import com.ics.common.utils.http.HttpUtils;
|
2024-04-08 11:15:03 +08:00
|
|
|
import com.ics.system.domain.Tenant;
|
2024-01-23 16:42:27 +08:00
|
|
|
import com.ics.system.domain.User;
|
2024-04-08 11:15:03 +08:00
|
|
|
import com.ics.system.service.ITenantService;
|
2024-01-23 16:42:27 +08:00
|
|
|
import org.apache.commons.compress.utils.Lists;
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
import org.wf.jwtp.annotation.RequiresPermissions;
|
|
|
|
|
2024-04-03 14:28:17 +08:00
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.Collections;
|
2024-01-23 16:42:27 +08:00
|
|
|
import java.util.List;
|
|
|
|
import java.util.Map;
|
2024-04-03 14:28:17 +08:00
|
|
|
import java.util.stream.Collectors;
|
2024-01-23 16:42:27 +08:00
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 客户管理 提供者
|
|
|
|
*
|
|
|
|
* @author zzm
|
|
|
|
* @date 2020-10-16
|
|
|
|
*/
|
|
|
|
@RestController
|
|
|
|
@RequestMapping("admin/customer")
|
|
|
|
public class CustomerController extends BaseController {
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
private ICustomerService customerService;
|
2024-03-02 17:13:10 +08:00
|
|
|
@Autowired
|
|
|
|
private IIcsCustomerStaffService icsCustomerStaffService;
|
2024-01-23 16:42:27 +08:00
|
|
|
|
2024-03-29 08:55:47 +08:00
|
|
|
@Autowired
|
|
|
|
private IParkService parkService;
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
private IRoomService roomService;
|
|
|
|
|
2024-04-08 11:15:03 +08:00
|
|
|
@Autowired
|
|
|
|
private ITenantService tenantService;
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
private IBuildingService buildingService;
|
2024-01-23 16:42:27 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* app的key值
|
|
|
|
*/
|
|
|
|
@Value("${qixin.appKey}")
|
|
|
|
private String appKey;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* app的密钥值
|
|
|
|
*/
|
|
|
|
@Value("${qixin.secretKey}")
|
|
|
|
private String secretKey;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* url
|
|
|
|
*/
|
|
|
|
@Value("${qixin.url}")
|
|
|
|
private String url;
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 调用启信api获取企业照面
|
|
|
|
*/
|
|
|
|
@RequiresPermissions("admin:customer:view")
|
|
|
|
@PostMapping("getBasicInfo")
|
|
|
|
public R getQiXinBasicInfo(String keyword) {
|
|
|
|
String qiXinBasicInfo = HttpUtils.sendGet(url, "appkey=" + appKey + "&secret_key=" + secretKey + "&keyword=" + keyword);
|
|
|
|
JSONObject result = (JSONObject) JSON.parse(qiXinBasicInfo);
|
|
|
|
// 启信宝的接口返回成功码-200
|
|
|
|
String SUCCESS_CODE = "200";
|
|
|
|
if (result != null) {
|
|
|
|
String status = result.get("status").toString();
|
|
|
|
if (SUCCESS_CODE.equals(status)) {
|
|
|
|
return R.data(result.get("data").toString());
|
|
|
|
} else {
|
|
|
|
return R.error(result.get("message").toString());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return R.error("无当前企业数据!");
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 查询${tableComment}
|
|
|
|
*/
|
|
|
|
@RequiresPermissions("admin:customer:view")
|
|
|
|
@GetMapping("get/{id}")
|
|
|
|
public Customer get(@PathVariable("id") Long id) {
|
2024-03-29 08:55:47 +08:00
|
|
|
|
|
|
|
Customer customer = customerService.selectCustomerById(id);
|
2024-04-03 14:28:17 +08:00
|
|
|
|
|
|
|
String roomId = customer.getRoomId();
|
|
|
|
List<String> roomIds = StrUtil.split(roomId, ',');
|
|
|
|
|
|
|
|
List<Long> collect = roomIds.stream().map(item -> Long.valueOf(item)).collect(Collectors.toList());
|
|
|
|
customer.setRoomIds(collect);
|
|
|
|
String buildId = customer.getBuildId();
|
|
|
|
List<String> buildIds = StrUtil.split(buildId, ',');
|
|
|
|
List<Long> collect1 = buildIds.stream().map(Long::valueOf).collect(Collectors.toList());
|
|
|
|
customer.setBuildingDetailIds(collect1);
|
2024-03-29 08:55:47 +08:00
|
|
|
return customer;
|
2024-01-23 16:42:27 +08:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 查询客户管理列表
|
|
|
|
*/
|
|
|
|
@RequiresPermissions("admin:customer:list")
|
|
|
|
@GetMapping("list")
|
|
|
|
public R list(Customer customer) {
|
|
|
|
startPage();
|
|
|
|
customer.setDeleteFlag(0);
|
2024-04-08 11:15:03 +08:00
|
|
|
List<Customer> customers = customerService.selectCustomerList(customer);
|
|
|
|
for (Customer customer1 : customers) {
|
|
|
|
Long tenantId = customer1.getTenantId();
|
|
|
|
Tenant tenant = tenantService.selectTenantById(tenantId);
|
|
|
|
customer1.setTenantName(tenant.getName());
|
|
|
|
Building building = buildingService.selectBuildingById(customer1.getBuildingId());
|
2024-04-12 11:13:01 +08:00
|
|
|
if (null != building){
|
|
|
|
customer1.setBuildingName(building.getBuildingName());
|
|
|
|
}
|
2024-04-08 11:15:03 +08:00
|
|
|
|
|
|
|
}
|
|
|
|
return result(customers);
|
2024-01-23 16:42:27 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 合同查询客户管理列表
|
|
|
|
*/
|
|
|
|
@RequiresPermissions("admin:customer:list")
|
|
|
|
@GetMapping("allList")
|
|
|
|
public R allList(Customer customer) {
|
|
|
|
List<Customer> customerList = customerService.selectCustomerList(customer);
|
2024-03-29 08:55:47 +08:00
|
|
|
|
2024-01-23 16:42:27 +08:00
|
|
|
List<Map> customerMaps = Lists.newArrayList();
|
|
|
|
for (Customer item : customerList) {
|
2024-03-29 08:55:47 +08:00
|
|
|
|
2024-01-23 16:42:27 +08:00
|
|
|
Map<String, Object> customerMap = Maps.newHashMap();
|
|
|
|
getCustomerMap(customerMap, item);
|
|
|
|
customerMaps.add(customerMap);
|
|
|
|
}
|
|
|
|
return R.data(customerMaps);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 合同根据客户id查询客户部分信息
|
|
|
|
*/
|
|
|
|
@RequiresPermissions("admin:customer:view")
|
|
|
|
@GetMapping("findByCustomerId")
|
|
|
|
public R findByCustomerId(Long customerId) {
|
|
|
|
Map<String, Object> customerMap = Maps.newHashMap();
|
|
|
|
Customer customer = customerService.selectCustomerById(customerId);
|
|
|
|
getCustomerMap(customerMap, customer);
|
|
|
|
return R.data(customerMap);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 合同获取客户的部分信息
|
|
|
|
*/
|
|
|
|
private void getCustomerMap(Map<String, Object> customerMap, Customer customer) {
|
|
|
|
customerMap.put("id", customer.getId());
|
|
|
|
customerMap.put("name", customer.getName());
|
|
|
|
customerMap.put("sector", customer.getSector());
|
|
|
|
customerMap.put("creditNo", customer.getCreditNo());
|
|
|
|
customerMap.put("mail", customer.getMailAddress());
|
|
|
|
customerMap.put("operName", customer.getOperName());
|
|
|
|
customerMap.put("phone", customer.getPhone());
|
|
|
|
customerMap.put("address", customer.getAddress());
|
|
|
|
customerMap.put("channelName", customer.getChannelName());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 新增保存客户管理
|
|
|
|
*/
|
|
|
|
@RequiresPermissions("admin:customer:add")
|
|
|
|
@PostMapping("save")
|
|
|
|
public R addSave(@RequestBody Customer customer) {
|
2024-03-26 09:53:05 +08:00
|
|
|
// if (User.isAdmin(getCurrentUserId())) {
|
|
|
|
// return R.error("不允许超级管理员用户新增");
|
|
|
|
// }
|
2024-03-29 08:55:47 +08:00
|
|
|
|
|
|
|
|
2024-04-03 14:28:17 +08:00
|
|
|
//房间转成逗号隔开
|
|
|
|
List<Long> buildingDetailIds = customer.getBuildingDetailIds();
|
|
|
|
|
|
|
|
String buildIds = CollUtil.join(buildingDetailIds, ",");
|
|
|
|
|
|
|
|
customer.setBuildId(buildIds);
|
|
|
|
List<Long> roomIds = customer.getRoomIds();
|
|
|
|
|
|
|
|
String roomids = CollUtil.join(roomIds, ",");
|
|
|
|
customer.setRoomId(roomids);
|
|
|
|
|
|
|
|
customer.setParkId(customer.getParkId());
|
|
|
|
customer.setTenantId(customer.getTenantId());
|
2024-01-23 16:42:27 +08:00
|
|
|
ValidatorUtils.validateEntity(customer);
|
|
|
|
customer.setCreateBy(getLoginName());
|
2024-03-29 08:55:47 +08:00
|
|
|
int i = customerService.insertCustomer(customer);
|
|
|
|
//如果新增成功,把房间的状态改为已启用
|
2024-04-03 14:28:17 +08:00
|
|
|
for (Long roomId : roomIds) {
|
|
|
|
Room room = roomService.selectRoomById(roomId);
|
|
|
|
room.setStatus(Room.Status.YES);
|
|
|
|
int i1 = roomService.updateRoom(room);
|
|
|
|
Assert.isTrue(i1 > 0, "修改房间已租状态失败");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2024-03-29 08:55:47 +08:00
|
|
|
return toAjax(i);
|
2024-01-23 16:42:27 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 修改保存客户管理
|
|
|
|
*/
|
|
|
|
@RequiresPermissions("admin:customer:edit")
|
|
|
|
@PostMapping("update")
|
|
|
|
public R editSave(@RequestBody Customer customer) {
|
2024-03-26 09:53:05 +08:00
|
|
|
// if (User.isAdmin(getCurrentUserId())) {
|
|
|
|
// return R.error("不允许超级管理员用户修改");
|
|
|
|
// }
|
2024-01-23 16:42:27 +08:00
|
|
|
ValidatorUtils.validateEntity(customer);
|
|
|
|
customer.setUpdateBy(getLoginName());
|
|
|
|
return toAjax(customerService.updateCustomer(customer));
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 删除${tableComment}
|
|
|
|
*/
|
|
|
|
@RequiresPermissions("admin:customer:remove")
|
|
|
|
@PostMapping("remove")
|
|
|
|
public R remove(String ids) {
|
|
|
|
return toAjax(customerService.deleteCustomerByIds(ids));
|
|
|
|
}
|
|
|
|
|
2024-03-02 17:13:10 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* 查询访客列表
|
|
|
|
* @param icsCustomerStaff
|
|
|
|
* @return
|
|
|
|
*/
|
|
|
|
@RequiresPermissions("admin:customer:visit")
|
|
|
|
@GetMapping("visitList")
|
|
|
|
public R visitList(IcsCustomerStaff icsCustomerStaff) {
|
|
|
|
startPage();
|
|
|
|
icsCustomerStaff.setDataType(Constants.CUSTOMER_VISIT);
|
|
|
|
return result(icsCustomerStaffService.selectIcsCustomerStaffList(icsCustomerStaff));
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 查询企业员工列表
|
|
|
|
* @param icsCustomerStaff
|
|
|
|
* @return
|
|
|
|
*/
|
|
|
|
@RequiresPermissions("admin:customer:staff")
|
|
|
|
@GetMapping("staffList")
|
|
|
|
public R staffList(IcsCustomerStaff icsCustomerStaff) {
|
|
|
|
startPage();
|
|
|
|
icsCustomerStaff.setDataType(Constants.CUSTOMER_STAFF);
|
|
|
|
return result(icsCustomerStaffService.selectIcsCustomerStaffList(icsCustomerStaff));
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|