package com.crsbg.controller; import cn.hutool.core.date.DateUtil; import cn.hutool.core.util.IdUtil; import com.crsbg.entity.Contacts; import com.crsbg.entity.Customer; import com.crsbg.entity.PageVO; import com.crsbg.entity.User; import com.crsbg.service.ContactsService; import com.crsbg.service.CustomerService; import com.crsbg.service.UserService; import com.crsbg.service.impl.ContactsServiceImpl; import com.crsbg.service.impl.CustomerServiceImpl; import com.crsbg.utils.JSONUtil; import com.crsbg.utils.ServiceFactory; import javax.servlet.ServletException; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import java.io.IOException; import java.util.HashMap; import java.util.List; import java.util.Map; public class ContactsController extends HttpServlet { private ContactsService contactsService = null; @Override protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { String path = request.getServletPath(); if("/controller/getContacts".equals(path)){ getContacts(request,response); }else if("/controller/addContacts".equals(path)){ addContacts(request,response); }else if("/controller/detailContacts".equals(path)){ detailContacts(request,response); }else if("/controller/updateContacts".equals(path)){ updateContacts(request,response); }else if("/controller/deleteContact".equals(path)){ deleteContact(request,response); }else if("/controller/deleteContacts".equals(path)){ deleteContacts(request,response); }else if("/controller/removeContactsActivity".equals(path)){ removeContactsActivity(request,response); }else if("/controller/addContactsActivity".equals(path)){ addContactsActivity(request,response); }else if("/controller/getContactsByName".equals(path)){ getContactsByName(request,response); } } private void getContactsByName(HttpServletRequest request, HttpServletResponse response) throws IOException { System.out.println("进入查询联系人列表getContactsByName..."); String fullname = request.getParameter("sfullname"); contactsService = (ContactsService) ServiceFactory.getService(new ContactsServiceImpl()); List<Contacts> contactsList = contactsService.getContactsByName(fullname); Map<String,Object> map = new HashMap<>(); map.put("code",0); map.put("message","请求成功"); map.put("count",contactsList.size()); map.put("data",contactsList); JSONUtil.getJSON(response,map); } private void addContactsActivity(HttpServletRequest request, HttpServletResponse response) throws IOException { System.out.println("进入关联关系addContactsActivity..."); String cid = request.getParameter("cid"); String[] aids = request.getParameterValues("aid"); contactsService = (ContactsService)ServiceFactory.getService(new ContactsServiceImpl()); boolean flag = contactsService.addContactsActivity(cid,aids); response.getWriter().print(flag); } private void removeContactsActivity(HttpServletRequest request, HttpServletResponse response) throws IOException { System.out.println("进入解除关联关系removeContactsActivity..."); String id = request.getParameter("id"); contactsService = (ContactsService)ServiceFactory.getService(new ContactsServiceImpl()); boolean flag = contactsService.removeContactsActivity(id); response.getWriter().print(flag); } private void deleteContacts(HttpServletRequest request, HttpServletResponse response) throws IOException { System.out.println("进入批量删除联系人deleteContacts..."); String[] ids = request.getParameterValues("id"); contactsService = (ContactsService)ServiceFactory.getService(new ContactsServiceImpl()); Map<String,Object> map = contactsService.deleteContacts(ids); JSONUtil.getJSON(response,map); } private void deleteContact(HttpServletRequest request, HttpServletResponse response) throws IOException { System.out.println("进入删除联系人deleteContact..."); String id = request.getParameter("id"); contactsService = (ContactsService)ServiceFactory.getService(new ContactsServiceImpl()); Map<String,Object> map = contactsService.deleteContact(id); JSONUtil.getJSON(response,map); } private void updateContacts(HttpServletRequest request, HttpServletResponse response) throws IOException { System.out.println("进入修改联系人updateContacts..."); String id = request.getParameter("id"); String fullname = request.getParameter("fullname"); String appellation = request.getParameter("appellation"); String customerId = request.getParameter("customerId"); String job = request.getParameter("job"); String phone = request.getParameter("phone"); String email = request.getParameter("email"); String birth = request.getParameter("birth"); String source = request.getParameter("source"); String description = request.getParameter("description"); String contactSummary = request.getParameter("contactSummary"); String nextContactDate = request.getParameter("nextContactDate"); String address = request.getParameter("address"); Contacts contacts = new Contacts(); contacts.setId(id); contacts.setFullname(fullname); contacts.setAppellation(appellation); contacts.setCustomerId(customerId); contacts.setJob(job); contacts.setPhone(phone); contacts.setEmail(email); contacts.setBirth(birth); contacts.setSource(source); contacts.setDescription(description); contacts.setContactSummary(contactSummary); contacts.setNextContactDate(nextContactDate); contacts.setAddress(address); contactsService = (ContactsService)ServiceFactory.getService(new ContactsServiceImpl()); boolean flag = contactsService.updateContacts(contacts); response.getWriter().print(flag); } private void detailContacts(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { System.out.println("进入联系人详情detailContacts..."); String id = request.getParameter("id"); contactsService = (ContactsService) ServiceFactory.getService(new ContactsServiceImpl()); Contacts contacts = contactsService.getContactsById(id); request.setAttribute("contacts",contacts); request.getRequestDispatcher("/pages/contacts-detail.jsp").forward(request,response); } private void addContacts(HttpServletRequest request, HttpServletResponse response) throws IOException { System.out.println("进入添加联系人addContacts..."); String id = IdUtil.simpleUUID(); String fullname = request.getParameter("fullname"); String appellation = request.getParameter("appellation"); String customerId = request.getParameter("customerId"); String job = request.getParameter("job"); String phone = request.getParameter("phone"); String email = request.getParameter("email"); String birth = request.getParameter("birth"); String source = request.getParameter("source"); String description = request.getParameter("description"); String contactSummary = request.getParameter("contactSummary"); String nextContactDate = request.getParameter("nextContactDate"); String address = request.getParameter("address"); String createBy = ((User)request.getSession().getAttribute("user")).getName(); String createTime = DateUtil.now(); Contacts contacts = new Contacts(); contacts.setId(id); contacts.setFullname(fullname); contacts.setAppellation(appellation); contacts.setCustomerId(customerId); contacts.setJob(job); contacts.setPhone(phone); contacts.setEmail(email); contacts.setBirth(birth); contacts.setSource(source); contacts.setDescription(description); contacts.setContactSummary(contactSummary); contacts.setNextContactDate(nextContactDate); contacts.setAddress(address); contacts.setCreateBy(createBy); contacts.setCreateTime(createTime); contactsService = (ContactsService)ServiceFactory.getService(new ContactsServiceImpl()); boolean flag = contactsService.addContacts(contacts); response.getWriter().print(flag); } private void getContacts(HttpServletRequest request, HttpServletResponse response) throws IOException { System.out.println("进入查询联系人getContacts..."); String fullname = request.getParameter("fullname"); String company = request.getParameter("company"); int page = Integer.parseInt(request.getParameter("page")); int limit = Integer.parseInt(request.getParameter("limit")); int pageNumber = (page-1)*limit; int pageSize = limit; Map<String,Object> param = new HashMap<>(); param.put("fullname",fullname); param.put("company",company); param.put("pageNumber",pageNumber); param.put("pageSize",pageSize); contactsService = (ContactsService)ServiceFactory.getService(new ContactsServiceImpl()); PageVO<Contacts> vo = contactsService.getContacts(param); Map<String,Object> map = new HashMap<>(); map.put("code",0); map.put("message","请求成功"); map.put("count",vo.getTotal()); map.put("data",vo.getDatas()); JSONUtil.getJSON(response,map); } }

yifeng868 LV8
6月11日
微信网友_7290996505972736 LV4
2024年12月11日
255921158 LV5
2024年9月8日
TY0165 LV20
2024年6月21日
sunlea LV20
2024年5月12日
haozhilang LV9
2023年11月20日
zhaozhiqi LV5
2023年9月25日
Anxglee LV7
2023年7月28日
hongdongdong LV14
2023年6月17日
a970712258 LV4
2023年6月1日

yifeng868 LV8
6月11日
zhangyue2025
3月15日
暂无贡献等级
微信网友_7290996505972736 LV4
2024年12月11日
17600446733 LV21
2024年12月10日
255921158 LV5
2024年9月8日
TY0165 LV20
2024年6月21日
15816705316
2024年5月31日
暂无贡献等级
sunlea LV20
2024年5月12日
李俊雄 LV3
2024年4月30日
m5433661 LV2
2024年3月28日