package com.goafanti.user.service.impl; import java.util.Date; import java.util.HashMap; import java.util.List; import java.util.Map; import com.goafanti.admin.service.DepartmentService; import org.springframework.beans.BeanUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import com.goafanti.common.constant.AFTConstants; import com.goafanti.common.dao.UserServiceFollowMapper; import com.goafanti.common.dao.UserServiceMapper; import com.goafanti.common.model.UserService; import com.goafanti.common.utils.DateUtils; import com.goafanti.common.utils.StringUtils; import com.goafanti.core.mybatis.BaseMybatisDao; import com.goafanti.core.mybatis.page.Pagination; import com.goafanti.core.shiro.token.TokenManager; import com.goafanti.user.bo.InputListOrderUserService; import com.goafanti.user.bo.InputUserServiceFollow; import com.goafanti.user.bo.OrderProject; import com.goafanti.user.bo.OutOrderUserService; import com.goafanti.user.bo.OutUserServiceFollow; import com.goafanti.user.service.UserServiceService; @Service public class UserServiceServiceImpl extends BaseMybatisDao implements UserServiceService { @Autowired private UserServiceMapper userServiceMapper; @Autowired private UserServiceFollowMapper userServiceFollowMapper; @Autowired private DepartmentService departmentService; @Override public int addUseService(InputUserServiceFollow us) { us.setAid(TokenManager.getAdminId()); if (StringUtils.isNotBlank(us.getRenewalTimes())) { us.setRenewalTime(DateUtils.StringToDate(us.getRenewalTimes(), AFTConstants.YYYYMMDD)); } Date date=new Date(); us.setCreateTime(date); userServiceFollowMapper.insertSelective(us); Integer id=userServiceMapper.selectByUid(us.getUid()); UserService u=new UserService(); BeanUtils.copyProperties(us, u); u.setNewTime(date); if (id==null) { userServiceMapper.insertSelective(u); }else { u.setId(id); u.setCreateTime(null); userServiceMapper.updateByPrimaryKeySelective(u); } return 1; } @Override public List listUseServiceFollow(String uid) { return userServiceFollowMapper.listUseServiceFollow(uid); } @SuppressWarnings("unchecked") @Override public Pagination listOrderUseService(InputListOrderUserService i) { Map map = setParams(i); Pagination p=(Pagination) findPage("OrderUseServiceList", "OrderUseServiceCount", map, i.getPageNo(), i.getPageSize()); List list= (List) p.getList(); setOrderUserService(list); return p; } private Map setParams(InputListOrderUserService i) { Mapmap =new HashMap(); if(i.getUserName()!=null)map.put("userName", i.getUserName()); if(i.getDeps()!=null)map.put("deps", departmentService.parseArray(i.getDeps())); if(i.getStartFollowTimes()!=null)map.put("startFollowTimes", i.getStartFollowTimes()); if(i.getEndFollowTimes()!=null)map.put("endFollowTimes", i.getEndFollowTimes()+" 23:59:59"); if(i.getStartSignTimes()!=null)map.put("startSignTimes", i.getStartSignTimes()); if(i.getEndSignTimes()!=null)map.put("endSignTimes", i.getEndSignTimes()+" 23:59:59"); if(i.getAddWechat()!=null)map.put("addWechat", i.getAddWechat()); if(i.getRenewal()!=null)map.put("renewal", i.getRenewal()); return map; } @SuppressWarnings("unchecked") @Override public List listOrderUseServiceGetList(InputListOrderUserService i) { Map map = setParams(i); if (i.getPageSize()==null) i.setPageSize(99999); List list=(List) findList("OrderUseServiceList", map,i.getPageNo(), i.getPageSize()); setOrderUserService(list); return list; } private void setOrderUserService(List list) { for (OutOrderUserService ou: list) { StringBuffer projects=new StringBuffer(); StringBuffer consultants=new StringBuffer(); StringBuffer declareBatchs=new StringBuffer(); StringBuffer certificationNos=new StringBuffer(); for (OrderProject o : ou.getList()) { if (StringUtils.isNotBlank(o.getCommodityName())) { projects.append(o.getCommodityName()); } else { projects.append("无"); } projects.append("/"); if (StringUtils.isNotBlank(o.getReceiverName())) { consultants.append(o.getReceiverName()); } else { consultants.append("无"); } consultants.append("/"); if (o.getDeclarationBatch() != null) { declareBatchs.append(o.getDeclarationBatch()); } else { declareBatchs.append("无"); } declareBatchs.append("/"); if (StringUtils.isNotBlank(o.getCertificateNumber())) { certificationNos.append(o.getCertificateNumber()); } else { certificationNos.append("无"); } certificationNos.append("/"); } if(projects.length()>1)ou.setProjects(projects.substring(0, projects.length()-1)); if(consultants.length()>1)ou.setConsultants(consultants.substring(0, consultants.length()-1)); if(declareBatchs.length()>1)ou.setDeclareBatchs(declareBatchs.substring(0, declareBatchs.length()-1)); if(certificationNos.length()>1)ou.setCertificationNos(certificationNos.substring(0, certificationNos.length()-1)); } } }