| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538 |
- package com.goafanti.demand.service.impl;
- import java.text.ParseException;
- import java.util.Calendar;
- import java.util.Date;
- import java.util.HashMap;
- import java.util.List;
- 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.constant.AFTConstants;
- import com.goafanti.common.dao.DemandMapper;
- import com.goafanti.common.dao.NoticeMapper;
- import com.goafanti.common.dao.UserMapper;
- import com.goafanti.common.dao.UserRoleMapper;
- import com.goafanti.common.enums.DeleteStatus;
- import com.goafanti.common.enums.DemandAuditStatus;
- import com.goafanti.common.enums.DemandReleaseStatus;
- import com.goafanti.common.enums.DemandStatus;
- import com.goafanti.common.enums.NoticeReadStatus;
- import com.goafanti.common.enums.NoticeStatus;
- import com.goafanti.common.enums.UserType;
- import com.goafanti.common.model.Demand;
- import com.goafanti.common.model.Notice;
- 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.core.shiro.token.TokenManager;
- import com.goafanti.demand.bo.DemandListBo;
- import com.goafanti.demand.bo.DemandManageDetailBo;
- import com.goafanti.demand.bo.DemandManageListBo;
- import com.goafanti.demand.service.DemandService;
- @Service
- public class DemandServiceImpl extends BaseMybatisDao<DemandMapper> implements DemandService {
- @Autowired
- private DemandMapper demandMapper;
- @Autowired
- private UserMapper userMapper;
- @Autowired
- private UserRoleMapper userRoleMapper;
- @Autowired
- private NoticeMapper noticeMapper;
- @SuppressWarnings("unchecked")
- @Override
- public Pagination<DemandManageListBo> selectUserDemandManageList(Integer auditStatus, String province,
- Integer serialNumber, String name, String keyword, Integer infoSources, Integer demandType,
- String validityPeriodStartDate, String validityPeriodEndDate, String username, Integer status,
- Integer releaseStatus, String releaseDateStartDate, String releaseDateEndDate, Integer pNo, Integer pSize) {
- Map<String, Object> params = new HashMap<>();
- Date vStart = null;
- Date vEnd = null;
- Date rStart = null;
- Date rEnd = null;
- if (!StringUtils.isBlank(validityPeriodStartDate)) {
- try {
- vStart = DateUtils.parseDate(validityPeriodStartDate, AFTConstants.YYYYMMDD);
- } catch (ParseException e) {
- }
- }
- if (!StringUtils.isBlank(validityPeriodEndDate)) {
- try {
- vEnd = DateUtils.parseDate(validityPeriodEndDate, AFTConstants.YYYYMMDD);
- } catch (ParseException e) {
- }
- }
- if (!StringUtils.isBlank(releaseDateStartDate)) {
- try {
- rStart = DateUtils.parseDate(releaseDateStartDate, AFTConstants.YYYYMMDD);
- } catch (ParseException e) {
- }
- }
- if (!StringUtils.isBlank(releaseDateEndDate)) {
- try {
- rEnd = DateUtils.parseDate(releaseDateEndDate, AFTConstants.YYYYMMDD);
- } catch (ParseException e) {
- }
- }
- if (null != vStart) {
- params.put("vStart", vStart);
- }
- if (null != vEnd) {
- params.put("vEnd", vEnd);
- }
- if (null != rStart) {
- params.put("rStart", rStart);
- }
- if (null != rEnd) {
- params.put("rEnd", rEnd);
- }
- if (null != auditStatus) {
- params.put("auditStatus", auditStatus);
- }
- if (!StringUtils.isBlank(province)) {
- params.put("province", province);
- }
- if (null != serialNumber) {
- params.put("serialNumber", serialNumber);
- }
- if (!StringUtils.isBlank(name)) {
- params.put("name", name);
- }
- if (!StringUtils.isBlank(keyword)) {
- params.put("keyword", keyword);
- }
- if (!StringUtils.isBlank(username)) {
- params.put("username", username);
- }
- if (null != infoSources) {
- params.put("infoSources", infoSources);
- }
- if (null != demandType) {
- params.put("demandType", demandType);
- }
- if (null != status) {
- params.put("status", status);
- }
- if (null != releaseStatus) {
- params.put("releaseStatus", releaseStatus);
- }
- if (pNo == null || pNo < 0) {
- pNo = 1;
- }
- if (pSize == null || pSize < 0) {
- pSize = 10;
- }
- if (TokenManager.hasRole(AFTConstants.SALESMANAGERADMIN) || TokenManager.hasRole(AFTConstants.SALESMANADMIN)) {
- params.put("principal", TokenManager.getAdminId());
- }
- if (TokenManager.hasRole(AFTConstants.MANAGERADMIN)) {
- params.put("mid", TokenManager.getAdminId());
- }
- if (TokenManager.hasRole(AFTConstants.TECHBROKER)) {
- params.put("techBroker", TokenManager.getAdminId());
- }
- return (Pagination<DemandManageListBo>) findPage("findManageUserDemandListByPage", "findManageUserDemandCount",
- params, pNo, pSize);
- }
- @SuppressWarnings("unchecked")
- @Override
- public Pagination<DemandManageListBo> selectOrgDemandManageList(Integer auditStatus, String province,
- Integer serialNumber, String name, String keyword, Integer infoSources, Integer demandType,
- String validityPeriodStartDate, String validityPeriodEndDate, String username, Integer status,
- Integer releaseStatus, String releaseDateStartDate, String releaseDateEndDate, Integer pNo, Integer pSize) {
- Map<String, Object> params = new HashMap<>();
- Date vStart = null;
- Date vEnd = null;
- Date rStart = null;
- Date rEnd = null;
- if (!StringUtils.isBlank(validityPeriodStartDate)) {
- try {
- vStart = DateUtils.parseDate(validityPeriodStartDate, AFTConstants.YYYYMMDD);
- } catch (ParseException e) {
- }
- }
- if (!StringUtils.isBlank(validityPeriodEndDate)) {
- try {
- vEnd = DateUtils.parseDate(validityPeriodEndDate, AFTConstants.YYYYMMDD);
- } catch (ParseException e) {
- }
- }
- if (!StringUtils.isBlank(releaseDateStartDate)) {
- try {
- rStart = DateUtils.parseDate(releaseDateStartDate, AFTConstants.YYYYMMDD);
- } catch (ParseException e) {
- }
- }
- if (!StringUtils.isBlank(releaseDateEndDate)) {
- try {
- rEnd = DateUtils.parseDate(releaseDateEndDate, AFTConstants.YYYYMMDD);
- } catch (ParseException e) {
- }
- }
- if (null != vStart) {
- params.put("vStart", vStart);
- }
- if (null != vEnd) {
- params.put("vEnd", vEnd);
- }
- if (null != rStart) {
- params.put("rStart", rStart);
- }
- if (null != rEnd) {
- params.put("rEnd", rEnd);
- }
- if (null != auditStatus) {
- params.put("auditStatus", auditStatus);
- }
- if (!StringUtils.isBlank(province)) {
- params.put("province", province);
- }
- if (null != serialNumber) {
- params.put("serialNumber", serialNumber);
- }
- if (!StringUtils.isBlank(name)) {
- params.put("name", name);
- }
- if (!StringUtils.isBlank(keyword)) {
- params.put("keyword", keyword);
- }
- if (!StringUtils.isBlank(username)) {
- params.put("username", username);
- }
- if (null != infoSources) {
- params.put("infoSources", infoSources);
- }
- if (null != demandType) {
- params.put("demandType", demandType);
- }
- if (null != status) {
- params.put("status", status);
- }
- if (null != releaseStatus) {
- params.put("releaseStatus", releaseStatus);
- }
- if (pNo == null || pNo < 0) {
- pNo = 1;
- }
- if (pSize == null || pSize < 0) {
- pSize = 10;
- }
- if (TokenManager.hasRole(AFTConstants.SALESMANAGERADMIN) || TokenManager.hasRole(AFTConstants.SALESMANADMIN)) {
- params.put("principal", TokenManager.getAdminId());
- }
- if (TokenManager.hasRole(AFTConstants.MANAGERADMIN)) {
- params.put("mid", TokenManager.getAdminId());
- }
- if (TokenManager.hasRole(AFTConstants.TECHBROKER)) {
- params.put("techBroker", TokenManager.getAdminId());
- }
- return (Pagination<DemandManageListBo>) findPage("findManageOrgDemandListByPage", "findManageOrgDemandCount",
- params, pNo, pSize);
- }
- @Override
- public void saveUserDemand(Demand d, String validityPeriodFormattedDate) {
- Date validityPeriod = null;
- if (!StringUtils.isBlank(validityPeriodFormattedDate)) {
- try {
- validityPeriod = DateUtils.parseDate(validityPeriodFormattedDate, AFTConstants.YYYYMMDD);
- } catch (ParseException e) {
- }
- }
- d.setValidityPeriod(validityPeriod);
- d.setId(UUID.randomUUID().toString());
- d.setDeletedSign(DeleteStatus.UNDELETE.getCode());
- Calendar now = Calendar.getInstance();
- now.set(Calendar.MILLISECOND, 0);
- d.setStatus(DemandStatus.UNRESOLVED.getCode());
- d.setAuditStatus(DemandAuditStatus.CREATE.getCode());
- d.setReleaseStatus(DemandReleaseStatus.UNRELEASE.getCode());
- d.setPrincipalId(TokenManager.getAdminId());
- if (DemandAuditStatus.SUBMIT.getCode().equals(d.getAuditStatus())) {
- d.setAuditStatus(DemandAuditStatus.INAUDIT.getCode());
- createAuditorNotice(d);
- }
- d.setCreateTime(now.getTime());
- demandMapper.insert(d);
- }
- @Override
- public int updateUserDemand(Demand d, String validityPeriodFormattedDate) {
- Date validityPeriod = null;
- if (!StringUtils.isBlank(validityPeriodFormattedDate)) {
- try {
- validityPeriod = DateUtils.parseDate(validityPeriodFormattedDate, AFTConstants.YYYYMMDD);
- } catch (ParseException e) {
- }
- }
- d.setValidityPeriod(validityPeriod);
- if (DemandAuditStatus.SUBMIT.getCode().equals(d.getAuditStatus())) {
- d.setReleaseStatus(DemandReleaseStatus.RELEASED.getCode());
- d.setAuditStatus(DemandAuditStatus.INAUDIT.getCode());
- d.setReleaseStatus(DemandReleaseStatus.RELEASED.getCode());
- createAuditorNotice(d);
- }
- return demandMapper.updateByPrimaryKeySelective(d);
- }
- @Override
- public DemandManageDetailBo selectUserDemandDetail(String id) {
- return demandMapper.selectUserDemandDetail(id);
- }
- @Override
- public int deleteByPrimaryKey(List<String> id) {
- return demandMapper.batchDeleteByPrimaryKey(id);
- }
- @Override
- public DemandManageDetailBo selectOrgDemandDetail(String id) {
- return demandMapper.selectOrgDemandDetail(id);
- }
- @Override
- public Demand selectByPrimaryKey(String id) {
- return demandMapper.selectByPrimaryKey(id);
- }
- @SuppressWarnings("unchecked")
- @Override
- public Pagination<DemandListBo> listDemand(Integer serialNumber, String name, String keyword, Integer demandType,
- String validityPeriodStartDate, String validityPeriodEndDate, Integer status, Integer releaseStatus,
- String releaseDateStartDate, String releaseDateEndDate, Integer pNo, Integer pSize) {
- Map<String, Object> params = new HashMap<>();
- Date vStart = null;
- Date vEnd = null;
- Date rStart = null;
- Date rEnd = null;
- params.put("employerId", TokenManager.getUserId());
- if (!StringUtils.isBlank(validityPeriodStartDate)) {
- try {
- vStart = DateUtils.parseDate(validityPeriodStartDate, AFTConstants.YYYYMMDD);
- } catch (ParseException e) {
- }
- }
- if (!StringUtils.isBlank(validityPeriodEndDate)) {
- try {
- vEnd = DateUtils.parseDate(validityPeriodEndDate, AFTConstants.YYYYMMDD);
- } catch (ParseException e) {
- }
- }
- if (!StringUtils.isBlank(releaseDateStartDate)) {
- try {
- rStart = DateUtils.parseDate(releaseDateStartDate, AFTConstants.YYYYMMDD);
- } catch (ParseException e) {
- }
- }
- if (!StringUtils.isBlank(releaseDateEndDate)) {
- try {
- rEnd = DateUtils.parseDate(releaseDateEndDate, AFTConstants.YYYYMMDD);
- } catch (ParseException e) {
- }
- }
- if (null != vStart) {
- params.put("vStart", vStart);
- }
- if (null != vEnd) {
- params.put("vEnd", vEnd);
- }
- if (null != rStart) {
- params.put("rStart", rStart);
- }
- if (null != rEnd) {
- params.put("rEnd", rEnd);
- }
- if (null != serialNumber) {
- params.put("serialNumber", serialNumber);
- }
- if (!StringUtils.isBlank(name)) {
- params.put("name", name);
- }
- if (!StringUtils.isBlank(keyword)) {
- params.put("keyword", keyword);
- }
- if (null != demandType) {
- params.put("demandType", demandType);
- }
- if (null != status) {
- params.put("status", status);
- }
- if (null != releaseStatus) {
- params.put("releaseStatus", releaseStatus);
- }
- if (pNo == null || pNo < 0) {
- pNo = 1;
- }
- if (pSize == null || pSize < 0) {
- pSize = 10;
- }
- return (Pagination<DemandListBo>) findPage("findDemandListByPage", "findDemandCount", params, pNo, pSize);
- }
- @Override
- public int updateReleaseStatus(Demand d) {
- d.setAuditStatus(DemandAuditStatus.CREATE.getCode());
- d.setReleaseStatus(DemandReleaseStatus.UNRELEASE.getCode());
- d.setStatus(DemandStatus.UNRESOLVED.getCode());
- demandMapper.updateReleaseDate(d.getId());
- return demandMapper.updateByPrimaryKeySelective(d);
- }
- @Override
- public int updateAuditDemand(Demand d, String techBroderId, Integer auditStatus) {
- d.setAuditStatus(auditStatus);
- if (DemandAuditStatus.AUDITED.getCode().equals(auditStatus)) {
- Calendar now = Calendar.getInstance();
- now.set(Calendar.MILLISECOND, 0);
- d.setReleaseDate(now.getTime());
- } else {
- d.setReleaseStatus(DemandReleaseStatus.UNRELEASE.getCode());
- }
- return demandMapper.updateByPrimaryKeySelective(d);
- }
- @Override
- public void saveDemand(Demand d, String validityPeriodFormattedDate) {
- Date validityPeriod = null;
- if (!StringUtils.isBlank(validityPeriodFormattedDate)) {
- try {
- validityPeriod = DateUtils.parseDate(validityPeriodFormattedDate, AFTConstants.YYYYMMDD);
- } catch (ParseException e) {
- }
- }
- d.setValidityPeriod(validityPeriod);
- d.setId(UUID.randomUUID().toString());
- d.setDeletedSign(DeleteStatus.UNDELETE.getCode());
- Calendar now = Calendar.getInstance();
- now.set(Calendar.MILLISECOND, 0);
- d.setStatus(DemandStatus.UNRESOLVED.getCode());
- d.setAuditStatus(DemandAuditStatus.CREATE.getCode());
- d.setReleaseStatus(DemandReleaseStatus.UNRELEASE.getCode());
- if (DemandAuditStatus.SUBMIT.getCode().equals(d.getAuditStatus())) {
- d.setAuditStatus(DemandAuditStatus.INAUDIT.getCode());
- d.setReleaseStatus(DemandReleaseStatus.RELEASED.getCode());
- createAuditorNotice(d);
- }
- d.setCreateTime(now.getTime());
- demandMapper.insert(d);
- }
- // 给所有审核员发送审核通知
- private void createAuditorNotice(Demand d) {
- List<String> ids = userRoleMapper.listAuditor();
- if (null != ids && ids.size() > 0) {
- for (String s : ids) {
- Notice n = new Notice();
- Calendar now = Calendar.getInstance();
- now.set(Calendar.MILLISECOND, 0);
- n.setId(UUID.randomUUID().toString());
- n.setCreateTime(now.getTime());
- n.setReaded(NoticeReadStatus.UNREAD.getCode());
- User u = userMapper.selectByPrimaryKey(d.getEmployerId());
- n.setRid(d.getId());
- n.setUid(d.getEmployerId());
- n.setAid(s);
- if (null != u) {
- n.setPid(u.getAid());
- }
- if (UserType.PERSONAL.getCode().equals(d.getDataCategory())) {
- n.setContent(NoticeStatus.PERSONALDEMAND.getDesc() + " " + DemandAuditStatus.SUBMIT.getDesc());
- n.setNoticeType(NoticeStatus.PERSONALDEMAND.getCode());
- } else if (UserType.ORGANIZATION.getCode().equals(d.getDataCategory())) {
- n.setContent(NoticeStatus.ORGANIZATIONDEMAND.getDesc() + " " + DemandAuditStatus.SUBMIT.getDesc());
- n.setNoticeType(NoticeStatus.ORGANIZATIONDEMAND.getCode());
- }
- noticeMapper.insert(n);
- }
- }
- }
- }
|