33import com .alibaba .fastjson .JSONObject ;
44import com .java110 .core .annotation .Java110Cmd ;
55import com .java110 .core .annotation .Java110Transactional ;
6+ import com .java110 .core .context .CmdContextUtils ;
67import com .java110 .core .context .DataFlowContext ;
78import com .java110 .core .context .ICmdDataFlowContext ;
89import com .java110 .core .event .cmd .Cmd ;
2223import com .java110 .po .file .FileRelPo ;
2324import com .java110 .po .owner .OwnerAppUserPo ;
2425import com .java110 .po .owner .OwnerPo ;
26+ import com .java110 .utils .cache .MappingCache ;
2527import com .java110 .utils .constant .BusinessTypeConstant ;
28+ import com .java110 .utils .constant .MappingConstant ;
2629import com .java110 .utils .exception .CmdException ;
2730import com .java110 .utils .util .Assert ;
2831import com .java110 .utils .util .BeanConvertUtil ;
2932import com .java110 .utils .util .ListUtil ;
33+ import com .java110 .utils .util .StringUtil ;
3034import org .apache .commons .lang3 .StringUtils ;
3135import org .springframework .beans .factory .annotation .Autowired ;
3236
5862)
5963
6064@ Java110ExampleDoc (
61- reqBody = "{\n " +
65+ reqBody = "{\n " +
6266 "\t \" memberId\" : 123123123,\n " +
6367 "\t \" ownerPhoto\" : \" \" ,\n " +
6468 "\t \" communityId\" : \" 2022121921870161\" \n " +
6569 "}" ,
66- resBody = "{\" code\" :0,\" msg\" :\" 成功\" }"
70+ resBody = "{\" code\" :0,\" msg\" :\" 成功\" }"
6771)
6872@ Java110Cmd (serviceCode = "owner.uploadOwnerPhoto" )
6973public class UploadOwnerPhotoCmd extends Cmd {
@@ -89,94 +93,64 @@ public class UploadOwnerPhotoCmd extends Cmd {
8993
9094 @ Override
9195 public void validate (CmdEvent event , ICmdDataFlowContext context , JSONObject reqJson ) throws CmdException {
92- Assert .jsonObjectHaveKey (reqJson , "memberId" , "请求报文中未包含ownerId" );
93- Assert .jsonObjectHaveKey (reqJson , "photo" , "请求报文中未包含photo" );
94- Assert .jsonObjectHaveKey (reqJson , "communityId" , "请求报文中未包含communityId" );
96+ Assert .hasKeyAndValue (reqJson , "photo" , "请求报文中未包含photo" );
97+ Assert .hasKeyAndValue (reqJson , "communityId" , "请求报文中未包含communityId" );
9598 }
9699
97100 @ Override
98101 @ Java110Transactional
99102 public void doCmd (CmdEvent event , ICmdDataFlowContext context , JSONObject reqJson ) throws CmdException , ParseException {
100- if (reqJson .containsKey ("photo" ) && !StringUtils .isEmpty (reqJson .getString ("photo" ))) {
101- FileDto fileDto = new FileDto ();
102- fileDto .setFileId (GenerateCodeFactory .getGeneratorId (GenerateCodeFactory .CODE_PREFIX_file_id ));
103- fileDto .setFileName (fileDto .getFileId ());
104- fileDto .setContext (reqJson .getString ("photo" ));
105- fileDto .setSuffix ("jpeg" );
106- fileDto .setCommunityId (reqJson .getString ("communityId" ));
107- String fileName = fileInnerServiceSMOImpl .saveFile (fileDto );
108- reqJson .put ("ownerPhotoId" , fileDto .getFileId ());
109- reqJson .put ("fileSaveName" , fileName );
110-
111- editOwnerPhoto (reqJson );
112103
104+ String userId = CmdContextUtils .getUserId (context );
105+
106+ OwnerAppUserDto ownerAppUserDto = new OwnerAppUserDto ();
107+ ownerAppUserDto .setUserId (userId );
108+ ownerAppUserDto .setCommunityId (reqJson .getString ("communityId" ));
109+ List <OwnerAppUserDto > ownerAppUserDtos = ownerAppUserInnerServiceSMOImpl .queryOwnerAppUsers (ownerAppUserDto );
110+
111+ if (ListUtil .isNull (ownerAppUserDtos )) {
112+ throw new CmdException ("未绑定业主" );
113113 }
114- //添加小区楼
115- editOwner (reqJson );
116- }
117114
118- public void editOwnerPhoto (JSONObject paramInJson ) {
119-
120- FileRelDto fileRelDto = new FileRelDto ();
121- fileRelDto .setRelTypeCd ("10000" );
122- fileRelDto .setObjId (paramInJson .getString ("memberId" ));
123- List <FileRelDto > fileRelDtos = fileRelInnerServiceSMOImpl .queryFileRels (fileRelDto );
124- if (ListUtil .isNull (fileRelDtos )) {
125- JSONObject businessUnit = new JSONObject ();
126- businessUnit .put ("fileRelId" , GenerateCodeFactory .getGeneratorId (GenerateCodeFactory .CODE_PREFIX_fileRelId ));
127- businessUnit .put ("relTypeCd" , "10000" );
128- businessUnit .put ("saveWay" , "table" );
129- businessUnit .put ("objId" , paramInJson .getString ("memberId" ));
130- businessUnit .put ("fileRealName" , paramInJson .getString ("fileSaveName" ));
131- businessUnit .put ("fileSaveName" , paramInJson .getString ("fileSaveName" ));
132- FileRelPo fileRelPo = BeanConvertUtil .covertBean (businessUnit , FileRelPo .class );
133- fileRelInnerServiceSMOImpl .saveFileRel (fileRelPo );
134- return ;
115+ String memberId = "" ;
116+ for (OwnerAppUserDto tmpOwnerAppUserDto : ownerAppUserDtos ) {
117+ if ("-1" .equals (tmpOwnerAppUserDto .getMemberId ())) {
118+ continue ;
119+ }
120+ memberId = tmpOwnerAppUserDto .getMemberId ();
121+ }
122+ if (StringUtil .isEmpty (memberId )) {
123+ throw new CmdException ("还没有认证房屋,请先认证房屋" );
135124 }
136125
137- JSONObject businessUnit = new JSONObject ();
138- businessUnit .putAll (BeanConvertUtil .beanCovertMap (fileRelDtos .get (0 )));
139- businessUnit .put ("fileRealName" , paramInJson .getString ("fileSaveName" ));
140- businessUnit .put ("fileSaveName" , paramInJson .getString ("fileSaveName" ));
141- FileRelPo fileRelPo = BeanConvertUtil .covertBean (businessUnit , FileRelPo .class );
142- fileRelInnerServiceSMOImpl .updateFileRel (fileRelPo );
126+ FileDto fileDto = new FileDto ();
127+ fileDto .setFileId (GenerateCodeFactory .getGeneratorId (GenerateCodeFactory .CODE_PREFIX_file_id ));
128+ fileDto .setFileName (fileDto .getFileId ());
129+ fileDto .setContext (reqJson .getString ("photo" ));
130+ fileDto .setSuffix ("jpeg" );
131+ fileDto .setCommunityId (reqJson .getString ("communityId" ));
132+ String fileName = fileInnerServiceSMOImpl .saveFile (fileDto );
133+ reqJson .put ("ownerPhotoId" , fileDto .getFileId ());
134+ reqJson .put ("fileSaveName" , fileName );
143135
136+ String imgUrl = MappingCache .getValue (MappingConstant .FILE_DOMAIN , "IMG_PATH" );
137+ String faceUrl = imgUrl + fileName ;
144138
145- }
146-
147- public void editOwner (JSONObject paramInJson ) {
148139
140+ //添加小区楼
149141 OwnerDto ownerDto = new OwnerDto ();
150- ownerDto .setMemberId (paramInJson . getString ( " memberId" ) );
142+ ownerDto .setMemberId (memberId );
151143 List <OwnerDto > ownerDtos = ownerInnerServiceSMOImpl .queryOwnerMembers (ownerDto );
152144
153145 Assert .listOnlyOne (ownerDtos , "未查询到业主信息或查询到多条" );
154146
155- JSONObject businessOwner = new JSONObject ();
156- businessOwner .putAll (BeanConvertUtil .beanCovertMap (ownerDtos .get (0 )));
157- businessOwner .putAll (paramInJson );
158-
159- if (paramInJson .containsKey ("wxPhoto" )) {
160- businessOwner .put ("link" , paramInJson .getString ("wxPhoto" ));
161- }
162- businessOwner .put ("state" , ownerDtos .get (0 ).getState ());
163- OwnerPo ownerPo = BeanConvertUtil .covertBean (businessOwner , OwnerPo .class );
147+ OwnerPo ownerPo = new OwnerPo ();
148+ ownerPo .setMemberId (memberId );
149+ ownerPo .setFaceUrl (faceUrl );
164150 int flag = ownerV1InnerServiceSMOImpl .updateOwner (ownerPo );
165- if (flag < 1 ){
151+ if (flag < 1 ) {
166152 throw new CmdException ("修改业主" );
167153 }
168- OwnerAppUserDto ownerAppUserDto = new OwnerAppUserDto ();
169- ownerAppUserDto .setMemberId (paramInJson .getString ("ownerId" ));
170- //查询app用户表
171- List <OwnerAppUserDto > ownerAppUserDtos = ownerAppUserInnerServiceSMOImpl .queryOwnerAppUsers (ownerAppUserDto );
172- if (ownerAppUserDtos != null && ownerAppUserDtos .size () > 0 ) {
173- for (OwnerAppUserDto ownerAppUser : ownerAppUserDtos ) {
174- OwnerAppUserPo ownerAppUserPo = BeanConvertUtil .covertBean (ownerAppUser , OwnerAppUserPo .class );
175- ownerAppUserPo .setLink (paramInJson .getString ("link" ));
176- ownerAppUserPo .setIdCard (paramInJson .getString ("idCard" ));
177- ownerAppUserV1InnerServiceSMOImpl .updateOwnerAppUser (ownerAppUserPo );
178- }
179- }
180154 }
181155
182156}
0 commit comments