|
@@ -0,0 +1,228 @@
|
|
|
+package com.iden.bms.service;
|
|
|
+
|
|
|
+import cn.hutool.core.bean.BeanUtil;
|
|
|
+import cn.hutool.core.collection.CollUtil;
|
|
|
+import cn.hutool.core.util.StrUtil;
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
+import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
|
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
+import com.iden.common.entity.IdenCrowd;
|
|
|
+import com.iden.common.entity.IdenPerson;
|
|
|
+
|
|
|
+import com.iden.common.entity.IdenPersonCrowdRef;
|
|
|
+import com.iden.common.enums.PersonType2Enum;
|
|
|
+import com.iden.common.enums.PersonTypeEnum;
|
|
|
+import com.iden.common.exception.BDException;
|
|
|
+import com.iden.common.service.IdenCrowdService;
|
|
|
+import com.iden.common.service.IdenPersonCrowdRefService;
|
|
|
+import com.iden.common.service.IdenPersonService;
|
|
|
+import com.iden.common.util.ImgUtil;
|
|
|
+import com.iden.common.util.MyBeanUtils;
|
|
|
+import com.iden.common.vo.PersonVO;
|
|
|
+import com.iden.common.vo.PageReqVO;
|
|
|
+import com.iden.common.vo.UserLogindConvertVO;
|
|
|
+import org.springframework.beans.BeanUtils;
|
|
|
+import org.springframework.beans.factory.annotation.Value;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+import org.springframework.transaction.annotation.Transactional;
|
|
|
+import org.springframework.web.multipart.MultipartFile;
|
|
|
+
|
|
|
+import javax.annotation.Resource;
|
|
|
+import java.io.FileOutputStream;
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.Date;
|
|
|
+import java.util.List;
|
|
|
+import java.util.UUID;
|
|
|
+
|
|
|
+/**
|
|
|
+ *
|
|
|
+ * @author makejava
|
|
|
+ * @since 2021-05-21 00:08:38
|
|
|
+ */
|
|
|
+@Service
|
|
|
+public class PersonService {
|
|
|
+
|
|
|
+ @Resource
|
|
|
+ private IdenPersonService idenPersonService;
|
|
|
+
|
|
|
+ @Resource
|
|
|
+ private IdenPersonCrowdRefService idenPersonCrowdRefService;
|
|
|
+ @Resource
|
|
|
+ private IdenCrowdService idenCrowdService;
|
|
|
+
|
|
|
+ @Value("${iden.root:#{null}}")
|
|
|
+ private String idenRoot;
|
|
|
+ @Value("${file.url:#{null}}")
|
|
|
+ private String fileUrl;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 查询人员列表
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public IPage<PersonVO> listPerson(String type,String nameOrCred, String district, String subdistrict, Long communityId, Long crowdId, String address, String gender, String personType, UserLogindConvertVO loginUser, PageReqVO pageReqVo) {
|
|
|
+ IPage<IdenPerson> page = new Page<>(pageReqVo.getCurrent(), pageReqVo.getPageSize());
|
|
|
+
|
|
|
+ QueryWrapper<IdenPerson> queryWrapper = new QueryWrapper<>();
|
|
|
+ queryWrapper.lambda().like(IdenPerson::getType,type)
|
|
|
+ .like(StrUtil.isNotEmpty(address), IdenPerson::getAddress,address)
|
|
|
+ .eq(StrUtil.isNotEmpty(gender),IdenPerson::getGender,gender)
|
|
|
+ .eq(StrUtil.isNotEmpty(personType),IdenPerson::getPersonType,personType)
|
|
|
+ .eq(StrUtil.isNotEmpty(district),IdenPerson::getDistrict,district)
|
|
|
+ .eq(StrUtil.isNotEmpty(subdistrict),IdenPerson::getSubdistrict,subdistrict)
|
|
|
+ .eq(communityId != null,IdenPerson::getCommunityId,communityId)
|
|
|
+ .and(StrUtil.isNotEmpty(nameOrCred),wrapper -> wrapper.like(IdenPerson::getName,nameOrCred)
|
|
|
+ .or().like(IdenPerson::getCredentialsCode,nameOrCred))
|
|
|
+ .orderByDesc(IdenPerson::getModifyTime)
|
|
|
+ .orderByDesc(IdenPerson::getCreateTime);
|
|
|
+
|
|
|
+ if (crowdId != null) {
|
|
|
+ queryWrapper.apply(" in ( select person_id from iden_person_crowd_ref ipcr where ipcr.crowd_id = "+ crowdId + ")");
|
|
|
+ }
|
|
|
+
|
|
|
+ IPage<IdenPerson> pageRes = this.idenPersonService.page(page, queryWrapper);
|
|
|
+ IPage<PersonVO> results = new Page<>(pageRes.getCurrent(),pageRes.getSize(),pageRes.getTotal());
|
|
|
+ if(CollUtil.isNotEmpty(pageRes.getRecords())){
|
|
|
+ List<PersonVO> list = new ArrayList<>();
|
|
|
+ pageRes.getRecords().forEach(item -> {
|
|
|
+ PersonVO resVO = new PersonVO();
|
|
|
+ BeanUtils.copyProperties(item,resVO);
|
|
|
+ resVO.setPersonTypeName(PersonTypeEnum.getValueToName(resVO.getPersonType()));
|
|
|
+ resVO.setTypeName(PersonType2Enum.getValueToName(resVO.getType()));
|
|
|
+
|
|
|
+ QueryWrapper<IdenPersonCrowdRef> queryWrapper1 = new QueryWrapper<>();
|
|
|
+ queryWrapper1.lambda().eq(IdenPersonCrowdRef::getPersonId,resVO.getId());
|
|
|
+ List<IdenPersonCrowdRef> listIdenPersonCrowdRef = idenPersonCrowdRefService.list(queryWrapper1);
|
|
|
+ StringBuilder sb = new StringBuilder();
|
|
|
+ if (CollUtil.isNotEmpty(listIdenPersonCrowdRef)) {
|
|
|
+ for(IdenPersonCrowdRef idenPersonCrowdRef : listIdenPersonCrowdRef){
|
|
|
+ IdenCrowd idenCrowd = idenCrowdService.getById(idenPersonCrowdRef.getCrowdId());
|
|
|
+ if(idenCrowd != null) {
|
|
|
+ sb.append(idenCrowd.getName()).append(",");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ String crowdName = sb.toString();
|
|
|
+ if(crowdName != null && crowdName.endsWith(",")) {
|
|
|
+ crowdName = crowdName.substring(0, crowdName.length() - 1);
|
|
|
+ }
|
|
|
+ resVO.setCrowdName(crowdName);
|
|
|
+ list.add(resVO);
|
|
|
+ });
|
|
|
+ results.setRecords(list);
|
|
|
+ }
|
|
|
+ return results;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 删除人员
|
|
|
+ * @param id
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public boolean deleteById(Long id){
|
|
|
+ return this.idenPersonService.removeById(id);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 详情
|
|
|
+ * @param id
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public PersonVO getPersonById(Long id){
|
|
|
+ IdenPerson idenPerson = this.idenPersonService.getById(id);
|
|
|
+ if (idenPerson!=null){
|
|
|
+ PersonVO resVO = new PersonVO();
|
|
|
+ BeanUtil.copyProperties(idenPerson,resVO);
|
|
|
+ resVO.setPersonTypeName(PersonTypeEnum.getValueToName(resVO.getPersonType()));
|
|
|
+ resVO.setTypeName(PersonType2Enum.getValueToName(resVO.getType()));
|
|
|
+
|
|
|
+ QueryWrapper<IdenPersonCrowdRef> queryWrapper1 = new QueryWrapper<>();
|
|
|
+ queryWrapper1.lambda().eq(IdenPersonCrowdRef::getPersonId,resVO.getId());
|
|
|
+ List<IdenPersonCrowdRef> listIdenPersonCrowdRef = idenPersonCrowdRefService.list(queryWrapper1);
|
|
|
+ StringBuilder sb = new StringBuilder();
|
|
|
+ if (CollUtil.isNotEmpty(listIdenPersonCrowdRef)) {
|
|
|
+ for(IdenPersonCrowdRef idenPersonCrowdRef : listIdenPersonCrowdRef){
|
|
|
+ IdenCrowd idenCrowd = idenCrowdService.getById(idenPersonCrowdRef.getCrowdId());
|
|
|
+ if(idenCrowd != null) {
|
|
|
+ sb.append(idenCrowd.getName()).append(",");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ String crowdName = sb.toString();
|
|
|
+ if(crowdName != null && crowdName.endsWith(",")) {
|
|
|
+ crowdName = crowdName.substring(0, crowdName.length() - 1);
|
|
|
+ }
|
|
|
+ resVO.setCrowdName(crowdName);
|
|
|
+ return resVO;
|
|
|
+ }
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 上传图像
|
|
|
+ * @param file
|
|
|
+ * @return 访问URL
|
|
|
+ */
|
|
|
+ public String uploadImage(MultipartFile file) throws BDException {
|
|
|
+ String logo = null;
|
|
|
+ try {
|
|
|
+ if (file != null) {
|
|
|
+ //获取文件名
|
|
|
+ String fileName = file.getOriginalFilename();
|
|
|
+ if (org.springframework.util.StringUtils.isEmpty(fileName) || file.getSize() == 0) {
|
|
|
+ throw new BDException("图像文件不能为空!");
|
|
|
+ }
|
|
|
+ //验证文件名是否合格
|
|
|
+ if (!ImgUtil.isImg(fileName)) {
|
|
|
+ throw new BDException("图像文件必须是图片格式!");
|
|
|
+ }
|
|
|
+ String saveFileName = UUID.randomUUID().toString() + "_" + fileName;
|
|
|
+ String picFullFileName = idenRoot + "data/final/image/person/" + saveFileName;
|
|
|
+ FileOutputStream fos = new FileOutputStream(picFullFileName);
|
|
|
+ fos.write(file.getBytes());
|
|
|
+ logo = fileUrl + "person/" + saveFileName;
|
|
|
+ } else {
|
|
|
+ throw new BDException("上传失败");
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ throw new BDException("上传失败",e);
|
|
|
+ }
|
|
|
+
|
|
|
+ return logo;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 保存人员
|
|
|
+ * @param vo
|
|
|
+ */
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
+ public int createPerson(PersonVO vo, UserLogindConvertVO loginUser){
|
|
|
+ QueryWrapper<IdenPerson> queryWrapper = new QueryWrapper<>();
|
|
|
+ queryWrapper.lambda().eq(IdenPerson::getCredentialsCode,vo.getCredentialsCode());
|
|
|
+ if(idenPersonService.count(queryWrapper) > 0){
|
|
|
+ return 1;
|
|
|
+ }
|
|
|
+ //保存人员
|
|
|
+ IdenPerson idenPerson = new IdenPerson();
|
|
|
+ BeanUtil.copyProperties(vo,idenPerson);
|
|
|
+ idenPerson.setCreateTime(new Date());
|
|
|
+
|
|
|
+ this.idenPersonService.save(idenPerson);
|
|
|
+ return 0;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 修改人员
|
|
|
+ * @param vo
|
|
|
+ */
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
+ public void updatePerson(PersonVO vo){
|
|
|
+ //保存人员
|
|
|
+ IdenPerson idenPerson = this.idenPersonService.getById(vo.getId());
|
|
|
+ MyBeanUtils.copyProperties(vo,idenPerson);
|
|
|
+ idenPerson.setModifyTime(new Date());
|
|
|
+ this.idenPersonService.updateById(idenPerson);
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+}
|