package com.goafanti.user.service.impl; import java.text.ParseException; import java.util.Date; import java.util.HashMap; import java.util.Map; import java.util.UUID; import org.apache.commons.lang3.StringUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import com.goafanti.common.dao.OrganizationIdentityMapper; import com.goafanti.common.dao.OrganizationInfoMapper; import com.goafanti.common.dao.PatentCostMapper; import com.goafanti.common.dao.UserMapper; import com.goafanti.common.model.OrganizationIdentity; import com.goafanti.common.model.OrganizationInfo; import com.goafanti.common.model.User; import com.goafanti.common.utils.DateUtils; import com.goafanti.core.mybatis.BaseMybatisDao; import com.goafanti.core.mybatis.page.Pagination; import com.goafanti.user.bo.OrgListBo; import com.goafanti.user.bo.UserDownLoadBo; import com.goafanti.user.bo.UserListBo; import com.goafanti.user.bo.UserPageHomeBo; import com.goafanti.user.service.UserService; @Service public class UserServiceImpl extends BaseMybatisDao implements UserService { @Autowired UserMapper userMapper; @Autowired OrganizationInfoMapper organizationInfoMapper; @Autowired OrganizationIdentityMapper organizationIdentityMapper; @Override public User insertRegister(User user,String contacts,String companyName,String uid) { userMapper.insert(user); if (1 == user.getType()){ if (!StringUtils.isBlank(companyName)){ OrganizationInfo organizationInfo = new OrganizationInfo(); organizationInfo.setUid(uid); organizationInfo.setCompanyName(companyName); organizationInfo.setId(UUID.randomUUID().toString()); organizationInfoMapper.insert(organizationInfo); } if (!StringUtils.isBlank(contacts)){ OrganizationIdentity organizationIdentity = new OrganizationIdentity(); organizationIdentity.setUid(uid); organizationIdentity.setId(UUID.randomUUID().toString()); organizationIdentity.setContacts(contacts); organizationIdentityMapper.insert(organizationIdentity); } } return user; } @Override public User selectByMobieAndType(java.lang.String mobile, Integer type) { return userMapper.selectByMobieAndType(mobile,type); } @Override public User selectByPrimaryKey(String id) { return userMapper.selectByPrimaryKey(id); } @Override public int updateByPrimaryKeySelective(User u) { return userMapper.updateByPrimaryKeySelective(u); } @Override public User insert(User user) { userMapper.insert(user); return user; } @Override public int updateByPrimaryKey(User u) { return userMapper.updateByPrimaryKey(u); } @Override public UserPageHomeBo selectUserPageHomeBoByUserId(String uid) { return userMapper.selectUserPageHomeBoByUserId(uid); } @Override public UserDownLoadBo selectUserDownLoadBoByUserId(String id) { return userMapper.selectUserDownLoadBoByUserId(id); } @SuppressWarnings("unchecked") @Override public Pagination listUser(String mobile, String email, String[] pDate, Integer number, String aftUsername, Integer auditStatus, Integer pageNo, Integer pageSize) throws ParseException { Map params = new HashMap<>(); Date pStart = null; Date pEnd = null; if (null != pDate ){ pStart = DateUtils.parseDate(pDate[0], "yyyy-MM-dd"); if (pDate.length == 2){ pEnd = DateUtils.addDays(DateUtils.parseDate(pDate[1], "yyyy-MM-dd"), 1); } } if (null != pStart){ params.put("pStart", pStart); } if (null != pEnd){ params.put("pEnd", pEnd); } if (!StringUtils.isBlank(mobile)){ params.put("mobile", mobile); } if (!StringUtils.isBlank(email)){ params.put("email", email); } if (null != number ){ params.put("number", number); } if (!StringUtils.isBlank(aftUsername)){ params.put("aftUsername", aftUsername); } if (null != auditStatus){ params.put("auditStatus", auditStatus); } if (pageNo == null || pageNo < 0) { pageNo = 1; } if (pageSize == null || pageSize < 0) { pageSize = 10; } return (Pagination) findPage("findUserListByPage","findUserCount", params, pageNo, pageSize); } @SuppressWarnings("unchecked") @Override public Pagination listOrg(String mobile, String email, String[] pDate, Integer number, String aftUsername, Integer auditStatus, Integer pageNo, Integer pageSize) throws ParseException { Map params = new HashMap<>(); Date pStart = null; Date pEnd = null; if (null != pDate ){ pStart = DateUtils.parseDate(pDate[0], "yyyy-MM-dd"); if (pDate.length == 2){ pEnd = DateUtils.addDays(DateUtils.parseDate(pDate[1], "yyyy-MM-dd"), 1); } } if (null != pStart){ params.put("pStart", pStart); } if (null != pEnd){ params.put("pEnd", pEnd); } if (!StringUtils.isBlank(mobile)){ params.put("mobile", mobile); } if (!StringUtils.isBlank(email)){ params.put("email", email); } if (null != number ){ params.put("number", number); } if (!StringUtils.isBlank(aftUsername)){ params.put("aftUsername", aftUsername); } if (null != auditStatus){ params.put("auditStatus", auditStatus); } if (pageNo == null || pageNo < 0) { pageNo = 1; } if (pageSize == null || pageSize < 0) { pageSize = 10; } return (Pagination) findPage("findOrgListByPage","findOrgCount", params, pageNo, pageSize); } }